Get user profiles (no entity association, use sqlfilter if needed)
static public getUserProfiles ( $user_ID, $sqlfilter = '' ) : array | ||
$user_ID | user ID | |
$sqlfilter | string additional filter (must start with AND) (default '') | |
return | array | of the IDs of the profiles |
/** * Print the user preference form * * @param $target form target * @param $ID integer Id of the user * * @return boolean : user found **/ function showMyForm($target, $ID) { global $CFG_GLPI, $PLUGIN_HOOKS; // Affiche un formulaire User if ($ID != Session::getLoginUserID() && !$this->currentUserHaveMoreRightThan($ID)) { return false; } if ($this->getFromDB($ID)) { $authtype = $this->getAuthMethodsByID(); $extauth = !($this->fields["authtype"] == Auth::DB_GLPI || $this->fields["authtype"] == Auth::NOT_YET_AUTHENTIFIED && !empty($this->fields["password"])); // No autocopletion : $save_autocompletion = $CFG_GLPI["use_ajax_autocompletion"]; $CFG_GLPI["use_ajax_autocompletion"] = false; echo "<div class='center'>"; echo "<form method='post' name='user_manager' action='" . $target . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . sprintf(__('%1$s: %2$s'), __('Login'), $this->fields["name"]); echo "<input type='hidden' name='name' value='" . $this->fields["name"] . "'>"; echo "<input type='hidden' name='id' value='" . $this->fields["id"] . "'>"; echo "</th></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Surname') . "</td><td>"; if ($extauth && isset($authtype['realname_field']) && !empty($authtype['realname_field'])) { echo $this->fields["realname"]; } else { Html::autocompletionTextField($this, "realname"); } echo "</td>"; //do some rights verification if (!$extauth && Session::haveRight("password_update", "1")) { echo "<td>" . __('Password') . "</td>"; echo "<td><input id='password' type='password' name='password' value='' size='30' autocomplete='off' onkeyup=\"return passwordCheck();\">"; echo "</td></tr>"; } else { echo "<td colspan='2'></tr>"; } echo "<tr class='tab_bg_1'><td>" . __('First name') . "</td><td>"; if ($extauth && isset($authtype['firstname_field']) && !empty($authtype['firstname_field'])) { echo $this->fields["firstname"]; } else { Html::autocompletionTextField($this, "firstname"); } echo "</td>"; if (!$extauth && Session::haveRight("password_update", "1")) { echo "<td>" . __('Password confirmation') . "</td>"; echo "<td><input type='password' name='password2' value='' size='30' autocomplete='off'>"; echo "</td></tr>"; } else { echo "<td colspan='2'></tr>"; } echo "<tr class='tab_bg_1'><td class='top'>" . _n('Email', 'Emails', 2); UserEmail::showAddEmailButton($this); echo "</td><td>"; UserEmail::showForUser($this); echo "</td>"; if (!$extauth && Session::haveRight("password_update", "1")) { echo "<td>" . __('Password security policy') . "</td>"; echo "<td>"; Config::displayPasswordSecurityChecks(); echo "</td>"; } else { echo "<td colspan='2'>"; } echo "</tr>"; echo "<tr class='tab_bg_1'><td>" . __('Mobile phone') . " :</td><td>"; if ($extauth && isset($authtype['mobile_field']) && !empty($authtype['mobile_field'])) { echo $this->fields["mobile"]; } else { Html::autocompletionTextField($this, "mobile"); } echo "</td>"; if (!GLPI_DEMO_MODE) { echo "<td>" . __('Language') . "</td><td>"; // Use session variable because field in table may be null if same of the global config Dropdown::showLanguages("language", array('value' => $_SESSION["glpilanguage"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Phone') . "</td><td>"; if ($extauth && isset($authtype['phone_field']) && !empty($authtype['phone_field'])) { echo $this->fields["phone"]; } else { Html::autocompletionTextField($this, "phone"); } echo "</td>"; if (count($_SESSION['glpiprofiles']) > 1) { echo "<td>" . __('Default profile') . "</td><td>"; $options = array(0 => Dropdown::EMPTY_VALUE); $options += Dropdown::getDropdownArrayNames('glpi_profiles', Profile_User::getUserProfiles($this->fields['id'])); Dropdown::showFromArray("profiles_id", $options, array('value' => $this->fields["profiles_id"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Phone 2') . "</td><td>"; if ($extauth && isset($authtype['phone2_field']) && !empty($authtype['phone2_field'])) { echo $this->fields["phone2"]; } else { Html::autocompletionTextField($this, "phone2"); } echo "</td>"; $entities = Profile_User::getUserEntities($this->fields['id'], 1); if (!GLPI_DEMO_MODE && count($_SESSION['glpiactiveentities']) > 1) { echo "<td>" . __('Default entity') . "</td><td>"; Entity::dropdown(array('value' => $this->fields['entities_id'], 'entity' => $entities)); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Location') . "</td><td>"; $entities = Profile_User::getUserEntities($ID, true); Location::dropdown(array('value' => $this->fields['locations_id'], 'entity' => $entities)); if (Session::haveRight("config", "w")) { echo "<td>" . __('Use GLPI in mode') . "</td><td>"; $modes[Session::NORMAL_MODE] = __('Normal'); //$modes[Session::TRANSLATION_MODE] = __('Translation'); $modes[Session::DEBUG_MODE] = __('Debug'); Dropdown::showFromArray('use_mode', $modes, array('value' => $this->fields["use_mode"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr><td class='tab_bg_2 center' colspan='4'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; $CFG_GLPI["use_ajax_autocompletion"] = $save_autocompletion; return true; } return false; }
/** * Add new mail with lang to current email array * * @param $data : array of data (mail, lang) **/ function addToAddressesList($data) { global $CFG_GLPI; $new_mail = trim(utf8_strtolower($data['email'])); $new_lang = ''; if (isset($data['language'])) { $new_lang = trim($data['language']); } $username = ''; if (isset($data['name']) && !empty($data['name'])) { $username = $data['name']; } if (isset($data['id']) && $data['id'] > 0) { $user = new User(); if (!$user->getFromDB($data['id']) || $user->getField('is_deleted') == 1 || $user->getField('is_active') == 0) { // unknown, deleted or disabled user return false; } $filt = getEntitiesRestrictRequest('AND', 'glpi_profiles_users', '', $this->getEntity(), true); $prof = Profile_User::getUserProfiles($data['id'], $filt); if (!count($prof)) { // No right on the entity of the object return false; } if (empty($username)) { $username = formatUserName(0, $user->getField('name'), $user->getField('realname'), $user->getField('firstname'), 0, 0, true); } } $notificationoption = $this->addAdditionnalUserInfo($data); if (!empty($new_mail)) { if (NotificationMail::isUserAddressValid($new_mail) && !isset($this->target[$new_mail])) { $this->target[$new_mail] = array('language' => empty($new_lang) ? $CFG_GLPI["language"] : $new_lang, 'email' => $new_mail, 'additionnaloption' => $notificationoption, 'username' => $username); } } }
/** * Add new mail with lang to current email array * * @param $data array of data (mail, lang[, id for user]) **/ function addToAddressesList(array $data) { global $CFG_GLPI; // No email set : get default for user if (!isset($data['email']) && isset($data['users_id'])) { $data['email'] = UserEmail::getDefaultForUser($data['users_id']); } $new_mail = trim(Toolbox::strtolower($data['email'])); $new_lang = ''; // Default USER TYPE is ANONYMOUS $notificationoption = array('usertype' => self::ANONYMOUS_USER); if (isset($data['language'])) { $new_lang = trim($data['language']); } $username = ''; if (isset($data['name']) && !empty($data['name'])) { $username = $data['name']; } if (isset($data['users_id']) && $data['users_id'] > 0) { $user = new User(); if (!$user->getFromDB($data['users_id']) || $user->getField('is_deleted') == 1 || $user->getField('is_active') == 0 || !is_null($user->getField('begin_date')) && $user->getField('begin_date') > $_SESSION["glpi_currenttime"] || !is_null($user->getField('end_date')) && $user->getField('end_date') < $_SESSION["glpi_currenttime"]) { // unknown, deleted or disabled user return false; } $filt = getEntitiesRestrictRequest('AND', 'glpi_profiles_users', '', $this->getEntity(), true); $prof = Profile_User::getUserProfiles($data['users_id'], $filt); if (!count($prof)) { // No right on the entity of the object return false; } if (empty($username)) { $username = formatUserName(0, $user->getField('name'), $user->getField('realname'), $user->getField('firstname'), 0, 0, true); } // It is a GLPI user : $notificationoption['usertype'] = self::GLPI_USER; if (Auth::isAlternateAuth($user->fields['authtype']) || $user->fields['authtype'] == Auth::NOT_YET_AUTHENTIFIED && Auth::isAlternateAuth(Auth::checkAlternateAuthSystems())) { $notificationoption['usertype'] = self::EXTERNAL_USER; } } // Pass user type as argument ? forced for specific cases if (isset($data['usertype'])) { $notificationoption['usertype'] = $data['usertype']; } $notificationoption = array_merge($this->addAdditionnalUserInfo($data), $notificationoption); if (!empty($new_mail)) { if (NotificationMail::isUserAddressValid($new_mail) && !isset($this->target[$new_mail])) { $param = array('language' => empty($new_lang) ? $CFG_GLPI["language"] : $new_lang, 'email' => $new_mail, 'additionnaloption' => $notificationoption, 'username' => $username); if (isset($data['users_id']) && $data['users_id']) { $param['users_id'] = $data['users_id']; } $this->target[$new_mail] = $param; } } }
/** * Print the user preference form * * @param $target form target * @param $ID Integer : Id of the user * * @return boolean : user found **/ function showMyForm($target, $ID) { global $CFG_GLPI, $LANG, $PLUGIN_HOOKS; // Affiche un formulaire User if ($ID != getLoginUserID() && !$this->currentUserHaveMoreRightThan($ID)) { return false; } if ($this->getFromDB($ID)) { $authtype = $this->getAuthMethodsByID(); $extauth = !($this->fields["authtype"] == Auth::DB_GLPI || $this->fields["authtype"] == Auth::NOT_YET_AUTHENTIFIED && !empty($this->fields["password"])); // No autocopletion : $save_autocompletion = $CFG_GLPI["use_ajax_autocompletion"]; $CFG_GLPI["use_ajax_autocompletion"] = false; echo "<div class='center'>"; echo "<form method='post' name='user_manager' action='" . $target . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . $LANG['setup'][18] . " : " . $this->fields["name"]; echo "<input type='hidden' name='name' value='" . $this->fields["name"] . "'>"; echo "<input type='hidden' name='id' value='" . $this->fields["id"] . "'>"; echo "</th></tr>"; echo "<tr class='tab_bg_1'><td>" . $LANG['common'][48] . " :</td><td>"; if ($extauth && isset($authtype['realname_field']) && !empty($authtype['realname_field'])) { echo $this->fields["realname"]; } else { autocompletionTextField($this, "realname"); } echo "</td>"; //do some rights verification if (!$extauth && haveRight("password_update", "1")) { echo "<td>" . $LANG['setup'][19] . " :</td>"; echo "<td><input type='password' name='password' value='' size='30' autocomplete='off'>"; echo "</td></tr>"; } else { echo "<td colspan='2'></tr>"; } echo "<tr class='tab_bg_1'><td>" . $LANG['common'][43] . " :</td><td>"; if ($extauth && isset($authtype['firstname_field']) && !empty($authtype['firstname_field'])) { echo $this->fields["firstname"]; } else { autocompletionTextField($this, "firstname"); } echo "</td>"; if (!$extauth && haveRight("password_update", "1")) { echo "<td>" . $LANG['setup'][20] . " :</td>"; echo "<td><input type='password' name='password2' value='' size='30' autocomplete='off'>"; echo "</td></tr>"; } else { echo "<td colspan='2'></tr>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . $LANG['setup'][14] . " :</td><td>"; if ($extauth && isset($authtype['email_field']) && !empty($authtype['email_field'])) { echo $this->fields["email"]; } else { autocompletionTextField($this, "email", array('name' => "email_form")); if (!NotificationMail::isUserAddressValid($this->fields["email"])) { echo "<br><span class='red'>" . $LANG['mailing'][110] . "</span>"; } } echo "</td>"; if (!GLPI_DEMO_MODE) { echo "<td>" . $LANG['setup'][41] . " :</td><td>"; /// Use sesion variable because field in table may be null if same of the global config Dropdown::showLanguages("language", array('value' => $_SESSION["glpilanguage"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . $LANG['common'][42] . " :</td><td>"; if ($extauth && isset($authtype['mobile_field']) && !empty($authtype['mobile_field'])) { echo $this->fields["mobile"]; } else { autocompletionTextField($this, "mobile"); } echo "</td>"; if (count($_SESSION['glpiprofiles']) > 1) { echo "<td>" . $LANG['profiles'][13] . " :</td><td>"; $options = array(0 => DROPDOWN_EMPTY_VALUE); $options += Dropdown::getDropdownArrayNames('glpi_profiles', Profile_User::getUserProfiles($this->fields['id'])); Dropdown::showFromArray("profiles_id", $options, array('value' => $this->fields["profiles_id"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . $LANG['help'][35] . " :</td><td>"; if ($extauth && isset($authtype['phone_field']) && !empty($authtype['phone_field'])) { echo $this->fields["phone"]; } else { autocompletionTextField($this, "phone"); } echo "</td>"; if (!GLPI_DEMO_MODE && count($_SESSION['glpiactiveentities']) > 1) { $entities = Profile_User::getUserEntities($this->fields['id'], 1); echo "<td>" . $LANG['profiles'][37] . " :</td><td>"; Dropdown::show('Entity', array('value' => $this->fields['entities_id'], 'entity' => $entities)); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . $LANG['help'][35] . " 2 : </td><td>"; if ($extauth && isset($authtype['phone2_field']) && !empty($authtype['phone2_field'])) { echo $this->fields["phone2"]; } else { autocompletionTextField($this, "phone2"); } echo "</td>"; if (haveRight("config", "w")) { echo "<td>" . $LANG['setup'][138] . " :</td><td>"; $modes[NORMAL_MODE] = $LANG['setup'][135]; $modes[TRANSLATION_MODE] = $LANG['setup'][136]; $modes[DEBUG_MODE] = $LANG['setup'][137]; Dropdown::showFromArray('use_mode', $modes, array('value' => $this->fields["use_mode"])); } else { echo "<td colspan='2'> "; } echo "</td></tr>"; echo "<tr><td class='tab_bg_2 center' colspan='4'>"; echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\" class='submit'>"; echo "</td></tr>"; echo "</table></form></div>"; $CFG_GLPI["use_ajax_autocompletion"] = $save_autocompletion; return true; } return false; }