Profile::getDefault PHP Method

getDefault() static public method

Get the default Profile for new user
static public getDefault ( ) : integer
return integer profiles_id
    static function getDefault()
    {
        global $DB;
        foreach ($DB->request('glpi_profiles', array('is_default' => 1)) as $data) {
            return $data['id'];
        }
        return 0;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Print the user form
  *
  * @param $ID        integer : Id of the user
  * @param $options   array
  *     - target form target
  *     - withtemplate boolean : template or basic item
  *
  * @return boolean : user found
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     // Affiche un formulaire User
     if ($ID != Session::getLoginUserID() && !Session::haveRight("user", "r")) {
         return false;
     }
     $this->initForm($ID, $options);
     if ($ID) {
         $caneditpassword = $this->currentUserHaveMoreRightThan($ID);
     } else {
         // can edit on creation form
         $caneditpassword = true;
     }
     $extauth = !($this->fields["authtype"] == Auth::DB_GLPI || $this->fields["authtype"] == Auth::NOT_YET_AUTHENTIFIED && !empty($this->fields["password"]));
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Login') . "</td>";
     // si on est dans le cas d'un ajout , cet input ne doit plus etre hidden
     if ($this->fields["name"] == "") {
         echo "<td><input name='name' value=\"" . $this->fields["name"] . "\"></td>";
         // si on est dans le cas d'un modif on affiche la modif du login si ce n'est pas une auth externe
     } else {
         if (!empty($this->fields["password"]) || $this->fields["authtype"] == Auth::DB_GLPI) {
             echo "<td>";
             echo "<input name='name' value=\"" . $this->fields["name"] . "\">";
         } else {
             echo "<td class='b'>" . $this->fields["name"];
             echo "<input type='hidden' name='name' value=\"" . $this->fields["name"] . "\">";
         }
         echo "</td>";
     }
     //do some rights verification
     if (Session::haveRight("user", "w") && (!$extauth || empty($ID)) && $caneditpassword) {
         echo "<td>" . __('Password') . "</td>";
         echo "<td><input id='password' type='password' name='password' value='' size='20'\n                    autocomplete='off' onkeyup=\"return passwordCheck();\">";
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Surname') . "</td><td>";
     Html::autocompletionTextField($this, "realname");
     echo "</td>";
     //do some rights verification
     if (Session::haveRight("user", "w") && (!$extauth || empty($ID)) && $caneditpassword) {
         echo "<td>" . __('Password confirmation') . "</td>";
         echo "<td><input type='password' name='password2' value='' size='20' autocomplete='off'>";
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'><td>" . __('First name') . "</td><td>";
     Html::autocompletionTextField($this, "firstname");
     echo "</td>";
     if (Session::haveRight("user", "w") && (!$extauth || empty($ID)) && $caneditpassword) {
         echo "<td>" . __('Password security policy') . "</td>";
         echo "<td>";
         Config::displayPasswordSecurityChecks();
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . _n('Email', 'Emails', 2);
     UserEmail::showAddEmailButton($this);
     echo "</td><td>";
     UserEmail::showForUser($this);
     echo "</td>";
     //Authentications information : auth method used and server used
     //don't display is creation of a new user'
     if (!empty($ID)) {
         if (Session::haveRight("user_authtype", "r")) {
             echo "<td>" . __('Authentication') . "</td><td>";
             echo Auth::getMethodName($this->fields["authtype"], $this->fields["auths_id"]);
             if (!empty($this->fields["date_sync"])) {
                 //TRANS: %s is the date of last sync
                 echo '<br>' . sprintf(__('Last synchronization on %s'), HTML::convDateTime($this->fields["date_sync"]));
             }
             if (!empty($this->fields["user_dn"])) {
                 //TRANS: %s is the user dn
                 echo '<br>' . sprintf(__('%1$s: %2$s'), __('User DN'), $this->fields["user_dn"]);
             }
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
     } else {
         echo "<td colspan='2'><input type='hidden' name='authtype' value='1'></td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Phone') . "</td><td>";
     Html::autocompletionTextField($this, "phone");
     echo "</td>";
     echo "<td>" . __('Active') . "</td><td>";
     Dropdown::showYesNo('is_active', $this->fields['is_active']);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Mobile phone') . "</td><td>";
     Html::autocompletionTextField($this, "mobile");
     echo "</td>";
     echo "<td>" . __('Category') . "</td><td>";
     UserCategory::dropdown(array('value' => $this->fields["usercategories_id"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Phone 2') . "</td><td>";
     Html::autocompletionTextField($this, "phone2");
     echo "</td>";
     echo "<td rowspan='4' class='middle'>" . __('Comments') . "</td>";
     echo "<td class='center middle' rowspan='4'>";
     echo "<textarea cols='45' rows='6' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Administrative number') . "</td><td>";
     Html::autocompletionTextField($this, "registration_number");
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . _x('person', 'Title') . "&nbsp;:</td><td>";
     UserTitle::dropdown(array('value' => $this->fields["usertitles_id"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Location') . "</td><td>";
     if (!empty($ID)) {
         $entities = Profile_User::getUserEntities($ID, true);
         if (count($entities) > 0) {
             Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $entities));
         } else {
             echo "&nbsp;";
         }
     } else {
         if (!Session::isMultiEntitiesMode()) {
             // Display all locations : only one entity
             Location::dropdown(array('value' => $this->fields["locations_id"]));
         } else {
             echo "&nbsp;";
         }
     }
     echo "</td></tr>";
     if (empty($ID)) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>" . _n('Authorization', 'Authorizations', 1) . "</th>";
         echo "<td>" . __('Recursive') . "</td><td>";
         Dropdown::showYesNo("_is_recursive", 0);
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Profile') . "</td><td>";
         Profile::dropdownUnder(array('name' => '_profiles_id', 'value' => Profile::getDefault()));
         echo "</td><td>" . __('Entity') . "</td><td>";
         Entity::dropdown(array('name' => '_entities_id', 'display_emptychoice' => false, 'entity' => $_SESSION['glpiactiveentities']));
         echo "</td></tr>";
     } else {
         if ($caneditpassword) {
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Default profile') . "</td><td>";
             $options[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"]));
             echo "</td><td>" . __('Default entity') . "</td><td>";
             $entities = Profile_User::getUserEntities($this->fields['id'], 1);
             Entity::dropdown(array('value' => $this->fields["entities_id"], 'entity' => $entities));
             echo "</td></tr>";
         }
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2' class='center'>";
         //TRANS: %s is the date
         printf(__('Last update on %s'), HTML::convDateTime($this->fields["date_mod"]));
         echo "<br>";
         printf(__('Last login on %s'), HTML::convDateTime($this->fields["last_login"]));
         echo "</td><td colspan='2'class='center'>";
         if ($ID > 0) {
             echo "<a target='_blank' href='" . $CFG_GLPI["root_doc"] . "/front/user.form.php?getvcard=1&amp;id={$ID}'>" . __('Vcard') . "</a>";
         }
         echo "</td></tr>";
     }
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
All Usage Examples Of Profile::getDefault