@@ -1635,19 +1635,17 @@ public static function preItemUpdate(CommonDBTM $item)
16351635 {
16361636 self ::preItem ($ item );
16371637 if (array_key_exists ('_plugin_fields_data ' , $ item ->input )) {
1638- $ data = $ item ->input ['_plugin_fields_data ' ];
1639- //update data
1640- $ container = new self ();
1641- if (
1642- count ($ data ) == 0
1643- || $ container ->updateFieldsValues ($ data , $ item ->getType (), isset ($ _REQUEST ['massiveaction ' ]))
1644- ) {
1645- $ item ->input ['date_mod ' ] = $ _SESSION ['glpi_currenttime ' ];
1646-
1647- return true ;
1638+ foreach ($ item ->input ['_plugin_fields_data ' ] as $ container_class ) {
1639+ //update container_class
1640+ $ container = new self ();
1641+ if (
1642+ count ($ container_class ) !== 0
1643+ && !$ container ->updateFieldsValues ($ container_class , $ item ->getType (), isset ($ _REQUEST ['massiveaction ' ]))
1644+ ) {
1645+ return $ item ->input = [];
1646+ }
16481647 }
1649-
1650- return $ item ->input = [];
1648+ $ item ->input ['date_mod ' ] = $ _SESSION ['glpi_currenttime ' ];
16511649 }
16521650
16531651 return true ;
@@ -1663,9 +1661,14 @@ public static function preItemUpdate(CommonDBTM $item)
16631661 */
16641662 public static function preItem (CommonDBTM $ item )
16651663 {
1664+ /** @var DBmysql $DB */
1665+ global $ DB ;
1666+
1667+ $ container_ids = [];
1668+ $ field_container = new PluginFieldsContainer ();
16661669 //find container (if not exist, do nothing)
16671670 if (isset ($ _REQUEST ['c_id ' ])) {
1668- $ c_id = $ _REQUEST ['c_id ' ];
1671+ $ container_ids = [ $ _REQUEST ['c_id ' ] ];
16691672 } else {
16701673 $ type = 'dom ' ;
16711674 if (isset ($ _REQUEST ['_plugin_fields_type ' ])) {
@@ -1675,57 +1678,54 @@ public static function preItem(CommonDBTM $item)
16751678 if ($ type == 'domtab ' ) {
16761679 $ subtype = $ _REQUEST ['_plugin_fields_subtype ' ];
16771680 }
1678- if (false === ($ c_id = self ::findContainer (get_Class ($ item ), $ type , $ subtype ))) {
1679- // tries for 'tab'
1680- if (false === ($ c_id = self ::findContainer (get_Class ($ item )))) {
1681- return false ;
1681+ foreach ($ item ->input as $ key => $ value ) {
1682+ if (!$ DB ->fieldExists (static ::getTable (), $ key ) || false === ($ container_id = self ::findContainer (get_Class ($ item ), $ type , $ subtype ))) {
1683+ // tries for 'tab'
1684+ if (false === ($ container_id = self ::findContainer (get_Class ($ item )))) {
1685+ return false ;
1686+ }
1687+ }
1688+ if (!in_array ($ container_id , $ container_ids , true )) {
1689+ $ container_ids [] = $ container_id ;
16821690 }
16831691 }
16841692 }
16851693
1686- $ loc_c = new PluginFieldsContainer ();
1687- $ loc_c ->getFromDB ($ c_id );
1688-
16891694 // check rights on $c_id
1695+ foreach ($ container_ids as $ container_id ) {
1696+ $ field_container ->getFromDB ($ container_id );
16901697
1691- if (isset ($ _SESSION ['glpiactiveprofile ' ]['id ' ]) && $ _SESSION ['glpiactiveprofile ' ]['id ' ] != null && $ c_id > 0 ) {
1692- $ right = PluginFieldsProfile::getRightOnContainer ($ _SESSION ['glpiactiveprofile ' ]['id ' ], $ c_id );
1693- if (($ right > READ ) === false ) {
1698+ if (isset ($ _SESSION ['glpiactiveprofile ' ]['id ' ]) && $ _SESSION ['glpiactiveprofile ' ]['id ' ] != null && $ container_id > 0 ) {
1699+ $ right = PluginFieldsProfile::getRightOnContainer ($ _SESSION ['glpiactiveprofile ' ]['id ' ], $ container_id );
1700+ if (($ right > READ ) === false ) {
1701+ return ;
1702+ }
1703+ } else {
16941704 return ;
16951705 }
1696- } else {
1697- return ;
1698- }
16991706
1707+ // need to check if container is usable on this object entity
1708+ $ entities = [$ field_container ->fields ['entities_id ' ]];
1709+ if ($ field_container ->fields ['is_recursive ' ]) {
1710+ $ entities = getSonsOf (getTableForItemType ('Entity ' ), $ field_container ->fields ['entities_id ' ]);
1711+ }
17001712
1701- // need to check if container is usable on this object entity
1702- $ entities = [$ loc_c ->fields ['entities_id ' ]];
1703- if ($ loc_c ->fields ['is_recursive ' ]) {
1704- $ entities = getSonsOf (getTableForItemType ('Entity ' ), $ loc_c ->fields ['entities_id ' ]);
1705- }
1706-
1707- //workaround: when a ticket is created from readdonly profile,
1708- //it is not initialized; see https://github.com/glpi-project/glpi/issues/1438
1709- if (!isset ($ item ->fields ) || count ($ item ->fields ) == 0 ) {
1710- $ item ->fields = $ item ->input ;
1711- }
1712-
1713- if ($ item ->isEntityAssign () && !in_array ($ item ->getEntityID (), $ entities )) {
1714- return false ;
1715- }
1713+ if ($ item ->isEntityAssign () && !in_array ($ item ->getEntityID (), $ entities )) {
1714+ return false ;
1715+ }
17161716
1717- if (false !== ($ data = self ::populateData ($ c_id , $ item ))) {
1718- if (self ::validateValues ($ data , $ item ::getType (), isset ($ _REQUEST ['massiveaction ' ])) === false ) {
1719- $ item ->input = [];
1717+ $ populate_data = self ::populateData ($ container_id , $ item );
1718+ if (false !== $ populate_data ) {
1719+ if (self ::validateValues ($ populate_data , $ item ::getType (), isset ($ _REQUEST ['massiveaction ' ])) === false ) {
1720+ $ item ->input = [];
17201721
1721- return [];
1722+ return [];
1723+ }
1724+ $ item ->input ['_plugin_fields_data ' ][] = $ populate_data ;
17221725 }
1723- $ item ->input ['_plugin_fields_data ' ] = $ data ;
1724-
1725- return $ data ;
17261726 }
17271727
1728- return ;
1728+ return $ item -> input [ ' _plugin_fields_data ' ] ;
17291729 }
17301730
17311731 /**
0 commit comments