/** * Init profiles during installation : * - add rights in profile table for the current user's profile * - current profile has all rights on the plugin */ static function initProfile() { $pfProfile = new self(); $profile = new Profile(); $a_rights = $pfProfile->getRightsGeneral(); foreach ($a_rights as $data) { if (countElementsInTable("glpi_profilerights", "`name` = '" . $data['field'] . "'") == 0) { ProfileRight::addProfileRights(array($data['field'])); $_SESSION['glpiactiveprofile'][$data['field']] = 0; } } // Add all rights to current profile of the user if (isset($_SESSION['glpiactiveprofile'])) { $dataprofile = array(); $dataprofile['id'] = $_SESSION['glpiactiveprofile']['id']; $profile->getFromDB($_SESSION['glpiactiveprofile']['id']); foreach ($a_rights as $info) { if (is_array($info) && (!empty($info['itemtype']) || !empty($info['rights'])) && !empty($info['label']) && !empty($info['field'])) { if (isset($info['rights'])) { $rights = $info['rights']; } else { $rights = $profile->getRightsFor($info['itemtype']); } foreach ($rights as $right => $label) { $dataprofile['_' . $info['field']][$right] = 1; $_SESSION['glpiactiveprofile'][$data['field']] = $right; } } } $profile->update($dataprofile); } }