getDefault() static public method

Get the default Profile for new user
static public getDefault ( ) : integer
return integer profiles_id
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;
 }
Exemplo n.º 2
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() && !self::canView()) {
         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"]));
     $options['formoptions'] = " enctype='multipart/form-data'";
     $this->showFormHeader($options);
     $rand = mt_rand();
     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"] . "\"></td>";
         } else {
             echo "<td class='b'>" . $this->fields["name"];
             echo "<input type='hidden' name='name' value=\"" . $this->fields["name"] . "\"></td>";
         }
     }
     if (!empty($this->fields["name"])) {
         echo "<td rowspan='3'>" . __('Picture') . "</td>";
         echo "<td rowspan='3'>";
         echo "<div class='user_picture_border_small' id='picture{$rand}'>";
         echo "<img class='user_picture_small' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($this->fields['picture']) . "'>";
         //         echo "<img src='".self::getURLForPicture($this->fields["picture"])."' class='user_picture'/>";
         echo "</div>";
         $full_picture = "<div class='user_picture_border'>";
         $full_picture .= "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getURLForPicture($this->fields['picture']) . "'>";
         $full_picture .= "</div>";
         Html::showTooltip($full_picture, array('applyto' => "picture{$rand}"));
         echo "<input type='file' name='picture' accept='image/*'>";
         echo "<input type='checkbox' name='_blank_picture'>&nbsp;" . __('Clear');
         echo "</td>";
     } else {
         echo "<td rowspan='3'></td>";
         echo "<td rowspan='3'></td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Surname') . "</td><td>";
     Html::autocompletionTextField($this, "realname");
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('First name') . "</td><td>";
     Html::autocompletionTextField($this, "firstname");
     echo "</td></tr>";
     //do some rights verification
     if (self::canUpdate() && (!$extauth || empty($ID)) && $caneditpassword) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Password') . "</td>";
         echo "<td><input id='password' type='password' name='password' value='' size='20'\n                    autocomplete='off' onkeyup=\"return passwordCheck();\"></td>";
         echo "<td rowspan='2'>" . __('Password security policy') . "</td>";
         echo "<td rowspan='2'>";
         Config::displayPasswordSecurityChecks();
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Password confirmation') . "</td>";
         echo "<td><input type='password' name='password2' value='' size='20' autocomplete='off'>";
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1'>";
     if (!GLPI_DEMO_MODE) {
         echo "<td>" . __('Active') . "</td><td>";
         Dropdown::showYesNo('is_active', $this->fields['is_active']);
         echo "</td>";
     } else {
         echo "<td colspan='2'></td>";
     }
     echo "<td>" . _n('Email', 'Emails', Session::getPluralNumber());
     UserEmail::showAddEmailButton($this);
     echo "</td><td>";
     UserEmail::showForUser($this);
     echo "</td>";
     echo "</tr>";
     if (!GLPI_DEMO_MODE) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Valid since') . "</td><td>";
         Html::showDateTimeField("begin_date", array('value' => $this->fields["begin_date"], 'timestep' => 1, 'maybeempty' => true));
         echo "</td>";
         echo "<td>" . __('Valid until') . "</td><td>";
         Html::showDateTimeField("end_date", array('value' => $this->fields["end_date"], 'timestep' => 1, 'maybeempty' => true));
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Phone') . "</td><td>";
     Html::autocompletionTextField($this, "phone");
     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(self::$rightname, self::READAUTHENT)) {
             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"]);
             }
             if ($this->fields['is_deleted_ldap']) {
                 echo '<br>' . __('User missing in LDAP directory');
             }
             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>" . __('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'>";
     if (!empty($ID)) {
         echo "<td>" . __('Location') . "</td><td>";
         $entities = Profile_User::getUserEntities($ID, true);
         if (count($entities) <= 0) {
             $entities = -1;
         }
         Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $entities));
         echo "</td>";
     }
     echo "</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 = Dropdown::getDropdownArrayNames('glpi_profiles', Profile_User::getUserProfiles($this->fields['id']));
             Dropdown::showFromArray("profiles_id", $options, array('value' => $this->fields["profiles_id"], 'display_emptychoice' => true));
             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);
     return true;
 }
 /**
  * Show users of an entity
  *
  * @param $entity Entity object
  **/
 static function showForEntity(Entity $entity)
 {
     global $DB, $CFG_GLPI, $LANG;
     $ID = $entity->getField('id');
     if (!$entity->can($ID, "r")) {
         return false;
     }
     $canedit = $entity->can($ID, "w");
     $canshowuser = haveRight("user", "r");
     $nb_per_line = 3;
     $rand = mt_rand();
     if ($canedit) {
         echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
         echo getItemTypeFormURL(__CLASS__) . "'>";
         $headerspan = $nb_per_line * 2;
     } else {
         $headerspan = $nb_per_line;
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='5'>" . $LANG['setup'][605] . "</tr>";
         echo "<tr><td class='tab_bg_2 center'>" . $LANG['common'][34] . "&nbsp;:&nbsp;";
         echo "<input type='hidden' name='entities_id' value='{$ID}'>";
         User::dropdown(array('right' => 'all'));
         echo "</td><td class='tab_bg_2 center'>" . $LANG['profiles'][22] . "&nbsp;:&nbsp;";
         Profile::dropdownUnder(array('value' => Profile::getDefault()));
         echo "</td><td class='tab_bg_2 center'>" . $LANG['profiles'][28] . "&nbsp;:&nbsp;";
         Dropdown::showYesNo("is_recursive", 0);
         echo "</td><td class='tab_bg_2 center'>";
         echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table></div>";
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='{$headerspan}'>" . $LANG['Menu'][14] . " (D=" . $LANG['profiles'][29] . ", R=" . $LANG['profiles'][28] . ")</th></tr>";
     $query = "SELECT DISTINCT `glpi_profiles`.`id`, `glpi_profiles`.`name`\n                FROM `glpi_profiles_users`\n                LEFT JOIN `glpi_profiles`\n                     ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n                LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                      AND `glpi_users`.`is_deleted` = '0'";
     $result = $DB->query($query);
     if ($DB->numrows($result) > 0) {
         initNavigateListItems('User', $LANG['entity'][0] . " = " . $entity->fields['name']);
         while ($data = $DB->fetch_array($result)) {
             echo "<tr><th colspan='{$headerspan}'>" . $LANG['profiles'][22] . "&nbsp;: " . $data["name"];
             echo "</th></tr>";
             $query = "SELECT `glpi_users`.*,\n                             `glpi_profiles_users`.`id` AS linkID,\n                             `glpi_profiles_users`.`is_recursive`,\n                             `glpi_profiles_users`.`is_dynamic`\n                      FROM `glpi_profiles_users`\n                      LEFT JOIN `glpi_users`\n                           ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                      WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                            AND `glpi_users`.`is_deleted` = '0'\n                            AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n                      ORDER BY `glpi_profiles_users`.`profiles_id`,\n                               `glpi_users`.`name`,\n                               `glpi_users`.`realname`,\n                               `glpi_users`.`firstname`";
             $result2 = $DB->query($query);
             if ($DB->numrows($result2) > 0) {
                 $i = 0;
                 while ($data2 = $DB->fetch_array($result2)) {
                     addToNavigateListItems('User', $data2["id"]);
                     if ($i % $nb_per_line == 0) {
                         if ($i != 0) {
                             echo "</tr>";
                         }
                         echo "<tr class='tab_bg_1'>";
                     }
                     if ($canedit) {
                         echo "<td width='10'>";
                         echo "<input type='checkbox' name='item[" . $data2["linkID"] . "]' value='1'>";
                         echo "</td>";
                     }
                     echo "<td>";
                     echo formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser);
                     if ($data2["is_dynamic"] || $data2["is_recursive"]) {
                         echo "<strong>&nbsp;(";
                         if ($data2["is_dynamic"]) {
                             echo "D";
                         }
                         if ($data2["is_dynamic"] && $data2["is_recursive"]) {
                             echo ", ";
                         }
                         if ($data2["is_recursive"]) {
                             echo "R";
                         }
                         echo ")</strong>";
                     }
                     echo "</td>";
                     $i++;
                 }
                 while ($i % $nb_per_line != 0) {
                     echo "<td>&nbsp;</td>";
                     if ($canedit) {
                         echo "<td>&nbsp;</td>";
                     }
                     $i++;
                 }
                 echo "</tr>";
             } else {
                 echo "<tr colspan='{$headerspan}'>" . $LANG['common'][54] . "</tr>";
             }
         }
     }
     echo "</table>";
     if ($canedit) {
         openArrowMassive("entityuser_form{$rand}", true);
         closeArrowMassive('delete', $LANG['buttons'][6]);
         echo "</form>";
     }
     echo "</div>";
 }
Exemplo n.º 4
0
 /**
  * Show users of an entity
  *
  * @param $entity Entity object
  **/
 static function showForEntity(Entity $entity)
 {
     global $DB;
     $ID = $entity->getField('id');
     if (!$entity->can($ID, READ)) {
         return false;
     }
     $canedit = $entity->canEdit($ID);
     $canshowuser = User::canView();
     $nb_per_line = 3;
     $rand = mt_rand();
     if ($canedit) {
         $headerspan = $nb_per_line * 2;
     } else {
         $headerspan = $nb_per_line;
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
         echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Add an authorization to a user') . "</tr>";
         echo "<tr class='tab_bg_1'><td class='tab_bg_2 center'>" . __('User') . "&nbsp;";
         echo "<input type='hidden' name='entities_id' value='{$ID}'>";
         User::dropdown(array('right' => 'all'));
         echo "</td><td class='tab_bg_2 center'>" . self::getTypeName(1) . "</td><td>";
         Profile::dropdownUnder(array('value' => Profile::getDefault()));
         echo "</td><td class='tab_bg_2 center'>" . __('Recursive') . "</td><td>";
         Dropdown::showYesNo("is_recursive", 0);
         echo "</td><td class='tab_bg_2 center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     $query = "SELECT DISTINCT `glpi_profiles`.`id`, `glpi_profiles`.`name`\n                FROM `glpi_profiles_users`\n                LEFT JOIN `glpi_profiles`\n                     ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n                LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                     AND `glpi_users`.`is_deleted` = '0'";
     $result = $DB->query($query);
     $nb = $DB->numrows($result);
     echo "<div class='spaced'>";
     if ($canedit && $nb) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<thead><tr>";
     echo "<th class='noHover' colspan='{$headerspan}'>";
     printf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive'));
     echo "</th></tr></thead>";
     if ($nb) {
         Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Entity::getTypeName(1), $entity->getName()));
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tbody><tr class='noHover'>";
             $reduce_header = 0;
             if ($canedit && $nb) {
                 echo "<th width='10'>";
                 echo Html::checkAllAsCheckbox("profile" . $data['id'] . "_{$rand}");
                 echo "</th>";
                 $reduce_header++;
             }
             echo "<th colspan='" . ($headerspan - $reduce_header) . "'>";
             printf(__('%1$s: %2$s'), __('Profile'), $data["name"]);
             echo "</th></tr></tbody>";
             echo "<tbody id='profile" . $data['id'] . "_{$rand}'>";
             $query = "SELECT `glpi_users`.*,\n                             `glpi_profiles_users`.`id` AS linkID,\n                             `glpi_profiles_users`.`is_recursive`,\n                             `glpi_profiles_users`.`is_dynamic`\n                      FROM `glpi_profiles_users`\n                      LEFT JOIN `glpi_users`\n                           ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                      WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                            AND `glpi_users`.`is_deleted` = '0'\n                            AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n                      ORDER BY `glpi_profiles_users`.`profiles_id`,\n                               `glpi_users`.`name`,\n                               `glpi_users`.`realname`,\n                               `glpi_users`.`firstname`";
             $result2 = $DB->query($query);
             if ($DB->numrows($result2) > 0) {
                 $i = 0;
                 while ($data2 = $DB->fetch_assoc($result2)) {
                     Session::addToNavigateListItems('User', $data2["id"]);
                     if ($i % $nb_per_line == 0) {
                         if ($i != 0) {
                             echo "</tr>";
                         }
                         echo "<tr class='tab_bg_1'>";
                     }
                     if ($canedit) {
                         echo "<td width='10'>";
                         Html::showMassiveActionCheckBox(__CLASS__, $data2["linkID"]);
                         echo "</td>";
                     }
                     $username = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser);
                     if ($data2["is_dynamic"] || $data2["is_recursive"]) {
                         $username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>(");
                         if ($data2["is_dynamic"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, __('D'));
                         }
                         if ($data2["is_dynamic"] && $data2["is_recursive"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, ", ");
                         }
                         if ($data2["is_recursive"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, __('R'));
                         }
                         $username = sprintf(__('%1$s%2$s'), $username, ")</span>");
                     }
                     echo "<td>" . $username . "</td>";
                     $i++;
                 }
                 while ($i % $nb_per_line != 0) {
                     echo "<td>&nbsp;</td>";
                     if ($canedit) {
                         echo "<td>&nbsp;</td>";
                     }
                     $i++;
                 }
                 echo "</tr>";
                 echo "</tbody>";
             } else {
                 echo "<tr colspan='{$headerspan}'>" . __('Item not found') . "</tr>";
             }
         }
     }
     echo "</table>";
     if ($canedit && $nb) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 5
0
 /**
  * Function that try to load from LDAP the user information...
  *
  * @param $ldap_connection ldap connection descriptor
  * @param $ldap_method LDAP method
  * @param $userdn Basedn of the user
  * @param $login User Login
  *
  * @return String : basedn of the user / false if not founded
  **/
 function getFromLDAP($ldap_connection, $ldap_method, $userdn, $login)
 {
     global $DB, $CFG_GLPI;
     // we prevent some delay...
     if (empty($ldap_method["host"])) {
         return false;
     }
     if ($ldap_connection) {
         //Set all the search fields
         $this->fields['password'] = "";
         $fields = AuthLDAP::getSyncFields($ldap_method);
         $fields = array_filter($fields);
         $f = array_values($fields);
         $sr = @ldap_read($ldap_connection, $userdn, "objectClass=*", $f);
         $v = ldap_get_entries_clean($ldap_connection, $sr);
         if (!is_array($v) || count($v) == 0 || empty($v[0][$fields['name']][0])) {
             return false;
         }
         //Store user's dn
         $this->fields['user_dn'] = addslashes($userdn);
         //Store date_sync
         $this->fields['date_sync'] = $_SESSION['glpi_currenttime'];
         foreach ($fields as $k => $e) {
             if (empty($v[0][$e][0])) {
                 switch ($k) {
                     case "language":
                         // Not set value : managed but user class
                         break;
                     case "usertitles_id":
                     case "usercategories_id":
                         $this->fields[$k] = 0;
                         break;
                     default:
                         $this->fields[$k] = "";
                 }
             } else {
                 switch ($k) {
                     case "language":
                         $language = Config::getLanguage($v[0][$e][0]);
                         if ($language != '') {
                             $this->fields[$k] = $language;
                         }
                         break;
                     case "usertitles_id":
                         $this->fields[$k] = Dropdown::importExternal('UserTitle', addslashes($v[0][$e][0]));
                         break;
                     case "usercategories_id":
                         $this->fields[$k] = Dropdown::importExternal('UserCategory', addslashes($v[0][$e][0]));
                         break;
                     default:
                         if (!empty($v[0][$e][0])) {
                             $this->fields[$k] = addslashes($v[0][$e][0]);
                         } else {
                             $this->fields[$k] = "";
                         }
                 }
             }
         }
         // Empty array to ensure than syncLdapGroups will be done
         $this->fields["_groups"] = array();
         ///The groups are retrieved by looking into an ldap user object
         if ($ldap_method["group_search_type"] == 0 || $ldap_method["group_search_type"] == 2) {
             $this->getFromLDAPGroupVirtual($ldap_connection, $ldap_method, $userdn, $login);
         }
         ///The groups are retrived by looking into an ldap group object
         if ($ldap_method["group_search_type"] == 1 || $ldap_method["group_search_type"] == 2) {
             $this->getFromLDAPGroupDiscret($ldap_connection, $ldap_method, $userdn, $login);
         }
         ///Only process rules if working on the master database
         if (!$DB->isSlave()) {
             //Instanciate the affectation's rule
             $rule = new RuleRightCollection();
             //Process affectation rules :
             //we don't care about the function's return because all
             //the datas are stored in session temporary
             if (isset($this->fields["_groups"])) {
                 $groups = $this->fields["_groups"];
             } else {
                 $groups = array();
             }
             $this->fields = $rule->processAllRules($groups, $this->fields, array('type' => 'LDAP', 'ldap_server' => $ldap_method["id"], 'connection' => $ldap_connection, 'userdn' => $userdn));
             $this->fields['_ruleright_process'] = true;
             //If rule  action is ignore import
             if (isset($this->fields["_stop_import"])) {
                 return false;
             }
             //or no rights found & do not import users with no rights
             if (!$CFG_GLPI["use_noright_users_add"]) {
                 $ok = false;
                 if (isset($this->fields["_ldap_rules"]) && count($this->fields["_ldap_rules"])) {
                     if (isset($this->fields["_ldap_rules"]["rules_entities_rights"]) && count($this->fields["_ldap_rules"]["rules_entities_rights"])) {
                         $ok = true;
                     }
                     if (!$ok) {
                         $entity_count = 0;
                         $right_count = 0;
                         if (Profile::getDefault()) {
                             $right_count++;
                         }
                         if (isset($this->fields["_ldap_rules"]["rules_entities"])) {
                             $entity_count += count($this->fields["_ldap_rules"]["rules_entities"]);
                         }
                         if (isset($this->input["_ldap_rules"]["rules_rights"])) {
                             $right_count += count($this->fields["_ldap_rules"]["rules_rights"]);
                         }
                         if ($entity_count && $right_count) {
                             $ok = true;
                         }
                     }
                 }
                 if (!$ok) {
                     $this->fields["_stop_import"] = true;
                     return false;
                 }
             }
             //Hook to retrieve more informations for ldap
             $this->fields = doHookFunction("retrieve_more_data_from_ldap", $this->fields);
         }
         return true;
     }
     return false;
 }