resume_text() static public méthode

Resume text for followup
static public resume_text ( $string, $length = 255 ) : cut
$string string string to resume
$length integer resume length (default 255)
Résultat cut string
Exemple #1
0
 /**
  * @covers Html::resume_text
  */
 public function testResume_text()
 {
     $origin = 'This is a very long string which will be truncated by a dedicated method. ' . 'If the string is not truncated, well... We\'re wrong and got a very serious issue in our codebase!' . 'And if the string has been correctly truncated, well... All is ok then, let\'s show if all the other tests are OK :)';
     $expected = 'This is a very long string which will be truncated by a dedicated method. ' . 'If the string is not truncated, well... We\'re wrong and got a very serious issue in our codebase!' . 'And if the string has been correctly truncated, well... All is ok then, let\'s show i (...)';
     $this->assertEquals($expected, Html::resume_text($origin));
     $origin = 'A string that is longer than 10 characters.';
     $expected = 'A string t (...)';
     $this->assertEquals($expected, Html::resume_text($origin, 10));
 }
 /**
  * Display a Planning Item
  *
  * @param $itemtype  itemtype
  * @param $val       Array    of the item to display
  *
  * @return Already planned information
  **/
 static function genericGetAlreadyPlannedInformation($itemtype, array $val)
 {
     global $CFG_GLPI;
     if ($item = getItemForItemtype($itemtype)) {
         $objectitemtype = $item->getItilObjectItemType();
         //TRANS: %1$s is a type, %2$$ is a date, %3$s is a date
         $out = sprintf(__('%1$s: from %2$s to %3$s:'), $item->getTypeName(1), Html::convDateTime($val["begin"]), Html::convDateTime($val["end"]));
         $out .= "<br><a href='" . Toolbox::getItemTypeFormURL($objectitemtype) . "?id=" . $val[getForeignKeyFieldForItemType($objectitemtype)] . "&amp;forcetab=" . $itemtype . "\$1'>";
         $out .= Html::resume_text($val["name"], 80) . '</a>';
         return $out;
     }
 }
 /**
  * Print out list recent or popular kb/faq
  *
  * @param $type      type : recent / popular / not published
  *
  * @return nothing (display table)
  **/
 static function showRecentPopular($type)
 {
     global $DB, $CFG_GLPI;
     $faq = !Session::haveRight(self::$rightname, READ);
     if ($type == "recent") {
         $orderby = "ORDER BY `date` DESC";
         $title = __('Recent entries');
     } else {
         if ($type == 'lastupdate') {
             $orderby = "ORDER BY `date_mod` DESC";
             $title = __('Last updated entries');
         } else {
             $orderby = "ORDER BY `view` DESC";
             $title = __('Most popular questions');
         }
     }
     $faq_limit = "";
     $addselect = "";
     // Force all joins for not published to verify no visibility set
     $join = self::addVisibilityJoins(true);
     if (Session::getLoginUserID()) {
         $faq_limit .= "WHERE " . self::addVisibilityRestrict();
     } else {
         // Anonymous access
         if (Session::isMultiEntitiesMode()) {
             $faq_limit .= " WHERE (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n                                   AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')";
         } else {
             $faq_limit .= " WHERE 1";
         }
     }
     // Only published
     $faq_limit .= " AND (`glpi_entities_knowbaseitems`.`entities_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_profiles`.`profiles_id` IS NOT NULL\n                           OR `glpi_groups_knowbaseitems`.`groups_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_users`.`users_id` IS NOT NULL)";
     // Add visibility date
     $faq_limit .= " AND (`glpi_knowbaseitems`.`begin_date` IS NULL\n                           OR `glpi_knowbaseitems`.`begin_date` < NOW())\n                      AND (`glpi_knowbaseitems`.`end_date` IS NULL\n                           OR `glpi_knowbaseitems`.`end_date` > NOW()) ";
     if ($faq) {
         // FAQ
         $faq_limit .= " AND (`glpi_knowbaseitems`.`is_faq` = '1')";
     }
     if (KnowbaseItemTranslation::isKbTranslationActive()) {
         $join .= "LEFT JOIN `glpi_knowbaseitemtranslations`\n                     ON (`glpi_knowbaseitems`.`id` = `glpi_knowbaseitemtranslations`.`knowbaseitems_id`\n                           AND `glpi_knowbaseitemtranslations`.`language` = '" . $_SESSION['glpilanguage'] . "')";
         $addselect .= ", `glpi_knowbaseitemtranslations`.`name` AS transname,\n                          `glpi_knowbaseitemtranslations`.`answer` AS transanswer ";
     }
     $query = "SELECT DISTINCT `glpi_knowbaseitems`.* {$addselect}\n                FROM `glpi_knowbaseitems`\n                {$join}\n                {$faq_limit}\n                {$orderby}\n                LIMIT 10";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($number > 0) {
         echo "<table class='tab_cadrehov'>";
         echo "<tr class='noHover'><th>" . $title . "</th></tr>";
         while ($data = $DB->fetch_assoc($result)) {
             $name = $data['name'];
             if (isset($data['transname']) && !empty($data['transname'])) {
                 $name = $data['transname'];
             }
             echo "<tr class='tab_bg_2'><td class='left'>";
             echo "<a " . ($data['is_faq'] ? " class='pubfaq' title='" . __("This item is part of the FAQ") . "' " : " class='knowbase' ") . " href=\"" . $CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\">" . Html::resume_text($name, 80) . "</a></td></tr>";
         }
         echo "</table>";
     }
 }
 /**
  * @see CommonDBTM::prepareInputForAdd()
  **/
 function prepareInputForAdd($input)
 {
     global $CFG_GLPI, $DB;
     // security (don't accept filename from $_POST)
     unset($input['filename']);
     if ($uid = Session::getLoginUserID()) {
         $input["users_id"] = Session::getLoginUserID();
     }
     // Create a doc only selecting a file from a item form
     $create_from_item = false;
     if (isset($input["items_id"]) && isset($input["itemtype"]) && ($item = getItemForItemtype($input["itemtype"])) && $input["items_id"] > 0) {
         $typename = $item->getTypeName(1);
         $name = NOT_AVAILABLE;
         if ($item->getFromDB($input["items_id"])) {
             $name = $item->getNameID();
         }
         //TRANS: %1$s is Document, %2$s is item type, %3$s is item name
         $input["name"] = addslashes(Html::resume_text(sprintf(__('%1$s: %2$s'), __('Document'), sprintf(__('%1$s - %2$s'), $typename, $name)), 200));
         $create_from_item = true;
     }
     $upload_ok = false;
     if (isset($input["_filename"]) && !empty($input["_filename"]) == 1) {
         $upload_ok = $this->moveDocument($input, stripslashes(array_shift($input["_filename"])));
     } else {
         if (isset($input["upload_file"]) && !empty($input["upload_file"])) {
             // Move doc from upload dir
             $upload_ok = $this->moveUploadedDocument($input, $input["upload_file"]);
         }
     }
     // Tag
     if (isset($input["_tag_filename"]) && !empty($input["_tag_filename"]) == 1) {
         $input['tag'] = array_shift($input["_tag_filename"]);
     }
     if (!isset($input["tag"]) || empty($input["tag"])) {
         $input['tag'] = Rule::getUuid();
     }
     // Upload failed : do not create document
     if ($create_from_item && !$upload_ok) {
         return false;
     }
     // Default document name
     if ((!isset($input['name']) || empty($input['name'])) && isset($input['filename'])) {
         $input['name'] = $input['filename'];
     }
     unset($input["upload_file"]);
     // Don't add if no file
     if (isset($input["_only_if_upload_succeed"]) && $input["_only_if_upload_succeed"] && (!isset($input['filename']) || empty($input['filename']))) {
         return false;
     }
     // Set default category for document linked to tickets
     if (isset($input['itemtype']) && $input['itemtype'] == 'Ticket' && (!isset($input['documentcategories_id']) || $input['documentcategories_id'] == 0)) {
         $input['documentcategories_id'] = $CFG_GLPI["documentcategories_id_forticket"];
     }
     /* Unicity check
        if (isset($input['sha1sum'])) {
           // Check if already upload in the current entity
           $crit = array('sha1sum'=>$input['sha1sum'],
                         'entities_id'=>$input['entities_id']);
           foreach ($DB->request($this->getTable(), $crit) as $data) {
              $link=$this->getFormURL();
              Session::addMessageAfterRedirect(__('"A document with that filename has already been attached to another record.').
                 "&nbsp;: <a href=\"".$link."?id=".
                       $data['id']."\">".$data['name']."</a>",
                 false, ERROR, true);
              return false;
           }
        } */
     return $input;
 }
 /**
  * Print out list recent or popular kb/faq
  *
  * @param $type      type : recent / popular / not published
  *
  * @return nothing (display table)
  **/
 static function showRecentPopular($type)
 {
     global $DB, $CFG_GLPI;
     $faq = !Session::haveRight("knowbase", "r");
     if ($type == "recent") {
         $orderby = "ORDER BY `date` DESC";
         $title = __('Recent entries');
     } else {
         if ($type == 'lastupdate') {
             $orderby = "ORDER BY `date_mod` DESC";
             $title = __('Last updated entries');
         } else {
             $orderby = "ORDER BY `view` DESC";
             $title = __('Most popular questions');
         }
     }
     $faq_limit = "";
     // Force all joins for not published to verify no visibility set
     $join = self::addVisibilityJoins(true);
     if (Session::getLoginUserID()) {
         $faq_limit .= "WHERE " . self::addVisibilityRestrict();
     } else {
         // Anonymous access
         if (Session::isMultiEntitiesMode()) {
             $faq_limit .= " WHERE (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n                                   AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')";
         } else {
             $faq_limit .= " WHERE 1";
         }
     }
     // Only published
     $faq_limit .= " AND (`glpi_entities_knowbaseitems`.`entities_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_profiles`.`profiles_id` IS NOT NULL\n                           OR `glpi_groups_knowbaseitems`.`groups_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_users`.`users_id` IS NOT NULL)";
     if ($faq) {
         // FAQ
         $faq_limit .= " AND (`glpi_knowbaseitems`.`is_faq` = '1')";
     }
     $query = "SELECT DISTINCT `glpi_knowbaseitems`.*\n                FROM `glpi_knowbaseitems`\n                {$join}\n                {$faq_limit}\n                {$orderby}\n                LIMIT 10";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($number > 0) {
         echo "<table class='tab_cadrehov'>";
         echo "<tr><th>" . $title . "</th></tr>";
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tr class='tab_bg_2'><td class='left'>";
             echo "<a " . ($data['is_faq'] ? " class='pubfaq' " : " class='knowbase' ") . " href=\"" . $CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\">" . Html::resume_text($data["name"], 80) . "</a></td></tr>";
         }
         echo "</table>";
     }
 }
Exemple #6
0
 /**
  * Generic Function to display Items
  *
  * @param $itemtype              item type
  * @param $ID                    ID of the SEARCH_OPTION item
  * @param $data            array containing data results
  * @param $num                   item num in the request
  * @param $meta                  is a meta item ? (default 0)
  * @param $addobjectparams array added parameters for union search
  *
  * @return string to print
  **/
 static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array())
 {
     global $CFG_GLPI, $DB;
     $searchopt =& self::getOptions($itemtype);
     if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) {
         if (isset($searchopt[$ID]['addobjectparams']) && $searchopt[$ID]['addobjectparams']) {
             return self::giveItem($data["TYPE"], $ID, $data, $num, $meta, $searchopt[$ID]['addobjectparams']);
         }
         return self::giveItem($data["TYPE"], $ID, $data, $num, $meta);
     }
     if (count($addobjectparams)) {
         $searchopt[$ID] = array_merge($searchopt[$ID], $addobjectparams);
     }
     // Plugin can override core definition for its type
     if ($plug = isPluginItemType($itemtype)) {
         $function = 'plugin_' . $plug['plugin'] . '_giveItem';
         if (function_exists($function)) {
             $out = $function($itemtype, $ID, $data, $num);
             if (!empty($out)) {
                 return $out;
             }
         }
     }
     $NAME = "ITEM_";
     //       if ($meta) {
     //          $NAME = "META_";
     //       }
     if (isset($searchopt[$ID]["table"])) {
         $table = $searchopt[$ID]["table"];
         $field = $searchopt[$ID]["field"];
         $linkfield = $searchopt[$ID]["linkfield"];
         /// TODO try to clean all specific cases using SpecificToDisplay
         switch ($table . '.' . $field) {
             case "glpi_users.name":
                 // USER search case
                 if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) {
                     $out = "";
                     $count_display = 0;
                     $added = array();
                     $showuserlink = 0;
                     if (Session::haveRight('user', READ)) {
                         $showuserlink = 1;
                     }
                     for ($k = 0; $k < $data[$num]['count']; $k++) {
                         if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0 || isset($data[$num][$k][2]) && $data[$num][$k][2] != '') {
                             if ($count_display) {
                                 $out .= self::LBBR;
                             }
                             if ($itemtype == 'Ticket') {
                                 if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0) {
                                     $userdata = getUserName($data[$num][$k]['name'], 2);
                                     $tooltip = "";
                                     if (Session::haveRight('user', READ)) {
                                         $tooltip = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                                     }
                                     $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip);
                                     $count_display++;
                                 }
                             } else {
                                 $out .= getUserName($data[$num][$k]['name'], $showuserlink);
                                 $count_display++;
                             }
                             // Manage alternative_email for tickets_users
                             if ($itemtype == 'Ticket' && isset($data[$num][$k][2])) {
                                 $split = explode(self::LONGSEP, $data[$num][$k][2]);
                                 for ($l = 0; $l < count($split); $l++) {
                                     $split2 = explode(" ", $split[$l]);
                                     if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) {
                                         if ($count_display) {
                                             $out .= self::LBBR;
                                         }
                                         $count_display++;
                                         $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>";
                                     }
                                 }
                             }
                         }
                     }
                     return $out;
                 }
                 if ($itemtype != 'User') {
                     $toadd = '';
                     if ($itemtype == 'Ticket' && $data[$num][0]['id'] > 0) {
                         $userdata = getUserName($data[$num][0]['id'], 2);
                         $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                     }
                     $usernameformat = formatUserName($data[$num][0]['id'], $data[$num][0]['name'], $data[$num][0]['realname'], $data[$num][0]['firstname'], 1);
                     return sprintf(__('%1$s %2$s'), $usernameformat, $toadd);
                 }
                 break;
             case "glpi_profiles.name":
                 if ($itemtype == 'User' && $ID == 20) {
                     $out = "";
                     $count_display = 0;
                     $added = array();
                     for ($k = 0; $k < $data[$num]['count']; $k++) {
                         if (strlen(trim($data[$num][$k]['name'])) > 0) {
                             $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_entities', $data[$num][$k]['entities_id']));
                             $comp = '';
                             if ($data[$num][$k]['is_recursive']) {
                                 $comp = __('R');
                                 if ($data[$num][$k]['is_dynamic']) {
                                     $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                                 }
                             }
                             if ($data[$num][$k]['is_dynamic']) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                             }
                             if (!empty($comp)) {
                                 $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                             }
                             if (!in_array($text, $added)) {
                                 if ($count_display) {
                                     $out .= self::LBBR;
                                 }
                                 $count_display++;
                                 $out .= $text;
                                 $added[] = $text;
                             }
                         }
                     }
                     return $out;
                 }
                 break;
             case "glpi_entities.completename":
                 if ($itemtype == 'User') {
                     $out = "";
                     $added = array();
                     $count_display = 0;
                     for ($k = 0; $k < $data[$num]['count']; $k++) {
                         if (strlen(trim($data[$num][$k]['name'])) > 0) {
                             $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_profiles', $data[$num][$k]['profiles_id']));
                             $comp = '';
                             if ($data[$num][$k]['is_recursive']) {
                                 $comp = __('R');
                                 if ($data[$num][$k]['is_dynamic']) {
                                     $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                                 }
                             }
                             if ($data[$num][$k]['is_dynamic']) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                             }
                             if (!empty($comp)) {
                                 $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                             }
                             if (!in_array($text, $added)) {
                                 if ($count_display) {
                                     $out .= self::LBBR;
                                 }
                                 $count_display++;
                                 $out .= $text;
                                 $added[] = $text;
                             }
                         }
                     }
                     return $out;
                 }
                 break;
             case "glpi_documenttypes.icon":
                 if (!empty($data[$num][0]['name'])) {
                     return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$num][0]['name'] . "'>";
                 }
                 return "&nbsp;";
             case "glpi_documents.filename":
                 $doc = new Document();
                 if ($doc->getFromDB($data['id'])) {
                     return $doc->getDownloadLink();
                 }
                 return NOT_AVAILABLE;
             case "glpi_tickets_tickets.tickets_id_1":
                 $out = "";
                 $displayed = array();
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     $linkid = $data[$num][$k]['tickets_id_2'] == $data['id'] ? $data[$num][$k]['name'] : $data[$num][$k]['tickets_id_2'];
                     if ($linkid > 0 && !isset($displayed[$linkid])) {
                         $text = "<a ";
                         $text .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id={$linkid}\">";
                         $text .= Dropdown::getDropdownName('glpi_tickets', $linkid) . "</a>";
                         if (count($displayed)) {
                             $out .= self::LBBR;
                         }
                         $displayed[$linkid] = $linkid;
                         $out .= $text;
                     }
                 }
                 return $out;
             case "glpi_problems.id":
                 if ($searchopt[$ID]["datatype"] == 'count') {
                     if ($data[$num][0]['name'] > 0 && Session::haveRight("problem", Problem::READALL)) {
                         if ($itemtype == 'ITILCategory') {
                             $options['criteria'][0]['field'] = 7;
                             $options['criteria'][0]['searchtype'] = 'equals';
                             $options['criteria'][0]['value'] = $data['id'];
                             $options['criteria'][0]['link'] = 'AND';
                         } else {
                             $options['criteria'][0]['field'] = 12;
                             $options['criteria'][0]['searchtype'] = 'equals';
                             $options['criteria'][0]['value'] = 'all';
                             $options['criteria'][0]['link'] = 'AND';
                             $options['metacriteria'][0]['itemtype'] = $itemtype;
                             $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name');
                             $options['metacriteria'][0]['searchtype'] = 'equals';
                             $options['metacriteria'][0]['value'] = $data['id'];
                             $options['metacriteria'][0]['link'] = 'AND';
                         }
                         $options['reset'] = 'reset';
                         $out = "<a id='problem{$itemtype}" . $data['id'] . "' ";
                         $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/problem.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                         $out .= $data[$num][0]['name'] . "</a>";
                         return $out;
                     }
                 }
                 break;
             case "glpi_tickets.id":
                 if ($searchopt[$ID]["datatype"] == 'count') {
                     if ($data[$num][0]['name'] > 0 && Session::haveRight("ticket", Ticket::READALL)) {
                         if ($itemtype == 'User') {
                             // Requester
                             if ($ID == 60) {
                                 $options['criteria'][0]['field'] = 4;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             }
                             // Writer
                             if ($ID == 61) {
                                 $options['criteria'][0]['field'] = 22;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             }
                             // Assign
                             if ($ID == 64) {
                                 $options['criteria'][0]['field'] = 5;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             }
                         } else {
                             if ($itemtype == 'ITILCategory') {
                                 $options['criteria'][0]['field'] = 7;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             } else {
                                 $options['criteria'][0]['field'] = 12;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = 'all';
                                 $options['criteria'][0]['link'] = 'AND';
                                 $options['metacriteria'][0]['itemtype'] = $itemtype;
                                 $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name');
                                 $options['metacriteria'][0]['searchtype'] = 'equals';
                                 $options['metacriteria'][0]['value'] = $data['id'];
                                 $options['metacriteria'][0]['link'] = 'AND';
                             }
                         }
                         $options['reset'] = 'reset';
                         $out = "<a id='ticket{$itemtype}" . $data['id'] . "' ";
                         $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                         $out .= $data[$num][0]['name'] . "</a>";
                         return $out;
                     }
                 }
                 break;
             case "glpi_tickets.due_date":
             case "glpi_problems.due_date":
             case "glpi_changes.due_date":
                 // Due date + progress
                 if ($ID == 151) {
                     $out = Html::convDate($data[$num][0]['name']);
                     // No due date in waiting status
                     if ($data[$num][0]['status'] == CommonITILObject::WAITING) {
                         return '';
                     }
                     if (empty($data[$num][0]['name'])) {
                         return '';
                     }
                     if ($data[$num][0]['status'] == Ticket::SOLVED || $data[$num][0]['status'] == Ticket::CLOSED) {
                         return $out;
                     }
                     $itemtype = getItemTypeForTable($table);
                     $item = new $itemtype();
                     $item->getFromDB($data['id']);
                     $percentage = 0;
                     $totaltime = 0;
                     $currenttime = 0;
                     if ($item->isField('slas_id') && $item->fields['slas_id'] != 0) {
                         // Have SLA
                         $sla = new SLA();
                         $sla->getFromDB($item->fields['slas_id']);
                         $currenttime = $sla->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
                         $totaltime = $sla->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
                     } else {
                         $calendars_id = Entity::getUsedConfig('calendars_id', $item->fields['entities_id']);
                         if ($calendars_id != 0) {
                             // Ticket entity have calendar
                             $calendar = new Calendar();
                             $calendar->getFromDB($calendars_id);
                             $currenttime = $calendar->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
                             $totaltime = $calendar->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
                         } else {
                             // No calendar
                             $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($item->fields['date']);
                             $totaltime = strtotime($data[$num][0]['name']) - strtotime($item->fields['date']);
                         }
                     }
                     if ($totaltime != 0) {
                         $percentage = round(100 * $currenttime / $totaltime);
                     } else {
                         // Total time is null : no active time
                         $percentage = 100;
                     }
                     if ($percentage > 100) {
                         $percentage = 100;
                     }
                     $percentage_text = $percentage;
                     if ($_SESSION['glpiduedatewarning_unit'] == '%') {
                         $less_warn_limit = $_SESSION['glpiduedatewarning_less'];
                         $less_warn = 100 - $percentage;
                     } else {
                         if ($_SESSION['glpiduedatewarning_unit'] == 'hour') {
                             $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP;
                             $less_warn = $totaltime - $currenttime;
                         } else {
                             if ($_SESSION['glpiduedatewarning_unit'] == 'day') {
                                 $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP;
                                 $less_warn = $totaltime - $currenttime;
                             }
                         }
                     }
                     if ($_SESSION['glpiduedatecritical_unit'] == '%') {
                         $less_crit_limit = $_SESSION['glpiduedatecritical_less'];
                         $less_crit = 100 - $percentage;
                     } else {
                         if ($_SESSION['glpiduedatecritical_unit'] == 'hour') {
                             $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP;
                             $less_crit = $totaltime - $currenttime;
                         } else {
                             if ($_SESSION['glpiduedatecritical_unit'] == 'day') {
                                 $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * DAY_TIMESTAMP;
                                 $less_crit = $totaltime - $currenttime;
                             }
                         }
                     }
                     $color = $_SESSION['glpiduedateok_color'];
                     if ($less_crit < $less_crit_limit) {
                         $color = $_SESSION['glpiduedatecritical_color'];
                     } else {
                         if ($less_warn < $less_warn_limit) {
                             $color = $_SESSION['glpiduedatewarning_color'];
                         }
                     }
                     //Calculate bar progress
                     $out .= "<div class='center' style='background-color: #ffffff; width: 100%;\n                            border: 1px solid #9BA563; position: relative;' >";
                     $out .= "<div style='position:absolute;'>&nbsp;" . $percentage_text . "%</div>";
                     $out .= "<div class='center' style='background-color: " . $color . ";\n                            width: " . $percentage . "%; height: 12px' ></div>";
                     $out .= "</div>";
                     return $out;
                 }
                 break;
             case "glpi_softwarelicenses.number":
                 if ($data[$num][0]['min'] == -1) {
                     return __('Unlimited');
                 }
                 if (empty($data[$num][0]['name'])) {
                     return 0;
                 }
                 return $data[$num][0]['name'];
             case "glpi_auth_tables.name":
                 return Auth::getMethodName($data[$num][0]['name'], $data[$num][0]['auths_id'], 1, $data[$num][0]['ldapname'] . $data[$num][0]['mailname']);
             case "glpi_reservationitems.comment":
                 if (empty($data[$num][0]['name'])) {
                     return "<a title=\"" . __s('Modify the comment') . "\"\n                           href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . __('None') . "</a>";
                 }
                 return "<a title=\"" . __s('Modify the comment') . "\"\n                        href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . Html::resume_text($data[$num][0]['name']) . "</a>";
             case 'glpi_crontasks.description':
                 $tmp = new CronTask();
                 return $tmp->getDescription($data[$num][0]['name']);
             case 'glpi_changes.status':
                 $status = Change::getStatus($data[$num][0]['name']);
                 return "<img src=\"" . Change::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
             case 'glpi_problems.status':
                 $status = Problem::getStatus($data[$num][0]['name']);
                 return "<img src=\"" . Problem::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
             case 'glpi_tickets.status':
                 $status = Ticket::getStatus($data[$num][0]['name']);
                 return "<img src=\"" . Ticket::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
             case 'glpi_projectstates.name':
                 $out = '';
                 $query = "SELECT `color`\n                         FROM `glpi_projectstates`\n                         WHERE `name` = '" . $data[$num][0]['name'] . "'";
                 foreach ($DB->request($query) as $color) {
                     $color = $color['color'];
                     $out = "<div style=\"background-color:" . $color . ";\">";
                     $name = $data[$num][0]['name'];
                     if (isset($data[$num][0]['trans'])) {
                         $name = $data[$num][0]['trans'];
                     }
                     if ($itemtype == 'ProjectState') {
                         $out .= "<a href='" . $CFG_GLPI["root_doc"] . "/front/projectstate.form.php?id=" . $data[$num][0]["id"] . "'>" . $name . "</a></div>";
                     } else {
                         $out .= $name . "</div>";
                     }
                 }
                 return $out;
             case 'glpi_items_tickets.items_id':
             case 'glpi_items_problems.items_id':
                 if (!empty($data[$num])) {
                     $items = array();
                     foreach ($data[$num] as $key => $val) {
                         if (is_numeric($key)) {
                             if (!empty($val['itemtype']) && ($item = getItemForItemtype($val['itemtype']))) {
                                 if ($item->getFromDB($val['name'])) {
                                     $items[] = $item->getLink(array('comments' => true));
                                 }
                             }
                         }
                     }
                     if (!empty($items)) {
                         return implode("<br>", $items);
                     }
                 }
                 return '&nbsp;';
             case 'glpi_items_tickets.itemtype':
             case 'glpi_items_problems.itemtype':
                 if (!empty($data[$num])) {
                     $itemtypes = array();
                     foreach ($data[$num] as $key => $val) {
                         if (is_numeric($key)) {
                             if (!empty($val['name'])) {
                                 if (substr($val['name'], 0, 6) == 'Plugin') {
                                     $plug = new $val['name']();
                                     $name = $plug->getTypeName();
                                     $itemtypes[] = __($name);
                                 } else {
                                     $itemtypes[] = __($val['name']);
                                 }
                             }
                         }
                     }
                     if (!empty($itemtypes)) {
                         return implode("<br>", $itemtypes);
                     }
                 }
                 return '&nbsp;';
             case 'glpi_tickets.name':
             case 'glpi_problems.name':
             case 'glpi_changes.name':
                 if (isset($data[$num][0]['content']) && isset($data[$num][0]['id']) && isset($data[$num][0]['status'])) {
                     $link = Toolbox::getItemTypeFormURL($itemtype);
                     $out = "<a id='{$itemtype}" . $data[$num][0]['id'] . "' href=\"" . $link;
                     $out .= strstr($link, '?') ? '&amp;' : '?';
                     $out .= 'id=' . $data[$num][0]['id'];
                     // Force solution tab if solved
                     if ($item = getItemForItemtype($itemtype)) {
                         if (in_array($data[$num][0]['status'], $item->getSolvedStatusArray())) {
                             $out .= "&amp;forcetab={$itemtype}\$2";
                         }
                     }
                     $out .= "\">";
                     $name = $data[$num][0]['name'];
                     if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) {
                         $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][0]['id']);
                     }
                     $out .= $name . "</a>";
                     $hdecode = Html::entity_decode_deep($data[$num][0]['content']);
                     $content = Toolbox::unclean_cross_side_scripting_deep($hdecode);
                     $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br(Html::Clean($content)), array('applyto' => $itemtype . $data[$num][0]['id'], 'display' => false)));
                     return $out;
                 }
             case 'glpi_ticketvalidations.status':
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if ($data[$num][$k]['name']) {
                         $status = TicketValidation::getStatus($data[$num][$k]['name']);
                         $bgcolor = TicketValidation::getStatusColor($data[$num][$k]['name']);
                         $out .= (empty($out) ? '' : self::LBBR) . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>';
                     }
                 }
                 return $out;
             case 'glpi_ticketsatisfactions.satisfaction':
                 if (self::$output_type == self::HTML_OUTPUT) {
                     return TicketSatisfaction::displaySatisfaction($data[$num][0]['name']);
                 }
                 break;
             case 'glpi_projects._virtual_planned_duration':
                 return Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($data["id"]), false);
             case 'glpi_projects._virtual_effective_duration':
                 return Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($data["id"]), false);
             case 'glpi_cartridgeitems._virtual':
                 return Cartridge::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT);
             case 'glpi_printers._virtual':
                 return Cartridge::getCountForPrinter($data["id"], self::$output_type != self::HTML_OUTPUT);
             case 'glpi_consumableitems._virtual':
                 return Consumable::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT);
             case 'glpi_links._virtual':
                 $out = '';
                 $link = new Link();
                 if (($item = getItemForItemtype($itemtype)) && $item->getFromDB($data['id']) && $link->getfromDB($data[$num][0]['id']) && $item->fields['entities_id'] == $link->fields['entities_id']) {
                     if (count($data[$num])) {
                         $count_display = 0;
                         foreach ($data[$num] as $val) {
                             if (is_array($val)) {
                                 $links = Link::getAllLinksFor($item, $val);
                                 foreach ($links as $link) {
                                     if ($count_display) {
                                         $out .= self::LBBR;
                                     }
                                     $out .= $link;
                                     $count_display++;
                                 }
                             }
                         }
                     }
                 }
                 return $out;
             case 'glpi_reservationitems._virtual':
                 if ($data[$num][0]['is_active']) {
                     return "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>";
                 } else {
                     return "&nbsp;";
                 }
         }
     }
     //// Default case
     // Link with plugin tables : need to know left join structure
     if (isset($table)) {
         if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) {
             if (count($matches) == 2) {
                 $plug = $matches[1];
                 $function = 'plugin_' . $plug . '_giveItem';
                 if (function_exists($function)) {
                     $out = $function($itemtype, $ID, $data, $num);
                     if (!empty($out)) {
                         return $out;
                     }
                 }
             }
         }
     }
     $unit = '';
     if (isset($searchopt[$ID]['unit'])) {
         $unit = $searchopt[$ID]['unit'];
     }
     // Preformat items
     if (isset($searchopt[$ID]["datatype"])) {
         switch ($searchopt[$ID]["datatype"]) {
             case "itemlink":
                 $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]);
                 $out = "";
                 $count_display = 0;
                 $separate = self::LBBR;
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = self::LBHR;
                 }
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (isset($data[$num][$k]['id'])) {
                         if ($count_display) {
                             $out .= $separate;
                         }
                         $count_display++;
                         $page = $linkitemtype::getFormUrl();
                         $page .= strpos($page, '?') ? '&id' : '?id';
                         $name = Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit);
                         if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][$k]['name'])) {
                             $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][$k]['id']);
                         }
                         $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $data[$num][$k]['id'] . "' href='{$page}=" . $data[$num][$k]['id'] . "'>" . $name . "</a>";
                     }
                 }
                 return $out;
             case "text":
                 $separate = self::LBBR;
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = self::LBHR;
                 }
                 $out = '';
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= $separate;
                         }
                         $count_display++;
                         $text = "";
                         if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) {
                             $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($data[$num][$k]['name'])));
                         } else {
                             $text = nl2br($data[$num][$k]['name']);
                         }
                         if (self::$output_type == self::HTML_OUTPUT && Toolbox::strlen($text) > $CFG_GLPI['cut']) {
                             $rand = mt_rand();
                             $out .= sprintf(__('%1$s %2$s'), "<span id='text{$rand}'>" . Html::resume_text($text, $CFG_GLPI['cut']) . '</span>', Html::showToolTip($text, array('applyto' => "text{$rand}", 'display' => false)));
                         } else {
                             $out .= $text;
                         }
                     }
                 }
                 return $out;
             case "date":
             case "date_delay":
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) {
                         $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel'];
                     } else {
                         $out .= (empty($out) ? '' : self::LBBR) . Html::convDate($data[$num][$k]['name']);
                     }
                 }
                 return $out;
             case "datetime":
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) {
                         $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel'];
                     } else {
                         $out .= (empty($out) ? '' : self::LBBR) . Html::convDateTime($data[$num][$k]['name']);
                     }
                 }
                 return $out;
             case "timestamp":
                 $withseconds = false;
                 if (isset($searchopt[$ID]['withseconds'])) {
                     $withseconds = $searchopt[$ID]['withseconds'];
                 }
                 $withdays = true;
                 if (isset($searchopt[$ID]['withdays'])) {
                     $withdays = $searchopt[$ID]['withdays'];
                 }
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($data[$num][$k]['name'], $withseconds, $withdays);
                 }
                 return $out;
             case "email":
                 $out = '';
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if ($count_display) {
                         $out .= self::LBBR;
                     }
                     $count_display++;
                     if (!empty($data[$num][$k]['name'])) {
                         $out .= empty($out) ? '' : self::LBBR;
                         $out .= "<a href='mailto:" . $data[$num][$k]['name'] . "'>" . $data[$num][$k]['name'];
                         $out .= "</a>";
                     }
                 }
                 return empty($out) ? "&nbsp;" : $out;
             case "weblink":
                 $orig_link = trim($data[$num][0]['name']);
                 if (!empty($orig_link)) {
                     // strip begin of link
                     $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link);
                     $link = preg_replace('/\\/$/', '', $link);
                     if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) {
                         $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "...";
                     }
                     return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>";
                 }
                 return "&nbsp;";
             case "count":
             case "number":
                 $out = "";
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= self::LBBR;
                         }
                         $count_display++;
                         if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                             $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                         } else {
                             $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$num][$k]['name'], false, 0));
                             $out .= Dropdown::getValueWithUnit($number, $unit);
                         }
                     }
                 }
                 return $out;
             case "decimal":
                 $out = "";
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= self::LBBR;
                         }
                         $count_display++;
                         if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                             $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                         } else {
                             $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$num][$k]['name']));
                             $out .= Dropdown::getValueWithUnit($number, $unit);
                         }
                     }
                 }
                 return $out;
             case "bool":
                 $out = "";
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= self::LBBR;
                         }
                         $count_display++;
                         $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$num][$k]['name']), $unit);
                     }
                 }
                 return $out;
             case "itemtypename":
                 if ($obj = getItemForItemtype($data[$num][0]['name'])) {
                     return $obj->getTypeName();
                 }
                 return "";
             case "language":
                 if (isset($CFG_GLPI['languages'][$data[$num][0]['name']])) {
                     return $CFG_GLPI['languages'][$data[$num][0]['name']][0];
                 }
                 return __('Default value');
         }
     }
     // Manage items with need group by / group_concat
     $out = "";
     $count_display = 0;
     $separate = self::LBBR;
     if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
         $separate = self::LBHR;
     }
     for ($k = 0; $k < $data[$num]['count']; $k++) {
         if (strlen(trim($data[$num][$k]['name'])) > 0) {
             if ($count_display) {
                 $out .= $separate;
             }
             $count_display++;
             // Get specific display if available
             $itemtype = getItemTypeForTable($table);
             if ($item = getItemForItemtype($itemtype)) {
                 $tmpdata = $data[$num][$k];
                 // Copy name to real field
                 $tmpdata[$field] = $data[$num][$k]['name'];
                 $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true, 'searchopt' => $searchopt[$ID]));
             }
             if (!empty($specific)) {
                 $out .= $specific;
             } else {
                 if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                     $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                 } else {
                     // Empty is 0 or empty
                     if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) {
                         $out .= $searchopt[$ID]['emptylabel'];
                     } else {
                         // Trans field exists
                         if (isset($data[$num][$k]['trans']) && !empty($data[$num][$k]['trans'])) {
                             $out .= Dropdown::getValueWithUnit($data[$num][$k]['trans'], $unit);
                         } else {
                             $out .= Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit);
                         }
                     }
                 }
             }
         }
     }
     return $out;
     // Trans in group concat
     if (count($split) == 3 && !empty($split[1])) {
         return Dropdown::getValueWithUnit($split[1], $unit);
     }
     return Dropdown::getValueWithUnit($split[0], $unit);
 }
 /**
  * Show projet associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated projet must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_projet_haveRight('projet', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginProjetProjet');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_projet_projets`.`name` AS assocName,\n                       `glpi_plugin_projet_projets`.*\n                FROM `glpi_plugin_projet_projets_items`\n                LEFT JOIN `glpi_plugin_projet_projets`\n                 ON (`glpi_plugin_projet_projets_items`.`plugin_projet_projets_id`=`glpi_plugin_projet_projets`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_projet_projets`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_projet_projets_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_projet_projets", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $projets = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $projets[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $projet = new PluginProjetProjet();
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_projet_projets`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_projet_haveRight('projet', 'r') && $nb > count($used)) {
             echo "<form name='projet_form{$rand}' id='projet_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             if ($item->getType() != 'User') {
                 $projet->dropdownProjet("plugin_projet_projets_id", $entities, $used);
             } else {
                 $strict_entities = Profile_User::getUserEntities($ID, true);
                 if (!Session::haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) {
                     $canedit = false;
                 }
                 if (countElementsInTableForEntity("glpi_plugin_projet_projets", $strict_entities) > count($used)) {
                     Dropdown::show('PluginProjetProjet', array('name' => "plugin_projet_projets_id", 'used' => $used, 'entity' => $strict_entities));
                 }
             }
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a project', 'projet') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($item->getType() == "Group" || $item->getType() == "User") {
         echo "<tr><th colspan='" . (7 + $colsup) . "'>" . _n('Associated project', 'Associated projects', 2, 'projet') . ":</th></tr>";
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Description') . "</th>";
     echo "<th>" . __('Progress') . "</th>";
     echo "<th>" . __('Start date') . "</th>";
     echo "<th>" . __('End date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginProjetProjet', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($projets as $data) {
             $projetID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($projet->getFromDB($projetID)) {
                 $link = $projet->getLink();
             }
             Session::addToNavigateListItems('PluginProjetProjet', $projetID);
             $used[$projetID] = $projetID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
             echo "<td align='center'>" . PluginProjetProjet::displayProgressBar('100', $data["advance"]) . "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_begin"]) . "</td>";
             if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) {
                 echo "<td class='center'><span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>";
             } else {
                 echo "<td class='center'><span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>";
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemple #8
0
 /**
  * Display a Planning Item
  *
  * @since version 9.1
  *
  * @param $val       array of the item to display
  * @param $who             ID of the user (0 if all)
  * @param $type            position of the item in the time block (in, through, begin or end)
  *                         (default '')
  * @param $complete        complete display (more details) (default 0)
  *
  * @return Nothing (display function)
  **/
 static function displayPlanningItem(array $val, $who, $type = "", $complete = 0)
 {
     global $CFG_GLPI;
     $html = "";
     $rand = mt_rand();
     $users_id = "";
     // show users_id project task
     $img = "rdv_private.png";
     // default icon for project task
     if ($val["users_id"] != Session::getLoginUserID()) {
         $users_id = "<br>" . sprintf(__('%1$s: %2$s'), __('By'), getUserName($val["users_id"]));
         $img = "rdv_public.png";
     }
     $html .= "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . $img . "' alt='' title=\"" . self::getTypeName(1) . "\">&nbsp;";
     $html .= "<a id='project_task_" . $val["id"] . $rand . "' href='" . $CFG_GLPI["root_doc"] . "/front/projecttask.form.php?id=" . $val["id"] . "'>";
     switch ($type) {
         case "in":
             //TRANS: %1$s is the start time of a planned item, %2$s is the end
             $beginend = sprintf(__('From %1$s to %2$s'), date("H:i", strtotime($val["begin"])), date("H:i", strtotime($val["end"])));
             $html .= sprintf(__('%1$s: %2$s'), $beginend, Html::resume_text($val["name"], 80));
             break;
         case "through":
             $html .= Html::resume_text($val["name"], 80);
             break;
         case "begin":
             $start = sprintf(__('Start at %s'), date("H:i", strtotime($val["begin"])));
             $html .= sprintf(__('%1$s: %2$s'), $start, Html::resume_text($val["name"], 80));
             break;
         case "end":
             $end = sprintf(__('End at %s'), date("H:i", strtotime($val["end"])));
             $html .= sprintf(__('%1$s: %2$s'), $end, Html::resume_text($val["name"], 80));
             break;
     }
     $html .= $users_id;
     $html .= "</a>";
     $html .= "<div class='b'>" . $val["status"] . " % completed</div>";
     $html .= "<div class='event-description'>" . html_entity_decode($val["content"]) . "</div>";
     return $html;
 }
Exemple #9
0
 /**
  * Display a Planning Item
  *
  * @param $val Array of the item to display
  *
  * @return Already planned information
  **/
 static function getAlreadyPlannedInformation(array $val)
 {
     global $CFG_GLPI;
     //TRANS: %1$s is the begin date, %2$s is the end date
     $beginend = sprintf(__('From %1$s to %2$s'), Html::convDateTime($val["begin"]), Html::convDateTime($val["end"]));
     $out = sprintf(__('%1$s: %2$s'), $beginend, "<a href='" . $CFG_GLPI["root_doc"] . "/front/reminder.form.php?id=" . $val["reminders_id"] . "'>" . Html::resume_text($val["name"], 80) . "</a>");
     return $out;
 }
 /**
  * Generic Function to display Items
  *
  * @param $itemtype              item type
  * @param $ID                    ID of the SEARCH_OPTION item
  * @param $data            array containing data results
  * @param $num                   item num in the request
  * @param $meta                  is a meta item ? (default 0)
  * @param $addobjectparams array added parameters for union search
  *
  * @return string to print
  **/
 static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array())
 {
     global $CFG_GLPI;
     $showuserlink = 0;
     if (Session::haveRight('user', READ)) {
         $showuserlink = 1;
     }
     $searchopt =& self::getOptions($itemtype);
     if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) {
         if (isset($searchopt[$ID]['addobjectparams']) && $searchopt[$ID]['addobjectparams']) {
             return self::giveItem($data["TYPE"], $ID, $data, $num, $meta, $searchopt[$ID]['addobjectparams']);
         }
         return self::giveItem($data["TYPE"], $ID, $data, $num, $meta);
     }
     if (count($addobjectparams)) {
         $searchopt[$ID] = array_merge($searchopt[$ID], $addobjectparams);
     }
     // Plugin can override core definition for its type
     if ($plug = isPluginItemType($itemtype)) {
         $function = 'plugin_' . $plug['plugin'] . '_giveItem';
         if (function_exists($function)) {
             $out = $function($itemtype, $ID, $data, $num);
             if (!empty($out)) {
                 return $out;
             }
         }
     }
     $NAME = "ITEM_";
     if ($meta) {
         $NAME = "META_";
     }
     $table = $searchopt[$ID]["table"];
     $field = $searchopt[$ID]["field"];
     $linkfield = $searchopt[$ID]["linkfield"];
     /// TODO try to clean all specific cases using SpecificToDisplay
     switch ($table . '.' . $field) {
         case "glpi_users.name":
             // USER search case
             if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) {
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $count_display = 0;
                 $added = array();
                 for ($k = 0; $k < count($split); $k++) {
                     if ($split[$k] > 0) {
                         if ($count_display) {
                             $out .= "<br>";
                         }
                         $count_display++;
                         if ($itemtype == 'Ticket') {
                             $userdata = getUserName($split[$k], 2);
                             $tooltip = "";
                             if (Session::haveRight('user', READ)) {
                                 $tooltip = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                             }
                             $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip);
                         } else {
                             $out .= getUserName($split[$k], $showuserlink);
                         }
                     }
                 }
                 // Manage alternative_email for tickets_users
                 if ($itemtype == 'Ticket' && isset($data[$NAME . $num . '_2'])) {
                     $split = explode("\$\$\$\$", $data[$NAME . $num . '_2']);
                     for ($k = 0; $k < count($split); $k++) {
                         $split2 = explode(" ", $split[$k]);
                         if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>";
                         }
                     }
                 }
                 return $out;
             }
             if ($itemtype != 'User') {
                 $toadd = '';
                 if ($itemtype == 'Ticket' && $data[$NAME . $num . "_3"] > 0) {
                     $userdata = getUserName($data[$NAME . $num . "_3"], 2);
                     $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                 }
                 if (Session::haveRight('user', READ)) {
                     $usernameformat = formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 1);
                 } else {
                     $usernameformat = formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 0);
                 }
                 return sprintf(__('%1$s %2$s'), $usernameformat, $toadd);
             }
             break;
         case "glpi_profiles.interface":
             return Profile::getInterfaceName($data[$NAME . $num]);
         case "glpi_profiles.name":
             if ($itemtype == 'User' && $ID == 20) {
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
                 $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]);
                 $split4 = explode("\$\$\$\$", $data[$NAME . $num . "_4"]);
                 $count_display = 0;
                 $added = array();
                 for ($k = 0; $k < count($split); $k++) {
                     if (strlen(trim($split[$k])) > 0) {
                         $text = sprintf(__('%1$s - %2$s'), $split[$k], Dropdown::getDropdownName('glpi_entities', $split2[$k]));
                         $comp = '';
                         if ($split3[$k]) {
                             $comp = __(READ);
                             if ($split4[$k]) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                             }
                         }
                         if ($split4[$k]) {
                             $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                         }
                         if (!empty($comp)) {
                             $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                         }
                         if (!in_array($text, $added)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $text;
                             $added[] = $text;
                         }
                     }
                 }
                 return $out;
             }
             break;
         case "glpi_entities.completename":
             if ($itemtype == 'User') {
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
                 $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]);
                 $split4 = explode("\$\$\$\$", $data[$NAME . $num . "_4"]);
                 $added = array();
                 $count_display = 0;
                 for ($k = 0; $k < count($split); $k++) {
                     if (strlen(trim($split[$k])) > 0) {
                         $text = sprintf(__('%1$s - %2$s'), $split[$k], Dropdown::getDropdownName('glpi_profiles', $split2[$k]));
                         $comp = '';
                         if ($split3[$k]) {
                             $comp = __(READ);
                             if ($split4[$k]) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                             }
                         }
                         if ($split4[$k]) {
                             $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                         }
                         if (!empty($comp)) {
                             $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                         }
                         if (!in_array($text, $added)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $text;
                             $added[] = $text;
                         }
                     }
                 }
                 return $out;
             }
             break;
         case "glpi_documenttypes.icon":
             if (!empty($data[$NAME . $num])) {
                 return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$NAME . $num] . "'>";
             }
             return "&nbsp;";
         case "glpi_documents.filename":
             $doc = new Document();
             if ($doc->getFromDB($data['id'])) {
                 return $doc->getDownloadLink();
             }
             return NOT_AVAILABLE;
         case "glpi_deviceharddrives.specificity":
         case "glpi_devicememories.specificity":
         case "glpi_deviceprocessors.specificity":
             return $data[$NAME . $num];
         case "glpi_networkports.mac":
             $out = "";
             if ($itemtype == 'Computer') {
                 $displayed = array();
                 if (!empty($data[$NAME . $num . "_2"])) {
                     $split = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         $lowstr = Toolbox::strtolower($split[$k]);
                         if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $split[$k];
                             $displayed[] = $lowstr;
                         }
                     }
                     if (!empty($data[$NAME . $num])) {
                         $out .= "<br>";
                     }
                 }
                 if (!empty($data[$NAME . $num])) {
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         $lowstr = Toolbox::strtolower($split[$k]);
                         if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $split[$k];
                             $displayed[] = $lowstr;
                         }
                     }
                 }
                 return $out;
             }
             break;
         case "glpi_contracts.duration":
         case "glpi_contracts.notice":
         case "glpi_contracts.periodicity":
         case "glpi_contracts.billing":
             if (!empty($data[$NAME . $num])) {
                 $split = explode('$$$$', $data[$NAME . $num]);
                 $output = "";
                 foreach ($split as $duration) {
                     $output .= (empty($output) ? '' : '<br>') . sprintf(_n('%d month', '%d months', $duration), $duration);
                 }
                 return $output;
             }
             return "&nbsp;";
         case "glpi_contracts.renewal":
             return Contract::getContractRenewalName($data[$NAME . $num]);
             //          case "glpi_infocoms.sink_time" :
             //             if (!empty($data[$NAME.$num])) {
             //                $split = explode("$$$$", $data[$NAME.$num]);
             //                $out   = '';
             //                foreach ($split as $val) {
             //                   $out .= (empty($out)?'':'<br>');
             //                   if ($val > 0) {
             //                      //TRANS: %d is a number of years
             //                      $out .= sprintf(_n('%d year', '%d years', $val), $val);
             //                   }
             //                }
             //                return $out;
             //             }
             //             return "&nbsp;";
             //
             //          case "glpi_infocoms.warranty_duration" :
             //             if (!empty($data[$NAME.$num])) {
             //                $split = explode("$$$$", $data[$NAME.$num]);
             //                $out   = '';
             //                foreach ($split as $val) {
             //                   $out .= (empty($out)?'':'<br>');
             //                   if ($val > 0) {
             //                      $out .= sprintf(_n('%d month', '%d months', $val), $val);
             //                   }
             //                   if ($val < 0) {
             //                      $out .= __('Lifelong');
             //                   }
             //                }
             //                return $out;
             //             }
             //             return "&nbsp;";
         //          case "glpi_infocoms.sink_time" :
         //             if (!empty($data[$NAME.$num])) {
         //                $split = explode("$$$$", $data[$NAME.$num]);
         //                $out   = '';
         //                foreach ($split as $val) {
         //                   $out .= (empty($out)?'':'<br>');
         //                   if ($val > 0) {
         //                      //TRANS: %d is a number of years
         //                      $out .= sprintf(_n('%d year', '%d years', $val), $val);
         //                   }
         //                }
         //                return $out;
         //             }
         //             return "&nbsp;";
         //
         //          case "glpi_infocoms.warranty_duration" :
         //             if (!empty($data[$NAME.$num])) {
         //                $split = explode("$$$$", $data[$NAME.$num]);
         //                $out   = '';
         //                foreach ($split as $val) {
         //                   $out .= (empty($out)?'':'<br>');
         //                   if ($val > 0) {
         //                      $out .= sprintf(_n('%d month', '%d months', $val), $val);
         //                   }
         //                   if ($val < 0) {
         //                      $out .= __('Lifelong');
         //                   }
         //                }
         //                return $out;
         //             }
         //             return "&nbsp;";
         case "glpi_infocoms.sink_type":
             $split = explode("\$\$\$\$", $data[$NAME . $num]);
             $out = '';
             foreach ($split as $val) {
                 $out .= (empty($out) ? '' : '<br>') . Infocom::getAmortTypeName($val);
             }
             return $out;
         case "glpi_infocoms.alert":
             if ($data[$NAME . $num] == pow(2, Alert::END)) {
                 return __s('Warranty expiration date');
             }
             return "";
         case "glpi_contracts.alert":
             switch ($data[$NAME . $num]) {
                 case pow(2, Alert::END):
                     return __('End');
                 case pow(2, Alert::NOTICE):
                     return __('Notice');
                 case pow(2, Alert::END) + pow(2, Alert::NOTICE):
                     return __('End + Notice');
             }
             return "";
         case "glpi_tickets_tickets.tickets_id_1":
             $out = "";
             $split = explode("\$\$\$\$", $data[$NAME . $num]);
             $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
             $displayed = array();
             for ($k = 0; $k < count($split); $k++) {
                 $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split[$k];
                 if ($linkid > 0 && !isset($displayed[$linkid])) {
                     $text = "<a ";
                     $text .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id={$linkid}\">";
                     $text .= Dropdown::getDropdownName('glpi_tickets', $linkid) . "</a>";
                     if (count($displayed)) {
                         $out .= "<br>";
                     }
                     $displayed[$linkid] = $linkid;
                     $out .= $text;
                 }
             }
             return $out;
         case "glpi_problems.count":
             if ($data[$NAME . $num] > 0 && Session::haveRight("problem", Problem::READALL)) {
                 if ($itemtype == 'ITILCategory') {
                     $options['field'][0] = 7;
                     $options['searchtype'][0] = 'equals';
                     $options['contains'][0] = $data['id'];
                     $options['link'][0] = 'AND';
                 }
                 $options['reset'] = 'reset';
                 $out = "<a id='problem{$itemtype}" . $data['id'] . "' ";
                 $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/problem.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                 $out .= $data[$NAME . $num] . "</a>";
             } else {
                 $out = $data[$NAME . $num];
             }
             return $out;
         case "glpi_tickets.count":
             if ($data[$NAME . $num] > 0 && Session::haveRight("ticket", Ticket::READALL)) {
                 if ($itemtype == 'User') {
                     $options['field'][0] = 4;
                     $options['searchtype'][0] = 'equals';
                     $options['contains'][0] = $data['id'];
                     $options['link'][0] = 'AND';
                     $options['field'][1] = 22;
                     $options['searchtype'][1] = 'equals';
                     $options['contains'][1] = $data['id'];
                     $options['link'][1] = 'OR';
                     $options['field'][2] = 5;
                     $options['searchtype'][2] = 'equals';
                     $options['contains'][2] = $data['id'];
                     $options['link'][2] = 'OR';
                 } else {
                     if ($itemtype == 'ITILCategory') {
                         $options['field'][0] = 7;
                         $options['searchtype'][0] = 'equals';
                         $options['contains'][0] = $data['id'];
                         $options['link'][0] = 'AND';
                     } else {
                         $options['field'][0] = 12;
                         $options['searchtype'][0] = 'equals';
                         $options['contains'][0] = 'all';
                         $options['link'][0] = 'AND';
                         $options['itemtype2'][0] = $itemtype;
                         $options['field2'][0] = self::getOptionNumber($itemtype, 'name');
                         $options['searchtype2'][0] = 'equals';
                         $options['contains2'][0] = $data['id'];
                         $options['link2'][0] = 'AND';
                     }
                 }
                 $options['reset'] = 'reset';
                 $out = "<a id='ticket{$itemtype}" . $data['id'] . "' ";
                 $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                 $out .= $data[$NAME . $num] . "</a>";
             } else {
                 $out = $data[$NAME . $num];
             }
             return $out;
         case "glpi_tickets.due_date":
             // Due date + progress
             if ($ID == 151) {
                 $out = Html::convDate($data[$NAME . $num]);
                 // No due date in waiting status
                 if ($data[$NAME . $num . '_2'] == CommonITILObject::WAITING) {
                     return '';
                 }
                 if (empty($data[$NAME . $num])) {
                     return '';
                 }
                 if ($data[$NAME . $num . '_2'] == Ticket::SOLVED || $data[$NAME . $num . '_2'] == Ticket::CLOSED) {
                     return $data[$NAME . $num];
                 }
                 $ticket = new Ticket();
                 $ticket->getFromDB($data['ITEM_0']);
                 $percentage = 0;
                 $totaltime = 0;
                 $currenttime = 0;
                 if ($ticket->fields['slas_id'] != 0) {
                     // Have SLA
                     $sla = new SLA();
                     $sla->getFromDB($ticket->fields['slas_id']);
                     $currenttime = $sla->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s'));
                     $totaltime = $sla->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]);
                 } else {
                     $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
                     if ($calendars_id != 0) {
                         // Ticket entity have calendar
                         $calendar = new Calendar();
                         $calendar->getFromDB($calendars_id);
                         $currenttime = $calendar->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s'));
                         $totaltime = $calendar->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]);
                     } else {
                         // No calendar
                         $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($ticket->fields['date']);
                         $totaltime = strtotime($data[$NAME . $num]) - strtotime($ticket->fields['date']);
                     }
                 }
                 if ($totaltime != 0) {
                     $percentage = round(100 * $currenttime / $totaltime);
                 } else {
                     // Total time is null : no active time
                     $percentage = 100;
                 }
                 if ($percentage > 100) {
                     $percentage = 100;
                 }
                 $percentage_text = $percentage;
                 if ($_SESSION['glpiduedatewarning_unit'] == '%') {
                     $less_warn_limit = $_SESSION['glpiduedatewarning_less'];
                     $less_warn = 100 - $percentage;
                 } else {
                     if ($_SESSION['glpiduedatewarning_unit'] == 'hours') {
                         $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP;
                         $less_warn = $totaltime - $currenttime;
                     } else {
                         if ($_SESSION['glpiduedatewarning_unit'] == 'days') {
                             $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP;
                             $less_warn = $totaltime - $currenttime;
                         }
                     }
                 }
                 if ($_SESSION['glpiduedatecritical_unit'] == '%') {
                     $less_crit_limit = $_SESSION['glpiduedatecritical_less'];
                     $less_crit = 100 - $percentage;
                 } else {
                     if ($_SESSION['glpiduedatecritical_unit'] == 'hours') {
                         $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP;
                         $less_crit = $totaltime - $currenttime;
                     } else {
                         if ($_SESSION['glpiduedatecritical_unit'] == 'days') {
                             $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * DAY_TIMESTAMP;
                             $less_crit = $totaltime - $currenttime;
                         }
                     }
                 }
                 $color = $_SESSION['glpiduedateok_color'];
                 if ($less_crit < $less_crit_limit) {
                     $color = $_SESSION['glpiduedatecritical_color'];
                 } else {
                     if ($less_warn < $less_warn_limit) {
                         $color = $_SESSION['glpiduedatewarning_color'];
                     }
                 }
                 //Calculate bar progress
                 $out .= "<div class='center' style='background-color: #ffffff; width: 100%;\n                         border: 1px solid #9BA563;' >";
                 $out .= "<div style='position:absolute;'>&nbsp;" . $percentage_text . "%</div>";
                 $out .= "<div class='center' style='background-color: " . $color . ";\n                         width: " . $percentage . "%; height: 12px' ></div>";
                 $out .= "</div>";
                 return $out;
             }
             break;
         case "glpi_softwarelicenses.number":
             if ($data[$NAME . $num . "_2"] == -1) {
                 return __('Unlimited');
             }
             if (empty($data[$NAME . $num])) {
                 return 0;
             }
             return $data[$NAME . $num];
         case "glpi_auth_tables.name":
             return Auth::getMethodName($data[$NAME . $num], $data[$NAME . $num . "_2"], 1, $data[$NAME . $num . "_3"] . $data[$NAME . $num . "_4"]);
         case "glpi_reservationitems.comment":
             if (empty($data[$NAME . $num])) {
                 return "<a title=\"" . __s('Modify the comment') . "\"\n                        href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . __('None') . "</a>";
             }
             return "<a title=\"" . __s('Modify the comment') . "\"\n                     href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . Html::resume_text($data[$NAME . $num]) . "</a>";
         case 'glpi_notifications.mode':
             return Notification::getMode($data[$NAME . $num]);
         case 'glpi_notifications.event':
             $item = NotificationTarget::getInstanceByType($data['itemtype']);
             if ($item) {
                 $events = $item->getAllEvents();
                 if (isset($events[$data[$NAME . $num]])) {
                     return $events[$data[$NAME . $num]];
                 }
             }
             return '';
         case 'glpi_reminders.state':
             return Planning::getState($data[$NAME . $num]);
         case 'glpi_crontasks.description':
             $tmp = new CronTask();
             return $tmp->getDescription($data['id']);
         case 'glpi_crontasks.state':
             return CronTask::getStateName($data[$NAME . $num]);
         case 'glpi_crontasks.mode':
             return CronTask::getModeName($data[$NAME . $num]);
         case 'glpi_crontasks.itemtype':
             if ($plug = isPluginItemType($data[$NAME . $num])) {
                 return $plug['plugin'];
             }
             return '';
         case 'glpi_changes.status':
             $status = Change::getStatus($data[$NAME . $num]);
             return "<img src=\"" . Change::getStatusIconURL($data[$NAME . $num]) . "\"\n                     alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
         case 'glpi_problems.status':
             $status = Problem::getStatus($data[$NAME . $num]);
             return "<img src=\"" . Problem::getStatusIconURL($data[$NAME . $num]) . "\"\n                     alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
         case 'glpi_tickets.status':
             $status = Ticket::getStatus($data[$NAME . $num]);
             return "<img src=\"" . Ticket::getStatusIconURL($data[$NAME . $num]) . "\"\n                     alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
         case 'glpi_tickets.items_id':
             if (!empty($data[$NAME . $num . "_2"]) && ($item = getItemForItemtype($data[$NAME . $num . "_2"]))) {
                 if ($item->getFromDB($data[$NAME . $num])) {
                     return $item->getLink(array('comments' => true));
                 }
             }
             return '&nbsp;';
         case 'glpi_tickets.name':
             if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 $link = Toolbox::getItemTypeFormURL('Ticket');
                 foreach ($split as $val) {
                     if (!empty($val)) {
                         $split2 = self::explodeWithID("\$\$", $val);
                         $out .= "<a id='ticket" . $split2[1] . "' href=\"" . $link;
                         $out .= strstr($link, '?') ? '&amp;' : '?';
                         $out .= 'id=' . $split2[1];
                         $out .= "\">";
                         $name = $split2[0];
                         if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) {
                             $name = sprintf(__('%1$s (%2$s)'), $name, $split2[1]);
                         }
                         $out .= $name . "</a><br>";
                     }
                 }
                 return $out;
             }
             $link = Toolbox::getItemTypeFormURL('Ticket');
             $out = "<a id='ticket" . $data[$NAME . $num . "_2"] . "' href=\"" . $link;
             $out .= strstr($link, '?') ? '&amp;' : '?';
             $out .= 'id=' . $data[$NAME . $num . "_2"];
             // Force solution tab if solved
             if ($data[$NAME . $num . "_4"] == CommonITILObject::SOLVED) {
                 $out .= "&amp;forcetab=Ticket\$2";
             }
             $out .= "\">";
             $name = $data[$NAME . $num];
             if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) {
                 $name = sprintf(__('%1$s (%2$s)'), $name, $data[$NAME . $num . "_2"]);
             }
             $out .= $name . "</a>";
             $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br($data[$NAME . $num . "_3"]), array('applyto' => 'ticket' . $data[$NAME . $num . "_2"], 'display' => false)));
             return $out;
         case 'glpi_ticketvalidations.status':
             $split = explode("\$\$\$\$", $data[$NAME . $num]);
             $out = '';
             foreach ($split as $val) {
                 if (!empty($val)) {
                     $split2 = self::explodeWithID("\$\$", $val);
                     $status = TicketValidation::getStatus($split2[0]);
                     $bgcolor = TicketValidation::getStatusColor($split2[0]);
                     $out .= (empty($out) ? '' : '<br>') . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>';
                 }
             }
             return $out;
         case 'glpi_ticketsatisfactions.type':
             return TicketSatisfaction::getTypeInquestName($data[$NAME . $num]);
         case 'glpi_ticketsatisfactions.satisfaction':
             return TicketSatisfaction::displaySatisfaction($data[$NAME . $num]);
         case 'glpi_notimportedemails.reason':
             return NotImportedEmail::getReason($data[$NAME . $num]);
         case 'glpi_notimportedemails.messageid':
             $clean = array('<' => '', '>' => '');
             return strtr($data[$NAME . $num], $clean);
     }
     //// Default case
     // Link with plugin tables : need to know left join structure
     if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) {
         if (count($matches) == 2) {
             $plug = $matches[1];
             $function = 'plugin_' . $plug . '_giveItem';
             if (function_exists($function)) {
                 $out = $function($itemtype, $ID, $data, $num);
                 if (!empty($out)) {
                     return $out;
                 }
             }
         }
     }
     $unit = '';
     if (isset($searchopt[$ID]['unit'])) {
         $unit = $searchopt[$ID]['unit'];
     }
     /// TODO try to use getvalueToDisplay instead of redefine display system
     // Preformat items
     if (isset($searchopt[$ID]["datatype"])) {
         switch ($searchopt[$ID]["datatype"]) {
             case "itemlink":
                 $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]);
                 if (isset($data[$NAME . $num . "_2"]) && strlen($data[$NAME . $num . "_2"])) {
                     $link = Toolbox::getItemTypeFormURL($linkitemtype);
                     $out = "<a id='" . $itemtype . "_" . $data[$NAME . $num . "_2"] . "' href=\"" . $link;
                     $out .= strstr($link, '?') ? '&amp;' : '?';
                     $out .= 'id=' . $data[$NAME . $num . "_2"];
                     if (isset($searchopt[$ID]['forcetab'])) {
                         $out .= "&amp;forcetab=" . $searchopt[$ID]['forcetab'];
                     }
                     $out .= "\">";
                     $name = Dropdown::getValueWithUnit($data[$NAME . $num], $unit);
                     if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) {
                         $name = sprintf(__('%1$s (%2$s)'), $name, $data[$NAME . $num . "_2"]);
                     }
                     $out .= $name . "</a>";
                     return $out;
                 }
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $count_display = 0;
                 $separate = '<br>';
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = '<hr>';
                 }
                 for ($k = 0; $k < count($split); $k++) {
                     if (strlen(trim($split[$k])) > 0) {
                         $split2 = self::explodeWithID("\$\$", $split[$k]);
                         if (isset($split2[1]) && $split2[1] > 0) {
                             if ($count_display) {
                                 $out .= $separate;
                             }
                             $count_display++;
                             $page = Toolbox::getItemTypeFormURL($linkitemtype);
                             $page .= strpos($page, '?') ? '&id' : '?id';
                             $name = Dropdown::getValueWithUnit($split2[0], $unit);
                             if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) {
                                 $name = sprintf(__('%1$s (%2$s)'), $name, $split2[1]);
                             }
                             $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $split2[1] . "' href='{$page}=" . $split2[1] . "'>" . $name . "</a>";
                         }
                     }
                 }
                 return $out;
             case "text":
                 $separate = '<br>';
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = '<hr>';
                 }
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 $count_display = 0;
                 foreach ($split as $val) {
                     if (strlen(trim($val)) > 0) {
                         $split2 = self::explodeWithID("\$\$", $val);
                         if ($count_display) {
                             $out .= $separate;
                         }
                         $count_display++;
                         if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) {
                             $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($split2[0])));
                         } else {
                             $text = nl2br($split2[0]);
                         }
                         if (self::$output_type == self::HTML_OUTPUT && Toolbox::strlen($text) > $CFG_GLPI['cut']) {
                             $rand = mt_rand();
                             $out .= sprintf(__('%1$s %2$s'), "<span id='text{$rand}'>" . Html::resume_text($text, $CFG_GLPI['cut']) . '</span>', Html::showToolTip($text, array('applyto' => "text{$rand}", 'display' => false)));
                         } else {
                             $out .= $text;
                         }
                     }
                 }
                 return $out;
             case "date":
             case "date_delay":
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 foreach ($split as $val) {
                     $out .= (empty($out) ? '' : '<br>') . Html::convDate($val);
                 }
                 return $out;
             case "datetime":
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 foreach ($split as $val) {
                     $out .= (empty($out) ? '' : '<br>') . Html::convDateTime($val);
                 }
                 return $out;
             case "timestamp":
                 $withseconds = false;
                 if (isset($searchopt[$ID]['withseconds'])) {
                     $withseconds = $searchopt[$ID]['withseconds'];
                 }
                 $withdays = true;
                 if (isset($searchopt[$ID]['withdays'])) {
                     $withdays = $searchopt[$ID]['withdays'];
                 }
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 foreach ($split as $val) {
                     $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($val, $withseconds, $withdays);
                 }
                 return $out;
             case "email":
                 $split = explode('$$$$', $data[$NAME . $num]);
                 $out = '';
                 $count_display = 0;
                 foreach ($split as $val) {
                     $split2 = self::explodeWithID("\$\$", $val);
                     if ($count_display) {
                         $out .= "<br>";
                     }
                     $count_display++;
                     if (!empty($val)) {
                         $out .= empty($out) ? '' : '<br>';
                         $out .= "<a href='mailto:{$split2['0']}'>{$split2['0']}</a>";
                     }
                 }
                 return empty($out) ? "&nbsp;" : $out;
             case "weblink":
                 $orig_link = trim($data[$NAME . $num]);
                 if (!empty($orig_link)) {
                     // strip begin of link
                     $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link);
                     $link = preg_replace('/\\/$/', '', $link);
                     if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) {
                         $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "...";
                     }
                     return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>";
                 }
                 return "&nbsp;";
             case "number":
                 if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                     $out = "";
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         if (strlen(trim($split[$k])) > 0) {
                             $split2 = self::explodeWithID("\$\$", $split[$k]);
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split2[0]])) {
                                 $out .= $searchopt[$ID]['toadd'][$split2[0]];
                             } else {
                                 $number = str_replace(' ', '&nbsp;', Html::formatNumber($split2[0], false, 0));
                                 $out .= Dropdown::getValueWithUnit($number, $unit);
                             }
                         }
                     }
                     return $out;
                 }
                 if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$NAME . $num]])) {
                     return $searchopt[$ID]['toadd'][$data[$NAME . $num]];
                 } else {
                     $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$NAME . $num], false, 0));
                     return Dropdown::getValueWithUnit($number, $unit);
                 }
             case "decimal":
                 if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                     $out = "";
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         if (strlen(trim($split[$k])) > 0) {
                             $split2 = self::explodeWithID("\$\$", $split[$k]);
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split2[0]])) {
                                 $out .= $searchopt[$ID]['toadd'][$split2[0]];
                             } else {
                                 $number = str_replace(' ', '&nbsp;', Html::formatNumber($split2[0]));
                                 $out .= Dropdown::getValueWithUnit($number, $unit);
                             }
                         }
                     }
                     return $out;
                 }
                 $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$NAME . $num]));
                 return Dropdown::getValueWithUnit($number, $unit);
             case "bool":
                 if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                     $out = "";
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         if (strlen(trim($split[$k])) > 0) {
                             $split2 = self::explodeWithID("\$\$", $split[$k]);
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($split2[0]), $unit);
                         }
                     }
                     return $out;
                 }
                 return Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$NAME . $num]), $unit);
             case "right":
                 return Profile::getRightValue($data[$NAME . $num]);
             case "itemtypename":
                 if ($obj = getItemForItemtype($data[$NAME . $num])) {
                     return $obj->getTypeName();
                 }
                 return "";
             case "language":
                 if (isset($CFG_GLPI['languages'][$data[$NAME . $num]])) {
                     return $CFG_GLPI['languages'][$data[$NAME . $num]][0];
                 }
                 return __('Default value');
         }
     }
     // Manage items with need group by / group_concat
     if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
         $out = "";
         $split = explode("\$\$\$\$", $data[$NAME . $num]);
         $count_display = 0;
         $separate = '<br>';
         if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
             $separate = '<hr>';
         }
         for ($k = 0; $k < count($split); $k++) {
             if (strlen(trim($split[$k])) > 0) {
                 if ($count_display) {
                     $out .= $separate;
                 }
                 $withoutid = self::explodeWithID("\$\$", $split[$k]);
                 $count_display++;
                 // Get specific display if available
                 $itemtype = getItemTypeForTable($table);
                 if ($item = getItemForItemtype($itemtype)) {
                     $tmpdata = array($field => $withoutid[0]);
                     $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true));
                 }
                 if (!empty($specific)) {
                     $out .= $specific;
                 } else {
                     $out .= Dropdown::getValueWithUnit($withoutid[0], $unit);
                 }
             }
         }
         return $out;
     }
     // Get specific display if available
     $itemtype = getItemTypeForTable($table);
     if ($item = getItemForItemtype($itemtype)) {
         $tmpdata = array($field => $data[$NAME . $num]);
         if (isset($searchopt[$ID]['additionalfields']) && count($searchopt[$ID]['additionalfields'])) {
             foreach ($searchopt[$ID]['additionalfields'] as $key) {
                 $tmpdata[$key] = $data[$NAME . $num . '_' . $key];
             }
         }
         $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true));
         if (!empty($specific)) {
             return $specific;
         }
     }
     // Manage auto CONCAT id
     $split = self::explodeWithID('$$', $data[$NAME . $num]);
     $split[0] = trim($split[0]);
     if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split[0]])) {
         return $searchopt[$ID]['toadd'][$split[0]];
     }
     // Empty is 0 or empty
     if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) {
         return $searchopt[$ID]['emptylabel'];
     }
     return Dropdown::getValueWithUnit($split[0], $unit);
 }
Exemple #11
0
 static function showUsers(CommonDBTM $item)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_projet_haveRight('projet', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     $canread = $item->can($ID, 'r');
     $query = "SELECT `glpi_plugin_projet_projets`.* FROM `glpi_plugin_projet_projets` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_projet_projets`.`entities_id`) ";
     if ($item->getType() == 'User') {
         $query .= " WHERE `glpi_plugin_projet_projets`.`users_id` = '" . $ID . "' ";
     } else {
         $query .= " WHERE `glpi_plugin_projet_projets`.`groups_id` = '" . $ID . "' ";
     }
     $query .= "AND `glpi_plugin_projet_projets`.`is_template` = 0 " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', '', $item->maybeRecursive());
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($number > 0) {
         echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php\">";
         echo "<div align='center'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='" . (4 + $colsup) . "'>" . __('Responsible of projects', 'projet') . ":</th></tr>";
         echo "<tr><th>" . __('Name') . "</th>";
         if (Session::isMultiEntitiesMode()) {
             echo "<th>" . __('Entity') . "</th>";
         }
         echo "<th>" . __('Description') . "</th>";
         echo "<th>" . __('Progress') . "</th>";
         echo "</tr>";
         while ($data = $DB->fetch_array($result)) {
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>";
             if ($canread && (in_array($data['entities_id'], $_SESSION['glpiactiveentities']) || $data["recursive"])) {
                 echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php?id=" . $data["id"] . "'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</a></td>";
             } else {
                 echo "<td class='center'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</td>";
             }
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
             echo "<td align='center'>" . $data["advance"] . " %</td>";
             echo "</tr>";
         }
         echo "</table></div>";
         Html::closeForm();
         echo "<br>";
     } else {
         echo "<div align='center'><table class='tab_cadre_fixe' style='text-align:center'>";
         echo "<tr><th>" . __('Responsible of projects', 'projet') . " - " . __('No item found');
         echo "</th></tr></table></div><br>";
     }
 }
 /**
  * Show KB categories
  *
  * @param $options   $_GET
  *
  * @return nothing (display the form)
  **/
 static function showFirstLevel($options)
 {
     global $DB, $CFG_GLPI;
     $faq = !Session::haveRight("knowbase", "r");
     // Default values of parameters
     $params["knowbaseitemcategories_id"] = "0";
     $params["target"] = $_SERVER['PHP_SELF'];
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $faq_limit = '';
     $parameters = '';
     // Manage search solution
     if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
         $parameters = "&amp;item_items_id=" . $options['item_items_id'] . "&amp;item_itemtype=" . $options['item_itemtype'];
     }
     if ($faq) {
         if (!$CFG_GLPI["use_public_faq"] && !Session::haveRight("faq", "r")) {
             return false;
         }
         if (Session::getLoginUserID()) {
             $faq_limit = getEntitiesRestrictRequest("AND", "glpi_knowbaseitemcategories", "", "", true);
         } else {
             // Anonymous access
             if (Session::isMultiEntitiesMode()) {
                 $faq_limit = " AND (`glpi_knowbaseitemcategories`.`entities_id` = '0'\n                                   AND `glpi_knowbaseitemcategories`.`is_recursive` = '1')";
             }
         }
         // Get All FAQ categories
         if (!isset($_SESSION['glpi_faqcategories'])) {
             $_SESSION['glpi_faqcategories'] = '(0)';
             $tmp = array();
             $query = "SELECT DISTINCT `glpi_knowbaseitems`.`knowbaseitemcategories_id`\n                      FROM `glpi_knowbaseitems`\n                      " . KnowbaseItem::addVisibilityJoins() . "\n                      LEFT JOIN `glpi_knowbaseitemcategories`\n                           ON (`glpi_knowbaseitemcategories`.`id`\n                                 = `glpi_knowbaseitems`.`knowbaseitemcategories_id`)\n                      WHERE `glpi_knowbaseitems`.`is_faq` = '1'\n                            AND " . KnowbaseItem::addVisibilityRestrict() . "\n                            {$faq_limit}";
             if ($result = $DB->query($query)) {
                 if ($DB->numrows($result)) {
                     while ($data = $DB->fetch_assoc($result)) {
                         if (!in_array($data['knowbaseitemcategories_id'], $tmp)) {
                             $tmp[] = $data['knowbaseitemcategories_id'];
                             $tmp = array_merge($tmp, getAncestorsOf('glpi_knowbaseitemcategories', $data['knowbaseitemcategories_id']));
                         }
                     }
                 }
                 if (count($tmp)) {
                     $_SESSION['glpi_faqcategories'] = "('" . implode("','", $tmp) . "')";
                 }
             }
         }
         $query = "SELECT DISTINCT `glpi_knowbaseitemcategories`.*\n                   FROM `glpi_knowbaseitemcategories`\n                   WHERE `glpi_knowbaseitemcategories`.`id` IN " . $_SESSION['glpi_faqcategories'] . "\n                         AND (`glpi_knowbaseitemcategories`.`knowbaseitemcategories_id`\n                                 = '" . $params["knowbaseitemcategories_id"] . "')\n                         {$faq_limit}\n                   ORDER BY `name` ASC";
     } else {
         if (!Session::haveRight("knowbase", "r")) {
             return false;
         }
         $faq_limit = getEntitiesRestrictRequest("AND", "glpi_knowbaseitemcategories", "entities_id", $_SESSION['glpiactiveentities'], true);
         $query = "SELECT *\n                   FROM `glpi_knowbaseitemcategories`\n                   WHERE `glpi_knowbaseitemcategories`.`knowbaseitemcategories_id`\n                              = '" . $params["knowbaseitemcategories_id"] . "'\n                         {$faq_limit}\n                   ORDER BY `name` ASC";
     }
     // Show category
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_central'>";
         echo "<tr><td colspan='3'><a href='" . $params['target'] . "?knowbaseitemcategories_id=0{$parameters}'>";
         echo "<img alt='' src='" . $CFG_GLPI["root_doc"] . "/pics/folder-open.png' class='bottom'></a>";
         // Display Category
         if ($params["knowbaseitemcategories_id"] != 0) {
             $tmpID = $params["knowbaseitemcategories_id"];
             $todisplay = "";
             while ($tmpID != 0) {
                 $query2 = "SELECT *\n                          FROM `glpi_knowbaseitemcategories`\n                          WHERE `glpi_knowbaseitemcategories`.`id` = '{$tmpID}'\n                                {$faq_limit}";
                 $result2 = $DB->query($query2);
                 if ($DB->numrows($result2) == 1) {
                     $data = $DB->fetch_assoc($result2);
                     $tmpID = $data["knowbaseitemcategories_id"];
                     $todisplay = "<a href='" . $params['target'] . "?knowbaseitemcategories_id=" . $data["id"] . "{$parameters}'>" . $data["name"] . "</a>" . (empty($todisplay) ? "" : " > ") . $todisplay;
                 } else {
                     $tmpID = 0;
                 }
             }
             echo " > " . $todisplay;
         }
         if ($DB->numrows($result) > 0) {
             $i = 0;
             while ($row = $DB->fetch_assoc($result)) {
                 // on affiche les résultats sur trois colonnes
                 if ($i % 3 == 0) {
                     echo "<tr>";
                 }
                 $ID = $row["id"];
                 echo "<td class='tdkb_result'>";
                 echo "<img alt='' src='" . $CFG_GLPI["root_doc"] . "/pics/folder.png' hspace='5'>";
                 echo "<span class='b'>" . "<a href='" . $params['target'] . "?knowbaseitemcategories_id=" . $row["id"] . "{$parameters}'>" . $row["name"] . "</a></span>";
                 echo "<div class='kb_resume'>" . Html::resume_text($row['comment'], 60) . "</div>";
                 if ($i % 3 == 2) {
                     echo "</tr>";
                 }
                 $i++;
             }
         }
         echo "<tr><td colspan='3'>&nbsp;</td></tr></table><br>";
     }
 }
Exemple #13
0
 /**
  * Display a Planning Item
  *
  * @param $val Array of the item to display
  * @param $who ID of the user (0 if all)
  * @param $type position of the item in the time block (in, through, begin or end)
  * @param $complete complete display (more details)
  *
  * @return Nothing (display function)
  **/
 static function displayPlanningItem(array $val, $who, $type = "", $complete = 0)
 {
     // $parm["type"] say begin end in or from type
     // Add items in the items fields of the parm array
     switch ($type) {
         case "in":
             //TRANS: %1$s is the start time of a planned item, %2$s is the end
             printf(__('From %1$s to %2$s :'), date("H:i", strtotime($val["begin"])), date("H:i", strtotime($val["end"])));
             break;
         case "through":
             echo Html::resume_text($val["name"], 80);
             break;
         case "begin":
             //TRANS: %s is the start time of a planned item
             printf(__('Start at %s:'), date("H:i", strtotime($val["begin"])));
             break;
         case "end":
             //TRANS: %s is the end time of a planned item
             printf(__('End at %s:'), date("H:i", strtotime($val["end"])));
             break;
     }
     echo "<br>";
     echo Html::resume_text($val["name"], 80);
 }
 /**
  * Display a Planning Item
  *
  * @param $parm Array of the item to display
  * @return Nothing (display function)
  **/
 static function displayPlanningItem(array $val, $who, $type = "", $complete = 0)
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/task.form.php?id=" . $val["id"] . "'";
     echo " onmouseout=\"cleanhide('content_task_" . $val["id"] . $rand . "')\" \n               onmouseover=\"cleandisplay('content_task_" . $val["id"] . $rand . "')\"";
     echo ">";
     switch ($type) {
         case "in":
             //TRANS: %1$s is the start time of a planned item, %2$s is the end
             $beginend = sprintf(__('From %1$s to %2$s :'), date("H:i", strtotime($val["begin"])), date("H:i", strtotime($val["end"])));
             printf(__('%1$s %2$s'), $beginend, Html::resume_text($val["name"], 80));
             break;
         case "begin":
             $start = sprintf(__('Start at %s'), date("H:i", strtotime($val["begin"])));
             printf(__('%1$s: %2$s'), $start, Html::resume_text($val["name"], 80));
             break;
         case "end":
             $end = sprintf(__('End at %s'), date("H:i", strtotime($val["end"])));
             printf(__('%1$s: %2$s'), $end, Html::resume_text($val["name"], 80));
             break;
     }
     if ($val["users_id"] && $who == 0) {
         echo " - " . __('User') . " " . getUserName($val["users_id"]);
     }
     echo "</a><br>";
     echo PluginProjetProjet::getTypeName(1) . " : <a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php?id=" . $val["plugin_projet_projets_id"] . "'";
     echo ">" . $val["project"] . "</a>";
     echo "<div class='over_link' id='content_task_" . $val["id"] . $rand . "'>";
     if ($val["end"]) {
         echo "<strong>" . __('End date') . "</strong> : " . Html::convdatetime($val["end"]) . "<br>";
     }
     if ($val["type"]) {
         echo "<strong>" . PluginProjetTaskType::getTypeName(1) . "</strong> : " . $val["type"] . "<br>";
     }
     if ($val["state"]) {
         echo "<strong>" . __('State') . "</strong> : " . $val['state'] . "<br>";
     }
     if ($val["location"]) {
         echo "<strong>" . _n('Location', 'Locations', 1) . "</strong>: " . $val["location"] . "<br>";
     }
     if ($val["priority"]) {
         echo "<strong>" . __('Priority') . "</strong> : " . Ticket::getPriorityName($val["priority"]) . "<br>";
     }
     if ($val["content"]) {
         echo "<strong>" . __('Description') . "</strong> : " . $val["content"];
     }
     echo "</div>";
 }
Exemple #15
0
 /**
  * Show the feed content
  **/
 function showFeedContent()
 {
     if (!$this->canViewItem()) {
         return false;
     }
     $feed = self::getRSSFeed($this->fields['url'], $this->fields['refresh_rate']);
     echo "<div class='firstbloc'>";
     if (!$feed || $feed->error()) {
         _e('Error retrieving RSS feed');
         $this->setError(true);
     } else {
         $this->setError(false);
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th colspan='3'>" . $feed->get_title() . "</th>";
         foreach ($feed->get_items(0, $this->fields['max_items']) as $item) {
             $link = $item->get_permalink();
             echo "<tr class='tab_bg_1'><td>";
             echo HTML::convDateTime($item->get_date('Y-m-d H:i:s'));
             echo "</td><td>";
             if (!is_null($link)) {
                 echo "<a target='_blank' href='{$link}'>" . $item->get_title() . '</a>';
             } else {
                 $item->get_title();
             }
             echo "</td><td>";
             $rand = mt_rand();
             echo "<span id='rssitem{$rand}' class='pointer'>";
             echo Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($item->get_content())), 1000);
             echo "</span>";
             Html::showToolTip(Toolbox::unclean_html_cross_side_scripting_deep($item->get_content()), array('applyto' => "rssitem{$rand}", 'display' => true));
             echo "</td></tr>";
         }
         echo "</table>";
     }
     echo "</div>";
 }
 /**
  * Get a list of KB/FAQ articles
  * for an authenticated user (or anonymous if allowed from config)
  *
  * @param $params array of options
  * @param $protocol the commonication protocol used
  **/
 static function methodListKnowBaseItems($params, $protocol)
 {
     global $DB, $CFG_GLPI;
     if (isset($params['help'])) {
         return array('start' => 'integer,optional', 'limit' => 'integer,optional', 'contains' => 'string,optional', 'category' => 'string,optional', 'faq' => 'bool,optional', 'type' => 'string,optionnal', 'help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         $params['faq'] = 1;
     } else {
         if (!isset($params['faq'])) {
             $params['faq'] = 0;
         }
     }
     $kb = new KnowbaseItem();
     if (!$kb->canView()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
     }
     if (!isset($params['category'])) {
         $params['category'] = 0;
     } else {
         if (!is_numeric($params['category'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'category');
         }
     }
     if (!isset($params['contains'])) {
         $params['contains'] = '';
     }
     if (!isset($params['type'])) {
         $params['type'] == 'search';
     }
     $query = KnowbaseItem::getListRequest(array('faq' => $params['faq'], 'contains' => addslashes($params['contains']), 'knowbaseitemcategories_id' => $params['category']), $params['type']);
     $resp = array();
     if (isset($params['count'])) {
         $resp['count'] = $DB->numrows($DB->query($query));
     } else {
         $start = 0;
         $limit = $CFG_GLPI["list_limit_max"];
         if (isset($params['limit']) && is_numeric($params['limit'])) {
             $limit = $params['limit'];
         }
         if (isset($params['start']) && is_numeric($params['start'])) {
             $start = $params['start'];
         }
         $query .= " LIMIT {$start}, {$limit}";
         foreach ($DB->request($query) as $data) {
             $data['resume'] = Toolbox::unclean_cross_side_scripting_deep($data['answer']);
             $data['resume'] = Html::clean(Html::resume_text(Html::clean($data['resume']), 200));
             $data['resume'] = html_entity_decode($data['resume'], 0, 'UTF-8');
             unset($data['answer']);
             $resp[] = $data;
         }
     }
     return $resp;
 }
Exemple #17
0
 /**
  * Display a Planning Item
  *
  * @param $val       array of the item to display
  * @param $who             ID of the user (0 if all)
  * @param $type            position of the item in the time block (in, through, begin or end)
  *                         (default '')
  * @param $complete        complete display (more details) (default 0)
  *
  * @return Nothing (display function)
  **/
 static function displayPlanningItem(array $val, $who, $type = "", $complete = 0)
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $users_id = "";
     // show users_id reminder
     $img = "rdv_private.png";
     // default icon for reminder
     if ($val["users_id"] != Session::getLoginUserID()) {
         $users_id = "<br>" . sprintf(__('%1$s: %2$s'), __('By'), getUserName($val["users_id"]));
         $img = "rdv_public.png";
     }
     echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . $img . "' alt='' title=\"" . self::getTypeName(1) . "\">&nbsp;";
     echo "<a id='reminder_" . $val["reminders_id"] . $rand . "' href='" . $CFG_GLPI["root_doc"] . "/front/reminder.form.php?id=" . $val["reminders_id"] . "'>";
     switch ($type) {
         case "in":
             //TRANS: %1$s is the start time of a planned item, %2$s is the end
             $beginend = sprintf(__('From %1$s to %2$s'), date("H:i", strtotime($val["begin"])), date("H:i", strtotime($val["end"])));
             printf(__('%1$s: %2$s'), $beginend, Html::resume_text($val["name"], 80));
             break;
         case "through":
             echo Html::resume_text($val["name"], 80);
             break;
         case "begin":
             $start = sprintf(__('Start at %s'), date("H:i", strtotime($val["begin"])));
             printf(__('%1$s: %2$s'), $start, Html::resume_text($val["name"], 80));
             break;
         case "end":
             $end = sprintf(__('End at %s'), date("H:i", strtotime($val["end"])));
             printf(__('%1$s: %2$s'), $end, Html::resume_text($val["name"], 80));
             break;
     }
     echo $users_id;
     echo "</a>";
     $recall = '';
     if (isset($val['reminders_id'])) {
         $pr = new PlanningRecall();
         if ($pr->getFromDBForItemAndUser($val['itemtype'], $val['reminders_id'], Session::getLoginUserID())) {
             $recall = "<br><span class='b'>" . sprintf(__('Recall on %s'), Html::convDateTime($pr->fields['when'])) . "<span>";
         }
     }
     if ($complete) {
         echo "<br><span class='b'>" . Planning::getState($val["state"]) . "</span><br>";
         echo $val["text"] . $recall;
     } else {
         Html::showToolTip("<span class='b'>" . Planning::getState($val["state"]) . "</span><br>\n                              " . $val["text"] . $recall, array('applyto' => "reminder_" . $val["reminders_id"] . $rand));
     }
     echo "";
 }
 /**
  * Display a Planning Item
  *
  * @param $itemtype  itemtype
  * @param $val       Array of the item to display
  * @param $who             ID of the user (0 if all)
  * @param $type            position of the item in the time block (in, through, begin or end)
  *                         (default '')
  * @param $complete        complete display (more details) (default 0)
  *
  * @return Nothing (display function)
  **/
 static function genericDisplayPlanningItem($itemtype, array $val, $who, $type = "", $complete = 0)
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $styleText = "";
     if (isset($val["state"])) {
         switch ($val["state"]) {
             case 2:
                 // Done
                 $styleText = "color:#747474;";
                 break;
         }
     }
     $parenttype = str_replace('Task', '', $itemtype);
     if ($parent = getItemForItemtype($parenttype)) {
         $parenttype_fk = $parent->getForeignKeyField();
     } else {
         return;
     }
     echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/rdv_interv.png' alt='' title=\"" . Html::entities_deep($parent->getTypeName(1)) . "\">&nbsp;&nbsp;";
     echo "<img src='" . $parent->getStatusIconURL($val["status"]) . "' alt='" . Html::entities_deep($parent->getStatus($val["status"])) . "' title=\"" . Html::entities_deep($parent->getStatus($val["status"])) . "\">";
     echo "&nbsp;<a id='content_tracking_" . $val["id"] . $rand . "'\n                   href='" . Toolbox::getItemTypeFormURL($parenttype) . "?id=" . $val[$parenttype_fk] . "'\n                   style='{$styleText}'>";
     switch ($type) {
         case "in":
             //TRANS: %1$s is the start time of a planned item, %2$s is the end
             printf(__('From %1$s to %2$s :'), date("H:i", strtotime($val["begin"])), date("H:i", strtotime($val["end"])));
             break;
         case "through":
             break;
         case "begin":
             //TRANS: %s is the start time of a planned item
             printf(__('Start at %s:'), date("H:i", strtotime($val["begin"])));
             break;
         case "end":
             //TRANS: %s is the end time of a planned item
             printf(__('End at %s:'), date("H:i", strtotime($val["end"])));
             break;
     }
     echo "<br>";
     //TRANS: %1$s is name of the item, %2$d is its ID
     printf(__('%1$s (#%2$d)'), Html::resume_text($val["name"], 80), $val[$parenttype_fk]);
     if (!empty($val["device"])) {
         echo "<br>" . $val["device"];
     }
     if ($who <= 0) {
         // show tech for "show all and show group"
         echo "<br>";
         //TRANS: %s is user name
         printf(__('By %s'), getUserName($val["users_id_tech"]));
     }
     echo "</a>";
     $recall = '';
     if (isset($val[getForeignKeyFieldForItemType($itemtype)]) && PlanningRecall::isAvailable()) {
         $pr = new PlanningRecall();
         if ($pr->getFromDBForItemAndUser($val['itemtype'], $val[getForeignKeyFieldForItemType($itemtype)], Session::getLoginUserID())) {
             $recall = "<br><span class='b'>" . sprintf(__('Recall on %s'), Html::convDateTime($pr->fields['when'])) . "<span>";
         }
     }
     if ($complete) {
         echo "<br><span class='b'>";
         if (isset($val["state"])) {
             echo Planning::getState($val["state"]) . "<br>";
         }
         echo sprintf(__('%1$s: %2$s'), __('Priority'), $parent->getPriorityName($val["priority"]));
         echo "<br>" . __('Description') . "</span><br>" . $val["content"];
         echo $recall;
     } else {
         $content = "<span class='b'>";
         if (isset($val["state"])) {
             $content .= Planning::getState($val["state"]) . "<br>";
         }
         $content .= sprintf(__('%1$s: %2$s'), __('Priority'), $parent->getPriorityName($val["priority"])) . "<br>" . __('Description') . "</span><br>" . $val["content"] . $recall;
         Html::showToolTip($content, array('applyto' => "content_tracking_" . $val["id"] . $rand));
     }
 }
 /**
  * @param $ID  integer  ID of the ticket
  **/
 static function showShortForTicket($ID)
 {
     global $DB, $CFG_GLPI;
     // Print Followups for a job
     $showprivate = Session::haveRight(self::$rightname, self::SEEPRIVATE);
     $RESTRICT = "";
     if (!$showprivate) {
         $RESTRICT = " AND (`is_private` = '0'\n                            OR `users_id` ='" . Session::getLoginUserID() . "') ";
     }
     // Get Number of Followups
     $query = "SELECT *\n                FROM `glpi_ticketfollowups`\n                WHERE `tickets_id` = '{$ID}'\n                      {$RESTRICT}\n                ORDER BY `date` DESC";
     $result = $DB->query($query);
     $out = "";
     if ($DB->numrows($result) > 0) {
         $out .= "<div class='center'><table class='tab_cadre' width='100%'>\n\n                  <tr><th>" . __('Date') . "</th><th>" . __('Requester') . "</th>\n                  <th>" . __('Description') . "</th></tr>\n";
         $showuserlink = 0;
         if (Session::haveRight('user', READ)) {
             $showuserlink = 1;
         }
         while ($data = $DB->fetch_assoc($result)) {
             $out .= "<tr class='tab_bg_3'>\n                     <td class='center'>" . Html::convDateTime($data["date"]) . "</td>\n                     <td class='center'>" . getUserName($data["users_id"], $showuserlink) . "</td>\n                     <td width='70%' class='b'>" . Html::resume_text($data["content"], $CFG_GLPI["cut"]) . "\n                     </td></tr>";
         }
         $out .= "</table></div>";
     }
     return $out;
 }
Exemple #20
0
function plugin_resources_install()
{
    global $DB;
    foreach (glob(GLPI_ROOT . '/plugins/resources/inc/*.php') as $file) {
        if (!preg_match('/resourceinjection/', $file) && !preg_match('/clientinjection/', $file) && !preg_match('/resourcepdf/', $file) && !preg_match('/datecriteria/', $file)) {
            include_once $file;
        }
    }
    $update = false;
    $update78 = false;
    $update80 = false;
    $update804 = false;
    $update83 = false;
    $install = false;
    if (!TableExists("glpi_plugin_resources_resources") && !TableExists("glpi_plugin_resources_employments")) {
        $install = true;
        //      $DB->runFile(GLPI_ROOT ."/plugins/resources/sql/empty-1.9.0.sql");
        //      $DB->runFile(GLPI_ROOT ."/plugins/resources/sql/update-1.9.1.sql");
        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/empty-1.9.1.sql");
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n         VALUES (1, '" . __('Long term contract', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n               VALUES (2, '" . __('Fixed term contract', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n               VALUES (3, '" . __('Trainee', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
    } else {
        if (TableExists("glpi_plugin_resources") && !TableExists("glpi_plugin_resources_employee")) {
            $update = true;
            $update78 = true;
            $update80 = true;
            $update804 = true;
            $update83 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.4.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
        } else {
            if (TableExists("glpi_plugin_resources_profiles") && FieldExists("glpi_plugin_resources_profiles", "interface")) {
                $update = true;
                $update78 = true;
                $update80 = true;
                $update804 = true;
                $update83 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
            } else {
                if (TableExists("glpi_plugin_resources") && !FieldExists("glpi_plugin_resources", "helpdesk_visible")) {
                    $update = true;
                    $update78 = true;
                    $update80 = true;
                    $update804 = true;
                    $update83 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                } else {
                    if (!TableExists("glpi_plugin_resources_contracttypes")) {
                        $update = true;
                        $update78 = true;
                        $update80 = true;
                        $update804 = true;
                        $update83 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                    } else {
                        if (TableExists("glpi_plugin_resources_contracttypes") && !FieldExists("glpi_plugin_resources_resources", "plugin_resources_resourcestates_id")) {
                            $update = true;
                            $update80 = true;
                            $update804 = true;
                            $update83 = true;
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                        } else {
                            if (!TableExists("glpi_plugin_resources_reportconfigs")) {
                                $update = true;
                                $update80 = true;
                                $update804 = true;
                                $update83 = true;
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                            } else {
                                if (!TableExists("glpi_plugin_resources_checklistconfigs")) {
                                    $update80 = true;
                                    $update804 = true;
                                    $update83 = true;
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                } else {
                                    if (!TableExists("glpi_plugin_resources_choiceitems")) {
                                        $update804 = true;
                                        $update83 = true;
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                    } else {
                                        if (!TableExists("glpi_plugin_resources_employments")) {
                                            $update83 = true;
                                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                            $query = "SELECT *\n               FROM `glpi_plugin_resources_employers`";
                                            $result = $DB->query($query);
                                            if ($DB->numrows($result) > 0) {
                                                while ($data = $DB->fetch_array($result)) {
                                                    $queryUpdate = "UPDATE `glpi_plugin_resources_employers`\n                            SET `completename`= '" . $data["name"] . "'\n                            WHERE `id`= '" . $data["id"] . "'";
                                                    $DB->query($queryUpdate) or die($DB->error());
                                                }
                                            }
                                        } else {
                                            if (TableExists("glpi_plugin_resources_ranks") && !FieldExists("glpi_plugin_resources_ranks", "begin_date")) {
                                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($update78 || $install) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resources'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.url##  : ##resource.url##\n\n   ##lang.resource.entity## : ##resource.entity##\n   ##IFresource.name####lang.resource.name## : ##resource.name##\n   ##ENDIFresource.name## ##IFresource.firstname####lang.resource.firstname## : ##resource.firstname##\n   ##ENDIFresource.firstname## ##IFresource.type####lang.resource.type## : ##resource.type##\n   ##ENDIFresource.type## ##IFresource.users####lang.resource.users## : ##resource.users##\n   ##ENDIFresource.users## ##IFresource.usersrecipient####lang.resource.usersrecipient## : ##resource.usersrecipient##\n   ##ENDIFresource.usersrecipient## ##IFresource.datedeclaration####lang.resource.datedeclaration## : ##resource.datedeclaration##\n   ##ENDIFresource.datedeclaration## ##IFresource.datebegin####lang.resource.datebegin## : ##resource.datebegin##\n   ##ENDIFresource.datebegin## ##IFresource.dateend####lang.resource.dateend## : ##resource.dateend##\n   ##ENDIFresource.dateend## ##IFresource.department####lang.resource.department## : ##resource.department##\n   ##ENDIFresource.department## ##IFresource.status####lang.resource.status## : ##resource.status##\n   ##ENDIFresource.status## ##IFresource.location####lang.resource.location## : ##resource.location##\n   ##ENDIFresource.location## ##IFresource.comment####lang.resource.comment## : ##resource.comment##\n   ##ENDIFresource.comment## ##IFresource.usersleaving####lang.resource.usersleaving## : ##resource.usersleaving##\n   ##ENDIFresource.usersleaving## ##IFresource.leaving####lang.resource.leaving## : ##resource.leaving##\n   ##ENDIFresource.leaving## ##IFresource.helpdesk####lang.resource.helpdesk## : ##resource.helpdesk##\n   ##ENDIFresource.helpdesk## ##FOREACHupdates##----------\n   ##lang.update.title## :\n   ##IFupdate.name####lang.resource.name## : ##update.name##\n   ##ENDIFupdate.name## ##IFupdate.firstname####lang.resource.firstname## : ##update.firstname##\n   ##ENDIFupdate.firstname## ##IFupdate.type####lang.resource.type## : ##update.type##\n   ##ENDIFupdate.type## ##IFupdate.users####lang.resource.users## : ##update.users##\n   ##ENDIFupdate.users## ##IFupdate.usersrecipient####lang.resource.usersrecipient## : ##update.usersrecipient##\n   ##ENDIFupdate.usersrecipient## ##IFupdate.datedeclaration####lang.resource.datedeclaration## : ##update.datedeclaration##\n   ##ENDIFupdate.datedeclaration## ##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin##\n   ##ENDIFupdate.datebegin## ##IFupdate.dateend####lang.resource.dateend## : ##update.dateend##\n   ##ENDIFupdate.dateend## ##IFupdate.department####lang.resource.department## : ##update.department##\n   ##ENDIFupdate.department## ##IFupdate.status####lang.resource.status## : ##update.status##\n   ##ENDIFupdate.status## ##IFupdate.location####lang.resource.location## : ##update.location##\n   ##ENDIFupdate.location## ##IFupdate.comment####lang.resource.comment## : ##update.comment##\n   ##ENDIFupdate.comment## ##IFupdate.usersleaving####lang.resource.usersleaving## : ##update.usersleaving##\n   ##ENDIFupdate.usersleaving## ##IFupdate.leaving####lang.resource.leaving## : ##update.leaving##\n   ##ENDIFupdate.leaving## ##IFupdate.helpdesk####lang.resource.helpdesk## : ##update.helpdesk##\n   ##ENDIFupdate.helpdesk## ----------##ENDFOREACHupdates##\n   ##FOREACHtasks####lang.task.title## :\n   ##IFtask.name####lang.task.name## : ##task.name##\n   ##ENDIFtask.name## ##IFtask.type####lang.task.type## : ##task.type##\n   ##ENDIFtask.type## ##IFtask.users####lang.task.users## : ##task.users##\n   ##ENDIFtask.users## ##IFtask.groups####lang.task.groups## : ##task.groups##\n   ##ENDIFtask.groups## ##IFtask.datebegin####lang.task.datebegin## : ##task.datebegin##\n   ##ENDIFtask.datebegin## ##IFtask.dateend####lang.task.dateend## : ##task.dateend##\n   ##ENDIFtask.dateend## ##IFtask.comment####lang.task.comment## : ##task.comment##\n   ##ENDIFtask.comment## ##IFtask.finished####lang.task.finished## : ##task.finished##\n   ##ENDIFtask.finished## ##IFtask.realtime####lang.task.realtime## : ##task.realtime##\n   ##ENDIFtask.realtime## ----------##ENDFOREACHtasks## ',\n                        '&lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.url##\n                        &lt;/strong&gt; :\n                        &lt;a href=\"##resource.url##\"&gt;##resource.url##\n                        &lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.entity##&lt;/strong&gt; : ##resource.entity##\n                        &lt;/span&gt; &lt;br /&gt; ##IFresource.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##resource.name##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.name## ##IFresource.firstname##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##resource.firstname##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.firstname## ##IFresource.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.type##&lt;/strong&gt; :  ##resource.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.type## ##IFresource.status##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.status##&lt;/strong&gt; :  ##resource.status##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.status## ##IFresource.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.users##&lt;/strong&gt; :  ##resource.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.users## ##IFresource.usersrecipient##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersrecipient##\n                        &lt;/strong&gt; :  ##resource.usersrecipient##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.usersrecipient## ##IFresource.datedeclaration##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datedeclaration##\n                        &lt;/strong&gt; :  ##resource.datedeclaration##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.datedeclaration## ##IFresource.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datebegin##&lt;/strong&gt; :  ##resource.datebegin##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.datebegin## ##IFresource.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.dateend##&lt;/strong&gt; :  ##resource.dateend##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.dateend## ##IFresource.department##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.department##&lt;/strong&gt; :  ##resource.department##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.department## ##IFresource.location##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.location##&lt;/strong&gt; :  ##resource.location##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.location## ##IFresource.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.comment##&lt;/strong&gt; :  ##resource.comment##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.comment## ##IFresource.usersleaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersleaving##&lt;/strong&gt; :  ##resource.usersleaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.usersleaving## ##IFresource.leaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.leaving##&lt;/strong&gt; :  ##resource.leaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.leaving## ##IFresource.helpdesk##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.helpdesk##&lt;/strong&gt; :  ##resource.helpdesk##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.helpdesk##   ##FOREACHupdates##----------\n                        &lt;br /&gt;\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.update.title## :&lt;/strong&gt;&lt;/span&gt;\n                        &lt;br /&gt; ##IFupdate.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##update.name##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.name## ##IFupdate.firstname##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##update.firstname##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.firstname## ##IFupdate.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.type##&lt;/strong&gt; : ##update.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.type## ##IFupdate.status##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.status##&lt;/strong&gt; : ##update.status##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.status## ##IFupdate.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.users##&lt;/strong&gt; : ##update.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.users## ##IFupdate.usersrecipient##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersrecipient##&lt;/strong&gt; : ##update.usersrecipient##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.usersrecipient## ##IFupdate.datedeclaration##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datedeclaration##\n                        &lt;/strong&gt; : ##update.datedeclaration##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.datedeclaration## ##IFupdate.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datebegin##&lt;/strong&gt; : ##update.datebegin##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.datebegin## ##IFupdate.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.dateend##&lt;/strong&gt; : ##update.dateend##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.dateend## ##IFupdate.department##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.department##&lt;/strong&gt; : ##update.department##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.department## ##IFupdate.location##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.location##&lt;/strong&gt; : ##update.location##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.location## ##IFupdate.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.comment##&lt;/strong&gt; : ##update.comment##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.comment## ##IFupdate.usersleaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersleaving##\n                        &lt;/strong&gt; : ##update.usersleaving##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.usersleaving## ##IFupdate.leaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.leaving##&lt;/strong&gt; : ##update.leaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.leaving## ##IFupdate.helpdesk##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.helpdesk##&lt;/strong&gt; : ##update.helpdesk##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.helpdesk####ENDFOREACHupdates##   ##FOREACHtasks##----------\n                        &lt;br /&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.title## :&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt; ##IFtask.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.name##&lt;/strong&gt; : ##task.name##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.name## ##IFtask.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.type##&lt;/strong&gt; : ##task.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.type## ##IFtask.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.users##&lt;/strong&gt; : ##task.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.users## ##IFtask.groups##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.groups##&lt;/strong&gt; : ##task.groups##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.groups## ##IFtask.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.datebegin##&lt;/strong&gt; : ##task.datebegin##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.datebegin## ##IFtask.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.dateend##&lt;/strong&gt; : ##task.dateend##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.dateend## ##IFtask.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.comment##&lt;/strong&gt; : ##task.comment##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.comment## ##IFtask.finished##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.finished##&lt;/strong&gt; : ##task.finished##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.finished## ##IFtask.realtime##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.realtime##&lt;/strong&gt; : ##task.realtime##\n                        &lt;/span&gt;##ENDIFtask.realtime##&lt;br /&gt;----------##ENDFOREACHtasks##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource', 0, 'PluginResourcesResource', 'new',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource', 0, 'PluginResourcesResource', 'update',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource', 0, 'PluginResourcesResource', 'delete',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Task', 0, 'PluginResourcesResource', 'newtask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Task', 0, 'PluginResourcesResource', 'updatetask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Task', 0, 'PluginResourcesResource', 'deletetask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Resources Tasks'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##resource.action## : ##resource.entity##',\n                        '##FOREACHtasks##\n   ##lang.task.name## : ##task.name##\n   ##lang.task.type## : ##task.type##\n   ##lang.task.users## : ##task.users##\n   ##lang.task.groups## : ##task.groups##\n   ##lang.task.datebegin## : ##task.datebegin##\n   ##lang.task.dateend## : ##task.dateend##\n   ##lang.task.comment## : ##task.comment##\n   ##lang.task.resource## : ##task.resource##\n   ##ENDFOREACHtasks##',\n                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.resource##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHtasks##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.resource##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHtasks##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Expired Resources Tasks', 0, 'PluginResourcesResource', 'AlertExpiredTasks',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Leaving Resources'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##resource.action## : ##resource.entity##',\n                        '##FOREACHresources##\n   ##lang.resource.name## : ##resource.name##\n   ##lang.resource.firstname## : ##resource.firstname##\n   ##lang.resource.type## : ##resource.type##\n   ##lang.resource.location## : ##resource.location##\n   ##lang.resource.users## : ##resource.users##\n   ##lang.resource.dateend## : ##resource.dateend##\n   ##ENDFOREACHresources##',\n                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHresources##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##resource.url##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHresources##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Leaving Resources', 0, 'PluginResourcesResource', 'AlertLeavingResources',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Resources Checklists'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##checklist.action## : ##checklist.entity##',\n                        '##lang.checklist.title##\n\n   ##FOREACHchecklists##\n   ##lang.checklist.name## ##lang.checklist.firstname## : ##checklist.name## ##checklist.firstname##\n   ##lang.checklist.datebegin## : ##checklist.datebegin##\n   ##lang.checklist.dateend## : ##checklist.dateend##\n   ##lang.checklist.entity## : ##checklist.entity##\n   ##lang.checklist.location## : ##checklist.location##\n   ##lang.checklist.type## : ##checklist.type##\n\n   ##lang.checklist.title2## :\n   ##tasklist.name##\n   ##ENDFOREACHchecklists##',\n                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr bgcolor=\"#d9c4b8\"&gt;\n   &lt;th colspan=\"7\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: center;\"&gt;##lang.checklist.title##&lt;/span&gt;&lt;/th&gt;\n   &lt;/tr&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.name## ##lang.checklist.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.entity##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.title2##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHchecklists##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##checklist.url##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.name## ##checklist.firstname##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.entity##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;table width=\"100%\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt; ##tasklist.name## &lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   &lt;/tbody&gt;\n   &lt;/table&gt;\n   &lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHchecklists##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Arrival Checklists', 0, 'PluginResourcesResource', 'AlertArrivalChecklists',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Leaving Checklists', 0, 'PluginResourcesResource', 'AlertLeavingChecklists',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Leaving Resource'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.title2##\n\n   ##lang.resource.url## : ##resource.url##\n\n   ##lang.resource.entity## : ##resource.entity##\n   ##IFresource.name## ##lang.resource.name## : ##resource.name##\n   ##ENDIFresource.name##\n   ##IFresource.firstname## ##lang.resource.firstname## : ##resource.firstname##\n   ##ENDIFresource.firstname##\n\n   ##lang.resource.badge##',\n                        '&lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.resource.title2##&lt;/strong&gt;\n   &lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.url##&lt;/strong&gt; :\n   &lt;a href=\"##resource.url##\"&gt;##resource.url##&lt;/a&gt;\n   &lt;/span&gt; &lt;br /&gt;&lt;br /&gt;\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.entity##&lt;/strong&gt; : ##resource.entity##&lt;/span&gt;\n   &lt;br /&gt; ##IFresource.name##\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##resource.name##&lt;br /&gt;\n   &lt;/span&gt;##ENDIFresource.name## ##IFresource.firstname##\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##resource.firstname##\n   &lt;br /&gt;&lt;/span&gt;##ENDIFresource.firstname##&lt;/p&gt;\n   &lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.resource.badge##&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;\n   &lt;/span&gt;&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Leaving Resource', 0, 'PluginResourcesResource', 'LeavingResource',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        $profiles = getAllDatasFromTable("glpi_plugin_resources_profiles");
        if (!empty($profiles)) {
            foreach ($profiles as $profile) {
                $query = "UPDATE `glpi_plugin_resources_profiles`\n                  SET `profiles_id` = '" . $resource["id"] . "'\n                  WHERE `id` = '" . $resource["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        $tables = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_tickets");
        foreach ($tables as $table) {
            $query = "DELETE FROM `{$table}` WHERE (`itemtype` = '4302' ) ";
            $DB->query($query);
        }
        Plugin::migrateItemType(array(4300 => 'PluginResourcesResource', 4301 => 'PluginResourcesTask', 4303 => 'PluginResourcesDirectory'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_resources_resources_items", "glpi_plugin_resources_choices", "glpi_plugin_resources_tasks_items"));
        Plugin::migrateItemType(array(1600 => "PluginBadgesBadge"), array("glpi_plugin_resources_resources_items", "glpi_plugin_resources_choices", "glpi_plugin_resources_tasks_items"));
    }
    if ($update || $install) {
        //Do One time on 0.78 for 1.6.2
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Report Creation'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.creationtitle##\n\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n##lang.resource.department## : ##resource.department##\n##lang.resource.location## : ##resource.location##\n##lang.resource.users## : ##resource.users##\n##lang.resource.usersrecipient## : ##resource.usersrecipient##\n##lang.resource.datedeclaration## : ##resource.datedeclaration##\n##lang.resource.datebegin## : ##resource.datebegin##\n\n##lang.resource.creation##\n\n##lang.resource.datecreation## : ##resource.datecreation##\n##lang.resource.login## : ##resource.login##\n##lang.resource.email## : ##resource.email##\n\n##lang.resource.informationtitle##\n\n##IFresource.commentaires####lang.resource.commentaires## : ##resource.commentaires####ENDIFresource.commentaires##\n\n##IFresource.informations####lang.resource.informations## : ##resource.informations####ENDIFresource.informations##',\n                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.creationtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"2\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" colspan=\"2\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.usersrecipient##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.usersrecipient##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datedeclaration##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datedeclaration##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.creation##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datecreation##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datecreation##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.login##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.login##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.email##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.email##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.informationtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFresource.commentaires##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFresource.commentaires## ##IFresource.informations##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.informations##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.informations##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFresource.informations##\n&lt;/tbody&gt;\n&lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Resource Report Creation', 0, 'PluginResourcesResource', 'report',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-11-16 11:36:46');";
        $result = $DB->query($query);
    }
    if ($update80) {
        $restrict = "`plugin_resources_resources_id` ='-1'";
        $checklists = getAllDatasFromTable("glpi_plugin_resources_checklists", $restrict);
        $PluginResourcesChecklistconfig = new PluginResourcesChecklistconfig();
        if (!empty($checklists)) {
            foreach ($checklists as $checklist) {
                $values["name"] = addslashes($checklist["name"]);
                $values["address"] = addslashes($checklist["address"]);
                $values["comment"] = addslashes($checklist["comment"]);
                $values["tag"] = $checklist["tag"];
                $values["entities_id"] = $checklist["entities_id"];
                $PluginResourcesChecklistconfig->add($values);
            }
        }
        $query = "DELETE FROM `glpi_plugin_resources_checklists`\n               WHERE `plugin_resources_resources_id` ='-1'\n                  OR `plugin_resources_resources_id` ='0';";
        $DB->query($query);
        // Put realtime in seconds
        if (FieldExists('glpi_plugin_resources_tasks', 'realtime')) {
            $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n            ADD `actiontime` INT( 11 ) NOT NULL DEFAULT 0 ;";
            $DB->queryOrDie($query, $this->version . " 0.80 Add actiontime in glpi_plugin_resources_tasks");
            $query = "UPDATE `glpi_plugin_resources_tasks`\n                   SET `actiontime` = ROUND(realtime * 3600)";
            $DB->queryOrDie($query, $this->version . " 0.80 Compute actiontime value in glpi_plugin_resources_tasks");
            $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n            DROP `realtime` ;";
            $DB->queryOrDie($query, $this->version . " 0.80 DROP realtime in glpi_plugin_resources_tasks");
        }
        // ADD plannings for tasks
        $tasks = getAllDatasFromTable("glpi_plugin_resources_tasks");
        if (!empty($tasks)) {
            foreach ($tasks as $task) {
                $query = "INSERT INTO `glpi_plugin_resources_taskplannings`\n               ( `id` , `plugin_resources_tasks_id` , `begin` , `end` )\n               VALUES (NULL , '" . $task["id"] . "', '" . $task["date_begin"] . "', '" . $task["date_end"] . "') ;";
                $DB->query($query);
            }
        }
        unset($input);
        $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n               DROP `date_begin`, DROP `date_end` ;";
        $DB->queryOrDie($query, $this->version . " 0.80 Drop date_begin and date_end in glpi_plugin_resources_tasks");
        // ADD tasks
        $PluginResourcesResource = new PluginResourcesResource();
        $taches = getAllDatasFromTable("glpi_plugin_resources_tasks");
        if (!empty($taches)) {
            foreach ($taches as $tache) {
                $PluginResourcesResource->getFromDB($tache["plugin_resources_resources_id"]);
                $input["entities_id"] = $PluginResourcesResource->fields["entities_id"];
                $query = "UPDATE `glpi_plugin_resources_tasks`\n               SET `entities_id` =  '" . $PluginResourcesResource->fields["entities_id"] . "' WHERE `id` = '" . $tache["id"] . "' ;";
                $DB->query($query);
            }
        }
    }
    if ($install || $update80) {
        $restrict = "`itemtype` = 'PluginResourcesResource'";
        $unicities = getAllDatasFromTable("glpi_fieldunicities", $restrict);
        if (empty($unicities)) {
            $query = "INSERT INTO `glpi_fieldunicities`\n                                      VALUES (NULL, 'Resources creation', 1, 'PluginResourcesResource', '0',\n                                             'name,firstname','1',\n                                             '1', '1', '');";
            $DB->queryOrDie($query, " 0.80 Create fieldunicities check");
        }
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Resting'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.restingtitle##\n##lang.resource.openby## : ##resource.openby##\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n\n##lang.resource.department## : ##resource.department##\n##lang.resource.users## : ##resource.users##\n\n##lang.resource.resting##\n\n##lang.resource.location## : ##resource.location##\n##lang.resource.home## : ##resource.home##\n##lang.resource.datebegin## : ##resource.datebegin##\n##lang.resource.dateend## : ##resource.dateend##\n\n##lang.resource.commentaires## : ##resource.commentaires##\n\n##FOREACHupdates##\n##lang.update.title##\n\n##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.resource.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.location####lang.resource.location## : ##update.location###ENDIFupdate.location##\n##IFupdate.home####lang.resource.home## : ##update.home####ENDIFupdate.home##\n##IFupdate.comment####lang.resource.comment## : ##update.comment####ENDIFupdate.comment##\n##ENDFOREACHupdates##',\n                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.restingtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.resting##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.home##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.home##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##FOREACHupdates##&lt;/p&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.update.title##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFupdate.datebegin##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin## : ##update.datebegin##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend## : ##update.dateend##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.dateend## ##IFupdate.location##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location## : ##update.location##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.location## ##IFupdate.home##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.home## : ##update.home##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.home## ##IFupdate.comment##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.comment## : ##update.comment##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.comment##\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##ENDFOREACHupdates##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Resting', 0, 'PluginResourcesResource', 'newresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Resting', 0, 'PluginResourcesResource', 'updateresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Resting', 0, 'PluginResourcesResource', 'deleteresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Holiday'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.holidaytitle##\n##lang.resource.openby## : ##resource.openby##\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n\n##lang.resource.department## : ##resource.department##\n##lang.resource.users## : ##resource.users##\n\n##lang.resource.holiday##\n\n##lang.resource.datebegin## : ##resource.datebegin##\n##lang.resource.dateend## : ##resource.dateend##\n\n##lang.resource.commentaires## : ##resource.commentaires##\n\n##FOREACHupdates##\n##lang.update.title##\n\n##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.resource.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.comment####lang.resource.comment## : ##update.comment####ENDIFupdate.comment##\n##ENDFOREACHupdates##',\n                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.holidaytitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.holiday##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##FOREACHupdates##&lt;/p&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.update.title##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFupdate.datebegin##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin## : ##update.datebegin##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend## : ##update.dateend##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.dateend## ##IFupdate.comment##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.comment## : ##update.comment##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.comment##\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##ENDFOREACHupdates##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Holiday', 0, 'PluginResourcesResource', 'newholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Holiday', 0, 'PluginResourcesResource', 'updateholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Holiday', 0, 'PluginResourcesResource', 'deleteholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update804) {
        $query = "SELECT * FROM `glpi_plugin_resources_choices`\n      WHERE `itemtype`!= ''\n      GROUP BY `comment`,`itemtype`";
        $result = $DB->query($query);
        $number = $DB->numrows($result);
        $affectedchoices = array();
        if (!empty($number)) {
            while ($data = $DB->fetch_assoc($result)) {
                $restrictaffected = "`itemtype` = '" . $data["itemtype"] . "'\n               AND `comment` = '" . addslashes($data["comment"]) . "'";
                $affected = getAllDatasFromTable("glpi_plugin_resources_choices", $restrictaffected);
                if (!empty($affected)) {
                    foreach ($affected as $affect) {
                        if ($affect["itemtype"] == $data["itemtype"] && $affect["comment"] == $data["comment"]) {
                            $affectedchoices[$data["id"]][] = $affect["plugin_resources_resources_id"];
                        }
                    }
                }
            }
        }
        $i = 0;
        if (!empty($affectedchoices)) {
            foreach ($affectedchoices as $key => $ressources) {
                $i++;
                $choice = new PluginResourcesChoice();
                $choice_item = new PluginResourcesChoiceItem();
                $types = array(__('Computer') => 'Computer', __('Monitor') => 'Monitor', __('Software') => 'Software', __('Network device') => 'NetworkEquipment', __('Printer') => 'Printer', __('Peripheral') => 'Peripheral', __('Phone') => 'Phone', __('Consumable model') => 'ConsumableItem', __('Specific network rights', 'resources') => '4303', __('Access to the applications', 'resources') => '4304', __('Specific securities groups', 'resources') => '4305', __('Specific distribution lists', 'resources') => '4306', __('Others needs', 'resources') => '4307', 'PluginBadgesBadge' => 'PluginBadgesBadge');
                if ($choice->getFromDB($key)) {
                    $key = array_search($choice->fields["itemtype"], $types);
                    if ($key) {
                        $name = $key;
                    } else {
                        $name = $choice->fields["itemtype"];
                    }
                    $valuesparent["name"] = $i . "." . $name;
                    $valuesparent["entities_id"] = 0;
                    $valuesparent["is_recursive"] = 1;
                    $newidparent = $choice_item->add($valuesparent);
                    $comment = "N/A";
                    if (!empty($choice->fields["comment"])) {
                        $comment = $choice->fields["comment"];
                    }
                    $valueschild["name"] = addslashes(Html::resume_text($comment, 50));
                    $valueschild["comment"] = addslashes($comment);
                    $valueschild["entities_id"] = 0;
                    $valueschild["is_recursive"] = 1;
                    $valueschild["plugin_resources_choiceitems_id"] = $newidparent;
                    $newidchild = $choice_item->add($valueschild);
                    foreach ($ressources as $id => $val) {
                        $query = "UPDATE `glpi_plugin_resources_choices`\n                           SET `plugin_resources_choiceitems_id` = '" . $newidchild . "'\n                          WHERE `plugin_resources_resources_id` = '" . $val . "'\n                          AND `itemtype` = '" . $choice->fields["itemtype"] . "'\n                           AND `comment` = '" . addslashes($choice->fields["comment"]) . "';";
                        $result = $DB->query($query);
                    }
                }
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_choices`\n   DROP `itemtype`,\n   DROP `comment`,\n   ADD UNIQUE KEY `unicity` (`plugin_resources_resources_id`,`plugin_resources_choiceitems_id`);";
        $result = $DB->query($query);
        $query = "ALTER TABLE `glpi_plugin_resources_choices`\n   ADD `comment` text collate utf8_unicode_ci;";
        $result = $DB->query($query);
    }
    //0.83 - Drop Matricule
    if (TableExists("glpi_plugin_resources_employees") && FieldExists("glpi_plugin_resources_employees", "matricule")) {
        $query = "SELECT * FROM `glpi_users`";
        $result = $DB->query($query);
        $number = $DB->numrows($result);
        if (!empty($number)) {
            while ($data = $DB->fetch_assoc($result)) {
                $restrict = "`items_id` = '" . $data["id"] . "'\n               AND `itemtype` = 'User'";
                $links = getAllDatasFromTable("glpi_plugin_resources_resources_items", $restrict);
                if (!empty($links)) {
                    foreach ($links as $link) {
                        $employee = new PluginResourcesEmployee();
                        if ($employee->getFromDBbyResources($link["plugin_resources_resources_id"])) {
                            $matricule = $employee->fields["matricule"];
                            if (isset($matricule) && !empty($matricule)) {
                                $query = "UPDATE `glpi_users`\n                           SET `registration_number` = '" . $matricule . "'\n                           WHERE `id` ='" . $link["items_id"] . "'";
                                $DB->query($query);
                            }
                        }
                    }
                }
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_employees`\n               DROP `matricule` ;";
        $result = $DB->query($query);
    }
    $rep_files_resources = GLPI_PLUGIN_DOC_DIR . "/resources";
    if (!is_dir($rep_files_resources)) {
        mkdir($rep_files_resources);
    }
    CronTask::Register('PluginResourcesResource', 'Resources', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesTask', 'ResourcesTask', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesChecklist', 'ResourcesChecklist', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesEmployment', 'ResourcesLeaving', DAY_TIMESTAMP, array('state' => CronTask::STATE_DISABLE));
    PluginResourcesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}