示例#1
0
 /**
  * Retrieve last history Data for an item
  *
  * @param $item CommonDBTM object
  * @param $start interger first line to retrieve
  * @param $limit interfer max number of line to retrive (0 for all)
  * @param $sqlfilter string to add an SQL filter
  *
  * @return array of localized log entry (TEXT only, no HTML)
  **/
 static function getHistoryData(CommonDBTM $item, $start = 0, $limit = 0, $sqlfilter = '')
 {
     global $DB, $LANG;
     $itemtype = $item->getType();
     $items_id = $item->getField('id');
     $SEARCHOPTION = Search::getOptions($itemtype);
     $query = "SELECT *\n                FROM `glpi_logs`\n                WHERE `items_id` = '{$items_id}'\n                      AND `itemtype` = '{$itemtype}' ";
     if ($sqlfilter) {
         $query .= "AND ({$sqlfilter}) ";
     }
     $query .= "ORDER BY `id` DESC";
     if ($limit) {
         $query .= " LIMIT " . intval($start) . "," . intval($limit);
     }
     $changes = array();
     foreach ($DB->request($query) as $data) {
         $tmp = array();
         $tmp['display_history'] = true;
         $tmp['id'] = $data["id"];
         $tmp['date_mod'] = convDateTime($data["date_mod"]);
         $tmp['user_name'] = $data["user_name"];
         $tmp['field'] = "";
         $tmp['change'] = "";
         $tmp['datatype'] = "";
         // This is an internal device ?
         if ($data["linked_action"]) {
             // Yes it is an internal device
             switch ($data["linked_action"]) {
                 case HISTORY_CREATE_ITEM:
                     $tmp['change'] = $LANG['log'][20];
                     break;
                 case HISTORY_DELETE_ITEM:
                     $tmp['change'] = $LANG['log'][22];
                     break;
                 case HISTORY_RESTORE_ITEM:
                     $tmp['change'] = $LANG['log'][23];
                     break;
                 case HISTORY_ADD_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['devices'][25] . " : " . "\"" . $data["new_value"] . "\"";
                     break;
                 case HISTORY_UPDATE_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     $change = '';
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                         $specif_fields = $item->getSpecifityLabel();
                         $tmp['change'] = $specif_fields['specificity'] . " : ";
                     }
                     $tmp['change'] .= $data["old_value"] . " --> " . "\"" . $data["new_value"] . "\"";
                     break;
                 case HISTORY_DELETE_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['devices'][26] . " : " . "\"" . $data["old_value"] . "\"";
                     break;
                 case HISTORY_INSTALL_SOFTWARE:
                     $tmp['field'] = $LANG['help'][31];
                     $tmp['change'] = $LANG['software'][44] . " : " . "\"" . $data["new_value"] . "\"";
                     break;
                 case HISTORY_UNINSTALL_SOFTWARE:
                     $tmp['field'] = $LANG['help'][31];
                     $tmp['change'] = $LANG['software'][45] . " : " . "\"" . $data["old_value"] . "\"";
                     break;
                 case HISTORY_DISCONNECT_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['log'][26] . " : " . "\"" . $data["old_value"] . "\"";
                     break;
                 case HISTORY_CONNECT_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['log'][27] . " : " . "\"" . $data["new_value"] . "\"";
                     break;
                 case HISTORY_OCS_IMPORT:
                     if (haveRight("view_ocsng", "r")) {
                         $tmp['field'] = "";
                         $tmp['change'] = $LANG['ocsng'][7] . " " . $LANG['ocsng'][45] . " :";
                         $tmp['change'] .= " " . "\"" . $data["new_value"] . "\"";
                     } else {
                         $tmp['display_history'] = false;
                     }
                     break;
                 case HISTORY_OCS_DELETE:
                     if (haveRight("view_ocsng", "r")) {
                         $tmp['field'] = "";
                         $tmp['change'] = $LANG['ocsng'][46] . " " . $LANG['ocsng'][45] . " :";
                         $tmp['change'] .= " " . "\"" . $data["old_value"] . "\"";
                     } else {
                         $tmp['display_history'] = false;
                     }
                     break;
                 case HISTORY_OCS_LINK:
                     if (haveRight("view_ocsng", "r")) {
                         $tmp['field'] = NOT_AVAILABLE;
                         if (class_exists($data["itemtype_link"])) {
                             $item = new $data["itemtype_link"]();
                             $tmp['field'] = $item->getTypeName();
                         }
                         $tmp['change'] = $LANG['ocsng'][47] . " " . $LANG['ocsng'][45] . " :";
                         $tmp['change'] .= " " . "\"" . $data["new_value"] . "\"";
                     } else {
                         $tmp['display_history'] = false;
                     }
                     break;
                 case HISTORY_OCS_IDCHANGED:
                     if (haveRight("view_ocsng", "r")) {
                         $tmp['field'] = "";
                         $tmp['change'] = $LANG['ocsng'][48] . " " . " : " . "\"" . $data["old_value"] . "\" -->  : " . "\"" . $data["new_value"] . "\"";
                     } else {
                         $tmp['display_history'] = false;
                     }
                     break;
                 case HISTORY_LOG_SIMPLE_MESSAGE:
                     $tmp['field'] = "";
                     $tmp['change'] = $data["new_value"];
                     break;
                 case HISTORY_ADD_RELATION:
                     $tmp['field'] = NOT_AVAILABLE;
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['log'][32] . " : " . "\"" . $data["new_value"] . "\"";
                     break;
                 case HISTORY_DEL_RELATION:
                     $tmp['field'] = NOT_AVAILABLE;
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['log'][33] . " : " . "\"" . $data["old_value"] . "\"";
                     break;
                 case HISTORY_ADD_SUBITEM:
                     $tmp['field'] = '';
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['log'][98] . " : " . $tmp['field'] . " (" . $data["new_value"] . ")";
                     break;
                 case HISTORY_UPDATE_SUBITEM:
                     $tmp['field'] = '';
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['log'][99] . " : " . $tmp['field'] . " (" . $data["new_value"] . ")";
                     break;
                 case HISTORY_DELETE_SUBITEM:
                     $tmp['field'] = '';
                     if (class_exists($data["itemtype_link"])) {
                         $item = new $data["itemtype_link"]();
                         $tmp['field'] = $item->getTypeName();
                     }
                     $tmp['change'] = $LANG['log'][100] . " : " . $tmp['field'] . " (" . $data["old_value"] . ")";
                     break;
             }
         } else {
             $fieldname = "";
             // It's not an internal device
             foreach ($SEARCHOPTION as $key2 => $val2) {
                 if ($key2 == $data["id_search_option"]) {
                     $tmp['field'] = $val2["name"];
                     $fieldname = $val2["field"];
                     if (isset($val2['datatype'])) {
                         $tmp['datatype'] = $val2["datatype"];
                     }
                 }
             }
             switch ($tmp['datatype']) {
                 case "bool":
                     $data["old_value"] = Dropdown::getYesNo($data["old_value"]);
                     $data["new_value"] = Dropdown::getYesNo($data["new_value"]);
                     break;
                 case "datetime":
                     $data["old_value"] = convDateTime($data["old_value"]);
                     $data["new_value"] = convDateTime($data["new_value"]);
                     break;
                 case "date":
                     $data["old_value"] = convDate($data["old_value"]);
                     $data["new_value"] = convDate($data["new_value"]);
                     break;
                 case "timestamp":
                     $data["old_value"] = timestampToString($data["old_value"]);
                     $data["new_value"] = timestampToString($data["new_value"]);
                     break;
                 case "actiontime":
                     $data["old_value"] = Ticket::getActionTime($data["old_value"]);
                     $data["new_value"] = Ticket::getActionTime($data["new_value"]);
                     break;
                 case "number":
                     $data["old_value"] = formatNumber($data["old_value"], false, 0);
                     $data["new_value"] = formatNumber($data["new_value"], false, 0);
                     break;
                 case "decimal":
                     $data["old_value"] = formatNumber($data["old_value"]);
                     $data["new_value"] = formatNumber($data["new_value"]);
                     break;
                 case "right":
                     $data["old_value"] = Profile::getRightValue($data["old_value"]);
                     $data["new_value"] = Profile::getRightValue($data["new_value"]);
                     break;
                 case "text":
                     $tmp['change'] = $LANG['log'][64];
                     break;
             }
             if (empty($tmp['change'])) {
                 $tmp['change'] = "\"" . $data["old_value"] . "\" --> \"" . $data["new_value"] . "\"";
             }
         }
         $changes[] = $tmp;
     }
     return $changes;
 }
示例#2
0
 /**
  * Compute forecast duration
  *
  *@param $ID ID of the project
  *@return text duration of project
  */
 static function getProjectForecast($ID)
 {
     global $DB;
     $query = "SELECT SUM(`actiontime`) \n            FROM `glpi_plugin_projet_tasks` \n            WHERE `plugin_projet_projets_id` = '{$ID}' ";
     if ($result = $DB->query($query)) {
         $sum = $DB->result($result, 0, 0);
         if (is_null($sum)) {
             return '--';
         }
         return Ticket::getActionTime($sum);
     } else {
         return '--';
     }
 }
 /**
  * @param $item            CommonDBTM object
  * @param $options   array
  * @param $simple          (false by default)
  **/
 function getDatasForObject(CommonDBTM $item, array $options, $simple = false)
 {
     global $CFG_GLPI, $DB;
     $objettype = strtolower($item->getType());
     $datas["##{$objettype}.title##"] = $item->getField('name');
     $datas["##{$objettype}.content##"] = $item->getField('content');
     $datas["##{$objettype}.description##"] = $item->getField('content');
     $datas["##{$objettype}.id##"] = sprintf("%07d", $item->getField("id"));
     if ($_SESSION['glpiticket_timeline'] == 1) {
         $datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . '$1');
     } else {
         $datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id"));
     }
     $tab = '$2';
     if ($_SESSION['glpiticket_timeline'] == 1) {
         $tab = '$1';
     }
     $datas["##{$objettype}.urlapprove##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . $tab);
     $entity = new Entity();
     if ($entity->getFromDB($this->getEntity())) {
         $datas["##{$objettype}.entity##"] = $entity->getField('completename');
         $datas["##{$objettype}.shortentity##"] = $entity->getField('name');
     }
     $datas["##{$objettype}.storestatus##"] = $item->getField('status');
     $datas["##{$objettype}.status##"] = $item->getStatus($item->getField('status'));
     $datas["##{$objettype}.urgency##"] = $item->getUrgencyName($item->getField('urgency'));
     $datas["##{$objettype}.impact##"] = $item->getImpactName($item->getField('impact'));
     $datas["##{$objettype}.priority##"] = $item->getPriorityName($item->getField('priority'));
     $datas["##{$objettype}.time##"] = $item->getActionTime($item->getField('actiontime'));
     $datas["##{$objettype}.creationdate##"] = Html::convDateTime($item->getField('date'));
     $datas["##{$objettype}.closedate##"] = Html::convDateTime($item->getField('closedate'));
     $datas["##{$objettype}.solvedate##"] = Html::convDateTime($item->getField('solvedate'));
     $datas["##{$objettype}.duedate##"] = Html::convDateTime($item->getField('due_date'));
     $datas["##{$objettype}.category##"] = '';
     if ($item->getField('itilcategories_id')) {
         $datas["##{$objettype}.category##"] = Dropdown::getDropdownName('glpi_itilcategories', $item->getField('itilcategories_id'));
     }
     $datas["##{$objettype}.authors##"] = '';
     $datas['authors'] = array();
     if ($item->countUsers(CommonITILActor::REQUESTER)) {
         $users = array();
         foreach ($item->getUsers(CommonITILActor::REQUESTER) as $tmpusr) {
             $uid = $tmpusr['users_id'];
             $user_tmp = new User();
             if ($uid && $user_tmp->getFromDB($uid)) {
                 $users[] = $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##'] = '';
                 }
                 if ($user_tmp->getField('usertitles_id')) {
                     $tmp['##author.title##'] = Dropdown::getDropdownName('glpi_usertitles', $user_tmp->getField('usertitles_id'));
                 } else {
                     $tmp['##author.title##'] = '';
                 }
                 if ($user_tmp->getField('usercategories_id')) {
                     $tmp['##author.category##'] = Dropdown::getDropdownName('glpi_usercategories', $user_tmp->getField('usercategories_id'));
                 } else {
                     $tmp['##author.category##'] = '';
                 }
                 $tmp['##author.email##'] = $user_tmp->getDefaultEmail();
                 $tmp['##author.mobile##'] = $user_tmp->getField('mobile');
                 $tmp['##author.phone##'] = $user_tmp->getField('phone');
                 $tmp['##author.phone2##'] = $user_tmp->getField('phone2');
                 $datas['authors'][] = $tmp;
             } else {
                 // Anonymous users only in xxx.authors, not in authors
                 $users[] = $tmpusr['alternative_email'];
             }
         }
         $datas["##{$objettype}.authors##"] = implode(', ', $users);
     }
     $datas["##{$objettype}.openbyuser##"] = '';
     if ($item->getField('users_id_recipient')) {
         $user_tmp = new User();
         $user_tmp->getFromDB($item->getField('users_id_recipient'));
         $datas["##{$objettype}.openbyuser##"] = $user_tmp->getName();
     }
     $datas["##{$objettype}.lastupdater##"] = '';
     if ($item->getField('users_id_lastupdater')) {
         $user_tmp = new User();
         $user_tmp->getFromDB($item->getField('users_id_lastupdater'));
         $datas["##{$objettype}.lastupdater##"] = $user_tmp->getName();
     }
     $datas["##{$objettype}.assigntousers##"] = '';
     if ($item->countUsers(CommonITILActor::ASSIGN)) {
         $users = array();
         foreach ($item->getUsers(CommonITILActor::ASSIGN) as $tmp) {
             $uid = $tmp['users_id'];
             $user_tmp = new User();
             if ($user_tmp->getFromDB($uid)) {
                 $users[$uid] = $user_tmp->getName();
             }
         }
         $datas["##{$objettype}.assigntousers##"] = implode(', ', $users);
     }
     $datas["##{$objettype}.assigntosupplier##"] = '';
     if ($item->countSuppliers(CommonITILActor::ASSIGN)) {
         $suppliers = array();
         foreach ($item->getSuppliers(CommonITILActor::ASSIGN) as $tmp) {
             $uid = $tmp['suppliers_id'];
             $supplier_tmp = new Supplier();
             if ($supplier_tmp->getFromDB($uid)) {
                 $suppliers[$uid] = $supplier_tmp->getName();
             }
         }
         $datas["##{$objettype}.assigntosupplier##"] = implode(', ', $suppliers);
     }
     $datas["##{$objettype}.groups##"] = '';
     if ($item->countGroups(CommonITILActor::REQUESTER)) {
         $groups = array();
         foreach ($item->getGroups(CommonITILActor::REQUESTER) as $tmp) {
             $gid = $tmp['groups_id'];
             $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
         }
         $datas["##{$objettype}.groups##"] = implode(', ', $groups);
     }
     $datas["##{$objettype}.observergroups##"] = '';
     if ($item->countGroups(CommonITILActor::OBSERVER)) {
         $groups = array();
         foreach ($item->getGroups(CommonITILActor::OBSERVER) as $tmp) {
             $gid = $tmp['groups_id'];
             $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
         }
         $datas["##{$objettype}.observergroups##"] = implode(', ', $groups);
     }
     $datas["##{$objettype}.observerusers##"] = '';
     if ($item->countUsers(CommonITILActor::OBSERVER)) {
         $users = array();
         foreach ($item->getUsers(CommonITILActor::OBSERVER) as $tmp) {
             $uid = $tmp['users_id'];
             $user_tmp = new User();
             if ($uid && $user_tmp->getFromDB($uid)) {
                 $users[] = $user_tmp->getName();
             } else {
                 $users[] = $tmp['alternative_email'];
             }
         }
         $datas["##{$objettype}.observerusers##"] = implode(', ', $users);
     }
     $datas["##{$objettype}.assigntogroups##"] = '';
     if ($item->countGroups(CommonITILActor::ASSIGN)) {
         $groups = array();
         foreach ($item->getGroups(CommonITILActor::ASSIGN) as $tmp) {
             $gid = $tmp['groups_id'];
             $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
         }
         $datas["##{$objettype}.assigntogroups##"] = implode(', ', $groups);
     }
     $datas["##{$objettype}.solution.type##"] = '';
     if ($item->getField('solutiontypes_id')) {
         $datas["##{$objettype}.solution.type##"] = Dropdown::getDropdownName('glpi_solutiontypes', $item->getField('solutiontypes_id'));
     }
     $datas["##{$objettype}.solution.description##"] = Toolbox::unclean_cross_side_scripting_deep($item->getField('solution'));
     // Complex mode
     if (!$simple) {
         $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["##{$objettype}.log.date##"] = $data['date_mod'];
             $tmp["##{$objettype}.log.user##"] = $data['user_name'];
             $tmp["##{$objettype}.log.field##"] = $data['field'];
             $tmp["##{$objettype}.log.content##"] = $data['change'];
             $datas['log'][] = $tmp;
         }
         $datas["##{$objettype}.numberoflogs##"] = count($datas['log']);
         // Get unresolved items
         $restrict = "`" . $item->getTable() . "`.`status`\n                        NOT IN ('" . implode("', '", array_merge($item->getSolvedStatusArray(), $item->getClosedStatusArray())) . "'\n                               )";
         if ($item->maybeDeleted()) {
             $restrict .= " AND `" . $item->getTable() . "`.`is_deleted` = '0' ";
         }
         $datas["##{$objettype}.numberofunresolved##"] = countElementsInTableForEntity($item->getTable(), $this->getEntity(), $restrict);
         // 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` =  '" . $item->getType() . "'\n                         AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'";
         $datas["documents"] = array();
         $addtodownloadurl = '';
         if ($item->getType() == 'Ticket') {
             $addtodownloadurl = "%2526tickets_id=" . $item->fields['id'];
         }
         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 . $addtodownloadurl);
                 $tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']);
                 $tmp['##document.filename##'] = $data['filename'];
                 $datas['documents'][] = $tmp;
             }
         }
         $datas["##{$objettype}.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . '_Document_Item$1');
         $datas["##{$objettype}.numberofdocuments##"] = count($datas['documents']);
         //costs infos
         $costtype = $item->getType() . 'Cost';
         $costs = $costtype::getCostsSummary($costtype, $item->getField("id"));
         $datas["##{$objettype}.costfixed##"] = $costs['costfixed'];
         $datas["##{$objettype}.costmaterial##"] = $costs['costmaterial'];
         $datas["##{$objettype}.costtime##"] = $costs['costtime'];
         $datas["##{$objettype}.totalcost##"] = $costs['totalcost'];
         $restrict = "`" . $item->getForeignKeyField() . "`='" . $item->getField('id') . "'";
         $restrict .= " ORDER BY `begin_date` DESC, `id` ASC";
         $costs = getAllDatasFromTable(getTableForItemType($costtype), $restrict);
         $datas['costs'] = array();
         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.time##'] = $item->getActionTime($cost['actiontime']);
             $tmp['##cost.costtime##'] = Html::formatNumber($cost['cost_time']);
             $tmp['##cost.costfixed##'] = Html::formatNumber($cost['cost_fixed']);
             $tmp['##cost.costmaterial##'] = Html::formatNumber($cost['cost_material']);
             $tmp['##cost.totalcost##'] = CommonITILCost::computeTotalCost($cost['actiontime'], $cost['cost_time'], $cost['cost_fixed'], $cost['cost_material']);
             $tmp['##cost.budget##'] = Dropdown::getDropdownName('glpi_budgets', $cost['budgets_id']);
             $datas['costs'][] = $tmp;
         }
         $datas["##{$objettype}.numberofcosts##"] = count($datas['costs']);
         //Task infos
         $tasktype = $item->getType() . 'Task';
         $taskobj = new $tasktype();
         $restrict = "`" . $item->getForeignKeyField() . "`='" . $item->getField('id') . "'";
         if ($taskobj->maybePrivate() && (!isset($options['additionnaloption']['show_private']) || !$options['additionnaloption']['show_private'])) {
             $restrict .= " AND `is_private` = '0'";
         }
         $restrict .= " ORDER BY `date` DESC, `id` ASC";
         $tasks = getAllDatasFromTable($taskobj->getTable(), $restrict);
         $datas['tasks'] = array();
         foreach ($tasks as $task) {
             $tmp = array();
             $tmp['##task.id##'] = $task['id'];
             if ($taskobj->maybePrivate()) {
                 $tmp['##task.isprivate##'] = Dropdown::getYesNo($task['is_private']);
             }
             $tmp['##task.author##'] = Html::clean(getUserName($task['users_id']));
             $tmp_taskcatinfo = Dropdown::getDropdownName('glpi_taskcategories', $task['taskcategories_id'], true, true, false);
             $tmp['##task.categoryid##'] = $task['taskcategories_id'];
             $tmp['##task.category##'] = $tmp_taskcatinfo['name'];
             $tmp['##task.categorycomment##'] = $tmp_taskcatinfo['comment'];
             $tmp['##task.date##'] = Html::convDateTime($task['date']);
             $tmp['##task.description##'] = $task['content'];
             $tmp['##task.time##'] = Ticket::getActionTime($task['actiontime']);
             $tmp['##task.status##'] = Planning::getState($task['state']);
             $tmp['##task.user##'] = Html::clean(getUserName($task['users_id_tech']));
             $tmp['##task.group##'] = Html::clean(Toolbox::clean_cross_side_scripting_deep(Dropdown::getDropdownName("glpi_groups", $task['groups_id_tech'])), true, 2, false);
             $tmp['##task.begin##'] = "";
             $tmp['##task.end##'] = "";
             if (!is_null($task['begin'])) {
                 $tmp['##task.begin##'] = Html::convDateTime($task['begin']);
                 $tmp['##task.end##'] = Html::convDateTime($task['end']);
             }
             $datas['tasks'][] = $tmp;
         }
         $datas["##{$objettype}.numberoftasks##"] = count($datas['tasks']);
     }
     return $datas;
 }
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI, $DB;
     if ($event == 'AlertExpiredTasks') {
         $this->datas['##projet.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
         $this->datas['##lang.projet.entity##'] = __('Entity');
         $this->datas['##projet.action##'] = __('Outdated tasks', 'projet');
         $this->datas['##lang.task.name##'] = __('Name');
         $this->datas['##lang.task.type##'] = __('Type');
         $this->datas['##lang.task.users##'] = __('User');
         $this->datas['##lang.task.groups##'] = __('Group');
         $this->datas['##lang.task.datebegin##'] = __('Start date');
         $this->datas['##lang.task.dateend##'] = __('End date');
         $this->datas['##lang.task.planned##'] = __('Used for planning', 'projet');
         $this->datas['##lang.task.realtime##'] = __('Effective duration', 'projet');
         $this->datas['##lang.task.comment##'] = __('Comments');
         $this->datas['##lang.task.projet##'] = PluginProjetProjet::getTypeName(1);
         foreach ($options['tasks'] as $id => $task) {
             $tmp = array();
             $tmp['##task.name##'] = $task['name'];
             $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_plugin_projet_tasktypes', $task['plugin_projet_tasktypes_id']);
             $tmp['##task.users##'] = Html::clean(getUserName($task['users_id']));
             $tmp['##task.groups##'] = Dropdown::getDropdownName('glpi_groups', $task['groups_id']);
             $restrict = " `plugin_projet_tasks_id` = '" . $task['id'] . "' ";
             $plans = getAllDatasFromTable("glpi_plugin_projet_taskplannings", $restrict);
             if (!empty($plans)) {
                 foreach ($plans as $plan) {
                     $tmp['##task.datebegin##'] = Html::convDateTime($plan["begin"]);
                     $tmp['##task.dateend##'] = Html::convDateTime($plan["end"]);
                 }
             } else {
                 $tmp['##task.datebegin##'] = '';
                 $tmp['##task.dateend##'] = '';
             }
             $tmp['##task.planned##'] = '';
             $tmp['##task.realtime##'] = Ticket::getActionTime($task["actiontime"]);
             $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['comment']));
             $tmp['##task.comment##'] = Html::clean($comment);
             $tmp['##task.projet##'] = Dropdown::getDropdownName('glpi_plugin_projet_projets', $task['plugin_projet_projets_id']);
             $this->datas['tasks'][] = $tmp;
         }
     } else {
         $events = $this->getAllEvents();
         $this->datas['##lang.projet.title##'] = $events[$event];
         $this->datas['##lang.projet.entity##'] = __('Entity');
         $this->datas['##projet.entity##'] = Dropdown::getDropdownName('glpi_entities', $this->obj->getField('entities_id'));
         $this->datas['##projet.id##'] = $this->obj->getField("id");
         $this->datas['##lang.projet.name##'] = __('Name');
         $this->datas['##projet.name##'] = $this->obj->getField("name");
         $this->datas['##lang.projet.datebegin##'] = __('Start date');
         $this->datas['##projet.datebegin##'] = Html::convDate($this->obj->getField('date_begin'));
         $this->datas['##lang.projet.dateend##'] = __('End date');
         $this->datas['##projet.dateend##'] = Html::convDate($this->obj->getField('date_end'));
         $this->datas['##lang.projet.users##'] = __('User');
         $this->datas['##projet.users##'] = Html::clean(getUserName($this->obj->getField("users_id")));
         $this->datas['##lang.projet.groups##'] = __('Group');
         $this->datas['##projet.groups##'] = Dropdown::getDropdownName('glpi_groups', $this->obj->getField('groups_id'));
         $this->datas['##lang.projet.status##'] = __('State');
         $this->datas['##projet.status##'] = Dropdown::getDropdownName('glpi_plugin_projet_projetstates', $this->obj->getField('plugin_projet_projetstates_id'));
         $this->datas['##lang.projet.parent##'] = __('Parent project', 'projet');
         $this->datas['##projet.parent##'] = PluginProjetProjet_Projet::displayLinkedProjetsTo($this->obj->getField('id'), true);
         $this->datas['##lang.projet.advance##'] = __('Progress');
         $this->datas['##projet.advance##'] = PluginProjetProjet::displayProgressBar('100', $this->obj->getField('advance'), array('simple' => true));
         $this->datas['##lang.projet.gantt##'] = __('Display on the global Gantt', 'projet');
         $this->datas['##projet.gantt##'] = Dropdown::getYesNo($this->obj->getField('show_gantt'));
         $this->datas['##lang.projet.comment##'] = __('Comments');
         $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->obj->getField("comment")));
         $this->datas['##projet.comment##'] = Html::clean($comment);
         $this->datas['##lang.projet.description##'] = __('Description');
         $description = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->obj->getField("description")));
         $this->datas['##projet.description##'] = Html::clean($description);
         $this->datas['##lang.projet.helpdesk##'] = __('Associable to a ticket');
         $this->datas['##projet.helpdesk##'] = Dropdown::getYesNo($this->obj->getField('is_helpdesk_visible'));
         $this->datas['##lang.projet.url##'] = __('URL');
         $this->datas['##projet.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_projet_" . $this->obj->getField("id"));
         //old values infos
         if (isset($this->target_object->oldvalues) && !empty($this->target_object->oldvalues) && $event == 'update') {
             $this->datas['##lang.update.title##'] = __('Modifications', 'projet');
             $tmp = array();
             if (isset($this->target_object->oldvalues['name'])) {
                 if (empty($this->target_object->oldvalues['name'])) {
                     $tmp['##update.name##'] = "---";
                 } else {
                     $tmp['##update.name##'] = $this->target_object->oldvalues['name'];
                 }
             }
             if (isset($this->target_object->oldvalues['date_begin'])) {
                 if (empty($this->target_object->oldvalues['date_begin'])) {
                     $tmp['##update.datebegin##'] = "---";
                 } else {
                     $tmp['##update.datebegin##'] = Html::convDate($this->target_object->oldvalues['date_begin']);
                 }
             }
             if (isset($this->target_object->oldvalues['date_end'])) {
                 if (empty($this->target_object->oldvalues['date_end'])) {
                     $tmp['##update.dateend##'] = "---";
                 } else {
                     $tmp['##update.dateend##'] = Html::convDate($this->target_object->oldvalues['date_end']);
                 }
             }
             if (isset($this->target_object->oldvalues['users_id'])) {
                 if (empty($this->target_object->oldvalues['users_id'])) {
                     $tmp['##update.users##'] = "---";
                 } else {
                     $tmp['##update.users##'] = Html::clean(getUserName($this->target_object->oldvalues['users_id']));
                 }
             }
             if (isset($this->target_object->oldvalues['groups_id'])) {
                 if (empty($this->target_object->oldvalues['groups_id'])) {
                     $tmp['##update.groups##'] = "---";
                 } else {
                     $tmp['##update.groups##'] = Dropdown::getDropdownName('glpi_groups', $this->target_object->oldvalues['groups_id']);
                 }
             }
             if (isset($this->target_object->oldvalues['plugin_projet_projetstates_id'])) {
                 if (empty($this->target_object->oldvalues['plugin_projet_projetstates_id'])) {
                     $tmp['##update.status##'] = "---";
                 } else {
                     $tmp['##update.status##'] = Dropdown::getDropdownName('glpi_plugin_projet_projetstates', $this->target_object->oldvalues['plugin_projet_projetstates_id']);
                 }
             }
             if (isset($this->target_object->oldvalues['plugin_projet_projets_id'])) {
                 if (empty($this->target_object->oldvalues['plugin_projet_projets_id'])) {
                     $tmp['##update.plugin_projet_projets_id##'] = "---";
                 } else {
                     $tmp['##update.plugin_projet_projets_id##'] = Dropdown::getDropdownName('glpi_plugin_projet_projets', $this->target_object->oldvalues['plugin_projet_projets_id']);
                 }
             }
             if (isset($this->target_object->oldvalues['advance'])) {
                 if (empty($this->target_object->oldvalues['advance'])) {
                     $tmp['##update.advance##'] = "---";
                 } else {
                     $tmp['##update.advance##'] = PluginProjetProjet::displayProgressBar('100', $this->target_object->oldvalues['advance'], array('simple' => true));
                 }
             }
             if (isset($this->target_object->oldvalues['comment'])) {
                 if (empty($this->target_object->oldvalues['comment'])) {
                     $tmp['##update.comment##'] = "---";
                 } else {
                     $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->target_object->oldvalues['comment']));
                     $tmp['##update.comment##'] = Html::clean($comment);
                 }
             }
             if (isset($this->target_object->oldvalues['description'])) {
                 if (empty($this->target_object->oldvalues['description'])) {
                     $tmp['##update.description##'] = "---";
                 } else {
                     $description = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->target_object->oldvalues['description']));
                     $tmp['##update.description##'] = Html::clean($description);
                 }
             }
             if (isset($this->target_object->oldvalues['show_gantt'])) {
                 if (empty($this->target_object->oldvalues['show_gantt'])) {
                     $tmp['##update.gantt##'] = "---";
                 } else {
                     $tmp['##update.gantt##'] = Dropdown::getYesNo($this->target_object->oldvalues['show_gantt']);
                 }
             }
             if (isset($this->target_object->oldvalues['is_helpdesk_visible'])) {
                 if (empty($this->target_object->oldvalues['is_helpdesk_visible'])) {
                     $tmp['##update.helpdesk##'] = "---";
                 } else {
                     $tmp['##update.helpdesk##'] = Dropdown::getYesNo($this->target_object->oldvalues['is_helpdesk_visible']);
                 }
             }
             $this->datas['updates'][] = $tmp;
         }
         // Projet followup
         $restrict = "`plugin_projet_projets_id`='" . $this->obj->getField('id') . "'";
         if (isset($options['followups_id']) && $options['followups_id']) {
             $restrict .= " AND `glpi_plugin_projet_followups`.`id` = '" . $options['followups_id'] . "'";
         }
         $restrict .= " ORDER BY `date` DESC";
         $followups = getAllDatasFromTable('glpi_plugin_projet_followups', $restrict);
         $this->datas['##lang.followup.description##'] = __('Content');
         $this->datas['##lang.followup.date##'] = __('Date');
         $this->datas['##lang.followup.recipient##'] = __('Writer');
         if (!empty($followups)) {
             $this->datas['##lang.followup.title##'] = _n('Associated followup', 'Associated followups', 2, 'projet');
             foreach ($followups as $followup) {
                 $tmp = array();
                 $tmp['##followup.recipient##'] = Html::clean(getUserName($followup['users_id']));
                 $tmp['##followup.date##'] = Html::convDate($followup['date']);
                 $content = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $followup['content']));
                 $tmp['##followup.description##'] = Html::clean($content);
                 $this->datas['followups'][] = $tmp;
             }
         }
         //task infos
         $restrict = "`plugin_projet_projets_id`='" . $this->obj->getField('id') . "'";
         if (isset($options['tasks_id']) && $options['tasks_id']) {
             $restrict .= " AND `glpi_plugin_projet_tasks`.`id` = '" . $options['tasks_id'] . "'";
         }
         $restrict .= " ORDER BY `name` DESC";
         $tasks = getAllDatasFromTable('glpi_plugin_projet_tasks', $restrict);
         $this->datas['##lang.task.title##'] = _n('Associated task', 'Associated tasks', 2, 'projet');
         $this->datas['##lang.task.name##'] = __('Name');
         $this->datas['##lang.task.users##'] = __('User');
         $this->datas['##lang.task.groups##'] = __('Group');
         $this->datas['##lang.task.contacts##'] = __('Supplier');
         $this->datas['##lang.task.type##'] = __('Type');
         $this->datas['##lang.task.status##'] = __('State');
         $this->datas['##lang.task.advance##'] = __('Progress');
         $this->datas['##lang.task.priority##'] = __('Priority');
         $this->datas['##lang.task.comment##'] = __('Comments');
         $this->datas['##lang.task.sub##'] = __('Results');
         $this->datas['##lang.task.others##'] = __('Others participants', 'projet');
         $this->datas['##lang.task.affect##'] = __('Affected people', 'projet');
         $this->datas['##lang.task.parenttask##'] = __('Parent task', 'projet');
         $this->datas['##lang.task.gantt##'] = __('Display on the Gantt', 'projet');
         $this->datas['##lang.task.depends##'] = __('Dependent', 'projet');
         $this->datas['##lang.task.realtime##'] = __('Effective duration', 'projet');
         $this->datas['##lang.task.location##'] = __('Location');
         $this->datas['##lang.task.projet##'] = _n('Project', 'Projects', 2, 'projet');
         if (!empty($tasks)) {
             $this->datas['##task.title##'] = _n('Associated task', 'Associated tasks', 2, 'projet');
             foreach ($tasks as $task) {
                 $tmp = array();
                 $tmp['##task.name##'] = $task['name'];
                 $tmp['##task.users##'] = Html::clean(getUserName($task['users_id']));
                 $tmp['##task.groups##'] = Dropdown::getDropdownName('glpi_groups', $task['groups_id']);
                 $tmp['##task.contacts##'] = Dropdown::getDropdownName('glpi_contacts', $task['contacts_id']);
                 $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_plugin_projet_tasktypes', $task['plugin_projet_tasktypes_id']);
                 $tmp['##task.status##'] = Dropdown::getDropdownName('glpi_plugin_projet_taskstates', $task['plugin_projet_taskstates_id']);
                 $tmp['##task.advance##'] = PluginProjetProjet::displayProgressBar('100', $task['advance'], array('simple' => true));
                 $tmp['##task.priority##'] = Ticket::getPriorityName($task['priority']);
                 $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['comment']));
                 $tmp['##task.comment##'] = Html::clean($comment);
                 $sub = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['sub']));
                 $tmp['##task.sub##'] = Html::clean($sub);
                 $others = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['others']));
                 $tmp['##task.others##'] = Html::clean($others);
                 $affect = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['affect']));
                 $tmp['##task.affect##'] = Html::clean($affect);
                 $tmp['##task.parenttask##'] = PluginProjetTask_Task::displayLinkedProjetTasksTo($task['id'], true);
                 $tmp['##task.gantt##'] = Dropdown::getYesNo($task['show_gantt']);
                 $tmp['##task.depends##'] = Dropdown::getYesNo($task['depends']);
                 $tmp['##task.realtime##'] = Ticket::getActionTime($task["actiontime"]);
                 $tmp['##task.location##'] = Dropdown::getDropdownName('glpi_locations', $task['locations_id']);
                 $tmp['##task.projet##'] = Dropdown::getDropdownName('glpi_plugin_projet_projets', $task['plugin_projet_projets_id']);
                 $this->datas['tasks'][] = $tmp;
             }
         }
     }
 }
 /**
  * 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'];
         }
     }
 }
 /**
  * @see NotificationTargetCommonITILObject::getDatasForObject()
  **/
 function getDatasForObject(CommonDBTM $item, array $options, $simple = false)
 {
     global $CFG_GLPI, $DB;
     // Common ITIL datas
     $datas = parent::getDatasForObject($item, $options, $simple);
     // Specific datas
     $costs = TicketCost::getCostsSummary($item->getField("id"));
     $datas["##ticket.costfixed##"] = $costs['costfixed'];
     $datas["##ticket.costmaterial##"] = $costs['costmaterial'];
     $datas["##ticket.costtime##"] = $costs['costtime'];
     $datas["##ticket.totalcost##"] = $costs['totalcost'];
     $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##'] = '';
     if (isset($item->fields['itemtype']) && ($hardware = getItemForItemtype($item->fields['itemtype'])) && isset($item->fields["items_id"]) && $hardware->getFromDB($item->fields["items_id"])) {
         //Object type
         $datas['##ticket.itemtype##'] = $hardware->getTypeName();
         //Object name
         $datas['##ticket.item.name##'] = $hardware->getField('name');
         //Object serial
         if ($hardware->isField('serial')) {
             $datas['##ticket.item.serial##'] = $hardware->getField('serial');
         }
         //Object contact
         if ($hardware->isField('contact')) {
             $datas['##ticket.item.contact##'] = $hardware->getField('contact');
         }
         //Object contact num
         if ($hardware->isField('contact_num')) {
             $datas['##ticket.item.contactnumber##'] = $hardware->getField('contact_num');
         }
         //Object otherserial
         if ($hardware->isField('otherserial')) {
             $datas['##ticket.item.otherserial##'] = $hardware->getField('otherserial');
         }
         //Object location
         if ($hardware->isField('locations_id')) {
             $datas['##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'))) {
                 $datas['##ticket.item.user##'] = $user_tmp->getName();
             }
         }
         //Object group
         if ($hardware->getField('groups_id')) {
             $datas['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $hardware->getField('groups_id'));
         }
         $modeltable = getSingular($hardware->getTable()) . "models";
         $modelfield = getForeignKeyFieldForTable($modeltable);
         if ($hardware->isField($modelfield)) {
             $datas['##ticket.item.model##'] = Dropdown::getDropdownName($modeltable, $hardware->getField($modelfield));
         }
     }
     // Get tasks, 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') . "'";
         if (!isset($options['additionnaloption']['show_private']) || !$options['additionnaloption']['show_private']) {
             $restrict .= " AND `is_private` = '0'";
         }
         $restrict .= " ORDER BY `date` DESC, `id` ASC";
         //Task infos
         $tasks = getAllDatasFromTable('glpi_tickettasks', $restrict);
         $datas['tasks'] = array();
         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##'] = Html::convDateTime($task['date']);
             $tmp['##task.description##'] = $task['content'];
             $tmp['##task.time##'] = Ticket::getActionTime($task['actiontime']);
             $tmp['##task.status##'] = Planning::getState($task['state']);
             $tmp['##task.user##'] = "";
             $tmp['##task.begin##'] = "";
             $tmp['##task.end##'] = "";
             if (!is_null($task['begin'])) {
                 $tmp['##task.user##'] = Html::clean(getUserName($task['users_id_tech']));
                 $tmp['##task.begin##'] = Html::convDateTime($task['begin']);
                 $tmp['##task.end##'] = Html::convDateTime($task['end']);
             }
             $datas['tasks'][] = $tmp;
         }
         $datas['##ticket.numberoftasks##'] = count($datas['tasks']);
         //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']);
         //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'];
         }
         //costs infos
         $restrict = "`tickets_id`='" . $item->getField('id') . "'";
         $restrict .= " ORDER BY `begin_date` DESC, `id` ASC";
         $costs = getAllDatasFromTable('glpi_ticketcosts', $restrict);
         $datas['costs'] = array();
         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.time##'] = $item->getActionTime($cost['actiontime']);
             $tmp['##cost.costtime##'] = Html::formatNumber($cost['cost_time']);
             $tmp['##cost.costfixed##'] = Html::formatNumber($cost['cost_fixed']);
             $tmp['##cost.costmaterial##'] = Html::formatNumber($cost['cost_material']);
             $tmp['##cost.totalcost##'] = TicketCost::computeTotalCost($cost['actiontime'], $cost['cost_time'], $cost['cost_fixed'], $cost['cost_material']);
             $tmp['##cost.budget##'] = Dropdown::getDropdownName('glpi_budgets', $cost['budgets_id']);
             $datas['costs'][] = $tmp;
         }
     }
     return $datas;
 }
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI, $DB;
     if ($event == 'AlertExpiredTasks') {
         $this->datas['##resource.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
         $this->datas['##lang.resource.entity##'] = __('Entity');
         $this->datas['##resource.action##'] = __('List of not finished tasks', 'resources');
         $this->datas['##lang.task.name##'] = __('Name');
         $this->datas['##lang.task.type##'] = __('Type');
         $this->datas['##lang.task.users##'] = __('Technician');
         $this->datas['##lang.task.groups##'] = __('Group');
         $this->datas['##lang.task.datebegin##'] = __('Begin date');
         $this->datas['##lang.task.dateend##'] = __('End date');
         $this->datas['##lang.task.planned##'] = __('Used for planning', 'resources');
         $this->datas['##lang.task.realtime##'] = __('Effective duration', 'resources');
         $this->datas['##lang.task.finished##'] = __('Carried out task', 'resources');
         $this->datas['##lang.task.comment##'] = __('Comments');
         $this->datas['##lang.task.resource##'] = PluginResourcesResource::getTypeName(1);
         foreach ($options['tasks'] as $id => $task) {
             $tmp = array();
             $tmp['##task.name##'] = $task['name'];
             $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_plugin_resources_tasktypes', $task['plugin_resources_tasktypes_id']);
             $tmp['##task.users##'] = Html::clean(getUserName($task['users_id']));
             $tmp['##task.groups##'] = Dropdown::getDropdownName('glpi_groups', $task['groups_id']);
             $restrict = " `plugin_resources_tasks_id` = '" . $task['id'] . "' ";
             $plans = getAllDatasFromTable("glpi_plugin_resources_taskplannings", $restrict);
             if (!empty($plans)) {
                 foreach ($plans as $plan) {
                     $tmp['##task.datebegin##'] = Html::convDateTime($plan["begin"]);
                     $tmp['##task.dateend##'] = Html::convDateTime($plan["end"]);
                 }
             } else {
                 $tmp['##task.datebegin##'] = '';
                 $tmp['##task.dateend##'] = '';
             }
             $tmp['##task.planned##'] = '';
             $tmp['##task.finished##'] = Dropdown::getYesNo($task['is_finished']);
             $tmp['##task.realtime##'] = Ticket::getActionTime($task["actiontime"]);
             $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['comment']));
             $tmp['##task.comment##'] = Html::clean($comment);
             $tmp['##task.resource##'] = Dropdown::getDropdownName('glpi_plugin_resources_resources', $task['plugin_resources_resources_id']);
             $this->datas['tasks'][] = $tmp;
         }
     } else {
         if ($event == 'AlertLeavingResources') {
             $this->datas['##resource.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
             $this->datas['##lang.resource.entity##'] = __('Entity');
             $this->datas['##resource.action##'] = __('These resources have normally left the company', 'resources');
             $this->datas['##lang.resource.id##'] = "ID";
             $this->datas['##lang.resource.name##'] = __('Name');
             $this->datas['##lang.resource.firstname##'] = __('First name');
             $this->datas['##lang.resource.type##'] = PluginResourcesContractType::getTypeName(1);
             $this->datas['##lang.resource.users##'] = __('Resource manager', 'resources');
             $this->datas['##lang.resource.usersrecipient##'] = __('Requester');
             $this->datas['##lang.resource.datedeclaration##'] = __('Request date');
             $this->datas['##lang.resource.datebegin##'] = __('Arrival date', 'resources');
             $this->datas['##lang.resource.dateend##'] = __('Departure date', 'resources');
             $this->datas['##lang.resource.department##'] = PluginResourcesDepartment::getTypeName(1);
             $this->datas['##lang.resource.status##'] = PluginResourcesResourceState::getTypeName(1);
             $this->datas['##lang.resource.location##'] = __('Location');
             $this->datas['##lang.resource.comment##'] = __('Description');
             $this->datas['##lang.resource.usersleaving##'] = __('Informant of leaving', 'resources');
             $this->datas['##lang.resource.leaving##'] = __('Declared as leaving', 'resources');
             $this->datas['##lang.resource.leavingreason##'] = PluginResourcesLeavingReason::getTypeName(1);
             $this->datas['##lang.resource.helpdesk##'] = __('Associable to a ticket');
             $this->datas['##lang.resource.url##'] = __('URL');
             foreach ($options['resources'] as $id => $resource) {
                 $tmp = array();
                 $tmp['##resource.name##'] = $resource['name'];
                 $tmp['##resource.firstname##'] = $resource['firstname'];
                 $tmp['##resource.type##'] = Dropdown::getDropdownName('glpi_plugin_resources_contracttypes', $resource['plugin_resources_contracttypes_id']);
                 $tmp['##resource.users##'] = Html::clean(getUserName($resource['users_id']));
                 $tmp['##resource.usersrecipient##'] = Html::clean(getUserName($resource['users_id_recipient']));
                 $tmp['##resource.datedeclaration##'] = Html::convDateTime($resource['date_declaration']);
                 $tmp['##resource.datebegin##'] = Html::convDateTime($resource['date_begin']);
                 $tmp['##resource.dateend##'] = Html::convDateTime($resource['date_end']);
                 $tmp['##resource.department##'] = Dropdown::getDropdownName('glpi_plugin_resources_departments', $resource['plugin_resources_departments_id']);
                 $tmp['##resource.status##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcestates', $resource['plugin_resources_resourcestates_id']);
                 $tmp['##resource.location##'] = Dropdown::getDropdownName('glpi_locations', $resource['locations_id']);
                 $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $resource['comment']));
                 $tmp['##resource.comment##'] = Html::clean($comment);
                 $tmp['##resource.usersleaving##'] = Html::clean(getUserName($resource['users_id_recipient_leaving']));
                 $tmp['##resource.leaving##'] = Dropdown::getYesNo($resource['is_leaving']);
                 $tmp['##resource.leavingreason##'] = Dropdown::getDropdownName('glpi_plugin_resources_leavingreasons', $resource['plugin_resources_leavingreasons_id']);
                 $tmp['##resource.helpdesk##'] = Dropdown::getYesNo($resource['is_helpdesk_visible']);
                 $tmp['##resource.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_resources_" . $resource['id']);
                 $this->datas['resources'][] = $tmp;
             }
         } else {
             if ($event == 'AlertArrivalChecklists' || $event == 'AlertLeavingChecklists') {
                 $this->datas['##checklist.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
                 $this->datas['##lang.checklist.entity##'] = __('Entity');
                 if ($event == 'AlertArrivalChecklists') {
                     $checklist_type = PluginResourcesChecklist::RESOURCES_CHECKLIST_IN;
                     $this->datas['##checklist.action##'] = __('Actions to do on these new resources', 'resources');
                     $this->datas['##lang.checklist.title##'] = __('New resource - checklist needs to verificated', 'resources');
                 } else {
                     $checklist_type = PluginResourcesChecklist::RESOURCES_CHECKLIST_OUT;
                     $this->datas['##checklist.action##'] = __('Actions to do on these leaving resources', 'resources');
                     $this->datas['##lang.checklist.title##'] = __('Leaving resource - checklist needs to verificated', 'resources');
                 }
                 $this->datas['##lang.checklist.title2##'] = __('Checklist needs to verificated', 'resources');
                 $this->datas['##lang.checklist.id##'] = "ID";
                 $this->datas['##lang.checklist.name##'] = __('Name');
                 $this->datas['##lang.checklist.firstname##'] = __('First name');
                 $this->datas['##lang.checklist.type##'] = PluginResourcesContractType::getTypeName(1);
                 $this->datas['##lang.checklist.users##'] = __('Resource manager', 'resources');
                 $this->datas['##lang.checklist.usersrecipient##'] = __('Requester');
                 $this->datas['##lang.checklist.datedeclaration##'] = __('Request date');
                 $this->datas['##lang.checklist.datebegin##'] = __('Arrival date', 'resources');
                 $this->datas['##lang.checklist.dateend##'] = __('Departure date', 'resources');
                 $this->datas['##lang.checklist.department##'] = PluginResourcesDepartment::getTypeName(1);
                 $this->datas['##lang.checklist.status##'] = PluginResourcesResourceState::getTypeName(1);
                 $this->datas['##lang.checklist.location##'] = __('Location');
                 $this->datas['##lang.checklist.comment##'] = __('Description');
                 $this->datas['##lang.checklist.usersleaving##'] = __('Informant of leaving', 'resources');
                 $this->datas['##lang.checklist.leaving##'] = __('Declared as leaving', 'resources');
                 //         $this->datas['##lang.checklist.leavingreason##'] = PluginResourcesLeavingReason::getTypeName(1);
                 $this->datas['##lang.checklist.helpdesk##'] = __('Associable to a ticket');
                 $this->datas['##lang.checklist.url##'] = "URL";
                 foreach ($options['checklists'] as $id => $checklist) {
                     $tmp = array();
                     $tmp['##checklist.id##'] = $checklist['plugin_resources_resources_id'];
                     $tmp['##checklist.name##'] = $checklist['resource_name'];
                     $tmp['##checklist.firstname##'] = $checklist['resource_firstname'];
                     $tmp['##checklist.type##'] = Dropdown::getDropdownName('glpi_plugin_resources_contracttypes', $checklist['plugin_resources_contracttypes_id']);
                     $tmp['##checklist.users##'] = Html::clean(getUserName($checklist['users_id']));
                     $tmp['##checklist.usersrecipient##'] = Html::clean(getUserName($checklist['users_id_recipient']));
                     $tmp['##checklist.datedeclaration##'] = Html::convDateTime($checklist['date_declaration']);
                     $tmp['##checklist.datebegin##'] = Html::convDateTime($checklist['date_begin']);
                     $tmp['##checklist.dateend##'] = Html::convDateTime($checklist['date_end']);
                     $tmp['##checklist.department##'] = Dropdown::getDropdownName('glpi_plugin_resources_departments', $checklist['plugin_resources_departments_id']);
                     $tmp['##checklist.status##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcestates', $checklist['plugin_resources_resourcestates_id']);
                     $tmp['##checklist.location##'] = Dropdown::getDropdownName('glpi_locations', $checklist['locations_id']);
                     $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $checklist['comment']));
                     $tmp['##checklist.comment##'] = Html::clean($comment);
                     $tmp['##checklist.usersleaving##'] = Html::clean(getUserName($checklist['users_id_recipient_leaving']));
                     $tmp['##checklist.leaving##'] = Dropdown::getYesNo($checklist['is_leaving']);
                     //            $tmp['##checklist.leavingreason##'] = Dropdown::getDropdownName('glpi_plugin_resources_leavingreasons',
                     //                                                   $checklist['plugin_resources_leavingreasons_id']);
                     $tmp['##checklist.helpdesk##'] = Dropdown::getYesNo($checklist['is_helpdesk_visible']);
                     $tmp['##checklist.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_resources_" . $checklist['plugin_resources_resources_id']);
                     $query = PluginResourcesChecklist::queryListChecklists($checklist['plugin_resources_resources_id'], $checklist_type);
                     $tmp['##tasklist.name##'] = '';
                     foreach ($DB->request($query) as $data) {
                         $tmp['##tasklist.name##'] .= $data["name"];
                         if ($_SESSION["glpiis_ids_visible"] == 1) {
                             $tmp['##tasklist.name##'] .= " (" . $data["id"] . ")";
                         }
                         $tmp['##tasklist.name##'] .= "\n";
                     }
                     $this->datas['checklists'][] = $tmp;
                 }
             } else {
                 if ($event == 'LeavingResource') {
                     $this->datas['##resource.entity##'] = Dropdown::getDropdownName('glpi_entities', $this->obj->getField('entities_id'));
                     $this->datas['##lang.resource.entity##'] = __('Entity');
                     $this->datas['##lang.resource.title##'] = __('A resource has been declared leaving', 'resources');
                     $this->datas['##lang.resource.title2##'] = __('Please check the leaving checklist of the resource', 'resources');
                     $this->datas['##lang.resource.id##'] = "ID";
                     $this->datas['##resource.id##'] = $this->obj->getField("id");
                     $this->datas['##lang.resource.name##'] = __('Name');
                     $this->datas['##resource.name##'] = $this->obj->getField("name");
                     $this->datas['##lang.resource.firstname##'] = __('First name');
                     $this->datas['##resource.firstname##'] = $this->obj->getField("firstname");
                     $this->datas['##lang.resource.type##'] = PluginResourcesContractType::getTypeName(1);
                     $this->datas['##resource.type##'] = Dropdown::getDropdownName('glpi_plugin_resources_contracttypes', $this->obj->getField('plugin_resources_contracttypes_id'));
                     $this->datas['##lang.resource.situation##'] = PluginResourcesResourceSituation::getTypeName(1);
                     $this->datas['##resource.situation##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcesituations', $this->obj->getField('plugin_resources_resourcesituations_id'));
                     $this->datas['##lang.resource.contractnature##'] = PluginResourcesContractNature::getTypeName(1);
                     $this->datas['##resource.contractnature##'] = Dropdown::getDropdownName('glpi_plugin_resources_contractnatures', $this->obj->getField('plugin_resources_contractnatures_id'));
                     $this->datas['##lang.resource.quota##'] = __('Quota', 'resources');
                     $this->datas['##resource.quota##'] = $this->obj->getField('quota');
                     $this->datas['##lang.resource.department##'] = PluginResourcesDepartment::getTypeName(1);
                     $this->datas['##resource.department##'] = Dropdown::getDropdownName('glpi_plugin_resources_departments', $this->obj->getField('plugin_resources_departments_id'));
                     $this->datas['##lang.resource.rank##'] = PluginResourcesRank::getTypeName(1);
                     $this->datas['##resource.rank##'] = Dropdown::getDropdownName('glpi_plugin_resources_ranks', $this->obj->getField('plugin_resources_ranks_id'));
                     $this->datas['##lang.resource.speciality##'] = PluginResourcesResourceSpeciality::getTypeName(1);
                     $this->datas['##resource.speciality##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcespecialities', $this->obj->getField('plugin_resources_resourcespecialities_id'));
                     $this->datas['##lang.resource.status##'] = PluginResourcesResourceState::getTypeName(1);
                     $this->datas['##resource.status##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcestates', $this->obj->getField('plugin_resources_resourcestates_id'));
                     $this->datas['##lang.resource.users##'] = __('Resource manager', 'resources');
                     $this->datas['##resource.users##'] = Html::clean(getUserName($this->obj->getField("users_id")));
                     $this->datas['##lang.resource.usersrecipient##'] = __('Requester');
                     $this->datas['##resource.usersrecipient##'] = Html::clean(getUserName($this->obj->getField("users_id_recipient")));
                     $this->datas['##lang.resource.datedeclaration##'] = __('Request date');
                     $this->datas['##resource.datedeclaration##'] = Html::convDate($this->obj->getField('date_declaration'));
                     $this->datas['##lang.resource.datebegin##'] = __('Arrival date', 'resources');
                     $this->datas['##resource.datebegin##'] = Html::convDate($this->obj->getField('date_begin'));
                     $this->datas['##lang.resource.dateend##'] = __('Departure date', 'resources');
                     $this->datas['##resource.dateend##'] = Html::convDate($this->obj->getField('date_end'));
                     $this->datas['##lang.resource.location##'] = __('Location');
                     $this->datas['##resource.location##'] = Dropdown::getDropdownName('glpi_locations', $this->obj->getField('locations_id'));
                     $this->datas['##lang.resource.helpdesk##'] = __('Associable to a ticket');
                     $this->datas['##resource.helpdesk##'] = Dropdown::getYesNo($this->obj->getField('is_helpdesk_visible'));
                     $this->datas['##lang.resource.leaving##'] = __('Declared as leaving', 'resources');
                     $this->datas['##resource.leaving##'] = Dropdown::getYesNo($this->obj->getField('is_leaving'));
                     $this->datas['##lang.resource.leavingreason##'] = PluginResourcesLeavingReason::getTypeName(1);
                     $this->datas['##resource.leavingreason##'] = Dropdown::getDropdownName('glpi_plugin_resources_leavingreasons', $this->obj->getField('plugin_resources_leavingreasons_id'));
                     $this->datas['##lang.resource.usersleaving##'] = __('Informant of leaving', 'resources');
                     $this->datas['##resource.usersleaving##'] = Html::clean(getUserName($this->obj->getField('users_id_recipient_leaving')));
                     $this->datas['##lang.resource.comment##'] = __('Description');
                     $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->obj->getField("comment")));
                     $this->datas['##resource.comment##'] = Html::clean($comment);
                     $this->datas['##lang.resource.url##'] = "URL";
                     $this->datas['##resource.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_resources_" . $this->obj->getField("id"));
                     $this->datas['##lang.resource.badge##'] = " ";
                     if (isset($this->target_object->input['checkbadge'])) {
                         if (!empty($this->target_object->input['checkbadge'])) {
                             $this->datas['##lang.resource.badge##'] = __('Thanks to recover his badges', 'resources');
                         } else {
                             $this->datas['##lang.resource.badge##'] = " ";
                         }
                     }
                 } else {
                     $events = $this->getAllEvents();
                     $this->datas['##lang.resource.title##'] = $events[$event];
                     $this->datas['##resource.action_user##'] = getUserName(Session::getLoginUserID());
                     $this->datas['##lang.resource.entity##'] = __('Entity');
                     $this->datas['##resource.entity##'] = Dropdown::getDropdownName('glpi_entities', $this->obj->getField('entities_id'));
                     $this->datas['##resource.id##'] = $this->obj->getField("id");
                     $this->datas['##lang.resource.name##'] = __('Name');
                     $this->datas['##resource.name##'] = $this->obj->getField("name");
                     $this->datas['##lang.resource.firstname##'] = __('First name');
                     $this->datas['##resource.firstname##'] = $this->obj->getField("firstname");
                     $this->datas['##lang.resource.type##'] = PluginResourcesContractType::getTypeName(1);
                     $this->datas['##resource.type##'] = Dropdown::getDropdownName('glpi_plugin_resources_contracttypes', $this->obj->getField('plugin_resources_contracttypes_id'));
                     $this->datas['##lang.resource.situation##'] = PluginResourcesResourceSituation::getTypeName(1);
                     $this->datas['##resource.situation##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcesituations', $this->obj->getField('plugin_resources_resourcesituations_id'));
                     $this->datas['##lang.resource.contractnature##'] = PluginResourcesContractNature::getTypeName(1);
                     $this->datas['##resource.contractnature##'] = Dropdown::getDropdownName('glpi_plugin_resources_contractnatures', $this->obj->getField('plugin_resources_contractnatures_id'));
                     $this->datas['##lang.resource.quota##'] = __('Quota', 'resources');
                     $this->datas['##resource.quota##'] = $this->obj->getField('quota');
                     $this->datas['##lang.resource.users##'] = __('Resource manager', 'resources');
                     $this->datas['##resource.users##'] = Html::clean(getUserName($this->obj->getField("users_id")));
                     $this->datas['##lang.resource.usersrecipient##'] = __('Requester');
                     $this->datas['##resource.usersrecipient##'] = Html::clean(getUserName($this->obj->getField("users_id_recipient")));
                     $this->datas['##lang.resource.datedeclaration##'] = __('Request date');
                     $this->datas['##resource.datedeclaration##'] = Html::convDate($this->obj->getField('date_declaration'));
                     $this->datas['##lang.resource.datebegin##'] = __('Arrival date', 'resources');
                     $this->datas['##resource.datebegin##'] = Html::convDate($this->obj->getField('date_begin'));
                     $this->datas['##lang.resource.dateend##'] = __('Departure date', 'resources');
                     $this->datas['##resource.dateend##'] = Html::convDate($this->obj->getField('date_end'));
                     $this->datas['##lang.resource.department##'] = PluginResourcesDepartment::getTypeName(1);
                     $this->datas['##resource.department##'] = Dropdown::getDropdownName('glpi_plugin_resources_departments', $this->obj->getField('plugin_resources_departments_id'));
                     $this->datas['##lang.resource.rank##'] = PluginResourcesRank::getTypeName(1);
                     $this->datas['##resource.rank##'] = Dropdown::getDropdownName('glpi_plugin_resources_ranks', $this->obj->getField('plugin_resources_ranks_id'));
                     $this->datas['##lang.resource.speciality##'] = PluginResourcesResourceSpeciality::getTypeName(1);
                     $this->datas['##resource.speciality##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcespecialities', $this->obj->getField('plugin_resources_resourcespecialities_id'));
                     $this->datas['##lang.resource.status##'] = PluginResourcesResourceState::getTypeName(1);
                     $this->datas['##resource.status##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcestates', $this->obj->getField('plugin_resources_resourcestates_id'));
                     $this->datas['##lang.resource.location##'] = __('Location');
                     $this->datas['##resource.location##'] = Dropdown::getDropdownName('glpi_locations', $this->obj->getField('locations_id'));
                     $this->datas['##lang.resource.comment##'] = __('Description');
                     $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->obj->getField("comment")));
                     $this->datas['##resource.comment##'] = Html::clean($comment);
                     $this->datas['##lang.resource.usersleaving##'] = __('Informant of leaving', 'resources');
                     $this->datas['##resource.usersleaving##'] = Html::clean(getUserName($this->obj->getField("users_id_recipient_leaving")));
                     $this->datas['##lang.resource.leaving##'] = __('Declared as leaving', 'resources');
                     $this->datas['##resource.leaving##'] = Dropdown::getYesNo($this->obj->getField('is_leaving'));
                     $this->datas['##lang.resource.leavingreason##'] = PluginResourcesLeavingReason::getTypeName(1);
                     $this->datas['##resource.leavingreason##'] = Dropdown::getDropdownName('glpi_plugin_resources_leavingreasons', $this->obj->getField('plugin_resources_leavingreasons_id'));
                     $this->datas['##lang.resource.helpdesk##'] = __('Associable to a ticket');
                     $this->datas['##resource.helpdesk##'] = Dropdown::getYesNo($this->obj->getField('is_helpdesk_visible'));
                     $this->datas['##lang.resource.url##'] = "URL";
                     $this->datas['##resource.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_resources_" . $this->obj->getField("id"));
                     if ($event == 'report') {
                         $this->datas['##lang.resource.creationtitle##'] = __('Creation report of the human resource', 'resources');
                         $this->datas['##resource.login##'] = "";
                         $this->datas['##resource.email##'] = "";
                         $restrict = "`itemtype` = 'User' \n                        AND `plugin_resources_resources_id` = '" . $this->obj->getField("id") . "'";
                         $items = getAllDatasFromTable("glpi_plugin_resources_resources_items", $restrict);
                         if (!empty($items)) {
                             foreach ($items as $item) {
                                 $user = new User();
                                 $user->getFromDB($item["items_id"]);
                                 $this->datas['##resource.login##'] = $user->fields["name"];
                                 $this->datas['##resource.email##'] = $user->getDefaultEmail();
                             }
                         }
                         $this->datas['##lang.resource.login##'] = __('Login');
                         $this->datas['##lang.resource.creation##'] = __('Informations of the created user', 'resources');
                         $this->datas['##lang.resource.datecreation##'] = __('Creation Date');
                         $this->datas['##resource.datecreation##'] = Html::convDate(date("Y-m-d"));
                         $this->datas['##lang.resource.email##'] = __('Email');
                         $this->datas['##lang.resource.informationtitle##'] = __('Additional informations', 'resources');
                         $PluginResourcesReportConfig = new PluginResourcesReportConfig();
                         $PluginResourcesReportConfig->getFromDB($options['reports_id']);
                         $this->datas['##lang.resource.informations##'] = __('Information', 'Informations', 2);
                         $information = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br>", $PluginResourcesReportConfig->fields['information']));
                         $this->datas['##resource.informations##'] = Html::clean(nl2br($information));
                         $this->datas['##lang.resource.commentaires##'] = __('Comments');
                         $commentaire = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br>", $PluginResourcesReportConfig->fields['comment']));
                         $this->datas['##resource.commentaires##'] = Html::clean(nl2br($commentaire));
                     }
                     if ($event == 'newresting' || $event == 'updateresting' || $event == 'deleteresting') {
                         $this->datas['##lang.resource.restingtitle##'] = __('Non contract period management', 'resources');
                         $this->datas['##lang.resource.resting##'] = __('Detail of non contract period', 'resources');
                         $this->datas['##lang.resource.datecreation##'] = __('Creation date');
                         $this->datas['##resource.datecreation##'] = Html::convDate(date("Y-m-d"));
                         $PluginResourcesResourceResting = new PluginResourcesResourceResting();
                         $PluginResourcesResourceResting->getFromDB($options['resting_id']);
                         $this->datas['##lang.resource.location##'] = __('Agency concerned');
                         $this->datas['##resource.location##'] = Dropdown::getDropdownName('glpi_locations', $PluginResourcesResourceResting->fields['locations_id']);
                         $this->datas['##lang.resource.home##'] = __('At home');
                         $this->datas['##resource.home##'] = Dropdown::getYesNo($PluginResourcesResourceResting->fields['at_home']);
                         $this->datas['##lang.resource.datebegin##'] = __('Begin date');
                         $this->datas['##resource.datebegin##'] = Html::convDate($PluginResourcesResourceResting->fields['date_begin']);
                         $this->datas['##lang.resource.dateend##'] = __('End date');
                         $this->datas['##resource.dateend##'] = Html::convDate($PluginResourcesResourceResting->fields['date_end']);
                         $this->datas['##lang.resource.informationtitle##'] = __('Additional informations', 'resources');
                         $this->datas['##lang.resource.commentaires##'] = __('Comments');
                         $commentaire = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br>", $PluginResourcesResourceResting->fields['comment']));
                         $this->datas['##resource.commentaires##'] = Html::clean(nl2br($commentaire));
                         $this->datas['##lang.resource.openby##'] = __('Reported by', 'resources');
                         $this->datas['##resource.openby##'] = Html::clean(getUserName(Session::getLoginUserID()));
                         if (isset($options['oldvalues']) && !empty($options['oldvalues'])) {
                             $this->target_object->oldvalues = $options['oldvalues'];
                         }
                     }
                     if ($event == 'newholiday' || $event == 'updateholiday' || $event == 'deleteholiday') {
                         $this->datas['##lang.resource.holidaytitle##'] = __('Forced holiday management', 'resources');
                         $this->datas['##lang.resource.holiday##'] = __('Detail of the forced holiday', 'resources');
                         $this->datas['##lang.resource.datecreation##'] = __('Creation date');
                         $this->datas['##resource.datecreation##'] = Html::convDate(date("Y-m-d"));
                         $PluginResourcesResourceHoliday = new PluginResourcesResourceHoliday();
                         $PluginResourcesResourceHoliday->getFromDB($options['holiday_id']);
                         $this->datas['##lang.resource.datebegin##'] = __('Begin date');
                         $this->datas['##resource.datebegin##'] = Html::convDate($PluginResourcesResourceHoliday->fields['date_begin']);
                         $this->datas['##lang.resource.dateend##'] = __('End date');
                         $this->datas['##resource.dateend##'] = Html::convDate($PluginResourcesResourceHoliday->fields['date_end']);
                         $this->datas['##lang.resource.informationtitle##'] = __('Additional informations', 'resources');
                         $this->datas['##lang.resource.commentaires##'] = __('Comments');
                         $commentaire = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br>", $PluginResourcesResourceHoliday->fields['comment']));
                         $this->datas['##resource.commentaires##'] = Html::clean(nl2br($commentaire));
                         $this->datas['##lang.resource.openby##'] = __('Reported by', 'resources');
                         $this->datas['##resource.openby##'] = Html::clean(getUserName(Session::getLoginUserID()));
                         if (isset($options['oldvalues']) && !empty($options['oldvalues'])) {
                             $this->target_object->oldvalues = $options['oldvalues'];
                         }
                     }
                     //old values infos
                     if (isset($this->target_object->oldvalues) && !empty($this->target_object->oldvalues) && ($event == 'update' || $event == 'updateresting' || $event == 'updateholiday')) {
                         $this->datas['##lang.update.title##'] = __('Modified fields', 'resources');
                         $tmp = array();
                         if (isset($this->target_object->oldvalues['name'])) {
                             if (empty($this->target_object->oldvalues['name'])) {
                                 $tmp['##update.name##'] = "---";
                             } else {
                                 $tmp['##update.name##'] = $this->target_object->oldvalues['name'];
                             }
                         }
                         if (isset($this->target_object->oldvalues['firstname'])) {
                             if (empty($this->target_object->oldvalues['firstname'])) {
                                 $tmp['##update.firstname##'] = "---";
                             } else {
                                 $tmp['##update.firstname##'] = $this->target_object->oldvalues['firstname'];
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_contracttypes_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_contracttypes_id'])) {
                                 $tmp['##update.type##'] = "---";
                             } else {
                                 $tmp['##update.type##'] = Dropdown::getDropdownName('glpi_plugin_resources_contracttypes', $this->target_object->oldvalues['plugin_resources_contracttypes_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['users_id'])) {
                             if (empty($this->target_object->oldvalues['users_id'])) {
                                 $tmp['##update.users##'] = "---";
                             } else {
                                 $tmp['##update.users##'] = Html::clean(getUserName($this->target_object->oldvalues['users_id']));
                             }
                         }
                         if (isset($this->target_object->oldvalues['users_id_recipient'])) {
                             if (empty($this->target_object->oldvalues['users_id_recipient'])) {
                                 $tmp['##update.usersrecipient##'] = "---";
                             } else {
                                 $tmp['##update.usersrecipient##'] = Html::clean(getUserName($this->target_object->oldvalues['users_id_recipient']));
                             }
                         }
                         if (isset($this->target_object->oldvalues['date_declaration'])) {
                             if (empty($this->target_object->oldvalues['date_declaration'])) {
                                 $tmp['##update.datedeclaration##'] = "---";
                             } else {
                                 $tmp['##update.datedeclaration##'] = Html::convDate($this->target_object->oldvalues['date_declaration']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['date_begin'])) {
                             if (empty($this->target_object->oldvalues['date_begin'])) {
                                 $tmp['##update.datebegin##'] = "---";
                             } else {
                                 $tmp['##update.datebegin##'] = Html::convDate($this->target_object->oldvalues['date_begin']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['date_end'])) {
                             if (empty($this->target_object->oldvalues['date_end'])) {
                                 $tmp['##update.dateend##'] = "---";
                             } else {
                                 $tmp['##update.dateend##'] = Html::convDate($this->target_object->oldvalues['date_end']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['quota'])) {
                             if (empty($this->target_object->oldvalues['quota'])) {
                                 $tmp['##update.quota##'] = "---";
                             } else {
                                 $tmp['##update.quota##'] = $this->target_object->oldvalues['quota'];
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_departments_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_departments_id'])) {
                                 $tmp['##update.department##'] = "---";
                             } else {
                                 $tmp['##update.department##'] = Dropdown::getDropdownName('glpi_plugin_resources_departments', $this->target_object->oldvalues['plugin_resources_departments_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_resourcestates_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_resourcestates_id'])) {
                                 $tmp['##update.status##'] = "---";
                             } else {
                                 $tmp['##update.status##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcestates', $this->target_object->oldvalues['plugin_resources_resourcestates_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_resourcesituations_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_resourcesituations_id'])) {
                                 $tmp['##update.situation##'] = "---";
                             } else {
                                 $tmp['##update.situation##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcesituations', $this->target_object->oldvalues['plugin_resources_resourcesituations_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_contractnatures_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_contractnatures_id'])) {
                                 $tmp['##update.contractnature##'] = "---";
                             } else {
                                 $tmp['##update.contractnature##'] = Dropdown::getDropdownName('glpi_plugin_resources_contractnatures', $this->target_object->oldvalues['plugin_resources_contractnatures_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_ranks_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_ranks_id'])) {
                                 $tmp['##update.rank##'] = "---";
                             } else {
                                 $tmp['##update.rank##'] = Dropdown::getDropdownName('glpi_plugin_resources_ranks', $this->target_object->oldvalues['plugin_resources_ranks_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_resourcespecialities_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_resourcespecialities_id'])) {
                                 $tmp['##update.speciality##'] = "---";
                             } else {
                                 $tmp['##update.speciality##'] = Dropdown::getDropdownName('glpi_plugin_resources_resourcespecialities', $this->target_object->oldvalues['plugin_resources_resourcespecialities_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['locations_id'])) {
                             if (empty($this->target_object->oldvalues['locations_id'])) {
                                 $tmp['##update.location##'] = "---";
                             } else {
                                 $tmp['##update.location##'] = Dropdown::getDropdownName('glpi_locations', $this->target_object->oldvalues['locations_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['comment'])) {
                             if (empty($this->target_object->oldvalues['comment'])) {
                                 $tmp['##update.comment##'] = "---";
                             } else {
                                 $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->target_object->oldvalues['comment']));
                                 $tmp['##update.comment##'] = Html::clean($comment);
                             }
                         }
                         if (isset($this->target_object->oldvalues['users_id_recipient_leaving'])) {
                             if (empty($this->target_object->oldvalues['users_id_recipient_leaving'])) {
                                 $tmp['##update.usersleaving##'] = "---";
                             } else {
                                 $tmp['##update.usersleaving##'] = Html::clean(getUserName($this->target_object->oldvalues['users_id_recipient_leaving']));
                             }
                         }
                         if (isset($this->target_object->oldvalues['is_leaving'])) {
                             if (empty($this->target_object->oldvalues['is_leaving'])) {
                                 $tmp['##update.leaving##'] = "---";
                             } else {
                                 $tmp['##update.leaving##'] = Dropdown::getYesNo($this->target_object->oldvalues['is_leaving']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['plugin_resources_leavingreasons_id'])) {
                             if (empty($this->target_object->oldvalues['plugin_resources_leavingreasons_id'])) {
                                 $tmp['##update.leavingreason##'] = "---";
                             } else {
                                 $tmp['##update.leavingreason##'] = Dropdown::getDropdownName('glpi_plugin_resources_leavingreasons', $this->target_object->oldvalues['plugin_resources_leavingreasons_id']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['is_helpdesk_visible'])) {
                             if (empty($this->target_object->oldvalues['is_helpdesk_visible'])) {
                                 $tmp['##update.helpdesk##'] = "---";
                             } else {
                                 $tmp['##update.helpdesk##'] = Dropdown::getYesNo($this->target_object->oldvalues['is_helpdesk_visible']);
                             }
                         }
                         if (isset($this->target_object->oldvalues['at_home'])) {
                             if (empty($this->target_object->oldvalues['at_home'])) {
                                 $tmp['##update.home##'] = "---";
                             } else {
                                 $tmp['##update.home##'] = Dropdown::getYesNo($this->target_object->oldvalues['at_home']);
                             }
                         }
                         $this->datas['updates'][] = $tmp;
                     }
                     //task infos
                     $restrict = "`plugin_resources_resources_id`='" . $this->obj->getField('id') . "' AND `is_deleted` = 0";
                     if (isset($options['tasks_id']) && $options['tasks_id']) {
                         $restrict .= " AND `glpi_plugin_resources_tasks`.`id` = '" . $options['tasks_id'] . "'";
                     }
                     $restrict .= " ORDER BY `name` DESC";
                     $tasks = getAllDatasFromTable('glpi_plugin_resources_tasks', $restrict);
                     $this->datas['##lang.task.title##'] = __('Associated tasks', 'resources');
                     $this->datas['##lang.task.name##'] = __('Name');
                     $this->datas['##lang.task.type##'] = __('Type');
                     $this->datas['##lang.task.users##'] = __('Technician');
                     $this->datas['##lang.task.groups##'] = __('Group');
                     $this->datas['##lang.task.datebegin##'] = __('Begin date');
                     $this->datas['##lang.task.dateend##'] = __('End date');
                     $this->datas['##lang.task.planned##'] = __('Used for planning', 'resources');
                     $this->datas['##lang.task.realtime##'] = __('Effective duration', 'resources');
                     $this->datas['##lang.task.finished##'] = __('Carried out task', 'resources');
                     $this->datas['##lang.task.comment##'] = __('Description');
                     foreach ($tasks as $task) {
                         $tmp = array();
                         $tmp['##task.name##'] = $task['name'];
                         $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_plugin_resources_tasktypes', $task['plugin_resources_tasktypes_id']);
                         $tmp['##task.users##'] = Html::clean(getUserName($task['users_id']));
                         $tmp['##task.groups##'] = Dropdown::getDropdownName('glpi_groups', $task['groups_id']);
                         $restrict = " `plugin_resources_tasks_id` = '" . $task['id'] . "' ";
                         $plans = getAllDatasFromTable("glpi_plugin_resources_taskplannings", $restrict);
                         if (!empty($plans)) {
                             foreach ($plans as $plan) {
                                 $tmp['##task.datebegin##'] = Html::convDateTime($plan["begin"]);
                                 $tmp['##task.dateend##'] = Html::convDateTime($plan["end"]);
                             }
                         } else {
                             $tmp['##task.datebegin##'] = '';
                             $tmp['##task.dateend##'] = '';
                         }
                         $tmp['##task.planned##'] = '';
                         $tmp['##task.finished##'] = Dropdown::getYesNo($task['is_finished']);
                         $tmp['##task.realtime##'] = Ticket::getActionTime($task["actiontime"]);
                         $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['comment']));
                         $tmp['##task.comment##'] = Html::clean($comment);
                         $this->datas['tasks'][] = $tmp;
                     }
                 }
             }
         }
     }
 }