예제 #1
0
 /**
  *  Generate ical file content
  *
  * @param $who user ID
  * @param $who_group group ID
  *
  * @return icalendar string
  **/
 static function generateIcal($who, $who_group)
 {
     global $CFG_GLPI, $LANG;
     if ($who == 0 && $who_group == 0) {
         return false;
     }
     include_once GLPI_ROOT . "/lib/icalcreator/iCalcreator.class.php";
     $v = new vcalendar();
     if (!empty($CFG_GLPI["version"])) {
         $v->setConfig('unique_id', "GLPI-Planning-" . trim($CFG_GLPI["version"]));
     } else {
         $v->setConfig('unique_id', "GLPI-Planning-UnknownVersion");
     }
     $v->setConfig('filename', "glpi.ics");
     $v->setProperty("method", "PUBLISH");
     $v->setProperty("version", "2.0");
     $v->setProperty("x-wr-calname", "GLPI-" . $who . "-" . $who_group);
     $v->setProperty("calscale", "GREGORIAN");
     $interv = array();
     $begin = time() - MONTH_TIMESTAMP * 12;
     $end = time() + MONTH_TIMESTAMP * 12;
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     // ---------------Tracking
     $interv = TicketPlanning::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     // ---------------Reminder
     $data = Reminder::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     $interv = array_merge($interv, $data);
     // ---------------Plugin
     $data = doHookFunction("planning_populate", array("begin" => $begin, "end" => $end, "who" => $who, "who_group" => $who_group));
     if (isset($data["items"]) && count($data["items"])) {
         $interv = array_merge($data["items"], $interv);
     }
     if (count($interv) > 0) {
         foreach ($interv as $key => $val) {
             $vevent = new vevent();
             //initiate EVENT
             if (isset($val["tickettasks_id"])) {
                 $vevent->setProperty("uid", "Job#" . $val["tickettasks_id"]);
             } else {
                 if (isset($val["reminders_id"])) {
                     $vevent->setProperty("uid", "Event#" . $val["reminders_id"]);
                 } else {
                     if (isset($val['planningID'])) {
                         // Specify the ID (for plugins)
                         $vevent->setProperty("uid", "Plugin#" . $val['planningID']);
                     } else {
                         $vevent->setProperty("uid", "Plugin#" . $key);
                     }
                 }
             }
             $vevent->setProperty("dstamp", $val["begin"]);
             $vevent->setProperty("dtstart", $val["begin"]);
             $vevent->setProperty("dtend", $val["end"]);
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("summary", $LANG['planning'][8] . " # " . $val["tickets_id"] . " " . $LANG['document'][14] . " # " . $val["device"]);
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("summary", $val["name"]);
                 }
             }
             if (isset($val["content"])) {
                 $vevent->setProperty("description", html_clean($val["content"]));
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("description", $val["name"]);
                 }
             }
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("url", $CFG_GLPI["url_base"] . "/index.php?redirect=tracking_" . $val["tickets_id"]);
             }
             $v->setComponent($vevent);
         }
     }
     $v->sort();
     //$v->parse();
     return $v->returnCalendar();
 }
 /**
  * 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'];
         }
     }
 }
예제 #3
0
 /** form for Task
  *
  * @param $ID Integer : Id of the task
  * @param $options array
  *     -  ticket Object : the ticket
  **/
 function showForm($ID, $options = array())
 {
     global $DB, $LANG, $CFG_GLPI;
     if (isset($options['ticket']) && !empty($options['ticket'])) {
         $ticket = $options['ticket'];
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         // Create item
         $input = array('tickets_id' => $ticket->getField('id'));
         $this->check(-1, 'w', $input);
     }
     $canplan = haveRight("show_planning", "1");
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td rowspan='5' class='middle right'>" . $LANG['joblist'][6] . "&nbsp;:</td>";
     echo "<td class='center middle' rowspan='5'>" . "<textarea name='content' cols='50' rows='6'>" . $this->fields["content"] . "</textarea></td>";
     if ($this->fields["date"]) {
         echo "<td>" . $LANG['common'][27] . "&nbsp;:</td>";
         echo "<td>" . convDateTime($this->fields["date"]);
     } else {
         echo "<td colspan='2'>&nbsp;";
     }
     echo "<input type='hidden' name='tickets_id' value='" . $this->fields["tickets_id"] . "'>";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][36] . "&nbsp;:</td><td>";
     Dropdown::show('TaskCategory', array('value' => $this->fields["taskcategories_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['common'][77] . "&nbsp;:</td>";
     echo "<td><select name='is_private'>";
     echo "<option value='0' " . (!$this->fields["is_private"] ? " selected" : "") . ">" . $LANG['choice'][0] . "</option>";
     echo "<option value='1' " . ($this->fields["is_private"] ? " selected" : "") . ">" . $LANG['choice'][1] . "</option>";
     echo "</select></td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['job'][31] . "&nbsp;:</td><td>";
     $units = getTimestampTimeUnits($this->fields["actiontime"]);
     $hour = $units['hour'] + 24 * $units['day'];
     $minute = $units['minute'];
     Dropdown::showInteger('hour', $hour, 0, 100, 1, array($hour));
     echo "&nbsp;" . $LANG['job'][21] . "&nbsp;&nbsp;";
     Dropdown::showInteger('minute', $minute, 0, 59);
     echo "&nbsp;" . $LANG['job'][22];
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['job'][35] . "</td>";
     echo "<td>";
     $plan = new TicketPlanning();
     $plan->showFormForTask($ticket, $this);
     echo "</td></tr>";
     $this->showFormButtons($options);
     return true;
 }
예제 #4
0
 static function displayPlanningItem($val, $who, $type = "", $complete = 0)
 {
     global $CFG_GLPI, $LANG, $PLUGIN_HOOKS;
     $color = "#e4e4e4";
     if (isset($val["state"])) {
         switch ($val["state"]) {
             case 0:
                 $color = "#efefe7";
                 // Information
                 break;
             case 1:
                 $color = "#fbfbfb";
                 // To be done
                 break;
             case 2:
                 $color = "#e7e7e2";
                 // Done
                 break;
         }
     }
     echo "<div class='item' style='background-color: {$color};'>";
     // Plugins case
     if (isset($val["plugin"]) && isset($PLUGIN_HOOKS['display_planning'][$val["plugin"]])) {
         $function = $PLUGIN_HOOKS['display_planning'][$val["plugin"]];
         if (is_callable($function)) {
             $val["type"] = $type;
             call_user_func($function, $val);
         }
     } else {
         if (isset($val["tickets_id"])) {
             // show tracking
             TicketPlanning::displayPlanningItem($val, $who, $type, $complete);
         } else {
             // show Reminder
             self::reminderDisplayPlanningItem($val, $who, $type, $complete);
         }
     }
     echo "</div>";
 }