/**
  * @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;
 }
 /**
  * Show tickets for a change
  *
  * @param $change Change object
  **/
 static function showForChange(Change $change)
 {
     global $DB, $CFG_GLPI;
     $ID = $change->getField('id');
     if (!$change->can($ID, READ)) {
         return false;
     }
     $canedit = $change->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_changes_tickets`.`id` AS linkID,\n                                `glpi_tickets`.*\n                FROM `glpi_changes_tickets`\n                LEFT JOIN `glpi_tickets`\n                     ON (`glpi_changes_tickets`.`tickets_id` = `glpi_tickets`.`id`)\n                WHERE `glpi_changes_tickets`.`changes_id` = '{$ID}'\n                ORDER BY `glpi_tickets`.`name`";
     $result = $DB->query($query);
     $tickets = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $tickets[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='changeticket_form{$rand}' id='changeticket_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a ticket') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td class='right'>";
         echo "<input type='hidden' name='changes_id' value='{$ID}'>";
         Ticket::dropdown(array('used' => $used, 'entity' => $change->getEntityID(), 'entity_sons' => $change->isRecursive()));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $numrows, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'), __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'solveticket' => __('Solve tickets')), 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('changes_id' => $change->getID()), 'width' => 1000, 'height' => 500);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr class='noHover'><th colspan='12'>" . Ticket::getTypeName($numrows) . "</th>";
     echo "</tr>";
     if ($numrows) {
         Ticket::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
         Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), Change::getTypeName(1), $change->fields["name"]));
         $i = 0;
         foreach ($tickets as $data) {
             Session::addToNavigateListItems('Ticket', $data["id"]);
             Ticket::showShort($data['id'], array('followups' => false, 'row_num' => $i, 'type_for_massiveaction' => __CLASS__, 'id_for_massiveaction' => $data['linkID']));
             $i++;
         }
         Ticket::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Show problems for a change
  *
  * @param $change Change object
  **/
 static function showForChange(Change $change)
 {
     global $DB, $CFG_GLPI;
     $ID = $change->getField('id');
     if (!$change->can($ID, 'r')) {
         return false;
     }
     $canedit = $change->can($ID, 'w');
     $rand = mt_rand();
     $showentities = Session::isMultiEntitiesMode();
     $query = "SELECT DISTINCT `glpi_changes_problems`.`id` AS linkID,\n                                `glpi_problems`.*\n                FROM `glpi_changes_problems`\n                LEFT JOIN `glpi_problems`\n                     ON (`glpi_changes_problems`.`problems_id` = `glpi_problems`.`id`)\n                WHERE `glpi_changes_problems`.`changes_id` = '{$ID}'\n                ORDER BY `glpi_problems`.`name`";
     $result = $DB->query($query);
     $problems = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $problems[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a problem') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>";
         echo "<input type='hidden' name='changes_id' value='{$ID}'>";
         Problem::dropdown(array('used' => $used, 'entity' => $change->getEntityID()));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr></table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $numrows);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr>";
     if ($canedit && $numrows) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . _n('Problem', 'Problems', 2) . "</th>";
     if ($showentities) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "</tr>";
     $used = array();
     if ($numrows) {
         Session::initNavigateListItems('Problem', sprintf(__('%1$s = %2$s'), Change::getTypeName(1), $change->fields["name"]));
         foreach ($problems as $data) {
             Session::addToNavigateListItems('Problem', $data["id"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                 echo "</td>";
             }
             echo "<td><a href='" . Toolbox::getItemTypeFormURL('Problem') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>";
             if ($showentities) {
                 echo "<td>" . Dropdown::getDropdownName('glpi_entities', $data["entities_id"]) . "</td>";
             }
             echo "</tr>";
         }
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Show projects for a change
  *
  * @param $change Change object
  **/
 static function showForChange(Change $change)
 {
     global $DB, $CFG_GLPI;
     $ID = $change->getField('id');
     if (!$change->can($ID, READ)) {
         return false;
     }
     $canedit = $change->canEdit($ID);
     $rand = mt_rand();
     $showentities = Session::isMultiEntitiesMode();
     $query = "SELECT DISTINCT `glpi_changes_projects`.`id` AS linkID,\n                                `glpi_projects`.*\n                FROM `glpi_changes_projects`\n                LEFT JOIN `glpi_projects`\n                     ON (`glpi_changes_projects`.`projects_id` = `glpi_projects`.`id`)\n                WHERE `glpi_changes_projects`.`changes_id` = '{$ID}'\n                ORDER BY `glpi_projects`.`name`";
     $result = $DB->query($query);
     $projects = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $projects[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='changeproject_form{$rand}' id='changeproject_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a project') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>";
         echo "<input type='hidden' name='changes_id' value='{$ID}'>";
         Project::dropdown(array('used' => $used, 'entity' => $change->getEntityID()));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr></table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov table-striped table-hover'>";
     echo "<tr class='noHover'><th colspan='12'>" . Project::getTypeName($numrows) . "</th></tr>";
     if ($numrows) {
         Project::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
         Session::initNavigateListItems('Project', sprintf(__('%1$s = %2$s'), Change::getTypeName(1), $change->fields["name"]));
         $i = 0;
         foreach ($projects as $data) {
             Session::addToNavigateListItems('Project', $data["id"]);
             Project::showShort($data['id'], array('row_num' => $i, 'type_for_massiveaction' => __CLASS__, 'id_for_massiveaction' => $data['linkID']));
             $i++;
         }
         Project::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * @see NotificationTarget::getDatasForTemplate()
  **/
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI, $DB;
     //----------- Reservation infos -------------- //
     $events = $this->getAllEvents();
     $item = $this->obj;
     $this->datas['##project.action##'] = $events[$event];
     $this->datas['##project.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "Project_" . $item->getField("id"));
     $this->datas["##project.name##"] = $item->getField('name');
     $this->datas["##project.code##"] = $item->getField('code');
     $this->datas["##project.description##"] = $item->getField('content');
     $this->datas["##project.comments##"] = $item->getField('comment');
     $this->datas["##project.creationdate##"] = Html::convDateTime($item->getField('date'));
     $this->datas["##project.lastupdatedate##"] = Html::convDateTime($item->getField('date_mod'));
     $this->datas["##project.priority##"] = CommonITILObject::getPriorityName($item->getField('priority'));
     $this->datas["##project.percent##"] = Dropdown::getValueWithUnit($item->getField('percent_done'), "%");
     $this->datas["##project.planstartdate##"] = Html::convDateTime($item->getField('plan_start_date'));
     $this->datas["##project.planenddate##"] = Html::convDateTime($item->getField('plan_end_date'));
     $this->datas["##project.realstartdate##"] = Html::convDateTime($item->getField('real_start_date'));
     $this->datas["##project.realenddate##"] = Html::convDateTime($item->getField('real_end_date'));
     $this->datas["##project.plannedduration##"] = Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($item->getID()), false);
     $this->datas["##project.effectiveduration##"] = Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($item->getID()), false);
     $entity = new Entity();
     $this->datas["##project.entity##"] = '';
     $this->datas["##project.shortentity##"] = '';
     if ($entity->getFromDB($this->getEntity())) {
         $this->datas["##project.entity##"] = $entity->getField('completename');
         $this->datas["##project.shortentity##"] = $entity->getField('name');
     }
     $this->datas["##project.father##"] = '';
     if ($item->getField('projects_id')) {
         $this->datas["##project.father##"] = Dropdown::getDropdownName('glpi_projects', $item->getField('projects_id'));
     }
     $this->datas["##project.state##"] = '';
     if ($item->getField('projectstates_id')) {
         $this->datas["##project.state##"] = Dropdown::getDropdownName('glpi_projectstates', $item->getField('projectstates_id'));
     }
     $this->datas["##project.type##"] = '';
     if ($item->getField('projecttypes_id')) {
         $this->datas["##project.type##"] = Dropdown::getDropdownName('glpi_projecttypes', $item->getField('projecttypes_id'));
     }
     $this->datas["##project.manager##"] = '';
     if ($item->getField('users_id')) {
         $user_tmp = new User();
         $user_tmp->getFromDB($item->getField('users_id'));
         $this->datas["##project.manager##"] = $user_tmp->getName();
     }
     $this->datas["##project.managergroup##"] = '';
     if ($item->getField('groups_id')) {
         $this->datas["##project.managergroup##"] = Dropdown::getDropdownName('glpi_groups', $item->getField('groups_id'));
     }
     // Team infos
     $restrict = "`projects_id` = '" . $item->getField('id') . "'";
     $items = getAllDatasFromTable('glpi_projectteams', $restrict);
     $this->datas['teammembers'] = array();
     if (count($items)) {
         foreach ($items as $data) {
             if ($item2 = getItemForItemtype($data['itemtype'])) {
                 if ($item2->getFromDB($data['items_id'])) {
                     $tmp = array();
                     $tmp['##teammember.itemtype##'] = $item2->getTypeName();
                     $tmp['##teammember.name##'] = $item2->getName();
                     $this->datas['teammembers'][] = $tmp;
                 }
             }
         }
     }
     $this->datas['##project.numberofteammembers##'] = count($this->datas['teammembers']);
     // Task infos
     $restrict = "`projects_id`='" . $item->getField('id') . "'";
     $restrict .= " ORDER BY `date` DESC, `id` ASC";
     $tasks = getAllDatasFromTable('glpi_projecttasks', $restrict);
     $this->datas['tasks'] = array();
     foreach ($tasks as $task) {
         $tmp = array();
         $tmp['##task.creationdate##'] = Html::convDateTime($task['date']);
         $tmp['##task.lastupdatedate##'] = Html::convDateTime($task['date_mod']);
         $tmp['##task.name##'] = $task['name'];
         $tmp['##task.description##'] = $task['content'];
         $tmp['##task.comments##'] = $task['comment'];
         $tmp['##task.state##'] = Dropdown::getDropdownName('glpi_projectstates', $task['projectstates_id']);
         $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_projecttasktypes', $task['projecttasktypes_id']);
         $tmp['##task.percent##'] = Dropdown::getValueWithUnit($task['percent_done'], "%");
         $this->datas["##task.planstartdate##"] = '';
         $this->datas["##task.planenddate##"] = '';
         $this->datas["##task.realstartdate##"] = '';
         $this->datas["##task.realenddate##"] = '';
         if (!is_null($task['plan_start_date'])) {
             $tmp['##task.planstartdate##'] = Html::convDateTime($task['plan_start_date']);
         }
         if (!is_null($task['plan_end_date'])) {
             $tmp['##task.planenddate##'] = Html::convDateTime($task['plan_end_date']);
         }
         if (!is_null($task['real_start_date'])) {
             $tmp['##task.realstartdate##'] = Html::convDateTime($task['real_start_date']);
         }
         if (!is_null($task['real_end_date'])) {
             $tmp['##task.realenddate##'] = Html::convDateTime($task['real_end_date']);
         }
         $this->datas['tasks'][] = $tmp;
     }
     $this->datas["##project.numberoftasks##"] = count($this->datas['tasks']);
     //costs infos
     $restrict = "`projects_id`='" . $item->getField('id') . "'";
     $restrict .= " ORDER BY `begin_date` DESC, `id` ASC";
     $costs = getAllDatasFromTable('glpi_projectcosts', $restrict);
     $this->datas['costs'] = array();
     $this->datas["##project.totalcost##"] = 0;
     foreach ($costs as $cost) {
         $tmp = array();
         $tmp['##cost.name##'] = $cost['name'];
         $tmp['##cost.comment##'] = $cost['comment'];
         $tmp['##cost.datebegin##'] = Html::convDate($cost['begin_date']);
         $tmp['##cost.dateend##'] = Html::convDate($cost['end_date']);
         $tmp['##cost.cost##'] = Html::formatNumber($cost['cost']);
         $tmp['##cost.budget##'] = Dropdown::getDropdownName('glpi_budgets', $cost['budgets_id']);
         $this->datas["##project.totalcost##"] += $cost['cost'];
         $this->datas['costs'][] = $tmp;
         /// TODO add ticket costs ?
     }
     $this->datas["##project.numberofcosts##"] = count($this->datas['costs']);
     // History infos
     $this->datas['log'] = array();
     // Use list_limit_max or load the full history ?
     foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) {
         $tmp = array();
         $tmp["##project.log.date##"] = $data['date_mod'];
         $tmp["##project.log.user##"] = $data['user_name'];
         $tmp["##project.log.field##"] = $data['field'];
         $tmp["##project.log.content##"] = $data['change'];
         $this->datas['log'][] = $tmp;
     }
     $this->datas["##project.numberoflogs##"] = count($this->datas['log']);
     // Changes infos
     $restrict = "`projects_id`='" . $item->getField('id') . "'";
     $changes = getAllDatasFromTable('glpi_changes_projects', $restrict);
     $this->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');
                 $this->datas['changes'][] = $tmp;
             }
         }
     }
     $this->datas['##project.numberofchanges##'] = count($this->datas['changes']);
     // Document
     $query = "SELECT `glpi_documents`.*\n                FROM `glpi_documents`\n                LEFT JOIN `glpi_documents_items`\n                  ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n                WHERE `glpi_documents_items`.`itemtype` =  'Project'\n                      AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'";
     $this->datas["documents"] = array();
     if ($result = $DB->query($query)) {
         while ($data = $DB->fetch_assoc($result)) {
             $tmp = array();
             $tmp['##document.id##'] = $data['id'];
             $tmp['##document.name##'] = $data['name'];
             $tmp['##document.weblink##'] = $data['link'];
             $tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']);
             $downloadurl = "/front/document.send.php?docid=" . $data['id'];
             $tmp['##document.downloadurl##'] = $this->formatURL($options['additionnaloption']['usertype'], $downloadurl);
             $tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']);
             $tmp['##document.filename##'] = $data['filename'];
             $this->datas['documents'][] = $tmp;
         }
     }
     $this->datas["##project.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], "Project_" . $item->getField("id") . '_Document_Item$1');
     $this->datas["##project.numberofdocuments##"] = count($this->datas['documents']);
     // Items infos
     $restrict = "`projects_id` = '" . $item->getField('id') . "'";
     $items = getAllDatasFromTable('glpi_items_projects', $restrict);
     $this->datas['items'] = array();
     if (count($items)) {
         foreach ($items as $data) {
             if ($item2 = getItemForItemtype($data['itemtype'])) {
                 if ($item2->getFromDB($data['items_id'])) {
                     $tmp = array();
                     $tmp['##item.itemtype##'] = $item2->getTypeName();
                     $tmp['##item.name##'] = $item2->getField('name');
                     $tmp['##item.serial##'] = $item2->getField('serial');
                     $tmp['##item.otherserial##'] = $item2->getField('otherserial');
                     $tmp['##item.contact##'] = $item2->getField('contact');
                     $tmp['##item.contactnum##'] = $item2->getField('contactnum');
                     $tmp['##item.location##'] = '';
                     $tmp['##item.user##'] = '';
                     $tmp['##item.group##'] = '';
                     $tmp['##item.model##'] = '';
                     //Object location
                     if ($item2->getField('locations_id') != NOT_AVAILABLE) {
                         $tmp['##item.location##'] = Dropdown::getDropdownName('glpi_locations', $item2->getField('locations_id'));
                     }
                     //Object user
                     if ($item2->getField('users_id')) {
                         $user_tmp = new User();
                         if ($user_tmp->getFromDB($item2->getField('users_id'))) {
                             $tmp['##item.user##'] = $user_tmp->getName();
                         }
                     }
                     //Object group
                     if ($item2->getField('groups_id')) {
                         $tmp['##item.group##'] = Dropdown::getDropdownName('glpi_groups', $item2->getField('groups_id'));
                     }
                     $modeltable = getSingular($item2->getTable()) . "models";
                     $modelfield = getForeignKeyFieldForTable($modeltable);
                     if ($item2->isField($modelfield)) {
                         $tmp['##item.model##'] = $item2->getField($modelfield);
                     }
                     $this->datas['items'][] = $tmp;
                 }
             }
         }
     }
     $this->datas['##project.numberofitems##'] = count($this->datas['items']);
     $this->getTags();
     foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
         if (!isset($this->datas[$tag])) {
             $this->datas[$tag] = $values['label'];
         }
     }
 }
 /**
  * @see NotificationTargetCommonITILObject::getDatasForObject()
  **/
 function getDatasForObject(CommonDBTM $item, array $options, $simple = false)
 {
     global $CFG_GLPI;
     // Common ITIL datas
     $datas = parent::getDatasForObject($item, $options, $simple);
     $datas["##problem.impacts##"] = $item->getField('impactcontent');
     $datas["##problem.causes##"] = $item->getField('causecontent');
     $datas["##problem.symptoms##"] = $item->getField('symptomcontent');
     // Complex mode
     if (!$simple) {
         $restrict = "`problems_id`='" . $item->getField('id') . "'";
         $tickets = getAllDatasFromTable('glpi_problems_tickets', $restrict);
         $datas['tickets'] = array();
         if (count($tickets)) {
             $ticket = new Ticket();
             foreach ($tickets as $data) {
                 if ($ticket->getFromDB($data['tickets_id'])) {
                     $tmp = array();
                     $tmp['##ticket.id##'] = $data['tickets_id'];
                     $tmp['##ticket.date##'] = $ticket->getField('date');
                     $tmp['##ticket.title##'] = $ticket->getField('name');
                     $tmp['##ticket.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "Ticket_" . $data['tickets_id']);
                     $tmp['##ticket.content##'] = $ticket->getField('content');
                     $datas['tickets'][] = $tmp;
                 }
             }
         }
         $datas['##problem.numberoftickets##'] = count($datas['tickets']);
         $restrict = "`problems_id`='" . $item->getField('id') . "'";
         $changes = getAllDatasFromTable('glpi_changes_problems', $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['##problem.numberofchanges##'] = count($datas['changes']);
         $restrict = "`problems_id` = '" . $item->getField('id') . "'";
         $items = getAllDatasFromTable('glpi_items_problems', $restrict);
         $datas['items'] = array();
         if (count($items)) {
             foreach ($items as $data) {
                 if ($item2 = getItemForItemtype($data['itemtype'])) {
                     if ($item2->getFromDB($data['items_id'])) {
                         $tmp = array();
                         $tmp['##item.itemtype##'] = $item2->getTypeName();
                         $tmp['##item.name##'] = $item2->getField('name');
                         $tmp['##item.serial##'] = $item2->getField('serial');
                         $tmp['##item.otherserial##'] = $item2->getField('otherserial');
                         $tmp['##item.contact##'] = $item2->getField('contact');
                         $tmp['##item.contactnum##'] = $item2->getField('contactnum');
                         $tmp['##item.location##'] = '';
                         $tmp['##item.user##'] = '';
                         $tmp['##item.group##'] = '';
                         $tmp['##item.model##'] = '';
                         //Object location
                         if ($item2->getField('locations_id') != NOT_AVAILABLE) {
                             $tmp['##item.location##'] = Dropdown::getDropdownName('glpi_locations', $item2->getField('locations_id'));
                         }
                         //Object user
                         if ($item2->getField('users_id')) {
                             $user_tmp = new User();
                             if ($user_tmp->getFromDB($item2->getField('users_id'))) {
                                 $tmp['##item.user##'] = $user_tmp->getName();
                             }
                         }
                         //Object group
                         if ($item2->getField('groups_id')) {
                             $tmp['##item.group##'] = Dropdown::getDropdownName('glpi_groups', $item2->getField('groups_id'));
                         }
                         $modeltable = getSingular($item2->getTable()) . "models";
                         $modelfield = getForeignKeyFieldForTable($modeltable);
                         if ($item2->isField($modelfield)) {
                             $tmp['##item.model##'] = $item2->getField($modelfield);
                         }
                         $datas['items'][] = $tmp;
                     }
                 }
             }
         }
         $datas['##problem.numberofitems##'] = count($datas['items']);
     }
     return $datas;
 }