diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 97d732f6908..1af04366651 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -1061,12 +1061,21 @@ if (count($listofextcals)) $event->id = $icalevent['UID']; $event->ref = $event->id; - $event->icalname = $namecal; + $userId = $userstatic->findUserIdByEmail($namecal); + if(!empty($userId)) + { + $event->userassigned[$userId] = $userId; + } + else + { + $event->icalname = $namecal; + $event->type_code = "ICALEVENT"; + } + $event->icalcolor = $colorcal; $usertime = 0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output. $event->datep = $datestart + $usertime; $event->datef = $dateend + $usertime; - $event->type_code = "ICALEVENT"; if ($icalevent['SUMMARY']) $event->label = $icalevent['SUMMARY']; elseif ($icalevent['DESCRIPTION']) $event->label = dol_nl2br($icalevent['DESCRIPTION'], 1); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index fdda769c5f4..6d278e635fa 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -3236,5 +3236,46 @@ class User extends CommonObject $this->errors[] = $this->db->lasterror(); return -1; } - } + } + + /** + * Cache the SQL results of the function "findUserIdByEmail($email)" + * + * @var array + */ + private $findUserIdByEmailCache; + + /** + * Find a user by the given e-mail or part of a e-mail and return its user id when found + * + * @param string $email The full e-mail or a part of a e-mail + * @return int|null The id of the user when found, otherwise null + */ + public function findUserIdByEmail($email) + { + if($this->findUserIdByEmailCache[$email]) + { + return $this->findUserIdByEmailCache[$email]; + } + + $sql = 'SELECT rowid'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'user'; + $sql .= ' WHERE email LIKE "%'.$email.'%"'; + + $resql = $this->db->query($sql); + if (!$resql) + { + return 0; + } + + $obj = $this->db->fetch_object($resql); + if (!$obj) + { + return 0; + } + + $this->findUserIdByEmailCache[$email] = (int)$obj->rowid; + + return (int)$obj->rowid; + } }