예제 #1
0
 /**
  * Synchronise Dynamics emails of the user
  *
  * Use _emails (set from getFromLDAP), not _usermails set from UI
  **/
 function syncDynamicEmails()
 {
     global $DB;
     // input["_emails"] not set when update from user.form or preference
     if (isset($this->fields["authtype"]) && isset($this->input["_emails"]) && ($this->fields["authtype"] == Auth::LDAP || Auth::isAlternateAuth($this->fields['authtype']) || $this->fields["authtype"] == Auth::MAIL)) {
         if (isset($this->fields["id"]) && $this->fields["id"] > 0) {
             $authtype = Auth::getMethodsByID($this->fields["authtype"], $this->fields["auths_id"]);
             if (count($authtype) || $this->fields["authtype"] == Auth::EXTERNAL) {
                 // Clean emails
                 $this->input["_emails"] = array_unique($this->input["_emails"]);
                 // Delete not available groups like to LDAP
                 $query = "SELECT `glpi_useremails`.`id`,\n                                `glpi_useremails`.`users_id`,\n                                `glpi_useremails`.`email`,\n                                `glpi_useremails`.`is_dynamic`\n                         FROM `glpi_useremails`\n                         WHERE `glpi_useremails`.`users_id` = '" . $this->fields["id"] . "'";
                 $result = $DB->query($query);
                 $useremail = new UserEmail();
                 if ($DB->numrows($result) > 0) {
                     while ($data = $DB->fetch_assoc($result)) {
                         $i = array_search($data["email"], $this->input["_emails"]);
                         if ($i !== false) {
                             // Delete found item in order not to add it again
                             unset($this->input["_emails"][$i]);
                         } else {
                             if ($data['is_dynamic']) {
                                 // Delete not found email
                                 $useremail->delete(array('id' => $data["id"]));
                             }
                         }
                     }
                 }
                 //If the email need to be added
                 if (count($this->input["_emails"]) > 0) {
                     foreach ($this->input["_emails"] as $email) {
                         $useremail->add(array('users_id' => $this->fields["id"], 'email' => $email, 'is_dynamic' => 1));
                     }
                     unset($this->input["_emails"]);
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * @param $values
  * @param $add                (true by default)
  * @param $rights    array
  */
 function processAfterInsertOrUpdate($values, $add = true, $rights = array())
 {
     global $DB;
     //Manage user emails
     if (isset($values['User']['useremails_id']) && $rights['add_dropdown'] && Session::haveRight('user', 'w')) {
         if (!countElementsInTable("glpi_useremails", "`users_id`='" . $values['User']['id'] . "'\n                                       AND `email`='" . $values['User']['useremails_id'] . "'")) {
             $useremail = new UserEmail();
             $tmp['users_id'] = $values['User']['id'];
             $tmp['email'] = $values['User']['useremails_id'];
             $useremail->add($tmp);
         }
     }
     if (isset($values['User']['password']) && $values['User']['password'] != '') {
         //We use an SQL request because updating the password is unesasy
         //(self reset password process in $user->prepareInputForUpdate())
         $password = sha1(Toolbox::unclean_cross_side_scripting_deep(stripslashes($values['User']["password"])));
         $query = "UPDATE `glpi_users`\n                   SET `password` = '" . $password . "'\n                   WHERE `id` = '" . $values['User']['id'] . "'";
         $DB->query($query);
     }
 }