static function checkAssignUser(Ticket $ticket)
 {
     global $DB;
     $ok = 0;
     $ptConfig = new PluginTimelineticketConfig();
     $ptConfig->getFromDB(1);
     if ($ptConfig->fields["add_waiting"] == 0) {
         $ok = 1;
     }
     if ($ok && in_array("status", $ticket->updates) && isset($ticket->oldvalues["status"]) && $ticket->oldvalues["status"] == Ticket::WAITING) {
         if ($ticket->countUsers(CommonITILActor::ASSIGN)) {
             foreach ($ticket->getUsers(CommonITILActor::ASSIGN) as $d) {
                 $ptAssignUser = new PluginTimelineticketAssignUser();
                 $calendar = new Calendar();
                 $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
                 $datedebut = $ticket->fields['date'];
                 if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
                     $delay = $calendar->getActiveTimeBetween($datedebut, $_SESSION["glpi_currenttime"]);
                 } else {
                     // cas 24/24 - 7/7
                     $delay = strtotime($_SESSION["glpi_currenttime"]) - strtotime($datedebut);
                 }
                 $input = array();
                 $input['tickets_id'] = $ticket->getID();
                 $input['users_id'] = $d["users_id"];
                 $input['date'] = $_SESSION["glpi_currenttime"];
                 $input['begin'] = $delay;
                 $ptAssignUser->add($input);
             }
         }
     } else {
         if ($ok && in_array("status", $ticket->updates) && isset($ticket->fields["status"]) && $ticket->fields["status"] == Ticket::WAITING) {
             if ($ticket->countUsers(CommonITILActor::ASSIGN)) {
                 foreach ($ticket->getUsers(CommonITILActor::ASSIGN) as $d) {
                     $calendar = new Calendar();
                     $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
                     $ptAssignUser = new PluginTimelineticketAssignUser();
                     $query = "SELECT MAX(`date`) AS datedebut, id\n                         FROM `" . $ptAssignUser->getTable() . "`\n                         WHERE `tickets_id` = '" . $ticket->getID() . "'\n                           AND `users_id`='" . $d["users_id"] . "'\n                           AND `delay` IS NULL";
                     $result = $DB->query($query);
                     $datedebut = '';
                     $input = array();
                     if ($result && $DB->numrows($result)) {
                         $datedebut = $DB->result($result, 0, 'datedebut');
                         $input['id'] = $DB->result($result, 0, 'id');
                     } else {
                         return;
                     }
                     if (!$datedebut) {
                         $delay = 0;
                         // Utilisation calendrier
                     } else {
                         if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
                             $delay = $calendar->getActiveTimeBetween($datedebut, $_SESSION["glpi_currenttime"]);
                         } else {
                             // cas 24/24 - 7/7
                             $delay = strtotime($_SESSION["glpi_currenttime"]) - strtotime($datedebut);
                         }
                     }
                     $input['delay'] = $delay;
                     $ptAssignUser->update($input);
                 }
             }
         } else {
             if (in_array("status", $ticket->updates) && isset($ticket->input["status"]) && ($ticket->input["status"] == Ticket::SOLVED || $ticket->input["status"] == Ticket::CLOSED)) {
                 if ($ticket->countUsers(CommonITILActor::ASSIGN)) {
                     foreach ($ticket->getUsers(CommonITILActor::ASSIGN) as $d) {
                         $calendar = new Calendar();
                         $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
                         $ptAssignUser = new PluginTimelineticketAssignUser();
                         $query = "SELECT MAX(`date`) AS datedebut, id\n                         FROM `" . $ptAssignUser->getTable() . "`\n                         WHERE `tickets_id` = '" . $ticket->getID() . "'\n                           AND `users_id`='" . $d["users_id"] . "'\n                           AND `delay` IS NULL";
                         $result = $DB->query($query);
                         $datedebut = '';
                         $input = array();
                         if ($result && $DB->numrows($result)) {
                             $datedebut = $DB->result($result, 0, 'datedebut');
                             $input['id'] = $DB->result($result, 0, 'id');
                         } else {
                             return;
                         }
                         if (!$datedebut) {
                             $delay = 0;
                             // Utilisation calendrier
                         } else {
                             if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
                                 $delay = $calendar->getActiveTimeBetween($datedebut, $_SESSION["glpi_currenttime"]);
                             } else {
                                 // cas 24/24 - 7/7
                                 $delay = strtotime($_SESSION["glpi_currenttime"]) - strtotime($datedebut);
                             }
                         }
                         $input['delay'] = $delay;
                         $ptAssignUser->update($input);
                     }
                 }
             }
         }
     }
 }