static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) { global $CFG_GLPI, $DB; $ID = $job->getField('id'); if (!$job->can($ID, 'r')) { return false; } $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . (empty($job->fields["name"]) ? __('Without title') : ($name = $job->fields["name"])) . '</b>'); if (count($_SESSION['glpiactiveentities']) > 1) { $entity = " (" . Dropdown::getDropdownName("glpi_entities", $job->fields["entities_id"]) . ")"; } else { $entity = ''; } $pdf->setColumnsSize(50, 50); $recipient_name = ''; if ($job->fields["users_id_recipient"]) { $recipient = new User(); $recipient->getFromDB($job->fields["users_id_recipient"]); $recipient_name = $recipient->getName(); } $sla = $due = $commentsla = ''; if ($job->fields['due_date']) { $due = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Due date') . "</b></i>", Html::convDateTime($job->fields['due_date'])); } $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Opening date') . "</i></b>", Html::convDateTime($job->fields["date"])), $due); $pdf->setColumnsSize(100); if ($job->fields["slas_id"] > 0) { $sla = "<b><i>" . sprintf(__('%1$s: %2$s'), __('SLA') . "</b></i>", Html::clean(Dropdown::getDropdownName("glpi_slas", $job->fields["slas_id"]))); $slalevel = new SlaLevel(); if ($slalevel->getFromDB($job->fields['slalevels_id'])) { $commentsla = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Escalation level') . "</b></i>", $slalevel->getName()); } $nextaction = new SlaLevel_Ticket(); if ($nextaction->getFromDBForTicket($job->fields["id"])) { $commentsla .= " <b><i>" . sprintf(__('Next escalation: %s') . "</b></i>", Html::convDateTime($nextaction->fields['date'])); if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) { $commentsla .= " <b><i>" . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()); } } $pdf->displayText($sla, $commentsla, 1); } $pdf->setColumnsSize(50, 50); $lastupdate = Html::convDateTime($job->fields["date_mod"]); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf(__('%1$s by %2$s'), $lastupdate, getUserName($job->fields["users_id_lastupdater"])); } $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('By') . "</i></b>", $recipient_name), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Last update') . '</i></b>', $lastupdate)); $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Type') . "</i></b>", Html::clean(Ticket::getTicketTypeName($job->fields["type"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Category') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_itilcategories", $job->fields["itilcategories_id"])))); $status = ''; if (in_array($job->fields["status"], $job->getSolvedStatusArray()) || in_array($job->fields["status"], $job->getClosedStatusArray())) { $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields["solvedate"])); } if (in_array($job->fields["status"], $job->getClosedStatusArray())) { $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields["closedate"])); } if ($job->fields["status"] == Ticket::WAITING) { $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['begin_waiting_date'])); } $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Status') . "</i></b>", Html::clean($job->getStatus($job->fields["status"])) . $status), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Request source') . "</i></b>", Html::clean(Dropdown::getDropdownName('glpi_requesttypes', $job->fields['requesttypes_id'])))); $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Urgency') . "</i></b>", Html::clean($job->getUrgencyName($job->fields["urgency"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Approval') . "</i></b>", TicketValidation::getStatus($job->fields['global_validation']))); $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Impact') . "</i></b>", Html::clean($job->getImpactName($job->fields["impact"])))); $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Priority') . "</i></b>", Html::clean($job->getPriorityName($job->fields["priority"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Location') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_locations", $job->fields["locations_id"])))); // Item $name = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Associated element') . "</i></b>", ''); $commentitem = ''; $pdf->setColumnsSize(100); if ($job->fields['itemtype'] && ($item = getItemForItemtype($job->fields['itemtype']))) { if ($item->getFromDB($job->fields["items_id"])) { $name = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Associated element') . "</i></b>", $item->getNameID()); if (isset($item->fields["serial"])) { $commentitem = ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Serial number') . "</i></b>", Html::clean($item->fields["serial"])); Html::clean($item->fields["serial"]); } if (isset($item->fields["otherserial"])) { $commentitem .= ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Inventory number') . "</i></b>", Html::clean($item->fields["otherserial"])); } if (isset($item->fields["locations_id"])) { $commentitem .= ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Location') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_locations", $item->fields["locations_id"]))); } } } $pdf->displayText($name, $commentitem, 1); $pdf->setColumnsSize(50, 50); // Requester $users = array(); $listusers = ''; $requester = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Requester'), $listusers); foreach ($job->getUsers(CommonITILActor::REQUESTER) as $d) { if ($d['users_id']) { $tmp = Html::clean(getUserName($d['users_id'])); if ($d['alternative_email']) { $tmp .= ' (' . $d['alternative_email'] . ')'; } } else { $tmp = $d['alternative_email']; } $users[] = $tmp; } if (count($users)) { $listusers = implode(', ', $users); } $pdf->displayText($requester, $listusers, 1); $groups = array(); $listgroups = ''; $requestergroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Requester group'), $listgroups); foreach ($job->getGroups(CommonITILActor::REQUESTER) as $d) { $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id'])); } if (count($groups)) { $listgroups = implode(', ', $groups); } $pdf->displayText($requestergroup, $listgroups, 1); // Observer $users = array(); $listusers = ''; $watcher = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Watcher'), $listusers); foreach ($job->getUsers(CommonITILActor::OBSERVER) as $d) { if ($d['users_id']) { $tmp = Html::clean(getUserName($d['users_id'])); if ($d['alternative_email']) { $tmp .= ' (' . $d['alternative_email'] . ')'; } } else { $tmp = $d['alternative_email']; } $users[] = $tmp; } if (count($users)) { $listusers = implode(', ', $users); } $pdf->displayText($watcher, $listusers, 1); $groups = array(); $listgroups = ''; $watchergroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Watcher group'), $listgroups); foreach ($job->getGroups(CommonITILActor::OBSERVER) as $d) { $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id'])); } if (count($groups)) { $listgroups = implode(', ', $groups); } $pdf->displayText($watchergroup, $listgroups, 1); // Assign to $users = array(); $listusers = ''; $assign = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('User assigned'), $listusers); foreach ($job->getUsers(CommonITILActor::ASSIGN) as $d) { if ($d['users_id']) { $tmp = Html::clean(getUserName($d['users_id'])); if ($d['alternative_email']) { $tmp .= ' (' . $d['alternative_email'] . ')'; } } else { $tmp = $d['alternative_email']; } $users[] = $tmp; } if (count($users)) { $listusers = implode(', ', $users); } $pdf->displayText($assign, $listusers, 1); $groups = array(); $listgroups = ''; $assigngroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Group assigned'), $listgroups); foreach ($job->getGroups(CommonITILActor::ASSIGN) as $d) { $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id'])); } if (count($groups)) { $listgroups = implode(', ', $groups); } $pdf->displayText($assigngroup, $listgroups, 1); // Supplier $suppliers = array(); $listsuppliers = ''; $assignsupplier = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Supplier assigned'), $listsuppliers); foreach ($job->getSuppliers(CommonITILActor::ASSIGN) as $d) { $suppliers[] = Html::clean(Dropdown::getDropdownName("glpi_suppliers", $d['suppliers_id'])); } if (count($suppliers)) { $listsuppliers = implode(', ', $suppliers); } $pdf->displayText($assignsupplier, $listsuppliers, 1); $pdf->setColumnsSize(100); $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Title') . "</i></b>", $job->fields["name"])); $pdf->displayText("<b><i>" . sprintf(__('%1$s: %2$s'), __('Description') . "</i></b>", $job->fields['content'])); // Linked tickets $tickets = Ticket_Ticket::getLinkedTicketsTo($ID); if (is_array($tickets) && count($tickets)) { $ticket = new Ticket(); foreach ($tickets as $linkID => $data) { $tmp = sprintf(__('%1$s %2$s'), Ticket_Ticket::getLinkName($data['link']), sprintf(__('%1$s %2$s'), __('ID'), $data['tickets_id'])); if ($ticket->getFromDB($data['tickets_id'])) { $tmp = sprintf(__('%1$s: %2$s'), $tmp, $ticket->getName()); } $jobs[] = $tmp; $jobs = implode("\n", $jobs); } $linked = "<b><i>" . sprintf(__('%1$s: %2$s') . "</i></b>", __('Linked tickets'), ''); $pdf->displayText($linked, $jobs, 1); } $pdf->displaySpace(); }
/** * Close linked tickets when ticket passed in parameter is closed * @param CommonDBTM $item the ticket object * @return nothing */ static function linkedTickets(CommonDBTM $ticket, $status = CommonITILObject::SOLVED) { if ($_SESSION['plugins']['escalade']['config']['close_linkedtickets']) { $input = array('status' => $status); $tickets = Ticket_Ticket::getLinkedTicketsTo($ticket->getID()); if (count($tickets)) { foreach ($tickets as $data) { $input['id'] = $data['tickets_id']; if ($ticket->can($input['id'], UPDATE) && $data['link'] == Ticket_Ticket::DUPLICATE_WITH) { $ticket->update($input); } } } } }
/** * @see NotificationTargetCommonITILObject::getDatasForObject() **/ function getDatasForObject(CommonDBTM $item, array $options, $simple = false) { global $CFG_GLPI; // Common ITIL datas $datas = parent::getDatasForObject($item, $options, $simple); $datas['##ticket.description##'] = Html::clean($datas['##ticket.description##']); $datas['##ticket.description##'] = $item->convertContentForNotification($datas['##ticket.description##'], $item); $datas['##ticket.content##'] = $datas['##ticket.description##']; // Specific datas $datas['##ticket.urlvalidation##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $item->getField("id") . "_TicketValidation\$1"); $datas['##ticket.globalvalidation##'] = TicketValidation::getStatus($item->getField('global_validation')); $datas['##ticket.type##'] = Ticket::getTicketTypeName($item->getField('type')); $datas['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $item->getField('requesttypes_id')); $autoclose_value = Entity::getUsedConfig('autoclose_delay', $this->getEntity(), '', Entity::CONFIG_NEVER); $datas['##ticket.autoclose##'] = __('Never'); $datas['##lang.ticket.autoclosewarning##'] = ""; if ($autoclose_value > 0) { $datas['##ticket.autoclose##'] = $autoclose_value; $datas['##lang.ticket.autoclosewarning##'] = sprintf(_n('Without a reply, the ticket will be automatically closed after %s day', 'Without a reply, the ticket will be automatically closed after %s days', $autoclose_value), $autoclose_value); } $datas['##ticket.sla##'] = ''; if ($item->getField('slas_id')) { $datas['##ticket.sla##'] = Dropdown::getDropdownName('glpi_slas', $item->getField('slas_id')); } $datas['##ticket.location##'] = ''; if ($item->getField('locations_id')) { $datas['##ticket.location##'] = Dropdown::getDropdownName('glpi_locations', $item->getField('locations_id')); } // is ticket deleted $datas['##ticket.isdeleted##'] = Dropdown::getYesNo($item->getField('is_deleted')); //Tags associated with the object linked to the ticket $datas['##ticket.itemtype##'] = ''; $datas['##ticket.item.name##'] = ''; $datas['##ticket.item.serial##'] = ''; $datas['##ticket.item.otherserial##'] = ''; $datas['##ticket.item.location##'] = ''; $datas['##ticket.item.contact##'] = ''; $datas['##ticket.item.contactnumber##'] = ''; $datas['##ticket.item.user##'] = ''; $datas['##ticket.item.group##'] = ''; $datas['##ticket.item.model##'] = ''; $item_ticket = new Item_Ticket(); $items = $item_ticket->find("`tickets_id` = '" . $item->getField('id') . "'"); $datas['items'] = array(); if (count($items)) { foreach ($items as $val) { if (isset($val['itemtype']) && ($hardware = getItemForItemtype($val['itemtype'])) && isset($val["items_id"]) && $hardware->getFromDB($val["items_id"])) { $tmp = array(); //Object type $tmp['##ticket.itemtype##'] = $hardware->getTypeName(); //Object name $tmp['##ticket.item.name##'] = $hardware->getField('name'); //Object serial if ($hardware->isField('serial')) { $tmp['##ticket.item.serial##'] = $hardware->getField('serial'); } //Object contact if ($hardware->isField('contact')) { $tmp['##ticket.item.contact##'] = $hardware->getField('contact'); } //Object contact num if ($hardware->isField('contact_num')) { $tmp['##ticket.item.contactnumber##'] = $hardware->getField('contact_num'); } //Object otherserial if ($hardware->isField('otherserial')) { $tmp['##ticket.item.otherserial##'] = $hardware->getField('otherserial'); } //Object location if ($hardware->isField('locations_id')) { $tmp['##ticket.item.location##'] = Dropdown::getDropdownName('glpi_locations', $hardware->getField('locations_id')); } //Object user if ($hardware->getField('users_id')) { $user_tmp = new User(); if ($user_tmp->getFromDB($hardware->getField('users_id'))) { $tmp['##ticket.item.user##'] = $user_tmp->getName(); } } //Object group if ($hardware->getField('groups_id')) { $tmp['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $hardware->getField('groups_id')); } $modeltable = getSingular($hardware->getTable()) . "models"; $modelfield = getForeignKeyFieldForTable($modeltable); if ($hardware->isField($modelfield)) { $tmp['##ticket.item.model##'] = Dropdown::getDropdownName($modeltable, $hardware->getField($modelfield)); } $datas['items'][] = $tmp; } } } $datas['##ticket.numberofitems##'] = count($datas['items']); // Get followups, log, validation, satisfaction, linked tickets if (!$simple) { // Linked tickets $linked_tickets = Ticket_Ticket::getLinkedTicketsTo($item->getField('id')); $datas['linkedtickets'] = array(); if (count($linked_tickets)) { $linkedticket = new Ticket(); foreach ($linked_tickets as $data) { if ($linkedticket->getFromDB($data['tickets_id'])) { $tmp = array(); $tmp['##linkedticket.id##'] = $data['tickets_id']; $tmp['##linkedticket.link##'] = Ticket_Ticket::getLinkName($data['link']); $tmp['##linkedticket.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $data['tickets_id']); $tmp['##linkedticket.title##'] = $linkedticket->getField('name'); $tmp['##linkedticket.content##'] = $linkedticket->getField('content'); $datas['linkedtickets'][] = $tmp; } } } $datas['##ticket.numberoflinkedtickets##'] = count($datas['linkedtickets']); $restrict = "`tickets_id`='" . $item->getField('id') . "'"; $problems = getAllDatasFromTable('glpi_problems_tickets', $restrict); $datas['problems'] = array(); if (count($problems)) { $problem = new Problem(); foreach ($problems as $data) { if ($problem->getFromDB($data['problems_id'])) { $tmp = array(); $tmp['##problem.id##'] = $data['problems_id']; $tmp['##problem.date##'] = $problem->getField('date'); $tmp['##problem.title##'] = $problem->getField('name'); $tmp['##problem.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "problem_" . $data['problems_id']); $tmp['##problem.content##'] = $problem->getField('content'); $datas['problems'][] = $tmp; } } } $datas['##ticket.numberofproblems##'] = count($datas['problems']); $restrict = "`tickets_id`='" . $item->getField('id') . "'"; $changes = getAllDatasFromTable('glpi_changes_tickets', $restrict); $datas['changes'] = array(); if (count($changes)) { $change = new Change(); foreach ($changes as $data) { if ($change->getFromDB($data['changes_id'])) { $tmp = array(); $tmp['##change.id##'] = $data['changes_id']; $tmp['##change.date##'] = $change->getField('date'); $tmp['##change.title##'] = $change->getField('name'); $tmp['##change.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "change_" . $data['changes_id']); $tmp['##change.content##'] = $change->getField('content'); $datas['changes'][] = $tmp; } } } $datas['##ticket.numberofchanges##'] = count($datas['changes']); if (!isset($options['additionnaloption']['show_private']) || !$options['additionnaloption']['show_private']) { $restrict .= " AND `is_private` = '0'"; } $restrict .= " ORDER BY `date` DESC, `id` ASC"; //Followup infos $followups = getAllDatasFromTable('glpi_ticketfollowups', $restrict); $datas['followups'] = array(); foreach ($followups as $followup) { $tmp = array(); $tmp['##followup.isprivate##'] = Dropdown::getYesNo($followup['is_private']); $tmp['##followup.author##'] = Html::clean(getUserName($followup['users_id'])); $tmp['##followup.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $followup['requesttypes_id']); $tmp['##followup.date##'] = Html::convDateTime($followup['date']); $tmp['##followup.description##'] = $followup['content']; $datas['followups'][] = $tmp; } $datas['##ticket.numberoffollowups##'] = count($datas['followups']); // Approbation of solution $restrict .= " LIMIT 1"; $replysolved = getAllDatasFromTable('glpi_ticketfollowups', $restrict); $data = current($replysolved); $datas['##ticket.solution.approval.description##'] = $data['content']; $datas['##ticket.solution.approval.date##'] = Html::convDateTime($data['date']); $datas['##ticket.solution.approval.author##'] = Html::clean(getUserName($data['users_id'])); //Validation infos $restrict = "`tickets_id`='" . $item->getField('id') . "'"; if (isset($options['validation_id']) && $options['validation_id']) { $restrict .= " AND `glpi_ticketvalidations`.`id` = '" . $options['validation_id'] . "'"; } $restrict .= " ORDER BY `submission_date` DESC, `id` ASC"; $validations = getAllDatasFromTable('glpi_ticketvalidations', $restrict); $datas['validations'] = array(); foreach ($validations as $validation) { $tmp = array(); $tmp['##validation.submission.title##'] = sprintf(__('An approval request has been submitted by %s'), Html::clean(getUserName($validation['users_id']))); $tmp['##validation.answer.title##'] = sprintf(__('An answer to an an approval request was produced by %s'), Html::clean(getUserName($validation['users_id_validate']))); $tmp['##validation.author##'] = Html::clean(getUserName($validation['users_id'])); $tmp['##validation.status##'] = TicketValidation::getStatus($validation['status']); $tmp['##validation.storestatus##'] = $validation['status']; $tmp['##validation.submissiondate##'] = Html::convDateTime($validation['submission_date']); $tmp['##validation.commentsubmission##'] = $validation['comment_submission']; $tmp['##validation.validationdate##'] = Html::convDateTime($validation['validation_date']); $tmp['##validation.validator##'] = Html::clean(getUserName($validation['users_id_validate'])); $tmp['##validation.commentvalidation##'] = $validation['comment_validation']; $datas['validations'][] = $tmp; } // Ticket Satisfaction $inquest = new TicketSatisfaction(); $datas['##satisfaction.type##'] = ''; $datas['##satisfaction.datebegin##'] = ''; $datas['##satisfaction.dateanswered##'] = ''; $datas['##satisfaction.satisfaction##'] = ''; $datas['##satisfaction.description##'] = ''; if ($inquest->getFromDB($item->getField('id'))) { // internal inquest if ($inquest->fields['type'] == 1) { $datas['##ticket.urlsatisfaction##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $item->getField("id") . '_Ticket$3'); // external inquest } else { if ($inquest->fields['type'] == 2) { $datas['##ticket.urlsatisfaction##'] = Entity::generateLinkSatisfaction($item); } } $datas['##satisfaction.type##'] = $inquest->getTypeInquestName($inquest->getfield('type')); $datas['##satisfaction.datebegin##'] = Html::convDateTime($inquest->fields['date_begin']); $datas['##satisfaction.dateanswered##'] = Html::convDateTime($inquest->fields['date_answered']); $datas['##satisfaction.satisfaction##'] = $inquest->fields['satisfaction']; $datas['##satisfaction.description##'] = $inquest->fields['comment']; } } return $datas; }
/** * Get all data needed for template processing **/ function getDatasForTemplate($event, $options = array()) { global $LANG, $CFG_GLPI; //----------- Ticket infos -------------- // if ($event != 'alertnotclosed') { $fields = array('ticket.title' => 'name', 'ticket.content' => 'content', 'ticket.description' => 'content', 'ticket.costfixed' => 'cost_fixed', 'ticket.costmaterial' => 'cost_material'); foreach ($fields as $tag => $table_field) { $this->datas['##' . $tag . '##'] = $this->obj->getField($table_field); } $this->datas['##ticket.id##'] = sprintf("%07d", $this->obj->getField("id")); $this->datas['##ticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id")); $this->datas['##ticket.urlapprove##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_4"); $this->datas['##ticket.urlvalidation##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_7"); $this->datas['##ticket.entity##'] = Dropdown::getDropdownName('glpi_entities', $this->getEntity()); $events = $this->getAllEvents(); if ($event == 'validation' && isset($options['validation_status'])) { $this->datas['##ticket.action##'] = $LANG['validation'][0] . ' - ' . TicketValidation::getStatus($options['validation_status']); } else { $this->datas['##ticket.action##'] = $events[$event]; } $this->datas['##ticket.storestatus##'] = $this->obj->getField('status'); $this->datas['##ticket.status##'] = Ticket::getStatus($this->obj->getField('status')); $this->datas['##ticket.globalvalidation##'] = TicketValidation::getStatus($this->obj->getField('global_validation')); $this->datas['##ticket.type##'] = Ticket::getTicketTypeName($this->obj->getField('type')); $this->datas['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $this->obj->getField('requesttypes_id')); $this->datas['##ticket.urgency##'] = Ticket::getUrgencyName($this->obj->getField('urgency')); $this->datas['##ticket.impact##'] = Ticket::getImpactName($this->obj->getField('impact')); $this->datas['##ticket.priority##'] = Ticket::getPriorityName($this->obj->getField('priority')); $this->datas['##ticket.time##'] = Ticket::getActionTime($this->obj->getField('actiontime')); $this->datas['##ticket.costtime##'] = $this->obj->getField('cost_time'); $this->datas['##ticket.creationdate##'] = convDateTime($this->obj->getField('date')); $this->datas['##ticket.closedate##'] = convDateTime($this->obj->getField('closedate')); $this->datas['##ticket.solvedate##'] = convDateTime($this->obj->getField('solvedate')); $this->datas['##ticket.duedate##'] = convDateTime($this->obj->getField('due_date')); $entitydata = new EntityData(); $autoclose_value = $CFG_GLPI['autoclose_delay']; if ($entitydata->getFromDB($this->getEntity())) { $autoclose_value = $entitydata->getField('autoclose_delay'); // Set global config value if ($autoclose_value == -1) { $autoclose_value = $CFG_GLPI['autoclose_delay']; } } if ($autoclose_value > 0) { $this->datas['##ticket.autoclose##'] = $autoclose_value; $this->datas['##lang.ticket.autoclosewarning##'] = $LANG['job'][54] . " " . $autoclose_value . " " . $LANG['stats'][31]; } else { $this->datas['##ticket.autoclose##'] = $LANG['setup'][307]; $this->datas['##lang.ticket.autoclosewarning##'] = ""; } if ($this->obj->getField('ticketcategories_id')) { $this->datas['##ticket.category##'] = Dropdown::getDropdownName('glpi_ticketcategories', $this->obj->getField('ticketcategories_id')); } else { $this->datas['##ticket.category##'] = ''; } if ($this->obj->getField('slas_id')) { $this->datas['##ticket.sla##'] = Dropdown::getDropdownName('glpi_slas', $this->obj->getField('slas_id')); } else { $this->datas['##ticket.sla##'] = ''; } if ($this->obj->countUsers(Ticket::REQUESTER)) { $users = array(); foreach ($this->obj->getUsers(Ticket::REQUESTER) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); $tmp = array(); $tmp['##author.id##'] = $uid; $tmp['##author.name##'] = $user_tmp->getName(); if ($user_tmp->getField('locations_id')) { $tmp['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id')); } else { $tmp['##author.location##'] = ''; } $tmp['##author.phone##'] = $user_tmp->getField('phone'); $tmp['##author.phone2##'] = $user_tmp->getField('phone2'); $this->datas['authors'][] = $tmp; } $this->datas['##ticket.authors##'] = implode(', ', $users); } else { $this->datas['##ticket.authors##'] = ''; } if ($this->obj->getField('users_id_recipient')) { $user_tmp = new User(); $user_tmp->getFromDB($this->obj->getField('users_id_recipient')); $this->datas['##ticket.openbyuser##'] = $user_tmp->getName(); } else { $this->datas['##ticket.openbyuser##'] = ''; } if ($this->obj->countUsers(Ticket::ASSIGN)) { $users = array(); foreach ($this->obj->getUsers(Ticket::ASSIGN) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $this->datas['##ticket.assigntousers##'] = implode(', ', $users); } else { $this->datas['##ticket.assigntousers##'] = ''; } if ($this->obj->countUsers(Ticket::OBSERVER)) { $users = array(); foreach ($this->obj->getUsers(Ticket::OBSERVER) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $this->datas['##ticket.observerusers##'] = implode(', ', $users); } else { $this->datas['##ticket.observerusers##'] = ''; } if ($this->obj->getField('suppliers_id_assign')) { $this->datas['##ticket.assigntosupplier##'] = Dropdown::getDropdownName('glpi_suppliers', $this->obj->getField('suppliers_id_assign')); } else { $this->datas['##ticket.assigntosupplier##'] = ''; } if ($this->obj->countGroups(Ticket::REQUESTER)) { $groups = array(); foreach ($this->obj->getUsers(Ticket::REQUESTER) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $this->datas['##ticket.groups##'] = implode(', ', $groups); } else { $this->datas['##ticket.groups##'] = ''; } if ($this->obj->countGroups(Ticket::OBSERVER)) { $groups = array(); foreach ($this->obj->getGroups(Ticket::OBSERVER) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $this->datas['##ticket.observergroups##'] = implode(', ', $groups); } else { $this->datas['##ticket.observergroups##'] = ''; } if ($this->obj->countGroups(Ticket::ASSIGN)) { $groups = array(); foreach ($this->obj->getGroups(Ticket::ASSIGN) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $this->datas['##ticket.assigntogroups##'] = implode(', ', $groups); } else { $this->datas['##ticket.assigntogroups##'] = ''; } //Tags associated with the object linked to the ticket if ($this->target_object != null) { //Object type $this->datas['##ticket.itemtype##'] = $this->target_object->getTypeName(); //Object name $this->datas['##ticket.item.name##'] = $this->target_object->getField('name'); //Object serial if ($this->target_object->isField('serial')) { $this->datas['##ticket.item.serial##'] = $this->target_object->getField('serial'); } else { $this->datas['##ticket.item.serial##'] = ''; } //Object contact if ($this->target_object->isField('contact')) { $this->datas['##ticket.item.contact##'] = $this->target_object->getField('contact'); } else { $this->datas['##ticket.item.contact##'] = ''; } //Object contact num if ($this->target_object->isField('contact_num')) { $this->datas['##ticket.item.contactnumber##'] = $this->target_object->getField('contact_num'); } else { $this->datas['##ticket.item.contactnumber##'] = ''; } //Object otherserial if ($this->target_object->isField('otherserial')) { $this->datas['##ticket.item.otherserial##'] = $this->target_object->getField('otherserial'); } else { $this->datas['##ticket.item.otherserial##'] = ''; } //Object location if ($this->target_object->isField('locations_id')) { $this->datas['##ticket.item.location##'] = Dropdown::getDropdownName('glpi_locations', $this->target_object->getField('locations_id')); } else { $this->datas['##ticket.item.location##'] = ''; } //Object user $this->datas['##ticket.item.user##'] = ''; if ($this->obj->getField('users_id')) { $user_tmp = new User(); if ($user_tmp->getFromDB($this->target_object->getField('users_id'))) { $this->datas['##ticket.item.user##'] = $user_tmp->getName(); } } //Object group if ($this->obj->getField('groups_id')) { $this->datas['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $this->target_object->getField('groups_id')); } else { $this->datas['##ticket.item.group##'] = ''; } $modeltable = getSingular($this->getTable()) . "models"; $modelfield = getForeignKeyFieldForTable($modeltable); if ($this->target_object->isField($modelfield)) { $this->datas['##ticket.item.model##'] = $this->target_object->getField($modelfield); } else { $this->datas['##ticket.item.model##'] = ''; } } else { $this->datas['##ticket.itemtype##'] = ''; $this->datas['##ticket.item.name##'] = ''; $this->datas['##ticket.item.serial##'] = ''; $this->datas['##ticket.item.otherserial##'] = ''; $this->datas['##ticket.item.location##'] = ''; } if ($this->obj->getField('ticketsolutiontypes_id')) { $this->datas['##ticket.solution.type##'] = Dropdown::getDropdownName('glpi_ticketsolutiontypes', $this->obj->getField('ticketsolutiontypes_id')); } else { $this->datas['##ticket.solution.type##'] = ''; } $this->datas['##ticket.solution.description##'] = unclean_cross_side_scripting_deep($this->obj->getField('solution')); // Linked tickets $linked_tickets = Ticket_Ticket::getLinkedTicketsTo($this->obj->getField('id')); if (count($linked_tickets)) { $linkedticket = new Ticket(); foreach ($linked_tickets as $data) { if ($linkedticket->getFromDB($data['tickets_id'])) { $tmp = array(); $tmp['##linkedticket.id##'] = $data['tickets_id']; $tmp['##linkedticket.link##'] = Ticket_Ticket::getLinkName($data['link']); $tmp['##linkedticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php" . "?redirect=ticket_" . $data['tickets_id']); $tmp['##linkedticket.title##'] = $linkedticket->getField('name'); $tmp['##linkedticket.content##'] = $linkedticket->getField('content'); $this->datas['linkedtickets'][] = $tmp; } } } if (!empty($this->datas['linkedtickets'])) { $this->datas['##ticket.numberoflinkedtickets##'] = count($this->datas['linkedtickets']); } else { $this->datas['##ticket.numberoflinkedtickets##'] = 0; } $restrict = "`tickets_id`='" . $this->obj->getField('id') . "'"; if (!isset($options['additionnaloption']) || !$options['additionnaloption']) { $restrict .= " AND `is_private` = '0'"; } $restrict .= " ORDER BY `date` DESC, `id` ASC"; //Task infos $tasks = getAllDatasFromTable('glpi_tickettasks', $restrict); foreach ($tasks as $task) { $tmp = array(); $tmp['##task.isprivate##'] = Dropdown::getYesNo($task['is_private']); $tmp['##task.author##'] = html_clean(getUserName($task['users_id'])); $tmp['##task.category##'] = Dropdown::getDropdownName('glpi_taskcategories', $task['taskcategories_id']); $tmp['##task.date##'] = convDateTime($task['date']); $tmp['##task.description##'] = $task['content']; $tmp['##task.time##'] = Ticket::getActionTime($task['actiontime']); $plan = new TicketPlanning(); if ($plan->getFromDBbyTask($task['id'])) { $tmp['##task.planning.user##'] = html_clean(getUserName($plan->fields['users_id'])); $tmp['##task.planning.begin##'] = convDateTime($plan->fields['begin']); $tmp['##task.planning.end##'] = convDateTime($plan->fields['end']); $tmp['##task.planning.status##'] = Planning::getState($plan->fields['state']); } else { $tmp['##task.planning.user##'] = ""; $tmp['##task.planning.begin##'] = ""; $tmp['##task.planning.end##'] = ""; $tmp['##task.planning.status##'] = ""; } $this->datas['tasks'][] = $tmp; } if (!empty($this->datas['tasks'])) { $this->datas['##ticket.numberoftasks##'] = count($this->datas['tasks']); } else { $this->datas['##ticket.numberoftasks##'] = 0; } //Followup infos $followups = getAllDatasFromTable('glpi_ticketfollowups', $restrict); foreach ($followups as $followup) { $tmp = array(); $tmp['##followup.isprivate##'] = Dropdown::getYesNo($followup['is_private']); $tmp['##followup.author##'] = html_clean(getUserName($followup['users_id'])); $tmp['##followup.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $followup['requesttypes_id']); $tmp['##followup.date##'] = convDateTime($followup['date']); $tmp['##followup.description##'] = $followup['content']; $this->datas['followups'][] = $tmp; } if (isset($this->datas['followups'])) { $this->datas['##ticket.numberoffollowups##'] = count($this->datas['followups']); } else { $this->datas['##ticket.numberoffollowups##'] = 0; } //Validation infos $restrict = "`tickets_id`='" . $this->obj->getField('id') . "'"; if (isset($options['validation_id']) && $options['validation_id']) { $restrict .= " AND `glpi_ticketvalidations`.`id` = '" . $options['validation_id'] . "'"; } $restrict .= " ORDER BY `submission_date` DESC, `id` ASC"; $validations = getAllDatasFromTable('glpi_ticketvalidations', $restrict); foreach ($validations as $validation) { $tmp = array(); $tmp['##validation.submission.title##'] = $LANG['validation'][27] . " (" . $LANG['job'][4] . " " . html_clean(getUserName($validation['users_id'])) . ")"; $tmp['##validation.answer.title##'] = $LANG['validation'][32] . " (" . $LANG['validation'][21] . " " . html_clean(getUserName($validation['users_id_validate'])) . ")"; $tmp['##validation.author##'] = html_clean(getUserName($validation['users_id'])); $tmp['##validation.status##'] = TicketValidation::getStatus($validation['status']); $tmp['##validation.storestatus##'] = $validation['status']; $tmp['##validation.submissiondate##'] = convDateTime($validation['submission_date']); $tmp['##validation.commentsubmission##'] = $validation['comment_submission']; $tmp['##validation.validationdate##'] = convDateTime($validation['validation_date']); $tmp['##validation.validator##'] = html_clean(getUserName($validation['users_id_validate'])); $tmp['##validation.commentvalidation##'] = $validation['comment_validation']; $this->datas['validations'][] = $tmp; } // Ticket Satisfaction $inquest = new TicketSatisfaction(); if ($inquest->getFromDB($this->obj->getField('id'))) { // internal inquest if ($inquest->fields['type'] == 1) { $this->datas['##ticket.urlsatisfaction##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_10"); // external inquest } else { if ($inquest->fields['type'] == 2) { $this->datas['##ticket.urlsatisfaction##'] = EntityData::generateLinkSatisfaction($this->obj); } } $this->datas['##satisfaction.type##'] = $inquest->getTypeInquestName($inquest->getfield('type')); $this->datas['##satisfaction.datebegin##'] = convDateTime($inquest->fields['date_begin']); $this->datas['##satisfaction.dateanswered##'] = convDateTime($inquest->fields['date_answered']); $this->datas['##satisfaction.satisfaction##'] = $inquest->fields['satisfaction']; $this->datas['##satisfaction.description##'] = $inquest->fields['comment']; } else { $this->datas['##satisfaction.type##'] = ''; $this->datas['##satisfaction.datebegin##'] = ''; $this->datas['##satisfaction.dateanswered##'] = ''; $this->datas['##satisfaction.satisfaction##'] = ''; $this->datas['##satisfaction.description##'] = ''; } // Use list_limit_max or load the full history ? foreach (Log::getHistoryData($this->obj, 0, $CFG_GLPI['list_limit_max']) as $data) { $tmp = array(); $tmp['##ticket.log.date##'] = $data['date_mod']; $tmp['##ticket.log.user##'] = $data['user_name']; $tmp['##ticket.log.field##'] = $data['field']; $tmp['##ticket.log.content##'] = $data['change']; $this->datas['log'][] = $tmp; } if (isset($this->datas['log'])) { $this->datas['##ticket.numberoflogs##'] = count($this->datas['log']); } else { $this->datas['##ticket.numberoflogs##'] = 0; } } else { if (isset($options['entities_id']) && isset($options['tickets'])) { $this->datas['##ticket.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']); $this->datas['##ticket.action##'] = $LANG['crontask'][15]; $t = new Ticket(); foreach ($options['tickets'] as $ticket) { $tmp = array(); $t->getFromDB($ticket['id']); $tmp['##ticket.id##'] = sprintf("%07d", $ticket['id']); $tmp['##ticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $ticket['id']); $tmp['##ticket.title##'] = $ticket['name']; $tmp['##ticket.status##'] = Ticket::getStatus($ticket['status']); $tmp['##ticket.globalvalidation##'] = TicketValidation::getStatus($ticket['global_validation']); $tmp['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $ticket['requesttypes_id']); $tmp['##ticket.urgency##'] = Ticket::getUrgencyName($ticket['urgency']); $tmp['##ticket.impact##'] = Ticket::getImpactName($ticket['impact']); $tmp['##ticket.priority##'] = Ticket::getPriorityName($ticket['priority']); $tmp['##ticket.time##'] = Ticket::getActionTime($ticket['actiontime']); $tmp['##ticket.costtime##'] = $ticket['cost_time']; $tmp['##ticket.creationdate##'] = convDateTime($ticket['date']); $tmp['##ticket.content##'] = $ticket['content']; if ($t->getField('ticketsolutiontypes_id')) { $tmp['##ticket.solution.type##'] = Dropdown::getDropdownName('glpi_ticketsolutiontypes', $t->getField('ticketsolutiontypes_id')); } else { $this->datas['##ticket.solution.type##'] = ''; } $tmp['##ticket.solution.description##'] = unclean_cross_side_scripting_deep($t->getField('solution')); if ($t->countUsers(Ticket::REQUESTER)) { $users = array(); foreach ($t->getUsers(Ticket::REQUESTER) as $uid => $val) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); $tmp2 = array(); $tmp2['##author.id##'] = $uid; $tmp2['##author.name##'] = $user_tmp->getName(); if ($user_tmp->getField('locations_id')) { $tmp2['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id')); } else { $tmp2['##author.location##'] = ''; } $tmp2['##author.phone##'] = $user_tmp->getField('phone'); $tmp2['##author.phone2##'] = $user_tmp->getField('phone2'); $tmp['authors'][] = $tmp2; } $tmp['##ticket.authors##'] = implode(', ', $users); } else { $tmp['##ticket.authors##'] = ''; } if ($t->countUsers(Ticket::ASSIGN)) { $users = array(); foreach ($t->getUsers(Ticket::ASSIGN) as $uid => $val) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $tmp['##ticket.assigntousers##'] = implode(', ', $users); } else { $tmp['##ticket.assigntousers##'] = ''; } if ($t->countGroups(Ticket::ASSIGN)) { $groups = array(); foreach ($t->getGroups(Ticket::ASSIGN) as $gid => $val) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $tmp['##ticket.assigntogroups##'] = implode(', ', $groups); } else { $tmp['##ticket.assigntogroups##'] = ''; } if ($t->countGroups(Ticket::REQUESTER)) { $groups = array(); foreach ($t->getGroups(Ticket::REQUESTER) as $gid => $val) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $tmp['##ticket.groups##'] = implode(', ', $groups); } else { $tmp['##ticket.groups##'] = ''; } if ($t->countUsers(Ticket::OBSERVER)) { $users = array(); foreach ($t->getUsers(Ticket::OBSERVER) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $tmp['##ticket.observerusers##'] = implode(', ', $users); } else { $tmp['##ticket.observerusers##'] = ''; } if ($t->countGroups(Ticket::OBSERVER)) { $groups = array(); foreach ($t->getGroups(Ticket::OBSERVER) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $tmp['##ticket.observergroups##'] = implode(', ', $groups); } else { $tmp['##ticket.observergroups##'] = ''; } if ($ticket['suppliers_id_assign']) { $tmp['##ticket.assigntosupplier##'] = Dropdown::getDropdownName('glpi_suppliers', $ticket['suppliers_id_assign']); } else { $tmp['##ticket.assigntosupplier##'] = ''; } $this->datas['tickets'][] = $tmp; } } } $this->getTags(); foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { if (!isset($this->datas[$tag])) { $this->datas[$tag] = $values['label']; } } }