| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Handle Form Create,Update,delete Operation |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace BitCode\BitForm\Admin\Form; |
| 9 |
|
| 10 |
use WP_Error; |
| 11 |
use BitCode\BitForm\Core\Util\IpTool; |
| 12 |
use BitCode\BitForm\Core\Util\FileHandler; |
| 13 |
use BitCode\BitForm\Core\Database\FormModel; |
| 14 |
use BitCode\BitForm\Core\Database\ReportsModel; |
| 15 |
use BitCode\BitForm\Admin\Form\AdminFormManager; |
| 16 |
use BitCode\BitForm\Core\Database\WorkFlowModel; |
| 17 |
use BitCode\BitForm\Core\Database\FormEntryModel; |
| 18 |
use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler; |
| 19 |
use BitCode\BitForm\Core\Database\IntegrationModel; |
| 20 |
use BitCode\BitForm\Core\Database\FormEntryLogModel; |
| 21 |
use BitCode\BitForm\Core\WorkFlow\WorkFlowRunHelper; |
| 22 |
use BitCode\BitForm\Core\Database\EmailTemplateModel; |
| 23 |
use BitCode\BitForm\Core\Database\FormEntryMetaModel; |
| 24 |
use BitCode\BitForm\Core\Database\SuccessMessageModel; |
| 25 |
use BitCode\BitForm\Core\Messages\EmailTemplateHandler; |
| 26 |
use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 27 |
use BitCode\BitForm\Core\Messages\SuccessMessageHandler; |
| 28 |
use BitCode\BitForm\Admin\Form\Template\TemplateProvider; |
| 29 |
|
| 30 |
class AdminFormHandler |
| 31 |
{ |
| 32 |
private static $formModel; |
| 33 |
private static $ipTool; |
| 34 |
public function __construct() |
| 35 |
{ |
| 36 |
static::$formModel = new FormModel(); |
| 37 |
static::$ipTool = new IpTool(); |
| 38 |
} |
| 39 |
public function getTemplate($Request, $post) |
| 40 |
{ |
| 41 |
$templateName = null; |
| 42 |
$newFormId = null; |
| 43 |
if (isset($post->template)) { |
| 44 |
$templateName = $post->template; |
| 45 |
$newFormId = $post->newFormId; |
| 46 |
} |
| 47 |
|
| 48 |
$templateProvider = new TemplateProvider(); |
| 49 |
$form_content_raw = $templateProvider->getTemplate($templateName, $newFormId); |
| 50 |
if (!$form_content_raw) { |
| 51 |
return new WP_Error("template_empty", __("Template is not found!! your provided template name is ", "bitform") . $templateName); |
| 52 |
} else { |
| 53 |
return \json_encode( |
| 54 |
array( |
| 55 |
'id' => 0, |
| 56 |
'form_content' => $form_content_raw, |
| 57 |
) |
| 58 |
); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
public function saveStyleSheet($styles, $sheetName) |
| 63 |
{ |
| 64 |
if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) { |
| 65 |
$createStyleFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName, 'w'); |
| 66 |
fwrite($createStyleFile, $styles); |
| 67 |
fclose($createStyleFile); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
public function saveLayoutStyleSheet($layout, $sheetName, $lay_row_height = 43) |
| 72 |
{ |
| 73 |
$md_width = 600; |
| 74 |
$sm_width = 400; |
| 75 |
$lg_styles = ''; |
| 76 |
$md_styles = ''; |
| 77 |
$sm_styles = ''; |
| 78 |
for ($i = 0; $i < count($layout->lg); $i++) { |
| 79 |
$fld = $layout->lg[$i]; |
| 80 |
|
| 81 |
$class = $fld->i; |
| 82 |
$lg_g_r_s = $fld->y + 1; |
| 83 |
$lg_g_c_s = $fld->x + 1; |
| 84 |
$lg_g_r_e = $fld->y !== 1 ? $fld->h + ($fld->y + 1) : 1; |
| 85 |
$lg_g_c_e = ($fld->x + 1) + $fld->w; |
| 86 |
$lg_g_r_span = $lg_g_r_e - $lg_g_r_s; |
| 87 |
$lg_g_c_span = $lg_g_c_e - $lg_g_c_s; |
| 88 |
$lg_min_height = $fld->h * $lay_row_height . "px;"; |
| 89 |
|
| 90 |
$lg_styles .= ".$class { grid-area: $lg_g_r_s / $lg_g_c_s / $lg_g_r_e / $lg_g_c_e ; -ms-grid-row: $lg_g_r_s; -ms-grid-row-span: $lg_g_r_span; -ms-grid-column: $lg_g_c_s; -ms-grid-column-span: $lg_g_c_span; min-height: $lg_min_height; }"; |
| 91 |
|
| 92 |
$fld = $layout->md[$i]; |
| 93 |
|
| 94 |
$class = $fld->i; |
| 95 |
$md_g_r_s = $fld->y + 1; |
| 96 |
$md_g_c_s = $fld->x + 1; |
| 97 |
$md_g_r_e = $fld->y !== 1 ? $fld->h + ($fld->y + 1) : 1; |
| 98 |
$md_g_c_e = ($fld->x + 1) + $fld->w; |
| 99 |
$md_g_r_span = $lg_g_r_e - $md_g_r_s; |
| 100 |
$md_g_c_span = $lg_g_c_e - $md_g_c_s; |
| 101 |
$md_min_height = $fld->h * $lay_row_height . "px;"; |
| 102 |
|
| 103 |
$md_styles .= ".$class { grid-area: $md_g_r_s / $md_g_c_s / $md_g_r_e / $md_g_c_e ; -ms-grid-row: $md_g_r_s; -ms-grid-row-span: $md_g_r_span; -ms-grid-column: $md_g_c_s; -ms-grid-column-span: $md_g_c_span; min-height: $md_min_height; }"; |
| 104 |
|
| 105 |
$fld = $layout->sm[$i]; |
| 106 |
|
| 107 |
$class = $fld->i; |
| 108 |
$sm_g_r_s = $fld->y + 1; |
| 109 |
$sm_g_c_s = $fld->x + 1; |
| 110 |
$sm_g_r_e = $fld->y !== 1 ? $fld->h + ($fld->y + 1) : 1; |
| 111 |
$sm_g_c_e = ($fld->x + 1) + $fld->w; |
| 112 |
$sm_g_r_span = $sm_g_r_e - $sm_g_r_s; |
| 113 |
$sm_g_c_span = $sm_g_c_e - $sm_g_c_s; |
| 114 |
$sm_min_height = $fld->h * $lay_row_height . "px;"; |
| 115 |
|
| 116 |
$sm_styles .= ".$class { grid-area: $sm_g_r_s / $sm_g_c_s / $sm_g_r_e / $sm_g_c_e ; -ms-grid-row: $sm_g_r_s; -ms-grid-row-span: $sm_g_r_span; -ms-grid-column: $sm_g_c_s; -ms-grid-column-span: $sm_g_c_span; min-height: $sm_min_height; }"; |
| 117 |
} |
| 118 |
$formStyle = "._frm-g{ |
| 119 |
display: grid; |
| 120 |
display: -ms-grid; |
| 121 |
grid-template-columns: repeat( 6 , minmax( 30px , 1fr )); |
| 122 |
-ms-grid-columns: minmax( 30px , 1fr ) minmax( 30px , 1fr ) minmax( 30px , 1fr ) minmax( 30px , 1fr ) minmax( 30px , 1fr ) minmax( 30px , 1fr ); |
| 123 |
} |
| 124 |
{$lg_styles} |
| 125 |
@media only screen and (max-width:{$md_width}px) { |
| 126 |
._frm-g {grid-template-columns: repeat( 4 , minmax( 30px , 1fr ));-ms-grid-columns: minmax( 30px , 1fr ) minmax( 30px , 1fr ) minmax( 30px , 1fr ) minmax( 30px , 1fr );} |
| 127 |
{$md_styles} |
| 128 |
} |
| 129 |
@media only screen and (max-width:{$sm_width}px) { |
| 130 |
._frm-g {grid-template-columns: repeat( 2 , minmax( 30px , 1fr ));-ms-grid-columns: minmax( 30px , 1fr ) minmax( 30px , 1fr );} |
| 131 |
{$sm_styles} |
| 132 |
}"; |
| 133 |
|
| 134 |
if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) { |
| 135 |
$createStyleFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName, 'w'); |
| 136 |
fwrite($createStyleFile, $formStyle); |
| 137 |
fclose($createStyleFile); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
public function createNewForm($Request, $post) |
| 142 |
{ |
| 143 |
if (!isset($post->form_id) || $post->form_id == '') { |
| 144 |
return new WP_Error('empty_form', __('Error Occured, Please Reload', 'bitform')); |
| 145 |
} |
| 146 |
|
| 147 |
$formManager = new AdminFormManager($post->form_id); |
| 148 |
if ($formManager->isExist()) { |
| 149 |
return new WP_Error('empty_form', __('Error Occured, Please Reload', 'bitform')); |
| 150 |
} |
| 151 |
|
| 152 |
if (isset($post->formStyle) && $post->formStyle) { |
| 153 |
$sheetName = 'bitform-' . $post->form_id . '.css'; |
| 154 |
$this->saveStyleSheet($post->formStyle, $sheetName); |
| 155 |
} |
| 156 |
|
| 157 |
if (isset($post->layoutChanged) && $post->layoutChanged) { |
| 158 |
$sheetName = 'bitform-layout-' . $post->form_id . '.css'; |
| 159 |
$rowHeight = (int)$post->rowHeight; |
| 160 |
$this->saveLayoutStyleSheet($post->layout, $sheetName, $rowHeight); |
| 161 |
} |
| 162 |
|
| 163 |
$fields = wp_unslash($post->fields); |
| 164 |
$layout = wp_unslash($post->layout); |
| 165 |
$form_name = wp_unslash($post->form_name); |
| 166 |
$formSettings = wp_unslash($post->formSettings); |
| 167 |
$workFlows = wp_unslash($post->workFlows); |
| 168 |
$additional = wp_unslash($post->additional); |
| 169 |
$reports = !empty($post->reports) ? $post->reports : (object) []; |
| 170 |
|
| 171 |
if (!class_exists("BitCode\\BitFormPro\\Plugin")) { |
| 172 |
if (count($workFlows) > 2) { |
| 173 |
return new WP_Error( |
| 174 |
'free_limit', |
| 175 |
__('you can add maximum 2 workflows ', 'bitform') |
| 176 |
); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
$mailTem = $formSettings->mailTem; |
| 181 |
$integrations = $formSettings->integrations; |
| 182 |
|
| 183 |
$user_details = static::$ipTool->getUserDetail(); |
| 184 |
// var_dump($fields); |
| 185 |
if (empty($fields) || empty($layout)) { |
| 186 |
return new WP_Error( |
| 187 |
'empty_form', |
| 188 |
__('Form is Empty, nothing to save', 'bitform') |
| 189 |
); |
| 190 |
} |
| 191 |
if (strlen($form_name) > 50) { |
| 192 |
return new WP_Error( |
| 193 |
'empty_form', |
| 194 |
__('Form Name Should Be Within 50 Characters', 'bitform') |
| 195 |
); |
| 196 |
} |
| 197 |
$form_content = array( |
| 198 |
'fields' => $fields, |
| 199 |
'layout' => $layout, |
| 200 |
); |
| 201 |
|
| 202 |
if (!empty($formSettings->submitBtn)) { |
| 203 |
$form_content = array_merge($form_content, array('buttons' => $formSettings->submitBtn)); |
| 204 |
} |
| 205 |
if (!empty($formSettings->theme)) { |
| 206 |
$form_content = array_merge($form_content, array('theme' => $formSettings->theme)); |
| 207 |
} |
| 208 |
|
| 209 |
if (!empty($additional)) { |
| 210 |
$form_content = array_merge($form_content, array('additional' => $additional)); |
| 211 |
} |
| 212 |
if (!empty($workFlows)) { |
| 213 |
$workFlowsStr = is_string($workFlows) ? $workFlows : json_encode($workFlows); |
| 214 |
$workFlowExist = []; |
| 215 |
if (\strpos($workFlowsStr, 'onload')) { |
| 216 |
$workFlowExist['onload'] = true; |
| 217 |
} |
| 218 |
if (\strpos($workFlowsStr, 'oninput')) { |
| 219 |
$workFlowExist['oninput'] = true; |
| 220 |
} |
| 221 |
$form_content = array_merge($form_content, array('workFlowExist' => $workFlowExist)); |
| 222 |
} |
| 223 |
$form_content = \wp_json_encode($form_content); |
| 224 |
|
| 225 |
$fdata = array( |
| 226 |
"id" => $post->form_id, |
| 227 |
"form_content" => $form_content, |
| 228 |
"user_id" => $user_details['id'], |
| 229 |
"user_ip" => $user_details['ip'], |
| 230 |
"user_device" => $user_details['device'], |
| 231 |
"status" => 1, |
| 232 |
"form_name" => $form_name, |
| 233 |
"created_at" => $user_details['time'], |
| 234 |
"updated_at" => $user_details['time'], |
| 235 |
); |
| 236 |
$save_status = static::$formModel->insert($fdata); |
| 237 |
|
| 238 |
if (is_wp_error($save_status)) { |
| 239 |
return $save_status; |
| 240 |
} elseif (!$save_status) { |
| 241 |
return false; |
| 242 |
} else { |
| 243 |
wp_mkdir_p(BITFORMS_UPLOAD_DIR . "/$save_status"); |
| 244 |
$formID = $save_status; |
| 245 |
$integartionIDForWorkflow = array(); |
| 246 |
// Confiramtion Message [start] |
| 247 |
if (!empty($formSettings->confirmation->type->successMsg)) { |
| 248 |
$successMessages = $formSettings->confirmation->type->successMsg; |
| 249 |
$successMessageHandler |
| 250 |
= new SuccessMessageHandler($formID, $user_details); |
| 251 |
foreach ($successMessages as $messageKey => $messageDetail) { |
| 252 |
$savedID = $successMessageHandler->saveMessage($messageDetail); |
| 253 |
if ($savedID) { |
| 254 |
$integartionIDForWorkflow['successMsg'][$messageKey] = $savedID; |
| 255 |
} |
| 256 |
} |
| 257 |
unset($formSettings->confirmation->type->successMsg); |
| 258 |
} |
| 259 |
// return $formSettings; |
| 260 |
// Confiramtion Message [end] */ |
| 261 |
// Email Template [start] |
| 262 |
if (!empty($mailTem)) { |
| 263 |
$emailTemplateHandler |
| 264 |
= new EmailTemplateHandler($formID, $user_details); |
| 265 |
foreach ($mailTem as $templateKey => $templateDetail) { |
| 266 |
if (empty($templateDetail->id)) { |
| 267 |
$savedID = $emailTemplateHandler->saveTemplate($templateDetail); |
| 268 |
if ($savedID) { |
| 269 |
$integartionIDForWorkflow['mailTem'][$templateKey] = $savedID; |
| 270 |
} |
| 271 |
} else { |
| 272 |
$emailTemplateHandler->updateTemplate($templateDetail); |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
// Email Template [end] */ |
| 277 |
//Integration [start] */ |
| 278 |
if (!empty($formSettings->confirmation->type)) { |
| 279 |
$integrationHandler = new IntegrationHandler($formID, $user_details); |
| 280 |
$allIntegrations = $formSettings->confirmation->type; |
| 281 |
foreach ($allIntegrations as $integrationType => $integrationGroup) { |
| 282 |
foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) { |
| 283 |
if (empty($singleIntegrationDetail->details)) { |
| 284 |
$integrationName = $singleIntegrationDetail->title; |
| 285 |
unset($singleIntegrationDetail->title); |
| 286 |
$integrationDetails = !is_string($singleIntegrationDetail) ? |
| 287 |
wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail; |
| 288 |
} else { |
| 289 |
$integrationName = $singleIntegrationDetail->title; |
| 290 |
$integrationDetails = !is_string($singleIntegrationDetail->details) ? |
| 291 |
wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details; |
| 292 |
} |
| 293 |
if (empty($singleIntegrationDetail->id)) { |
| 294 |
$savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form'); |
| 295 |
$integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID; |
| 296 |
} else { |
| 297 |
$integrationHandler->updateIntegration($singleIntegrationDetail->id, $integrationName, $integrationType, $integrationDetails, 'form'); |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
if (!empty($integrations)) { |
| 303 |
foreach ($integrations as $singleIntegrationKey => $singleIntegrationDetail) { |
| 304 |
$integrationName = $singleIntegrationDetail->name; |
| 305 |
unset($singleIntegrationDetail->name); |
| 306 |
$integrationType = $singleIntegrationDetail->type; |
| 307 |
unset($singleIntegrationDetail->type); |
| 308 |
$singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id; |
| 309 |
unset($singleIntegrationDetail->id); |
| 310 |
if (empty($singleIntegrationDetail->details)) { |
| 311 |
$integrationDetails = !is_string($singleIntegrationDetail) ? |
| 312 |
wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail; |
| 313 |
} else { |
| 314 |
$integrationDetails = !is_string($singleIntegrationDetail->details) ? |
| 315 |
wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details; |
| 316 |
} |
| 317 |
if (empty($singleIntegrationDetailID)) { |
| 318 |
$savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form'); |
| 319 |
$integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID; |
| 320 |
$integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form'); |
| 321 |
} else { |
| 322 |
$integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form'); |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
//Integrations [end] |
| 327 |
if (!empty($workFlows)) { |
| 328 |
$workFlowHandler = new WorkFlowHandler($formID, $user_details); |
| 329 |
// $formContent = $this->getAForm(array('id' => $save_status), null); |
| 330 |
$workflowCount = count($workFlows); |
| 331 |
while ($workflowCount) { |
| 332 |
$workFlow = $workFlows[--$workflowCount]; |
| 333 |
if (empty($workFlow->id)) { |
| 334 |
$savedID = $workFlowHandler->saveworkFlow($workFlow, $integartionIDForWorkflow); |
| 335 |
$newData['workflow'] = 1; |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
//wrokFlows [end] |
| 340 |
if (!empty($reports)) { |
| 341 |
$reportsModel = new ReportsModel(); |
| 342 |
// $formContent = $this->getAForm(array('id' => $save_status), null); |
| 343 |
foreach ($reports as $reportIndex => $report) { |
| 344 |
if (empty($report->id)) { |
| 345 |
$reportsModel->insert( |
| 346 |
array( |
| 347 |
"type" => 'table', |
| 348 |
"category" => 'form', |
| 349 |
"context" => $formID, |
| 350 |
"details" => is_string($report->details) ? $report->details : wp_json_encode($report->details), |
| 351 |
"isDefault" => 1, |
| 352 |
"user_id" => $user_details['id'], |
| 353 |
"user_ip" => $user_details['ip'], |
| 354 |
"user_device" => $user_details['device'], |
| 355 |
"created_at" => $user_details['time'], |
| 356 |
"updated_at" => $user_details['time'], |
| 357 |
) |
| 358 |
); |
| 359 |
$newData['reports'] = 1; |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
$updated_data = $this->getAForm(array('id' => $save_status), null); |
| 364 |
$updated_data['message'] = __('Form Saved successfully', 'bitform'); |
| 365 |
return $updated_data; |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
public function updateForm($Request, $post) |
| 370 |
{ |
| 371 |
if ($post->formStyle) { |
| 372 |
$sheetName = 'bitform-' . $post->id . '.css'; |
| 373 |
$this->saveStyleSheet($post->formStyle, $sheetName); |
| 374 |
} |
| 375 |
|
| 376 |
if ($post->layoutChanged) { |
| 377 |
$sheetName = 'bitform-layout-' . $post->id . '.css'; |
| 378 |
$rowHeight = (int)$post->rowHeight; |
| 379 |
$this->saveLayoutStyleSheet($post->layout, $sheetName, $rowHeight); |
| 380 |
} |
| 381 |
|
| 382 |
if (property_exists($post, 'fields') && $post->fields !== null && property_exists($post, 'layout') && $post->layout) { |
| 383 |
$fields = wp_unslash($post->fields); |
| 384 |
$layout = wp_unslash($post->layout); |
| 385 |
$formID = wp_unslash($post->id); |
| 386 |
$form_name = wp_unslash($post->form_name); |
| 387 |
$formSettings = wp_unslash($post->formSettings); |
| 388 |
$workFlows = wp_unslash($post->workFlows); |
| 389 |
$additional = wp_unslash($post->additional); |
| 390 |
$reports = wp_unslash($post->reports); |
| 391 |
} |
| 392 |
|
| 393 |
$mailTem = $formSettings->mailTem; |
| 394 |
$integrations = $formSettings->integrations; |
| 395 |
|
| 396 |
$user_details = static::$ipTool->getUserDetail(); |
| 397 |
if (empty($fields) || empty($layout) || is_null($formID)) { |
| 398 |
return new WP_Error('empty_form', 'Form is Empty, nothing to update'); |
| 399 |
} |
| 400 |
|
| 401 |
if (!class_exists("BitCode\\BitFormPro\\Plugin")) { |
| 402 |
if (count($workFlows) > 2) { |
| 403 |
return new WP_Error( |
| 404 |
'free_limit', |
| 405 |
__('you can add maximum 2 workflows ', 'bitform') |
| 406 |
); |
| 407 |
} |
| 408 |
} |
| 409 |
$form_content = array( |
| 410 |
'fields' => $fields, |
| 411 |
'layout' => $layout, |
| 412 |
); |
| 413 |
if (!empty($formSettings->submitBtn)) { |
| 414 |
$form_content = array_merge($form_content, array('buttons' => $formSettings->submitBtn)); |
| 415 |
} |
| 416 |
if (!empty($formSettings->theme)) { |
| 417 |
$form_content = array_merge($form_content, array('theme' => $formSettings->theme)); |
| 418 |
} |
| 419 |
if (!empty($additional)) { |
| 420 |
$form_content = array_merge($form_content, array('additional' => $additional)); |
| 421 |
} |
| 422 |
$integartionIDForWorkflow = array(); |
| 423 |
$newData['settingConfiramation'] = 0; |
| 424 |
$newData['integation'] = 0; |
| 425 |
$newData['mailTemplate'] = 0; |
| 426 |
$newData['workflow'] = 0; |
| 427 |
$newData['reports'] = 0; |
| 428 |
// Confiramtion Message [start] |
| 429 |
if (!empty($formSettings->confirmation->type->successMsg)) { |
| 430 |
$successMessages = $formSettings->confirmation->type->successMsg; |
| 431 |
$successMessageHandler |
| 432 |
= new SuccessMessageHandler($formID, $user_details); |
| 433 |
foreach ($successMessages as $messageKey => $messageDetail) { |
| 434 |
if (empty($messageDetail->id)) { |
| 435 |
$savedID = $successMessageHandler->saveMessage($messageDetail); |
| 436 |
if ($savedID) { |
| 437 |
$newData['settingConfiramation'] = 1; |
| 438 |
$integartionIDForWorkflow['successMsg'][$messageKey] = $savedID; |
| 439 |
} |
| 440 |
} else { |
| 441 |
$successMessageHandler->updateMessage($messageDetail); |
| 442 |
} |
| 443 |
} |
| 444 |
unset($formSettings->confirmation->type->successMsg); |
| 445 |
} |
| 446 |
// return $formSettings; |
| 447 |
// Confiramtion Message [end] */ |
| 448 |
// Email Template [start] |
| 449 |
if (!empty($mailTem)) { |
| 450 |
$emailTemplateHandler |
| 451 |
= new EmailTemplateHandler($formID, $user_details); |
| 452 |
foreach ($mailTem as $templateKey => $templateDetail) { |
| 453 |
if (empty($templateDetail->id)) { |
| 454 |
$savedID = $emailTemplateHandler->saveTemplate($templateDetail); |
| 455 |
if (is_wp_error($savedID) && $savedID->get_error_code() === 'result_empty') { |
| 456 |
$newData['mailTemplate'] = 2; |
| 457 |
} else { |
| 458 |
$newData['mailTemplate'] = 1; |
| 459 |
$integartionIDForWorkflow['mailTem'][$templateKey] = $savedID; |
| 460 |
} |
| 461 |
} else { |
| 462 |
$emailTemplateHandler->updateTemplate($templateDetail); |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
// return $formSettings; |
| 467 |
// Email Template [end] */ |
| 468 |
//Integration [start] */ |
| 469 |
$integrationHandler = new IntegrationHandler($formID, $user_details); |
| 470 |
if (!empty($formSettings->confirmation->type)) { |
| 471 |
$allIntegrations = $formSettings->confirmation->type; |
| 472 |
foreach ($allIntegrations as $integrationType => $integrationGroup) { |
| 473 |
foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) { |
| 474 |
if (empty($singleIntegrationDetail->details)) { |
| 475 |
$integrationName = $singleIntegrationDetail->title; |
| 476 |
unset($singleIntegrationDetail->title); |
| 477 |
$singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id; |
| 478 |
unset($singleIntegrationDetail->id); |
| 479 |
$integrationDetails = !is_string($singleIntegrationDetail) ? |
| 480 |
wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail; |
| 481 |
} else { |
| 482 |
$singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id; |
| 483 |
unset($singleIntegrationDetail->id); |
| 484 |
$integrationName = $singleIntegrationDetail->title; |
| 485 |
$integrationDetails = !is_string($singleIntegrationDetail->details) ? |
| 486 |
wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details; |
| 487 |
} |
| 488 |
if (empty($singleIntegrationDetailID)) { |
| 489 |
$savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form'); |
| 490 |
$newData['settingConfiramation'] = 1; |
| 491 |
$integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID; |
| 492 |
} else { |
| 493 |
$integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form'); |
| 494 |
} |
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
if (!empty($integrations)) { |
| 499 |
foreach ($integrations as $singleIntegrationKey => $singleIntegrationDetail) { |
| 500 |
$integrationName = $singleIntegrationDetail->name; |
| 501 |
unset($singleIntegrationDetail->name); |
| 502 |
$integrationType = $singleIntegrationDetail->type; |
| 503 |
unset($singleIntegrationDetail->type); |
| 504 |
$singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id; |
| 505 |
unset($singleIntegrationDetail->id); |
| 506 |
if (empty($singleIntegrationDetail->details)) { |
| 507 |
$integrationDetails = !is_string($singleIntegrationDetail) ? |
| 508 |
wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail; |
| 509 |
} else { |
| 510 |
$integrationDetails = !is_string($singleIntegrationDetail->details) ? |
| 511 |
wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details; |
| 512 |
} |
| 513 |
if (empty($singleIntegrationDetailID)) { |
| 514 |
$savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form'); |
| 515 |
$integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID; |
| 516 |
if (is_wp_error($savedID) && $savedID->get_error_code() !== 'result_empty') { |
| 517 |
$newData['integation'] = 2; |
| 518 |
} else { |
| 519 |
$newData['integation'] = 1; |
| 520 |
} |
| 521 |
} else { |
| 522 |
$integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form'); |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
//Integrations [end] |
| 527 |
//workFlows [start] */ |
| 528 |
$workFlowExist = []; |
| 529 |
if (!empty($workFlows)) { |
| 530 |
$workFlowHandler = new WorkFlowHandler($formID, $user_details); |
| 531 |
// foreach ($workFlows as $workFlowIndex => $workFlow) { |
| 532 |
$workflowCount = count($workFlows); |
| 533 |
while ($workflowCount) { |
| 534 |
$workFlow = $workFlows[--$workflowCount]; |
| 535 |
if ($workFlow->action_type === 'onload') { |
| 536 |
$workFlowExist['onload'] = true; |
| 537 |
} |
| 538 |
if ($workFlow->action_type === 'oninput') { |
| 539 |
$workFlowExist['oninput'] = true; |
| 540 |
} |
| 541 |
if (empty($workFlow->id)) { |
| 542 |
$savedID = $workFlowHandler->saveworkFlow($workFlow, $integartionIDForWorkflow); |
| 543 |
if (is_wp_error($savedID) && $savedID->get_error_code() !== 'result_empty') { |
| 544 |
$newData['workflow'] = 2; |
| 545 |
} else { |
| 546 |
$newData['workflow'] = 1; |
| 547 |
} |
| 548 |
} else { |
| 549 |
$workFlowHandler->updateworkFlow($workFlow->id, $workFlow, $integartionIDForWorkflow); |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
$form_content = array_merge($form_content, array('workFlowExist' => $workFlowExist)); |
| 554 |
//wrokFlows [end] |
| 555 |
//reports [start] */ |
| 556 |
if (!empty($reports)) { |
| 557 |
$reportsModel = new ReportsModel(); |
| 558 |
$fieldNames = []; |
| 559 |
foreach ($fields as $key => $field) { |
| 560 |
if (!empty($field->lbl)) { |
| 561 |
// $name = preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $field->lbl); |
| 562 |
$fieldNames["$key"] = $field->lbl; |
| 563 |
} |
| 564 |
} |
| 565 |
foreach ($reports as $reportIndex => $report) { |
| 566 |
$reportDetails = $reportsModel->validateReportFields($report, $fieldNames); |
| 567 |
|
| 568 |
if (empty($report->id)) { |
| 569 |
$reportSaveStatus = $reportsModel->insert( |
| 570 |
array( |
| 571 |
"type" => 'table', |
| 572 |
"category" => 'form', |
| 573 |
"context" => $formID, |
| 574 |
"details" => is_string($reportDetails) ? $reportDetails : wp_json_encode($reportDetails), |
| 575 |
"isDefault" => 1, |
| 576 |
"user_id" => $user_details['id'], |
| 577 |
"user_ip" => $user_details['ip'], |
| 578 |
"user_device" => $user_details['device'], |
| 579 |
"created_at" => $user_details['time'], |
| 580 |
"updated_at" => $user_details['time'], |
| 581 |
) |
| 582 |
); |
| 583 |
if (is_wp_error($reportSaveStatus) && $reportSaveStatus->get_error_code() !== 'result_empty') { |
| 584 |
$newData['reports'] = 2; |
| 585 |
} else { |
| 586 |
$newData['reports'] = 1; |
| 587 |
} |
| 588 |
} else { |
| 589 |
$reportsModel->update( |
| 590 |
array( |
| 591 |
"type" => 'table', |
| 592 |
"category" => 'form', |
| 593 |
"context" => $formID, |
| 594 |
"details" => is_string($reportDetails) ? $reportDetails : wp_json_encode($reportDetails), |
| 595 |
"isDefault" => 1, |
| 596 |
"user_id" => $user_details['id'], |
| 597 |
"user_ip" => $user_details['ip'], |
| 598 |
"user_device" => $user_details['device'], |
| 599 |
"updated_at" => $user_details['time'], |
| 600 |
), |
| 601 |
array( |
| 602 |
'id' => $report->id, |
| 603 |
) |
| 604 |
); |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
//reports [end] |
| 609 |
$form_content = wp_json_encode($form_content); |
| 610 |
$update_status = static::$formModel->update( |
| 611 |
array( |
| 612 |
"form_name" => $form_name, |
| 613 |
"form_content" => $form_content, |
| 614 |
"user_id" => $user_details['id'], |
| 615 |
"user_ip" => $user_details['ip'], |
| 616 |
"user_device" => $user_details['device'], |
| 617 |
"status" => 1, |
| 618 |
"updated_at" => $user_details['time'], |
| 619 |
), |
| 620 |
array( |
| 621 |
"id" => $formID, |
| 622 |
) |
| 623 |
); |
| 624 |
if (is_wp_error($update_status)) { |
| 625 |
return $update_status; |
| 626 |
} elseif (!$update_status) { |
| 627 |
return new WP_Error('empty_form', __('Form update Failed', 'bitform')); |
| 628 |
} else { |
| 629 |
$updated_data = $this->getAForm(array('id' => $formID), null); |
| 630 |
if ($newData['settingConfiramation'] === 0 && $newData['mailTemplate'] === 0 && $newData['integation'] === 0) { |
| 631 |
unset($updated_data['formSettings']); |
| 632 |
} |
| 633 |
if ($newData['integation'] === 0) { |
| 634 |
unset($updated_data['integrations']); |
| 635 |
} elseif ($newData['integation'] === 2) { |
| 636 |
$errorIN = ''; |
| 637 |
$errorIN .= empty($errorIN) ? 'integation' : ', integation'; |
| 638 |
} |
| 639 |
if ($newData['mailTemplate'] === 0) { |
| 640 |
unset($updated_data['mailTem']); |
| 641 |
} elseif ($newData['mailTemplate'] === 2) { |
| 642 |
$errorIN .= empty($errorIN) ? 'mailTemplate' : ', mailTemplate'; |
| 643 |
} |
| 644 |
if ($newData['workflow'] === 0) { |
| 645 |
unset($updated_data['workFlows']); |
| 646 |
} elseif ($newData['workflow'] === 2) { |
| 647 |
$errorIN .= empty($errorIN) ? 'workflow' : ', workflow'; |
| 648 |
} |
| 649 |
if ($newData['reports'] === 2) { |
| 650 |
$errorIN .= empty($errorIN) ? 'reports' : ', reports'; |
| 651 |
} |
| 652 |
if (!empty($errorIN)) { |
| 653 |
$updated_data['message'] = sprintf(__('Error Occured in saving %s', 'bitform'), $errorIN); |
| 654 |
return new WP_Error('form_update_error', $updated_data); |
| 655 |
} |
| 656 |
$updated_data['message'] = __('Form updated successfully', 'bitform'); |
| 657 |
return $updated_data; |
| 658 |
} |
| 659 |
} |
| 660 |
public function changeFormStatus($Request, $post) |
| 661 |
{ |
| 662 |
if (isset($Request['status']) && $Request['id']) { |
| 663 |
$status = wp_unslash($Request['status']); |
| 664 |
$id = wp_unslash($Request['id']); |
| 665 |
} else { |
| 666 |
$status = wp_unslash($post->status); |
| 667 |
$id = wp_unslash($post->id); |
| 668 |
} |
| 669 |
$user_details = static::$ipTool->getUserDetail(); |
| 670 |
// return $post->fields; |
| 671 |
$status = $status === 'true' || $status === true ? true : false; |
| 672 |
if (!is_bool($status) || is_null($id)) { |
| 673 |
// echo $status; |
| 674 |
return new WP_Error('status_change', __('Form status change failed', 'bitform')); |
| 675 |
} |
| 676 |
$update_status = static::$formModel->update( |
| 677 |
array( |
| 678 |
"user_id" => $user_details['id'], |
| 679 |
"user_ip" => $user_details['ip'], |
| 680 |
"user_device" => $user_details['device'], |
| 681 |
"status" => $status ? 1 : 0, |
| 682 |
"updated_at" => $user_details['time'], |
| 683 |
), |
| 684 |
array( |
| 685 |
"id" => $id, |
| 686 |
) |
| 687 |
); |
| 688 |
if (is_wp_error($update_status)) { |
| 689 |
return $update_status; |
| 690 |
} elseif (!$update_status) { |
| 691 |
return false; |
| 692 |
} else { |
| 693 |
return __('Form status changed successfully', 'bitform'); |
| 694 |
} |
| 695 |
} |
| 696 |
public function changeBulkFormStatus($Request, $post) |
| 697 |
{ |
| 698 |
if (isset($Request['status']) && $Request['formID']) { |
| 699 |
$status = wp_unslash($Request['status']); |
| 700 |
$formID = wp_unslash($Request['formID']); |
| 701 |
} else { |
| 702 |
$status = wp_unslash($post->status); |
| 703 |
$formID = wp_unslash($post->formID); |
| 704 |
} |
| 705 |
$user_details = static::$ipTool->getUserDetail(); |
| 706 |
// return $post->fields; |
| 707 |
$status = $status === 'true' || $status === true ? true : false; |
| 708 |
if (!is_bool($status) || is_null($formID) || !is_array($formID)) { |
| 709 |
// echo $status; |
| 710 |
return new WP_Error('status_change', __('Form status change failed', 'bitform')); |
| 711 |
} |
| 712 |
$update_status = static::$formModel->bulkUpdate( |
| 713 |
array( |
| 714 |
"user_id" => $user_details['id'], |
| 715 |
"user_ip" => $user_details['ip'], |
| 716 |
"user_device" => $user_details['device'], |
| 717 |
"status" => $status ? 1 : 0, |
| 718 |
"updated_at" => $user_details['time'], |
| 719 |
), |
| 720 |
array( |
| 721 |
"id" => $formID, |
| 722 |
) |
| 723 |
); |
| 724 |
if (is_wp_error($update_status)) { |
| 725 |
return $update_status; |
| 726 |
} elseif (!$update_status) { |
| 727 |
return false; |
| 728 |
} else { |
| 729 |
return __('Form status changed successfully', 'bitform'); |
| 730 |
} |
| 731 |
} |
| 732 |
public function getAllForm() |
| 733 |
{ |
| 734 |
$get_status = static::$formModel->get( |
| 735 |
array( |
| 736 |
"id", |
| 737 |
"status", |
| 738 |
"views", |
| 739 |
"entries", |
| 740 |
"form_name", |
| 741 |
"created_at", |
| 742 |
), |
| 743 |
array( |
| 744 |
"status" => array( |
| 745 |
'operator' => '!=', |
| 746 |
'value' => 2, |
| 747 |
), |
| 748 |
) |
| 749 |
); |
| 750 |
if (is_wp_error($get_status)) { |
| 751 |
return $get_status; |
| 752 |
} elseif (!$get_status) { |
| 753 |
return false; |
| 754 |
} else { |
| 755 |
return $get_status; |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
public function getAForm($Request, $post) |
| 760 |
{ |
| 761 |
if (isset($Request['id'])) { |
| 762 |
$formID = wp_unslash($Request['id']); |
| 763 |
} else { |
| 764 |
$formID = wp_unslash($post->id); |
| 765 |
} |
| 766 |
// return $post->fields; |
| 767 |
if (is_null($formID)) { |
| 768 |
return new WP_Error('empty_form', __('Form id is Empty', 'bitform')); |
| 769 |
} |
| 770 |
$formManager = new AdminFormManager($formID); |
| 771 |
if (!$formManager->isExist()) { |
| 772 |
return new WP_Error('not_exists', __('Form is not exists', 'bitform')); |
| 773 |
} |
| 774 |
$form_content = $formManager->getFormContent(); |
| 775 |
if ($formManager->isExist()) { |
| 776 |
$form_content_arr = array( |
| 777 |
'layout' => $form_content->layout, |
| 778 |
'fields' => $form_content->fields, |
| 779 |
'form_name' => $formManager->getFormName(), |
| 780 |
'workFlowExist' => $form_content->workFlowExist, |
| 781 |
); |
| 782 |
$successMessageHandler |
| 783 |
= new SuccessMessageHandler($formID); |
| 784 |
$successMessages = $successMessageHandler->getAllMessage(); |
| 785 |
if (!is_wp_error($successMessages)) { |
| 786 |
foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) { |
| 787 |
$allConfirmation['type']['successMsg'][$sucessMessagekey] = |
| 788 |
array( |
| 789 |
'id' => $sucessMessagevalue->id, |
| 790 |
'title' => $sucessMessagevalue->message_title, |
| 791 |
'msg' => $sucessMessagevalue->message_content, |
| 792 |
); |
| 793 |
} |
| 794 |
} |
| 795 |
$emailTemplateHandler |
| 796 |
= new EmailTemplateHandler($formID); |
| 797 |
$emailTemplates = $emailTemplateHandler->getAllTemplate(); |
| 798 |
if (!is_wp_error($emailTemplates)) { |
| 799 |
foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) { |
| 800 |
$mailTem[] = |
| 801 |
array( |
| 802 |
'id' => $emailTemplatevalue->id, |
| 803 |
'title' => $emailTemplatevalue->title, |
| 804 |
'sub' => $emailTemplatevalue->sub, |
| 805 |
'body' => $emailTemplatevalue->body, |
| 806 |
); |
| 807 |
} |
| 808 |
} |
| 809 |
$integrationHandler = new IntegrationHandler($formID); |
| 810 |
$formIntegrations = $integrationHandler->getAllIntegration('form'); |
| 811 |
if (!is_wp_error($formIntegrations)) { |
| 812 |
foreach ($formIntegrations as $integrationkey => $integrationValue) { |
| 813 |
if ($integrationValue->integration_type === 'redirectPage' || $integrationValue->integration_type === 'webHooks') { |
| 814 |
$integrationData = array( |
| 815 |
'id' => $integrationValue->id, |
| 816 |
'title' => $integrationValue->integration_name, |
| 817 |
); |
| 818 |
if (!empty($integrationValue->integration_details)) { |
| 819 |
// var_dump(json_decode($integrationValue->integration_details)); |
| 820 |
$integration_details = (array) json_decode($integrationValue->integration_details); |
| 821 |
$integrationData = array_merge($integrationData, $integration_details); |
| 822 |
} else { |
| 823 |
$integration_details = array( |
| 824 |
'url' => '', |
| 825 |
); |
| 826 |
$integrationData = array_merge($integrationData, $integration_details); |
| 827 |
} |
| 828 |
$allConfirmation['type'][$integrationValue->integration_type][] |
| 829 |
= $integrationData; |
| 830 |
} else { |
| 831 |
$integrationData = array( |
| 832 |
'id' => $integrationValue->id, |
| 833 |
'name' => $integrationValue->integration_name, |
| 834 |
'type' => $integrationValue->integration_type, |
| 835 |
); |
| 836 |
$integrations[] = array_merge( |
| 837 |
$integrationData, |
| 838 |
is_string($integrationValue->integration_details) ? |
| 839 |
(array) json_decode($integrationValue->integration_details) : |
| 840 |
$integrationValue->integration_details |
| 841 |
); |
| 842 |
} |
| 843 |
} |
| 844 |
} |
| 845 |
$settingsContent = array( |
| 846 |
'formName' => $formManager->getFormName(), |
| 847 |
'theme' => $form_content->theme, |
| 848 |
'submitBtn' => $form_content->buttons, |
| 849 |
); |
| 850 |
|
| 851 |
if (!empty($allConfirmation)) { |
| 852 |
$confirmation = array( |
| 853 |
'confirmation' => $allConfirmation, |
| 854 |
); |
| 855 |
} else { |
| 856 |
$confirmation = array( |
| 857 |
'confirmation' => array('type' => []), |
| 858 |
); |
| 859 |
} |
| 860 |
$settingsContent = array_merge($settingsContent, $confirmation); |
| 861 |
if (!empty($integrations)) { |
| 862 |
$settingsContent = array_merge( |
| 863 |
$settingsContent, |
| 864 |
array( |
| 865 |
'integrations' => $integrations, |
| 866 |
) |
| 867 |
); |
| 868 |
} else { |
| 869 |
$settingsContent = array_merge( |
| 870 |
$settingsContent, |
| 871 |
array( |
| 872 |
'integrations' => [] |
| 873 |
) |
| 874 |
); |
| 875 |
} |
| 876 |
if (!empty($mailTem)) { |
| 877 |
$settingsContent = array_merge( |
| 878 |
$settingsContent, |
| 879 |
array( |
| 880 |
'mailTem' => $mailTem, |
| 881 |
) |
| 882 |
); |
| 883 |
} else { |
| 884 |
$settingsContent = array_merge( |
| 885 |
$settingsContent, |
| 886 |
array( |
| 887 |
'mailTem' => [] |
| 888 |
) |
| 889 |
); |
| 890 |
} |
| 891 |
$formSettings = array( |
| 892 |
'formSettings' => $settingsContent, |
| 893 |
); |
| 894 |
$data = array( |
| 895 |
"id" => $formID, |
| 896 |
"form_name" => $formManager->getFormName(), |
| 897 |
"form_content" => $form_content_arr, |
| 898 |
"additional" => empty($form_content->additional) ? array( |
| 899 |
"enabled" => array( |
| 900 |
"blocked_ip" => false, |
| 901 |
"restrict_form" => false, |
| 902 |
), |
| 903 |
"settings" => array( |
| 904 |
"restrict_form" => array( |
| 905 |
'day' => [], |
| 906 |
'date' => array( |
| 907 |
'from' => null, |
| 908 |
'to' => null, |
| 909 |
), |
| 910 |
'time' => array( |
| 911 |
'from' => null, |
| 912 |
'to' => null, |
| 913 |
), |
| 914 |
), |
| 915 |
"entry_limit" => null, |
| 916 |
"blocked_ip" => [], |
| 917 |
), |
| 918 |
"onePerIp" => false, |
| 919 |
) : $form_content->additional, |
| 920 |
"created_at" => $formManager->getFormMetaData()['created_at'], |
| 921 |
"views" => $formManager->getFormMetaData()['views'], |
| 922 |
"entries" => $formManager->getFormMetaData()['entries'], |
| 923 |
"status" => $formManager->getFormMetaData()['status'], |
| 924 |
); |
| 925 |
$data = array_merge($data, $formSettings); |
| 926 |
$workFlowHandler = new WorkFlowHandler($formID); |
| 927 |
$workFlows = array('workFlows' => $workFlowHandler->getAllworkFlow()); |
| 928 |
$data = array_merge($data, $workFlows); |
| 929 |
$reportsModel = new ReportsModel(); |
| 930 |
$returnedReportData = $reportsModel->get( |
| 931 |
array( |
| 932 |
"id", |
| 933 |
"details", |
| 934 |
"isDefault", |
| 935 |
"type", |
| 936 |
), |
| 937 |
array( |
| 938 |
"category" => 'form', |
| 939 |
"context" => $formID, |
| 940 |
) |
| 941 |
); |
| 942 |
if (!is_wp_error($returnedReportData)) { |
| 943 |
$fieldNames = []; |
| 944 |
foreach ($form_content->fields as $key => $field) { |
| 945 |
if (!empty($field->lbl)) { |
| 946 |
// $name = preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $field->lbl); |
| 947 |
$fieldNames["$key"] = $field->lbl; |
| 948 |
} |
| 949 |
} |
| 950 |
if ($formManager->isGCLIDEnabled()) { |
| 951 |
$fieldNames["GCLID"] = "GCLID"; |
| 952 |
} |
| 953 |
foreach ($returnedReportData as $reportKey => $reportData) { |
| 954 |
$reportDetails = $reportsModel->validateReportFields($reportData, $fieldNames); |
| 955 |
if (!empty($reportDetails) && is_string($reportDetails)) { |
| 956 |
$returnedReportData[$reportKey]->details = json_decode($reportDetails); |
| 957 |
} elseif (!empty($reportDetails)) { |
| 958 |
$returnedReportData[$reportKey]->details = $reportDetails; |
| 959 |
} else { |
| 960 |
$returnedReportData[$reportKey]->details = []; |
| 961 |
} |
| 962 |
} |
| 963 |
$reports = array('reports' => $returnedReportData); |
| 964 |
$data = array_merge($data, $reports); |
| 965 |
} |
| 966 |
|
| 967 |
$formFields = $formManager->getFieldLabel(); |
| 968 |
$data = array_merge($data, array('Labels' => $formFields)); |
| 969 |
|
| 970 |
return $data; |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
public function deleteAForm($Request, $post) |
| 975 |
{ |
| 976 |
if (isset($Request['id'])) { |
| 977 |
$formID = wp_unslash($Request['id']); |
| 978 |
} else { |
| 979 |
$formID = wp_unslash($post->id); |
| 980 |
} |
| 981 |
if (is_null($formID)) { |
| 982 |
return new WP_Error('empty_form', __('Form id is Empty', 'bitform')); |
| 983 |
} |
| 984 |
$delete_status = static::$formModel->delete( |
| 985 |
array( |
| 986 |
"id" => $formID, |
| 987 |
) |
| 988 |
); |
| 989 |
|
| 990 |
$successMessageModel |
| 991 |
= new SuccessMessageModel(); |
| 992 |
$deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]); |
| 993 |
|
| 994 |
$emailTemplateModel |
| 995 |
= new EmailTemplateModel(); |
| 996 |
$deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]); |
| 997 |
|
| 998 |
$integrationModel = new IntegrationModel(); |
| 999 |
$deleteIntegrationStatus = $integrationModel->delete(['form_id' => $formID]); |
| 1000 |
|
| 1001 |
$workFlowModel = new WorkFlowModel(); |
| 1002 |
$deleteworkFlowStatus = $workFlowModel->delete(['form_id' => $formID]); |
| 1003 |
|
| 1004 |
$reportsModel = new ReportsModel(); |
| 1005 |
$deleteReportStatus = $reportsModel->delete(['context' => $formID]); |
| 1006 |
|
| 1007 |
$formEntryModel = new FormEntryModel(); |
| 1008 |
$returnedEntries = $formEntryModel->get("id", ["form_id" => $formID]); |
| 1009 |
$entries = []; |
| 1010 |
|
| 1011 |
if (!is_wp_error($returnedEntries)) { |
| 1012 |
foreach ($returnedEntries as $entryKey => $entryInfo) { |
| 1013 |
$entries[] = $entryInfo->id; |
| 1014 |
} |
| 1015 |
global $wpdb; |
| 1016 |
$prefix = $wpdb->prefix; |
| 1017 |
if (count($entries) > 0) { |
| 1018 |
$deleteEntriesStatus = $formEntryModel->bulkDelete( |
| 1019 |
array( |
| 1020 |
"`{$prefix}bitforms_form_entries`.`id`" => $entries, |
| 1021 |
"`{$prefix}bitforms_form_entries`.`form_id`" => $formID, |
| 1022 |
) |
| 1023 |
); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
|
| 1027 |
$fileHandler = new FileHandler(); |
| 1028 |
if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) { |
| 1029 |
$fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID); |
| 1030 |
} |
| 1031 |
if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) { |
| 1032 |
$fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID); |
| 1033 |
} |
| 1034 |
if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css')) { |
| 1035 |
unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css'); |
| 1036 |
} |
| 1037 |
if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css')) { |
| 1038 |
unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css'); |
| 1039 |
} |
| 1040 |
return is_wp_error($delete_status) ? $delete_status : __('Form deleted successfully', 'bitform'); |
| 1041 |
} |
| 1042 |
public function deleteBlukForm($Request, $post) |
| 1043 |
{ |
| 1044 |
if (isset($Request['formID'])) { |
| 1045 |
$formID = wp_unslash($Request['formID']); |
| 1046 |
} else { |
| 1047 |
$formID = wp_unslash($post->formID); |
| 1048 |
} |
| 1049 |
if (is_null($formID) || !is_array($formID)) { |
| 1050 |
return new WP_Error('empty_form', __('Form id is Empty', 'bitform')); |
| 1051 |
} |
| 1052 |
|
| 1053 |
foreach ($formID as $id) { |
| 1054 |
unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $id . '.css'); |
| 1055 |
unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $id . '.css'); |
| 1056 |
} |
| 1057 |
$delete_status = static::$formModel->bulkDelete( |
| 1058 |
array( |
| 1059 |
"id" => $formID, |
| 1060 |
) |
| 1061 |
); |
| 1062 |
$successMessageModel |
| 1063 |
= new SuccessMessageModel(); |
| 1064 |
$deleteMsgStatus = $successMessageModel->bulkDelete(['form_id' => $formID]); |
| 1065 |
|
| 1066 |
$emailTemplateModel |
| 1067 |
= new EmailTemplateModel(); |
| 1068 |
$deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]); |
| 1069 |
|
| 1070 |
$integrationModel = new IntegrationModel(); |
| 1071 |
$deleteIntegrationStatus = $integrationModel->bulkDelete(['form_id' => $formID]); |
| 1072 |
|
| 1073 |
$workFlowModel = new WorkFlowModel(); |
| 1074 |
$deleteworkFlowStatus = $workFlowModel->bulkDelete(['form_id' => $formID]); |
| 1075 |
|
| 1076 |
$reportsModel = new ReportsModel(); |
| 1077 |
$deleteReportStatus = $reportsModel->bulkDelete(['context' => $formID]); |
| 1078 |
|
| 1079 |
$formEntryModel = new FormEntryModel(); |
| 1080 |
$returnedEntries = $formEntryModel->get("id", ["form_id" => $formID]); |
| 1081 |
$entries = []; |
| 1082 |
foreach ($returnedEntries as $entryKey => $entryInfo) { |
| 1083 |
$entries[] = $entryInfo->id; |
| 1084 |
} |
| 1085 |
global $wpdb; |
| 1086 |
$prefix = $wpdb->prefix; |
| 1087 |
if (count($entries) > 0) { |
| 1088 |
$deleteEntriesStatus = $formEntryModel->bulkDelete( |
| 1089 |
array( |
| 1090 |
"`{$prefix}bitforms_form_entries`.`id`" => $entries, |
| 1091 |
"`{$prefix}bitforms_form_entries`.`form_id`" => $formID, |
| 1092 |
) |
| 1093 |
); |
| 1094 |
} |
| 1095 |
|
| 1096 |
$fileHandler = new FileHandler(); |
| 1097 |
foreach ($formID as $fId) { |
| 1098 |
if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) { |
| 1099 |
$fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId); |
| 1100 |
} |
| 1101 |
unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $fId . '.css'); |
| 1102 |
unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $fId . '.css'); |
| 1103 |
} |
| 1104 |
|
| 1105 |
return is_wp_error($delete_status) ? $delete_status : __('Forms deleted successfully', 'bitform'); |
| 1106 |
} |
| 1107 |
|
| 1108 |
public function genarateNewLayoutNField($layout, $fields, $oldId, $newId) |
| 1109 |
{ |
| 1110 |
$newField = (object) []; |
| 1111 |
foreach ($layout->lg as $ind => $itm) { |
| 1112 |
$fld_tmp = $fields->{$layout->lg[$ind]->i}; |
| 1113 |
$layout->lg[$ind]->i = str_replace("bf$oldId-", "bf$newId-", $layout->lg[$ind]->i); |
| 1114 |
$layout->md[$ind]->i = str_replace("bf$oldId-", "bf$newId-", $layout->md[$ind]->i); |
| 1115 |
$layout->sm[$ind]->i = str_replace("bf$oldId-", "bf$newId-", $layout->sm[$ind]->i); |
| 1116 |
$newField->{$layout->lg[$ind]->i} = $fld_tmp; |
| 1117 |
} |
| 1118 |
return ['layout' => $layout, 'fields' => $newField]; |
| 1119 |
} |
| 1120 |
|
| 1121 |
public function duplicateAForm($Request, $post) |
| 1122 |
{ |
| 1123 |
|
| 1124 |
$oldFormId = intval($post->id); |
| 1125 |
$newFormId = intval($post->newFormId); |
| 1126 |
if (is_null($oldFormId)) { |
| 1127 |
return new WP_Error('empty_form', __('Form id is Empty', 'bitform')); |
| 1128 |
} |
| 1129 |
|
| 1130 |
$formManager = new AdminFormManager($oldFormId); |
| 1131 |
if (!$formManager->isExist()) { |
| 1132 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1133 |
} |
| 1134 |
|
| 1135 |
$duplicatedForm = $this->getAForm($Request, $post); |
| 1136 |
$new_lay_fields = $this->genarateNewLayoutNField($duplicatedForm['form_content']['layout'], $duplicatedForm['form_content']['fields'], $oldFormId, $newFormId); |
| 1137 |
$duplicatedForm['form_content']['layout'] = $new_lay_fields['layout']; |
| 1138 |
$duplicatedForm['form_content']['fields'] = $new_lay_fields['fields']; |
| 1139 |
$insCol = ["id", "form_content", "user_id", "user_ip", "user_device", "status", "form_name", "created_at", "updated_at"]; |
| 1140 |
$form_name = substr($duplicatedForm['form_name'], 0, 50); |
| 1141 |
|
| 1142 |
$formContent = $duplicatedForm['form_content']; |
| 1143 |
$formContent['buttons'] = $duplicatedForm['formSettings']['submitBtn']; |
| 1144 |
$formContent['theme'] = $duplicatedForm['formSettings']['theme']; |
| 1145 |
$userDetails = static::$ipTool->getUserDetail(); |
| 1146 |
$dupCol = array( |
| 1147 |
$post->newFormId, |
| 1148 |
\json_encode($formContent), |
| 1149 |
$userDetails['id'], |
| 1150 |
$userDetails['ip'], |
| 1151 |
$userDetails['device'], |
| 1152 |
"status", |
| 1153 |
"Duplicate of $form_name", |
| 1154 |
$userDetails['time'], |
| 1155 |
$userDetails['time'], |
| 1156 |
); |
| 1157 |
$duplicate_status = static::$formModel->duplicate($insCol, $dupCol, ['id' => $oldFormId]); |
| 1158 |
if (is_wp_error($duplicate_status) && $duplicate_status->get_error_code() !== 'result_empty') { |
| 1159 |
return $duplicate_status; |
| 1160 |
} |
| 1161 |
$successMessageHandler |
| 1162 |
= new SuccessMessageHandler($newFormId, $userDetails); |
| 1163 |
$dupMsgStatus = $successMessageHandler->duplicaleAllMessage($oldFormId); |
| 1164 |
|
| 1165 |
$emailTemplateHandler = new EmailTemplateHandler($newFormId, $userDetails); |
| 1166 |
$emailTemplateHandler->duplicateAllTempInAForm($oldFormId); |
| 1167 |
|
| 1168 |
$integrationHandler = new IntegrationHandler($newFormId, $userDetails); |
| 1169 |
$integrationHandler->duplicateAllInAForm($oldFormId); |
| 1170 |
|
| 1171 |
$workFlowHandler = new WorkFlowHandler($newFormId, $userDetails); |
| 1172 |
$workFlowHandler->duplicateWorkFlow($oldFormId); |
| 1173 |
|
| 1174 |
$reportsModel = new ReportsModel(); |
| 1175 |
$repCols = array("type", "category", "context", "details", "isDefault", "user_id", "user_ip", "user_device", "created_at", "updated_at"); |
| 1176 |
$repDupData = array( |
| 1177 |
'table', |
| 1178 |
'form', |
| 1179 |
$newFormId, |
| 1180 |
"details", |
| 1181 |
"isDefault", |
| 1182 |
$userDetails['id'], |
| 1183 |
$userDetails['ip'], |
| 1184 |
$userDetails['device'], |
| 1185 |
$userDetails['time'], |
| 1186 |
$userDetails['time'], |
| 1187 |
); |
| 1188 |
$reportsModel->duplicate($repCols, $repDupData, ['context' => $oldFormId]); |
| 1189 |
|
| 1190 |
// duplicate stylesheet |
| 1191 |
$style_dir = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR; |
| 1192 |
// layout style copy |
| 1193 |
$mainFormLayStyle = fopen($style_dir . 'bitform-layout-' . $oldFormId . '.css', 'r'); |
| 1194 |
$styleStr = fread($mainFormLayStyle, filesize($style_dir . 'bitform-layout-' . $oldFormId . '.css')); |
| 1195 |
$newStyle = str_replace(".bf$oldFormId-", ".bf$newFormId-", $styleStr); |
| 1196 |
$createStyleFile = fopen($style_dir . "bitform-layout-$newFormId.css", 'w'); |
| 1197 |
fwrite($createStyleFile, $newStyle); |
| 1198 |
fclose($createStyleFile); |
| 1199 |
// style copy |
| 1200 |
$mainFormStyle = fopen($style_dir . 'bitform-' . $oldFormId . '.css', 'r'); |
| 1201 |
$styleStr = fread($mainFormStyle, filesize($style_dir . 'bitform-' . $oldFormId . '.css')); |
| 1202 |
$newStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr); |
| 1203 |
$createStyleFile = fopen($style_dir . "bitform-$newFormId.css", 'w'); |
| 1204 |
fwrite($createStyleFile, $newStyle); |
| 1205 |
fclose($createStyleFile); |
| 1206 |
|
| 1207 |
if (!is_wp_error($duplicate_status) || (is_wp_error($duplicate_status) && $duplicate_status->get_error_code() === 'result_empty')) { |
| 1208 |
$duplicatedForm = $this->getAForm(null, (object) ['id' => $newFormId]); |
| 1209 |
$duplicatedForm['message'] = __('Form duplicated successfully', 'bitform'); |
| 1210 |
return $duplicatedForm; |
| 1211 |
} |
| 1212 |
return $duplicate_status; |
| 1213 |
} |
| 1214 |
|
| 1215 |
public function getFormEntryLabelAndCount($Request, $post) |
| 1216 |
{ |
| 1217 |
if (isset($Request['id'])) { |
| 1218 |
$id = wp_unslash($Request['id']); |
| 1219 |
} else { |
| 1220 |
$id = wp_unslash($post->id); |
| 1221 |
} |
| 1222 |
if (is_null($id)) { |
| 1223 |
return new WP_Error('empty_form', __('Form id is Empty', 'bitform')); |
| 1224 |
} |
| 1225 |
$formManager = new AdminFormManager($id); |
| 1226 |
if (!$formManager->isExist()) { |
| 1227 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1228 |
} |
| 1229 |
$formFields = $formManager->getFieldLabel(); |
| 1230 |
$formEntry = new FormEntryModel(); |
| 1231 |
$count = $formEntry->count( |
| 1232 |
array( |
| 1233 |
'form_id' => $id, |
| 1234 |
) |
| 1235 |
); |
| 1236 |
$reportsModel = new ReportsModel(); |
| 1237 |
$returnedReportData = $reportsModel->get( |
| 1238 |
array( |
| 1239 |
"id", |
| 1240 |
"details", |
| 1241 |
"isDefault", |
| 1242 |
"type", |
| 1243 |
), |
| 1244 |
array( |
| 1245 |
"category" => 'form', |
| 1246 |
"context" => $id, |
| 1247 |
) |
| 1248 |
); |
| 1249 |
$labels = []; |
| 1250 |
if (!is_wp_error($returnedReportData)) { |
| 1251 |
$fieldNames = []; |
| 1252 |
foreach ($formFields as $field) { |
| 1253 |
$fieldNames[$field['key']] = $field['name']; |
| 1254 |
$labels[$field['key']] = $field; |
| 1255 |
} |
| 1256 |
foreach ($returnedReportData as $reportKey => $reportData) { |
| 1257 |
$reportDetails = $reportsModel->validateReportFields($reportData, $fieldNames); |
| 1258 |
if (!empty($reportDetails) && is_string($reportDetails)) { |
| 1259 |
$returnedReportData[$reportKey]->details = json_decode($reportDetails); |
| 1260 |
} elseif (!empty($reportDetails)) { |
| 1261 |
$returnedReportData[$reportKey]->details = $reportDetails; |
| 1262 |
} |
| 1263 |
} |
| 1264 |
$response['reports'] = empty($returnedReportData) ? [] : $returnedReportData; |
| 1265 |
} |
| 1266 |
|
| 1267 |
$response['count'] = intval($count[0]->count); |
| 1268 |
$response['Labels'] = $formFields; |
| 1269 |
$response['fieldDetails'] = $labels; |
| 1270 |
return $response; |
| 1271 |
} |
| 1272 |
public function getFormEntry($Request, $post) |
| 1273 |
{ |
| 1274 |
|
| 1275 |
if (isset($Request['id'])) { |
| 1276 |
$id = wp_unslash($Request['id']); |
| 1277 |
$offset = isset($Request['offset']) ? |
| 1278 |
wp_unslash($Request['offset']) : 0; |
| 1279 |
$pageSize = isset($Request['pageSize']) ? |
| 1280 |
wp_unslash($Request['pageSize']) : 10; |
| 1281 |
} else { |
| 1282 |
$id = wp_unslash($post->id); |
| 1283 |
$offset = isset($post->offset) ? wp_unslash($post->offset) : 0; |
| 1284 |
$sortBy = isset($post->sortBy) ? wp_unslash($post->sortBy) : null; |
| 1285 |
$filters = isset($post->filters) ? wp_unslash($post->filters) : null; |
| 1286 |
$globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null; |
| 1287 |
$pageSize = isset($post->pageSize) ? |
| 1288 |
wp_unslash($post->pageSize) : 10; |
| 1289 |
} |
| 1290 |
if (is_null($id)) { |
| 1291 |
return new WP_Error('empty_form', __('Form id is Empty', 'bitform')); |
| 1292 |
} |
| 1293 |
$formManager = new AdminFormManager($id); |
| 1294 |
if (!$formManager->isExist()) { |
| 1295 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1296 |
} |
| 1297 |
|
| 1298 |
$formEntry = new FormEntryModel(); |
| 1299 |
$entries = $formEntry->get( |
| 1300 |
'id', |
| 1301 |
array( |
| 1302 |
'form_id' => $id, |
| 1303 |
), |
| 1304 |
null, |
| 1305 |
null, |
| 1306 |
'created_at', |
| 1307 |
'DESC' |
| 1308 |
); |
| 1309 |
if (is_wp_error($entries)) { |
| 1310 |
if ($entries->get_error_code() === 'result_empty') { |
| 1311 |
return array( |
| 1312 |
'count' => 0, |
| 1313 |
'entries' => [], |
| 1314 |
); |
| 1315 |
} |
| 1316 |
return $entries; |
| 1317 |
} |
| 1318 |
$filter['field'] = $filters; |
| 1319 |
$filter['global'] = $globalFilter; |
| 1320 |
|
| 1321 |
$formFields = $formManager->getFieldLabel(); |
| 1322 |
$entryMeta = new FormEntryMetaModel(); |
| 1323 |
$formEntries = $entryMeta->getEntryMeta($formFields, $entries, $pageSize, $offset, $filter, $sortBy); |
| 1324 |
|
| 1325 |
return $formEntries; |
| 1326 |
} |
| 1327 |
public function getExportEntry($post){ |
| 1328 |
$formId = wp_unslash($post->formId); |
| 1329 |
$limit = isset($post->limit) ? wp_unslash($post->limit) : null; |
| 1330 |
$sortBy = isset($post->sortBy) ? wp_unslash($post->sortBy) :'ASC'; |
| 1331 |
$sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id'; |
| 1332 |
if (is_null($formId )) { |
| 1333 |
return new WP_Error('empty_form', __('Form id is Empty', 'bitform')); |
| 1334 |
} |
| 1335 |
$formManager = new AdminFormManager($formId); |
| 1336 |
if (!$formManager->isExist()) { |
| 1337 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1338 |
} |
| 1339 |
|
| 1340 |
$formEntry = new FormEntryModel(); |
| 1341 |
$entries = $formEntry->get( |
| 1342 |
'id', |
| 1343 |
array( |
| 1344 |
'form_id' => $formId , |
| 1345 |
), |
| 1346 |
null, |
| 1347 |
null, |
| 1348 |
'created_at', |
| 1349 |
'DESC' |
| 1350 |
); |
| 1351 |
if (is_wp_error($entries)) { |
| 1352 |
if ($entries->get_error_code() === 'result_empty') { |
| 1353 |
return array( |
| 1354 |
'count' => 0, |
| 1355 |
'entries' => [], |
| 1356 |
); |
| 1357 |
} |
| 1358 |
return $entries; |
| 1359 |
} |
| 1360 |
$formFields = $formManager->getFieldLabel(); |
| 1361 |
$entryMeta = new FormEntryMetaModel(); |
| 1362 |
$filter = []; |
| 1363 |
$formEntries = $entryMeta->getExportEntry($formFields, $entries, $limit, $sortBy,$sortByField,$filter); |
| 1364 |
return $formEntries; |
| 1365 |
} |
| 1366 |
public function deleteBlukFormEntries($Request, $post) |
| 1367 |
{ |
| 1368 |
if (isset($Request['formID'])) { |
| 1369 |
$formID = wp_unslash($Request['formID']); |
| 1370 |
$entries = wp_unslash($Request['entries']); |
| 1371 |
} else { |
| 1372 |
$formID = wp_unslash($post->formID); |
| 1373 |
$entries = wp_unslash($post->entries); |
| 1374 |
} |
| 1375 |
if (is_null($formID) || !is_array($entries) || count($entries) === 0) { |
| 1376 |
return new WP_Error('empty_form', __('Form id or entries id is Empty', 'bitform')); |
| 1377 |
} |
| 1378 |
$formManager = new AdminFormManager($formID); |
| 1379 |
if (!$formManager->isExist()) { |
| 1380 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1381 |
} |
| 1382 |
$workFlowRunHelper = new WorkFlowRunHelper($formID); |
| 1383 |
$workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete( |
| 1384 |
$formManager, |
| 1385 |
$formID, |
| 1386 |
$entries |
| 1387 |
); |
| 1388 |
if (isset($workFlowreturnedOnDelete['entries'])) { |
| 1389 |
if (count($workFlowreturnedOnDelete['entries']) === 0) { |
| 1390 |
return ["message" => __('Entry Deletetion prevented by workflow', 'bitform')]; |
| 1391 |
} elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) { |
| 1392 |
$message = __('Entry Deleted successfully', 'bitform'); |
| 1393 |
} else { |
| 1394 |
$result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']); |
| 1395 |
$entries = $workFlowreturnedOnDelete['entries']; |
| 1396 |
$message = __('Entry Deleted successfully, Some prevented by workflow', 'bitform'); |
| 1397 |
} |
| 1398 |
} else { |
| 1399 |
$message = __('Entry Deleted successfully', 'bitform'); |
| 1400 |
} |
| 1401 |
global $wpdb; |
| 1402 |
$prefix = $wpdb->prefix; |
| 1403 |
$formEntryModel = new FormEntryModel(); |
| 1404 |
$delete_status = $formEntryModel->bulkDelete( |
| 1405 |
array( |
| 1406 |
"`{$prefix}bitforms_form_entries`.`id`" => $entries, |
| 1407 |
"`{$prefix}bitforms_form_entries`.`form_id`" => $formID, |
| 1408 |
) |
| 1409 |
); |
| 1410 |
if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) { |
| 1411 |
$fileHandler = new FileHandler(); |
| 1412 |
foreach ($entries as $enrtyKey => $entryID) { |
| 1413 |
$fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID; |
| 1414 |
if (file_exists($fileEntries)) { |
| 1415 |
$fileHandler->rmrf($fileEntries); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
} |
| 1419 |
$count = $formEntryModel->count( |
| 1420 |
array( |
| 1421 |
'form_id' => $formID, |
| 1422 |
) |
| 1423 |
); |
| 1424 |
$formManager->resetSubmissionCount(intval($count[0]->count)); |
| 1425 |
if (is_wp_error($delete_status)) { |
| 1426 |
return new WP_Error('entry_not_exists', __("Form entry deletion failed", "bitform")); |
| 1427 |
} |
| 1428 |
$result['message'] = $message; |
| 1429 |
return $result; |
| 1430 |
} |
| 1431 |
public function duplicateFormEntry($Request, $post) |
| 1432 |
{ |
| 1433 |
if (isset($Request['formID'])) { |
| 1434 |
$formID = wp_unslash($Request['formID']); |
| 1435 |
$entries = wp_unslash($Request['entries']); |
| 1436 |
} else { |
| 1437 |
$formID = wp_unslash($post->formID); |
| 1438 |
$entries = wp_unslash($post->entries); |
| 1439 |
} |
| 1440 |
if (is_null($formID) || !is_array($entries) || empty($entries)) { |
| 1441 |
return new WP_Error('empty_form', __('Form id or entries id is Empty', 'bitform')); |
| 1442 |
} |
| 1443 |
|
| 1444 |
$formManager = new AdminFormManager($formID); |
| 1445 |
if (!$formManager->isExist()) { |
| 1446 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1447 |
} |
| 1448 |
$formEntryModel = new FormEntryModel(); |
| 1449 |
$entryMeta = new FormEntryMetaModel(); |
| 1450 |
$user_details = static::$ipTool->getUserDetail(); |
| 1451 |
$total_entries = count($entries); |
| 1452 |
$duplicate_count = 0; |
| 1453 |
$test = ''; |
| 1454 |
$fileHandler = new FileHandler(); |
| 1455 |
$result = array(); |
| 1456 |
foreach ($entries as $entryIndex => $entryID) { |
| 1457 |
$duplicatedEntryId = $formEntryModel->insert( |
| 1458 |
array( |
| 1459 |
'form_id' => $formID, |
| 1460 |
'user_id' => $user_details['id'], |
| 1461 |
'user_ip' => $user_details['ip'], |
| 1462 |
'user_device' => $user_details['device'], |
| 1463 |
'referer' => 'duplicate of #' . $entryID, |
| 1464 |
'status' => 0, |
| 1465 |
'created_at' => $user_details['time'], |
| 1466 |
) |
| 1467 |
); |
| 1468 |
if ($duplicatedEntryId) { |
| 1469 |
$duplicate_status = $entryMeta->duplicateEntryMeta( |
| 1470 |
array( |
| 1471 |
'duplicateID' => $duplicatedEntryId, |
| 1472 |
'entryID' => $entryID, |
| 1473 |
) |
| 1474 |
); |
| 1475 |
if ($duplicate_status) { |
| 1476 |
$result['details'][$entryID] = $duplicatedEntryId; |
| 1477 |
$duplicate_count = $duplicate_count + 1; |
| 1478 |
if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) { |
| 1479 |
$fileHandler->cpyr( |
| 1480 |
BITFORMS_UPLOAD_DIR . "/$formID/$entryID", |
| 1481 |
BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId" |
| 1482 |
); |
| 1483 |
} |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} |
| 1487 |
|
| 1488 |
$count = $formEntryModel->count( |
| 1489 |
array( |
| 1490 |
'form_id' => $formID, |
| 1491 |
) |
| 1492 |
); |
| 1493 |
$formManager->resetSubmissionCount(intval($count[0]->count)); |
| 1494 |
$result['message'] = count($entries) === 1 ? __('Entry Duplicated successfully', 'bitform') : __('Entries Duplicated successfully', 'bitform'); |
| 1495 |
return ($total_entries === $duplicate_count) ? $result : false; |
| 1496 |
} |
| 1497 |
public function editFormEntry($Request, $post) |
| 1498 |
{ |
| 1499 |
|
| 1500 |
if (isset($Request['formID'])) { |
| 1501 |
$formID = wp_unslash($Request['formID']); |
| 1502 |
$entryID = wp_unslash($Request['entryID']); |
| 1503 |
} else { |
| 1504 |
$formID = wp_unslash($post->formID); |
| 1505 |
$entryID = wp_unslash($post->entryID); |
| 1506 |
} |
| 1507 |
if (is_null($formID) || is_null($entryID)) { |
| 1508 |
return new WP_Error('empty_form', __('Form id or entries id is Empty', 'bitform')); |
| 1509 |
} |
| 1510 |
|
| 1511 |
$formManager = new AdminFormManager($formID); |
| 1512 |
if (!$formManager->isExist()) { |
| 1513 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1514 |
} |
| 1515 |
$formEntryModel = new FormEntryModel(); |
| 1516 |
$entryMeta = new FormEntryMetaModel(); |
| 1517 |
|
| 1518 |
$formEntry = $formEntryModel->get( |
| 1519 |
"*", |
| 1520 |
array( |
| 1521 |
'form_id' => $formID, |
| 1522 |
'id' => $entryID, |
| 1523 |
) |
| 1524 |
); |
| 1525 |
|
| 1526 |
if (!$formEntry) { |
| 1527 |
return new WP_Error('empty_form', __('provided form entries does not exists', 'bitform')); |
| 1528 |
} |
| 1529 |
$formEntryMeta = $entryMeta->get( |
| 1530 |
array( |
| 1531 |
'meta_key', |
| 1532 |
'meta_value', |
| 1533 |
), |
| 1534 |
array( |
| 1535 |
'bitforms_form_entry_id' => $entryID, |
| 1536 |
) |
| 1537 |
); |
| 1538 |
$entries = array(); |
| 1539 |
foreach ($formEntryMeta as $key => $value) { |
| 1540 |
$entries[$value->meta_key] = $value->meta_value; |
| 1541 |
} |
| 1542 |
$formContent = $formManager->getFormContent(); |
| 1543 |
$fieldsKey = $formManager->getFieldsKey(); |
| 1544 |
$form_fields = $formContent->fields; |
| 1545 |
$layout = $formContent->layout; |
| 1546 |
foreach ($form_fields as $key => $value) { |
| 1547 |
// $field_name = preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\!]/', '_', $value->lbl); |
| 1548 |
if (isset($entries[$key])) { |
| 1549 |
$form_fields->{$key}->val = $entries[$key]; |
| 1550 |
$form_fields->{$key}->name = $key; |
| 1551 |
} |
| 1552 |
} |
| 1553 |
$workFlowRunHelper = new WorkFlowRunHelper($formID); |
| 1554 |
$workFlowreturnedOnLoad = $workFlowRunHelper->executeOnLoad( |
| 1555 |
'edit', |
| 1556 |
$form_fields |
| 1557 |
); |
| 1558 |
$workFlowreturnedOnUserInput = $workFlowRunHelper->executeOnUserInput( |
| 1559 |
'edit', |
| 1560 |
$form_fields |
| 1561 |
); |
| 1562 |
// var_dump($workFlowreturned); |
| 1563 |
if (!empty($workFlowreturnedOnLoad['fields'])) { |
| 1564 |
$form_fields = $workFlowreturnedOnLoad['fields']; |
| 1565 |
} |
| 1566 |
$formData = array( |
| 1567 |
'layout' => $layout, |
| 1568 |
'fields' => $form_fields, |
| 1569 |
'conditional' => !empty($workFlowreturnedOnUserInput['conditional']) ? $workFlowreturnedOnUserInput['conditional'] : false, |
| 1570 |
'fieldToCheck' => !empty($workFlowreturnedOnUserInput['fieldToCheck']) ? $workFlowreturnedOnUserInput['fieldToCheck'] : false, |
| 1571 |
'fieldToChange' => !empty($workFlowreturnedOnUserInput['fieldToChange']) ? $workFlowreturnedOnUserInput['fieldToChange'] : false, |
| 1572 |
'fieldsKey' => $fieldsKey, |
| 1573 |
); |
| 1574 |
return $formData; |
| 1575 |
} |
| 1576 |
public function updateFormEntry($Request, $post) |
| 1577 |
{ |
| 1578 |
|
| 1579 |
if (isset($Request['formID']) && isset($Request['entryID'])) { |
| 1580 |
$formID = wp_unslash($Request['formID']); |
| 1581 |
$entryID = wp_unslash($Request['entryID']); |
| 1582 |
unset($Request['action']); |
| 1583 |
unset($Request['formID']); |
| 1584 |
unset($Request['entryID']); |
| 1585 |
$updatedValue = wp_unslash($Request); |
| 1586 |
} |
| 1587 |
|
| 1588 |
if (is_null($updatedValue) || !is_array($updatedValue)) { |
| 1589 |
return new WP_Error('empty_data', __('Nothing to updata. Data is empty!!', 'bitform')); |
| 1590 |
} |
| 1591 |
|
| 1592 |
if (is_null($formID) || is_null($entryID)) { |
| 1593 |
return new WP_Error('empty_data', __('Form id or entries id is Empty', 'bitform')); |
| 1594 |
} |
| 1595 |
|
| 1596 |
$formManager = new AdminFormManager($formID); |
| 1597 |
if (!$formManager->isExist()) { |
| 1598 |
return new WP_Error('empty_data', __('provided form does not exists', 'bitform')); |
| 1599 |
} |
| 1600 |
return $formManager->updateFormEntry($updatedValue, $formID, $entryID); |
| 1601 |
} |
| 1602 |
|
| 1603 |
public function getLogHistory($Request, $post) |
| 1604 |
{ |
| 1605 |
if (isset($Request['formID'])) { |
| 1606 |
$formID = wp_unslash($Request['formID']); |
| 1607 |
$entryID = wp_unslash($Request['entryID']); |
| 1608 |
} else { |
| 1609 |
$formID = wp_unslash($post->formID); |
| 1610 |
$entryID = wp_unslash($post->entryID); |
| 1611 |
} |
| 1612 |
|
| 1613 |
if (is_null($formID) || is_null($entryID)) { |
| 1614 |
return new WP_Error('empty_form', __('Form id or entries id is Empty', 'bitform')); |
| 1615 |
} |
| 1616 |
|
| 1617 |
$formManager = new AdminFormManager($formID); |
| 1618 |
if (!$formManager->isExist()) { |
| 1619 |
return new WP_Error('empty_form', __('provided form does not exists', 'bitform')); |
| 1620 |
} |
| 1621 |
$formLogModel = new FormEntryLogModel(); |
| 1622 |
|
| 1623 |
$log_history = $formLogModel->geLogHistory($formID, $entryID); |
| 1624 |
return $log_history; |
| 1625 |
} |
| 1626 |
|
| 1627 |
public function importDataStore($Request, $post){ |
| 1628 |
if (isset($Request['formID'])) { |
| 1629 |
$formID = wp_unslash($Request['formID']); |
| 1630 |
} else { |
| 1631 |
$formID = wp_unslash($post->formID); |
| 1632 |
} |
| 1633 |
if (is_null($formID)) { |
| 1634 |
return new WP_Error('empty_form', __('Form id or entries id is Empty', 'bitform')); |
| 1635 |
} |
| 1636 |
|
| 1637 |
} |
| 1638 |
|
| 1639 |
public function getAllWPPages($Request, $post) |
| 1640 |
{ |
| 1641 |
$pages = get_pages(array('post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc')); |
| 1642 |
$allPages = array(); |
| 1643 |
foreach ($pages as $pageKey => $pageDetails) { |
| 1644 |
$allPages[$pageKey]['title'] = $pageDetails->post_title; |
| 1645 |
$allPages[$pageKey]['url'] = get_page_link($pageDetails->ID); |
| 1646 |
} |
| 1647 |
return $allPages; |
| 1648 |
} |
| 1649 |
public function deleteAIntegration($Request, $post) |
| 1650 |
{ |
| 1651 |
if (isset($Request['formID']) && $Request['id']) { |
| 1652 |
$formID = json_decode(wp_unslash($Request['formID'])); |
| 1653 |
$id = wp_unslash($Request['id']); |
| 1654 |
} else { |
| 1655 |
$formID = wp_unslash($post->formID); |
| 1656 |
$id = wp_unslash($post->id); |
| 1657 |
} |
| 1658 |
if (empty($formID) || empty($id)) { |
| 1659 |
return new WP_Error('empty_form', 'Form ID or Integration ID is Empty, nothing to delete'); |
| 1660 |
} |
| 1661 |
|
| 1662 |
$integrationHandler = new IntegrationHandler($formID); |
| 1663 |
$delete_status = $integrationHandler->deleteIntegration($id); |
| 1664 |
if (is_wp_error($delete_status)) { |
| 1665 |
return $delete_status; |
| 1666 |
} |
| 1667 |
|
| 1668 |
return array( |
| 1669 |
'message' => __('Integration deleted', 'bitform'), |
| 1670 |
); |
| 1671 |
} |
| 1672 |
|
| 1673 |
public function deleteSuccessMessage($Request, $post) |
| 1674 |
{ |
| 1675 |
if (isset($Request['formID']) && $Request['id']) { |
| 1676 |
$formID = json_decode(wp_unslash($Request['formID'])); |
| 1677 |
$id = wp_unslash($Request['id']); |
| 1678 |
} else { |
| 1679 |
$formID = wp_unslash($post->formID); |
| 1680 |
$id = wp_unslash($post->id); |
| 1681 |
} |
| 1682 |
if (empty($formID) || empty($id)) { |
| 1683 |
return new WP_Error('empty_form', 'Form ID or Message ID is Empty, nothing to delete'); |
| 1684 |
} |
| 1685 |
$successMessageHandler |
| 1686 |
= new SuccessMessageHandler($formID); |
| 1687 |
$delete_status = $successMessageHandler->deleteMessage($id); |
| 1688 |
if (is_wp_error($delete_status)) { |
| 1689 |
return $delete_status; |
| 1690 |
} |
| 1691 |
return array( |
| 1692 |
'message' => __('Message deleted', 'bitform'), |
| 1693 |
); |
| 1694 |
} |
| 1695 |
|
| 1696 |
public function deleteAWorkflow($Request, $post) |
| 1697 |
{ |
| 1698 |
if (isset($Request['formID']) && $Request['id']) { |
| 1699 |
$formID = json_decode(wp_unslash($Request['formID'])); |
| 1700 |
$id = wp_unslash($Request['id']); |
| 1701 |
} else { |
| 1702 |
$formID = wp_unslash($post->formID); |
| 1703 |
$id = wp_unslash($post->id); |
| 1704 |
} |
| 1705 |
if (empty($formID) || empty($id)) { |
| 1706 |
return new WP_Error('empty_form', 'Form ID or Workflow ID is Empty, nothing to delete'); |
| 1707 |
} |
| 1708 |
$workFlowHandler = new WorkFlowHandler($formID); |
| 1709 |
$delete_status = $workFlowHandler->deleteworkFlow($id); |
| 1710 |
if (is_wp_error($delete_status)) { |
| 1711 |
return $delete_status; |
| 1712 |
} |
| 1713 |
return array( |
| 1714 |
'message' => __('workflow deleted', 'bitform'), |
| 1715 |
); |
| 1716 |
} |
| 1717 |
public function deleteAMailTemplate($Request, $post) |
| 1718 |
{ |
| 1719 |
if (isset($Request['formID']) && $Request['id']) { |
| 1720 |
$formID = json_decode(wp_unslash($Request['formID'])); |
| 1721 |
$id = wp_unslash($Request['id']); |
| 1722 |
} else { |
| 1723 |
$formID = wp_unslash($post->formID); |
| 1724 |
$id = wp_unslash($post->id); |
| 1725 |
} |
| 1726 |
if (empty($formID) || empty($id)) { |
| 1727 |
return new WP_Error('empty_form', 'Form ID or Email Template ID is Empty, nothing to delete'); |
| 1728 |
} |
| 1729 |
$emailTemplateHandler = new EmailTemplateHandler($formID); |
| 1730 |
$delete_status = $emailTemplateHandler->deleteTemplate($id); |
| 1731 |
if (is_wp_error($delete_status)) { |
| 1732 |
return $delete_status; |
| 1733 |
} |
| 1734 |
return array( |
| 1735 |
'message' => __('Email Template deleted', 'bitform'), |
| 1736 |
); |
| 1737 |
} |
| 1738 |
public function duplicateAMailTemplate($Request, $post) |
| 1739 |
{ |
| 1740 |
if (isset($Request['formID']) && $Request['id']) { |
| 1741 |
$formID = json_decode(wp_unslash($Request['formID'])); |
| 1742 |
$id = wp_unslash($Request['id']); |
| 1743 |
} else { |
| 1744 |
$formID = wp_unslash($post->formID); |
| 1745 |
$id = wp_unslash($post->id); |
| 1746 |
} |
| 1747 |
if (empty($formID) || empty($id)) { |
| 1748 |
return new WP_Error('empty_form', 'Form ID or Email Template ID is Empty, nothing to duplicate'); |
| 1749 |
} |
| 1750 |
$emailTemplateHandler = new EmailTemplateHandler($formID); |
| 1751 |
$duplicate_status = $emailTemplateHandler->duplicateTemplate($id); |
| 1752 |
if (is_wp_error($duplicate_status)) { |
| 1753 |
return $duplicate_status; |
| 1754 |
} |
| 1755 |
return array( |
| 1756 |
'message' => __('Email Template duplicated', 'bitform'), |
| 1757 |
); |
| 1758 |
} |
| 1759 |
public function setAllFormsReport($Request, $post) |
| 1760 |
{ |
| 1761 |
$reports = empty($post->reports) ? null : wp_unslash($post->reports); |
| 1762 |
if (empty($reports)) { |
| 1763 |
return new WP_Error('empty_report_prefs', 'Report data is Empty, nothing to save or update'); |
| 1764 |
} |
| 1765 |
if (!empty($reports)) { |
| 1766 |
$reportsModel = new ReportsModel(); |
| 1767 |
$user_details = static::$ipTool->getUserDetail(); |
| 1768 |
foreach ($reports as $reportIndex => $report) { |
| 1769 |
if (empty($report->id)) { |
| 1770 |
$reportSaveSatus = $reportsModel->insert( |
| 1771 |
array( |
| 1772 |
"type" => 'table', |
| 1773 |
"category" => 'app', |
| 1774 |
"context" => 'allForm', |
| 1775 |
"details" => is_string($report->details) ? $report->details : wp_json_encode($report->details), |
| 1776 |
"isDefault" => 1, |
| 1777 |
"user_id" => $user_details['id'], |
| 1778 |
"user_ip" => $user_details['ip'], |
| 1779 |
"user_device" => $user_details['device'], |
| 1780 |
"created_at" => $user_details['time'], |
| 1781 |
"updated_at" => $user_details['time'], |
| 1782 |
) |
| 1783 |
); |
| 1784 |
$newData['reports'] = 1; |
| 1785 |
} else { |
| 1786 |
$reportSaveSatus = $reportsModel->update( |
| 1787 |
array( |
| 1788 |
"type" => 'table', |
| 1789 |
"category" => 'app', |
| 1790 |
"context" => 'allForm', |
| 1791 |
"details" => is_string($report->details) ? $report->details : wp_json_encode($report->details), |
| 1792 |
"isDefault" => 1, |
| 1793 |
"user_id" => $user_details['id'], |
| 1794 |
"user_ip" => $user_details['ip'], |
| 1795 |
"user_device" => $user_details['device'], |
| 1796 |
"updated_at" => $user_details['time'], |
| 1797 |
), |
| 1798 |
array( |
| 1799 |
'id' => $report->id, |
| 1800 |
) |
| 1801 |
); |
| 1802 |
} |
| 1803 |
} |
| 1804 |
} |
| 1805 |
if (is_wp_error($reportSaveSatus)) { |
| 1806 |
if ($reportSaveSatus->get_error_code() === 'result_empty') { |
| 1807 |
return new WP_Error('empty_report_prefs', 'Nothing to save or update'); |
| 1808 |
} |
| 1809 |
return new WP_Error('error_report_prefs', 'Error occured in saving reports'); |
| 1810 |
} |
| 1811 |
$returnedReportData = $reportsModel->get( |
| 1812 |
array( |
| 1813 |
"id", |
| 1814 |
"details", |
| 1815 |
"isDefault", |
| 1816 |
"category", |
| 1817 |
"context", |
| 1818 |
), |
| 1819 |
array( |
| 1820 |
"category" => 'app', |
| 1821 |
"context" => 'allForm', |
| 1822 |
) |
| 1823 |
); |
| 1824 |
if (!is_wp_error($returnedReportData)) { |
| 1825 |
foreach ($returnedReportData as $reportKey => $reportData) { |
| 1826 |
if (isset($reportData->details) && is_string($reportData->details)) { |
| 1827 |
$returnedReportData[$reportKey]->details = json_decode($reportData->details); |
| 1828 |
} |
| 1829 |
} |
| 1830 |
$reports = $returnedReportData; |
| 1831 |
} |
| 1832 |
return array( |
| 1833 |
'message' => __('Report preferrences saved successfully', 'bitform'), |
| 1834 |
'reports' => empty($reports) ? [] : $reports, |
| 1835 |
); |
| 1836 |
} |
| 1837 |
|
| 1838 |
public function savegReCaptcha($Request, $post) |
| 1839 |
{ |
| 1840 |
if (isset($post->reCaptchaV2)) { |
| 1841 |
$reCaptchaV2 = $post->reCaptchaV2; |
| 1842 |
} else { |
| 1843 |
$reCaptchaV2 = $post->reCaptchaV2; |
| 1844 |
} |
| 1845 |
if (is_null($reCaptchaV2)) { |
| 1846 |
return new WP_Error('empty_gcaptchdetails', __('g-ReCAPTCHA details is empty', 'bitform')); |
| 1847 |
} |
| 1848 |
if (is_string($reCaptchaV2) && !empty(json_decode($reCaptchaV2)->id)) { |
| 1849 |
$reCaptchaV2 = json_decode($reCaptchaV2); |
| 1850 |
$integrationID = $reCaptchaV2->id; |
| 1851 |
unset($reCaptchaV2->id); |
| 1852 |
} else { |
| 1853 |
$integrationID = $reCaptchaV2->id; |
| 1854 |
unset($reCaptchaV2->id); |
| 1855 |
} |
| 1856 |
$reCaptchaV2 = json_encode($reCaptchaV2); |
| 1857 |
$integrationName = 'google reCaptcha'; |
| 1858 |
$integrationType = 'gReCaptcha'; |
| 1859 |
$integrationDetails = $reCaptchaV2; |
| 1860 |
$user_details = static::$ipTool->getUserDetail(); |
| 1861 |
$integrationHandler = new IntegrationHandler(0, $user_details); |
| 1862 |
$response = array(); |
| 1863 |
if (empty($integrationID)) { |
| 1864 |
$captchaSaveStatus = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'app'); |
| 1865 |
$response['id'] = $captchaSaveStatus; |
| 1866 |
$response['message'] = __('g-reCAPTCHA saved successfully', 'bitform'); |
| 1867 |
} else { |
| 1868 |
$captchaSaveStatus = $integrationHandler->updateIntegration($integrationID, $integrationName, $integrationType, $integrationDetails, 'app'); |
| 1869 |
$response['message'] = __('g-reCAPTCHA updated successfully', 'bitform'); |
| 1870 |
} |
| 1871 |
|
| 1872 |
if (is_wp_error($captchaSaveStatus)) { |
| 1873 |
return $captchaSaveStatus; |
| 1874 |
} |
| 1875 |
return $response; |
| 1876 |
} |
| 1877 |
} |
| 1878 |
|