PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.16.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.16.2
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
← All changes | includes/Admin/Form/AdminFormHandler.php +384 -67 2.10.22.16.2 View file →
@@ -21,15 +21,16 @@
21 21 use BitCode\BitForm\Core\Integration\IntegrationHandler;
22 22 use BitCode\BitForm\Core\Messages\EmailTemplateHandler;
23 23 use BitCode\BitForm\Core\Messages\PdfTemplateHandler;
24 24 use BitCode\BitForm\Core\Messages\SuccessMessageHandler;
25 +use BitCode\BitForm\Core\Migration\MigrationHelper;
25 26 use BitCode\BitForm\Core\Util\FileHandler;
26 27 use BitCode\BitForm\Core\Util\FormDuplicateHelper;
27 28 use BitCode\BitForm\Core\Util\HttpHelper;
28 29 use BitCode\BitForm\Core\Util\IpTool;
30 +use BitCode\BitForm\Core\Util\Utilities;
29 31 use BitCode\BitForm\Core\WorkFlow\WorkFlow;
30 32 use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler;
31 -use BitCode\BitFormPro\Admin\AppSetting\Pdf;
32 33 use WP_Error;
33 34
34 35 class AdminFormHandler
35 36 {
@@ -176,9 +177,9 @@
176 177
177 178 private function pdfFontDownload($fontName)
178 179 {
179 180 if (class_exists('\BitCode\BitFormPro\Admin\AppSetting\Pdf')) {
180 - Pdf::getInstance()->fontsDownload($fontName);
181 + \BitCode\BitFormPro\Admin\AppSetting\Pdf::getInstance()->fontsDownload($fontName);
181 182 }
182 183 return false;
183 184 }
184 185
@@ -217,11 +218,12 @@
217 218
218 219 $fields = wp_unslash($post->fields);
219 220 // $fields = $post->fields;
220 221 $layout = wp_unslash($post->layout);
221 - $nestedLayout = isset($post->nestedLayout) ? wp_unslash($post->nestedLayout) : (object) [];
222 + $nestedLayout = isset($post->nestedLayouts) ? wp_unslash($post->nestedLayouts) : (object) [];
222 223 $formInfo = wp_unslash($post->formInfo);
223 224 $form_name = wp_unslash($post->form_name);
225 + $form_name = strlen($form_name) > 50 ? substr($form_name, 0, 50) : $form_name;
224 226 $formSettings = (object) wp_unslash($post->formSettings);
225 227 $atomic_class_map = isset($post->atomicClassMap) ? wp_unslash($post->atomicClassMap) : [];
226 228 $breakpointSize = wp_unslash($post->breakpointSize);
227 229 $style = $post->style;
@@ -235,8 +237,9 @@
235 237
236 238 $mailTem = $formSettings->mailTem;
237 239 $pdfTem = $formSettings->pdfTem;
238 240 $integrations = $formSettings->integrations;
241 + $formPermissions = $formSettings->formPermissions;
239 242
240 243 $user_details = static::$ipTool->getUserDetail();
241 244 if (empty($fields) || empty($layout)) {
242 245 return new WP_Error(
@@ -263,8 +266,12 @@
263 266 if (!empty($formSettings->theme)) {
264 267 $form_content = array_merge($form_content, ['theme' => $formSettings->theme]);
265 268 }
266 269
270 + if (!empty($formSettings->formPermissions)) {
271 + $form_content = array_merge($form_content, ['formPermissions' => $formSettings->formPermissions]);
272 + }
273 +
267 274 if (!empty($additional)) {
268 275 $form_content = array_merge($form_content, ['additional' => $additional]);
269 276 }
270 277 if (!empty($workFlows)) {
@@ -566,8 +573,12 @@
566 573 } */
567 574 if (!empty($formSettings->theme)) {
568 575 $form_content = array_merge($form_content, ['theme' => $formSettings->theme]);
569 576 }
577 +
578 + if (!empty($formSettings->formPermissions)) {
579 + $form_content = array_merge($form_content, ['formPermissions' => $formSettings->formPermissions]);
580 + }
570 581 if (!empty($additional)) {
571 582 $form_content = array_merge($form_content, ['additional' => $additional]);
572 583 }
573 584 $integartionIDForWorkflow = [];
@@ -575,8 +586,9 @@
575 586 $newData['integation'] = 0;
576 587 $newData['mailTemplate'] = 0;
577 588 $newData['workflow'] = 0;
578 589 $newData['reports'] = 0;
590 + $newData['pdfTemplate'] = 0;
579 591 // Confiramtion Message [start]
580 592 if (!empty($formSettings->confirmation->type->successMsg)) {
581 593 $successMessages = $formSettings->confirmation->type->successMsg;
582 594 $successMessageHandler
@@ -710,8 +722,9 @@
710 722 }
711 723 if ('oninput' === $workFlow->action_type || ('always' === $workFlow->action_type && 'cond' === $workFlow->action_behaviour)) {
712 724 $workFlowExist['oninput'] = true;
713 725 }
726 + // $integartionIDForWorkflow = apply_filters('bitform_filter_integration_id', $workFlow, $formID, $index);
714 727 if (empty($workFlow->id)) {
715 728 $savedID = $workFlowHandler->saveworkFlow($workFlow, $integartionIDForWorkflow, $index);
716 729 if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) {
717 730 $newData['workflow'] = 2;
@@ -829,9 +842,9 @@
829 842 }
830 843
831 844 $updated_data = $this->getAForm(['id' => $formID], null);
832 845
833 - if (0 === $newData['settingConfiramation'] && 0 === $newData['mailTemplate'] && 0 === $newData['integation']) {
846 + if (0 === $newData['settingConfiramation'] && 0 === $newData['mailTemplate'] && 0 === $newData['integation'] && 0 === $newData['pdfTemplate']) {
834 847 unset($updated_data['formSettings']);
835 848 }
836 849 if (0 === $newData['integation']) {
837 850 unset($updated_data['integrations']);
@@ -843,13 +856,13 @@
843 856 unset($updated_data['mailTem']);
844 857 } elseif (2 === $newData['mailTemplate']) {
845 858 $errorIN .= empty($errorIN) ? 'mailTemplate' : ', mailTemplate';
846 859 }
847 - // if (0 === $newData['pdfTemplate']) {
848 - // unset($updated_data['pdfTem']);
849 - // } elseif (2 === $newData['pdfTemplate']) {
850 - // $errorIN .= empty($errorIN) ? 'pdfTemplate' : ', pdfTemplate';
851 - // }
860 + if (0 === $newData['pdfTemplate']) {
861 + unset($updated_data['pdfTem']);
862 + } elseif (2 === $newData['pdfTemplate']) {
863 + $errorIN .= empty($errorIN) ? 'pdfTemplate' : ', pdfTemplate';
864 + }
852 865 if (0 === $newData['workflow']) {
853 866 unset($updated_data['workFlows']);
854 867 } elseif (2 === $newData['workflow']) {
855 868 $errorIN .= empty($errorIN) ? 'workflow' : ', workflow';
@@ -1077,10 +1090,11 @@
1077 1090 }
1078 1091 }
1079 1092 }
1080 1093 $settingsContent = [
1081 - 'formName' => $formManager->getFormName(),
1082 - 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1094 + 'formName' => $formManager->getFormName(),
1095 + 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1096 + 'formPermissions' => isset($form_content->formPermissions) ? $form_content->formPermissions : (object) [],
1083 1097 // 'submitBtn' => $form_content->buttons,
1084 1098 ];
1085 1099
1086 1100 if (!empty($allConfirmation)) {
@@ -1228,8 +1242,225 @@
1228 1242 return $data;
1229 1243 }
1230 1244 }
1231 1245
1246 + public function getAFormV1($Request, $post)
1247 + {
1248 + if (isset($Request['id'])) {
1249 + $formID = wp_unslash($Request['id']);
1250 + } else {
1251 + $formID = wp_unslash($post->id);
1252 + }
1253 + // return $post->fields;
1254 + if (is_null($formID)) {
1255 + return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1256 + }
1257 + $formManager = new AdminFormManager($formID);
1258 + if (!$formManager->isExist()) {
1259 + return new WP_Error('not_exists', __('Form is not exists.', 'bit-form'));
1260 + }
1261 + $form_content = $formManager->getFormContent();
1262 + if ($formManager->isExist()) {
1263 + $form_content_arr = [
1264 + 'layout' => $form_content->layout,
1265 + 'fields' => $form_content->fields,
1266 + 'form_name' => $formManager->getFormName(),
1267 + 'workFlowExist' => $form_content->workFlowExist,
1268 + 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1269 + ];
1270 + $successMessageHandler
1271 + = new SuccessMessageHandler($formID);
1272 + $successMessages = $successMessageHandler->getAllMessage();
1273 + if (!is_wp_error($successMessages)) {
1274 + foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) {
1275 + $allConfirmation['type']['successMsg'][$sucessMessagekey] =
1276 + [
1277 + 'id' => $sucessMessagevalue->id,
1278 + 'title' => $sucessMessagevalue->message_title,
1279 + 'msg' => $sucessMessagevalue->message_content,
1280 + ];
1281 + }
1282 + }
1283 + $emailTemplateHandler
1284 + = new EmailTemplateHandler($formID);
1285 + $emailTemplates = $emailTemplateHandler->getAllTemplate();
1286 + if (!is_wp_error($emailTemplates)) {
1287 + foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1288 + $mailTem[] =
1289 + [
1290 + 'id' => $emailTemplatevalue->id,
1291 + 'title' => $emailTemplatevalue->title,
1292 + 'sub' => $emailTemplatevalue->sub,
1293 + 'body' => $emailTemplatevalue->body,
1294 + ];
1295 + }
1296 + }
1297 + $integrationHandler = new IntegrationHandler($formID);
1298 + $formIntegrations = $integrationHandler->getAllIntegration('form');
1299 + if (!is_wp_error($formIntegrations)) {
1300 + foreach ($formIntegrations as $integrationkey => $integrationValue) {
1301 + if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1302 + $integrationData = [
1303 + 'id' => $integrationValue->id,
1304 + 'title' => $integrationValue->integration_name,
1305 + ];
1306 + if (!empty($integrationValue->integration_details)) {
1307 + // var_dump(json_decode($integrationValue->integration_details));
1308 + $integration_details = (array) json_decode($integrationValue->integration_details);
1309 + $integrationData = array_merge($integration_details, $integrationData);
1310 + } else {
1311 + $integration_details = [
1312 + 'url' => '',
1313 + ];
1314 + $integrationData = array_merge($integrationData, $integration_details);
1315 + }
1316 + $allConfirmation['type'][$integrationValue->integration_type][]
1317 + = $integrationData;
1318 + } else {
1319 + $integrationData = [
1320 + 'id' => $integrationValue->id,
1321 + 'name' => $integrationValue->integration_name,
1322 + 'type' => $integrationValue->integration_type,
1323 + ];
1324 + $integrations[] = array_merge(
1325 + $integrationData,
1326 + is_string($integrationValue->integration_details) ?
1327 + (array) json_decode($integrationValue->integration_details) :
1328 + $integrationValue->integration_details
1329 + );
1330 + }
1331 + }
1332 + }
1333 + $settingsContent = [
1334 + 'formName' => $formManager->getFormName(),
1335 + 'theme' => $form_content->theme,
1336 + // 'submitBtn' => $form_content->buttons,
1337 + ];
1338 +
1339 + if (!empty($allConfirmation)) {
1340 + $confirmation = [
1341 + 'confirmation' => $allConfirmation,
1342 + ];
1343 + } else {
1344 + $confirmation = [
1345 + 'confirmation' => ['type' => []],
1346 + ];
1347 + }
1348 + $settingsContent = array_merge($settingsContent, $confirmation);
1349 + if (!empty($integrations)) {
1350 + $settingsContent = array_merge(
1351 + $settingsContent,
1352 + [
1353 + 'integrations' => $integrations,
1354 + ]
1355 + );
1356 + } else {
1357 + $settingsContent = array_merge(
1358 + $settingsContent,
1359 + [
1360 + 'integrations' => []
1361 + ]
1362 + );
1363 + }
1364 + if (!empty($mailTem)) {
1365 + $settingsContent = array_merge(
1366 + $settingsContent,
1367 + [
1368 + 'mailTem' => $mailTem,
1369 + ]
1370 + );
1371 + } else {
1372 + $settingsContent = array_merge(
1373 + $settingsContent,
1374 + [
1375 + 'mailTem' => []
1376 + ]
1377 + );
1378 + }
1379 + $formSettings = [
1380 + 'formSettings' => $settingsContent,
1381 + ];
1382 + $data = [
1383 + 'id' => $formID,
1384 + 'form_name' => $formManager->getFormName(),
1385 + 'form_content' => $form_content_arr,
1386 + 'additional' => empty($form_content->additional) ? [
1387 + 'enabled' => [
1388 + 'blocked_ip' => false,
1389 + 'restrict_form' => false,
1390 + ],
1391 + 'settings' => [
1392 + 'restrict_form' => [
1393 + 'day' => [],
1394 + 'date' => [
1395 + 'from' => null,
1396 + 'to' => null,
1397 + ],
1398 + 'time' => [
1399 + 'from' => null,
1400 + 'to' => null,
1401 + ],
1402 + ],
1403 + 'entry_limit' => null,
1404 + 'blocked_ip' => [],
1405 + ],
1406 + 'onePerIp' => false,
1407 + ] : $form_content->additional,
1408 + 'created_at' => $formManager->getFormMetaData()['created_at'],
1409 + 'views' => $formManager->getFormMetaData()['views'],
1410 + 'entries' => $formManager->getFormMetaData()['entries'],
1411 + 'status' => $formManager->getFormMetaData()['status'],
1412 + ];
1413 + $data = array_merge($data, $formSettings);
1414 + $workFlowHandler = new WorkFlowHandler($formID);
1415 + $workFlows = ['workFlows' => $workFlowHandler->getAllworkFlowV1()];
1416 + $data = array_merge($data, $workFlows);
1417 + $reportsModel = new ReportsModel();
1418 + $returnedReportData = $reportsModel->get(
1419 + [
1420 + 'id',
1421 + 'details',
1422 + 'isDefault',
1423 + 'type',
1424 + ],
1425 + [
1426 + 'category' => 'form',
1427 + 'context' => $formID,
1428 + ]
1429 + );
1430 +
1431 + if (!is_wp_error($returnedReportData)) {
1432 + $fieldNames = [];
1433 + foreach ($formManager->getFieldLabel() as $key => $field) {
1434 + $fieldNames[$field['key']] = isset($field->lbl) ? $field->lbl : '';
1435 + }
1436 + if ($formManager->isGCLIDEnabled()) {
1437 + $fieldNames['GCLID'] = 'GCLID';
1438 + }
1439 + foreach ($returnedReportData as $reportKey => $reportData) {
1440 + $reportDetails = $reportsModel->validateReportFields($reportData, $fieldNames);
1441 + if (!empty($reportDetails) && is_string($reportDetails)) {
1442 + $returnedReportData[$reportKey]->details = json_decode($reportDetails);
1443 + } elseif (!empty($reportDetails)) {
1444 + $returnedReportData[$reportKey]->details = $reportDetails;
1445 + } else {
1446 + $returnedReportData[$reportKey]->details = [];
1447 + }
1448 + if ('1' === (string) $reportData->isDefault) {
1449 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1450 + }
1451 + }
1452 + $reports = ['reports' => $returnedReportData];
1453 + $data = array_merge($data, $reports);
1454 + }
1455 +
1456 + $formFields = $formManager->getFieldLabel();
1457 + $data = array_merge($data, ['Labels' => $formFields]);
1458 +
1459 + return $data;
1460 + }
1461 + }
1462 +
1232 1463 public function deleteAForm($Request, $post)
1233 1464 {
1234 1465 if (isset($Request['id'])) {
1235 1466 $formID = wp_unslash($Request['id']);
@@ -1238,8 +1469,13 @@
1238 1469 }
1239 1470 if (is_null($formID)) {
1240 1471 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1241 1472 }
1473 +
1474 + if (!filter_var($formID, FILTER_VALIDATE_INT)) {
1475 + return new WP_Error('invalid_form', __('Form id is invalid.', 'bit-form'));
1476 + }
1477 +
1242 1478 $delete_status = static::$formModel->delete(
1243 1479 [
1244 1480 'id' => $formID,
1245 1481 ]
@@ -1244,14 +1480,12 @@
1244 1480 'id' => $formID,
1245 1481 ]
1246 1482 );
1247 1483
1248 - $successMessageModel
1249 - = new SuccessMessageModel();
1484 + $successMessageModel = new SuccessMessageModel();
1250 1485 $deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]);
1251 1486
1252 - $emailTemplateModel
1253 - = new EmailTemplateModel();
1487 + $emailTemplateModel = new EmailTemplateModel();
1254 1488 $deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]);
1255 1489
1256 1490 $pdfTemplateModel = new PdfTemplateModel();
1257 1491 $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
@@ -1268,22 +1502,11 @@
1268 1502 $formEntryModel = new FormEntryModel();
1269 1503 $returnedEntries = $formEntryModel->get('id', ['form_id' => $formID]);
1270 1504 $entries = [];
1271 1505
1272 - if (!is_wp_error($returnedEntries)) {
1273 - foreach ($returnedEntries as $entryKey => $entryInfo) {
1274 - $entries[] = $entryInfo->id;
1275 - }
1276 - global $wpdb;
1277 - $prefix = $wpdb->prefix;
1278 - if (count($entries) > 0) {
1279 - $deleteEntriesStatus = $formEntryModel->bulkDelete(
1280 - [
1281 - "`{$prefix}bitforms_form_entries`.`id`" => $entries,
1282 - "`{$prefix}bitforms_form_entries`.`form_id`" => $formID,
1283 - ]
1284 - );
1285 - }
1506 + // checked namespace exist
1507 + if (class_exists('\BitCode\BitFormPro\Admin\BfTable\Table')) {
1508 + \BitCode\BitFormPro\Admin\BfTable\Table::deleteTableByFormId($formID);
1286 1509 }
1287 1510
1288 1511 $fileHandler = new FileHandler();
1289 1512 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
@@ -1291,23 +1514,25 @@
1291 1514 }
1292 1515 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
1293 1516 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID);
1294 1517 }
1295 - if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css')) {
1296 - unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css');
1297 - }
1298 - if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css')) {
1299 - unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css');
1300 - }
1301 - if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.css')) {
1302 - unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.css');
1303 - }
1304 - if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-scripts' . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.js')) {
1305 - unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-scripts' . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.js');
1306 - }
1307 - if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-conversational-' . $formID . '.css')) {
1308 - unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-conversational-' . $formID . '.css');
1309 - }
1518 + $formStylePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles';
1519 +
1520 + $formCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css';
1521 + FileHandler::deleteIsFileExists($formCssPath);
1522 +
1523 + $layoutCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css';
1524 + FileHandler::deleteIsFileExists($layoutCssPath);
1525 +
1526 + $customCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.css';
1527 + FileHandler::deleteIsFileExists($customCssPath);
1528 +
1529 + $customJSPath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-scripts' . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.js';
1530 + FileHandler::deleteIsFileExists($customJSPath);
1531 +
1532 + $conversationCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-conversational-' . $formID . '.css';
1533 + FileHandler::deleteIsFileExists($conversationCssPath);
1534 +
1310 1535 return is_wp_error($delete_status) ? $delete_status : __('Form deleted successfully.', 'bit-form');
1311 1536 }
1312 1537
1313 1538 public function deleteBlukForm($Request, $post)
@@ -1316,20 +1541,27 @@
1316 1541 $formID = wp_unslash($Request['formID']);
1317 1542 } else {
1318 1543 $formID = wp_unslash($post->formID);
1319 1544 }
1545 +
1320 1546 if (is_null($formID) || !is_array($formID)) {
1321 1547 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1322 1548 }
1549 +
1550 + if (!Helpers::checkIsIntArr($formID)) {
1551 + return new WP_Error('invalid_form', __('Form id is invalid', 'bit-form'));
1552 + }
1553 +
1323 1554 $cssPath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR;
1324 1555 foreach ($formID as $id) {
1325 - unlink($cssPath . 'bitform-' . $id . '.css');
1326 - if (file_exists($cssPath . 'bitform-layout-' . $id . '.css')) {
1327 - unlink($cssPath . 'bitform-layout-' . $id . '.css');
1328 - }
1329 - if (file_exists($cssPath . 'bitform-' . $id . '-formid' . '.css')) {
1330 - unlink($cssPath . 'bitform-' . $id . '-formid' . '.css');
1331 - }
1556 + $formCssPath = $cssPath . 'bitform-' . $id . '.css';
1557 + FileHandler::deleteIsFileExists($formCssPath);
1558 +
1559 + $layoutPath = $cssPath . 'bitform-layout-' . $id . '.css';
1560 + FileHandler::deleteIsFileExists($layoutPath);
1561 +
1562 + $bitformCustomPath = $cssPath . 'bitform-' . $id . '-formid' . '.css';
1563 + FileHandler::deleteIsFileExists($bitformCustomPath);
1332 1564 }
1333 1565 $delete_status = static::$formModel->bulkDelete(
1334 1566 [
1335 1567 'id' => $formID,
@@ -1334,14 +1566,18 @@
1334 1566 [
1335 1567 'id' => $formID,
1336 1568 ]
1337 1569 );
1570 +
1571 + if (is_wp_error($delete_status)) {
1572 + wp_send_json_error($delete_status->get_error_message(), 400);
1573 + }
1574 +
1338 1575 $successMessageModel
1339 1576 = new SuccessMessageModel();
1340 1577 $deleteMsgStatus = $successMessageModel->bulkDelete(['form_id' => $formID]);
1341 1578
1342 - $emailTemplateModel
1343 - = new EmailTemplateModel();
1579 + $emailTemplateModel = new EmailTemplateModel();
1344 1580 $deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]);
1345 1581
1346 1582 $pdfTemplateModel = new PdfTemplateModel();
1347 1583 $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
@@ -1356,8 +1592,13 @@
1356 1592 $deleteReportStatus = $reportsModel->bulkDelete(['context' => $formID]);
1357 1593
1358 1594 $formEntryModel = new FormEntryModel();
1359 1595 $returnedEntries = $formEntryModel->get('id', ['form_id' => $formID]);
1596 +
1597 + if (class_exists('\BitCode\BitFormPro\Admin\BfTable\Table')) {
1598 + \BitCode\BitFormPro\Admin\BfTable\Table::deleteTableByBulkFormId($formID);
1599 + }
1600 +
1360 1601 $entries = [];
1361 1602 foreach ($returnedEntries as $entryKey => $entryInfo) {
1362 1603 if (!empty($entryInfo->id)) {
1363 1604 $entries[] = $entryInfo->id;
@@ -1378,11 +1619,8 @@
1378 1619 foreach ($formID as $fId) {
1379 1620 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) {
1380 1621 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId);
1381 1622 }
1382 -
1383 - // unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $fId . '.css');
1384 - // unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $fId . '.css');
1385 1623 }
1386 1624
1387 1625 return is_wp_error($delete_status) ? $delete_status : __('Forms deleted successfully.', 'bit-form');
1388 1626 }
@@ -1454,9 +1692,9 @@
1454 1692 }
1455 1693 $importtedForm = (array)$post->formDetail;
1456 1694 $importtedForm['form_content']['fields'] = $importtedForm['fields'];
1457 1695 $importtedForm['form_content']['layout'] = $importtedForm['layout'];
1458 - $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayout'];
1696 + $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayouts'];
1459 1697 $importtedForm['form_content']['formInfo'] = $importtedForm['formInfo'];
1460 1698 unset($importtedForm['fields'], $importtedForm['layout'], $importtedForm['nestedLayout'], $importtedForm['formInfo']);
1461 1699 $formData = FormDuplicateHelper::createReplica((array)$importtedForm, $oldFormId, $newFormId);
1462 1700
@@ -1484,9 +1722,11 @@
1484 1722 $fileName = 'bitform-custom-' . $newFormId . '.css';
1485 1723 $customCode['CSS'] = $formData->customCode->customCss;
1486 1724 Helpers::saveFile($customCssPath, $fileName, $formData->customCode->customCss, 'w');
1487 1725 }
1488 - $importResponse['customCode'] = $customCode;
1726 + if (!is_wp_error($importResponse)) {
1727 + $importResponse['customCode'] = $customCode;
1728 + }
1489 1729 if (!is_wp_error($importResponse) || (is_wp_error($importResponse) && 'result_empty' === $importResponse->get_error_code())) {
1490 1730 $responseData = $this->getAForm(null, (object) ['id' => $newFormId]);
1491 1731 $responseData['customCode'] = $customCode;
1492 1732 $responseData['message'] = __('Form imported successfully.', 'bit-form');
@@ -1682,8 +1922,28 @@
1682 1922 $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
1683 1923 return $formEntries;
1684 1924 }
1685 1925
1926 + public function getSingleEntry($formId, $entryId)
1927 + {
1928 + $formManager = new AdminFormManager($formId);
1929 + if (!$formManager->isExist()) {
1930 + return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
1931 + }
1932 +
1933 + $formFields = $formManager->getFieldLabel(true);
1934 + $fieldDetails = $formManager->getFields();
1935 + $entryMeta = new FormEntryMetaModel();
1936 + // $formEntry = new FormEntryModel();
1937 +
1938 + $entries = $entryMeta->getSingleEntryMeta($formFields, $entryId);
1939 + return $entries[0];
1940 +
1941 + // $customFieldHandler = new CustomFieldHandler();
1942 + // $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
1943 + // return $formEntries;
1944 + }
1945 +
1686 1946 public function getEntriesForReport($Request, $post)
1687 1947 {
1688 1948 if (isset($Request['id'])) {
1689 1949 $id = wp_unslash($Request['id']);
@@ -1798,8 +2058,17 @@
1798 2058 }
1799 2059 if (is_null($formID) || !is_array($entries) || 0 === count($entries)) {
1800 2060 return new WP_Error('empty_form', __('Invalid Form ID or Entries ID.', 'bit-form'));
1801 2061 }
2062 +
2063 + if (!filter_var($formID, FILTER_VALIDATE_INT)) {
2064 + return new WP_Error('invalid_form', __('Form id is invalid.', 'bit-form'));
2065 + }
2066 +
2067 + if (!Helpers::checkIsIntArr($entries)) {
2068 + return new WP_Error('invalid_entries', __('Entries id is invalid', 'bit-form'));
2069 + }
2070 +
1802 2071 $formManager = new AdminFormManager($formID);
1803 2072 if (!$formManager->isExist()) {
1804 2073 return new WP_Error('empty_form', __('Form does not exist.', 'bit-form'));
1805 2074 }
@@ -1865,8 +2134,16 @@
1865 2134 if (is_null($formID) || !is_array($entries) || empty($entries)) {
1866 2135 return new WP_Error('empty_form', __('Form id or entries id is invalid', 'bit-form'));
1867 2136 }
1868 2137
2138 + if (!filter_var($formID, FILTER_VALIDATE_INT)) {
2139 + return new WP_Error('invalid_form', __('Form id is invalid', 'bit-form'));
2140 + }
2141 +
2142 + if (!Helpers::checkIsIntArr($entries)) {
2143 + return new WP_Error('invalid_entries', __('Entries id is invalid', 'bit-form'));
2144 + }
2145 +
1869 2146 $formManager = new AdminFormManager($formID);
1870 2147 if (!$formManager->isExist()) {
1871 2148 return new WP_Error('empty_form', __('Form does not exist', 'bit-form'));
1872 2149 }
@@ -2172,8 +2449,17 @@
2172 2449 }
2173 2450 if (empty($formID) || empty($id)) {
2174 2451 return new WP_Error('empty_form', 'Invalid Form ID or Email Template ID.');
2175 2452 }
2453 +
2454 + if (false === filter_var($id, FILTER_VALIDATE_INT)) {
2455 + return new WP_Error('empty_form', 'Invalid Email Template ID.');
2456 + }
2457 +
2458 + if (false === filter_var($formID, FILTER_VALIDATE_INT)) {
2459 + return new WP_Error('empty_form', 'Invalid Form ID.');
2460 + }
2461 +
2176 2462 $emailTemplateHandler = new EmailTemplateHandler($formID);
2177 2463 $duplicate_status = $emailTemplateHandler->duplicateTemplate($id);
2178 2464 if (is_wp_error($duplicate_status)) {
2179 2465 return $duplicate_status;
@@ -2314,22 +2600,34 @@
2314 2600 }
2315 2601 if (is_string($paySetting)) {
2316 2602 $paySetting = json_decode($paySetting);
2317 2603 }
2604 +
2318 2605 $canSave = null;
2319 -
2320 - if ('PayPal' === $paySetting->type) {
2321 - $canSave = $this->addWebhookToPaypal($paySetting);
2322 - } elseif ('Razorpay' === $paySetting->type) {
2323 - $canSave = true;
2324 - } elseif ('Stripe' === $paySetting->type) {
2325 - $canSave = $this->addWebhookToStripe($paySetting);
2606 + switch($paySetting->type) {
2607 + case 'PayPal':
2608 + $canSave = $this->addWebhookToPaypal($paySetting);
2609 + break;
2610 + case 'Razorpay':
2611 + $canSave = true;
2612 + break;
2613 + case 'Stripe':
2614 + $canSave = $this->addWebhookToStripe($paySetting);
2615 + break;
2616 + case 'Mollie':
2617 + $canSave = true;
2618 + break;
2619 + default:
2620 + $canSave = null;
2326 2621 }
2327 2622 if (is_null($canSave)) {
2328 2623 return new WP_Error('stripe', __('Please re-check your Client ID & Secret', 'bit-form'));
2329 2624 }
2330 - $integrationID = $paySetting->id;
2331 - unset($paySetting->id);
2625 + $integrationID = null;
2626 + if (isset($paySetting->id)) {
2627 + $integrationID = $paySetting->id;
2628 + unset($paySetting->id);
2629 + }
2332 2630 $integrationName = $paySetting->name;
2333 2631 $integrationType = 'payments';
2334 2632 $paySetting = wp_json_encode($paySetting);
2335 2633 $integrationDetails = $paySetting;
@@ -2462,6 +2760,25 @@
2462 2760 public function updateSuccessMessageClassName($str, $msgIdx, $msgId)
2463 2761 {
2464 2762 $TEMP_CONF_ID = '_tmp_' . $msgIdx . '_conf_id';
2465 2763 return str_replace($TEMP_CONF_ID, $msgId, $str);
2764 + }
2765 +
2766 + public function startMigrationProcess()
2767 + {
2768 + Utilities::duplicateDbTable('form', 'form_v1');
2769 + Utilities::duplicateDbTable('workflows', 'workflows_v1');
2770 + Utilities::duplicateDbTable('success_messages', 'success_messages_v1');
2771 + MigrationHelper::duplicateV1StyleFiles();
2772 + $all_forms = $this->getAllForm();
2773 + $v1FormContents = [];
2774 + $defaultStyleClass = MigrationHelper::getBitformDefaultStyleClass();
2775 + foreach ($all_forms as $form) {
2776 + $formContents = $this->getAFormV1(['id' => $form->id], ['id' => $form->id]);
2777 + $v1FormContents[] = $formContents;
2778 + FrontEndScriptGenerator::saveCssFile("{$form->id}", $defaultStyleClass);
2779 + FrontEndScriptGenerator::saveCssFile("{$form->id}-formid", $defaultStyleClass);
2780 + }
2781 + set_transient('bitforms_v1_form_contents', $v1FormContents);
2782 + update_option('bitforms_migrating_to_v2', true);
2466 2783 }
2467 2784 }