PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.9
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.9
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Form / FormManager.php

FormManager.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.9, at includes/Core/Form/FormManager.php

661 lines 26.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Get set Form,fields
5 */
6
7 namespace BitCode\BitForm\Core\Form;
8
9 /**
10 * FrontendFormManager class
11 */
12
13 use WP_Error;
14 use BitCode\BitForm\Core\Util\IpTool;
15 use BitCode\BitForm\Core\Form\ApiResponse;
16 use BitCode\BitForm\Core\Util\FileHandler;
17 use BitCode\BitForm\Core\Database\FormModel;
18 use BitCode\BitForm\Core\Database\FormEntryModel;
19 use BitCode\BitForm\Core\Database\FormEntryLogModel;
20 use BitCode\BitForm\Core\WorkFlow\WorkFlowRunHelper;
21 use BitCode\BitForm\Core\Database\FormEntryMetaModel;
22 use BitCode\BitForm\Core\Form\Validator\FormFieldValidator;
23 use BitCode\BitForm\Admin\Form\CustomFieldHandler;
24 use BitCode\BitForm\Core\Integration\IntegrationHandler;
25 use BitCode\BitForm\Core\Util\FieldValueHandler;
26
27 class FormManager
28 {
29 protected static $form;
30 protected $formModel;
31 protected $form_id;
32 private $_has_upload;
33 private $_field_label;
34 private $_fields;
35 public function __construct($form_id)
36 {
37 $this->form_id = $form_id;
38 $this->formModel = new FormModel();
39
40 static::$form = $this->formModel->get(
41 [
42 "id",
43 "form_content",
44 "form_name",
45 'created_at',
46 'views',
47 'entries',
48 'status'
49 ],
50 array(
51 'id' => $form_id
52 )
53 );
54 }
55
56 public function isExist()
57 {
58 return (!static::$form || is_wp_error(static::$form)) ? false : true;
59 }
60
61 public function checkStatus()
62 {
63 return static::$form[0]->status === '1' ? true : false;
64 }
65
66 public function getFormContentWithValue($defaultValues)
67 {
68 $form_content = \json_decode(static::$form[0]->form_content);
69 if (!is_array($defaultValues)) {
70 return $form_content;
71 }
72 foreach ($form_content->fields as $fieldKey => $fieldDetails) {
73 // $field_name = empty($fieldDetails->lbl) ? null : \preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\!]/', '_', $fieldDetails->lbl);
74 if ((isset($fieldDetails->mul) || $fieldDetails->typ === 'check') && isset($defaultValues[$fieldKey])) {
75 if (is_array($defaultValues[$fieldKey])) {
76 $fieldDetails->val =
77 wp_json_encode(
78 array_map('sanitize_text_field', $defaultValues[$fieldKey])
79 );
80 } else {
81 $fieldDetails->val = sanitize_text_field($defaultValues[$fieldKey]);
82 }
83 } elseif (isset($defaultValues[$fieldKey])) {
84 $fieldDetails->val = is_string($defaultValues[$fieldKey]) ?
85 sanitize_text_field($defaultValues[$fieldKey]) :
86 sanitize_text_field($defaultValues[$fieldKey][count($defaultValues[$fieldKey]) - 1]);
87 }
88 }
89 return $form_content;
90 }
91
92 public function getFormContent()
93 {
94 $formContent = json_decode(static::$form[0]->form_content);
95 $types = ['check', 'radio', 'select'];
96 $filter = false;
97 foreach ($formContent->fields as $field) {
98 if (in_array($field->typ, $types) && property_exists($field, "customType")) {
99 $filter = true;
100 }
101 }
102 if ($filter == true) {
103 $updateFields = apply_filters('bitform_dynamic_field_filter', $formContent->fields);
104 $formContent->fields = $updateFields;
105 }
106 return $formContent;
107 }
108
109 public function getFormName()
110 {
111 return static::$form[0]->form_name;
112 }
113
114 public function getFields()
115 {
116 if (!is_null($this->_fields)) {
117 return $this->_fields;
118 }
119 $form_content = \json_decode(static::$form[0]->form_content);
120 $layout = $form_content->layout;
121 $fields = $form_content->fields;
122 $field_details = array();
123 foreach ($fields as $key => $field) {
124 if ($field->typ === 'recaptcha') {
125 continue;
126 }
127 // $field_name = empty($field->lbl) ? null : \preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $field->lbl);
128 $field_type = $field->typ;
129 $field_details[$key]['label'] = empty($field->lbl) ? null : $field->lbl;
130 $field_details[$key]['type'] = $field_type;
131 $field_details[$key]['key'] = $key;
132 if (isset($field->customType)) {
133 $field_details[$key]['customType'] = $field->customType;
134 }
135
136 if (isset($field->err)) {
137 if (isset($field->err->entryUnique)) {
138 $field_details[$key]['entryUnique'] = $field->err->entryUnique;
139 }
140 if (isset($field->err->userUnique)) {
141 $field_details[$key]['userUnique'] = $field->err->userUnique;
142 }
143 }
144
145 if (isset($field->mul)) {
146 $field_details[$key]['mul'] = $field->mul;
147 }
148 if ($field_type === 'file-up' && isset($field->exts)) {
149 $field_details[$key]['valid']['type'] = $field->exts;
150 }
151 if ($field_type === 'file-up' && isset($field->mxUp)) {
152 $field_details[$key]['valid']['upload_size'] = (int) $field->mxUp;
153 }
154 if (isset($field->valid) && !is_null($field->valid)) {
155 if (isset($field->valid->req)) {
156 $field_details[$key]['valid']['req'] = $field->valid->req;
157 }
158 if (isset($field->valid->reqMsg)) {
159 $field_details[$key]['valid']['reqMsg'] = $field->valid->reqMsg;
160 }
161 if (isset($field->valid->typMsg)) {
162 $field_details[$key]['valid']['typMsg'] = $field->valid->typMsg;
163 }
164 }
165 }
166 if ($this->isGCLIDEnabled()) {
167 $field_details['GCLID']['name'] = 'GCLID';
168 $field_details['GCLID']['adminLbl'] = 'GCLID';
169 $field_details['GCLID']['key'] = 'GCLID';
170 $field_details['GCLID']['type'] = 'hidden';
171 }
172 $this->_fields = $field_details;
173 return $field_details;
174 }
175 public function getFieldsKey()
176 {
177 $form_content = \json_decode(static::$form[0]->form_content);
178 $fields = $form_content->fields;
179 $field_details = array();
180 foreach ($fields as $key => $field) {
181 if ($field->typ === 'recaptcha') {
182 continue;
183 }
184 // $field_name = empty($field->lbl) ? null : \preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $field->lbl);
185 $field_details[$key] = $key;
186 }
187 if ($this->isGCLIDEnabled()) {
188 $field_details['GCLID'] = 'GCLID';
189 }
190 return $field_details;
191 }
192
193 public function getFieldLabel($forQuery = false)
194 {
195 if (!is_null($this->_field_label)) {
196 return $this->_field_label;
197 }
198 $form_content = \json_decode(static::$form[0]->form_content);
199 $fields = $form_content->fields;
200 $field_details = array();
201 $fieldCounter = 0;
202 foreach ($fields as $key => $field) {
203 if ($field->typ === 'recaptcha' || $field->typ === 'html' || $field->typ === 'button') {
204 continue;
205 }
206 $field_details[$fieldCounter]['name'] = empty($field->lbl) ? null : $field->lbl;
207 $field_details[$fieldCounter]['adminLbl'] = empty($field->adminLbl) ? $field_details[$fieldCounter]['name'] : $field->adminLbl;
208 $field_details[$fieldCounter]['key'] = $key;
209 $field_details[$fieldCounter]['type'] = $field->typ;
210 $fieldCounter += 1;
211 }
212 if ($this->isGCLIDEnabled()) {
213 $field_details[$fieldCounter]['name'] = 'GCLID';
214 $field_details[$fieldCounter]['adminLbl'] = 'GCLID';
215 $field_details[$fieldCounter]['key'] = 'GCLID';
216 $field_details[$fieldCounter]['type'] = 'hidden';
217 $fieldCounter += 1;
218 }
219 if (!$forQuery) {
220 $field_details = (array) $this->addEntryInfo($field_details, $fieldCounter);
221 }
222 $this->_field_label = $field_details;
223 return $field_details;
224 }
225
226 public function getUploadFields()
227 {
228 if (!is_null($this->_has_upload)) {
229 return $this->_has_upload;
230 }
231 $upload_fields = array();
232 $form_field_details = $this->getFields();
233 foreach ($form_field_details as $field_name => $__field_detail) {
234 if (isset($__field_detail['type']) && $__field_detail['type'] === 'file-up') {
235 $upload_fields[] = $field_name;
236 }
237 }
238 $this->_has_upload = $upload_fields;
239 return $upload_fields;
240 }
241
242 private function entryInsert($user_details)
243 {
244 $formEntryModel = new FormEntryModel();
245 $entryId = $formEntryModel->insert(
246 array(
247 'form_id' => $this->form_id,
248 'user_id' => $user_details['id'],
249 'user_ip' => $user_details['ip'],
250 'user_device' => $user_details['device'],
251 'referer' => $user_details['page'],
252 'status' => 1,
253 'created_at' => $user_details['time']
254 )
255 );
256 return $entryId;
257 }
258
259 private function submisionLog($user_details, $entry_id, $type)
260 {
261 $formEntryLogModel = new FormEntryLogModel();
262 $logId = $formEntryLogModel->form_log_insert(
263 array(
264 "user_id" => $user_details['id'],
265 "action_type" => $type,
266 "log_type" => "entry",
267 "ip" => $user_details['ip'],
268 "form_entry_id" => $entry_id,
269 "content" => null,
270 "form_id" => $this->form_id,
271 "created_at" => $user_details['time'],
272 )
273 );
274 return $logId;
275 }
276
277 private function isArrayAllKeyInt($InputArray)
278 {
279 if (!is_array($InputArray)) {
280 return false;
281 }
282
283 if (count($InputArray) <= 0) {
284 return true;
285 }
286
287 return array_unique(array_map("is_int", array_keys($InputArray))) === array(true);
288 }
289
290 private function saveEntryMeta($submitted_data, $entry_id)
291 {
292 $errorInEntryMetaInsert = false;
293 $entryMeta = new FormEntryMetaModel();
294 foreach ($submitted_data as $key => $value) {
295 $value = $submitted_data[$key];
296 if (is_string($value)) {
297 $value = wp_unslash($value);
298 } elseif ($this->isArrayAllKeyInt($value)) {
299 $value = wp_json_encode(array_values($value));
300 } else {
301 $value = wp_json_encode($value);
302 }
303 $status = $entryMeta->insert(
304 array(
305 'bitforms_form_entry_id' => $entry_id,
306 'meta_key' => $key,
307 'meta_value' => $value
308 )
309 );
310 if (is_wp_error($status)) {
311 $errorInEntryMetaInsert = true;
312 break;
313 }
314 }
315 return $errorInEntryMetaInsert;
316 }
317
318 public function saveFormEntry($submitted_data)
319 {
320 $form_content = \json_decode(static::$form[0]->form_content);
321 do_action('bitform_save_entry', $this, $submitted_data);
322 $key = null;
323 $ipTool = new IpTool();
324 $fileHandler = new FileHandler();
325 $form_fields = $this->getFields();
326 $file_fields = $this->getUploadFields();
327 foreach ($_FILES as $file_name => $file_details) {
328 if ($file_fields && in_array($file_name, $file_fields)) {
329 if ($file_fields && in_array($file_name, $file_fields)) {
330 $validation = $fileHandler->validation($file_name, $file_details, $this->form_id);
331 if (!empty($validation['error_type']) && !empty($validation['message'])) {
332 return new WP_Error($validation['error_type'], __($validation['message'], 'bit-form'));
333 }
334 }
335 }
336 }
337
338 $user_details = $ipTool->getUserDetail();
339 $submitted_data = $this->passwordEncrypted($submitted_data, $form_fields);
340 global $wpdb;
341 $wpdb->query("START TRANSACTION");
342 $entry_id = $this->entryInsert($user_details);
343 $log_id = null;
344 if (is_wp_error($entry_id)) {
345 return new WP_Error('insert_error', __('Sorry, Error occurred in saving form entry', 'bit-form'));
346 }
347 if ($entry_id) {
348 $log_id = $this->submisionLog($user_details, $entry_id, 'create', $key);
349 if (is_wp_error($log_id)) {
350 $wpdb->query("ROLLBACK");
351 return new WP_Error('error_entry_log', __('Sorry, error occurred in logging form entry', 'bit-form'));
352 }
353 }
354 if ($entry_id) {
355 $submitted_fields = $this->getFormContentWithValue($submitted_data)->fields;
356 $workFlowRunHelper = new WorkFlowRunHelper($this->form_id);
357 $workFlowreturnedOnSubmit = $workFlowRunHelper->executeOnSubmit(
358 'create',
359 $submitted_fields,
360 $submitted_data,
361 $entry_id,
362 $log_id
363 );
364 if (!empty($workFlowreturnedOnSubmit['fields'])) {
365 $submitted_data = $workFlowreturnedOnSubmit['fields'];
366 }
367
368 $file_fields = $this->getUploadFields();
369 $fileHandler = new FileHandler();
370 foreach ($_FILES as $file_name => $file_details) {
371 if ($file_fields && in_array($file_name, $file_fields)) {
372 $filePath = $fileHandler->moveUploadedFiles($file_details, $this->form_id, $entry_id);
373 if (!empty($filePath)) {
374 $submitted_data[$file_name] = $filePath;
375 }
376 }
377 }
378
379 if (!isset($form_content->additional->enabled->submission)) {
380 $errorInEntryMetaInsert = $this->saveEntryMeta($submitted_data, $entry_id);
381 if ($errorInEntryMetaInsert) {
382 $wpdb->query("ROLLBACK");
383 return new WP_Error('insert_error', __('Sorry, Error occured in saving form entry data', 'bit-form'));
384 }
385 }
386 $wpdb->query("COMMIT");
387 $this->setSubmissionCount();
388 $workFlowreturnedOnSubmit['fields'] = $submitted_data;
389
390 return $workFlowreturnedOnSubmit;
391 }
392 }
393
394 public function passwordEncrypted($updatedValue, $form_fields)
395 {
396 $integrationHandler = new IntegrationHandler($this->form_id);
397 $formIntegrations = $integrationHandler->getAllIntegration('wp_user_auth', 'wp_auth', 1);
398 if (!isset($formIntegrations->errors['result_empty'])) {
399 foreach ($form_fields as $field) {
400 if (array_key_exists($field['key'], $updatedValue) && $field['type'] == 'password') {
401 $updatedValue[$field['key']] = '**** (encrypted)';
402 }
403 }
404 }
405 return $updatedValue;
406 }
407
408 public function updateFormEntry($updatedValue, $formID, $entryID)
409 {
410 $formEntryModel = new FormEntryModel();
411 $formEntryLogModel = new FormEntryLogModel();
412 $formOldData = $formEntryLogModel->get_form_value($entryID);
413 $key = null;
414 $entryMeta = new FormEntryMetaModel();
415 $ipTool = new IpTool();
416 $user_details = $ipTool->getUserDetail();
417 $form_fields = $this->getFields();
418 $updatedValue = $this->passwordEncrypted($updatedValue, $form_fields);
419 $field_map = [];
420 foreach ($formOldData as $index => $data) {
421 foreach ($form_fields as $field_key => $field) {
422 if ($data->meta_key == $field['key']) {
423 $field_map[$field_key] = $field['key'];
424 }
425 }
426 }
427 $formFieldValidator = new FormFieldValidator($form_fields, $updatedValue, $_FILES);
428 $validateField = $formFieldValidator->validate('edit', $formID);
429 if (!$validateField) {
430 $errorMessage = count($formFieldValidator->getMessage()) > 0 ?
431 $formFieldValidator->getMessage() : __("Internal error occured!!!", 'bit-form');
432 return new WP_Error('validation_error', $errorMessage);
433 }
434 $formEntry = $formEntryModel->update(
435 array(
436 "user_id" => $user_details['id'],
437 "user_ip" => $user_details['ip'],
438 "user_device" => $user_details['device'],
439 // "status" => 0,
440 "updated_at" => $user_details['time']
441 ),
442 array(
443 'form_id' => $formID,
444 'id' => $entryID
445 )
446 );
447 $log_id = null;
448 if ($formEntry) {
449 $log_id = $this->submisionLog($user_details, $entryID, 'update');
450 }
451
452 if (is_wp_error($formEntry) || !$formEntry) {
453 return new WP_Error('empty_form', __('provided form entries does not exists', 'bit-form'));
454 }
455
456 $file_fields = $this->getUploadFields();
457 if (count($file_fields) > 0) {
458 $fileHandler = new FileHandler();
459 foreach ($file_fields as $file_name) {
460 if (isset($updatedValue[$file_name . '_old'])) {
461 $file_exists = $entryMeta->get(
462 'meta_value',
463 array(
464 'bitforms_form_entry_id' => $entryID,
465 'meta_key' => $file_name
466 )
467 );
468 if (!is_wp_error($file_exists) && count($file_exists) > 0) {
469 $files_in_db = json_decode($file_exists[0]->meta_value);
470 $files_old = empty($updatedValue[$file_name . '_old']) ? [] : explode(',', $updatedValue[$file_name . '_old']);
471 $deleted_file = array_diff($files_in_db, $files_old);
472 if (count($deleted_file) > 0) {
473 $fileHandler->deleteFiles($formID, $entryID, $deleted_file);
474 }
475 $updatedValue[$file_name] = wp_json_encode($files_old);
476 }
477 }
478 if (!empty($_FILES[$file_name]['name'])) {
479 $meta_value = $fileHandler->moveUploadedFiles($_FILES[$file_name], $formID, $entryID);
480 if (!empty($meta_value)) {
481 if (isset($updatedValue[$file_name . '_old']) && !is_wp_error($file_exists) && count($file_exists) > 0) {
482 $meta_value = empty($files_old) ? $meta_value : array_merge($meta_value, $files_old);
483 $updatedValue[$file_name] = wp_json_encode($meta_value);
484 } else {
485 $data = array(
486 'bitforms_form_entry_id' => $entryID,
487 'meta_key' => $file_name,
488 'meta_value' => wp_json_encode($meta_value)
489 );
490 $newFileInsertStatus = $entryMeta->insert(
491 $data
492 );
493 $updatedValue[$file_name] = wp_json_encode($meta_value);
494 }
495 }
496 }
497 }
498 }
499
500
501
502 unset($updatedValue['_ajax_nonce']);
503 unset($_REQUEST['g-recaptcha-response']);
504
505 $workFlowRunHelper = new WorkFlowRunHelper($formID);
506 $workFlowreturnedOnSubmit = $workFlowRunHelper->executeOnSubmit(
507 'edit',
508 $this->getFormContentWithValue($updatedValue)->fields,
509 $updatedValue,
510 $entryID,
511 $log_id
512 );
513 if (!empty($workFlowreturnedOnSubmit['fields'])) {
514 $updatedValue = $workFlowreturnedOnSubmit['fields'];
515 }
516
517
518 $toUpdateValues = [];
519 foreach ($form_fields as $field) {
520 if (isset($updatedValue[$field['key']])) {
521 $toUpdateValues[$field['key']] = $updatedValue[$field['key']];
522 }
523 }
524 $formEntryMetaUpdateStatus = $entryMeta->update(
525 $toUpdateValues,
526 array(
527 'bitforms_form_entry_id' => $entryID
528 )
529 );
530 if (is_wp_error($formEntryMetaUpdateStatus) || isset($newFileInsertStatus) && is_wp_error($newFileInsertStatus)) {
531 return $formEntryMetaUpdateStatus;
532 }
533 $toUpdateValues = array_merge($formEntryMetaUpdateStatus, array('entry_id' => $entryID));
534 if (empty($workFlowreturnedOnSubmit['message'])) {
535 $workFlowreturnedOnSubmit['message'] = __('Entry Updated Successfully', 'bit-form');
536 }
537 $customFieldHandler = new CustomFieldHandler();
538 $toUpdateValues = $customFieldHandler->updatedData($form_fields, $toUpdateValues);
539 $workFlowreturnedOnSubmit['updatedData'] = $toUpdateValues;
540 $counter = 0;
541 for ($i = 0; $i < count($formOldData); $i++) {
542 if (array_key_exists($formOldData[$i]->meta_key . '_old', $toUpdateValues)) {
543 unset($toUpdateValues[$formOldData[$i]->meta_key . '_old']);
544 }
545 if (in_array($formOldData[$i]->meta_key, $file_fields)) {
546 if (
547 empty($_FILES[$formOldData[$i]->meta_key]['name'])
548 || (is_array($_FILES[$formOldData[$i]->meta_key]['name'])
549 && count($_FILES[$formOldData[$i]->meta_key]['name']) === 1
550 && empty($_FILES[$formOldData[$i]->meta_key]['name'][0]))
551 ) {
552 unset($toUpdateValues[$formOldData[$i]->meta_key]);
553 continue;
554 }
555 if (is_array($_FILES[$formOldData[$i]->meta_key]['name']) && !in_array($_FILES[$formOldData[$i]->meta_key]['name'], json_decode($formOldData[$i]->meta_value))) {
556 $key[$i] = '${' . $formOldData[$i]->meta_key . '} file was Updated To ' . json_encode($_FILES[$formOldData[$i]->meta_key]['name']);
557 } elseif (!is_array($_FILES[$formOldData[$i]->meta_key]['name']) && !in_array($_FILES[$formOldData[$i]->meta_key]['name'], json_decode($formOldData[$i]->meta_value))) {
558 $key[$i] = '${' . $formOldData[$i]->meta_key . '} file was Updated To ' . $_FILES[$formOldData[$i]->meta_key]['name'];
559 }
560 unset($toUpdateValues[$formOldData[$i]->meta_key]);
561 } elseif (isset($toUpdateValues[$formOldData[$i]->meta_key])) {
562 if (is_array($toUpdateValues[$formOldData[$i]->meta_key])) {
563 if (json_decode($formOldData[$i]->meta_value) !== $toUpdateValues[$formOldData[$i]->meta_key]) {
564 $key[$i] = '${' . $formOldData[$i]->meta_key . '} was Updated From ' . implode(',', json_decode($formOldData[$i]->meta_value)) . ' To ' . implode(",", $toUpdateValues[$formOldData[$i]->meta_key]);
565 }
566 } elseif (is_string($toUpdateValues[$formOldData[$i]->meta_key]) && !FieldValueHandler::isEmpty($toUpdateValues[$formOldData[$i]->meta_key])) {
567 if ($formOldData[$i]->meta_value !== $toUpdateValues[$formOldData[$i]->meta_key]) {
568 $key[$i] = '${' . $formOldData[$i]->meta_key . '} was Updated' . ($formOldData[$i]->meta_value ? ' From ' . $formOldData[$i]->meta_value : '') . ' To ' . $toUpdateValues[$formOldData[$i]->meta_key];
569 }
570 }
571 }
572 $counter++;
573 }
574
575 $newField = array_keys(array_diff_key($formEntryMetaUpdateStatus, $field_map));
576 for ($i = 0; $i < count($newField); $i++) {
577 if (is_array($toUpdateValues[$newField[$i]]) && !empty($toUpdateValues[$newField[$i]])) {
578 $key[$counter + $i] = '${' . $newField[$i] . '} Updated To ' . implode(",", $toUpdateValues[$newField[$i]]);
579 } elseif (is_string($newField[$i]) && !FieldValueHandler::isEmpty($toUpdateValues[$newField[$i]])) {
580 $key[$counter + $i] = '${' . $newField[$i] . '} Updated To ' . $toUpdateValues[$newField[$i]];
581 }
582 }
583 if ($key !== null) {
584 $logUpdate = implode("b::f", (array) $key);
585 $formEntryLogUpdate = $formEntryLogModel->logUpdate($logUpdate, $log_id);
586 }
587 return $workFlowreturnedOnSubmit;
588 }
589
590 public function setSubmissionCount($countStep = 1)
591 {
592 $update_status = $this->formModel->update(
593 array(
594 'entries' => intval(static::$form[0]->entries) + $countStep
595 ),
596 array(
597 'id' => $this->form_id
598 )
599 );
600 }
601 public function resetSubmissionCount($countStep)
602 {
603 $update_status = $this->formModel->update(
604 array(
605 'entries' => intval($countStep)
606 ),
607 array(
608 'id' => $this->form_id
609 )
610 );
611 }
612
613 public function getCaptchaSettings()
614 {
615 $formContents = $this->getFormContent();
616 $fieldStr = wp_json_encode($formContents->fields);
617 if (strpos($fieldStr, '"typ":"recaptcha"') !== false) {
618 return true;
619 }
620 }
621 public function getCaptchaV3Settings()
622 {
623 $formContents = $this->getFormContent();
624 if (!empty($formContents->additional->enabled) && !empty($formContents->additional->enabled->recaptchav3)) {
625 return $formContents->additional->settings->recaptchav3;
626 }
627 return false;
628 }
629
630 public function isGCLIDEnabled()
631 {
632 $formContents = $this->getFormContent();
633 if (isset($formContents->additional->enabled->captureGCLID) && $formContents->additional->enabled->captureGCLID) {
634 return true;
635 }
636 return false;
637 }
638
639 protected function addEntryInfo($field_details, $counter)
640 {
641 $infos = [
642 '__user_id' => __('User'),
643 '__entry_status' => __('Status'),
644 //'__user_location' => __(''),
645 '__referer' => __('Refer URL'),
646 '__user_device' => __('Device'),
647 '__user_ip' => __('IP address'),
648 '__created_at' => __('Created Time'),
649 '__updated_at' => __('Modified Time'),
650 ];
651 foreach ($infos as $key => $value) {
652 $field_details[$counter]['name'] = $value;
653 $field_details[$counter]['key'] = $key;
654 $field_details[$counter]['type'] = 'sys';
655 $counter = $counter + 1;
656 }
657
658 return $field_details;
659 }
660 }
661