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

1,287 lines 40.2 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
17 class AdminAjax {
18 public function register() {
19 add_action('wp_ajax_bitforms_integrations', [$this, 'integrations']);
20 add_action('wp_ajax_integration', [$this, 'integration']);
21 add_action('wp_ajax_bitforms_update_form', [$this, 'updateForm']);
22 add_action('wp_ajax_bitforms_templates', [$this, 'templates']);
23 add_action('wp_ajax_bitforms_create_new_form', [$this, 'createNewForm']);
24 add_action('wp_ajax_bitforms_save_css', [$this, 'saveCss']);
25 add_action('wp_ajax_bitforms_get_template', [$this, 'getTemplate']);
26 add_action('wp_ajax_bitforms_change_status', [$this, 'changeFormStatus']);
27 add_action('wp_ajax_bitforms_bulk_status_change', [$this, 'changeBulkFormStatus']);
28 add_action('wp_ajax_bitforms_get_a_form', [$this, 'getAForm']);
29 add_action('wp_ajax_bitforms_bulk_delete_form', [$this, 'deleteBlukForm']);
30 add_action('wp_ajax_bitforms_bulk_delete_form_entries', [$this, 'deleteBlukFormEntries']);
31 add_action('wp_ajax_bitforms_delete_aform', [$this, 'deleteAForm']);
32 add_action('wp_ajax_bitforms_duplicate_aform', [$this, 'duplicateAForm']);
33 add_action('wp_ajax_bitforms_export_aform', [$this, 'exportAForm']);
34 add_action('wp_ajax_bitforms_import_aform', [$this, 'importAForm']);
35 add_action('wp_ajax_bitforms_get_form_entries', [$this, 'getFormEntry']);
36 add_action('wp_ajax_bitforms_duplicate_form_entries', [$this, 'duplicateFormEntry']);
37 add_action('wp_ajax_bitforms_edit_form_entry', [$this, 'editFormEntry']);
38 add_action('wp_ajax_bitforms_update_form_entry', [$this, 'updateFormEntry']);
39 add_action('wp_ajax_bitforms_get_all_form', [$this, 'getAllForms']);
40 add_action('wp_ajax_bitforms_get_all_wp_pages', [$this, 'getAllWPPages']);
41 add_action('wp_ajax_bitforms_delete_success_messsage', [$this, 'deleteSuccessMessage']);
42 add_action('wp_ajax_bitforms_delete_integration', [$this, 'deleteAIntegration']);
43 add_action('wp_ajax_bitforms_delete_workflow', [$this, 'deleteAWorkflow']);
44 add_action('wp_ajax_bitforms_delete_mailtemplate', [$this, 'deleteAMailTemplate']);
45 add_action('wp_ajax_bitforms_duplicate_mailtemplate', [$this, 'duplicateAMailTemplate']);
46 add_action('wp_ajax_bitforms_save_allForm_report_prefs', [$this, 'setAllFormsReport']);
47 add_action('wp_ajax_bitforms_save_grecaptcha', [$this, 'savegReCaptcha']);
48 add_action('wp_ajax_bitforms_form_log_history', [$this, 'getLogHistory']);
49 add_action('wp_ajax_bitforms_import_file_data', [$this, 'importFileData']);
50 add_action('wp_ajax_bitforms_filter_export_data', [$this, 'filterExportEntry']);
51 add_action('wp_ajax_bitforms_api_key', [$this, 'saveApiKey']);
52 add_action('wp_ajax_bitforms_form_helpers_state', [$this, 'builerHelperState']);
53 add_action('wp_ajax_bitforms_icn_save_setting', [$this, 'iconUpload']);
54 add_action('wp_ajax_bitforms_get_download_icn', [$this, 'getDownlodedIcons']);
55 add_action('wp_ajax_bitforms_icon_remove', [$this, 'iconRemove']);
56 add_action('wp_ajax_bitforms_add_custom_code', [$this, 'addCustomCode']);
57 add_action('wp_ajax_bitforms_get_custom_code', [$this, 'getCustomCode']);
58 add_action('wp_ajax_bitforms_entry_status_update', [$this, 'updateEntryStatus']);
59 add_action('wp_ajax_bitforms_get_generel_settings', [$this, 'getGenerelSettings']);
60 add_action('wp_ajax_bitforms_save_generel_settings', [$this, 'saveGenerelSettings']);
61 add_action('wp_ajax_bitforms_get_form_entry_count', [$this, 'getFormEntryLabelAndCount']);
62 add_action('wp_ajax_bitforms_save_payment_setting', [$this, 'savePaymentSettings']);
63
64 // form migrate code
65 add_action('wp_ajax_bitforms_get_migrated_form_contents', [$this, 'migrateFormContents']);
66 add_action('wp_ajax_bitforms_migrate_to_v2_complete', [$this, 'migrationComplete']);
67 add_action('wp_ajax_bitforms_migrate_back_to_v1', [$this, 'migrationBackToV1']);
68
69 // PRO TO FREE (SMTP)
70 add_action('wp_ajax_bitforms_get_mail_config', [$this, 'getEmailConfig']);
71 add_action('wp_ajax_bitforms_mail_config', [$this, 'saveEmailConfig']);
72 add_action('wp_ajax_bitforms_test_email', [$this, 'testEmail']);
73 }
74
75 /**
76 * Undocumented function
77 *
78 * @return void
79 */
80 public function integrations() {
81 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
82 $testIntegration = new Integrations();
83 $allIntegrations = $testIntegration->getAllintegrations();
84 if ($allIntegrations) {
85 wp_send_json_success($allIntegrations, 200);
86 } else {
87 wp_send_json_error(
88 __('No Integration Found', 'bit-form'),
89 404
90 );
91 }
92 } else {
93 wp_send_json_error(
94 __(
95 'Token expired',
96 'bit-form'
97 ),
98 401
99 );
100 }
101 }
102
103 public function templates() {
104 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
105 $templateProvider = new TemplateProvider();
106 $status = $templateProvider->getAllTemplates();
107 if (is_wp_error($status)) {
108 wp_send_json_error($status->get_error_message(), 411);
109 } else {
110 wp_send_json_success($status, 200);
111 }
112 } else {
113 wp_send_json_error(
114 __(
115 'Token expired',
116 'bit-form'
117 ),
118 401
119 );
120 }
121 }
122
123 public function builerHelperState() {
124 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
125 $inputJSON = file_get_contents('php://input');
126 $input = json_decode($inputJSON);
127
128 $formID = $input->formID;
129 $formHandler = FormHandler::getInstance();
130 $results = $formHandler->admin->builerHelperState($formID);
131 if (is_wp_error($results)) {
132 wp_send_json_error($results, 411);
133 } else {
134 wp_send_json_success($results, 200);
135 }
136 } else {
137 wp_send_json_error(
138 __(
139 'Token expired',
140 'bit-form'
141 ),
142 401
143 );
144 }
145 }
146
147 public function getTemplate() {
148 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
149 $inputJSON = file_get_contents('php://input');
150 $input = json_decode($inputJSON);
151 $formHandler = FormHandler::getInstance();
152 $status = $formHandler->admin->getTemplate($_REQUEST, $input);
153 if (is_wp_error($status)) {
154 wp_send_json_error($status->get_error_message(), 411);
155 } else {
156 wp_send_json_success($status, 200);
157 }
158 } else {
159 wp_send_json_error(
160 __(
161 'Token expired',
162 'bit-form'
163 ),
164 401
165 );
166 }
167 }
168
169 public function getAllForms() {
170 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
171 $formHandler = FormHandler::getInstance();
172 $all_forms = $formHandler->admin->getAllForm();
173 if (is_wp_error($all_forms)) {
174 wp_send_json_error($all_forms->get_error_message(), 411);
175 } else {
176 wp_send_json_success($all_forms, 200);
177 }
178 } else {
179 wp_send_json_error(
180 __(
181 'Token expired',
182 'bit-form'
183 ),
184 401
185 );
186 }
187 }
188
189 public function migrateFormContents() {
190 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
191 update_site_option('bitforms_db_version', '2.0');
192 DB::migrate();
193 $migrateFormsHandler = new MigrateForms();
194 $all_forms = $migrateFormsHandler->migrateToV2();
195 wp_send_json_success($all_forms, 200);
196 } else {
197 wp_send_json_error(
198 __(
199 'Token expired',
200 'bit-form'
201 ),
202 401
203 );
204 }
205 }
206
207 private function formatFormContentForUpdate($formContents) {
208 $updatedFormContents = (object) [];
209 $updatedPaths = [
210 'id' => 'id',
211 'form_name' => 'form_name',
212 'layout' => 'form_content->layout',
213 'fields' => 'form_content->fields',
214 'additional' => 'additional',
215 'workFlows' => 'workFlows',
216 'formStyle' => null,
217 'style' => null,
218 'staticStyles' => null,
219 'themeColors' => null,
220 'themeVars' => null,
221 'breakpointSize' => null,
222 'customCodes' => null,
223 'builderSettings' => null,
224 'layoutChanged' => null,
225 'rowHeight' => null,
226 'formSettings' => 'formSettings',
227 ];
228 foreach ($updatedPaths as $key => $value) {
229 if (!is_null($value)) {
230 $value = Helpers::getDataFromNestedPath($formContents, $value);
231 }
232 $updatedFormContents->$key = $value;
233 }
234
235 foreach ($formContents['reports'] as $report) {
236 if ('1' === $report['isDefault']) {
237 $updatedFormContents->currentReport = $report;
238 $updatedFormContents->report_id = $report['id'];
239 }
240 }
241
242 $updatedFormContents = json_decode(wp_json_encode($updatedFormContents));
243
244 $updatedFormContents->formSettings->theme = 'default';
245
246 return $updatedFormContents;
247 }
248
249 public function getEmailConfig() {
250 \ignore_user_abort();
251
252 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
253 unset($_REQUEST['_ajax_nonce'], $_REQUEST['action']);
254 $ipTool = new IpTool();
255 $user_details = $ipTool->getUserDetail();
256 $integrationHandler = new IntegrationHandler(0, $user_details);
257 $user_details = $ipTool->getUserDetail();
258 $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp');
259 wp_send_json_success($formIntegrations, 200);
260 } else {
261 wp_send_json_error(
262 __(
263 'Token expired',
264 'bitformpro'
265 ),
266 401
267 );
268 }
269 }
270
271 public function saveEmailConfig() {
272 \ignore_user_abort();
273 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
274 $ipTool = new IpTool();
275 $status = $_REQUEST['status'];
276 $user_details = $ipTool->getUserDetail();
277 $integrationHandler = new IntegrationHandler(0, $user_details);
278 unset($_REQUEST['_ajax_nonce'], $_REQUEST['action'], $_REQUEST['status']);
279 $integrationDetails = json_encode($_REQUEST);
280 $user_details = $ipTool->getUserDetail();
281 $integrationName = 'smtp';
282 $integrationType = 'smtp';
283 $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp');
284 if (isset($formIntegrations->errors['result_empty'])) {
285 $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'mail', $status);
286 } else {
287 $integrationHandler->updateIntegration($formIntegrations[0]->id, $integrationName, $integrationType, $integrationDetails, 'mail', $status);
288 }
289 wp_send_json_success($formIntegrations, 200);
290 } else {
291 wp_send_json_error(
292 __(
293 'Token expired',
294 'bitformpro'
295 ),
296 401
297 );
298 }
299 }
300
301 public function testEmail() {
302 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
303 $to = wp_unslash($_REQUEST['to']);
304 $subject = wp_unslash($_REQUEST['subject']);
305 $message = wp_unslash($_REQUEST['message']);
306 unset($_REQUEST['_ajax_nonce'], $_REQUEST['action']);
307 if (!empty($to) && !empty($subject) && !empty($message)) {
308 try {
309 (new MailConfig())->sendMail();
310 add_action('wp_mail_failed', function ($error) {
311 $data = [];
312 $data['errors'] = $error->errors['wp_mail_failed'];
313 wp_send_json_error($data, 400);
314 });
315 $result = wp_mail($to, $subject, $message);
316 wp_send_json_success($result, 200);
317 } catch (Exception $e) {
318 wp_send_json_error($e->getMessage(), 400);
319 }
320 } else {
321 wp_send_json_error(
322 __(
323 'Some of the test fields are empty or an invalid email supplied',
324 'bitformpro'
325 ),
326 401
327 );
328 }
329 } else {
330 wp_send_json_error(
331 __(
332 'Token expired',
333 'bitformpro'
334 ),
335 401
336 );
337 }
338 }
339
340 public function migrationComplete() {
341 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
342 delete_transient('bitforms_v1_form_contents');
343 delete_option('bitforms_migrating_to_v2');
344 update_option('bitforms_migrated_to_v2', true);
345 wp_send_json_success(__('Migration Complete', 'bit-form'), 200);
346 } else {
347 wp_send_json_error(
348 __(
349 'Token expired',
350 'bit-form'
351 ),
352 401
353 );
354 }
355 }
356
357 public function migrationBackToV1() {
358 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
359 $migrateFormsHandler = new MigrateForms();
360 $migrateFormsHandler->rollbackToV1();
361 wp_send_json_success(__('Migration Back to V1', 'bit-form'), 200);
362 } else {
363 wp_send_json_error(
364 __(
365 'Token expired',
366 'bit-form'
367 ),
368 401
369 );
370 }
371 }
372
373 public function importDataStore() {
374 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
375 $inputJSON = file_get_contents('php://input');
376 $input = json_decode($inputJSON);
377 echo json_encode($input);
378 die;
379 // $formHandler = FormHandler::getInstance();
380 // $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input);
381 // if (is_wp_error($status)) {
382 // wp_send_json_error($status->get_error_message(), 411);
383 // } else {
384 // wp_send_json_success($status, 200);
385 // }
386 } else {
387 wp_send_json_error(
388 __(
389 'Token expired',
390 'bit-form'
391 ),
392 401
393 );
394 }
395 }
396
397 public function getFormEntryLabelAndCount() {
398 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
399 $inputJSON = file_get_contents('php://input');
400 $input = json_decode($inputJSON);
401 $formHandler = FormHandler::getInstance();
402 $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input);
403 if (is_wp_error($status)) {
404 wp_send_json_error($status->get_error_message(), 411);
405 } else {
406 wp_send_json_success($status, 200);
407 }
408 } else {
409 wp_send_json_error(
410 __(
411 'Token expired',
412 'bit-form'
413 ),
414 401
415 );
416 }
417 }
418
419 public function getFormEntry() {
420 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
421 $inputJSON = file_get_contents('php://input');
422 $input = json_decode($inputJSON);
423 $formHandler = FormHandler::getInstance();
424 $status = $formHandler->admin->getFormEntry($_REQUEST, $input);
425 if (is_wp_error($status)) {
426 wp_send_json_error($status->get_error_message(), 411);
427 } else {
428 wp_send_json_success($status, 200);
429 }
430 } else {
431 wp_send_json_error(__('Token expired', 'bit-form'), 401);
432 }
433 }
434
435 public function filterExportEntry() {
436 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
437 $inputJSON = file_get_contents('php://input');
438 $input = json_decode($inputJSON);
439 $formHandler = FormHandler::getInstance();
440 $status = $formHandler->admin->getExportEntry($input->data);
441 if (is_wp_error($status)) {
442 wp_send_json_error($status->get_error_message(), 411);
443 } else {
444 wp_send_json_success($status, 200);
445 }
446 } else {
447 wp_send_json_error(__('Token expired', 'bit-form'), 401);
448 }
449 }
450
451 /**
452 * Undocumented function
453 *
454 * @return void
455 */
456 public function updateForm() {
457 \ignore_user_abort();
458 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
459 $inputJSON = file_get_contents('php://input');
460 $input = json_decode($inputJSON);
461 $formHandler = FormHandler::getInstance();
462 $status = $formHandler->admin->updateForm($_REQUEST, $input);
463 FrontEndScriptGenerator::customCodeFile($input->id, $input->customCodes);
464 if (is_wp_error($status)) {
465 wp_send_json_error($status->get_error_message(), 411);
466 } else {
467 wp_send_json_success($status, 200);
468 }
469 } else {
470 wp_send_json_error(
471 __(
472 'Token expired',
473 'bit-form'
474 ),
475 401
476 );
477 }
478 }
479
480 public function saveCss() {
481 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
482 $inputJSON = file_get_contents('php://input');
483 $input = json_decode($inputJSON);
484 if (isset($input->atomicCssText)) {
485 $status = FrontEndScriptGenerator::saveCssFile("{$input->form_id}", $input->atomicCssText);
486 }
487 if (isset($input->atomicCssWithFormIdText)) {
488 $status = FrontEndScriptGenerator::saveCssFile("{$input->form_id}-formid", $input->atomicCssWithFormIdText);
489 }
490 if (isset($input->atomicClassMap) || isset($input->atomicClassMap)) {
491 $formModel = new FormModel();
492 $atomicClsMap = [
493 'atomic_class_map' => isset($input->atomicClassMap) ? $input->atomicClassMap : (object) [],
494 'atomic_class_map_with_form_id' => isset($input->atomicClassMapWithFormId) ? $input->atomicClassMapWithFormId : (object) [],
495 ];
496 $updateData['atomic_class_map'] = wp_json_encode($atomicClsMap);
497 $formModel->update(
498 $updateData,
499 [
500 'id' => $input->form_id,
501 ]
502 );
503 }
504 if (is_wp_error($status)) {
505 wp_send_json_error($status->get_error_message(), 411);
506 } else {
507 wp_send_json_success($status, 200);
508 }
509 } else {
510 wp_send_json_error(
511 __(
512 'Token expired',
513 'bit-form'
514 ),
515 401
516 );
517 }
518 }
519
520 public function createNewForm() {
521 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
522 $inputJSON = file_get_contents('php://input');
523 $input = json_decode($inputJSON);
524 $formHandler = FormHandler::getInstance();
525 $status = $formHandler->admin->createNewForm($_REQUEST, $input);
526 FrontEndScriptGenerator::customCodeFile($input->form_id, $input->customCodes);
527 if (is_wp_error($status)) {
528 wp_send_json_error($status->get_error_message(), 411);
529 } else {
530 wp_send_json_success($status, 200);
531 }
532 } else {
533 wp_send_json_error(
534 __(
535 'Token expired',
536 'bit-form'
537 ),
538 401
539 );
540 }
541 }
542
543 public function updateEntryStatus() {
544 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
545 $inputJSON = file_get_contents('php://input');
546 $input = json_decode($inputJSON);
547 $formId = sanitize_text_field($input->formId);
548 $entryId = sanitize_text_field($input->entryId);
549 $formEntryModel = new FormEntryModel();
550 $updatedTime = current_time('mysql');
551 $status = $formEntryModel->update(
552 [
553 'status' => 0,
554 'updated_at' => $updatedTime,
555 ],
556 [
557 'form_id' => $formId,
558 'id' => $entryId,
559 ]
560 );
561 if (is_wp_error($status)) {
562 wp_send_json_error($status->get_error_message(), 411);
563 } else {
564 wp_send_json_success(['update_at_time' => $updatedTime], 200);
565 }
566 } else {
567 wp_send_json_error(
568 __(
569 'Token expired',
570 'bit-form'
571 ),
572 401
573 );
574 }
575 }
576
577 public function changeFormStatus() {
578 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
579 $inputJSON = file_get_contents('php://input');
580 $input = json_decode($inputJSON);
581 $formHandler = FormHandler::getInstance();
582 $status = $formHandler->admin->changeFormStatus($_REQUEST, $input);
583 if (is_wp_error($status)) {
584 wp_send_json_error($status->get_error_message(), 411);
585 } else {
586 wp_send_json_success($status, 200);
587 }
588 } else {
589 wp_send_json_error(
590 __(
591 'Token expired',
592 'bit-form'
593 ),
594 401
595 );
596 }
597 }
598
599 public function changeBulkFormStatus() {
600 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
601 $inputJSON = file_get_contents('php://input');
602 $input = json_decode($inputJSON);
603 $formHandler = FormHandler::getInstance();
604 $status = $formHandler->admin->changeBulkFormStatus($_REQUEST, $input);
605 if (is_wp_error($status)) {
606 wp_send_json_error($status->get_error_message(), 411);
607 } else {
608 wp_send_json_success($status, 200);
609 }
610 } else {
611 wp_send_json_error(
612 __(
613 'Token expired',
614 'bit-form'
615 ),
616 401
617 );
618 }
619 }
620
621 public function getAForm() {
622 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
623 $inputJSON = file_get_contents('php://input');
624 $input = json_decode($inputJSON);
625 $formHandler = FormHandler::getInstance();
626 $status = $formHandler->admin->getAForm($_REQUEST, $input);
627 if (is_wp_error($status)) {
628 wp_send_json_error($status->get_error_message(), 411);
629 } else {
630 wp_send_json_success($status, 200);
631 }
632 } else {
633 wp_send_json_error(
634 __(
635 'Token expired',
636 'bit-form'
637 ),
638 401
639 );
640 }
641 }
642
643 public function duplicateAForm() {
644 \ignore_user_abort();
645 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
646 $inputJSON = file_get_contents('php://input');
647 $input = json_decode($inputJSON);
648 $formHandler = FormHandler::getInstance();
649 $status = $formHandler->admin->duplicateAForm($_REQUEST, $input);
650 if (is_wp_error($status)) {
651 wp_send_json_error($status->get_error_message(), 411);
652 } else {
653 wp_send_json_success($status, 200);
654 }
655 } else {
656 wp_send_json_error(
657 __(
658 'Token expired',
659 'bit-form'
660 ),
661 401
662 );
663 }
664 }
665
666 public function importAForm() {
667 \ignore_user_abort();
668 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
669 $inputJSON = file_get_contents('php://input');
670 $input = json_decode($inputJSON);
671 $formHandler = FormHandler::getInstance();
672 $status = $formHandler->admin->importAForm($input);
673 if (is_wp_error($status)) {
674 wp_send_json_error($status->get_error_message(), 411);
675 } else {
676 wp_send_json_success($status, 200);
677 }
678 } else {
679 wp_send_json_error(
680 __(
681 'Token expired',
682 'bit-form'
683 ),
684 401
685 );
686 }
687 }
688
689 // public function exportAForm() {
690 // if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
691 // $formHandler = FormHandler::getInstance();
692 // $status = $formHandler->admin->exportAForm($_REQUEST);
693 // if (is_wp_error($status)) {
694 // wp_send_json_error($status->get_error_message(), 411);
695 // }
696 // } else {
697 // wp_send_json_error(
698 // __(
699 // 'Token expired',
700 // 'bit-form'
701 // ),
702 // 401
703 // );
704 // }
705 // }
706 public function exportAForm() {
707 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
708 $inputJSON = file_get_contents('php://input');
709 $input = json_decode($inputJSON);
710 $formHandler = FormHandler::getInstance();
711 $status = $formHandler->admin->exportAForm($_REQUEST, $input);
712 if (is_wp_error($status)) {
713 wp_send_json_error($status->get_error_message(), 411);
714 } else {
715 wp_send_json_success($status);
716 }
717 } else {
718 wp_send_json_error(
719 __(
720 'Token expired',
721 'bit-form'
722 ),
723 401
724 );
725 }
726 }
727
728 public function deleteAForm() {
729 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
730 $inputJSON = file_get_contents('php://input');
731 $input = json_decode($inputJSON);
732 $formHandler = FormHandler::getInstance();
733 $status = $formHandler->admin->deleteAForm($_REQUEST, $input);
734 if (is_wp_error($status)) {
735 wp_send_json_error($status->get_error_message(), 411);
736 } else {
737 wp_send_json_success($status, 200);
738 }
739 } else {
740 wp_send_json_error(
741 __(
742 'Token expired',
743 'bit-form'
744 ),
745 401
746 );
747 }
748 }
749
750 public function deleteBlukForm() {
751 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
752 $inputJSON = file_get_contents('php://input');
753 $input = json_decode($inputJSON);
754 $formHandler = FormHandler::getInstance();
755 $status = $formHandler->admin->deleteBlukForm($_REQUEST, $input);
756 if (is_wp_error($status)) {
757 wp_send_json_error($status->get_error_message(), 411);
758 } else {
759 wp_send_json_success($status, 200);
760 }
761 } else {
762 wp_send_json_error(
763 __(
764 'Token expired',
765 'bit-form'
766 ),
767 401
768 );
769 }
770 }
771
772 public function deleteBlukFormEntries() {
773 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
774 $inputJSON = file_get_contents('php://input');
775 $input = json_decode($inputJSON);
776 $formHandler = FormHandler::getInstance();
777 $status = $formHandler->admin->deleteBlukFormEntries($_REQUEST, $input);
778 if (is_wp_error($status)) {
779 wp_send_json_error($status->get_error_message(), 411);
780 } else {
781 wp_send_json_success($status, 200);
782 }
783 } else {
784 wp_send_json_error(
785 __(
786 'Token expired',
787 'bit-form'
788 ),
789 401
790 );
791 }
792 }
793
794 public function duplicateFormEntry() {
795 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
796 $inputJSON = file_get_contents('php://input');
797 $input = json_decode($inputJSON);
798 $formHandler = FormHandler::getInstance();
799 $status = $formHandler->admin->duplicateFormEntry($_REQUEST, $input);
800 if (is_wp_error($status)) {
801 wp_send_json_error($status->get_error_message(), 411);
802 } else {
803 wp_send_json_success($status, 200);
804 }
805 } else {
806 wp_send_json_error(
807 __(
808 'Token expired',
809 'bit-form'
810 ),
811 401
812 );
813 }
814 }
815
816 public function editFormEntry() {
817 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
818 $inputJSON = file_get_contents('php://input');
819 $input = json_decode($inputJSON);
820 $formHandler = FormHandler::getInstance();
821 $status = $formHandler->admin->editFormEntry($_REQUEST, $input);
822 if (is_wp_error($status)) {
823 wp_send_json_error($status->get_error_message(), 411);
824 } else {
825 wp_send_json_success($status, 200);
826 }
827 } else {
828 wp_send_json_error(
829 __(
830 'Token expired',
831 'bit-form'
832 ),
833 401
834 );
835 }
836 }
837
838 public function getLogHistory() {
839 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
840 $inputJSON = file_get_contents('php://input');
841 $input = json_decode($inputJSON);
842 $formHandler = FormHandler::getInstance();
843 $status = $formHandler->admin->getLogHistory($_REQUEST, $input);
844 if (is_wp_error($status)) {
845 wp_send_json_error($status->get_error_message(), 411);
846 } else {
847 wp_send_json_success($status, 200);
848 }
849 } else {
850 wp_send_json_error(
851 __(
852 'Token expired',
853 'bit-form'
854 ),
855 401
856 );
857 }
858 }
859
860 public function updateFormEntry() {
861 \ignore_user_abort();
862 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
863 $formHandler = FormHandler::getInstance();
864 $status = $formHandler->admin->updateFormEntry($_REQUEST, $_POST);
865
866 if (is_wp_error($status)) {
867 wp_send_json_error($status->get_error_message(), 411);
868 } else {
869 $status = IntegrationHandler::maybeSetCronForIntegration($status, 'update');
870 wp_send_json_success($status, 200);
871 }
872 } else {
873 wp_send_json_error(
874 __(
875 'Token expired',
876 'bit-form'
877 ),
878 401
879 );
880 }
881 }
882
883 public function getAllWPPages() {
884 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
885 $inputJSON = file_get_contents('php://input');
886 $input = json_decode($inputJSON);
887 $formHandler = FormHandler::getInstance();
888 $status = $formHandler->admin->getAllWPPages($_REQUEST, $input);
889 if (is_wp_error($status)) {
890 wp_send_json_error($status->get_error_message(), 411);
891 } else {
892 wp_send_json_success($status, 200);
893 }
894 } else {
895 wp_send_json_error(
896 __(
897 'Token expired',
898 'bit-form'
899 ),
900 401
901 );
902 }
903 }
904
905 public function deleteSuccessMessage() {
906 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
907 $inputJSON = file_get_contents('php://input');
908 $input = json_decode($inputJSON);
909 $formHandler = FormHandler::getInstance();
910 $status = $formHandler->admin->deleteSuccessMessage($_REQUEST, $input);
911 if (is_wp_error($status)) {
912 wp_send_json_error($status->get_error_message(), 411);
913 } else {
914 wp_send_json_success($status, 200);
915 }
916 } else {
917 wp_send_json_error(
918 __(
919 'Token expired',
920 'bit-form'
921 ),
922 401
923 );
924 }
925 }
926
927 public function deleteAIntegration() {
928 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
929 $inputJSON = file_get_contents('php://input');
930 $input = json_decode($inputJSON);
931 $formHandler = FormHandler::getInstance();
932 $status = $formHandler->admin->deleteAIntegration($_REQUEST, $input);
933 if (is_wp_error($status)) {
934 wp_send_json_error($status->get_error_message(), 411);
935 } else {
936 wp_send_json_success($status, 200);
937 }
938 } else {
939 wp_send_json_error(
940 __(
941 'Token expired',
942 'bit-form'
943 ),
944 401
945 );
946 }
947 }
948
949 public function deleteAWorkflow() {
950 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
951 $inputJSON = file_get_contents('php://input');
952 $input = json_decode($inputJSON);
953 $formHandler = FormHandler::getInstance();
954 $status = $formHandler->admin->deleteAWorkflow($_REQUEST, $input);
955 if (is_wp_error($status)) {
956 wp_send_json_error($status->get_error_message(), 411);
957 } else {
958 wp_send_json_success($status, 200);
959 }
960 } else {
961 wp_send_json_error(
962 __(
963 'Token expired',
964 'bit-form'
965 ),
966 401
967 );
968 }
969 }
970
971 public function deleteAMailTemplate() {
972 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
973 $inputJSON = file_get_contents('php://input');
974 $input = json_decode($inputJSON);
975 $formHandler = FormHandler::getInstance();
976 $status = $formHandler->admin->deleteAMailTemplate($_REQUEST, $input);
977 if (is_wp_error($status)) {
978 wp_send_json_error($status->get_error_message(), 411);
979 } else {
980 wp_send_json_success($status, 200);
981 }
982 } else {
983 wp_send_json_error(
984 __(
985 'Token expired',
986 'bit-form'
987 ),
988 401
989 );
990 }
991 }
992
993 public function duplicateAMailTemplate() {
994 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
995 $inputJSON = file_get_contents('php://input');
996 $input = json_decode($inputJSON);
997 $formHandler = FormHandler::getInstance();
998 $status = $formHandler->admin->duplicateAMailTemplate($_REQUEST, $input);
999 if (is_wp_error($status)) {
1000 wp_send_json_error($status->get_error_message(), 411);
1001 } else {
1002 wp_send_json_success($status, 200);
1003 }
1004 } else {
1005 wp_send_json_error(
1006 __(
1007 'Token expired',
1008 'bit-form'
1009 ),
1010 401
1011 );
1012 }
1013 }
1014
1015 public function setAllFormsReport() {
1016 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1017 $inputJSON = file_get_contents('php://input');
1018 $input = json_decode($inputJSON);
1019 $formHandler = FormHandler::getInstance();
1020 $status = $formHandler->admin->setAllFormsReport($_REQUEST, $input);
1021 if (is_wp_error($status)) {
1022 wp_send_json_error($status->get_error_message(), 411);
1023 } else {
1024 wp_send_json_success($status, 200);
1025 }
1026 } else {
1027 wp_send_json_error(
1028 __(
1029 'Token expired',
1030 'bit-form'
1031 ),
1032 401
1033 );
1034 }
1035 }
1036
1037 public function savegReCaptcha() {
1038 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1039 $inputJSON = file_get_contents('php://input');
1040 $input = json_decode($inputJSON);
1041 $formHandler = FormHandler::getInstance();
1042 $status = $formHandler->admin->savegReCaptcha($_REQUEST, $input);
1043 if (is_wp_error($status)) {
1044 wp_send_json_error($status->get_error_message(), 411);
1045 } else {
1046 wp_send_json_success($status, 200);
1047 }
1048 } else {
1049 wp_send_json_error(
1050 __(
1051 'Token expired',
1052 'bit-form'
1053 ),
1054 401
1055 );
1056 }
1057 }
1058
1059 public function saveApiKey() {
1060 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1061 $inputJSON = file_get_contents('php://input');
1062 $input = json_decode($inputJSON);
1063 if (empty($input->api_key)) {
1064 $api_key = get_option('bitform_secret_api_key');
1065 } elseif (!empty($input->api_key)) {
1066 update_option('bitform_secret_api_key', $input->api_key);
1067 $api_key = $input->api_key;
1068 }
1069 if (!$api_key) {
1070 $api_key = hash('sha1', base64_encode(12345));
1071 update_option('bitform_secret_api_key', $api_key);
1072 }
1073 wp_send_json_success($api_key, 200);
1074 } else {
1075 wp_send_json_error(
1076 __(
1077 'Token expired',
1078 'bit-form'
1079 ),
1080 401
1081 );
1082 }
1083 }
1084
1085 public function iconUpload() {
1086 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1087 $inputJSON = file_get_contents('php://input');
1088 $input = json_decode($inputJSON);
1089 $uploadDirInfo = wp_upload_dir();
1090 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1091 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons';
1092 if (!is_dir($icnDir)) {
1093 mkdir($icnDir);
1094 }
1095
1096 $imageUrlData = file_get_contents($input->src);
1097
1098 $filename = basename($input->src);
1099
1100 $uploaded = file_put_contents($icnDir . '/' . $filename, $imageUrlData);
1101
1102 if ($uploaded) {
1103 $uploadedFile = BITFORMS_UPLOAD_BASE_URL . '/' . 'icons' . '/' . $filename;
1104 wp_send_json_success($uploadedFile, 200);
1105 }
1106 } else {
1107 wp_send_json_error(
1108 __(
1109 'Token expired',
1110 'bit-form'
1111 ),
1112 401
1113 );
1114 }
1115 }
1116
1117 private function getFiles() {
1118 $uploadDirInfo = wp_upload_dir();
1119 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1120 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons';
1121 $files = [];
1122 if (file_exists($icnDir)) {
1123 $openDir = opendir($icnDir . DIRECTORY_SEPARATOR);
1124
1125 while (false !== ($fileName = readdir($openDir))) {
1126 $ext = substr($fileName, strrpos($fileName, '.') + 1);
1127 if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'svg'])) {
1128 $files[] = $fileName;
1129 }
1130 }
1131
1132 closedir($openDir);
1133 }
1134 return $files;
1135 }
1136
1137 public function getDownlodedIcons() {
1138 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1139 $files = $this->getFiles();
1140 wp_send_json_success($files, 200);
1141 } else {
1142 wp_send_json_error(
1143 __(
1144 'Token expired',
1145 'bit-form'
1146 ),
1147 401
1148 );
1149 }
1150 }
1151
1152 public function iconRemove() {
1153 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1154 $inputJSON = file_get_contents('php://input');
1155 $input = json_decode($inputJSON);
1156
1157 $uploadDirInfo = wp_upload_dir();
1158
1159 $wpUploadbaseDir = $uploadDirInfo['basedir'];
1160 $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR;
1161 if (file_exists($icnDir . $input->file)) {
1162 unlink($icnDir . $input->file);
1163 wp_send_json_success($this->getFiles(), 200);
1164 }
1165 } else {
1166 wp_send_json_error(
1167 __(
1168 'Token expired',
1169 'bit-form'
1170 ),
1171 401
1172 );
1173 }
1174 }
1175
1176 public function addCustomCode() {
1177 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1178 $inputJSON = file_get_contents('php://input');
1179 $input = json_decode($inputJSON);
1180 FrontEndScriptGenerator::customCodeFile($input->form_id, $input->customCodes);
1181 $status = ['message' => 'File Update Successfully..'];
1182 if (is_wp_error($status)) {
1183 wp_send_json_error($status->get_error_message(), 411);
1184 } else {
1185 wp_send_json_success($status, 200);
1186 }
1187 } else {
1188 wp_send_json_error(
1189 __(
1190 'Token expired',
1191 'bit-form'
1192 ),
1193 401
1194 );
1195 }
1196 }
1197
1198 public function getCustomCode() {
1199 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1200 $inputJSON = file_get_contents('php://input');
1201 $input = json_decode($inputJSON);
1202 $status = FrontEndScriptGenerator::getCustomCodes($input->form_id);
1203 if (is_wp_error($status)) {
1204 wp_send_json_error($status->get_error_message(), 411);
1205 } else {
1206 wp_send_json_success($status, 200);
1207 }
1208 } else {
1209 wp_send_json_error(
1210 __(
1211 'Token expired',
1212 'bit-form'
1213 ),
1214 401
1215 );
1216 }
1217 }
1218
1219 public function getGenerelSettings() {
1220 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1221 $data = get_option('bitform_app_config');
1222
1223 if (is_wp_error($data)) {
1224 wp_send_json_error($data->get_error_message(), 411);
1225 } else {
1226 if (empty($data)) {
1227 $data = (object)[];
1228 }
1229 wp_send_json_success($data, 200);
1230 }
1231 } else {
1232 wp_send_json_error(
1233 __(
1234 'Token expired'
1235 ),
1236 401
1237 );
1238 }
1239 }
1240
1241 public function saveGenerelSettings() {
1242 if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) {
1243 $inputJSON = file_get_contents('php://input');
1244 $input = json_decode($inputJSON);
1245 $status = update_option('bitform_app_config', $input->config);
1246 if (is_wp_error($status)) {
1247 wp_send_json_error($status->get_error_message(), 411);
1248 } else {
1249 if (Helpers::property_exists_nested($input, 'config->cache_plugin', true)) {
1250 $formHandler = FormHandler::getInstance();
1251 $formHandler->admin->updateGeneratedScriptPageIds();
1252 }
1253 wp_send_json_success(__('Save successfully done'));
1254 }
1255 } else {
1256 wp_send_json_error(
1257 __(
1258 'Token expired'
1259 ),
1260 401
1261 );
1262 }
1263 }
1264
1265 public function savePaymentSettings() {
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 $formHandler = FormHandler::getInstance();
1270 $status = $formHandler->admin->savePaymentSetting($_REQUEST, $input);
1271 if (is_wp_error($status)) {
1272 wp_send_json_error($status->get_error_message(), 411);
1273 } else {
1274 wp_send_json_success($status, 200);
1275 }
1276 } else {
1277 wp_send_json_error(
1278 __(
1279 'Token expired',
1280 'bit-form'
1281 ),
1282 401
1283 );
1284 }
1285 }
1286 }
1287