Exemplo n.º 1
0
 /**
  * Synchronise LDAP group of the user
  **/
 function syncLdapGroups()
 {
     global $DB;
     // input["_groups"] not set when update from user.form or preference
     if (isset($this->fields["authtype"]) && isset($this->input["_groups"]) && ($this->fields["authtype"] == Auth::LDAP || Auth::isAlternateAuth($this->fields['authtype']))) {
         if (isset($this->fields["id"]) && $this->fields["id"] > 0) {
             $authtype = Auth::getMethodsByID($this->fields["authtype"], $this->fields["auths_id"]);
             if (count($authtype)) {
                 // Clean groups
                 $this->input["_groups"] = array_unique($this->input["_groups"]);
                 // Delete not available groups like to LDAP
                 $query = "SELECT `glpi_groups_users`.`id`,\n                                `glpi_groups_users`.`groups_id`,\n                                `glpi_groups_users`.`is_dynamic`\n                         FROM `glpi_groups_users`\n                         LEFT JOIN `glpi_groups`\n                              ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`)\n                         WHERE `glpi_groups_users`.`users_id` = '" . $this->fields["id"] . "'";
                 $result = $DB->query($query);
                 $groupuser = new Group_User();
                 if ($DB->numrows($result) > 0) {
                     while ($data = $DB->fetch_assoc($result)) {
                         if (in_array($data["groups_id"], $this->input["_groups"])) {
                             // Delete found item in order not to add it again
                             unset($this->input["_groups"][array_search($data["groups_id"], $this->input["_groups"])]);
                         } else {
                             if ($data['is_dynamic']) {
                                 $groupuser->delete(array('id' => $data["id"]));
                             }
                         }
                     }
                 }
                 //If the user needs to be added to one group or more
                 if (count($this->input["_groups"]) > 0) {
                     foreach ($this->input["_groups"] as $group) {
                         $groupuser->add(array('users_id' => $this->fields["id"], 'groups_id' => $group, 'is_dynamic' => 1));
                     }
                     unset($this->input["_groups"]);
                 }
             }
         }
     }
 }
     $user->update($_POST);
     Event::log($_POST['id'], "users", 5, "setup", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
     Html::back();
 } else {
     if (isset($_POST["addgroup"])) {
         $groupuser->check(-1, CREATE, $_POST);
         if ($groupuser->add($_POST)) {
             Event::log($_POST["users_id"], "users", 4, "setup", sprintf(__('%s adds a user to a group'), $_SESSION["glpiname"]));
         }
         Html::back();
     } else {
         if (isset($_POST["deletegroup"])) {
             if (count($_POST["item"])) {
                 foreach ($_POST["item"] as $key => $val) {
                     if ($groupuser->can($key, DELETE)) {
                         $groupuser->delete(array('id' => $key));
                     }
                 }
             }
             Event::log($_POST["users_id"], "users", 4, "setup", sprintf(__('%s deletes users from a group'), $_SESSION["glpiname"]));
             Html::back();
         } else {
             if (isset($_POST["change_auth_method"])) {
                 Session::checkRight('user', User::UPDATEAUTHENT);
                 if (isset($_POST["auths_id"])) {
                     User::changeAuthMethod(array($_POST["id"]), $_POST["authtype"], $_POST["auths_id"]);
                 }
                 Html::back();
             } else {
                 if (isset($_GET["ext_auth"])) {
                     Html::header(User::getTypeName(Session::getPluralNumber()), '', "admin", "user");