. * --------------------------------------------------------------------- * @copyright Copyright © 2021 - 2022 Edgard * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ * @link https://github.com/edgardmessias/glpi-singlesignon/ * --------------------------------------------------------------------- */ class PluginSinglesignonPreference extends CommonDBTM { static protected $notable = true; static $rightname = ''; // Provider data public $user_id = null; public $providers = []; public $providers_users = []; public function __construct($user_id = null) { parent::__construct(); $this->user_id = $user_id; } public function loadProviders() { $signon_provider = new PluginSinglesignonProvider(); $condition = '`is_active` = 1'; if (version_compare(GLPI_VERSION, '9.4', '>=')) { $condition = [$condition]; } $this->providers = $signon_provider->find($condition); $provider_user = new PluginSinglesignonProvider_User(); $condition = "`users_id` = {$this->user_id}"; if (version_compare(GLPI_VERSION, '9.4', '>=')) { $condition = [$condition]; } $this->providers_users = $provider_user->find($condition); } public function update(array $input, $history = 1, $options = []) { if (!isset($input['_remove_sso']) || !is_array($input['_remove_sso'])) { return false; } $ids = $input['_remove_sso']; if (empty($ids)) { return false; } $provider_user = new PluginSinglesignonProvider_User(); $condition = "`users_id` = {$this->user_id} AND `id` IN (" . implode(',', $ids) . ")"; if (version_compare(GLPI_VERSION, '9.4', '>=')) { $condition = [$condition]; } $providers_users = $provider_user->find($condition); foreach ($providers_users as $pu) { $provider_user->delete($pu); } } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch (get_class($item)) { case 'Preference': case 'User': return [1 => __sso('Single Sign-on')]; default: return ''; } } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch (get_class($item)) { case 'User': $prefer = new self($item->fields['id']); $prefer->loadProviders(); $prefer->showFormUser($item); break; case 'Preference': $prefer = new self(Session::getLoginUserID()); $prefer->loadProviders(); $prefer->showFormPreference($item); break; } return true; } function showFormUser(CommonGLPI $item) { global $CFG_GLPI; if (!User::canView()) { return false; } $canedit = Session::haveRight(User::$rightname, UPDATE); if ($canedit) { echo "