| 1 |
<?php |
| 2 |
require_once SMART_FORMS_DIR.'php_classes/edit/pre_edit_entry.php'; |
| 3 |
|
| 4 |
class php_entry_editor |
| 5 |
{ |
| 6 |
function execute_editor($entryId,$entryData,$elementOptions) |
| 7 |
{ |
| 8 |
global $wpdb; |
| 9 |
$entry=new PreEditEntry($entryId,$entryData,$elementOptions); |
| 10 |
do_action('smart_forms_before_editing_entry',array($entry)); |
| 11 |
$result= $wpdb->update( |
| 12 |
SMART_FORMS_ENTRY, |
| 13 |
array( |
| 14 |
'data'=>$entryData, |
| 15 |
), |
| 16 |
array( |
| 17 |
'entry_id'=>$entryId |
| 18 |
) |
| 19 |
); |
| 20 |
|
| 21 |
if($result==false) |
| 22 |
return true; |
| 23 |
|
| 24 |
$entryData=json_decode($entryData,true); |
| 25 |
|
| 26 |
$entryData["_formid"]=$entryId; |
| 27 |
$result=$this->ParseAndInsertDetail($entryId,$entryData,$this->GetFormElementsDictionary($elementOptions)); |
| 28 |
return $result; |
| 29 |
} |
| 30 |
|
| 31 |
public function GetFormElementsDictionary($elementOptions) |
| 32 |
{ |
| 33 |
$elements=json_decode($elementOptions,true); |
| 34 |
$formElementsDictionary =array(); |
| 35 |
foreach($elements as $element) |
| 36 |
$formElementsDictionary[$element["Id"]]=$element; |
| 37 |
|
| 38 |
return $formElementsDictionary; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
function ParseAndInsertDetail($entryId,$entryData,$formElementsDictionary) |
| 43 |
{ |
| 44 |
include_once(SMART_FORMS_DIR.'string_renderer/rednao_string_builder.php'); |
| 45 |
include_once(SMART_FORMS_DIR.'smart-forms-ajax.php'); |
| 46 |
$stringBuilder=new rednao_string_builder(); |
| 47 |
global $wpdb; |
| 48 |
$wpdb->delete(SMART_FORMS_ENTRY_DETAIL, array('entry_id' => $entryId)); |
| 49 |
foreach($entryData as $key=>$unprocessedValue) |
| 50 |
{ |
| 51 |
if(!isset($formElementsDictionary[$key])) |
| 52 |
continue; |
| 53 |
|
| 54 |
$fieldConfiguration=$formElementsDictionary[$key]; |
| 55 |
$value=$stringBuilder->GetStringFromColumn($fieldConfiguration,$unprocessedValue); |
| 56 |
$exValue=$stringBuilder->GetExValue($fieldConfiguration,$unprocessedValue); |
| 57 |
$dateValue=$stringBuilder->GetDateValue($fieldConfiguration,$unprocessedValue); |
| 58 |
if($dateValue!=null) |
| 59 |
$dateValue=date('Y-m-d',$dateValue); |
| 60 |
$jsonValue=json_encode($unprocessedValue); |
| 61 |
if(!$this->InsertDetailRecord($entryId,$key,$value,$jsonValue,$exValue,$dateValue)) |
| 62 |
return true; |
| 63 |
} |
| 64 |
|
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
function InsertDetailRecord($entry_id, $fieldId, $value, $jsonValue,$exValue,$dateValue) |
| 69 |
{ |
| 70 |
global $wpdb; |
| 71 |
$arrayToInsert=array_merge(array( |
| 72 |
"entry_id"=>$entry_id, |
| 73 |
"field_id"=>$fieldId, |
| 74 |
"json_value"=>$jsonValue, |
| 75 |
"value"=>$value |
| 76 |
),$exValue); |
| 77 |
|
| 78 |
if($dateValue!=null) |
| 79 |
$arrayToInsert["datevalue"]=$dateValue; |
| 80 |
return $wpdb->insert(SMART_FORMS_ENTRY_DETAIL,$arrayToInsert); |
| 81 |
} |
| 82 |
} |