@@ -172,7 +172,7 @@ public static function installBaseData(Migration $migration, $version)
172172 foreach ($ result as $ type ) {
173173 $ migration_genericobject_itemtype [$ type ['itemtype ' ]] = [
174174 'genericobject_itemtype ' => $ type ['itemtype ' ],
175- 'itemtype ' => 'Glpi\CustomAsset \\' . $ type ['name ' ] . 'Asset ' ,
175+ 'itemtype ' => 'Glpi \\\\ CustomAsset \\ \\' . $ type ['name ' ] . 'Asset ' ,
176176 'genericobject_name ' => $ type ['name ' ],
177177 'name ' => $ type ['name ' ] . 'Asset ' ,
178178 ];
@@ -191,7 +191,7 @@ public static function installBaseData(Migration $migration, $version)
191191 $ container_class = new self ();
192192 foreach ($ result as $ container ) {
193193 self ::generateTemplate ($ container );
194- foreach (json_decode ($ container ['itemtypes ' ]) as $ itemtype ) {
194+ foreach (PluginFieldsToolbox:: decodeJSONItemtypes ($ container ['itemtypes ' ]) as $ itemtype ) {
195195 $ classname = self ::getClassname ($ itemtype , $ container ["name " ]);
196196 $ old_table = $ classname ::getTable ();
197197 // Rename genericobject container table
@@ -239,7 +239,7 @@ public static function installUserData(Migration $migration, $version)
239239 foreach ($ containers as $ container ) {
240240 $ itemtypes = [];
241241 if (!empty ($ container ['itemtypes ' ])) {
242- $ decoded = json_decode ($ container ['itemtypes ' ], true );
242+ $ decoded = PluginFieldsToolbox:: decodeJSONItemtypes ($ container ['itemtypes ' ], true );
243243 if (is_array ($ decoded )) {
244244 $ itemtypes = $ decoded ;
245245 }
@@ -290,7 +290,7 @@ public static function installUserData(Migration $migration, $version)
290290
291291 // Update container name
292292 $ new_name = $ toolbox ->getSystemNameFromLabel ($ container ['label ' ]);
293- foreach (json_decode ($ container ['itemtypes ' ]) as $ itemtype ) {
293+ foreach (PluginFieldsToolbox:: decodeJSONItemtypes ($ container ['itemtypes ' ]) as $ itemtype ) {
294294 while (strlen (getTableForItemType (self ::getClassname ($ itemtype , $ new_name ))) > 64 ) {
295295 // limit tables names to 64 chars (MySQL limit)
296296 $ new_name = substr ($ new_name , 0 , -1 );
@@ -304,7 +304,7 @@ public static function installUserData(Migration $migration, $version)
304304 );
305305
306306 // Rename container tables and itemtype if needed
307- foreach (json_decode ($ container ['itemtypes ' ]) as $ itemtype ) {
307+ foreach (PluginFieldsToolbox:: decodeJSONItemtypes ($ container ['itemtypes ' ]) as $ itemtype ) {
308308 $ migration ->renameItemtype (
309309 self ::getClassname ($ itemtype , $ old_name ),
310310 self ::getClassname ($ itemtype , $ new_name ),
@@ -640,7 +640,7 @@ public function prepareInputForAdd($input)
640640 $ found = $ this ->find (['type ' => 'dom ' ]);
641641 if (count ($ found ) > 0 ) {
642642 foreach (array_column ($ found , 'itemtypes ' ) as $ founditemtypes ) {
643- foreach (json_decode ($ founditemtypes ) as $ founditemtype ) {
643+ foreach (PluginFieldsToolbox:: decodeJSONItemtypes ($ founditemtypes ) as $ founditemtype ) {
644644 if (in_array ($ founditemtype , $ input ['itemtypes ' ])) {
645645 Session::AddMessageAfterRedirect (__ ("You cannot add several blocks with type 'Insertion in the form' on same object " , 'fields ' ), false , ERROR );
646646
@@ -656,7 +656,7 @@ public function prepareInputForAdd($input)
656656 $ found = $ this ->find (['type ' => 'domtab ' , 'subtype ' => $ input ['subtype ' ]]);
657657 if (count ($ found ) > 0 ) {
658658 foreach (array_column ($ found , 'itemtypes ' ) as $ founditemtypes ) {
659- foreach (json_decode ($ founditemtypes ) as $ founditemtype ) {
659+ foreach (PluginFieldsToolbox:: decodeJSONItemtypes ($ founditemtypes ) as $ founditemtype ) {
660660 if (in_array ($ founditemtype , $ input ['itemtypes ' ])) {
661661 Session::AddMessageAfterRedirect (__ ("You cannot add several blocks with type 'Insertion in the form of a specific tab' on same object tab " , 'fields ' ), false , ERROR );
662662
@@ -688,7 +688,7 @@ public function prepareInputForAdd($input)
688688 $ found = $ this ->find (['name ' => $ input ['name ' ]]);
689689 if (count ($ found ) > 0 ) {
690690 foreach (array_column ($ found , 'itemtypes ' ) as $ founditemtypes ) {
691- foreach (json_decode ($ founditemtypes ) as $ founditemtype ) {
691+ foreach (PluginFieldsToolbox:: decodeJSONItemtypes ($ founditemtypes ) as $ founditemtype ) {
692692 if (in_array ($ founditemtype , $ input ['itemtypes ' ])) {
693693 Session::AddMessageAfterRedirect (__ ('You cannot add several blocs with identical name on same object ' , 'fields ' ), false , ERROR );
694694
@@ -781,7 +781,7 @@ public function pre_deleteItem()
781781
782782 $ _SESSION ['delete_container ' ] = true ;
783783
784- foreach (json_decode ($ this ->fields ['itemtypes ' ]) as $ itemtype ) {
784+ foreach (PluginFieldsToolbox:: decodeJSONItemtypes ($ this ->fields ['itemtypes ' ]) as $ itemtype ) {
785785 $ classname = self ::getClassname ($ itemtype , $ this ->fields ['name ' ]);
786786 $ sysname = self ::getSystemName ($ itemtype , $ this ->fields ['name ' ]);
787787 $ class_filename = $ sysname . '.class.php ' ;
@@ -843,7 +843,7 @@ public static function preItemPurge($item)
843843 $ containers = new self ();
844844 $ founded_containers = $ containers ->find ();
845845 foreach ($ founded_containers as $ container ) {
846- $ itemtypes = json_decode ($ container ['itemtypes ' ]);
846+ $ itemtypes = PluginFieldsToolbox:: decodeJSONItemtypes ($ container ['itemtypes ' ]);
847847 if (in_array ($ itemtype , $ itemtypes )) {
848848 $ classname = self ::getClassname ($ itemtype , $ container ['name ' ]);
849849 $ fields = new $ classname ();
@@ -927,7 +927,7 @@ public function showForm($ID, $options = [])
927927 echo '<td> ' . __ ('Associated item type ' ) . ' : </td> ' ;
928928 echo '<td> ' ;
929929 if ($ ID > 0 ) {
930- $ types = json_decode ($ this ->fields ['itemtypes ' ]);
930+ $ types = PluginFieldsToolbox:: decodeJSONItemtypes ($ this ->fields ['itemtypes ' ]);
931931 $ obj = '' ;
932932 $ count = count ($ types );
933933 $ i = 1 ;
@@ -968,7 +968,7 @@ public function showForm($ID, $options = [])
968968 echo '<td> ' ;
969969 echo " <span id='subtype_ $ rand'></span> " ;
970970 if ($ ID > 0 && !empty ($ this ->fields ['subtype ' ])) {
971- $ itemtypes = json_decode ($ this ->fields ['itemtypes ' ], true );
971+ $ itemtypes = PluginFieldsToolbox:: decodeJSONItemtypes ($ this ->fields ['itemtypes ' ], true );
972972 $ itemtype = array_shift ($ itemtypes );
973973 $ dbu = new DbUtils ();
974974 $ item = $ dbu ->getItemForItemtype ($ itemtype );
@@ -1233,7 +1233,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
12331233 foreach ($ itemtypes [$ item ->getType ()] as $ tab_name => $ tab_label ) {
12341234 // needs to check if entity of item is in hierachy of $tab_name
12351235 foreach ($ container ->find (['is_active ' => 1 , 'name ' => $ tab_name ]) as $ data ) {
1236- $ dataitemtypes = json_decode ($ data ['itemtypes ' ]);
1236+ $ dataitemtypes = PluginFieldsToolbox:: decodeJSONItemtypes ($ data ['itemtypes ' ]);
12371237 if (in_array (get_class ($ item ), $ dataitemtypes ) != false ) {
12381238 $ entities = [$ data ['entities_id ' ]];
12391239 if ($ data ['is_recursive ' ]) {
@@ -1265,7 +1265,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
12651265 //retrieve container for current tab
12661266 $ container = new self ();
12671267 if ($ container ->getFromDB ($ tabnum )) {
1268- $ dataitemtypes = json_decode ($ container ->fields ['itemtypes ' ]);
1268+ $ dataitemtypes = PluginFieldsToolbox:: decodeJSONItemtypes ($ container ->fields ['itemtypes ' ]);
12691269 if (in_array (get_class ($ item ), $ dataitemtypes ) != false ) {
12701270 return PluginFieldsField::showForTabContainer ($ container ->fields ['id ' ], $ item );
12711271 }
@@ -2242,7 +2242,7 @@ public function prepareInputForClone($input)
22422242 if (array_key_exists ('itemtypes ' , $ input ) && !empty ($ input ['itemtypes ' ])) {
22432243 // $input has been transformed with `Toolbox::addslashes_deep()`, and `self::prepareInputForAdd()`
22442244 // is expecting an array, so it have to be unslashed then json decoded.
2245- $ input ['itemtypes ' ] = json_decode ($ input ['itemtypes ' ]);
2245+ $ input ['itemtypes ' ] = PluginFieldsToolbox:: decodeJSONItemtypes ($ input ['itemtypes ' ]);
22462246 } else {
22472247 unset($ input ['itemtypes ' ]);
22482248 }
0 commit comments