PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.1
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 / Admin / AdminAjax.php

AdminAjax.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.10.1, at includes/Admin/AdminAjax.php

1,732 lines 51.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Admin;
4
5 use BitCode\BitForm\Admin\Form\FrontEndScriptGenerator;
6 use BitCode\BitForm\Admin\Form\Helpers;
7 use BitCode\BitForm\Admin\Form\Template\TemplateProvider;
8 use BitCode\BitForm\Core\Database\DB;
9 use BitCode\BitForm\Core\Database\FormEntryModel;
10 use BitCode\BitForm\Core\Database\FormModel;
11 use BitCode\BitForm\Core\Form\FormHandler;
12 use BitCode\BitForm\Core\Integration\IntegrationHandler;
13 use BitCode\BitForm\Core\Integration\Integrations;
14 use BitCode\BitForm\Core\Migration\MigrateForms;
15 use BitCode\BitForm\Core\Util\IpTool;
16 use BitCode\BitForm\Core\Util\MailConfig;
17
18 class AdminAjax
19 {
20 public function register()
21 {
22 add_action('wp_ajax_bitforms_integrations', [$this, 'integrations']);
23 add_action('wp_ajax_integration', [$this, 'integration']);
24 add_action('wp_ajax_bitforms_update_form', [$this, 'updateForm']);
25 add_action('wp_ajax_bitforms_templates', [$this, 'templates']);
26 add_action('wp_ajax_bitforms_create_new_form', [$this, 'createNewForm']);
27 add_action('wp_ajax_bitforms_save_css', [$this, 'saveCss']);
28 add_action('wp_ajax_bitforms_get_template', [$this, 'getTemplate']);
29 add_action('wp_ajax_bitforms_change_status', [$this, 'changeFormStatus']);
30 add_action('wp_ajax_bitforms_bulk_status_change', [$this, 'changeBulkFormStatus']);
31 add_action('wp_ajax_bitforms_get_a_form', [$this, 'getAForm']);
32 add_action('wp_ajax_bitforms_bulk_delete_form', [$this, 'deleteBlukForm']);
33 add_action('wp_ajax_bitforms_bulk_delete_form_entries', [$this, 'deleteBlukFormEntries']);
34 add_action('wp_ajax_bitforms_delete_aform', [$this, 'deleteAForm']);
35 add_action('wp_ajax_bitforms_duplicate_aform', [$this, 'duplicateAForm']);
36 add_action('wp_ajax_bitforms_export_aform', [$this, 'exportAForm']);
37 add_action('wp_ajax_bitforms_import_aform', [$this, 'importAForm']);
38 add_action('wp_ajax_bitforms_get_form_entries', [$this, 'getFormEntry']);
39 add_action('wp_ajax_bitforms_get_entries_for_report', [$this, 'getEntriesForReport']);
40 add_action('wp_ajax_bitforms_duplicate_form_entries', [$this, 'duplicateFormEntry']);
41 add_action('wp_ajax_bitforms_edit_form_entry', [$this, 'editFormEntry']);
42 add_action('wp_ajax_bitforms_update_form_entry', [$this, 'updateFormEntry']);
43 add_action('wp_ajax_bitforms_get_all_form', [$this, 'getAllForms']);
44 add_action('wp_ajax_bitforms_get_all_wp_pages', [$this, 'getAllWPPages']);
45 add_action('wp_ajax_bitforms_delete_success_messsage', [$this, 'deleteSuccessMessage']);
46 add_action('wp_ajax_bitforms_delete_integration', [$this, 'deleteAIntegration']);
47 add_action('wp_ajax_bitforms_delete_workflow', [$this, 'deleteAWorkflow']);
48 add_action('wp_ajax_bitforms_delete_mailtemplate', [$this, 'deleteAMailTemplate']);
49 add_action('wp_ajax_bitforms_duplicate_mailtemplate', [$this, 'duplicateAMailTemplate']);
50 add_action('wp_ajax_bitforms_save_allForm_report_prefs', [$this, 'setAllFormsReport']);
51 add_action('wp_ajax_bitforms_save_grecaptcha', [$this, 'savegReCaptcha']);
52 add_action('wp_ajax_bitforms_form_log_history', [$this, 'getLogHistory']);
53 add_action('wp_ajax_bitforms_import_file_data', [$this, 'importFileData']);
54 add_action('wp_ajax_bitforms_filter_export_data', [$this, 'filterExportEntry']);
55 add_action('wp_ajax_bitforms_api_key', [$this, 'saveApiKey']);
56 add_action('wp_ajax_bitforms_form_helpers_state', [$this, 'builerHelperState']);
57 add_action('wp_ajax_bitforms_icn_save_setting', [$this, 'iconUpload']);
58 add_action('wp_ajax_bitforms_get_download_icn', [$this, 'getDownlodedIcons']);
59 add_action('wp_ajax_bitforms_icon_remove', [$this, 'iconRemove']);
60 add_action('wp_ajax_bitforms_add_custom_code', [$this, 'addCustomCode']);
61 add_action('wp_ajax_bitforms_get_custom_code', [$this, 'getCustomCode']);
62 add_action('wp_ajax_bitforms_entry_status_update', [$this, 'updateEntryStatus']);
63 add_action('wp_ajax_bitforms_get_generel_settings', [$this, 'getGenerelSettings']);
64 add_action('wp_ajax_bitforms_save_generel_settings', [$this, 'saveGenerelSettings']);
65 add_action('wp_ajax_bitforms_get_form_entry_count', [$this, 'getFormEntryLabelAndCount']);
66 add_action('wp_ajax_bitforms_save_payment_setting', [$this, 'savePaymentSettings']);
67
68 // form migrate code
69 add_action('wp_ajax_bitforms_get_migrated_form_contents', [$this, 'migrateFormContents']);
70 add_action('wp_ajax_bitforms_migrate_to_v2_complete', [$this, 'migrationComplete']);
71 add_action('wp_ajax_bitforms_migrate_back_to_v1', [$this, 'migrationBackToV1']);
72
73 // PRO TO FREE (SMTP)
74 add_action('wp_ajax_bitforms_get_mail_config', [$this, 'getEmailConfig']);
75 add_action('wp_ajax_bitforms_mail_config', [$this, 'saveEmailConfig']);
76 add_action('wp_ajax_bitforms_test_email', [$this, 'testEmail']);
77
78 // PODS INTEGRATION
79 add_action('wp_ajax_bitforms_get_pod_field', [$this, 'getPodsField']);
80 add_action('wp_ajax_bitforms_get_pod_type', [$this, 'getPodsType']);
81
82 // ACF INTEGRATION
83 add_action('wp_ajax_bitforms_get_acf_group_fields', [$this, 'getAcfGroupFields']);
84 add_action('wp_ajax_bitforms_get_custom_field', [$this, 'getCustomField']);
85
86 // common (get post type) for integration
87 add_action('wp_ajax_bitforms_get_post_type', [$this, 'postTypeByUser']);
88
89 // Meta Box INTEGRATION
90 add_action('wp_ajax_bitforms_get_metabox_fields', [$this, 'getMetaboxFields']);
91
92 // CHANGELOG VERSION OPTIONS
93 add_action('wp_ajax_bitforms_changelog_version', [$this, 'setChangelogVersion']);
94
95 // conversational
96 add_action('wp_ajax_bitforms_save_conversational_css', [$this, 'saveConversationalCSS']);
97
98 // PDF
99 }
100
101 /**
102 * Undocumented function
103 *
104 * @return void
105 */
106 public function integrations()
107 {
108 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
109 $testIntegration = new Integrations();
110 $allIntegrations = $testIntegration->getAllintegrations();
111 if ($allIntegrations) {
112 wp_send_json_success($allIntegrations, 200);
113 } else {
114 wp_send_json_error(
115 __('No Integration Found', 'bit-form'),
116 404
117 );
118 }
119 } else {
120 wp_send_json_error(
121 __(
122 'Token expired',
123 'bit-form'
124 ),
125 401
126 );
127 }
128 }
129
130 public function templates()
131 {
132 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
133 $templateProvider = new TemplateProvider();
134 $status = $templateProvider->getAllTemplates();
135 if (is_wp_error($status)) {
136 wp_send_json_error($status->get_error_message(), 411);
137 } else {
138 wp_send_json_success($status, 200);
139 }
140 } else {
141 wp_send_json_error(
142 __(
143 'Token expired',
144 'bit-form'
145 ),
146 401
147 );
148 }
149 }
150
151 public function builerHelperState()
152 {
153 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
154 $inputJSON = file_get_contents('php://input');
155 $input = json_decode($inputJSON);
156
157 $formID = $input->formID;
158 $formHandler = FormHandler::getInstance();
159 $results = $formHandler->admin->builerHelperState($formID);
160 if (is_wp_error($results)) {
161 wp_send_json_error($results, 411);
162 } else {
163 wp_send_json_success($results, 200);
164 }
165 } else {
166 wp_send_json_error(
167 __(
168 'Token expired',
169 'bit-form'
170 ),
171 401
172 );
173 }
174 }
175
176 public function getTemplate()
177 {
178 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
179 $inputJSON = file_get_contents('php://input');
180 $input = json_decode($inputJSON);
181 $formHandler = FormHandler::getInstance();
182 $status = $formHandler->admin->getTemplate($_REQUEST, $input);
183 if (is_wp_error($status)) {
184 wp_send_json_error($status->get_error_message(), 411);
185 } else {
186 wp_send_json_success($status, 200);
187 }
188 } else {
189 wp_send_json_error(
190 __(
191 'Token expired',
192 'bit-form'
193 ),
194 401
195 );
196 }
197 }
198
199 public function getAllForms()
200 {
201 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
202 $formHandler = FormHandler::getInstance();
203 $all_forms = $formHandler->admin->getAllForm();
204 if (is_wp_error($all_forms)) {
205 wp_send_json_error($all_forms->get_error_message(), 411);
206 } else {
207 wp_send_json_success($all_forms, 200);
208 }
209 } else {
210 wp_send_json_error(
211 __(
212 'Token expired',
213 'bit-form'
214 ),
215 401
216 );
217 }
218 }
219
220 public function migrateFormContents()
221 {
222 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
223 update_site_option('bitforms_db_version', '2.0');
224 DB::migrate();
225 $migrateFormsHandler = new MigrateForms();
226 $all_forms = $migrateFormsHandler->migrateToV2();
227 wp_send_json_success($all_forms, 200);
228 } else {
229 wp_send_json_error(
230 __(
231 'Token expired',
232 'bit-form'
233 ),
234 401
235 );
236 }
237 }
238
239 public function setChangelogVersion()
240 {
241 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
242 $inputJSON = file_get_contents('php://input');
243 $input = json_decode($inputJSON);
244 $version = isset($input->version) ? $input->version : '';
245 update_option('bitforms_changelog_version', $version);
246 wp_send_json_success($version, 200);
247 } else {
248 wp_send_json_error(
249 __(
250 'Token expired',
251 'bit-form'
252 ),
253 401
254 );
255 }
256 }
257
258 private function formatFormContentForUpdate($formContents)
259 {
260 $updatedFormContents = (object) [];
261 $updatedPaths = [
262 'id' => 'id',
263 'form_name' => 'form_name',
264 'layout' => 'form_content->layout',
265 'fields' => 'form_content->fields',
266 'additional' => 'additional',
267 'workFlows' => 'workFlows',
268 'formStyle' => null,
269 'style' => null,
270 'staticStyles' => null,
271 'themeColors' => null,
272 'themeVars' => null,
273 'breakpointSize' => null,
274 'customCodes' => null,
275 'builderSettings' => null,
276 'layoutChanged' => null,
277 'rowHeight' => null,
278 'formSettings' => 'formSettings',
279 ];
280 foreach ($updatedPaths as $key => $value) {
281 if (!is_null($value)) {
282 $value = Helpers::getDataFromNestedPath($formContents, $value);
283 }
284 $updatedFormContents->$key = $value;
285 }
286
287 foreach ($formContents['reports'] as $report) {
288 if ('1' === $report['isDefault']) {
289 $updatedFormContents->currentReport = $report;
290 $updatedFormContents->report_id = $report['id'];
291 }
292 }
293
294 $updatedFormContents = json_decode(wp_json_encode($updatedFormContents));
295
296 $updatedFormContents->formSettings->theme = 'default';
297
298 return $updatedFormContents;
299 }
300
301 public function getEmailConfig()
302 {
303 \ignore_user_abort();
304
305 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
306 unset($_REQUEST['_ajax_nonce'], $_REQUEST['action']);
307 $ipTool = new IpTool();
308 $user_details = $ipTool->getUserDetail();
309 $integrationHandler = new IntegrationHandler(0, $user_details);
310 $user_details = $ipTool->getUserDetail();
311 $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp');
312 wp_send_json_success($formIntegrations, 200);
313 } else {
314 wp_send_json_error(
315 __(
316 'Token expired',
317 'bit-form'
318 ),
319 401
320 );
321 }
322 }
323
324 public function saveEmailConfig()
325 {
326 \ignore_user_abort();
327 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
328 $ipTool = new IpTool();
329 $status = $_REQUEST['status'];
330 $user_details = $ipTool->getUserDetail();
331 $integrationHandler = new IntegrationHandler(0, $user_details);
332 unset($_REQUEST['_ajax_nonce'], $_REQUEST['action'], $_REQUEST['status']);
333 $integrationDetails = wp_json_encode($_REQUEST);
334 $user_details = $ipTool->getUserDetail();
335 $integrationName = 'smtp';
336 $integrationType = 'smtp';
337 $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp');
338 if (isset($formIntegrations->errors['result_empty'])) {
339 $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'mail', $status);
340 } else {
341 $integrationHandler->updateIntegration($formIntegrations[0]->id, $integrationName, $integrationType, $integrationDetails, 'mail', $status);
342 }
343 wp_send_json_success($formIntegrations, 200);
344 } else {
345 wp_send_json_error(
346 __(
347 'Token expired',
348 'bit-form'
349 ),
350 401
351 );
352 }
353 }
354
355 public function testEmail()
356 {
357 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
358 $to = wp_unslash($_REQUEST['to']);
359 $subject = wp_unslash($_REQUEST['subject']);
360 $message = wp_unslash($_REQUEST['message']);
361 unset($_REQUEST['_ajax_nonce'], $_REQUEST['action']);
362 if (!empty($to) && !empty($subject) && !empty($message)) {
363 try {
364 (new MailConfig())->sendMail();
365 add_action('wp_mail_failed', function ($error) {
366 $data = [];
367 $data['errors'] = $error->errors['wp_mail_failed'];
368 wp_send_json_error($data, 400);
369 });
370 $result = wp_mail($to, $subject, $message);
371 wp_send_json_success($result, 200);
372 } catch (\Exception $e) {
373 wp_send_json_error($e->getMessage(), 400);
374 }
375 } else {
376 wp_send_json_error(
377 __(
378 'Some of the test fields are empty or an invalid email supplied',
379 'bit-form'
380 ),
381 401
382 );
383 }
384 } else {
385 wp_send_json_error(
386 __(
387 'Token expired',
388 'bit-form'
389 ),
390 401
391 );
392 }
393 }
394
395 public function migrationComplete()
396 {
397 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
398 delete_transient('bitforms_v1_form_contents');
399 delete_option('bitforms_migrating_to_v2');
400 update_option('bitforms_migrated_to_v2', true);
401 wp_send_json_success(__('Migration Complete', 'bit-form'), 200);
402 } else {
403 wp_send_json_error(
404 __(
405 'Token expired',
406 'bit-form'
407 ),
408 401
409 );
410 }
411 }
412
413 public function migrationBackToV1()
414 {
415 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
416 $migrateFormsHandler = new MigrateForms();
417 $migrateFormsHandler->rollbackToV1();
418 wp_send_json_success(__('Migration Back to V1', 'bit-form'), 200);
419 } else {
420 wp_send_json_error(
421 __(
422 'Token expired',
423 'bit-form'
424 ),
425 401
426 );
427 }
428 }
429
430 public function importDataStore()
431 {
432 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
433 $inputJSON = file_get_contents('php://input');
434 $input = json_decode($inputJSON);
435 echo wp_json_encode($input);
436 die;
437 // $formHandler = FormHandler::getInstance();
438 // $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input);
439 // if (is_wp_error($status)) {
440 // wp_send_json_error($status->get_error_message(), 411);
441 // } else {
442 // wp_send_json_success($status, 200);
443 // }
444 } else {
445 wp_send_json_error(
446 __(
447 'Token expired',
448 'bit-form'
449 ),
450 401
451 );
452 }
453 }
454
455 public function getFormEntryLabelAndCount()
456 {
457 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
458 $inputJSON = file_get_contents('php://input');
459 $input = json_decode($inputJSON);
460 $formHandler = FormHandler::getInstance();
461 $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input);
462 if (is_wp_error($status)) {
463 wp_send_json_error($status->get_error_message(), 411);
464 } else {
465 wp_send_json_success($status, 200);
466 }
467 } else {
468 wp_send_json_error(
469 __(
470 'Token expired',
471 'bit-form'
472 ),
473 401
474 );
475 }
476 }
477
478 public function getFormEntry()
479 {
480 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
481 $inputJSON = file_get_contents('php://input');
482 $input = json_decode($inputJSON);
483 $formHandler = FormHandler::getInstance();
484 $status = $formHandler->admin->getFormEntry($_REQUEST, $input);
485 if (is_wp_error($status)) {
486 wp_send_json_error($status->get_error_message(), 411);
487 } else {
488 wp_send_json_success($status, 200);
489 }
490 } else {
491 wp_send_json_error(__('Token expired', 'bit-form'), 401);
492 }
493 }
494
495 public function getEntriesForReport()
496 {
497 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
498 $inputJSON = file_get_contents('php://input');
499 $input = json_decode($inputJSON);
500 $formHandler = FormHandler::getInstance();
501 $status = $formHandler->admin->getEntriesForReport($_REQUEST, $input);
502 if (is_wp_error($status)) {
503 wp_send_json_error($status->get_error_message(), 411);
504 } else {
505 wp_send_json_success($status, 200);
506 }
507 } else {
508 wp_send_json_error(__('Token expired', 'bit-form'), 401);
509 }
510 }
511
512 public function filterExportEntry()
513 {
514 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
515 $inputJSON = file_get_contents('php://input');
516 $input = json_decode($inputJSON);
517 $formHandler = FormHandler::getInstance();
518 $status = $formHandler->admin->getExportEntry($input->data);
519 if (is_wp_error($status)) {
520 wp_send_json_error($status->get_error_message(), 411);
521 } else {
522 wp_send_json_success($status, 200);
523 }
524 } else {
525 wp_send_json_error(__('Token expired', 'bit-form'), 401);
526 }
527 }
528
529 /**
530 * Undocumented function
531 *
532 * @return void
533 */
534 public function updateForm()
535 {
536 \ignore_user_abort();
537 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
538 $inputJSON = file_get_contents('php://input');
539 $input = json_decode($inputJSON);
540 // wp_send_json_success($input, 200);
541 $formHandler = FormHandler::getInstance();
542 $status = $formHandler->admin->updateForm($_REQUEST, $input);
543 if (isset($input->customCodes)) {
544 FrontEndScriptGenerator::customCodeFile($input->id, $input->customCodes);
545 }
546 if (is_wp_error($status)) {
547 wp_send_json_error($status->get_error_message(), 411);
548 } else {
549 wp_send_json_success($status, 200);
550 }
551 } else {
552 wp_send_json_error(
553 __(
554 'Token expired',
555 'bit-form'
556 ),
557 401
558 );
559 }
560 }
561
562 public function saveCss()
563 {
564 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
565 $inputJSON = file_get_contents('php://input');
566 $input = json_decode($inputJSON);
567 if (isset($input->atomicCssText)) {
568 $status = FrontEndScriptGenerator::saveCssFile("{$input->form_id}", $input->atomicCssText);
569 }
570 if (isset($input->atomicCssWithFormIdText)) {
571 $status = FrontEndScriptGenerator::saveCssFile("{$input->form_id}-formid", $input->atomicCssWithFormIdText);
572 }
573 if (isset($input->atomicClassMap) || isset($input->atomicClassMap)) {
574 $formModel = new FormModel();
575 $atomicClsMap = [
576 'atomic_class_map' => isset($input->atomicClassMap) ? $input->atomicClassMap : (object) [],
577 'atomic_class_map_with_form_id' => isset($input->atomicClassMapWithFormId) ? $input->atomicClassMapWithFormId : (object) [],
578 ];
579 $updateData['atomic_class_map'] = wp_json_encode($atomicClsMap);
580 $formModel->update(
581 $updateData,
582 [
583 'id' => $input->form_id,
584 ]
585 );
586 }
587 if (is_wp_error($status)) {
588 wp_send_json_error($status->get_error_message(), 411);
589 } else {
590 wp_send_json_success($status, 200);
591 }
592 } else {
593 wp_send_json_error(
594 __(
595 'Token expired',
596 'bit-form'
597 ),
598 401
599 );
600 }
601 }
602
603 public function createNewForm()
604 {
605 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
606 $inputJSON = file_get_contents('php://input');
607 $input = json_decode($inputJSON);
608 // wp_send_json_success($input, 200);
609 $formHandler = FormHandler::getInstance();
610 $status = $formHandler->admin->createNewForm($_REQUEST, $input);
611 if (isset($input->customCodes)) {
612 FrontEndScriptGenerator::customCodeFile($input->form_id, $input->customCodes);
613 }
614 if (is_wp_error($status)) {
615 wp_send_json_error($status->get_error_message(), 411);
616 } else {
617 wp_send_json_success($status, 200);
618 }
619 } else {
620 wp_send_json_error(
621 __(
622 'Token expired',
623 'bit-form'
624 ),
625 401
626 );
627 }
628 }
629
630 public function updateEntryStatus()
631 {
632 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
633 $inputJSON = file_get_contents('php://input');
634 $input = json_decode($inputJSON);
635 $formId = sanitize_text_field($input->formId);
636 $entryId = sanitize_text_field($input->entryId);
637 $formEntryModel = new FormEntryModel();
638 $updatedTime = current_time('mysql');
639 $status = $formEntryModel->update(
640 [
641 'status' => 0,
642 'updated_at' => $updatedTime,
643 ],
644 [
645 'form_id' => $formId,
646 'id' => $entryId,
647 ]
648 );
649 if (is_wp_error($status)) {
650 wp_send_json_error($status->get_error_message(), 411);
651 } else {
652 wp_send_json_success(['update_at_time' => $updatedTime], 200);
653 }
654 } else {
655 wp_send_json_error(
656 __(
657 'Token expired',
658 'bit-form'
659 ),
660 401
661 );
662 }
663 }
664
665 public function changeFormStatus()
666 {
667 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
668 $inputJSON = file_get_contents('php://input');
669 $input = json_decode($inputJSON);
670 $formHandler = FormHandler::getInstance();
671 $status = $formHandler->admin->changeFormStatus($_REQUEST, $input);
672 if (is_wp_error($status)) {
673 wp_send_json_error($status->get_error_message(), 411);
674 } else {
675 wp_send_json_success($status, 200);
676 }
677 } else {
678 wp_send_json_error(
679 __(
680 'Token expired',
681 'bit-form'
682 ),
683 401
684 );
685 }
686 }
687
688 public function changeBulkFormStatus()
689 {
690 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
691 $inputJSON = file_get_contents('php://input');
692 $input = json_decode($inputJSON);
693 $formHandler = FormHandler::getInstance();
694 $status = $formHandler->admin->changeBulkFormStatus($_REQUEST, $input);
695 if (is_wp_error($status)) {
696 wp_send_json_error($status->get_error_message(), 411);
697 } else {
698 wp_send_json_success($status, 200);
699 }
700 } else {
701 wp_send_json_error(
702 __(
703 'Token expired',
704 'bit-form'
705 ),
706 401
707 );
708 }
709 }
710
711 public function getAForm()
712 {
713 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
714 $inputJSON = file_get_contents('php://input');
715 $input = json_decode($inputJSON);
716 $formHandler = FormHandler::getInstance();
717 $status = $formHandler->admin->getAForm($_REQUEST, $input);
718 if (is_wp_error($status)) {
719 wp_send_json_error($status->get_error_message(), 411);
720 } else {
721 wp_send_json_success($status, 200);
722 }
723 } else {
724 wp_send_json_error(
725 __(
726 'Token expired',
727 'bit-form'
728 ),
729 401
730 );
731 }
732 }
733
734 public function duplicateAForm()
735 {
736 \ignore_user_abort();
737 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
738 $inputJSON = file_get_contents('php://input');
739 $input = json_decode($inputJSON);
740 $formHandler = FormHandler::getInstance();
741 $status = $formHandler->admin->duplicateAForm($_REQUEST, $input);
742 if (is_wp_error($status)) {
743 wp_send_json_error($status->get_error_message(), 411);
744 } else {
745 wp_send_json_success($status, 200);
746 }
747 } else {
748 wp_send_json_error(
749 __(
750 'Token expired',
751 'bit-form'
752 ),
753 401
754 );
755 }
756 }
757
758 public function importAForm()
759 {
760 \ignore_user_abort();
761 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
762 $inputJSON = file_get_contents('php://input');
763 $input = json_decode($inputJSON);
764 $formHandler = FormHandler::getInstance();
765 $status = $formHandler->admin->importAForm($input);
766 if (is_wp_error($status)) {
767 wp_send_json_error($status->get_error_message(), 411);
768 } else {
769 wp_send_json_success($status, 200);
770 }
771 } else {
772 wp_send_json_error(
773 __(
774 'Token expired',
775 'bit-form'
776 ),
777 401
778 );
779 }
780 }
781
782 // public function exportAForm() {
783 // if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
784 // $formHandler = FormHandler::getInstance();
785 // $status = $formHandler->admin->exportAForm($_REQUEST);
786 // if (is_wp_error($status)) {
787 // wp_send_json_error($status->get_error_message(), 411);
788 // }
789 // } else {
790 // wp_send_json_error(
791 // __(
792 // 'Token expired',
793 // 'bit-form'
794 // ),
795 // 401
796 // );
797 // }
798 // }
799 public function exportAForm()
800 {
801 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
802 $inputJSON = file_get_contents('php://input');
803 $input = json_decode($inputJSON);
804 $formHandler = FormHandler::getInstance();
805 $status = $formHandler->admin->exportAForm($_REQUEST, $input);
806 if (is_wp_error($status)) {
807 wp_send_json_error($status->get_error_message(), 411);
808 } else {
809 wp_send_json_success($status);
810 }
811 } else {
812 wp_send_json_error(
813 __(
814 'Token expired',
815 'bit-form'
816 ),
817 401
818 );
819 }
820 }
821
822 public function deleteAForm()
823 {
824 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
825 $inputJSON = file_get_contents('php://input');
826 $input = json_decode($inputJSON);
827 $formHandler = FormHandler::getInstance();
828 $status = $formHandler->admin->deleteAForm($_REQUEST, $input);
829 if (is_wp_error($status)) {
830 wp_send_json_error($status->get_error_message(), 411);
831 } else {
832 wp_send_json_success($status, 200);
833 }
834 } else {
835 wp_send_json_error(
836 __(
837 'Token expired',
838 'bit-form'
839 ),
840 401
841 );
842 }
843 }
844
845 public function deleteBlukForm()
846 {
847 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
848 $inputJSON = file_get_contents('php://input');
849 $input = json_decode($inputJSON);
850 $formHandler = FormHandler::getInstance();
851 $status = $formHandler->admin->deleteBlukForm($_REQUEST, $input);
852 if (is_wp_error($status)) {
853 wp_send_json_error($status->get_error_message(), 411);
854 } else {
855 wp_send_json_success($status, 200);
856 }
857 } else {
858 wp_send_json_error(
859 __(
860 'Token expired',
861 'bit-form'
862 ),
863 401
864 );
865 }
866 }
867
868 public function deleteBlukFormEntries()
869 {
870 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
871 $inputJSON = file_get_contents('php://input');
872 $input = json_decode($inputJSON);
873 $formHandler = FormHandler::getInstance();
874 $status = $formHandler->admin->deleteBlukFormEntries($_REQUEST, $input);
875 if (is_wp_error($status)) {
876 wp_send_json_error($status->get_error_message(), 411);
877 } else {
878 wp_send_json_success($status, 200);
879 }
880 } else {
881 wp_send_json_error(
882 __(
883 'Token expired',
884 'bit-form'
885 ),
886 401
887 );
888 }
889 }
890
891 public function duplicateFormEntry()
892 {
893 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
894 $inputJSON = file_get_contents('php://input');
895 $input = json_decode($inputJSON);
896 $formHandler = FormHandler::getInstance();
897 $status = $formHandler->admin->duplicateFormEntry($_REQUEST, $input);
898 if (is_wp_error($status)) {
899 wp_send_json_error($status->get_error_message(), 411);
900 } else {
901 wp_send_json_success($status, 200);
902 }
903 } else {
904 wp_send_json_error(
905 __(
906 'Token expired',
907 'bit-form'
908 ),
909 401
910 );
911 }
912 }
913
914 public function editFormEntry()
915 {
916 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
917 $inputJSON = file_get_contents('php://input');
918 $input = json_decode($inputJSON);
919 $formHandler = FormHandler::getInstance();
920 $status = $formHandler->admin->editFormEntry($_REQUEST, $input);
921 if (is_wp_error($status)) {
922 wp_send_json_error($status->get_error_message(), 411);
923 } else {
924 wp_send_json_success($status, 200);
925 }
926 } else {
927 wp_send_json_error(
928 __(
929 'Token expired',
930 'bit-form'
931 ),
932 401
933 );
934 }
935 }
936
937 public function getLogHistory()
938 {
939 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
940 $inputJSON = file_get_contents('php://input');
941 $input = json_decode($inputJSON);
942 $formHandler = FormHandler::getInstance();
943 $status = $formHandler->admin->getLogHistory($_REQUEST, $input);
944 if (is_wp_error($status)) {
945 wp_send_json_error($status->get_error_message(), 411);
946 } else {
947 wp_send_json_success($status, 200);
948 }
949 } else {
950 wp_send_json_error(
951 __(
952 'Token expired',
953 'bit-form'
954 ),
955 401
956 );
957 }
958 }
959
960 public function updateFormEntry()
961 {
962 \ignore_user_abort();
963 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
964 $formHandler = FormHandler::getInstance();
965 $status = $formHandler->admin->updateFormEntry($_REQUEST, $_POST);
966
967 if (is_wp_error($status)) {
968 wp_send_json_error($status->get_error_message(), 411);
969 } else {
970 $status = IntegrationHandler::maybeSetCronForIntegration($status, 'update');
971 wp_send_json_success($status, 200);
972 }
973 } else {
974 wp_send_json_error(
975 __(
976 'Token expired',
977 'bit-form'
978 ),
979 401
980 );
981 }
982 }
983
984 public function getAllWPPages()
985 {
986 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
987 $inputJSON = file_get_contents('php://input');
988 $input = json_decode($inputJSON);
989 $formHandler = FormHandler::getInstance();
990 $status = $formHandler->admin->getAllWPPages($_REQUEST, $input);
991 if (is_wp_error($status)) {
992 wp_send_json_error($status->get_error_message(), 411);
993 } else {
994 wp_send_json_success($status, 200);
995 }
996 } else {
997 wp_send_json_error(
998 __(
999 'Token expired',
1000 'bit-form'
1001 ),
1002 401
1003 );
1004 }
1005 }
1006
1007 public function deleteSuccessMessage()
1008 {
1009 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1010 $inputJSON = file_get_contents('php://input');
1011 $input = json_decode($inputJSON);
1012 $formHandler = FormHandler::getInstance();
1013 $status = $formHandler->admin->deleteSuccessMessage($_REQUEST, $input);
1014 if (is_wp_error($status)) {
1015 wp_send_json_error($status->get_error_message(), 411);
1016 } else {
1017 wp_send_json_success($status, 200);
1018 }
1019 } else {
1020 wp_send_json_error(
1021 __(
1022 'Token expired',
1023 'bit-form'
1024 ),
1025 401
1026 );
1027 }
1028 }
1029
1030 public function deleteAIntegration()
1031 {
1032 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1033 $inputJSON = file_get_contents('php://input');
1034 $input = json_decode($inputJSON);
1035 $formHandler = FormHandler::getInstance();
1036 $status = $formHandler->admin->deleteAIntegration($_REQUEST, $input);
1037 if (is_wp_error($status)) {
1038 wp_send_json_error($status->get_error_message(), 411);
1039 } else {
1040 wp_send_json_success($status, 200);
1041 }
1042 } else {
1043 wp_send_json_error(
1044 __(
1045 'Token expired',
1046 'bit-form'
1047 ),
1048 401
1049 );
1050 }
1051 }
1052
1053 public function deleteAWorkflow()
1054 {
1055 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1056 $inputJSON = file_get_contents('php://input');
1057 $input = json_decode($inputJSON);
1058 $formHandler = FormHandler::getInstance();
1059 $status = $formHandler->admin->deleteAWorkflow($_REQUEST, $input);
1060 if (is_wp_error($status)) {
1061 wp_send_json_error($status->get_error_message(), 411);
1062 } else {
1063 wp_send_json_success($status, 200);
1064 }
1065 } else {
1066 wp_send_json_error(
1067 __(
1068 'Token expired',
1069 'bit-form'
1070 ),
1071 401
1072 );
1073 }
1074 }
1075
1076 public function deleteAMailTemplate()
1077 {
1078 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1079 $inputJSON = file_get_contents('php://input');
1080 $input = json_decode($inputJSON);
1081 $formHandler = FormHandler::getInstance();
1082 $status = $formHandler->admin->deleteAMailTemplate($_REQUEST, $input);
1083 if (is_wp_error($status)) {
1084 wp_send_json_error($status->get_error_message(), 411);
1085 } else {
1086 wp_send_json_success($status, 200);
1087 }
1088 } else {
1089 wp_send_json_error(
1090 __(
1091 'Token expired',
1092 'bit-form'
1093 ),
1094 401
1095 );
1096 }
1097 }
1098
1099 public function duplicateAMailTemplate()
1100 {
1101 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1102 $inputJSON = file_get_contents('php://input');
1103 $input = json_decode($inputJSON);
1104 $formHandler = FormHandler::getInstance();
1105 $status = $formHandler->admin->duplicateAMailTemplate($_REQUEST, $input);
1106 if (is_wp_error($status)) {
1107 wp_send_json_error($status->get_error_message(), 411);
1108 } else {
1109 wp_send_json_success($status, 200);
1110 }
1111 } else {
1112 wp_send_json_error(
1113 __(
1114 'Token expired',
1115 'bit-form'
1116 ),
1117 401
1118 );
1119 }
1120 }
1121
1122 public function setAllFormsReport()
1123 {
1124 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1125 $inputJSON = file_get_contents('php://input');
1126 $input = json_decode($inputJSON);
1127 $formHandler = FormHandler::getInstance();
1128 $status = $formHandler->admin->setAllFormsReport($_REQUEST, $input);
1129 if (is_wp_error($status)) {
1130 wp_send_json_error($status->get_error_message(), 411);
1131 } else {
1132 wp_send_json_success($status, 200);
1133 }
1134 } else {
1135 wp_send_json_error(
1136 __(
1137 'Token expired',
1138 'bit-form'
1139 ),
1140 401
1141 );
1142 }
1143 }
1144
1145 public function savegReCaptcha()
1146 {
1147 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1148 $inputJSON = file_get_contents('php://input');
1149 $input = json_decode($inputJSON);
1150 $formHandler = FormHandler::getInstance();
1151 $status = $formHandler->admin->savegReCaptcha($_REQUEST, $input);
1152 if (is_wp_error($status)) {
1153 wp_send_json_error($status->get_error_message(), 411);
1154 } else {
1155 wp_send_json_success($status, 200);
1156 }
1157 } else {
1158 wp_send_json_error(
1159 __(
1160 'Token expired',
1161 'bit-form'
1162 ),
1163 401
1164 );
1165 }
1166 }
1167
1168 public function saveApiKey()
1169 {
1170 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1171 $inputJSON = file_get_contents('php://input');
1172 $input = json_decode($inputJSON);
1173 if (empty($input->api_key)) {
1174 $api_key = get_option('bitform_secret_api_key');
1175 } elseif (!empty($input->api_key)) {
1176 update_option('bitform_secret_api_key', $input->api_key);
1177 $api_key = $input->api_key;
1178 }
1179 if (!$api_key) {
1180 $api_key = hash('sha1', base64_encode(12345));
1181 update_option('bitform_secret_api_key', $api_key);
1182 }
1183 wp_send_json_success($api_key, 200);
1184 } else {
1185 wp_send_json_error(
1186 __(
1187 'Token expired',
1188 'bit-form'
1189 ),
1190 401
1191 );
1192 }
1193 }
1194
1195 public function iconUpload()
1196 {
1197 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1198 $inputJSON = file_get_contents('php://input');
1199 $input = json_decode($inputJSON);
1200 $uploadDirInfo = wp_upload_dir();
1201 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1202 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons';
1203 if (!is_dir($icnDir)) {
1204 mkdir($icnDir);
1205 }
1206
1207 $imageUrlData = file_get_contents($input->src);
1208
1209 $filename = sanitize_file_name($input->id . '-' . basename($input->src));
1210 $uploaded = file_put_contents($icnDir . '/' . $filename, $imageUrlData);
1211
1212 if ($uploaded) {
1213 $uploadedFile = BITFORMS_UPLOAD_BASE_URL . '/' . 'icons' . '/' . $filename;
1214 wp_send_json_success($uploadedFile, 200);
1215 }
1216 } else {
1217 wp_send_json_error(
1218 __(
1219 'Token expired',
1220 'bit-form'
1221 ),
1222 401
1223 );
1224 }
1225 }
1226
1227 private function getFiles()
1228 {
1229 $uploadDirInfo = wp_upload_dir();
1230 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1231 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons';
1232 $files = [];
1233 if (file_exists($icnDir)) {
1234 $openDir = opendir($icnDir . DIRECTORY_SEPARATOR);
1235
1236 while (false !== ($fileName = readdir($openDir))) {
1237 $ext = substr($fileName, strrpos($fileName, '.') + 1);
1238 if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'svg'])) {
1239 $files[] = $fileName;
1240 }
1241 }
1242
1243 closedir($openDir);
1244 }
1245 return $files;
1246 }
1247
1248 public function getDownlodedIcons()
1249 {
1250 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1251 $files = $this->getFiles();
1252 wp_send_json_success($files, 200);
1253 } else {
1254 wp_send_json_error(
1255 __(
1256 'Token expired',
1257 'bit-form'
1258 ),
1259 401
1260 );
1261 }
1262 }
1263
1264 public function iconRemove()
1265 {
1266 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1267 $inputJSON = file_get_contents('php://input');
1268 $input = json_decode($inputJSON);
1269
1270 $uploadDirInfo = wp_upload_dir();
1271
1272 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1273 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR;
1274 if (file_exists($icnDir . $input->file)) {
1275 unlink($icnDir . $input->file);
1276 wp_send_json_success($this->getFiles(), 200);
1277 }
1278 } else {
1279 wp_send_json_error(
1280 __(
1281 'Token expired',
1282 'bit-form'
1283 ),
1284 401
1285 );
1286 }
1287 }
1288
1289 public function addCustomCode()
1290 {
1291 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1292 $inputJSON = file_get_contents('php://input');
1293 $input = json_decode($inputJSON);
1294 FrontEndScriptGenerator::customCodeFile($input->form_id, $input->customCodes);
1295 $status = ['message' => 'File Update Successfully..'];
1296 if (is_wp_error($status)) {
1297 wp_send_json_error($status->get_error_message(), 411);
1298 } else {
1299 wp_send_json_success($status, 200);
1300 }
1301 } else {
1302 wp_send_json_error(
1303 __(
1304 'Token expired',
1305 'bit-form'
1306 ),
1307 401
1308 );
1309 }
1310 }
1311
1312 public function getCustomCode()
1313 {
1314 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1315 $inputJSON = file_get_contents('php://input');
1316 $input = json_decode($inputJSON);
1317 $status = FrontEndScriptGenerator::getCustomCodes($input->form_id);
1318 if (is_wp_error($status)) {
1319 wp_send_json_error($status->get_error_message(), 411);
1320 } else {
1321 wp_send_json_success($status, 200);
1322 }
1323 } else {
1324 wp_send_json_error(
1325 __(
1326 'Token expired',
1327 'bit-form'
1328 ),
1329 401
1330 );
1331 }
1332 }
1333
1334 public function getGenerelSettings()
1335 {
1336 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1337 $data = get_option('bitform_app_config');
1338
1339 if (is_wp_error($data)) {
1340 wp_send_json_error($data->get_error_message(), 411);
1341 } else {
1342 if (empty($data)) {
1343 $data = (object)[];
1344 }
1345 wp_send_json_success($data, 200);
1346 }
1347 } else {
1348 wp_send_json_error(
1349 __(
1350 'Token expired'
1351 ),
1352 401
1353 );
1354 }
1355 }
1356
1357 public function saveGenerelSettings()
1358 {
1359 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1360 $inputJSON = file_get_contents('php://input');
1361 $input = json_decode($inputJSON);
1362 $status = update_option('bitform_app_config', $input->config);
1363 if (is_wp_error($status)) {
1364 wp_send_json_error($status->get_error_message(), 411);
1365 } else {
1366 if (Helpers::property_exists_nested($input, 'config->cache_plugin', true)) {
1367 $formHandler = FormHandler::getInstance();
1368 $formHandler->admin->updateGeneratedScriptPageIds();
1369 }
1370 wp_send_json_success(__('Save successfully done'));
1371 }
1372 } else {
1373 wp_send_json_error(
1374 __(
1375 'Token expired'
1376 ),
1377 401
1378 );
1379 }
1380 }
1381
1382 public function savePaymentSettings()
1383 {
1384 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1385 $inputJSON = file_get_contents('php://input');
1386 $input = json_decode($inputJSON);
1387 $formHandler = FormHandler::getInstance();
1388 $status = $formHandler->admin->savePaymentSetting($_REQUEST, $input);
1389 if (is_wp_error($status)) {
1390 wp_send_json_error($status->get_error_message(), 411);
1391 } else {
1392 wp_send_json_success($status, 200);
1393 }
1394 } else {
1395 wp_send_json_error(
1396 __(
1397 'Token expired',
1398 'bit-form'
1399 ),
1400 401
1401 );
1402 }
1403 }
1404
1405 public function getPodsField()
1406 {
1407 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1408 $inputJSON = file_get_contents('php://input');
1409 $input = json_decode($inputJSON);
1410 $podsAdminExists = is_plugin_active('pods/init.php');
1411
1412 $podField = [];
1413 if ($podsAdminExists) {
1414 $pods = pods($input->pod_type);
1415 $i = 0;
1416 foreach ($pods->fields as $field) {
1417 $i++;
1418 $podField[$i]['key'] = $field['name'];
1419 $podField[$i]['name'] = $field['label'];
1420 $podField[$i]['required'] = 1 === $field['options']['required'] ? true : false;
1421 }
1422 }
1423
1424 if (is_wp_error($podField)) {
1425 wp_send_json_error($podField, 411);
1426 } else {
1427 wp_send_json_success($podField, 200);
1428 }
1429 } else {
1430 wp_send_json_error(
1431 __(
1432 'Token expired',
1433 'bit-form'
1434 ),
1435 401
1436 );
1437 }
1438 }
1439
1440 public function getPodsType()
1441 {
1442 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1443 $users = get_users(['fields' => ['ID', 'display_name']]);
1444 $pods = [];
1445 $podsAdminExists = is_plugin_active('pods/init.php');
1446 if ($podsAdminExists) {
1447 $allPods = pods_api()->load_pods();
1448 foreach ($allPods as $key => $pod) {
1449 $pods[$key]['name'] = $pod['name'];
1450 $pods[$key]['label'] = $pod['label'];
1451 }
1452 }
1453 $data = ['users' => $users, 'post_types' => $pods];
1454 wp_send_json_success($data, 200);
1455 } else {
1456 wp_send_json_error(
1457 __(
1458 'Token expired',
1459 'bit-form'
1460 ),
1461 401
1462 );
1463 }
1464 }
1465
1466 public function postTypeByUser()
1467 {
1468 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1469 $users = get_users(
1470 [
1471 'fields' => ['ID', 'display_name', 'user_login', 'user_email', 'user_nicename'],
1472 ]
1473 );
1474
1475 $postTypes = $this->getPostTypes();
1476
1477 $data = ['post_types' => $postTypes, 'users' => $users];
1478 wp_send_json_success($data, 200);
1479 } else {
1480 wp_send_json_error(
1481 __(
1482 'Token expired',
1483 'bitformpro'
1484 ),
1485 401
1486 );
1487 }
1488 }
1489
1490 private function getPostTypes()
1491 {
1492 $all_cpt = get_post_types([
1493 'public' => true,
1494 'exclude_from_search' => false,
1495 '_builtin' => false,
1496 'capability_type' => 'post',
1497
1498 ], 'objects');
1499 $cpt = [];
1500
1501 foreach ($all_cpt as $key => $post_type) {
1502 $cpt[$key]['name'] = $post_type->name;
1503 $cpt[$key]['label'] = $post_type->label;
1504 }
1505 $wp_post_types = get_post_types([
1506 'public' => true,
1507 '_builtin' => true,
1508 ]);
1509
1510 $wp_all_post_types = [];
1511
1512 foreach ($wp_post_types as $key => $post_type) {
1513 if ('attachment' !== $post_type) {
1514 $wp_all_post_types[$key]['name'] = $post_type;
1515 $wp_all_post_types[$key]['label'] = ucwords($post_type);
1516 }
1517 }
1518 return array_merge($wp_all_post_types, $cpt);
1519 }
1520
1521 public function getAcfGroupFields()
1522 {
1523 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1524 $acfFields = [];
1525 $types = ['select', 'checkbox', 'radio'];
1526
1527 $field_groups = get_posts(['post_type' => 'acf-field-group']);
1528
1529 if ($field_groups) {
1530 $groups = acf_get_field_groups();
1531 foreach ($groups as $group) {
1532 foreach (acf_get_fields($group['key']) as $acfField) {
1533 if (in_array($acfField['type'], $types)) {
1534 array_push($acfFields, [
1535 'key' => $acfField['key'],
1536 'name' => $acfField['label'],
1537 'choices' => $acfField['choices'],
1538 'group_title' => $group['title'],
1539 'location' => $group['location'],
1540 ]);
1541 }
1542 }
1543 }
1544 }
1545
1546 wp_send_json_success($acfFields, 200);
1547 } else {
1548 wp_send_json_error(
1549 __(
1550 'Token expired',
1551 'bit-form'
1552 ),
1553 401
1554 );
1555 }
1556 }
1557
1558 public function getCustomField()
1559 {
1560 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1561 $inputJSON = file_get_contents('php://input');
1562 $input = json_decode($inputJSON);
1563 $acfFields = [];
1564 $acfFile = [];
1565
1566 $filterTypes = [
1567 'text',
1568 'textarea',
1569 'password',
1570 'wysiwyg',
1571 'number',
1572 'radio',
1573 'color_picker',
1574 'oembed',
1575 'email',
1576 'url',
1577 'date_picker',
1578 'true_false',
1579 'date_time_picker',
1580 'time_picker',
1581 'message',
1582 'checkbox',
1583 'select',
1584 'post_object',
1585 'user',
1586 ];
1587 $filterFile = ['file', 'image', 'gallery'];
1588
1589 $field_groups = get_posts(['post_type' => 'acf-field-group']);
1590 if ($field_groups) {
1591 $groups = acf_get_field_groups(['post_type' => $input->post_type]);
1592
1593 foreach ($groups as $group) {
1594 foreach (acf_get_fields($group['key']) as $acfField) {
1595 if (in_array($acfField['type'], $filterTypes)) {
1596 array_push($acfFields, [
1597 'key' => $acfField['key'],
1598 'name' => $acfField['label'],
1599 'required' => $acfField['required'],
1600 ]);
1601 } elseif (in_array($acfField['type'], $filterFile)) {
1602 array_push($acfFile, [
1603 'key' => $acfField['key'],
1604 'name' => $acfField['label'],
1605 'required' => $acfField['required'],
1606 ]);
1607 } elseif (in_array($acfField['type'], ['group'])) {
1608 foreach ($acfField['sub_fields'] as $subField) {
1609 if (in_array($subField['type'], $filterTypes)) {
1610 array_push($acfFields, [
1611 'key' => $subField['key'],
1612 'name' => $subField['label'],
1613 'required' => $subField['required'],
1614 ]);
1615 } elseif (in_array($subField['type'], $filterFile)) {
1616 array_push($acfFile, [
1617 'key' => $subField['key'],
1618 'name' => $subField['label'],
1619 'required' => $subField['required'],
1620 ]);
1621 }
1622 }
1623 }
1624 }
1625 }
1626 }
1627 wp_send_json_success(['acfFields' => $acfFields, 'acfFile' => $acfFile], 200);
1628 } else {
1629 wp_send_json_error(
1630 __(
1631 'Token expired',
1632 'bit-form'
1633 ),
1634 401
1635 );
1636 }
1637 }
1638
1639 public function getMetaboxFields()
1640 {
1641 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1642 $inputJSON = file_get_contents('php://input');
1643 $input = json_decode($inputJSON);
1644
1645 $metaboxFields = [];
1646 $metaboxFile = [];
1647
1648 $filterTypes = [
1649 'file_input',
1650 'group',
1651 'tab',
1652 'osm',
1653 'heading',
1654 'key_value',
1655 'map',
1656 'custom_html',
1657 'background',
1658 'fieldset_text',
1659 'taxonomy',
1660 'taxonomy_advanced',
1661 ];
1662
1663 $fileTypes = [
1664 'image',
1665 'image_upload',
1666 'file_advanced',
1667 'file_upload',
1668 'single_image',
1669 'file',
1670 'image_advanced',
1671 'video',
1672 ];
1673
1674 if (function_exists('rwmb_meta')) {
1675 $fields = rwmb_get_object_fields($input->post_type);
1676 foreach ($fields as $index => $field) {
1677 if (!in_array($field['type'], $fileTypes)) {
1678 if (!in_array($field['type'], $filterTypes)) {
1679 $metaboxFields[$index]['name'] = $field['name'];
1680 }
1681
1682 $metaboxFields[$index]['key'] = $field['id'];
1683 $metaboxFields[$index]['required'] = $field['required'];
1684 } else {
1685 $metaboxFile[$index]['name'] = $field['name'];
1686 $metaboxFile[$index]['key'] = $field['id'];
1687 $metaboxFile[$index]['required'] = $field['required'];
1688 }
1689 }
1690 }
1691 wp_send_json_success(
1692 [
1693 'metaboxFields' => array_values($metaboxFields),
1694 'metaboxFile' => array_values($metaboxFile),
1695 ],
1696 200
1697 );
1698 } else {
1699 wp_send_json_error(
1700 __(
1701 'Token expired',
1702 'bitformpro'
1703 ),
1704 401
1705 );
1706 }
1707 }
1708
1709 public function saveConversationalCSS()
1710 {
1711 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1712 $inputJSON = file_get_contents('php://input');
1713 $requestsParams = json_decode($inputJSON);
1714 $formId = $requestsParams->formID;
1715 $css = $requestsParams->css;
1716
1717 $path = 'form-styles';
1718 $fileName = "bitform-conversational-$formId.css";
1719 FrontEndScriptGenerator::customCodeFileSaveOrDelete($css, $path, $fileName);
1720 wp_send_json_success(__('Conversational CSS Saved Successfully!', 'bitform'), 200);
1721 } else {
1722 wp_send_json_error(
1723 __(
1724 'Token expired',
1725 'bitform'
1726 ),
1727 401
1728 );
1729 }
1730 }
1731 }
1732