| @@ -13,32 +13,39 @@ | ||
| 13 | 13 | use BitCode\BitForm\Core\Database\FormEntryMetaModel; |
| 14 | 14 | use BitCode\BitForm\Core\Database\FormEntryModel; |
| 15 | 15 | use BitCode\BitForm\Core\Database\FormModel; |
| 16 | 16 | use BitCode\BitForm\Core\Database\IntegrationModel; |
| 17 | +use BitCode\BitForm\Core\Database\PdfTemplateModel; | |
| 17 | 18 | use BitCode\BitForm\Core\Database\ReportsModel; |
| 18 | 19 | use BitCode\BitForm\Core\Database\SuccessMessageModel; |
| 19 | 20 | use BitCode\BitForm\Core\Database\WorkFlowModel; |
| 20 | 21 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 21 | 22 | use BitCode\BitForm\Core\Messages\EmailTemplateHandler; |
| 23 | +use BitCode\BitForm\Core\Messages\PdfTemplateHandler; | |
| 22 | 24 | use BitCode\BitForm\Core\Messages\SuccessMessageHandler; |
| 25 | +use BitCode\BitForm\Core\Migration\MigrationHelper; | |
| 23 | 26 | use BitCode\BitForm\Core\Util\FileHandler; |
| 24 | 27 | use BitCode\BitForm\Core\Util\FormDuplicateHelper; |
| 25 | 28 | use BitCode\BitForm\Core\Util\HttpHelper; |
| 26 | 29 | use BitCode\BitForm\Core\Util\IpTool; |
| 30 | +use BitCode\BitForm\Core\Util\Utilities; | |
| 31 | +use BitCode\BitForm\Core\WorkFlow\WorkFlow; | |
| 27 | 32 | use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler; |
| 28 | -use BitCode\BitForm\Core\WorkFlow\WorkFlowRunHelper; | |
| 29 | 33 | use WP_Error; |
| 30 | 34 | |
| 31 | -class AdminFormHandler { | |
| 35 | +class AdminFormHandler | |
| 36 | +{ | |
| 32 | 37 | private static $formModel; |
| 33 | 38 | private static $ipTool; |
| 34 | 39 | |
| 35 | - public function __construct() { | |
| 40 | + public function __construct() | |
| 41 | + { | |
| 36 | 42 | static::$formModel = new FormModel(); |
| 37 | 43 | static::$ipTool = new IpTool(); |
| 38 | 44 | } |
| 39 | 45 | |
| 40 | - public function getTemplate($Request, $post) { | |
| 46 | + public function getTemplate($Request, $post) | |
| 47 | + { | |
| 41 | 48 | $templateName = null; |
| 42 | 49 | $newFormId = null; |
| 43 | 50 | if (isset($post->template)) { |
| 44 | 51 | $templateName = $post->template; |
| @@ -49,9 +56,9 @@ | ||
| 49 | 56 | $form_content_raw = $templateProvider->getTemplate($templateName, $newFormId); |
| 50 | 57 | if (!$form_content_raw) { |
| 51 | 58 | return new WP_Error('template_empty', __('Template not found, by this name: ', 'bit-form') . $templateName); |
| 52 | 59 | } else { |
| 53 | - return \json_encode( | |
| 60 | + return wp_json_encode( | |
| 54 | 61 | [ |
| 55 | 62 | 'id' => 0, |
| 56 | 63 | 'form_content' => $form_content_raw, |
| 57 | 64 | ] |
| @@ -58,9 +65,10 @@ | ||
| 58 | 65 | ); |
| 59 | 66 | } |
| 60 | 67 | } |
| 61 | 68 | |
| 62 | - public function saveStyleSheet($styles, $sheetName) { | |
| 69 | + public function saveStyleSheet($styles, $sheetName) | |
| 70 | + { | |
| 63 | 71 | $this->createFormStylesDirIfNotExists(); |
| 64 | 72 | |
| 65 | 73 | if ( |
| 66 | 74 | file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles') |
| @@ -73,9 +81,10 @@ | ||
| 73 | 81 | } |
| 74 | 82 | return false; |
| 75 | 83 | } |
| 76 | 84 | |
| 77 | - public function saveLayoutStyleSheet($layout, $sheetName, $lay_row_height = 43) { | |
| 85 | + public function saveLayoutStyleSheet($layout, $sheetName, $lay_row_height = 43) | |
| 86 | + { | |
| 78 | 87 | $md_width = 600; |
| 79 | 88 | $sm_width = 400; |
| 80 | 89 | $lg_styles = ''; |
| 81 | 90 | $md_styles = ''; |
| @@ -155,9 +164,10 @@ | ||
| 155 | 164 | } |
| 156 | 165 | return false; |
| 157 | 166 | } |
| 158 | 167 | |
| 159 | - public function createFormStylesDirIfNotExists() { | |
| 168 | + public function createFormStylesDirIfNotExists() | |
| 169 | + { | |
| 160 | 170 | if (!file_exists(BITFORMS_UPLOAD_DIR)) { |
| 161 | 171 | wp_mkdir_p(BITFORMS_UPLOAD_DIR); |
| 162 | 172 | } |
| 163 | 173 | if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) { |
| @@ -164,9 +174,18 @@ | ||
| 164 | 174 | wp_mkdir_p(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles'); |
| 165 | 175 | } |
| 166 | 176 | } |
| 167 | 177 | |
| 168 | - public function createNewForm($Request, $post) { | |
| 178 | + private function pdfFontDownload($fontName) | |
| 179 | + { | |
| 180 | + if (class_exists('\BitCode\BitFormPro\Admin\AppSetting\Pdf')) { | |
| 181 | + \BitCode\BitFormPro\Admin\AppSetting\Pdf::getInstance()->fontsDownload($fontName); | |
| 182 | + } | |
| 183 | + return false; | |
| 184 | + } | |
| 185 | + | |
| 186 | + public function createNewForm($Request, $post) | |
| 187 | + { | |
| 169 | 188 | // wp_send_json_success($post); |
| 170 | 189 | // exit; |
| 171 | 190 | if (!isset($post->form_id) || '' === $post->form_id) { |
| 172 | 191 | return new WP_Error('empty_form', __('Error Occurred, Please Reload', 'bit-form')); |
| @@ -197,10 +216,14 @@ | ||
| 197 | 216 | $this->saveLayoutStyleSheet($post->layout, $sheetName, $rowHeight); |
| 198 | 217 | } |
| 199 | 218 | |
| 200 | 219 | $fields = wp_unslash($post->fields); |
| 220 | + // $fields = $post->fields; | |
| 201 | 221 | $layout = wp_unslash($post->layout); |
| 222 | + $nestedLayout = isset($post->nestedLayouts) ? wp_unslash($post->nestedLayouts) : (object) []; | |
| 223 | + $formInfo = wp_unslash($post->formInfo); | |
| 202 | 224 | $form_name = wp_unslash($post->form_name); |
| 225 | + $form_name = strlen($form_name) > 50 ? substr($form_name, 0, 50) : $form_name; | |
| 203 | 226 | $formSettings = (object) wp_unslash($post->formSettings); |
| 204 | 227 | $atomic_class_map = isset($post->atomicClassMap) ? wp_unslash($post->atomicClassMap) : []; |
| 205 | 228 | $breakpointSize = wp_unslash($post->breakpointSize); |
| 206 | 229 | $style = $post->style; |
| @@ -212,9 +235,11 @@ | ||
| 212 | 235 | $reports = !empty($post->reports) ? $post->reports : (object) []; |
| 213 | 236 | $builderSettings = (object) isset($post->builderSettings) ? wp_unslash($post->builderSettings) : []; |
| 214 | 237 | |
| 215 | 238 | $mailTem = $formSettings->mailTem; |
| 239 | + $pdfTem = $formSettings->pdfTem; | |
| 216 | 240 | $integrations = $formSettings->integrations; |
| 241 | + $formPermissions = $formSettings->formPermissions; | |
| 217 | 242 | |
| 218 | 243 | $user_details = static::$ipTool->getUserDetail(); |
| 219 | 244 | if (empty($fields) || empty($layout)) { |
| 220 | 245 | return new WP_Error( |
| @@ -228,10 +253,12 @@ | ||
| 228 | 253 | __('Form Name Should Be Within 50 Characters', 'bit-form') |
| 229 | 254 | ); |
| 230 | 255 | } |
| 231 | 256 | $form_content = [ |
| 232 | - 'fields' => $fields, | |
| 233 | - 'layout' => $layout, | |
| 257 | + 'fields' => $fields, | |
| 258 | + 'layout' => $layout, | |
| 259 | + 'nestedLayout' => $nestedLayout, | |
| 260 | + 'formInfo' => $formInfo, | |
| 234 | 261 | ]; |
| 235 | 262 | |
| 236 | 263 | /* if (!empty($formSettings->submitBtn)) { |
| 237 | 264 | $form_content = array_merge($form_content, array('buttons' => $formSettings->submitBtn)); |
| @@ -239,20 +266,26 @@ | ||
| 239 | 266 | if (!empty($formSettings->theme)) { |
| 240 | 267 | $form_content = array_merge($form_content, ['theme' => $formSettings->theme]); |
| 241 | 268 | } |
| 242 | 269 | |
| 270 | + if (!empty($formSettings->formPermissions)) { | |
| 271 | + $form_content = array_merge($form_content, ['formPermissions' => $formSettings->formPermissions]); | |
| 272 | + } | |
| 273 | + | |
| 243 | 274 | if (!empty($additional)) { |
| 244 | 275 | $form_content = array_merge($form_content, ['additional' => $additional]); |
| 245 | 276 | } |
| 246 | 277 | if (!empty($workFlows)) { |
| 247 | - $workFlowsStr = is_string($workFlows) ? $workFlows : json_encode($workFlows); | |
| 278 | + $workflows = is_string($workFlows) ? json_decode($workFlows) : $workFlows; | |
| 248 | 279 | $workFlowExist = []; |
| 249 | - if (\strpos($workFlowsStr, 'onload')) { | |
| 250 | - $workFlowExist['onload'] = true; | |
| 280 | + foreach ($workflows as $index => $workFlow) { | |
| 281 | + if (in_array($workFlow->action_type, ['always', 'onload'])) { | |
| 282 | + $workFlowExist['onload'] = true; | |
| 283 | + } | |
| 284 | + if ('oninput' === $workFlow->action_type || ('always' === $workFlow->action_type && 'cond' === $workFlow->action_behaviour)) { | |
| 285 | + $workFlowExist['oninput'] = true; | |
| 286 | + } | |
| 251 | 287 | } |
| 252 | - if (\strpos($workFlowsStr, 'oninput')) { | |
| 253 | - $workFlowExist['oninput'] = true; | |
| 254 | - } | |
| 255 | 288 | $form_content = array_merge($form_content, ['workFlowExist' => $workFlowExist]); |
| 256 | 289 | } |
| 257 | 290 | $form_content = \wp_json_encode($form_content); |
| 258 | 291 | |
| @@ -296,9 +329,9 @@ | ||
| 296 | 329 | $successMessageHandler = new SuccessMessageHandler($formID, $user_details); |
| 297 | 330 | foreach ($successMessages as $messageKey => $messageDetail) { |
| 298 | 331 | $savedID = $successMessageHandler->saveMessage($messageDetail); |
| 299 | 332 | if ($savedID) { |
| 300 | - $msgIdx = empty($messageDetail->id) ? $messageKey : \json_encode(['id' => $messageDetail->id]); | |
| 333 | + $msgIdx = empty($messageDetail->id) ? $messageKey : wp_json_encode(['id' => $messageDetail->id]); | |
| 301 | 334 | $integartionIDForWorkflow['successMsg'][$msgIdx] = $savedID; |
| 302 | 335 | $messageDetail->id = $savedID; |
| 303 | 336 | $style = $this->updateSuccessMessageClassName($style, $messageKey, $savedID); |
| 304 | 337 | $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID); |
| @@ -311,11 +344,13 @@ | ||
| 311 | 344 | 'themeColors' => $themeColors, |
| 312 | 345 | 'builderSettings' => $builderSettings |
| 313 | 346 | ]; |
| 314 | 347 | $update_status = static::$formModel->update( |
| 315 | - ['builder_helper_state' => \wp_json_encode($builder_helper_state), | |
| 316 | - 'atomic_class_map' => $atomic_class_map, ], | |
| 317 | 348 | [ |
| 349 | + 'builder_helper_state' => \wp_json_encode($builder_helper_state), | |
| 350 | + 'atomic_class_map' => $atomic_class_map, | |
| 351 | + ], | |
| 352 | + [ | |
| 318 | 353 | 'id' => $formID, |
| 319 | 354 | ] |
| 320 | 355 | ); |
| 321 | 356 | if (is_wp_error($update_status)) { |
| @@ -331,14 +366,39 @@ | ||
| 331 | 366 | = new EmailTemplateHandler($formID, $user_details); |
| 332 | 367 | foreach ($mailTem as $templateKey => $templateDetail) { |
| 333 | 368 | $savedID = $emailTemplateHandler->saveTemplate($templateDetail); |
| 334 | 369 | if ($savedID) { |
| 335 | - $tempIdx = empty($templateDetail->id) ? $templateKey : \json_encode(['id' => $templateDetail->id]); | |
| 370 | + $tempIdx = empty($templateDetail->id) ? $templateKey : wp_json_encode(['id' => $templateDetail->id]); | |
| 336 | 371 | $integartionIDForWorkflow['mailNotify'][$tempIdx] = $savedID; |
| 337 | 372 | } |
| 338 | 373 | } |
| 339 | 374 | } |
| 340 | 375 | // Email Template [end] */ |
| 376 | + | |
| 377 | + // PDF Template [start] | |
| 378 | + if (!empty($pdfTem)) { | |
| 379 | + $pdfTemplateHandler = new PdfTemplateHandler($formID); | |
| 380 | + $workFlowString = ''; | |
| 381 | + if (!empty($workFlows)) { | |
| 382 | + $workFlowString = wp_json_encode($workFlows); | |
| 383 | + } | |
| 384 | + foreach ($pdfTem as $templateDetail) { | |
| 385 | + $savedID = $pdfTemplateHandler->save($templateDetail); | |
| 386 | + | |
| 387 | + $pdfSetting = $templateDetail->setting; | |
| 388 | + | |
| 389 | + if (isset($pdfSetting->font->name) && !empty($pdfSetting->font->name)) { | |
| 390 | + $this->pdfFontDownload($pdfSetting->font->name); | |
| 391 | + } | |
| 392 | + if (!empty($workFlowString)) { | |
| 393 | + $workFlowString = str_replace('"pdfId":"{\"id\":\"' . $templateDetail->id . '\"}"', '"pdfId":"{\"id\":\"' . $savedID . '\"}"', $workFlowString); | |
| 394 | + } | |
| 395 | + } | |
| 396 | + if (!empty($workFlowString) && !empty($workFlows)) { | |
| 397 | + $workFlows = json_decode($workFlowString); | |
| 398 | + } | |
| 399 | + } | |
| 400 | + // PDF Template [end] */ | |
| 341 | 401 | //Integration [start] */ |
| 342 | 402 | $integrationHandler = new IntegrationHandler($formID, $user_details); |
| 343 | 403 | if (!empty($formSettings->confirmation->type)) { |
| 344 | 404 | $allIntegrations = $formSettings->confirmation->type; |
| @@ -355,9 +415,9 @@ | ||
| 355 | 415 | $integrationDetails = !is_string($singleIntegrationDetail->details) ? |
| 356 | 416 | wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details; |
| 357 | 417 | } |
| 358 | 418 | $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form'); |
| 359 | - $integIdx = empty($singleIntegrationDetail->id) ? $savedID : \json_encode(['id' => $singleIntegrationDetail->id]); | |
| 419 | + $integIdx = empty($singleIntegrationDetail->id) ? $savedID : wp_json_encode(['id' => $singleIntegrationDetail->id]); | |
| 360 | 420 | $integartionIDForWorkflow[$integrationType][$integIdx] = $savedID; |
| 361 | 421 | } |
| 362 | 422 | } |
| 363 | 423 | } |
| @@ -376,9 +436,9 @@ | ||
| 376 | 436 | $integrationDetails = !is_string($singleIntegrationDetail->details) ? |
| 377 | 437 | wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details; |
| 378 | 438 | } |
| 379 | 439 | $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form'); |
| 380 | - $integIdx = empty($singleIntegrationDetailID) ? $singleIntegrationKey : \json_encode(['id' => $singleIntegrationDetailID]); | |
| 440 | + $integIdx = empty($singleIntegrationDetailID) ? $singleIntegrationKey : wp_json_encode(['id' => $singleIntegrationDetailID]); | |
| 381 | 441 | $integartionIDForWorkflow['integ'][$integIdx] = $savedID; |
| 382 | 442 | } |
| 383 | 443 | } |
| 384 | 444 | //Integrations [end] |
| @@ -400,9 +460,9 @@ | ||
| 400 | 460 | } |
| 401 | 461 | //wrokFlows [end] |
| 402 | 462 | $details = [ |
| 403 | 463 | 'report_name' => 'All Entries', |
| 404 | - 'hiddenColumns' => [], | |
| 464 | + 'hiddenColumns' => ['__user_id', '__user_ip', '__referer', '__user_device', '__created_at', '__updated_at'], | |
| 405 | 465 | 'pageSize' => 10, |
| 406 | 466 | 'sortBy' => [], |
| 407 | 467 | 'filters' => [], |
| 408 | 468 | 'globalFilter' => '', |
| @@ -434,20 +494,11 @@ | ||
| 434 | 494 | return $updated_data; |
| 435 | 495 | } |
| 436 | 496 | } |
| 437 | 497 | |
| 438 | - public function updateForm($Request, $post) { | |
| 439 | - // wp_send_json_success($post); | |
| 440 | - if ($post->formStyle) { | |
| 441 | - $sheetName = 'bitform-' . $post->id . '.css'; | |
| 442 | - $this->saveStyleSheet($post->formStyle, $sheetName); | |
| 443 | - } | |
| 444 | - | |
| 445 | - if ($post->layoutChanged) { | |
| 446 | - $sheetName = 'bitform-layout-' . $post->id . '.css'; | |
| 447 | - $rowHeight = (int)$post->rowHeight; | |
| 448 | - $this->saveLayoutStyleSheet($post->layout, $sheetName, $rowHeight); | |
| 449 | - } | |
| 498 | + public function updateForm($Request, $post) | |
| 499 | + { | |
| 500 | + // return ['checked dta'=>$post]; | |
| 450 | 501 | $formId = $post->id; |
| 451 | 502 | // get the builder_helper_state from the form |
| 452 | 503 | $builder_helper_state = self::$formModel->get(['builder_helper_state'], ['id' => $formId]); |
| 453 | 504 | $builder_helper_state = (!is_wp_error($builder_helper_state) && 1 === count($builder_helper_state) && isset($builder_helper_state[0]->builder_helper_state)) ? $builder_helper_state[0]->builder_helper_state : '{}'; |
| @@ -476,8 +527,10 @@ | ||
| 476 | 527 | |
| 477 | 528 | if (property_exists($post, 'fields') && null !== $post->fields && property_exists($post, 'layout') && $post->layout) { |
| 478 | 529 | $fields = wp_unslash($post->fields); |
| 479 | 530 | $layout = wp_unslash($post->layout); |
| 531 | + $nestedLayout = wp_unslash($post->nestedLayouts); | |
| 532 | + $formInfo = wp_unslash($post->formInfo); | |
| 480 | 533 | $formID = wp_unslash($post->id); |
| 481 | 534 | $form_name = wp_unslash($post->form_name); |
| 482 | 535 | $formSettings = wp_unslash($post->formSettings); |
| 483 | 536 | $workFlows = wp_unslash($post->workFlows); |
| @@ -485,11 +538,13 @@ | ||
| 485 | 538 | $reports = wp_unslash($post->currentReport); |
| 486 | 539 | } |
| 487 | 540 | |
| 488 | 541 | $mailTem = $formSettings->mailTem; |
| 542 | + $pdfTem = isset($formSettings->pdfTem) ? $formSettings->pdfTem : []; | |
| 489 | 543 | $integrations = $formSettings->integrations; |
| 490 | 544 | |
| 491 | 545 | $user_details = static::$ipTool->getUserDetail(); |
| 546 | + | |
| 492 | 547 | if (empty($fields) || empty($layout) || is_null($formID)) { |
| 493 | 548 | return new WP_Error('empty_form', 'Can not update empty form.'); |
| 494 | 549 | } |
| 495 | 550 | |
| @@ -500,12 +555,16 @@ | ||
| 500 | 555 | __('You are allowed to add maximum 2 workflows ', 'bit-form') |
| 501 | 556 | ); |
| 502 | 557 | } |
| 503 | 558 | } |
| 559 | + | |
| 504 | 560 | $form_content = [ |
| 505 | - 'fields' => $fields, | |
| 506 | - 'layout' => $layout, | |
| 561 | + 'fields' => $fields, | |
| 562 | + 'layout' => $layout, | |
| 563 | + 'nestedLayout' => $nestedLayout, | |
| 564 | + 'formInfo' => $formInfo, | |
| 507 | 565 | ]; |
| 566 | + | |
| 508 | 567 | if (isset($post->report_id)) { |
| 509 | 568 | $form_content['report_id'] = wp_unslash($post->report_id); |
| 510 | 569 | } |
| 511 | 570 | |
| @@ -514,8 +573,12 @@ | ||
| 514 | 573 | } */ |
| 515 | 574 | if (!empty($formSettings->theme)) { |
| 516 | 575 | $form_content = array_merge($form_content, ['theme' => $formSettings->theme]); |
| 517 | 576 | } |
| 577 | + | |
| 578 | + if (!empty($formSettings->formPermissions)) { | |
| 579 | + $form_content = array_merge($form_content, ['formPermissions' => $formSettings->formPermissions]); | |
| 580 | + } | |
| 518 | 581 | if (!empty($additional)) { |
| 519 | 582 | $form_content = array_merge($form_content, ['additional' => $additional]); |
| 520 | 583 | } |
| 521 | 584 | $integartionIDForWorkflow = []; |
| @@ -523,8 +586,9 @@ | ||
| 523 | 586 | $newData['integation'] = 0; |
| 524 | 587 | $newData['mailTemplate'] = 0; |
| 525 | 588 | $newData['workflow'] = 0; |
| 526 | 589 | $newData['reports'] = 0; |
| 590 | + $newData['pdfTemplate'] = 0; | |
| 527 | 591 | // Confiramtion Message [start] |
| 528 | 592 | if (!empty($formSettings->confirmation->type->successMsg)) { |
| 529 | 593 | $successMessages = $formSettings->confirmation->type->successMsg; |
| 530 | 594 | $successMessageHandler |
| @@ -547,9 +611,9 @@ | ||
| 547 | 611 | } |
| 548 | 612 | unset($formSettings->confirmation->type->successMsg); |
| 549 | 613 | } |
| 550 | 614 | // return $formSettings; |
| 551 | - // Confiramtion Message [end] */ | |
| 615 | + // Confirmation Message [end] */ | |
| 552 | 616 | // Email Template [start] |
| 553 | 617 | if (!empty($mailTem)) { |
| 554 | 618 | $emailTemplateHandler |
| 555 | 619 | = new EmailTemplateHandler($formID, $user_details); |
| @@ -568,8 +632,25 @@ | ||
| 568 | 632 | } |
| 569 | 633 | } |
| 570 | 634 | // return $formSettings; |
| 571 | 635 | // Email Template [end] */ |
| 636 | + if (!empty($pdfTem)) { | |
| 637 | + $pdfTemplateHandler = new PdfTemplateHandler($formID); | |
| 638 | + | |
| 639 | + foreach ($pdfTem as $templateKey => $templateDetail) { | |
| 640 | + if (isset($templateDetail->setting->font->name)) { | |
| 641 | + $this->pdfFontDownload($templateDetail->setting->font->name); | |
| 642 | + } | |
| 643 | + | |
| 644 | + $savedID = $pdfTemplateHandler->saveOrUpdate($templateDetail); | |
| 645 | + if (is_wp_error($savedID) && 'result_empty' === $savedID->get_error_code()) { | |
| 646 | + $newData['pdfTemplate'] = 2; | |
| 647 | + } else { | |
| 648 | + $newData['pdfTemplate'] = 1; | |
| 649 | + $integartionIDForWorkflow['pdfTem'][$templateKey] = $savedID; | |
| 650 | + } | |
| 651 | + } | |
| 652 | + } | |
| 572 | 653 | //Integration [start] */ |
| 573 | 654 | $integrationHandler = new IntegrationHandler($formID, $user_details); |
| 574 | 655 | if (!empty($formSettings->confirmation->type)) { |
| 575 | 656 | $allIntegrations = $formSettings->confirmation->type; |
| @@ -632,16 +713,18 @@ | ||
| 632 | 713 | $workFlowExist = []; |
| 633 | 714 | if (!empty($workFlows)) { |
| 634 | 715 | $workFlowHandler = new WorkFlowHandler($formID, $user_details); |
| 635 | 716 | // foreach ($workFlows as $workFlowIndex => $workFlow) { |
| 717 | + $workflows = is_string($workFlows) ? json_decode($workFlows) : $workFlows; | |
| 636 | 718 | |
| 637 | - foreach ($workFlows as $index => $workFlow) { | |
| 638 | - if ('onload' === $workFlow->action_type) { | |
| 719 | + foreach ($workflows as $index => $workFlow) { | |
| 720 | + if (in_array($workFlow->action_type, ['always', 'onload'])) { | |
| 639 | 721 | $workFlowExist['onload'] = true; |
| 640 | 722 | } |
| 641 | - if ('oninput' === $workFlow->action_type) { | |
| 723 | + if ('oninput' === $workFlow->action_type || ('always' === $workFlow->action_type && 'cond' === $workFlow->action_behaviour)) { | |
| 642 | 724 | $workFlowExist['oninput'] = true; |
| 643 | 725 | } |
| 726 | + // $integartionIDForWorkflow = apply_filters('bitform_filter_integration_id', $workFlow, $formID, $index); | |
| 644 | 727 | if (empty($workFlow->id)) { |
| 645 | 728 | $savedID = $workFlowHandler->saveworkFlow($workFlow, $integartionIDForWorkflow, $index); |
| 646 | 729 | if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) { |
| 647 | 730 | $newData['workflow'] = 2; |
| @@ -648,9 +731,9 @@ | ||
| 648 | 731 | } else { |
| 649 | 732 | $newData['workflow'] = 1; |
| 650 | 733 | } |
| 651 | 734 | } else { |
| 652 | - $newData = $workFlowHandler->updateworkFlow($workFlow->id, $workFlow, $integartionIDForWorkflow, $index, $newData); | |
| 735 | + $newData = $workFlowHandler->updateworkFlow($workFlow->id, $workFlow, $integartionIDForWorkflow, $index, $newData); | |
| 653 | 736 | } |
| 654 | 737 | } |
| 655 | 738 | } |
| 656 | 739 | $form_content = array_merge($form_content, ['workFlowExist' => $workFlowExist]); |
| @@ -701,8 +784,26 @@ | ||
| 701 | 784 | ); |
| 702 | 785 | } |
| 703 | 786 | } |
| 704 | 787 | //reports [end] |
| 788 | + //form abandonment [start] | |
| 789 | + if (!empty($formSettings->formAbandonment)) { | |
| 790 | + $formAbandonment = $formSettings->formAbandonment; | |
| 791 | + // search for existing form abandonment in integration table | |
| 792 | + $abandonmentInteg = $integrationHandler->getAllIntegration('formAbandonment', 'formAbandonment'); | |
| 793 | + if (!is_wp_error($abandonmentInteg) && !empty($abandonmentInteg)) { | |
| 794 | + $abandonmentInteg = $abandonmentInteg[0]; | |
| 795 | + } | |
| 796 | + if (isset($abandonmentInteg->id)) { | |
| 797 | + $abandonmentIntegID = $abandonmentInteg->id; | |
| 798 | + $abandonmentIntegDetails = wp_json_encode($formAbandonment); | |
| 799 | + $integrationHandler->updateIntegration($abandonmentIntegID, 'formAbandonment', 'formAbandonment', $abandonmentIntegDetails, 'formAbandonment'); | |
| 800 | + } else { | |
| 801 | + $abandonmentIntegDetails = wp_json_encode($formAbandonment); | |
| 802 | + $integrationHandler->saveIntegration('formAbandonment', 'formAbandonment', $abandonmentIntegDetails, 'formAbandonment'); | |
| 803 | + } | |
| 804 | + } | |
| 805 | + //form abandonment [end] | |
| 705 | 806 | $form_content = wp_json_encode($form_content); |
| 706 | 807 | $updateData = [ |
| 707 | 808 | 'form_name' => $form_name, |
| 708 | 809 | 'form_content' => $form_content, |
| @@ -710,9 +811,8 @@ | ||
| 710 | 811 | 'user_ip' => $user_details['ip'], |
| 711 | 812 | 'builder_helper_state' => \wp_json_encode((object)$builder_helper_state), |
| 712 | 813 | 'generated_script_page_ids' => \wp_json_encode((object) []), |
| 713 | 814 | 'user_device' => $user_details['device'], |
| 714 | - 'status' => 1, | |
| 715 | 815 | 'updated_at' => $user_details['time'], |
| 716 | 816 | ]; |
| 717 | 817 | if (isset($atomic_class_map)) { |
| 718 | 818 | $updateData['atomic_class_map'] = $atomic_class_map; |
| @@ -741,9 +841,10 @@ | ||
| 741 | 841 | unset($post->deletedFldKey); |
| 742 | 842 | } |
| 743 | 843 | |
| 744 | 844 | $updated_data = $this->getAForm(['id' => $formID], null); |
| 745 | - if (0 === $newData['settingConfiramation'] && 0 === $newData['mailTemplate'] && 0 === $newData['integation']) { | |
| 845 | + | |
| 846 | + if (0 === $newData['settingConfiramation'] && 0 === $newData['mailTemplate'] && 0 === $newData['integation'] && 0 === $newData['pdfTemplate']) { | |
| 746 | 847 | unset($updated_data['formSettings']); |
| 747 | 848 | } |
| 748 | 849 | if (0 === $newData['integation']) { |
| 749 | 850 | unset($updated_data['integrations']); |
| @@ -755,8 +856,13 @@ | ||
| 755 | 856 | unset($updated_data['mailTem']); |
| 756 | 857 | } elseif (2 === $newData['mailTemplate']) { |
| 757 | 858 | $errorIN .= empty($errorIN) ? 'mailTemplate' : ', mailTemplate'; |
| 758 | 859 | } |
| 860 | + if (0 === $newData['pdfTemplate']) { | |
| 861 | + unset($updated_data['pdfTem']); | |
| 862 | + } elseif (2 === $newData['pdfTemplate']) { | |
| 863 | + $errorIN .= empty($errorIN) ? 'pdfTemplate' : ', pdfTemplate'; | |
| 864 | + } | |
| 759 | 865 | if (0 === $newData['workflow']) { |
| 760 | 866 | unset($updated_data['workFlows']); |
| 761 | 867 | } elseif (2 === $newData['workflow']) { |
| 762 | 868 | $errorIN .= empty($errorIN) ? 'workflow' : ', workflow'; |
| @@ -775,9 +881,10 @@ | ||
| 775 | 881 | return $updated_data; |
| 776 | 882 | } |
| 777 | 883 | } |
| 778 | 884 | |
| 779 | - public function setEmptyMetaValue($fieldkeys) { | |
| 885 | + public function setEmptyMetaValue($fieldkeys) | |
| 886 | + { | |
| 780 | 887 | $sqlEscaped = array_map(function ($fld) { |
| 781 | 888 | return "'" . esc_sql($fld) . "'"; |
| 782 | 889 | }, $fieldkeys); |
| 783 | 890 | $deletedFldKey = implode(',', $sqlEscaped); |
| @@ -786,95 +893,99 @@ | ||
| 786 | 893 | $sql = $wpdb->prepare("UPDATE $tablename SET meta_value = %s WHERE meta_key IN ( " . $deletedFldKey . ')', ''); |
| 787 | 894 | $wpdb->query($sql); |
| 788 | 895 | } |
| 789 | 896 | |
| 790 | - public function changeFormStatus($Request, $post) { | |
| 791 | - if (isset($Request['status']) && $Request['id']) { | |
| 792 | - $status = wp_unslash($Request['status']); | |
| 793 | - $id = wp_unslash($Request['id']); | |
| 794 | - } else { | |
| 795 | - $status = wp_unslash($post->status); | |
| 796 | - $id = wp_unslash($post->id); | |
| 797 | - } | |
| 798 | - $user_details = static::$ipTool->getUserDetail(); | |
| 799 | - // return $post->fields; | |
| 800 | - $status = 'true' === $status || true === $status ? true : false; | |
| 801 | - if (!is_bool($status) || is_null($id)) { | |
| 802 | - // echo $status; | |
| 803 | - return new WP_Error('status_change', __('Form status change failed.', 'bit-form')); | |
| 804 | - } | |
| 805 | - $update_status = static::$formModel->update( | |
| 806 | - [ | |
| 807 | - 'user_id' => $user_details['id'], | |
| 808 | - 'user_ip' => $user_details['ip'], | |
| 809 | - 'user_device' => $user_details['device'], | |
| 810 | - 'status' => $status ? 1 : 0, | |
| 811 | - 'updated_at' => $user_details['time'], | |
| 812 | - ], | |
| 813 | - [ | |
| 814 | - 'id' => $id, | |
| 815 | - ] | |
| 816 | - ); | |
| 817 | - if (is_wp_error($update_status)) { | |
| 818 | - return $update_status; | |
| 819 | - } elseif (!$update_status) { | |
| 820 | - return false; | |
| 821 | - } else { | |
| 822 | - return __('Form status changed successfully', 'bit-form'); | |
| 823 | - } | |
| 897 | + public function changeFormStatus($Request, $post) | |
| 898 | + { | |
| 899 | + if (isset($Request['status']) && $Request['id']) { | |
| 900 | + $status = wp_unslash($Request['status']); | |
| 901 | + $id = wp_unslash($Request['id']); | |
| 902 | + } else { | |
| 903 | + $status = wp_unslash($post->status); | |
| 904 | + $id = wp_unslash($post->id); | |
| 824 | 905 | } |
| 906 | + $user_details = static::$ipTool->getUserDetail(); | |
| 907 | + // return $post->fields; | |
| 908 | + $status = 'true' === $status || true === $status ? true : false; | |
| 909 | + if (!is_bool($status) || is_null($id)) { | |
| 910 | + // echo $status; | |
| 911 | + return new WP_Error('status_change', __('Form status change failed.', 'bit-form')); | |
| 912 | + } | |
| 913 | + $update_status = static::$formModel->update( | |
| 914 | + [ | |
| 915 | + 'user_id' => $user_details['id'], | |
| 916 | + 'user_ip' => $user_details['ip'], | |
| 917 | + 'user_device' => $user_details['device'], | |
| 918 | + 'status' => $status ? 1 : 0, | |
| 919 | + 'updated_at' => $user_details['time'], | |
| 920 | + ], | |
| 921 | + [ | |
| 922 | + 'id' => $id, | |
| 923 | + ] | |
| 924 | + ); | |
| 925 | + if (is_wp_error($update_status)) { | |
| 926 | + return $update_status; | |
| 927 | + } elseif (!$update_status) { | |
| 928 | + return false; | |
| 929 | + } else { | |
| 930 | + return __('Form status changed successfully', 'bit-form'); | |
| 931 | + } | |
| 932 | + } | |
| 825 | 933 | |
| 826 | - public function changeBulkFormStatus($Request, $post) { | |
| 827 | - if (isset($Request['status']) && $Request['formID']) { | |
| 828 | - $status = wp_unslash($Request['status']); | |
| 829 | - $formID = wp_unslash($Request['formID']); | |
| 830 | - } else { | |
| 831 | - $status = wp_unslash($post->status); | |
| 832 | - $formID = wp_unslash($post->formID); | |
| 833 | - } | |
| 834 | - $user_details = static::$ipTool->getUserDetail(); | |
| 835 | - // return $post->fields; | |
| 836 | - $status = 'true' === $status || true === $status ? true : false; | |
| 837 | - if (!is_bool($status) || is_null($formID) || !is_array($formID)) { | |
| 838 | - // echo $status; | |
| 839 | - return new WP_Error('status_change', __('Form status change failed.', 'bit-form')); | |
| 840 | - } | |
| 841 | - $update_status = static::$formModel->bulkUpdate( | |
| 842 | - [ | |
| 843 | - 'user_id' => $user_details['id'], | |
| 844 | - 'user_ip' => $user_details['ip'], | |
| 845 | - 'user_device' => $user_details['device'], | |
| 846 | - 'status' => $status ? 1 : 0, | |
| 847 | - 'updated_at' => $user_details['time'], | |
| 848 | - ], | |
| 849 | - [ | |
| 850 | - 'id' => $formID, | |
| 851 | - ] | |
| 852 | - ); | |
| 853 | - if (is_wp_error($update_status)) { | |
| 854 | - return $update_status; | |
| 855 | - } elseif (!$update_status) { | |
| 856 | - return false; | |
| 857 | - } else { | |
| 858 | - return __('Form status changed successfully', 'bit-form'); | |
| 859 | - } | |
| 934 | + public function changeBulkFormStatus($Request, $post) | |
| 935 | + { | |
| 936 | + if (isset($Request['status']) && $Request['formID']) { | |
| 937 | + $status = wp_unslash($Request['status']); | |
| 938 | + $formID = wp_unslash($Request['formID']); | |
| 939 | + } else { | |
| 940 | + $status = wp_unslash($post->status); | |
| 941 | + $formID = wp_unslash($post->formID); | |
| 860 | 942 | } |
| 943 | + $user_details = static::$ipTool->getUserDetail(); | |
| 944 | + // return $post->fields; | |
| 945 | + $status = 'true' === $status || true === $status ? true : false; | |
| 946 | + if (!is_bool($status) || is_null($formID) || !is_array($formID)) { | |
| 947 | + // echo $status; | |
| 948 | + return new WP_Error('status_change', __('Form status change failed.', 'bit-form')); | |
| 949 | + } | |
| 950 | + $update_status = static::$formModel->bulkUpdate( | |
| 951 | + [ | |
| 952 | + 'user_id' => $user_details['id'], | |
| 953 | + 'user_ip' => $user_details['ip'], | |
| 954 | + 'user_device' => $user_details['device'], | |
| 955 | + 'status' => $status ? 1 : 0, | |
| 956 | + 'updated_at' => $user_details['time'], | |
| 957 | + ], | |
| 958 | + [ | |
| 959 | + 'id' => $formID, | |
| 960 | + ] | |
| 961 | + ); | |
| 962 | + if (is_wp_error($update_status)) { | |
| 963 | + return $update_status; | |
| 964 | + } elseif (!$update_status) { | |
| 965 | + return false; | |
| 966 | + } else { | |
| 967 | + return __('Form status changed successfully', 'bit-form'); | |
| 968 | + } | |
| 969 | + } | |
| 861 | 970 | |
| 862 | - public function getAllForm() { | |
| 863 | - global $wpdb; | |
| 971 | + public function getAllForm() | |
| 972 | + { | |
| 973 | + global $wpdb; | |
| 864 | 974 | |
| 865 | - $allForms = $wpdb->get_results("SELECT forms.id,forms.entries as fm_entries,forms.form_name,forms.status,forms.views,forms.created_at,COUNT(entries.id) as entries FROM `{$wpdb->prefix}bitforms_form` as forms LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id GROUP BY forms.id"); | |
| 975 | + $allForms = $wpdb->get_results("SELECT forms.id,forms.entries as fm_entries,forms.form_name,forms.status,forms.views,forms.created_at,COUNT(entries.id) as entries FROM `{$wpdb->prefix}bitforms_form` as forms LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id GROUP BY forms.id"); | |
| 866 | 976 | |
| 867 | - if (is_wp_error($allForms)) { | |
| 868 | - return $allForms; | |
| 869 | - } elseif (!$allForms) { | |
| 870 | - return []; | |
| 871 | - } else { | |
| 872 | - return $allForms; | |
| 873 | - } | |
| 977 | + if (is_wp_error($allForms)) { | |
| 978 | + return $allForms; | |
| 979 | + } elseif (!$allForms) { | |
| 980 | + return []; | |
| 981 | + } else { | |
| 982 | + return $allForms; | |
| 874 | 983 | } |
| 984 | + } | |
| 875 | 985 | |
| 876 | - public function getAForm($Request, $post) { | |
| 986 | + public function getAForm($Request, $post) | |
| 987 | + { | |
| 877 | 988 | if (isset($Request['id'])) { |
| 878 | 989 | $formID = wp_unslash($Request['id']); |
| 879 | 990 | } else { |
| 880 | 991 | $formID = wp_unslash($post->id); |
| @@ -891,8 +1002,10 @@ | ||
| 891 | 1002 | $helper_states = $formManager->getFormHelperStates(); |
| 892 | 1003 | if ($formManager->isExist()) { |
| 893 | 1004 | $form_content_arr = [ |
| 894 | 1005 | 'layout' => $form_content->layout, |
| 1006 | + 'nestedLayout' => !empty($form_content->nestedLayout) ? $form_content->nestedLayout : (object) [], | |
| 1007 | + 'formInfo' => !empty($form_content->formInfo) ? $form_content->formInfo : (object) ['formName' => $formManager->getFormName()], | |
| 895 | 1008 | 'fields' => $form_content->fields, |
| 896 | 1009 | 'form_name' => $formManager->getFormName(), |
| 897 | 1010 | 'workFlowExist' => $form_content->workFlowExist, |
| 898 | 1011 | 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null |
| @@ -925,8 +1038,24 @@ | ||
| 925 | 1038 | 'body' => $emailTemplatevalue->body, |
| 926 | 1039 | ]; |
| 927 | 1040 | } |
| 928 | 1041 | } |
| 1042 | + // get all pdf template | |
| 1043 | + $pdfTemplateHandler = new PdfTemplateHandler($formID); | |
| 1044 | + $pdfTemplates = $pdfTemplateHandler->getAll(); | |
| 1045 | + | |
| 1046 | + if (!is_wp_error($pdfTemplates)) { | |
| 1047 | + foreach ($pdfTemplates as $value) { | |
| 1048 | + $pdfTem[] = | |
| 1049 | + [ | |
| 1050 | + 'id' => $value->id, | |
| 1051 | + 'title' => $value->title, | |
| 1052 | + 'setting' => json_decode($value->setting), | |
| 1053 | + 'body' => $value->body, | |
| 1054 | + ]; | |
| 1055 | + } | |
| 1056 | + } | |
| 1057 | + | |
| 929 | 1058 | $integrationHandler = new IntegrationHandler($formID); |
| 930 | 1059 | $formIntegrations = $integrationHandler->getAllIntegration('form'); |
| 931 | 1060 | if (!is_wp_error($formIntegrations)) { |
| 932 | 1061 | foreach ($formIntegrations as $integrationkey => $integrationValue) { |
| @@ -954,17 +1083,18 @@ | ||
| 954 | 1083 | ]; |
| 955 | 1084 | $integrations[] = array_merge( |
| 956 | 1085 | $integrationData, |
| 957 | 1086 | is_string($integrationValue->integration_details) ? |
| 958 | - (array) json_decode($integrationValue->integration_details) : | |
| 959 | - $integrationValue->integration_details | |
| 1087 | + (array) json_decode($integrationValue->integration_details) : | |
| 1088 | + $integrationValue->integration_details | |
| 960 | 1089 | ); |
| 961 | 1090 | } |
| 962 | 1091 | } |
| 963 | 1092 | } |
| 964 | 1093 | $settingsContent = [ |
| 965 | - 'formName' => $formManager->getFormName(), | |
| 966 | - '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) [], | |
| 967 | 1097 | // 'submitBtn' => $form_content->buttons, |
| 968 | 1098 | ]; |
| 969 | 1099 | |
| 970 | 1100 | if (!empty($allConfirmation)) { |
| @@ -991,8 +1121,9 @@ | ||
| 991 | 1121 | 'integrations' => [] |
| 992 | 1122 | ] |
| 993 | 1123 | ); |
| 994 | 1124 | } |
| 1125 | + | |
| 995 | 1126 | if (!empty($mailTem)) { |
| 996 | 1127 | $settingsContent = array_merge( |
| 997 | 1128 | $settingsContent, |
| 998 | 1129 | [ |
| @@ -1006,8 +1137,24 @@ | ||
| 1006 | 1137 | 'mailTem' => [] |
| 1007 | 1138 | ] |
| 1008 | 1139 | ); |
| 1009 | 1140 | } |
| 1141 | + | |
| 1142 | + if (!empty($pdfTem)) { | |
| 1143 | + $settingsContent = array_merge( | |
| 1144 | + $settingsContent, | |
| 1145 | + [ | |
| 1146 | + 'pdfTem' => $pdfTem, | |
| 1147 | + ] | |
| 1148 | + ); | |
| 1149 | + } else { | |
| 1150 | + $settingsContent = array_merge( | |
| 1151 | + $settingsContent, | |
| 1152 | + [ | |
| 1153 | + 'pdfTem' => [], | |
| 1154 | + ] | |
| 1155 | + ); | |
| 1156 | + } | |
| 1010 | 1157 | $formSettings = [ |
| 1011 | 1158 | 'formSettings' => $settingsContent, |
| 1012 | 1159 | ]; |
| 1013 | 1160 | $data = [ |
| @@ -1095,17 +1242,240 @@ | ||
| 1095 | 1242 | return $data; |
| 1096 | 1243 | } |
| 1097 | 1244 | } |
| 1098 | 1245 | |
| 1099 | - public function deleteAForm($Request, $post) { | |
| 1246 | + public function getAFormV1($Request, $post) | |
| 1247 | + { | |
| 1100 | 1248 | if (isset($Request['id'])) { |
| 1101 | 1249 | $formID = wp_unslash($Request['id']); |
| 1102 | 1250 | } else { |
| 1103 | 1251 | $formID = wp_unslash($post->id); |
| 1104 | 1252 | } |
| 1253 | + // return $post->fields; | |
| 1105 | 1254 | if (is_null($formID)) { |
| 1106 | 1255 | return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); |
| 1107 | 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 | + | |
| 1463 | + public function deleteAForm($Request, $post) | |
| 1464 | + { | |
| 1465 | + if (isset($Request['id'])) { | |
| 1466 | + $formID = wp_unslash($Request['id']); | |
| 1467 | + } else { | |
| 1468 | + $formID = wp_unslash($post->id); | |
| 1469 | + } | |
| 1470 | + if (is_null($formID)) { | |
| 1471 | + return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); | |
| 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 | + | |
| 1108 | 1478 | $delete_status = static::$formModel->delete( |
| 1109 | 1479 | [ |
| 1110 | 1480 | 'id' => $formID, |
| 1111 | 1481 | ] |
| @@ -1110,16 +1480,17 @@ | ||
| 1110 | 1480 | 'id' => $formID, |
| 1111 | 1481 | ] |
| 1112 | 1482 | ); |
| 1113 | 1483 | |
| 1114 | - $successMessageModel | |
| 1115 | - = new SuccessMessageModel(); | |
| 1484 | + $successMessageModel = new SuccessMessageModel(); | |
| 1116 | 1485 | $deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]); |
| 1117 | 1486 | |
| 1118 | - $emailTemplateModel | |
| 1119 | - = new EmailTemplateModel(); | |
| 1487 | + $emailTemplateModel = new EmailTemplateModel(); | |
| 1120 | 1488 | $deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]); |
| 1121 | 1489 | |
| 1490 | + $pdfTemplateModel = new PdfTemplateModel(); | |
| 1491 | + $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]); | |
| 1492 | + | |
| 1122 | 1493 | $integrationModel = new IntegrationModel(); |
| 1123 | 1494 | $deleteIntegrationStatus = $integrationModel->delete(['form_id' => $formID]); |
| 1124 | 1495 | |
| 1125 | 1496 | $workFlowModel = new WorkFlowModel(); |
| @@ -1131,22 +1502,11 @@ | ||
| 1131 | 1502 | $formEntryModel = new FormEntryModel(); |
| 1132 | 1503 | $returnedEntries = $formEntryModel->get('id', ['form_id' => $formID]); |
| 1133 | 1504 | $entries = []; |
| 1134 | 1505 | |
| 1135 | - if (!is_wp_error($returnedEntries)) { | |
| 1136 | - foreach ($returnedEntries as $entryKey => $entryInfo) { | |
| 1137 | - $entries[] = $entryInfo->id; | |
| 1138 | - } | |
| 1139 | - global $wpdb; | |
| 1140 | - $prefix = $wpdb->prefix; | |
| 1141 | - if (count($entries) > 0) { | |
| 1142 | - $deleteEntriesStatus = $formEntryModel->bulkDelete( | |
| 1143 | - [ | |
| 1144 | - "`{$prefix}bitforms_form_entries`.`id`" => $entries, | |
| 1145 | - "`{$prefix}bitforms_form_entries`.`form_id`" => $formID, | |
| 1146 | - ] | |
| 1147 | - ); | |
| 1148 | - } | |
| 1506 | + // checked namespace exist | |
| 1507 | + if (class_exists('\BitCode\BitFormPro\Admin\BfTable\Table')) { | |
| 1508 | + \BitCode\BitFormPro\Admin\BfTable\Table::deleteTableByFormId($formID); | |
| 1149 | 1509 | } |
| 1150 | 1510 | |
| 1151 | 1511 | $fileHandler = new FileHandler(); |
| 1152 | 1512 | if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) { |
| @@ -1154,35 +1514,54 @@ | ||
| 1154 | 1514 | } |
| 1155 | 1515 | if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) { |
| 1156 | 1516 | $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID); |
| 1157 | 1517 | } |
| 1158 | - if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css')) { | |
| 1159 | - unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css'); | |
| 1160 | - } | |
| 1161 | - if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css')) { | |
| 1162 | - unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css'); | |
| 1163 | - } | |
| 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 | + | |
| 1164 | 1535 | return is_wp_error($delete_status) ? $delete_status : __('Form deleted successfully.', 'bit-form'); |
| 1165 | 1536 | } |
| 1166 | 1537 | |
| 1167 | - public function deleteBlukForm($Request, $post) { | |
| 1538 | + public function deleteBlukForm($Request, $post) | |
| 1539 | + { | |
| 1168 | 1540 | if (isset($Request['formID'])) { |
| 1169 | 1541 | $formID = wp_unslash($Request['formID']); |
| 1170 | 1542 | } else { |
| 1171 | 1543 | $formID = wp_unslash($post->formID); |
| 1172 | 1544 | } |
| 1545 | + | |
| 1173 | 1546 | if (is_null($formID) || !is_array($formID)) { |
| 1174 | 1547 | return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); |
| 1175 | 1548 | } |
| 1549 | + | |
| 1550 | + if (!Helpers::checkIsIntArr($formID)) { | |
| 1551 | + return new WP_Error('invalid_form', __('Form id is invalid', 'bit-form')); | |
| 1552 | + } | |
| 1553 | + | |
| 1176 | 1554 | $cssPath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR; |
| 1177 | 1555 | foreach ($formID as $id) { |
| 1178 | - unlink($cssPath . 'bitform-' . $id . '.css'); | |
| 1179 | - if (file_exists($cssPath . 'bitform-layout-' . $id . '.css')) { | |
| 1180 | - unlink($cssPath . 'bitform-layout-' . $id . '.css'); | |
| 1181 | - } | |
| 1182 | - if (file_exists($cssPath . 'bitform-' . $id . '-formid' . '.css')) { | |
| 1183 | - unlink($cssPath . 'bitform-' . $id . '-formid' . '.css'); | |
| 1184 | - } | |
| 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); | |
| 1185 | 1564 | } |
| 1186 | 1565 | $delete_status = static::$formModel->bulkDelete( |
| 1187 | 1566 | [ |
| 1188 | 1567 | 'id' => $formID, |
| @@ -1187,16 +1566,23 @@ | ||
| 1187 | 1566 | [ |
| 1188 | 1567 | 'id' => $formID, |
| 1189 | 1568 | ] |
| 1190 | 1569 | ); |
| 1570 | + | |
| 1571 | + if (is_wp_error($delete_status)) { | |
| 1572 | + wp_send_json_error($delete_status->get_error_message(), 400); | |
| 1573 | + } | |
| 1574 | + | |
| 1191 | 1575 | $successMessageModel |
| 1192 | 1576 | = new SuccessMessageModel(); |
| 1193 | 1577 | $deleteMsgStatus = $successMessageModel->bulkDelete(['form_id' => $formID]); |
| 1194 | 1578 | |
| 1195 | - $emailTemplateModel | |
| 1196 | - = new EmailTemplateModel(); | |
| 1579 | + $emailTemplateModel = new EmailTemplateModel(); | |
| 1197 | 1580 | $deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]); |
| 1198 | 1581 | |
| 1582 | + $pdfTemplateModel = new PdfTemplateModel(); | |
| 1583 | + $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]); | |
| 1584 | + | |
| 1199 | 1585 | $integrationModel = new IntegrationModel(); |
| 1200 | 1586 | $deleteIntegrationStatus = $integrationModel->bulkDelete(['form_id' => $formID]); |
| 1201 | 1587 | |
| 1202 | 1588 | $workFlowModel = new WorkFlowModel(); |
| @@ -1206,11 +1592,18 @@ | ||
| 1206 | 1592 | $deleteReportStatus = $reportsModel->bulkDelete(['context' => $formID]); |
| 1207 | 1593 | |
| 1208 | 1594 | $formEntryModel = new FormEntryModel(); |
| 1209 | 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 | + | |
| 1210 | 1601 | $entries = []; |
| 1211 | 1602 | foreach ($returnedEntries as $entryKey => $entryInfo) { |
| 1212 | - $entries[] = $entryInfo->id; | |
| 1603 | + if (!empty($entryInfo->id)) { | |
| 1604 | + $entries[] = $entryInfo->id; | |
| 1605 | + } | |
| 1213 | 1606 | } |
| 1214 | 1607 | global $wpdb; |
| 1215 | 1608 | $prefix = $wpdb->prefix; |
| 1216 | 1609 | if (count($entries) > 0) { |
| @@ -1226,17 +1619,15 @@ | ||
| 1226 | 1619 | foreach ($formID as $fId) { |
| 1227 | 1620 | if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) { |
| 1228 | 1621 | $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId); |
| 1229 | 1622 | } |
| 1230 | - | |
| 1231 | - // unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $fId . '.css'); | |
| 1232 | - // unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $fId . '.css'); | |
| 1233 | 1623 | } |
| 1234 | 1624 | |
| 1235 | 1625 | return is_wp_error($delete_status) ? $delete_status : __('Forms deleted successfully.', 'bit-form'); |
| 1236 | 1626 | } |
| 1237 | 1627 | |
| 1238 | - public function genarateNewLayoutNField($layout, $fields, $oldId, $newId) { | |
| 1628 | + public function genarateNewLayoutNField($layout, $fields, $oldId, $newId) | |
| 1629 | + { | |
| 1239 | 1630 | $newField = (object) []; |
| 1240 | 1631 | foreach ($layout->lg as $ind => $itm) { |
| 1241 | 1632 | $fld_tmp = $fields->{$layout->lg[$ind]->i}; |
| 1242 | 1633 | $layout->lg[$ind]->i = str_replace("bf$oldId-", "bf$newId-", $layout->lg[$ind]->i); |
| @@ -1246,9 +1637,10 @@ | ||
| 1246 | 1637 | } |
| 1247 | 1638 | return ['layout' => $layout, 'fields' => $newField]; |
| 1248 | 1639 | } |
| 1249 | 1640 | |
| 1250 | - public function duplicateAForm($Request, $post) { | |
| 1641 | + public function duplicateAForm($Request, $post) | |
| 1642 | + { | |
| 1251 | 1643 | $oldFormId = intval($post->id); |
| 1252 | 1644 | $newFormId = intval($post->newFormId); |
| 1253 | 1645 | if ($oldFormId < 1) { |
| 1254 | 1646 | return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); |
| @@ -1290,9 +1682,10 @@ | ||
| 1290 | 1682 | } |
| 1291 | 1683 | return $duplicateResponse; |
| 1292 | 1684 | } |
| 1293 | 1685 | |
| 1294 | - public function importAForm($post) { | |
| 1686 | + public function importAForm($post) | |
| 1687 | + { | |
| 1295 | 1688 | $oldFormId = !empty($post->formDetail->form_id) ? $post->formDetail->form_id : null; |
| 1296 | 1689 | $newFormId = intval($post->newFormId); |
| 1297 | 1690 | if (!$oldFormId || empty($post->formDetail->fields) || empty($post->formDetail->layout)) { |
| 1298 | 1691 | return new WP_Error('invalid_form', __('Please import a valid json.', 'bit-form')); |
| @@ -1299,9 +1692,11 @@ | ||
| 1299 | 1692 | } |
| 1300 | 1693 | $importtedForm = (array)$post->formDetail; |
| 1301 | 1694 | $importtedForm['form_content']['fields'] = $importtedForm['fields']; |
| 1302 | 1695 | $importtedForm['form_content']['layout'] = $importtedForm['layout']; |
| 1303 | - unset($importtedForm['fields'], $importtedForm['layout']); | |
| 1696 | + $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayouts']; | |
| 1697 | + $importtedForm['form_content']['formInfo'] = $importtedForm['formInfo']; | |
| 1698 | + unset($importtedForm['fields'], $importtedForm['layout'], $importtedForm['nestedLayout'], $importtedForm['formInfo']); | |
| 1304 | 1699 | $formData = FormDuplicateHelper::createReplica((array)$importtedForm, $oldFormId, $newFormId); |
| 1305 | 1700 | |
| 1306 | 1701 | if (!empty($importtedForm['rowHeight'])) { |
| 1307 | 1702 | $formData->rowHeight = $importtedForm['rowHeight']; |
| @@ -1312,10 +1707,29 @@ | ||
| 1312 | 1707 | $formData->layoutChanged = '-'; |
| 1313 | 1708 | } |
| 1314 | 1709 | $importResponse = $this->createNewForm(null, $formData); |
| 1315 | 1710 | |
| 1711 | + $customCode = []; | |
| 1712 | + // add custom js | |
| 1713 | + if (!empty($formData->customCode->customJs)) { | |
| 1714 | + $customJsPath = 'form-scripts'; | |
| 1715 | + $fileName = 'bitform-custom-' . $newFormId . '.js'; | |
| 1716 | + $customCode['JavaScript'] = $formData->customCode->customJs; | |
| 1717 | + Helpers::saveFile($customJsPath, $fileName, $formData->customCode->customJs, 'w'); | |
| 1718 | + } | |
| 1719 | + // add custom css | |
| 1720 | + if (!empty($formData->customCode->customCss)) { | |
| 1721 | + $customCssPath = 'form-styles'; | |
| 1722 | + $fileName = 'bitform-custom-' . $newFormId . '.css'; | |
| 1723 | + $customCode['CSS'] = $formData->customCode->customCss; | |
| 1724 | + Helpers::saveFile($customCssPath, $fileName, $formData->customCode->customCss, 'w'); | |
| 1725 | + } | |
| 1726 | + if (!is_wp_error($importResponse)) { | |
| 1727 | + $importResponse['customCode'] = $customCode; | |
| 1728 | + } | |
| 1316 | 1729 | if (!is_wp_error($importResponse) || (is_wp_error($importResponse) && 'result_empty' === $importResponse->get_error_code())) { |
| 1317 | 1730 | $responseData = $this->getAForm(null, (object) ['id' => $newFormId]); |
| 1731 | + $responseData['customCode'] = $customCode; | |
| 1318 | 1732 | $responseData['message'] = __('Form imported successfully.', 'bit-form'); |
| 1319 | 1733 | return $responseData; |
| 1320 | 1734 | } |
| 1321 | 1735 | return $importResponse; |
| @@ -1342,9 +1756,9 @@ | ||
| 1342 | 1756 | // $formData->formStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr); |
| 1343 | 1757 | // $formData->layoutChanged = '-'; |
| 1344 | 1758 | // $formData->rowHeight = FormDuplicateHelper::calcRowHeight($styleStr, $oldFormId); |
| 1345 | 1759 | |
| 1346 | - // $formJson = json_encode($formData); | |
| 1760 | + // $formJson = wp_json_encode($formData); | |
| 1347 | 1761 | // header('Content-Type: application/force-download'); |
| 1348 | 1762 | // header('Content-Type: application/octet-stream'); |
| 1349 | 1763 | // header('Content-Type: application/download'); |
| 1350 | 1764 | // header('Content-Disposition: attachment; filename="bitform_export_' . $oldFormId . '.json"'); |
| @@ -1358,9 +1772,10 @@ | ||
| 1358 | 1772 | // echo $formJson; |
| 1359 | 1773 | // die(); |
| 1360 | 1774 | // } |
| 1361 | 1775 | |
| 1362 | - public function exportAForm($Request, $post) { | |
| 1776 | + public function exportAForm($Request, $post) | |
| 1777 | + { | |
| 1363 | 1778 | $oldFormId = intval($post->id); |
| 1364 | 1779 | if ($oldFormId < 1) { |
| 1365 | 1780 | return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); |
| 1366 | 1781 | } |
| @@ -1389,9 +1804,10 @@ | ||
| 1389 | 1804 | } |
| 1390 | 1805 | return $formData; |
| 1391 | 1806 | } |
| 1392 | 1807 | |
| 1393 | - public function getFormEntryLabelAndCount($Request, $post) { | |
| 1808 | + public function getFormEntryLabelAndCount($Request, $post) | |
| 1809 | + { | |
| 1394 | 1810 | if (isset($Request['id'])) { |
| 1395 | 1811 | $id = wp_unslash($Request['id']); |
| 1396 | 1812 | } else { |
| 1397 | 1813 | $id = wp_unslash($post->id); |
| @@ -1446,9 +1862,10 @@ | ||
| 1446 | 1862 | $response['fieldDetails'] = $labels; |
| 1447 | 1863 | return $response; |
| 1448 | 1864 | } |
| 1449 | 1865 | |
| 1450 | - public function getFormEntry($Request, $post) { | |
| 1866 | + public function getFormEntry($Request, $post) | |
| 1867 | + { | |
| 1451 | 1868 | if (isset($Request['id'])) { |
| 1452 | 1869 | $id = wp_unslash($Request['id']); |
| 1453 | 1870 | $offset = isset($Request['offset']) ? |
| 1454 | 1871 | wp_unslash($Request['offset']) : 0; |
| @@ -1505,182 +1922,284 @@ | ||
| 1505 | 1922 | $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails); |
| 1506 | 1923 | return $formEntries; |
| 1507 | 1924 | } |
| 1508 | 1925 | |
| 1509 | - public function getExportEntry($post) { | |
| 1510 | - $formId = wp_unslash($post->formId); | |
| 1511 | - $fileFormate = isset($post->fileFormate) ? wp_unslash($post->fileFormate) : null; | |
| 1512 | - $limit = isset($post->limit) ? wp_unslash($post->limit) : null; | |
| 1513 | - $sortBy = isset($post->sort) ? wp_unslash($post->sort) : 'ASC'; | |
| 1514 | - $sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id'; | |
| 1515 | - $formFields = json_decode($post->selectedField); | |
| 1516 | - if (is_null($formId)) { | |
| 1517 | - return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); | |
| 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 | + | |
| 1946 | + public function getEntriesForReport($Request, $post) | |
| 1947 | + { | |
| 1948 | + if (isset($Request['id'])) { | |
| 1949 | + $id = wp_unslash($Request['id']); | |
| 1950 | + $offset = isset($Request['offset']) ? | |
| 1951 | + wp_unslash($Request['offset']) : null; | |
| 1952 | + $pageSize = isset($Request['pageSize']) ? | |
| 1953 | + wp_unslash($Request['pageSize']) : null; | |
| 1954 | + } else { | |
| 1955 | + $id = wp_unslash($post->id); | |
| 1956 | + $conditions = isset($post->conditions) ? wp_unslash($post->conditions) : []; | |
| 1957 | + $dateBetweenFilter = isset($post->entriesFilterByDate) ? wp_unslash($post->entriesFilterByDate) : []; | |
| 1958 | + $offset = isset($post->offset) ? wp_unslash($post->offset) : null; | |
| 1959 | + $sortBy = isset($post->sortBy) ? wp_unslash($post->sortBy) : null; | |
| 1960 | + $filters = isset($post->filters) ? wp_unslash($post->filters) : null; | |
| 1961 | + $globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null; | |
| 1962 | + $pageSize = isset($post->pageSize) ? | |
| 1963 | + wp_unslash($post->pageSize) : null; | |
| 1964 | + } | |
| 1965 | + if (is_null($id)) { | |
| 1966 | + return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); | |
| 1967 | + } | |
| 1968 | + $formManager = new AdminFormManager($id); | |
| 1969 | + if (!$formManager->isExist()) { | |
| 1970 | + return new WP_Error('empty_form', __('Form does not exists', 'bit-form')); | |
| 1971 | + } | |
| 1972 | + | |
| 1973 | + $formEntry = new FormEntryModel(); | |
| 1974 | + $entries = $formEntry->get( | |
| 1975 | + 'id', | |
| 1976 | + [ | |
| 1977 | + 'form_id' => $id, | |
| 1978 | + ], | |
| 1979 | + null, | |
| 1980 | + null, | |
| 1981 | + 'created_at', | |
| 1982 | + 'DESC' | |
| 1983 | + ); | |
| 1984 | + if (is_wp_error($entries)) { | |
| 1985 | + if ('result_empty' === $entries->get_error_code()) { | |
| 1986 | + return [ | |
| 1987 | + 'count' => 0, | |
| 1988 | + 'entries' => [], | |
| 1989 | + ]; | |
| 1518 | 1990 | } |
| 1519 | - $formManager = new AdminFormManager($formId); | |
| 1520 | - $fieldLabels = $formManager->getFieldLabel(true); | |
| 1521 | - if (!$formManager->isExist()) { | |
| 1522 | - return new WP_Error('empty_form', __('Form does not exists', 'bit-form')); | |
| 1991 | + return $entries; | |
| 1992 | + } | |
| 1993 | + $filter['field'] = $filters; | |
| 1994 | + $filter['global'] = $globalFilter; | |
| 1995 | + | |
| 1996 | + $formFields = $formManager->getFieldLabel(true); | |
| 1997 | + $fieldDetails = $formManager->getFields(); | |
| 1998 | + | |
| 1999 | + $entryMeta = new FormEntryMetaModel(); | |
| 2000 | + $formEntries = $entryMeta->getEntryMeta($formFields, $entries, $pageSize, $offset, $filter, $sortBy, $conditions, $dateBetweenFilter); | |
| 2001 | + $customFieldHandler = new CustomFieldHandler(); | |
| 2002 | + $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails); | |
| 2003 | + $formEntries['entries'] = Helpers::filterNullEntries($formEntries['entries']); | |
| 2004 | + return $formEntries; | |
| 2005 | + } | |
| 2006 | + | |
| 2007 | + public function getExportEntry($post) | |
| 2008 | + { | |
| 2009 | + $formId = wp_unslash($post->formId); | |
| 2010 | + $fileFormate = isset($post->fileFormate) ? wp_unslash($post->fileFormate) : null; | |
| 2011 | + $limit = isset($post->limit) ? wp_unslash($post->limit) : null; | |
| 2012 | + $sortBy = isset($post->sort) ? wp_unslash($post->sort) : 'ASC'; | |
| 2013 | + $sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id'; | |
| 2014 | + $formFields = json_decode($post->selectedField); | |
| 2015 | + if (is_null($formId)) { | |
| 2016 | + return new WP_Error('empty_form', __('Form id is empty.', 'bit-form')); | |
| 2017 | + } | |
| 2018 | + $formManager = new AdminFormManager($formId); | |
| 2019 | + $fieldLabels = $formManager->getFieldLabel(true); | |
| 2020 | + if (!$formManager->isExist()) { | |
| 2021 | + return new WP_Error('empty_form', __('Form does not exists', 'bit-form')); | |
| 2022 | + } | |
| 2023 | + | |
| 2024 | + $formEntry = new FormEntryModel(); | |
| 2025 | + $entries = $formEntry->get( | |
| 2026 | + 'id', | |
| 2027 | + [ | |
| 2028 | + 'form_id' => $formId, | |
| 2029 | + ], | |
| 2030 | + null, | |
| 2031 | + null, | |
| 2032 | + 'created_at', | |
| 2033 | + 'DESC' | |
| 2034 | + ); | |
| 2035 | + if (is_wp_error($entries)) { | |
| 2036 | + if ('result_empty' === $entries->get_error_code()) { | |
| 2037 | + return [ | |
| 2038 | + 'count' => 0, | |
| 2039 | + 'entries' => [], | |
| 2040 | + ]; | |
| 1523 | 2041 | } |
| 2042 | + return $entries; | |
| 2043 | + } | |
| 2044 | + $entryMeta = new FormEntryMetaModel(); | |
| 2045 | + $filter = []; | |
| 2046 | + $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField); | |
| 2047 | + return $formEntries; | |
| 2048 | + } | |
| 1524 | 2049 | |
| 1525 | - $formEntry = new FormEntryModel(); | |
| 1526 | - $entries = $formEntry->get( | |
| 1527 | - 'id', | |
| 1528 | - [ | |
| 1529 | - 'form_id' => $formId, | |
| 1530 | - ], | |
| 1531 | - null, | |
| 1532 | - null, | |
| 1533 | - 'created_at', | |
| 1534 | - 'DESC' | |
| 1535 | - ); | |
| 1536 | - if (is_wp_error($entries)) { | |
| 1537 | - if ('result_empty' === $entries->get_error_code()) { | |
| 1538 | - return [ | |
| 1539 | - 'count' => 0, | |
| 1540 | - 'entries' => [], | |
| 1541 | - ]; | |
| 1542 | - } | |
| 1543 | - return $entries; | |
| 1544 | - } | |
| 1545 | - $entryMeta = new FormEntryMetaModel(); | |
| 1546 | - $filter = []; | |
| 1547 | - $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField); | |
| 1548 | - return $formEntries; | |
| 2050 | + public function deleteBlukFormEntries($Request, $post) | |
| 2051 | + { | |
| 2052 | + if (isset($Request['formID'])) { | |
| 2053 | + $formID = wp_unslash($Request['formID']); | |
| 2054 | + $entries = wp_unslash($Request['entries']); | |
| 2055 | + } else { | |
| 2056 | + $formID = wp_unslash($post->formID); | |
| 2057 | + $entries = wp_unslash($post->entries); | |
| 1549 | 2058 | } |
| 2059 | + if (is_null($formID) || !is_array($entries) || 0 === count($entries)) { | |
| 2060 | + return new WP_Error('empty_form', __('Invalid Form ID or Entries ID.', 'bit-form')); | |
| 2061 | + } | |
| 1550 | 2062 | |
| 1551 | - public function deleteBlukFormEntries($Request, $post) { | |
| 1552 | - if (isset($Request['formID'])) { | |
| 1553 | - $formID = wp_unslash($Request['formID']); | |
| 1554 | - $entries = wp_unslash($Request['entries']); | |
| 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 | + | |
| 2071 | + $formManager = new AdminFormManager($formID); | |
| 2072 | + if (!$formManager->isExist()) { | |
| 2073 | + return new WP_Error('empty_form', __('Form does not exist.', 'bit-form')); | |
| 2074 | + } | |
| 2075 | + $workFlowRunHelper = new WorkFlow($formID); | |
| 2076 | + $workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete( | |
| 2077 | + $formManager, | |
| 2078 | + $formID, | |
| 2079 | + $entries | |
| 2080 | + ); | |
| 2081 | + if (isset($workFlowreturnedOnDelete['entries'])) { | |
| 2082 | + if (0 === count($workFlowreturnedOnDelete['entries'])) { | |
| 2083 | + return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')]; | |
| 2084 | + } elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) { | |
| 2085 | + $message = __('Entry Deleted successfully', 'bit-form'); | |
| 1555 | 2086 | } else { |
| 1556 | - $formID = wp_unslash($post->formID); | |
| 1557 | - $entries = wp_unslash($post->entries); | |
| 2087 | + $result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']); | |
| 2088 | + $entries = $workFlowreturnedOnDelete['entries']; | |
| 2089 | + $message = __('Entry Deleted successfully, Some prevented by workflow', 'bit-form'); | |
| 1558 | 2090 | } |
| 1559 | - if (is_null($formID) || !is_array($entries) || 0 === count($entries)) { | |
| 1560 | - return new WP_Error('empty_form', __('Invalid Form ID or Entries ID.', 'bit-form')); | |
| 1561 | - } | |
| 1562 | - $formManager = new AdminFormManager($formID); | |
| 1563 | - if (!$formManager->isExist()) { | |
| 1564 | - return new WP_Error('empty_form', __('Form does not exist.', 'bit-form')); | |
| 1565 | - } | |
| 1566 | - $workFlowRunHelper = new WorkFlowRunHelper($formID); | |
| 1567 | - $workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete( | |
| 1568 | - $formManager, | |
| 1569 | - $formID, | |
| 1570 | - $entries | |
| 1571 | - ); | |
| 1572 | - if (isset($workFlowreturnedOnDelete['entries'])) { | |
| 1573 | - if (0 === count($workFlowreturnedOnDelete['entries'])) { | |
| 1574 | - return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')]; | |
| 1575 | - } elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) { | |
| 1576 | - $message = __('Entry Deleted successfully', 'bit-form'); | |
| 1577 | - } else { | |
| 1578 | - $result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']); | |
| 1579 | - $entries = $workFlowreturnedOnDelete['entries']; | |
| 1580 | - $message = __('Entry Deleted successfully, Some prevented by workflow', 'bit-form'); | |
| 2091 | + } else { | |
| 2092 | + $message = __('Entry Deleted successfully', 'bit-form'); | |
| 2093 | + } | |
| 2094 | + global $wpdb; | |
| 2095 | + $prefix = $wpdb->prefix; | |
| 2096 | + $formEntryModel = new FormEntryModel(); | |
| 2097 | + $delete_status = $formEntryModel->bulkDelete( | |
| 2098 | + [ | |
| 2099 | + "`{$prefix}bitforms_form_entries`.`id`" => $entries, | |
| 2100 | + "`{$prefix}bitforms_form_entries`.`form_id`" => $formID, | |
| 2101 | + ] | |
| 2102 | + ); | |
| 2103 | + if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) { | |
| 2104 | + $fileHandler = new FileHandler(); | |
| 2105 | + foreach ($entries as $enrtyKey => $entryID) { | |
| 2106 | + $fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID; | |
| 2107 | + if (file_exists($fileEntries)) { | |
| 2108 | + $fileHandler->rmrf($fileEntries); | |
| 1581 | 2109 | } |
| 1582 | - } else { | |
| 1583 | - $message = __('Entry Deleted successfully', 'bit-form'); | |
| 1584 | 2110 | } |
| 1585 | - global $wpdb; | |
| 1586 | - $prefix = $wpdb->prefix; | |
| 1587 | - $formEntryModel = new FormEntryModel(); | |
| 1588 | - $delete_status = $formEntryModel->bulkDelete( | |
| 2111 | + } | |
| 2112 | + $count = $formEntryModel->count( | |
| 2113 | + [ | |
| 2114 | + 'form_id' => $formID, | |
| 2115 | + ] | |
| 2116 | + ); | |
| 2117 | + $formManager->resetSubmissionCount(intval($count[0]->count)); | |
| 2118 | + if (is_wp_error($delete_status)) { | |
| 2119 | + return new WP_Error('entry_not_exists', __('Form entry deletion failed.', 'bit-form')); | |
| 2120 | + } | |
| 2121 | + $result['message'] = $message; | |
| 2122 | + return $result; | |
| 2123 | + } | |
| 2124 | + | |
| 2125 | + public function duplicateFormEntry($Request, $post) | |
| 2126 | + { | |
| 2127 | + if (isset($Request['formID'])) { | |
| 2128 | + $formID = wp_unslash($Request['formID']); | |
| 2129 | + $entries = wp_unslash($Request['entries']); | |
| 2130 | + } else { | |
| 2131 | + $formID = wp_unslash($post->formID); | |
| 2132 | + $entries = wp_unslash($post->entries); | |
| 2133 | + } | |
| 2134 | + if (is_null($formID) || !is_array($entries) || empty($entries)) { | |
| 2135 | + return new WP_Error('empty_form', __('Form id or entries id is invalid', 'bit-form')); | |
| 2136 | + } | |
| 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 | + | |
| 2146 | + $formManager = new AdminFormManager($formID); | |
| 2147 | + if (!$formManager->isExist()) { | |
| 2148 | + return new WP_Error('empty_form', __('Form does not exist', 'bit-form')); | |
| 2149 | + } | |
| 2150 | + $formEntryModel = new FormEntryModel(); | |
| 2151 | + $entryMeta = new FormEntryMetaModel(); | |
| 2152 | + $user_details = static::$ipTool->getUserDetail(); | |
| 2153 | + $total_entries = count($entries); | |
| 2154 | + $duplicate_count = 0; | |
| 2155 | + $test = ''; | |
| 2156 | + $fileHandler = new FileHandler(); | |
| 2157 | + $result = []; | |
| 2158 | + foreach ($entries as $entryIndex => $entryID) { | |
| 2159 | + $duplicatedEntryId = $formEntryModel->insert( | |
| 1589 | 2160 | [ |
| 1590 | - "`{$prefix}bitforms_form_entries`.`id`" => $entries, | |
| 1591 | - "`{$prefix}bitforms_form_entries`.`form_id`" => $formID, | |
| 2161 | + 'form_id' => $formID, | |
| 2162 | + 'user_id' => $user_details['id'], | |
| 2163 | + 'user_ip' => $user_details['ip'], | |
| 2164 | + 'user_device' => $user_details['device'], | |
| 2165 | + 'referer' => 'duplicate of #' . $entryID, | |
| 2166 | + 'status' => 1, | |
| 2167 | + 'created_at' => $user_details['time'], | |
| 1592 | 2168 | ] |
| 1593 | 2169 | ); |
| 1594 | - if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) { | |
| 1595 | - $fileHandler = new FileHandler(); | |
| 1596 | - foreach ($entries as $enrtyKey => $entryID) { | |
| 1597 | - $fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID; | |
| 1598 | - if (file_exists($fileEntries)) { | |
| 1599 | - $fileHandler->rmrf($fileEntries); | |
| 1600 | - } | |
| 1601 | - } | |
| 1602 | - } | |
| 1603 | - $count = $formEntryModel->count( | |
| 1604 | - [ | |
| 1605 | - 'form_id' => $formID, | |
| 1606 | - ] | |
| 1607 | - ); | |
| 1608 | - $formManager->resetSubmissionCount(intval($count[0]->count)); | |
| 1609 | - if (is_wp_error($delete_status)) { | |
| 1610 | - return new WP_Error('entry_not_exists', __('Form entry deletion failed.', 'bit-form')); | |
| 1611 | - } | |
| 1612 | - $result['message'] = $message; | |
| 1613 | - return $result; | |
| 1614 | - } | |
| 1615 | - | |
| 1616 | - public function duplicateFormEntry($Request, $post) { | |
| 1617 | - if (isset($Request['formID'])) { | |
| 1618 | - $formID = wp_unslash($Request['formID']); | |
| 1619 | - $entries = wp_unslash($Request['entries']); | |
| 1620 | - } else { | |
| 1621 | - $formID = wp_unslash($post->formID); | |
| 1622 | - $entries = wp_unslash($post->entries); | |
| 1623 | - } | |
| 1624 | - if (is_null($formID) || !is_array($entries) || empty($entries)) { | |
| 1625 | - return new WP_Error('empty_form', __('Form id or entries id is invalid', 'bit-form')); | |
| 1626 | - } | |
| 1627 | - | |
| 1628 | - $formManager = new AdminFormManager($formID); | |
| 1629 | - if (!$formManager->isExist()) { | |
| 1630 | - return new WP_Error('empty_form', __('Form does not exist', 'bit-form')); | |
| 1631 | - } | |
| 1632 | - $formEntryModel = new FormEntryModel(); | |
| 1633 | - $entryMeta = new FormEntryMetaModel(); | |
| 1634 | - $user_details = static::$ipTool->getUserDetail(); | |
| 1635 | - $total_entries = count($entries); | |
| 1636 | - $duplicate_count = 0; | |
| 1637 | - $test = ''; | |
| 1638 | - $fileHandler = new FileHandler(); | |
| 1639 | - $result = []; | |
| 1640 | - foreach ($entries as $entryIndex => $entryID) { | |
| 1641 | - $duplicatedEntryId = $formEntryModel->insert( | |
| 2170 | + if ($duplicatedEntryId) { | |
| 2171 | + $duplicate_status = $entryMeta->duplicateEntryMeta( | |
| 1642 | 2172 | [ |
| 1643 | - 'form_id' => $formID, | |
| 1644 | - 'user_id' => $user_details['id'], | |
| 1645 | - 'user_ip' => $user_details['ip'], | |
| 1646 | - 'user_device' => $user_details['device'], | |
| 1647 | - 'referer' => 'duplicate of #' . $entryID, | |
| 1648 | - 'status' => 1, | |
| 1649 | - 'created_at' => $user_details['time'], | |
| 2173 | + 'duplicateID' => $duplicatedEntryId, | |
| 2174 | + 'entryID' => $entryID, | |
| 1650 | 2175 | ] |
| 1651 | 2176 | ); |
| 1652 | - if ($duplicatedEntryId) { | |
| 1653 | - $duplicate_status = $entryMeta->duplicateEntryMeta( | |
| 1654 | - [ | |
| 1655 | - 'duplicateID' => $duplicatedEntryId, | |
| 1656 | - 'entryID' => $entryID, | |
| 1657 | - ] | |
| 1658 | - ); | |
| 1659 | - if ($duplicate_status) { | |
| 1660 | - $result['details'][$entryID] = $duplicatedEntryId; | |
| 1661 | - $duplicate_count = $duplicate_count + 1; | |
| 1662 | - if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) { | |
| 1663 | - $fileHandler->cpyr( | |
| 1664 | - BITFORMS_UPLOAD_DIR . "/$formID/$entryID", | |
| 1665 | - BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId" | |
| 1666 | - ); | |
| 1667 | - } | |
| 2177 | + if ($duplicate_status) { | |
| 2178 | + $result['details'][$entryID] = $duplicatedEntryId; | |
| 2179 | + $duplicate_count = $duplicate_count + 1; | |
| 2180 | + if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) { | |
| 2181 | + $fileHandler->cpyr( | |
| 2182 | + BITFORMS_UPLOAD_DIR . "/$formID/$entryID", | |
| 2183 | + BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId" | |
| 2184 | + ); | |
| 1668 | 2185 | } |
| 1669 | 2186 | } |
| 1670 | 2187 | } |
| 2188 | + } | |
| 1671 | 2189 | |
| 1672 | - $count = $formEntryModel->count( | |
| 1673 | - [ | |
| 1674 | - 'form_id' => $formID, | |
| 1675 | - ] | |
| 1676 | - ); | |
| 1677 | - $formManager->resetSubmissionCount(intval($count[0]->count)); | |
| 1678 | - $result['message'] = 1 === count($entries) ? __('Entry Duplicated successfully', 'bit-form') : __('Entries Duplicated successfully', 'bit-form'); | |
| 1679 | - return ($total_entries === $duplicate_count) ? $result : false; | |
| 1680 | - } | |
| 2190 | + $count = $formEntryModel->count( | |
| 2191 | + [ | |
| 2192 | + 'form_id' => $formID, | |
| 2193 | + ] | |
| 2194 | + ); | |
| 2195 | + $formManager->resetSubmissionCount(intval($count[0]->count)); | |
| 2196 | + $result['message'] = 1 === count($entries) ? __('Entry Duplicated successfully', 'bit-form') : __('Entries Duplicated successfully', 'bit-form'); | |
| 2197 | + return ($total_entries === $duplicate_count) ? $result : false; | |
| 2198 | + } | |
| 1681 | 2199 | |
| 1682 | - public function editFormEntry($Request, $post) { | |
| 2200 | + public function editFormEntry($Request, $post) | |
| 2201 | + { | |
| 1683 | 2202 | if (isset($Request['formID'])) { |
| 1684 | 2203 | $formID = wp_unslash($Request['formID']); |
| 1685 | 2204 | $entryID = wp_unslash($Request['entryID']); |
| 1686 | 2205 | } else { |
| @@ -1732,9 +2251,9 @@ | ||
| 1732 | 2251 | $form_fields->{$key}->val = $entries[$key]; |
| 1733 | 2252 | $form_fields->{$key}->name = $key; |
| 1734 | 2253 | } |
| 1735 | 2254 | } |
| 1736 | - $workFlowRunHelper = new WorkFlowRunHelper($formID); | |
| 2255 | + $workFlowRunHelper = new WorkFlow($formID); | |
| 1737 | 2256 | $workFlowreturnedOnLoad = $workFlowRunHelper->executeOnLoad( |
| 1738 | 2257 | 'edit', |
| 1739 | 2258 | $form_fields |
| 1740 | 2259 | ); |
| @@ -1755,16 +2274,18 @@ | ||
| 1755 | 2274 | ]; |
| 1756 | 2275 | return $formData; |
| 1757 | 2276 | } |
| 1758 | 2277 | |
| 1759 | - public function updateFormEntry($Request, $post) { | |
| 2278 | + public function updateFormEntry($Request, $post) | |
| 2279 | + { | |
| 1760 | 2280 | if (isset($Request['formID'], $Request['entryID'])) { |
| 1761 | 2281 | $formID = wp_unslash($Request['formID']); |
| 1762 | 2282 | $entryID = wp_unslash($Request['entryID']); |
| 1763 | 2283 | unset($Request['action'], $Request['formID'], $Request['entryID']); |
| 1764 | - | |
| 1765 | - $updatedValue = wp_unslash($post); | |
| 1766 | 2284 | } |
| 2285 | + $formManager = new AdminFormManager($formID); | |
| 2286 | + $formManager->fieldNameReplaceOfPost(); | |
| 2287 | + $updatedValue = wp_unslash($_POST); | |
| 1767 | 2288 | |
| 1768 | 2289 | if (is_null($updatedValue) || !is_array($updatedValue)) { |
| 1769 | 2290 | return new WP_Error('empty_data', __('Failed to update, Data is empty.', 'bit-form')); |
| 1770 | 2291 | } |
| @@ -1772,9 +2293,8 @@ | ||
| 1772 | 2293 | if (is_null($formID) || is_null($entryID)) { |
| 1773 | 2294 | return new WP_Error('empty_data', __('Invalid Form ID or entries ID.', 'bit-form')); |
| 1774 | 2295 | } |
| 1775 | 2296 | |
| 1776 | - $formManager = new AdminFormManager($formID); | |
| 1777 | 2297 | if (!$formManager->isExist()) { |
| 1778 | 2298 | return new WP_Error('empty_data', __('Form does not exist.', 'bit-form')); |
| 1779 | 2299 | } |
| 1780 | 2300 | return $formManager->updateFormEntry($updatedValue, $formID, $entryID); |
| @@ -1779,9 +2299,10 @@ | ||
| 1779 | 2299 | } |
| 1780 | 2300 | return $formManager->updateFormEntry($updatedValue, $formID, $entryID); |
| 1781 | 2301 | } |
| 1782 | 2302 | |
| 1783 | - public function getLogHistory($Request, $post) { | |
| 2303 | + public function getLogHistory($Request, $post) | |
| 2304 | + { | |
| 1784 | 2305 | if (isset($Request['formID'])) { |
| 1785 | 2306 | $formID = wp_unslash($Request['formID']); |
| 1786 | 2307 | $entryID = wp_unslash($Request['entryID']); |
| 1787 | 2308 | } else { |
| @@ -1802,9 +2323,10 @@ | ||
| 1802 | 2323 | $log_history = $formLogModel->geLogHistory($formID, $entryID); |
| 1803 | 2324 | return $log_history; |
| 1804 | 2325 | } |
| 1805 | 2326 | |
| 1806 | - public function importDataStore($Request, $post) { | |
| 2327 | + public function importDataStore($Request, $post) | |
| 2328 | + { | |
| 1807 | 2329 | if (isset($Request['formID'])) { |
| 1808 | 2330 | $formID = wp_unslash($Request['formID']); |
| 1809 | 2331 | } else { |
| 1810 | 2332 | $formID = wp_unslash($post->formID); |
| @@ -1813,9 +2335,10 @@ | ||
| 1813 | 2335 | return new WP_Error('empty_form', __('Invalid Form id or entries id.', 'bit-form')); |
| 1814 | 2336 | } |
| 1815 | 2337 | } |
| 1816 | 2338 | |
| 1817 | - public function getAllWPPages($Request, $post) { | |
| 2339 | + public function getAllWPPages($Request, $post) | |
| 2340 | + { | |
| 1818 | 2341 | $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']); |
| 1819 | 2342 | $allPages = []; |
| 1820 | 2343 | foreach ($pages as $pageKey => $pageDetails) { |
| 1821 | 2344 | $allPages[$pageKey]['title'] = $pageDetails->post_title; |
| @@ -1823,9 +2346,10 @@ | ||
| 1823 | 2346 | } |
| 1824 | 2347 | return $allPages; |
| 1825 | 2348 | } |
| 1826 | 2349 | |
| 1827 | - public function deleteAIntegration($Request, $post) { | |
| 2350 | + public function deleteAIntegration($Request, $post) | |
| 2351 | + { | |
| 1828 | 2352 | if (isset($Request['formID']) && $Request['id']) { |
| 1829 | 2353 | $formID = json_decode(wp_unslash($Request['formID'])); |
| 1830 | 2354 | $id = wp_unslash($Request['id']); |
| 1831 | 2355 | } else { |
| @@ -1846,9 +2370,10 @@ | ||
| 1846 | 2370 | 'message' => __('Integration deleted', 'bit-form'), |
| 1847 | 2371 | ]; |
| 1848 | 2372 | } |
| 1849 | 2373 | |
| 1850 | - public function deleteSuccessMessage($Request, $post) { | |
| 2374 | + public function deleteSuccessMessage($Request, $post) | |
| 2375 | + { | |
| 1851 | 2376 | if (isset($Request['formID']) && $Request['id']) { |
| 1852 | 2377 | $formID = json_decode(wp_unslash($Request['formID'])); |
| 1853 | 2378 | $id = wp_unslash($Request['id']); |
| 1854 | 2379 | } else { |
| @@ -1868,9 +2393,10 @@ | ||
| 1868 | 2393 | 'message' => __('Message deleted', 'bit-form'), |
| 1869 | 2394 | ]; |
| 1870 | 2395 | } |
| 1871 | 2396 | |
| 1872 | - public function deleteAWorkflow($Request, $post) { | |
| 2397 | + public function deleteAWorkflow($Request, $post) | |
| 2398 | + { | |
| 1873 | 2399 | if (isset($Request['formID']) && $Request['id']) { |
| 1874 | 2400 | $formID = json_decode(wp_unslash($Request['formID'])); |
| 1875 | 2401 | $id = wp_unslash($Request['id']); |
| 1876 | 2402 | } else { |
| @@ -1889,9 +2415,10 @@ | ||
| 1889 | 2415 | 'message' => __('workflow deleted', 'bit-form'), |
| 1890 | 2416 | ]; |
| 1891 | 2417 | } |
| 1892 | 2418 | |
| 1893 | - public function deleteAMailTemplate($Request, $post) { | |
| 2419 | + public function deleteAMailTemplate($Request, $post) | |
| 2420 | + { | |
| 1894 | 2421 | if (isset($Request['formID']) && $Request['id']) { |
| 1895 | 2422 | $formID = json_decode(wp_unslash($Request['formID'])); |
| 1896 | 2423 | $id = wp_unslash($Request['id']); |
| 1897 | 2424 | } else { |
| @@ -1910,9 +2437,10 @@ | ||
| 1910 | 2437 | 'message' => __('Email Template deleted', 'bit-form'), |
| 1911 | 2438 | ]; |
| 1912 | 2439 | } |
| 1913 | 2440 | |
| 1914 | - public function duplicateAMailTemplate($Request, $post) { | |
| 2441 | + public function duplicateAMailTemplate($Request, $post) | |
| 2442 | + { | |
| 1915 | 2443 | if (isset($Request['formID']) && $Request['id']) { |
| 1916 | 2444 | $formID = json_decode(wp_unslash($Request['formID'])); |
| 1917 | 2445 | $id = wp_unslash($Request['id']); |
| 1918 | 2446 | } else { |
| @@ -1921,8 +2449,17 @@ | ||
| 1921 | 2449 | } |
| 1922 | 2450 | if (empty($formID) || empty($id)) { |
| 1923 | 2451 | return new WP_Error('empty_form', 'Invalid Form ID or Email Template ID.'); |
| 1924 | 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 | + | |
| 1925 | 2462 | $emailTemplateHandler = new EmailTemplateHandler($formID); |
| 1926 | 2463 | $duplicate_status = $emailTemplateHandler->duplicateTemplate($id); |
| 1927 | 2464 | if (is_wp_error($duplicate_status)) { |
| 1928 | 2465 | return $duplicate_status; |
| @@ -1931,9 +2468,10 @@ | ||
| 1931 | 2468 | 'message' => __('Email Template duplicated', 'bit-form'), |
| 1932 | 2469 | ]; |
| 1933 | 2470 | } |
| 1934 | 2471 | |
| 1935 | - public function setAllFormsReport($Request, $post) { | |
| 2472 | + public function setAllFormsReport($Request, $post) | |
| 2473 | + { | |
| 1936 | 2474 | $reports = empty($post->reports) ? null : wp_unslash($post->reports); |
| 1937 | 2475 | if (empty($reports)) { |
| 1938 | 2476 | return new WP_Error('empty_report_prefs', 'Report data is Empty, nothing to save or update.'); |
| 1939 | 2477 | } |
| @@ -2009,9 +2547,10 @@ | ||
| 2009 | 2547 | 'reports' => empty($reports) ? [] : $reports, |
| 2010 | 2548 | ]; |
| 2011 | 2549 | } |
| 2012 | 2550 | |
| 2013 | - public function savegReCaptcha($Request, $post) { | |
| 2551 | + public function savegReCaptcha($Request, $post) | |
| 2552 | + { | |
| 2014 | 2553 | $reCaptcha = $post->reCaptcha; |
| 2015 | 2554 | |
| 2016 | 2555 | if (is_null($reCaptcha)) { |
| 2017 | 2556 | return new WP_Error('empty_gcaptchdetails', __('g-ReCAPTCHA details is empty', 'bit-form')); |
| @@ -2023,11 +2562,16 @@ | ||
| 2023 | 2562 | } else { |
| 2024 | 2563 | $integrationID = $reCaptcha->id; |
| 2025 | 2564 | unset($reCaptcha->id); |
| 2026 | 2565 | } |
| 2027 | - $reCaptcha = json_encode($reCaptcha); | |
| 2028 | - $integrationName = 'google reCaptcha'; | |
| 2029 | - $integrationType = 'v2' === $post->version ? 'gReCaptcha' : 'gReCaptchaV3'; | |
| 2566 | + $reCaptcha = wp_json_encode($reCaptcha); | |
| 2567 | + | |
| 2568 | + // $integrationName = 'google reCaptcha'; | |
| 2569 | + $integrationName = $post->integrationName; | |
| 2570 | + | |
| 2571 | + // $integrationType = 'v2' === $post->version ? 'gReCaptcha' : 'gReCaptchaV3'; | |
| 2572 | + $integrationType = $post->integrationType; | |
| 2573 | + | |
| 2030 | 2574 | $integrationDetails = $reCaptcha; |
| 2031 | 2575 | $user_details = static::$ipTool->getUserDetail(); |
| 2032 | 2576 | $integrationHandler = new IntegrationHandler(0, $user_details); |
| 2033 | 2577 | $response = []; |
| @@ -2033,12 +2577,12 @@ | ||
| 2033 | 2577 | $response = []; |
| 2034 | 2578 | if (empty($integrationID)) { |
| 2035 | 2579 | $captchaSaveStatus = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'app'); |
| 2036 | 2580 | $response['id'] = $captchaSaveStatus; |
| 2037 | - $response['message'] = __('g-reCAPTCHA saved successfully', 'bit-form'); | |
| 2581 | + $response['message'] = __('reCAPTCHA saved successfully', 'bit-form'); | |
| 2038 | 2582 | } else { |
| 2039 | 2583 | $captchaSaveStatus = $integrationHandler->updateIntegration($integrationID, $integrationName, $integrationType, $integrationDetails, 'app'); |
| 2040 | - $response['message'] = __('g-reCAPTCHA updated successfully', 'bit-form'); | |
| 2584 | + $response['message'] = __('reCAPTCHA updated successfully', 'bit-form'); | |
| 2041 | 2585 | } |
| 2042 | 2586 | |
| 2043 | 2587 | if (is_wp_error($captchaSaveStatus)) { |
| 2044 | 2588 | return $captchaSaveStatus; |
| @@ -2045,9 +2589,10 @@ | ||
| 2045 | 2589 | } |
| 2046 | 2590 | return $response; |
| 2047 | 2591 | } |
| 2048 | 2592 | |
| 2049 | - public function savePaymentSetting($Request, $post) { | |
| 2593 | + public function savePaymentSetting($Request, $post) | |
| 2594 | + { | |
| 2050 | 2595 | if (isset($post->paySetting)) { |
| 2051 | 2596 | $paySetting = $post->paySetting; |
| 2052 | 2597 | } |
| 2053 | 2598 | if (is_null($paySetting)) { |
| @@ -2055,21 +2600,37 @@ | ||
| 2055 | 2600 | } |
| 2056 | 2601 | if (is_string($paySetting)) { |
| 2057 | 2602 | $paySetting = json_decode($paySetting); |
| 2058 | 2603 | } |
| 2059 | - if ('PayPal' === $paySetting->type) { | |
| 2060 | - $canSave = $this->addWebhookToPaypal($paySetting); | |
| 2061 | - } elseif ('Razorpay' === $paySetting->type) { | |
| 2062 | - $canSave = true; | |
| 2604 | + | |
| 2605 | + $canSave = null; | |
| 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; | |
| 2063 | 2621 | } |
| 2064 | 2622 | if (is_null($canSave)) { |
| 2065 | - return ['message' => __('Please re-check your Client ID & Secret', 'bit-form')]; | |
| 2623 | + return new WP_Error('stripe', __('Please re-check your Client ID & Secret', 'bit-form')); | |
| 2066 | 2624 | } |
| 2067 | - $integrationID = $paySetting->id; | |
| 2068 | - unset($paySetting->id); | |
| 2625 | + $integrationID = null; | |
| 2626 | + if (isset($paySetting->id)) { | |
| 2627 | + $integrationID = $paySetting->id; | |
| 2628 | + unset($paySetting->id); | |
| 2629 | + } | |
| 2069 | 2630 | $integrationName = $paySetting->name; |
| 2070 | 2631 | $integrationType = 'payments'; |
| 2071 | - $paySetting = json_encode($paySetting); | |
| 2632 | + $paySetting = wp_json_encode($paySetting); | |
| 2072 | 2633 | $integrationDetails = $paySetting; |
| 2073 | 2634 | $user_details = static::$ipTool->getUserDetail(); |
| 2074 | 2635 | $integrationHandler = new IntegrationHandler(0, $user_details); |
| 2075 | 2636 | $response = []; |
| @@ -2087,9 +2648,10 @@ | ||
| 2087 | 2648 | } |
| 2088 | 2649 | return $response; |
| 2089 | 2650 | } |
| 2090 | 2651 | |
| 2091 | - private function addWebhookToPaypal($paySetting) { | |
| 2652 | + private function addWebhookToPaypal($paySetting) | |
| 2653 | + { | |
| 2092 | 2654 | $transaction_mode = $paySetting->mode; |
| 2093 | 2655 | $clientId = $paySetting->clientID; |
| 2094 | 2656 | $clientSecret = $paySetting->clientSecret; |
| 2095 | 2657 | $base_url = 'sandbox' === $transaction_mode ? 'https://api-m.sandbox.paypal.com' : 'https://api.paypal.com'; |
| @@ -2115,9 +2677,51 @@ | ||
| 2115 | 2677 | } |
| 2116 | 2678 | return true; |
| 2117 | 2679 | } |
| 2118 | 2680 | |
| 2119 | - public function builerHelperState($formId) { | |
| 2681 | + private function addWebhookToStripe($paySetting) | |
| 2682 | + { | |
| 2683 | + $clientSecret = $paySetting->clientSecret; | |
| 2684 | + | |
| 2685 | + $create_webhook_url = 'https://api.stripe.com/v1/webhook_endpoints'; | |
| 2686 | + $headers = [ | |
| 2687 | + 'Content-Type' => 'application/x-www-form-urlencoded', | |
| 2688 | + 'Authorization' => "Bearer $clientSecret", | |
| 2689 | + ]; | |
| 2690 | + | |
| 2691 | + $webhook_url = get_rest_url() . 'bitform/v1/payments/stripe'; | |
| 2692 | + | |
| 2693 | + $apiResponse = HttpHelper::get($create_webhook_url, '', $headers); | |
| 2694 | + | |
| 2695 | + if (isset($apiResponse->error)) { | |
| 2696 | + return null; | |
| 2697 | + } | |
| 2698 | + $webhookList = $apiResponse->data; | |
| 2699 | + $webhook_already_exist = false; | |
| 2700 | + | |
| 2701 | + foreach ($webhookList as $webhook) { | |
| 2702 | + if ($webhook->url === $webhook_url) { | |
| 2703 | + $webhook_already_exist = true; | |
| 2704 | + break; | |
| 2705 | + } | |
| 2706 | + } | |
| 2707 | + | |
| 2708 | + $data = [ | |
| 2709 | + 'enabled_events[]' => 'payment_intent.succeeded', | |
| 2710 | + 'url' => $webhook_url, | |
| 2711 | + ]; | |
| 2712 | + | |
| 2713 | + if (!$webhook_already_exist) { | |
| 2714 | + $webhook_response = HttpHelper::post($create_webhook_url, $data, $headers); | |
| 2715 | + if (is_wp_error($webhook_response) || (isset($webhook_response->error) && $webhook_response->error)) { | |
| 2716 | + return null; | |
| 2717 | + } | |
| 2718 | + } | |
| 2719 | + return true; | |
| 2720 | + } | |
| 2721 | + | |
| 2722 | + public function builerHelperState($formId) | |
| 2723 | + { | |
| 2120 | 2724 | $data = static::$formModel->get( |
| 2121 | 2725 | ['id', 'builder_helper_state'], |
| 2122 | 2726 | ['id' => $formId] |
| 2123 | 2727 | ); |
| @@ -2132,9 +2736,10 @@ | ||
| 2132 | 2736 | |
| 2133 | 2737 | return $data; |
| 2134 | 2738 | } |
| 2135 | 2739 | |
| 2136 | - public function updateGeneratedScriptPageIds() { | |
| 2740 | + public function updateGeneratedScriptPageIds() | |
| 2741 | + { | |
| 2137 | 2742 | $updateData = [ |
| 2138 | 2743 | 'generated_script_page_ids' => \wp_json_encode((object) []), |
| 2139 | 2744 | ]; |
| 2140 | 2745 | $update_status = static::$formModel->update( |
| @@ -2151,9 +2756,29 @@ | ||
| 2151 | 2756 | return true; |
| 2152 | 2757 | } |
| 2153 | 2758 | } |
| 2154 | 2759 | |
| 2155 | - public function updateSuccessMessageClassName($str, $msgIdx, $msgId) { | |
| 2760 | + public function updateSuccessMessageClassName($str, $msgIdx, $msgId) | |
| 2761 | + { | |
| 2156 | 2762 | $TEMP_CONF_ID = '_tmp_' . $msgIdx . '_conf_id'; |
| 2157 | 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); | |
| 2158 | 2783 | } |
| 2159 | 2784 | } |