예제 #1
0
 function post_addItem()
 {
     global $CFG_GLPI;
     if (isset($this->input['content'])) {
         if (isset($this->input['_stock_image'])) {
             $this->addImagePaste();
         }
     }
     // Log this event
     $username = '******';
     if (isset($_SESSION["glpiname"])) {
         $username = $_SESSION["glpiname"];
     }
     Event::log($this->fields['id'], "ticket", 4, "tracking", sprintf(__('%1$s adds the item %2$s'), $username, $this->fields['id']));
     if (isset($this->input["_followup"]) && is_array($this->input["_followup"]) && strlen($this->input["_followup"]['content']) > 0) {
         $fup = new TicketFollowup();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id']);
         if (isset($this->input["_followup"]['content']) && strlen($this->input["_followup"]['content']) > 0) {
             $toadd["content"] = $this->input["_followup"]['content'];
         }
         if (isset($this->input["_followup"]['is_private'])) {
             $toadd["is_private"] = $this->input["_followup"]['is_private'];
         }
         // $toadd['_no_notif'] = true;
         $fup->add($toadd);
     }
     if (isset($this->input["plan"]) && count($this->input["plan"]) || isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $task = new TicketTask();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id'], "actiontime" => $this->input["actiontime"]);
         if (isset($this->input["plan"]) && count($this->input["plan"])) {
             $toadd["plan"] = $this->input["plan"];
         }
         if (isset($_SESSION['glpitask_private'])) {
             $toadd['is_private'] = $_SESSION['glpitask_private'];
         }
         // $toadd['_no_notif'] = true;
         $task->add($toadd);
     }
     $ticket_ticket = new Ticket_Ticket();
     // From interface
     if (isset($this->input['_link'])) {
         $this->input['_link']['tickets_id_1'] = $this->fields['id'];
         // message if ticket's ID doesn't exist
         if (!empty($this->input['_link']['tickets_id_2'])) {
             if ($ticket_ticket->can(-1, CREATE, $this->input['_link'])) {
                 $ticket_ticket->add($this->input['_link']);
             } else {
                 Session::addMessageAfterRedirect(__('Unknown ticket'), false, ERROR);
             }
         }
     }
     // From mailcollector : do not check rights
     if (isset($this->input["_linkedto"])) {
         $input2['tickets_id_1'] = $this->fields['id'];
         $input2['tickets_id_2'] = $this->input["_linkedto"];
         $input2['link'] = Ticket_Ticket::LINK_TO;
         $ticket_ticket->add($input2);
     }
     // Manage SLT Level : add actions
     foreach (array(SLT::TTR, SLT::TTO) as $sltType) {
         list($dateField, $sltField) = SLT::getSltFieldNames($sltType);
         if (isset($this->input[$sltField]) && $this->input[$sltField] > 0) {
             $this->manageSltLevel($this->input[$sltField]);
         }
     }
     // Add project task link if needed
     if (isset($this->input['_projecttasks_id'])) {
         $projecttask = new ProjectTask();
         if ($projecttask->getFromDB($this->input['_projecttasks_id'])) {
             $pt = new ProjectTask_Ticket();
             $pt->add(array('projecttasks_id' => $this->input['_projecttasks_id'], 'tickets_id' => $this->fields['id']));
         }
     }
     if (!empty($this->input['items_id'])) {
         $item_ticket = new Item_Ticket();
         foreach ($this->input['items_id'] as $itemtype => $items) {
             foreach ($items as $items_id) {
                 $item_ticket->add(array('items_id' => $items_id, 'itemtype' => $itemtype, 'tickets_id' => $this->fields['id'], '_disablenotif' => true));
             }
         }
     }
     parent::post_addItem();
     $this->manageValidationAdd($this->input);
     // Processing Email
     if ($CFG_GLPI["use_mailing"]) {
         // Clean reload of the ticket
         $this->getFromDB($this->fields['id']);
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         NotificationEvent::raiseEvent($type, $this);
     }
     if (isset($_SESSION['glpiis_ids_visible']) && !$_SESSION['glpiis_ids_visible']) {
         Session::addMessageAfterRedirect(sprintf(__('%1$s (%2$s)'), __('Your ticket has been registered, its treatment is in progress.'), sprintf(__('%1$s: %2$s'), __('Ticket'), "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $this->fields['id'] . "'>" . $this->fields['id'] . "</a>")));
     }
 }
예제 #2
0
 function post_addItem()
 {
     global $LANG, $CFG_GLPI;
     // Add document if needed
     $this->addFiles($this->fields['id']);
     if (isset($this->input["_followup"]) && is_array($this->input["_followup"]) && strlen($this->input["_followup"]['content']) > 0) {
         $fup = new TicketFollowup();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == "solved") {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id']);
         if (isset($this->input["_followup"]['content']) && strlen($this->input["_followup"]['content']) > 0) {
             $toadd["content"] = $this->input["_followup"]['content'];
         }
         if (isset($this->input["_followup"]['is_private'])) {
             $toadd["is_private"] = $this->input["_followup"]['is_private'];
         }
         $toadd['_no_notif'] = true;
         $fup->add($toadd);
     }
     if (isset($this->input["plan"]) || isset($this->input["_hour"]) && isset($this->input["_minute"]) && isset($this->input["realtime"]) && $this->input["realtime"] > 0) {
         $task = new TicketTask();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == "solved") {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id']);
         if (isset($this->input["_hour"])) {
             $toadd["hour"] = $this->input["_hour"];
         }
         if (isset($this->input["_minute"])) {
             $toadd["minute"] = $this->input["_minute"];
         }
         if (isset($this->input["plan"])) {
             $toadd["plan"] = $this->input["plan"];
         }
         $toadd['_no_notif'] = true;
         $task->add($toadd);
     }
     $ticket_ticket = new Ticket_Ticket();
     // From interface
     if (isset($this->input['_link'])) {
         $this->input['_link']['tickets_id_1'] = $this->fields['id'];
         if ($ticket_ticket->can(-1, 'w', $this->input['_link'])) {
             $ticket_ticket->add($this->input['_link']);
         }
     }
     // From mailcollector : do not check rights
     if (isset($this->input["_linkedto"])) {
         $input2['tickets_id_1'] = $this->fields['id'];
         $input2['tickets_id_2'] = $this->input["_linkedto"];
         $input2['link'] = Ticket_Ticket::LINK_TO;
         $ticket_ticket->add($input2);
     }
     // Manage SLA Level : add actions
     if (isset($this->input["slas_id"]) && $this->input["slas_id"] > 0 && isset($this->input["slalevels_id"]) && $this->input["slalevels_id"] > 0) {
         $sla = new SLA();
         if ($sla->getFromDB($this->input["slas_id"])) {
             // Add first level in working table
             if ($this->input["slalevels_id"] > 0) {
                 $sla->addLevelToDo($this);
             }
         }
     }
     // Add user groups linked to tickets
     $ticket_user = new Ticket_User();
     $group_ticket = new Group_Ticket();
     if (isset($this->input["_users_id_requester"]) && ($this->input["_users_id_requester"] > 0 || isset($this->input["_users_id_requester_notif"]['alternative_email']) && !empty($this->input["_users_id_requester_notif"]['alternative_email']))) {
         $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_requester"], 'type' => self::REQUESTER);
         if (isset($this->input["_users_id_requester_notif"])) {
             foreach ($this->input["_users_id_requester_notif"] as $key => $val) {
                 $input2[$key] = $val;
             }
         }
         $ticket_user->add($input2);
     }
     if (isset($this->input["_users_id_observer"]) && ($this->input["_users_id_observer"] > 0 || isset($this->input["_users_id_observer_notif"]['alternative_email']) && !empty($this->input["_users_id_observer_notif"]['alternative_email']))) {
         $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_observer"], 'type' => self::OBSERVER);
         if (isset($this->input["_users_id_observer_notif"])) {
             foreach ($this->input["_users_id_observer_notif"] as $key => $val) {
                 $input2[$key] = $val;
             }
         }
         $ticket_user->add($input2);
     }
     if (isset($this->input["_users_id_assign"]) && $this->input["_users_id_assign"] > 0) {
         $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_assign"], 'type' => self::ASSIGN);
         if (isset($this->input["_users_id_assign_notif"])) {
             foreach ($this->input["_users_id_assign_notif"] as $key => $val) {
                 $input2[$key] = $val;
             }
         }
         $ticket_user->add($input2);
     }
     if (isset($this->input["_groups_id_requester"]) && $this->input["_groups_id_requester"] > 0) {
         $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_requester"], 'type' => self::REQUESTER));
     }
     if (isset($this->input["_groups_id_assign"]) && $this->input["_groups_id_assign"] > 0) {
         $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_assign"], 'type' => self::ASSIGN));
     }
     if (isset($this->input["_groups_id_observer"]) && $this->input["_groups_id_observer"] > 0) {
         $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_observer"], 'type' => self::OBSERVER));
     }
     // Additional actors : using default notification parameters
     // Observers : for mailcollector
     if (isset($this->input["_additional_observers"]) && is_array($this->input["_additional_observers"]) && count($this->input["_additional_observers"])) {
         $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::OBSERVER);
         foreach ($this->input["_additional_observers"] as $tmp) {
             if (isset($tmp['users_id'])) {
                 foreach ($tmp as $key => $val) {
                     $input2[$key] = $val;
                 }
                 $ticket_user->add($input2);
             }
         }
     }
     if (isset($this->input["_additional_assigns"]) && is_array($this->input["_additional_assigns"]) && count($this->input["_additional_assigns"])) {
         $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::ASSIGN);
         foreach ($this->input["_additional_assigns"] as $tmp) {
             if (isset($tmp['users_id'])) {
                 foreach ($tmp as $key => $val) {
                     $input2[$key] = $val;
                 }
                 $ticket_user->add($input2);
             }
         }
     }
     if (isset($this->input["_additional_requesters"]) && is_array($this->input["_additional_requesters"]) && count($this->input["_additional_requesters"])) {
         $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::REQUESTER);
         foreach ($this->input["_additional_requesters"] as $tmp) {
             if (isset($tmp['users_id'])) {
                 foreach ($tmp as $key => $val) {
                     $input2[$key] = $val;
                 }
                 $ticket_user->add($input2);
             }
         }
     }
     //Action for send_validation rule
     if (isset($this->input["_add_validation"]) && $this->input["_add_validation"] > 0) {
         $validation = new Ticketvalidation();
         $values['tickets_id'] = $this->fields['id'];
         $values['users_id_validate'] = $this->input["_add_validation"];
         if ($validation->can(-1, 'w', $values)) {
             $validation->add($values);
             Event::log($this->fields['id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . "  " . $LANG['log'][21]);
         }
     }
     // Processing Email
     if ($CFG_GLPI["use_mailing"]) {
         // Clean reload of the ticket
         $this->getFromDB($this->fields['id']);
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == "solved") {
             $type = "solved";
         }
         NotificationEvent::raiseEvent($type, $this);
     }
     if (isset($_SESSION['glpiis_ids_visible']) && !$_SESSION['glpiis_ids_visible']) {
         addMessageAfterRedirect($LANG['help'][18] . " (" . $LANG['job'][38] . "&nbsp;" . "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $this->fields['id'] . "'>" . $this->fields['id'] . "</a>)");
     }
 }
예제 #3
0
 function post_addItem()
 {
     global $CFG_GLPI;
     // Log this event
     $username = '******';
     if (isset($_SESSION["glpiname"])) {
         $username = $_SESSION["glpiname"];
     }
     Event::log($this->fields['id'], "ticket", 4, "tracking", sprintf(__('%1$s adds the item %2$s'), $username, $this->fields['id']));
     if (isset($this->input["_followup"]) && is_array($this->input["_followup"]) && strlen($this->input["_followup"]['content']) > 0) {
         $fup = new TicketFollowup();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id']);
         if (isset($this->input["_followup"]['content']) && strlen($this->input["_followup"]['content']) > 0) {
             $toadd["content"] = $this->input["_followup"]['content'];
         }
         if (isset($this->input["_followup"]['is_private'])) {
             $toadd["is_private"] = $this->input["_followup"]['is_private'];
         }
         $toadd['_no_notif'] = true;
         $fup->add($toadd);
     }
     if (isset($this->input["plan"]) && count($this->input["plan"]) || isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $task = new TicketTask();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id'], "actiontime" => $this->input["actiontime"]);
         if (isset($this->input["plan"]) && count($this->input["plan"])) {
             $toadd["plan"] = $this->input["plan"];
         }
         if (isset($_SESSION['glpitask_private'])) {
             $toadd['is_private'] = $_SESSION['glpitask_private'];
         }
         $toadd['_no_notif'] = true;
         $task->add($toadd);
     }
     $ticket_ticket = new Ticket_Ticket();
     // From interface
     if (isset($this->input['_link'])) {
         $this->input['_link']['tickets_id_1'] = $this->fields['id'];
         // message if ticket's ID doesn't exist
         if (!empty($this->input['_link']['tickets_id_2'])) {
             if ($ticket_ticket->can(-1, 'w', $this->input['_link'])) {
                 $ticket_ticket->add($this->input['_link']);
             } else {
                 Session::addMessageAfterRedirect(__('Unknown ticket'), false, ERROR);
             }
         }
     }
     // From mailcollector : do not check rights
     if (isset($this->input["_linkedto"])) {
         $input2['tickets_id_1'] = $this->fields['id'];
         $input2['tickets_id_2'] = $this->input["_linkedto"];
         $input2['link'] = Ticket_Ticket::LINK_TO;
         $ticket_ticket->add($input2);
     }
     // Manage SLA Level : add actions
     if (isset($this->input["slas_id"]) && $this->input["slas_id"] > 0 && isset($this->input["slalevels_id"]) && $this->input["slalevels_id"] > 0) {
         $calendars_id = Entity::getUsedConfig('calendars_id', $this->fields['entities_id']);
         $sla = new SLA();
         if ($sla->getFromDB($this->input["slas_id"])) {
             $sla->setTicketCalendar($calendars_id);
             // Add first level in working table
             if ($this->input["slalevels_id"] > 0) {
                 $sla->addLevelToDo($this);
             }
             // Replay action in case of open date is set before now
         }
         SlaLevel_Ticket::replayForTicket($this->getID());
     }
     parent::post_addItem();
     //Action for send_validation rule
     if (isset($this->input["_add_validation"])) {
         $validations_to_send = array();
         if (!is_array($this->input["_add_validation"])) {
             $this->input["_add_validation"] = array($this->input["_add_validation"]);
         }
         foreach ($this->input["_add_validation"] as $validation) {
             switch ($validation) {
                 case 'requester_supervisor':
                     if (isset($this->input['_groups_id_requester']) && $this->input['_groups_id_requester']) {
                         $users = Group_User::getGroupUsers($this->input['_groups_id_requester'], "is_manager='1'");
                         foreach ($users as $data) {
                             $validations_to_send[] = $data['id'];
                         }
                     }
                     break;
                 case 'assign_supervisor':
                     if (isset($this->input['_groups_id_assign']) && $this->input['_groups_id_assign']) {
                         $users = Group_User::getGroupUsers($this->input['_groups_id_assign'], "is_manager='1'");
                         foreach ($users as $data) {
                             $validations_to_send[] = $data['id'];
                         }
                     }
                     break;
                 default:
                     $validations_to_send[] = $validation;
             }
         }
         // Keep only one
         $validations_to_send = array_unique($validations_to_send);
         $validation = new TicketValidation();
         foreach ($validations_to_send as $users_id) {
             if ($users_id > 0) {
                 $values = array();
                 $values['tickets_id'] = $this->fields['id'];
                 $values['users_id_validate'] = $users_id;
                 $values['_ticket_add'] = true;
                 // to know update by rules
                 if (isset($this->input["_rule_process"])) {
                     $values['_rule_process'] = $this->input["_rule_process"];
                 }
                 // if auto_import, tranfert it for validation
                 if (isset($this->input['_auto_import'])) {
                     $values['_auto_import'] = $this->input['_auto_import'];
                 }
                 // Cron or rule process of hability to do
                 if (Session::isCron() || isset($this->input["_auto_import"]) || isset($this->input["_rule_process"]) || $validation->can(-1, 'w', $values)) {
                     // cron or allowed user
                     $validation->add($values);
                     Event::log($this->fields['id'], "ticket", 4, "tracking", sprintf(__('%1$s updates the item %2$s'), $_SESSION["glpiname"], $this->fields['id']));
                 }
             }
         }
     }
     // Processing Email
     if ($CFG_GLPI["use_mailing"]) {
         // Clean reload of the ticket
         $this->getFromDB($this->fields['id']);
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         NotificationEvent::raiseEvent($type, $this);
     }
     if (isset($_SESSION['glpiis_ids_visible']) && !$_SESSION['glpiis_ids_visible']) {
         Session::addMessageAfterRedirect(sprintf(__('%1$s (%2$s)'), __('Your ticket has been registered, its treatment is in progress.'), sprintf(__('%1$s: %2$s'), __('Ticket'), "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $this->fields['id'] . "'>" . $this->fields['id'] . "</a>")));
     }
 }
예제 #4
0
 /**
  * CLone a ticket and his relations
  * @param  integer $tickets_id id of the ticket to clone
  * @return print a json response (return nothing)
  */
 static function cloneAndLink($tickets_id)
 {
     global $DB;
     //get old ticket
     $ticket = new Ticket();
     if (!$ticket->getFromDB($tickets_id)) {
         echo "{\"success\":false, \"message\":\"" . __("Error : get old ticket", "escalade") . "\"}";
         exit;
     }
     //set fields
     $fields = $ticket->fields;
     $fields = array_map(array('Toolbox', 'addslashes_deep'), $fields);
     $fields['id'] = 0;
     $fields['_users_id_requester'] = 0;
     $fields['status'] = CommonITILObject::INCOMING;
     /*var_dump($fields);
       exit;*/
     //create new ticket (duplicate from previous)
     if (!($newID = $ticket->add($fields))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding new ticket", "escalade") . "\"}";
         exit;
     }
     //add link between them
     $ticket_ticket = new Ticket_Ticket();
     if (!$ticket_ticket->add(array('tickets_id_1' => $tickets_id, 'tickets_id_2' => $newID, 'link' => Ticket_Ticket::LINK_TO))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding link between the two tickets", "escalade") . "\"}";
         exit;
     }
     //add a followup to indicate duplication
     $followup = new TicketFollowup();
     if (!$followup->add(array('tickets_id' => $newID, 'users_id' => Session::getLoginUserID(), 'content' => __("This ticket has been from the ticket num", "escalade") . " " . $tickets_id, 'is_private' => true, 'requesttypes_id' => 6))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding followups", "escalade") . "\"}";
         exit;
     }
     //add actors to the new ticket (without assign)
     //users
     $query_users = "INSERT INTO glpi_tickets_users\n      SELECT '' AS id, {$newID} as tickets_id, users_id, type, use_notification, alternative_email\n      FROM glpi_tickets_users\n      WHERE tickets_id = {$tickets_id} AND type != 2";
     if (!($res = $DB->query($query_users))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding actors (user)", "escalade") . "\"}";
         exit;
     }
     //groups
     $query_groups = "INSERT INTO glpi_groups_tickets\n      SELECT '' AS id, {$newID} as tickets_id, groups_id, type\n      FROM glpi_groups_tickets\n      WHERE tickets_id = {$tickets_id} AND type != 2";
     if (!($res = $DB->query($query_groups))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding actors (group)", "escalade") . "\"}";
         exit;
     }
     //add documents
     $query_docs = "INSERT INTO glpi_documents_items (documents_id, items_id, itemtype, entities_id, is_recursive, date_mod)\n      SELECT documents_id, {$newID}, 'Ticket', entities_id, is_recursive, date_mod\n      FROM glpi_documents_items\n      WHERE items_id = {$tickets_id} AND itemtype = 'Ticket'";
     if (!($res = $DB->query($query_docs))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding documents", "escalade") . "\"}";
         exit;
     }
     //add history to the new ticket
     $changes[0] = '0';
     $changes[1] = __("This ticket has been from the ticket num", "escalade") . " " . $tickets_id;
     $changes[2] = "";
     Log::history($newID, 'Ticket', $changes, 'Ticket');
     //add message (ticket cloned) after redirect
     Session::addMessageAfterRedirect(__("This ticket has been from the ticket num", "escalade") . " " . $tickets_id);
     //all ok
     echo "{\"success\":true, \"newID\":{$newID}}";
 }