From 23d71d2ae329b03a91b6a08c968570c2a20e59fa Mon Sep 17 00:00:00 2001 From: Thierry Bugier Pineau Date: Wed, 8 Mar 2017 22:38:00 +0100 Subject: [PATCH 1/3] save new helpdesk itemtype for active profile when installing --- inc/profile.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/inc/profile.class.php b/inc/profile.class.php index ffa43a0..10b3306 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -60,6 +60,17 @@ static function createFirstAccess($ID) { //Add right to the current session $_SESSION['glpiactiveprofile'][self::RIGHT_SIMCARD_SIMCARD] = $firstAccessRights[self::RIGHT_SIMCARD_SIMCARD]; + + // add plugin's itemtype in helpdesk itemtypes for the current profile + $profile = new Profile(); + $profile->getFromDB($_SESSION['glpiactiveprofile']['id']); + $helpdeskItemtypes = json_decode($profile->fields['helpdesk_item_type'], JSON_OBJECT_AS_ARRAY); + $helpdeskItemtypes[] = 'PluginSimcardSimcard'; + $profile->update(array( + 'id' => $profile->getID(), + 'helpdesk_item_type' => json_encode($helpdeskItemtypes), + )); + // Immediately apply the new helpdesk itemtype to the current profile $_SESSION['glpiactiveprofile']['helpdesk_item_type'][] = 'PluginSimcardSimcard'; } From 8cf01888729210b7aee8650a108fb613bc03587d Mon Sep 17 00:00:00 2001 From: Thierry Bugier Pineau Date: Wed, 8 Mar 2017 23:19:15 +0100 Subject: [PATCH 2/3] use argument instead of session, document method --- inc/profile.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/inc/profile.class.php b/inc/profile.class.php index 10b3306..bf450d0 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -43,6 +43,10 @@ function createAccess($ID) { $this->add(['profiles_id' => $ID]); } + /** + * + * @param integer $ID Id of the profile to update + */ static function createFirstAccess($ID) { $profileRight = new ProfileRight(); @@ -63,7 +67,7 @@ static function createFirstAccess($ID) { // add plugin's itemtype in helpdesk itemtypes for the current profile $profile = new Profile(); - $profile->getFromDB($_SESSION['glpiactiveprofile']['id']); + $profile->getFromDB($ID); $helpdeskItemtypes = json_decode($profile->fields['helpdesk_item_type'], JSON_OBJECT_AS_ARRAY); $helpdeskItemtypes[] = 'PluginSimcardSimcard'; $profile->update(array( From e4ebd4a9cccbac00331ba4fad3a5ac7217f167f5 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Pineau Date: Thu, 9 Mar 2017 10:41:25 +0100 Subject: [PATCH 3/3] fix call of json_decode() --- inc/profile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/profile.class.php b/inc/profile.class.php index bf450d0..a2dcf46 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -68,7 +68,7 @@ static function createFirstAccess($ID) { // add plugin's itemtype in helpdesk itemtypes for the current profile $profile = new Profile(); $profile->getFromDB($ID); - $helpdeskItemtypes = json_decode($profile->fields['helpdesk_item_type'], JSON_OBJECT_AS_ARRAY); + $helpdeskItemtypes = json_decode($profile->fields['helpdesk_item_type'], true); $helpdeskItemtypes[] = 'PluginSimcardSimcard'; $profile->update(array( 'id' => $profile->getID(),