/** * 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"]); } } } } }