@@ -705,84 +705,6 @@ public static function validateStartChat(& $inputForm, & $start_data_fields, & $
705705 $ chat ->chat_locale = $ siteAccessOptions ['content_language ' ];
706706 }
707707 }
708-
709- $ unsetAdminCustomFields = array ();
710-
711- if (isset ($ start_data_fields ['custom_fields ' ]) && $ start_data_fields ['custom_fields ' ] != '' ) {
712- $ customAdminfields = json_decode ($ start_data_fields ['custom_fields ' ],true );
713-
714- $ valuesArray = array ();
715-
716- // Fill values if exists
717- if ($ form ->hasValidData ( 'value_items_admin ' )){
718- $ inputForm ->value_items_admin = $ valuesArray = $ form ->value_items_admin ;
719- }
720-
721- // If data comes from payload we process it a different way
722- if (isset ($ additionalParams ['payload_data ' ])) {
723- foreach ($ customAdminfields as $ key => $ adminField ) {
724- if (isset ($ additionalParams ['payload_data ' ]['value_items_admin_ ' . $ key ])) {
725- $ inputForm ->value_items_admin [$ key ] = $ valuesArray [$ key ] = $ additionalParams ['payload_data ' ]['value_items_admin_ ' . $ key ];
726- }
727- }
728- }
729-
730- if ($ form ->hasValidData ( 'via_hidden ' )){
731- $ inputForm ->via_hidden = $ form ->via_hidden ;
732- }
733-
734- if ($ form ->hasValidData ( 'via_encrypted ' )) {
735- $ inputForm ->via_encrypted = $ form ->via_encrypted ;
736- }
737-
738- if (is_array ($ customAdminfields )) {
739-
740- foreach ($ customAdminfields as $ key => $ adminField ) {
741-
742- if (isset ($ adminField ['showcondition ' ]) && $ adminField ['showcondition ' ] === 'uempty ' && $ chat ->nick !== 'Visitor ' && !empty ($ chat ->nick )) {
743- continue ;
744- }
745-
746- $ fieldName = self ::extractFieldName ($ adminField );
747-
748- if (isset ($ adminField ['showcondition ' ]) && $ adminField ['showcondition ' ] === 'uempty ' ) {
749- $ unsetAdminCustomFields [] = array (
750- 'identifier ' => isset ($ adminField ['fieldidentifier ' ]) ? $ adminField ['fieldidentifier ' ] : null ,
751- 'key ' => $ fieldName
752- );
753- }
754-
755- if (
756- (
757- isset ($ adminField ['isrequired ' ]) && ($ adminField ['isrequired ' ] == 'true ' || $ adminField ['isrequired ' ] == 1 ) && !isset ($ inputForm ->value_items_admin [$ key ]) && ($ adminField ['visibility ' ] == 'all ' || $ adminField ['visibility ' ] == (isset ($ additionalParams ['offline ' ]) ? 'off ' : 'on ' ))
758- ) ||
759- (
760- isset ($ inputForm ->value_items_admin [$ key ]) && isset ($ adminField ['isrequired ' ]) && ($ adminField ['isrequired ' ] == 'true ' || $ adminField ['isrequired ' ] == 1 ) &&
761- ($ adminField ['visibility ' ] == 'all ' || $ adminField ['visibility ' ] == (isset ($ additionalParams ['offline ' ]) ? 'off ' : 'on ' )) &&
762- (!isset ($ valuesArray [$ key ]) || trim ($ valuesArray [$ key ]) == '' )
763- )
764- ) {
765- $ Errors [(isset ($ additionalParams ['payload_data ' ]) ? 'value_items_admin_ ' . $ key : 'additional_admin_ ' . $ key )] = trim ($ fieldName ).': ' .erTranslationClassLhTranslation::getInstance ()->getTranslation ('chat/startchat ' ,'is required ' );
766- }
767-
768- if (isset ($ valuesArray [$ key ]) && $ valuesArray [$ key ] != '' ) {
769-
770- $ valueStore = (isset ($ valuesArray [$ key ]) ? trim ($ valuesArray [$ key ]) : '' );
771- $ secure = false ;
772- if (isset ($ inputForm ->via_encrypted [$ key ]) && $ inputForm ->via_encrypted [$ key ] == 't ' && $ valueStore != '' ) {
773- try {
774- $ valueStore = self ::decryptAdditionalField ($ valueStore , $ chat );
775- $ secure = true ;
776- } catch (Exception $ e ) {
777- $ valueStore = $ e ->getMessage ();
778- }
779- }
780-
781- $ stringParts [] = array ('secure ' => $ secure , 'h ' => (isset ($ inputForm ->via_hidden [$ key ]) || $ adminField ['fieldtype ' ] == 'hidden ' ), 'identifier ' => (isset ($ adminField ['fieldidentifier ' ])) ? $ adminField ['fieldidentifier ' ] : null , 'key ' => $ fieldName , 'value ' => $ valueStore );
782- }
783- }
784- }
785- }
786708
787709 $ refererALL = isset ($ _POST ['URLRefer ' ]) ? $ _POST ['URLRefer ' ] : '' ;
788710
@@ -821,6 +743,8 @@ public static function validateStartChat(& $inputForm, & $start_data_fields, & $
821743 $ inputForm ->jsvar = $ form ->jsvar ;
822744 }
823745
746+ $ identifiers = [];
747+
824748 foreach (erLhAbstractModelChatVariable::getList (array ('customfilter ' => array ('dep_id = 0 OR dep_id = ' . (int )$ chat ->dep_id ))) as $ jsVar ) {
825749 if (($ form ->hasValidData ( 'jsvar ' ) && isset ($ additionalParams ['payload_data ' ]['jsvar ' ][$ jsVar ->id ]) && $ additionalParams ['payload_data ' ]['jsvar ' ][$ jsVar ->id ] !== null && $ additionalParams ['payload_data ' ]['jsvar ' ][$ jsVar ->id ] !== '' ) || ($ jsVar ->type == 5 && isset ($ _COOKIE [$ jsVar ->js_variable ]))) {
826750
@@ -944,27 +868,82 @@ public static function validateStartChat(& $inputForm, & $start_data_fields, & $
944868 $ stringParts = array_filter ($ stringParts , function ($ item ) use ($ jsVar ) {
945869 return !isset ($ item ['identifier ' ]) || $ item ['identifier ' ] !== $ jsVar ->var_identifier ;
946870 });
947-
871+ $ identifiers [] = $ jsVar -> var_identifier ;
948872 $ stringParts [] = array ('secure ' => $ secure , 'h ' => false , 'identifier ' => $ jsVar ->var_identifier , 'key ' => $ jsVar ->var_name , 'value ' => $ val );
949873 }
950874 }
951875
952876 }
953877 }
954878
955- if (!empty ($ unsetAdminCustomFields ) && $ chat ->nick !== 'Visitor ' && !empty ($ chat ->nick )) {
956- $ stringParts = array_filter ($ stringParts , function ($ item ) use ($ unsetAdminCustomFields ) {
957- foreach ($ unsetAdminCustomFields as $ adminField ) {
958- if (
959- (isset ($ item ['identifier ' ]) ? $ item ['identifier ' ] : null ) === $ adminField ['identifier ' ] &&
960- (isset ($ item ['key ' ]) ? $ item ['key ' ] : null ) === $ adminField ['key ' ]
961- ) {
962- return false ;
879+
880+ if (isset ($ start_data_fields ['custom_fields ' ]) && $ start_data_fields ['custom_fields ' ] != '' ) {
881+ $ customAdminfields = json_decode ($ start_data_fields ['custom_fields ' ],true );
882+
883+ $ valuesArray = array ();
884+
885+ // Fill values if exists
886+ if ($ form ->hasValidData ( 'value_items_admin ' )){
887+ $ inputForm ->value_items_admin = $ valuesArray = $ form ->value_items_admin ;
888+ }
889+
890+ // If data comes from payload we process it a different way
891+ if (isset ($ additionalParams ['payload_data ' ])) {
892+ foreach ($ customAdminfields as $ key => $ adminField ) {
893+ if (isset ($ additionalParams ['payload_data ' ]['value_items_admin_ ' . $ key ])) {
894+ $ inputForm ->value_items_admin [$ key ] = $ valuesArray [$ key ] = $ additionalParams ['payload_data ' ]['value_items_admin_ ' . $ key ];
963895 }
964896 }
897+ }
965898
966- return true ;
967- });
899+ if ($ form ->hasValidData ( 'via_hidden ' )){
900+ $ inputForm ->via_hidden = $ form ->via_hidden ;
901+ }
902+
903+ if ($ form ->hasValidData ( 'via_encrypted ' )) {
904+ $ inputForm ->via_encrypted = $ form ->via_encrypted ;
905+ }
906+
907+ if (is_array ($ customAdminfields )) {
908+
909+ foreach ($ customAdminfields as $ key => $ adminField ) {
910+
911+ if ((isset ($ adminField ['showcondition ' ]) && $ adminField ['showcondition ' ] === 'uempty ' && $ chat ->nick !== 'Visitor ' && !empty ($ chat ->nick )) || isset ($ adminField ['fieldidentifier ' ]) && in_array ($ adminField ['fieldidentifier ' ], $ identifiers )) {
912+ continue ;
913+ }
914+
915+ $ fieldName = self ::extractFieldName ($ adminField );
916+
917+ if (
918+ (
919+ isset ($ adminField ['isrequired ' ]) && ($ adminField ['isrequired ' ] == 'true ' || $ adminField ['isrequired ' ] == 1 ) && !isset ($ inputForm ->value_items_admin [$ key ]) && ($ adminField ['visibility ' ] == 'all ' || $ adminField ['visibility ' ] == (isset ($ additionalParams ['offline ' ]) ? 'off ' : 'on ' ))
920+ ) ||
921+ (
922+ isset ($ inputForm ->value_items_admin [$ key ]) && isset ($ adminField ['isrequired ' ]) && ($ adminField ['isrequired ' ] == 'true ' || $ adminField ['isrequired ' ] == 1 ) &&
923+ ($ adminField ['visibility ' ] == 'all ' || $ adminField ['visibility ' ] == (isset ($ additionalParams ['offline ' ]) ? 'off ' : 'on ' )) &&
924+ (!isset ($ valuesArray [$ key ]) || trim ($ valuesArray [$ key ]) == '' )
925+ )
926+ ) {
927+ $ Errors [(isset ($ additionalParams ['payload_data ' ]) ? 'value_items_admin_ ' . $ key : 'additional_admin_ ' . $ key )] = trim ($ fieldName ).': ' .erTranslationClassLhTranslation::getInstance ()->getTranslation ('chat/startchat ' ,'is required ' );
928+ }
929+
930+ if (isset ($ valuesArray [$ key ]) && $ valuesArray [$ key ] != '' ) {
931+
932+ $ valueStore = (isset ($ valuesArray [$ key ]) ? trim ($ valuesArray [$ key ]) : '' );
933+ $ secure = false ;
934+ if (isset ($ inputForm ->via_encrypted [$ key ]) && $ inputForm ->via_encrypted [$ key ] == 't ' && $ valueStore != '' ) {
935+ try {
936+ $ valueStore = self ::decryptAdditionalField ($ valueStore , $ chat );
937+ $ secure = true ;
938+ } catch (Exception $ e ) {
939+ $ valueStore = $ e ->getMessage ();
940+ }
941+ }
942+
943+ $ stringParts [] = array ('secure ' => $ secure , 'h ' => (isset ($ inputForm ->via_hidden [$ key ]) || $ adminField ['fieldtype ' ] == 'hidden ' ), 'identifier ' => (isset ($ adminField ['fieldidentifier ' ])) ? $ adminField ['fieldidentifier ' ] : null , 'key ' => $ fieldName , 'value ' => $ valueStore );
944+ }
945+ }
946+ }
968947 }
969948
970949 if ($ department !== false ) {
0 commit comments