@@ -65,7 +65,29 @@ public static function renderForm($form, $asAdmin = false) {
6565 // Support {args.form.*} and {args.form_collected.*} variable substitution
6666 $ translationArgs = array ('form ' => $ form );
6767 if (self ::$ collectedObject !== false ) {
68- $ translationArgs ['form_collected ' ] = self ::$ collectedObject ;
68+ $ formCollected = clone self ::$ collectedObject ;
69+ $ contentArray = $ formCollected ->content_array ;
70+ if (isset ($ contentArray ['lhc_field_changes ' ])) {
71+ if (isset ($ contentArray ['lhc_field_changes ' ]['field_history ' ]) && is_array ($ contentArray ['lhc_field_changes ' ]['field_history ' ])) {
72+ foreach ($ contentArray ['lhc_field_changes ' ]['field_history ' ] as $ field => $ history ) {
73+ if (isset ($ history ['user_id ' ])) {
74+ $ contentArray ['lhc_field_changes ' ]['field_history ' ][$ field ]['user ' ] = erLhcoreClassModelUser::fetch ($ history ['user_id ' ]);
75+ }
76+ }
77+ }
78+ if (isset ($ contentArray ['lhc_field_changes ' ]['modified_operators ' ]) && is_array ($ contentArray ['lhc_field_changes ' ]['modified_operators ' ])) {
79+ $ modifierNames = [];
80+ foreach ($ contentArray ['lhc_field_changes ' ]['modified_operators ' ] as $ userId => $ modifierData ) {
81+ $ user = erLhcoreClassModelUser::fetch ($ userId );
82+ if ($ user instanceof erLhcoreClassModelUser) {
83+ $ modifierNames [] = $ user ->name_official ;
84+ }
85+ }
86+ $ contentArray ['lhc_field_changes ' ]['modifiers ' ] = implode (', ' , $ modifierNames );
87+ }
88+ $ formCollected ->content_array = $ contentArray ;
89+ }
90+ $ translationArgs ['form_collected ' ] = $ formCollected ;
6991 }
7092 $ contentForm = erLhcoreClassGenericBotWorkflow::translateMessage ($ contentForm , array ('args ' => $ translationArgs ));
7193
@@ -168,7 +190,7 @@ public static function setCollectedInformation($information) {
168190 public static function processInput ($ inputDefinition , $ asAdmin = false ) {
169191 if (is_array ($ inputDefinition )) {
170192 $ paramsParsed = $ inputDefinition ;
171- } else {
193+ } elseif ( is_string ( $ inputDefinition )) {
172194 $ inputDefinition = str_replace (array ('[[ ' ,']] ' ), '' , $ inputDefinition );
173195 $ paramsInput = explode ('|| ' , $ inputDefinition );
174196 $ defaultType = array_shift ($ paramsInput );
@@ -186,10 +208,16 @@ public static function processInput($inputDefinition, $asAdmin = false) {
186208
187209 $ paramsParsed ['as_admin ' ] = $ asAdmin ;
188210
189- return call_user_func ('erLhcoreClassFormRenderer::renderInputType ' .ucfirst ($ paramsParsed ['type ' ]),$ paramsParsed );
211+ $ method = 'renderInputType ' .ucfirst (isset ($ paramsParsed ['type ' ]) ? $ paramsParsed ['type ' ] : '' );
212+ if (!method_exists ('erLhcoreClassFormRenderer ' , $ method )) {
213+ return 'INVALID_FIELD ' ;
214+ }
215+
216+ return call_user_func ('erLhcoreClassFormRenderer:: ' .$ method ,$ paramsParsed );
190217 }
191218
192219 public static function renderInputTypeRange ($ params ) {
220+
193221 $ additionalAttributes = self ::renderAdditionalAtrributes ($ params );
194222
195223 if (ezcInputForm::hasPostData ()) {
@@ -973,7 +1001,8 @@ public static function storeCollectedInformation($form, $collectedInformation, $
9731001 // Finish collect information
9741002 foreach ($ collectedInformation as $ fieldName => & $ params ) {
9751003 // Do not save file again if it was chat file
976- if (!in_array ($ fieldName , $ chatAttributes ) && $ params ['definition ' ]['type ' ] == 'file ' && !(isset ($ params ['definition ' ]['scope ' ]) && $ params ['definition ' ]['scope ' ] == 'chat ' )) {
1004+
1005+ if (!in_array ($ fieldName , $ chatAttributes ) && isset ($ params ['definition ' ]['type ' ]) && $ params ['definition ' ]['type ' ] == 'file ' && !(isset ($ params ['definition ' ]['scope ' ]) && $ params ['definition ' ]['scope ' ] == 'chat ' )) {
9771006
9781007 $ dir = 'var/storageform/ ' .date ('Y ' ).'y/ ' .date ('m ' ).'/ ' .date ('d ' ).'/ ' .$ formCollected ->id .'/ ' ;
9791008
@@ -998,6 +1027,60 @@ public static function storeCollectedInformation($form, $collectedInformation, $
9981027 }
9991028 }
10001029
1030+
1031+ if (isset ($ form ->configuration_array ['track_field_changes ' ]) && $ form ->configuration_array ['track_field_changes ' ] == true && $ form ->form_type == erLhAbstractModelForm::FORM_TYPE_INTERNAL ) {
1032+ if ($ formCollected ->user_id != erLhcoreClassUser::instance ()->getUserID ()) {
1033+ $ currentUserId = erLhcoreClassUser::instance ()->getUserID ();
1034+ $ currentTime = time ();
1035+
1036+ // Load previous content to compare against
1037+ $ previousContent = $ formCollected ->content_array ;
1038+ if (!is_array ($ previousContent )) {
1039+ $ previousContent = [];
1040+ }
1041+
1042+ // Preserve existing field changes history from previous saves
1043+ $ fieldChanges = isset ($ previousContent ['lhc_field_changes ' ]) ? $ previousContent ['lhc_field_changes ' ] : ['modified_operators ' => [], 'field_history ' => []];
1044+ $ modifiedFields = [];
1045+
1046+ foreach ($ collectedInformation as $ fieldName => $ params ) {
1047+ if ($ fieldName === 'lhc_field_changes ' ) continue ;
1048+ if (!isset ($ params ['definition ' ]['log_changes ' ]) || $ params ['definition ' ]['log_changes ' ] != 'true ' ) continue ;
1049+
1050+ $ newValue = isset ($ params ['value ' ]) ? $ params ['value ' ] : null ;
1051+ $ oldValue = isset ($ previousContent [$ fieldName ]['value ' ]) ? $ previousContent [$ fieldName ]['value ' ] : null ;
1052+
1053+ // Compare values; skip comparison for file fields (track by filename instead)
1054+ if ($ params ['definition ' ]['type ' ] == 'file ' ) {
1055+ $ newValue = isset ($ params ['filename ' ]) ? $ params ['filename ' ] : null ;
1056+ $ oldValue = isset ($ previousContent [$ fieldName ]['filename ' ]) ? $ previousContent [$ fieldName ]['filename ' ] : null ;
1057+ }
1058+
1059+ if ($ newValue !== $ oldValue ) {
1060+ $ modifiedFields [] = $ fieldName ;
1061+
1062+ $ fieldChanges ['field_history ' ][$ fieldName ] = [
1063+ 'user_id ' => $ currentUserId ,
1064+ 'modified_at ' => $ currentTime ,
1065+ 'old_value ' => $ oldValue ,
1066+ 'new_value ' => $ newValue
1067+ ];
1068+ }
1069+ }
1070+
1071+ if (!empty ($ modifiedFields )) {
1072+ $ existingFields = isset ($ fieldChanges ['modified_operators ' ][$ currentUserId ]['fields ' ]) ? $ fieldChanges ['modified_operators ' ][$ currentUserId ]['fields ' ] : [];
1073+ $ fieldChanges ['modified_operators ' ][$ currentUserId ] = [
1074+ 'fields ' => array_unique (array_merge ($ existingFields , $ modifiedFields )),
1075+ 'modified_at ' => $ currentTime
1076+ ];
1077+ }
1078+
1079+ $ collectedInformation ['lhc_field_changes ' ] = $ fieldChanges ;
1080+ }
1081+ }
1082+
1083+
10011084 $ formCollected ->content = json_encode ($ collectedInformation );
10021085 $ formCollected ->custom_fields = json_encode ($ customFields );
10031086 $ formCollected ->saveThis ();
0 commit comments