コード例 #1
0
ファイル: ticket.class.php プロジェクト: glpi-project/glpi
 /**
  * @since version 0.90
  *
  **/
 function getTimelineItems()
 {
     global $DB, $CFG_GLPI;
     $timeline = array();
     $user = new User();
     $group = new Group();
     $followup_obj = new TicketFollowup();
     $task_obj = new TicketTask();
     $document_item_obj = new Document_Item();
     $ticket_valitation_obj = new TicketValidation();
     //checks rights
     $showpublic = Session::haveRightsOr("followup", array(TicketFollowup::SEEPUBLIC, TicketFollowup::SEEPRIVATE)) || Session::haveRightsOr("task", array(TicketTask::SEEPUBLIC, TicketTask::SEEPRIVATE));
     $restrict_fup = $restrict_task = "";
     if (!Session::haveRight("followup", TicketFollowup::SEEPRIVATE)) {
         $restrict_fup = " AND (`is_private` = '0'\n                                OR `users_id` ='" . Session::getLoginUserID() . "') ";
     }
     if (!Session::haveRight("task", TicketTask::SEEPRIVATE)) {
         $restrict_task = " AND (`is_private` = '0'\n                                 OR `users_id` ='" . Session::getLoginUserID() . "') ";
     }
     if (!$showpublic) {
         $restrict = " AND 1 = 0";
     }
     //add ticket followups to timeline
     if ($followup_obj->canview()) {
         $followups = $followup_obj->find("tickets_id = " . $this->getID() . " {$restrict_fup}", 'date DESC');
         foreach ($followups as $followups_id => $followup) {
             $followup_obj->getFromDB($followups_id);
             $followup['can_edit'] = $followup_obj->canUpdateItem();
             $timeline[$followup['date'] . "_followup_" . $followups_id] = array('type' => 'TicketFollowup', 'item' => $followup);
         }
     }
     //add ticket tasks to timeline
     if ($task_obj->canview()) {
         $tasks = $task_obj->find("tickets_id = " . $this->getID() . " {$restrict_task}", 'date DESC');
         foreach ($tasks as $tasks_id => $task) {
             $task_obj->getFromDB($tasks_id);
             $task['can_edit'] = $task_obj->canUpdateItem();
             $timeline[$task['date'] . "_task_" . $tasks_id] = array('type' => 'TicketTask', 'item' => $task);
         }
     }
     //add ticket documents to timeline
     $document_obj = new Document();
     $document_items = $document_item_obj->find("itemtype = 'Ticket' AND items_id = " . $this->getID());
     foreach ($document_items as $document_item) {
         $document_obj->getFromDB($document_item['documents_id']);
         $timeline[$document_obj->fields['date_mod'] . "_document_" . $document_item['documents_id']] = array('type' => 'Document_Item', 'item' => $document_obj->fields);
     }
     //add existing solution
     if (!empty($this->fields['solution']) || !empty($this->fields['solutiontypes_id'])) {
         $users_id = 0;
         $solution_date = $this->fields['solvedate'];
         //search date and user of last solution in glpi_logs
         if ($res_solution = $DB->query("SELECT `date_mod` AS solution_date, `user_name`, `id`\n                                         FROM `glpi_logs`\n                                         WHERE `itemtype` = 'Ticket'\n                                               AND `items_id` = " . $this->getID() . "\n                                               AND `id_search_option` = 24\n                                         ORDER BY `id` DESC\n                                         LIMIT 1")) {
             $data_solution = $DB->fetch_assoc($res_solution);
             if (!empty($data_solution['solution_date'])) {
                 $solution_date = $data_solution['solution_date'];
             }
             // find user
             if (!empty($data_solution['user_name'])) {
                 $users_id = addslashes(trim(preg_replace("/.*\\(([0-9]+)\\)/", "\$1", $data_solution['user_name'])));
             }
         }
         // fix trouble with html_entity_decode who skip accented characters (on windows browser)
         $solution_content = preg_replace_callback("/(&#[0-9]+;)/", function ($m) {
             return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
         }, $this->fields['solution']);
         $timeline[$solution_date . "_solution"] = array('type' => 'Solution', 'item' => array('id' => 0, 'content' => Toolbox::unclean_cross_side_scripting_deep($solution_content), 'date' => $solution_date, 'users_id' => $users_id, 'solutiontypes_id' => $this->fields['solutiontypes_id'], 'can_edit' => Ticket::canUpdate() && $this->canSolve()));
     }
     // add ticket validation to timeline
     if ($this->fields['type'] == Ticket::DEMAND_TYPE && (Session::haveRight('ticketvalidation', TicketValidation::VALIDATEREQUEST) || Session::haveRight('ticketvalidation', TicketValidation::CREATEREQUEST)) || $this->fields['type'] == Ticket::INCIDENT_TYPE && (Session::haveRight('ticketvalidation', TicketValidation::VALIDATEINCIDENT) || Session::haveRight('ticketvalidation', TicketValidation::CREATEINCIDENT))) {
         $ticket_validations = $ticket_valitation_obj->find('tickets_id = ' . $this->getID());
         foreach ($ticket_validations as $validations_id => $validation) {
             $canedit = $ticket_valitation_obj->can($validations_id, UPDATE);
             $user->getFromDB($validation['users_id_validate']);
             $timeline[$validation['submission_date'] . "_validation_" . $validations_id] = array('type' => 'TicketValidation', 'item' => array('id' => $validations_id, 'date' => $validation['submission_date'], 'content' => __('Validation request') . " => " . $user->getlink() . "<br>" . $validation['comment_submission'], 'users_id' => $validation['users_id'], 'can_edit' => $canedit));
             if (!empty($validation['validation_date'])) {
                 $timeline[$validation['validation_date'] . "_validation_" . $validations_id] = array('type' => 'TicketValidation', 'item' => array('id' => $validations_id, 'date' => $validation['validation_date'], 'content' => __('Validation request answer') . " : " . _sx('status', ucfirst(TicketValidation::getStatus($validation['status']))) . "<br>" . $validation['comment_validation'], 'users_id' => $validation['users_id_validate'], 'status' => "status_" . $validation['status'], 'can_edit' => $canedit));
             }
         }
     }
     //reverse sort timeline items by key (date)
     krsort($timeline);
     return $timeline;
 }