PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.0
3.3.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 All 138 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.0, at includes/Admin/AdminAjax.php

1,733 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 = $input->id . '-' . basename($input->src);
1210
1211 $uploaded = file_put_contents($icnDir . '/' . $filename, $imageUrlData);
1212
1213 if ($uploaded) {
1214 $uploadedFile = BITFORMS_UPLOAD_BASE_URL . '/' . 'icons' . '/' . $filename;
1215 wp_send_json_success($uploadedFile, 200);
1216 }
1217 } else {
1218 wp_send_json_error(
1219 __(
1220 'Token expired',
1221 'bit-form'
1222 ),
1223 401
1224 );
1225 }
1226 }
1227
1228 private function getFiles()
1229 {
1230 $uploadDirInfo = wp_upload_dir();
1231 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1232 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons';
1233 $files = [];
1234 if (file_exists($icnDir)) {
1235 $openDir = opendir($icnDir . DIRECTORY_SEPARATOR);
1236
1237 while (false !== ($fileName = readdir($openDir))) {
1238 $ext = substr($fileName, strrpos($fileName, '.') + 1);
1239 if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'svg'])) {
1240 $files[] = $fileName;
1241 }
1242 }
1243
1244 closedir($openDir);
1245 }
1246 return $files;
1247 }
1248
1249 public function getDownlodedIcons()
1250 {
1251 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1252 $files = $this->getFiles();
1253 wp_send_json_success($files, 200);
1254 } else {
1255 wp_send_json_error(
1256 __(
1257 'Token expired',
1258 'bit-form'
1259 ),
1260 401
1261 );
1262 }
1263 }
1264
1265 public function iconRemove()
1266 {
1267 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1268 $inputJSON = file_get_contents('php://input');
1269 $input = json_decode($inputJSON);
1270
1271 $uploadDirInfo = wp_upload_dir();
1272
1273 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1274 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR;
1275 if (file_exists($icnDir . $input->file)) {
1276 unlink($icnDir . $input->file);
1277 wp_send_json_success($this->getFiles(), 200);
1278 }
1279 } else {
1280 wp_send_json_error(
1281 __(
1282 'Token expired',
1283 'bit-form'
1284 ),
1285 401
1286 );
1287 }
1288 }
1289
1290 public function addCustomCode()
1291 {
1292 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1293 $inputJSON = file_get_contents('php://input');
1294 $input = json_decode($inputJSON);
1295 FrontEndScriptGenerator::customCodeFile($input->form_id, $input->customCodes);
1296 $status = ['message' => 'File Update Successfully..'];
1297 if (is_wp_error($status)) {
1298 wp_send_json_error($status->get_error_message(), 411);
1299 } else {
1300 wp_send_json_success($status, 200);
1301 }
1302 } else {
1303 wp_send_json_error(
1304 __(
1305 'Token expired',
1306 'bit-form'
1307 ),
1308 401
1309 );
1310 }
1311 }
1312
1313 public function getCustomCode()
1314 {
1315 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1316 $inputJSON = file_get_contents('php://input');
1317 $input = json_decode($inputJSON);
1318 $status = FrontEndScriptGenerator::getCustomCodes($input->form_id);
1319 if (is_wp_error($status)) {
1320 wp_send_json_error($status->get_error_message(), 411);
1321 } else {
1322 wp_send_json_success($status, 200);
1323 }
1324 } else {
1325 wp_send_json_error(
1326 __(
1327 'Token expired',
1328 'bit-form'
1329 ),
1330 401
1331 );
1332 }
1333 }
1334
1335 public function getGenerelSettings()
1336 {
1337 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1338 $data = get_option('bitform_app_config');
1339
1340 if (is_wp_error($data)) {
1341 wp_send_json_error($data->get_error_message(), 411);
1342 } else {
1343 if (empty($data)) {
1344 $data = (object)[];
1345 }
1346 wp_send_json_success($data, 200);
1347 }
1348 } else {
1349 wp_send_json_error(
1350 __(
1351 'Token expired'
1352 ),
1353 401
1354 );
1355 }
1356 }
1357
1358 public function saveGenerelSettings()
1359 {
1360 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1361 $inputJSON = file_get_contents('php://input');
1362 $input = json_decode($inputJSON);
1363 $status = update_option('bitform_app_config', $input->config);
1364 if (is_wp_error($status)) {
1365 wp_send_json_error($status->get_error_message(), 411);
1366 } else {
1367 if (Helpers::property_exists_nested($input, 'config->cache_plugin', true)) {
1368 $formHandler = FormHandler::getInstance();
1369 $formHandler->admin->updateGeneratedScriptPageIds();
1370 }
1371 wp_send_json_success(__('Save successfully done'));
1372 }
1373 } else {
1374 wp_send_json_error(
1375 __(
1376 'Token expired'
1377 ),
1378 401
1379 );
1380 }
1381 }
1382
1383 public function savePaymentSettings()
1384 {
1385 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1386 $inputJSON = file_get_contents('php://input');
1387 $input = json_decode($inputJSON);
1388 $formHandler = FormHandler::getInstance();
1389 $status = $formHandler->admin->savePaymentSetting($_REQUEST, $input);
1390 if (is_wp_error($status)) {
1391 wp_send_json_error($status->get_error_message(), 411);
1392 } else {
1393 wp_send_json_success($status, 200);
1394 }
1395 } else {
1396 wp_send_json_error(
1397 __(
1398 'Token expired',
1399 'bit-form'
1400 ),
1401 401
1402 );
1403 }
1404 }
1405
1406 public function getPodsField()
1407 {
1408 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1409 $inputJSON = file_get_contents('php://input');
1410 $input = json_decode($inputJSON);
1411 $podsAdminExists = is_plugin_active('pods/init.php');
1412
1413 $podField = [];
1414 if ($podsAdminExists) {
1415 $pods = pods($input->pod_type);
1416 $i = 0;
1417 foreach ($pods->fields as $field) {
1418 $i++;
1419 $podField[$i]['key'] = $field['name'];
1420 $podField[$i]['name'] = $field['label'];
1421 $podField[$i]['required'] = 1 === $field['options']['required'] ? true : false;
1422 }
1423 }
1424
1425 if (is_wp_error($podField)) {
1426 wp_send_json_error($podField, 411);
1427 } else {
1428 wp_send_json_success($podField, 200);
1429 }
1430 } else {
1431 wp_send_json_error(
1432 __(
1433 'Token expired',
1434 'bit-form'
1435 ),
1436 401
1437 );
1438 }
1439 }
1440
1441 public function getPodsType()
1442 {
1443 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1444 $users = get_users(['fields' => ['ID', 'display_name']]);
1445 $pods = [];
1446 $podsAdminExists = is_plugin_active('pods/init.php');
1447 if ($podsAdminExists) {
1448 $allPods = pods_api()->load_pods();
1449 foreach ($allPods as $key => $pod) {
1450 $pods[$key]['name'] = $pod['name'];
1451 $pods[$key]['label'] = $pod['label'];
1452 }
1453 }
1454 $data = ['users' => $users, 'post_types' => $pods];
1455 wp_send_json_success($data, 200);
1456 } else {
1457 wp_send_json_error(
1458 __(
1459 'Token expired',
1460 'bit-form'
1461 ),
1462 401
1463 );
1464 }
1465 }
1466
1467 public function postTypeByUser()
1468 {
1469 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1470 $users = get_users(
1471 [
1472 'fields' => ['ID', 'display_name', 'user_login', 'user_email', 'user_nicename'],
1473 ]
1474 );
1475
1476 $postTypes = $this->getPostTypes();
1477
1478 $data = ['post_types' => $postTypes, 'users' => $users];
1479 wp_send_json_success($data, 200);
1480 } else {
1481 wp_send_json_error(
1482 __(
1483 'Token expired',
1484 'bitformpro'
1485 ),
1486 401
1487 );
1488 }
1489 }
1490
1491 private function getPostTypes()
1492 {
1493 $all_cpt = get_post_types([
1494 'public' => true,
1495 'exclude_from_search' => false,
1496 '_builtin' => false,
1497 'capability_type' => 'post',
1498
1499 ], 'objects');
1500 $cpt = [];
1501
1502 foreach ($all_cpt as $key => $post_type) {
1503 $cpt[$key]['name'] = $post_type->name;
1504 $cpt[$key]['label'] = $post_type->label;
1505 }
1506 $wp_post_types = get_post_types([
1507 'public' => true,
1508 '_builtin' => true,
1509 ]);
1510
1511 $wp_all_post_types = [];
1512
1513 foreach ($wp_post_types as $key => $post_type) {
1514 if ('attachment' !== $post_type) {
1515 $wp_all_post_types[$key]['name'] = $post_type;
1516 $wp_all_post_types[$key]['label'] = ucwords($post_type);
1517 }
1518 }
1519 return array_merge($wp_all_post_types, $cpt);
1520 }
1521
1522 public function getAcfGroupFields()
1523 {
1524 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1525 $acfFields = [];
1526 $types = ['select', 'checkbox', 'radio'];
1527
1528 $field_groups = get_posts(['post_type' => 'acf-field-group']);
1529
1530 if ($field_groups) {
1531 $groups = acf_get_field_groups();
1532 foreach ($groups as $group) {
1533 foreach (acf_get_fields($group['key']) as $acfField) {
1534 if (in_array($acfField['type'], $types)) {
1535 array_push($acfFields, [
1536 'key' => $acfField['key'],
1537 'name' => $acfField['label'],
1538 'choices' => $acfField['choices'],
1539 'group_title' => $group['title'],
1540 'location' => $group['location'],
1541 ]);
1542 }
1543 }
1544 }
1545 }
1546
1547 wp_send_json_success($acfFields, 200);
1548 } else {
1549 wp_send_json_error(
1550 __(
1551 'Token expired',
1552 'bit-form'
1553 ),
1554 401
1555 );
1556 }
1557 }
1558
1559 public function getCustomField()
1560 {
1561 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1562 $inputJSON = file_get_contents('php://input');
1563 $input = json_decode($inputJSON);
1564 $acfFields = [];
1565 $acfFile = [];
1566
1567 $filterTypes = [
1568 'text',
1569 'textarea',
1570 'password',
1571 'wysiwyg',
1572 'number',
1573 'radio',
1574 'color_picker',
1575 'oembed',
1576 'email',
1577 'url',
1578 'date_picker',
1579 'true_false',
1580 'date_time_picker',
1581 'time_picker',
1582 'message',
1583 'checkbox',
1584 'select',
1585 'post_object',
1586 'user',
1587 ];
1588 $filterFile = ['file', 'image', 'gallery'];
1589
1590 $field_groups = get_posts(['post_type' => 'acf-field-group']);
1591 if ($field_groups) {
1592 $groups = acf_get_field_groups(['post_type' => $input->post_type]);
1593
1594 foreach ($groups as $group) {
1595 foreach (acf_get_fields($group['key']) as $acfField) {
1596 if (in_array($acfField['type'], $filterTypes)) {
1597 array_push($acfFields, [
1598 'key' => $acfField['key'],
1599 'name' => $acfField['label'],
1600 'required' => $acfField['required'],
1601 ]);
1602 } elseif (in_array($acfField['type'], $filterFile)) {
1603 array_push($acfFile, [
1604 'key' => $acfField['key'],
1605 'name' => $acfField['label'],
1606 'required' => $acfField['required'],
1607 ]);
1608 } elseif (in_array($acfField['type'], ['group'])) {
1609 foreach ($acfField['sub_fields'] as $subField) {
1610 if (in_array($subField['type'], $filterTypes)) {
1611 array_push($acfFields, [
1612 'key' => $subField['key'],
1613 'name' => $subField['label'],
1614 'required' => $subField['required'],
1615 ]);
1616 } elseif (in_array($subField['type'], $filterFile)) {
1617 array_push($acfFile, [
1618 'key' => $subField['key'],
1619 'name' => $subField['label'],
1620 'required' => $subField['required'],
1621 ]);
1622 }
1623 }
1624 }
1625 }
1626 }
1627 }
1628 wp_send_json_success(['acfFields' => $acfFields, 'acfFile' => $acfFile], 200);
1629 } else {
1630 wp_send_json_error(
1631 __(
1632 'Token expired',
1633 'bit-form'
1634 ),
1635 401
1636 );
1637 }
1638 }
1639
1640 public function getMetaboxFields()
1641 {
1642 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1643 $inputJSON = file_get_contents('php://input');
1644 $input = json_decode($inputJSON);
1645
1646 $metaboxFields = [];
1647 $metaboxFile = [];
1648
1649 $filterTypes = [
1650 'file_input',
1651 'group',
1652 'tab',
1653 'osm',
1654 'heading',
1655 'key_value',
1656 'map',
1657 'custom_html',
1658 'background',
1659 'fieldset_text',
1660 'taxonomy',
1661 'taxonomy_advanced',
1662 ];
1663
1664 $fileTypes = [
1665 'image',
1666 'image_upload',
1667 'file_advanced',
1668 'file_upload',
1669 'single_image',
1670 'file',
1671 'image_advanced',
1672 'video',
1673 ];
1674
1675 if (function_exists('rwmb_meta')) {
1676 $fields = rwmb_get_object_fields($input->post_type);
1677 foreach ($fields as $index => $field) {
1678 if (!in_array($field['type'], $fileTypes)) {
1679 if (!in_array($field['type'], $filterTypes)) {
1680 $metaboxFields[$index]['name'] = $field['name'];
1681 }
1682
1683 $metaboxFields[$index]['key'] = $field['id'];
1684 $metaboxFields[$index]['required'] = $field['required'];
1685 } else {
1686 $metaboxFile[$index]['name'] = $field['name'];
1687 $metaboxFile[$index]['key'] = $field['id'];
1688 $metaboxFile[$index]['required'] = $field['required'];
1689 }
1690 }
1691 }
1692 wp_send_json_success(
1693 [
1694 'metaboxFields' => array_values($metaboxFields),
1695 'metaboxFile' => array_values($metaboxFile),
1696 ],
1697 200
1698 );
1699 } else {
1700 wp_send_json_error(
1701 __(
1702 'Token expired',
1703 'bitformpro'
1704 ),
1705 401
1706 );
1707 }
1708 }
1709
1710 public function saveConversationalCSS()
1711 {
1712 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1713 $inputJSON = file_get_contents('php://input');
1714 $requestsParams = json_decode($inputJSON);
1715 $formId = $requestsParams->formID;
1716 $css = $requestsParams->css;
1717
1718 $path = 'form-styles';
1719 $fileName = "bitform-conversational-$formId.css";
1720 FrontEndScriptGenerator::customCodeFileSaveOrDelete($css, $path, $fileName);
1721 wp_send_json_success(__('Conversational CSS Saved Successfully!', 'bitform'), 200);
1722 } else {
1723 wp_send_json_error(
1724 __(
1725 'Token expired',
1726 'bitform'
1727 ),
1728 401
1729 );
1730 }
1731 }
1732 }
1733