Exemplo n.º 1
0
 /**
  * @param $email  (default '')
  **/
 static function getOrImportByEmail($email = '')
 {
     global $DB, $CFG_GLPI;
     $query = "SELECT `users_id` as id\n                FROM `glpi_useremails`\n                LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_useremails`.`users_id`)\n                WHERE `glpi_useremails`.`email` = '{$email}'\n                ORDER BY `glpi_users`.`is_active`  DESC";
     $result = $DB->query($query);
     //User still exists in DB
     if ($result && $DB->numrows($result)) {
         return $DB->result($result, 0, "id");
     } else {
         if ($CFG_GLPI["is_users_auto_add"]) {
             //Get all ldap servers with email field configured
             $ldaps = AuthLdap::getServersWithImportByEmailActive();
             //Try to find the user by his email on each ldap server
             foreach ($ldaps as $ldap) {
                 $params['method'] = AuthLdap::IDENTIFIER_EMAIL;
                 $params['value'] = $email;
                 $res = AuthLdap::ldapImportUserByServerId($params, AuthLdap::ACTION_IMPORT, $ldap);
                 if (isset($res['id'])) {
                     return $res['id'];
                 }
             }
         }
     }
     return 0;
 }