formatNumber() static public method

Convert a number to correct display
static public formatNumber ( $number, $edit = false, $forcedecimal ) : formatted
$number float Number to display
$edit boolean display number for edition ? (id edit use . in all case) (false by default)
$forcedecimal integer Force decimal number (do not use default value) (default -1)
return formatted number
Example #1
0
 static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job)
 {
     global $CFG_GLPI, $DB;
     $ID = $job->getField('id');
     //////////////followups///////////
     $query = "SELECT *\n                FROM `glpi_ticketcosts`\n                WHERE `tickets_id` = '{$ID}'\n                ORDER BY `begin_date`";
     $result = $DB->query($query);
     if (!$DB->numrows($result)) {
         $pdf->setColumnsSize(100);
         $pdf->displayLine(__('No ticket cost for this ticket', 'pdf'));
     } else {
         $pdf->setColumnsSize(60, 20, 20);
         $pdf->displayTitle("<b>" . TicketCost::getTypeName($DB->numrows($result)), __('Ticket duration'), CommonITILObject::getActionTime($job->fields['actiontime']) . "</b>");
         $pdf->setColumnsSize(20, 10, 10, 10, 10, 10, 10, 10, 10);
         $pdf->setColumnsAlign('center', 'center', 'center', 'left', 'right', 'right', 'right', 'right', 'right');
         $pdf->displayTitle("<b><i>" . __('Name') . "</i></b>", "<b><i>" . __('Begin date') . "</i></b>", "<b><i>" . __('End date') . "</i></b>", "<b><i>" . __('Budget') . "</i></b>", "<b><i>" . __('Duration') . "</i></b>", "<b><i>" . __('Time cost') . "</i></b>", "<b><i>" . __('Fixed cost') . "</i></b>", "<b><i>" . __('Material cost') . "</i></b>", "<b><i>" . __('Total cost') . "</i></b>");
         while ($data = $DB->fetch_array($result)) {
             $cost = TicketCost::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']);
             $pdf->displayLine($data['name'], Html::convDate($data['begin_date']), Html::convDate($data['end_date']), Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']), CommonITILObject::getActionTime($data['actiontime']), Html::formatNumber($data['cost_time']), Html::formatNumber($data['cost_fixed']), Html::formatNumber($data['cost_material']), Html::formatNumber($cost));
             $total_time += $data['actiontime'];
             $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP;
             $total_fixed += $data['cost_fixed'];
             $total_material += $data['cost_material'];
             $total += $cost;
         }
         $pdf->setColumnsSize(50, 10, 10, 10, 10, 10);
         $pdf->setColumnsAlign('right', 'right', 'right', 'right', 'right', 'right');
         $pdf->displayLine('<b>' . __('Total'), CommonITILObject::getActionTime($total_time), Html::formatNumber($total_costtime), Html::formatNumber($total_fixed), Html::formatNumber($total_material), Html::formatNumber($total));
     }
     $pdf->displaySpace();
 }
 static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
 {
     global $DB;
     $ID = $item->getField('id');
     // From ComputerVirtualMachine::showForComputer()
     $virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}'");
     $pdf->setColumnsSize(100);
     if (count($virtualmachines)) {
         $pdf->displayTitle("<b>" . __('List of virtual machines') . "</b>");
         $pdf->setColumnsSize(20, 8, 8, 8, 25, 8, 8, 15);
         $pdf->setColumnsAlign('left', 'center', 'center', 'center', 'left', 'right', 'right', 'left');
         $typ = explode(' ', __('Virtualization system'));
         $sys = explode(' ', __('Virtualization model'));
         $sta = explode(' ', __('State of the virtual machine'));
         $pdf->displayTitle(__('Name'), $typ[0], $sys[0], $sta[0], __('UUID'), __('CPU'), __('Mio'), __('Machine'));
         foreach ($virtualmachines as $virtualmachine) {
             $name = '';
             if ($link_computer = ComputerVirtualMachine::findVirtualMachine($virtualmachine)) {
                 $computer = new Computer();
                 if ($computer->getFromDB($link_computer)) {
                     $name = $computer->getName();
                 }
             }
             $pdf->displayLine($virtualmachine['name'], Html::clean(Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id'])), Html::clean(Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id'])), Html::clean(Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id'])), $virtualmachine['uuid'], $virtualmachine['vcpu'], Html::clean(Html::formatNumber($virtualmachine['ram'], false, 0)), $name);
         }
     } else {
         $pdf->displayTitle("<b>" . __('No virtual machine associated with the computer') . "</b>");
     }
     // From ComputerVirtualMachine::showForVirtualMachine()
     if ($item->fields['uuid']) {
         $where = "`uuid`" . ComputerVirtualMachine::getUUIDRestrictRequest($item->fields['uuid']);
         $hosts = getAllDatasFromTable('glpi_computervirtualmachines', $where);
         if (count($hosts)) {
             $pdf->setColumnsSize(100);
             $pdf->displayTitle("<b>" . __('List of host machines') . "</b>");
             $pdf->setColumnsSize(26, 37, 37);
             $pdf->displayTitle(__('Name'), __('Operating system'), __('Entity'));
             $computer = new Computer();
             foreach ($hosts as $host) {
                 if ($computer->getFromDB($host['computers_id'])) {
                     $pdf->displayLine($computer->getName(), Html::clean(Dropdown::getDropdownName('glpi_operatingsystems', $computer->getField('operatingsystems_id'))), Html::clean(Dropdown::getDropdownName('glpi_entities', $computer->getEntityID())));
                 }
             }
         }
     }
     $pdf->displaySpace();
 }
 static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
 {
     global $DB;
     $ID = $item->getField('id');
     $query = "SELECT `glpi_filesystems`.`name` AS fsname, `glpi_computerdisks`.*\n                FROM `glpi_computerdisks`\n                LEFT JOIN `glpi_filesystems`\n                  ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n                WHERE (`computers_id` = '" . $ID . "')";
     $result = $DB->query($query);
     $pdf->setColumnsSize(100);
     if ($DB->numrows($result) > 0) {
         $pdf->displayTitle("<b>" . _n('Volume', 'Volumes', 2) . "</b>");
         $pdf->setColumnsSize(22, 23, 22, 11, 11, 11);
         $pdf->displayTitle('<b>' . __('Name'), __('Partition'), _('Mount point'), __('Type'), __('Global size'), __('Free size') . '</b>');
         $pdf->setColumnsAlign('left', 'left', 'left', 'center', 'right', 'right');
         while ($data = $DB->fetch_assoc($result)) {
             $pdf->displayLine('<b>' . Toolbox::decodeFromUtf8(empty($data['name']) ? $data['ID'] : $data['name'], "windows-1252") . '</b>', $data['device'], $data['mountpoint'], Html::clean(Dropdown::getDropdownName('glpi_filesystems', $data["filesystems_id"])), sprintf(__('%s Mio'), Html::clean(Html::formatNumber($data['totalsize'], false, 0))), sprintf(__('%s Mio'), Html::clean(Html::formatNumber($data['freesize'], false, 0))));
         }
     } else {
         $pdf->displayTitle("<b>" . __('No volume found', 'pdf') . "</b>");
     }
     $pdf->displaySpace();
 }
Example #4
0
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $CFG_GLPI;
     $ID = $item->getField('id');
     if (!Session::haveRight("infocom", "r")) {
         return false;
     }
     $ic = new Infocom();
     $pdf->setColumnsSize(100);
     if ($ic->getFromDBforDevice(get_class($item), $ID)) {
         $pdf->displayTitle("<b>" . __('Financial and administrative information') . "</b>");
         $pdf->setColumnsSize(50, 50);
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Supplier') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Budget') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_budgets", $ic->fields["budgets_id"]))));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Order number') . "</i></b>", $ic->fields["order_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Order date') . "</i></b>", Html::convDate($ic->fields["order_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Immobilization number') . "</i></b>", $ic->fields["immo_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Date of purchase') . "</i></b>", Html::convDate($ic->fields["buy_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Invoice number') . "</i></b>", $ic->fields["bill"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Delivery date') . "</i></b>", Html::convDate($ic->fields["delivery_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Delivery form') . "</i></b>", $ic->fields["delivery_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Startup date') . "</i></b>", Html::convDate($ic->fields["use_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Value') . "</i></b>", Html::clean(Html::formatNumber($ic->fields["value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), _('Date of last physical inventory') . "</i></b>", Html::convDate($ic->fields["inventory_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty extension value') . "</i></b>", Html::clean(Html::formatNumber($ic->fields["warranty_value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Amortization duration') . "</i></b>", sprintf(__('%1$s (%2$s)'), sprintf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]), Infocom::getAmortTypeName($ic->fields["sink_type"]))));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Account net value') . "</i></b>", Infocom::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $CFG_GLPI['date_tax'], "n")), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Amortization coefficient') . "</i></b>", $ic->fields["sink_coeff"]));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('TCO (value + tracking cost)') . "</i></b>", Html::clean(Infocom::showTco($item->getField('ticket_tco'), $ic->fields["value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Monthly TCO') . "</i></b>", Html::clean(Infocom::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]))));
         PluginPdfCommon::mainLine($pdf, $ic, 'comment');
         $pdf->setColumnsSize(100);
         $pdf->displayTitle("<b>" . __('Warranty information') . "</b>");
         $pdf->setColumnsSize(50, 50);
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Start date of warranty') . "</i></b>", Html::convDate($ic->fields["warranty_date"])), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty duration') . "</i></b>", sprintf(__('%1$s - %2$s'), sprintf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]), sprintf(__('Valid to %s'), Infocom::getWarrantyExpir($ic->fields["buy_date"], $ic->fields["warranty_duration"])))));
         $col1 = "<b><i>" . __('Alarms on financial and administrative information') . "</i></b>";
         if ($ic->fields["alert"] == 0) {
             $col1 = sprintf(__('%1$s: %2$s'), $col1, __('No'));
         } else {
             if ($ic->fields["alert"] == 4) {
                 $col1 = sprintf(__('%1$s: %2$s'), $col1, __('Warranty expiration date'));
             }
         }
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty information') . "</i></b>", $ic->fields["warranty_info"]), $col1);
     } else {
         $pdf->displayTitle("<b>" . __('No financial information', 'pdf') . "</b>");
     }
     $pdf->displaySpace();
 }
 /**
  * Print the contract costs
  *
  * @param $contract               Contract object
  * @param $withtemplate  boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForContract(Contract $contract, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $contract->fields['id'];
     if (!$contract->getFromDB($ID) || !$contract->can($ID, READ)) {
         return false;
     }
     $canedit = $contract->can($ID, UPDATE);
     echo "<div class='center'>";
     $query = "SELECT *\n                FROM `glpi_contractcosts`\n                WHERE `contracts_id` = '{$ID}'\n                ORDER BY `begin_date`";
     $rand = mt_rand();
     if ($canedit) {
         echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n";
         echo "<script type='text/javascript' >\n";
         echo "function viewAddCost" . $ID . "_{$rand}() {\n";
         $params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $ID, 'id' => -1);
         Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>";
         echo __('Add a new cost') . "</a></div>\n";
     }
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th colspan='5'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>";
         if ($DB->numrows($result)) {
             echo "<tr><th>" . __('Name') . "</th>";
             echo "<th>" . __('Begin date') . "</th>";
             echo "<th>" . __('End date') . "</th>";
             echo "<th>" . __('Budget') . "</th>";
             echo "<th>" . __('Cost') . "</th>";
             echo "</tr>";
             Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Contract::getTypeName(1), $contract->getName()));
             $total = 0;
             while ($data = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data['contracts_id'] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">";
                 $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name'];
                 echo "<td>";
                 printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false)));
                 if ($canedit) {
                     echo "\n<script type='text/javascript' >\n";
                     echo "function viewEditCost" . $data['contracts_id'] . "_" . $data["id"] . "_{$rand}() {\n";
                     $params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $data["contracts_id"], 'id' => $data["id"]);
                     Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
                     echo "};";
                     echo "</script>\n";
                 }
                 echo "</td>";
                 echo "<td>" . Html::convDate($data['begin_date']) . "</td>";
                 echo "<td>" . Html::convDate($data['end_date']) . "</td>";
                 echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>";
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost']) . "</td>";
                 $total += $data['cost'];
                 echo "</tr>";
                 Session::addToNavigateListItems(__CLASS__, $data['id']);
             }
             echo "<tr class='b noHover'><td colspan='3'>&nbsp;</td>";
             echo "<td class='right'>" . __('Total cost') . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>';
         } else {
             echo "<tr><th colspan='5'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
     }
     echo "</div><br>";
 }
Example #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);
 }
Example #7
0
 /**
  * Show Infocom form for an item (not a standard showForm)
  *
  * @param $item                  CommonDBTM object
  * @param $withtemplate integer  template or basic item (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $CFG_GLPI;
     // Show Infocom or blank form
     if (!Session::haveRight("infocom", "r")) {
         return false;
     }
     if (!$item) {
         echo "<div class='spaced'>" . __('Requested item not found') . "</div>";
     } else {
         $date_tax = $CFG_GLPI["date_tax"];
         $dev_ID = $item->getField('id');
         $ic = new self();
         $option = "";
         if ($withtemplate == 2) {
             $option = " readonly ";
         }
         if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) {
             echo "<div class='firstbloc center'>" . __('For this type of item, the financial and administrative information are only a model for the items which you should add.') . "</div>";
         }
         if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) {
             $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID());
             if ($ic->can(-1, "w", $input) && $withtemplate != 2) {
                 echo "<div class='spaced b'>";
                 echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>";
                 echo sprintf(__('%1$s - %2$s'), $item->getTypeName(1), $item->getName()) . "</th></tr>";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/infocom.form.php", 'add', __('Enable the financial and administrative information'), array('itemtype' => $item->getType(), 'items_id' => $dev_ID));
                 echo "</td></tr></table></div>";
             }
         } else {
             // getFromDBforDevice
             $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2;
             if ($canedit) {
                 echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>";
             }
             echo "<div class='spaced'>";
             echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>";
             echo "<tr><th colspan='4'>" . __('Financial and administrative information') . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Supplier') . "</td>";
             echo "<td>";
             if ($withtemplate == 2) {
                 echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]);
             } else {
                 Supplier::dropdown(array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID()));
             }
             echo "</td>";
             if (Session::haveRight("budget", "r")) {
                 echo "<td>" . __('Budget') . "</td><td >";
                 Budget::dropdown(array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1));
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             // Can edit calendar ?
             $editcalendar = $withtemplate != 2;
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Order number') . "</td>";
             echo "<td >";
             Html::autocompletionTextField($ic, "order_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Order date') . "</td><td>";
             Html::showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             $istemplate = '';
             if ($item->isTemplate() || in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) {
                 $istemplate = '*';
             }
             echo "<td>" . sprintf(__('%1$s%2$s'), __('Immobilization number'), $istemplate) . "</td>";
             echo "<td>";
             $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID());
             Html::autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option));
             echo "</td>";
             echo "<td>" . __('Date of purchase') . "</td><td>";
             Html::showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Invoice number') . "</td>";
             echo "<td>";
             Html::autocompletionTextField($ic, "bill", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Delivery date') . "</td><td>";
             Html::showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Delivery form') . "</td><td>";
             Html::autocompletionTextField($ic, "delivery_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Startup date') . "</td><td>";
             Html::showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Value') . "</td>";
             echo "<td><input type='text' name='value' {$option} value='" . Html::formatNumber($ic->fields["value"], true) . "' size='14'></td>";
             echo "</td>";
             echo "<td>" . __('Date of last physical inventory') . "</td><td>";
             Html::showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Warranty extension value') . "</td>";
             echo "<td><input type='text' {$option} name='warranty_value' value='" . Html::formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>";
             echo "<td rowspan='5'>" . __('Comments') . "</td>";
             echo "<td rowspan='5' class='middle'>";
             echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"];
             echo "</textarea></td></tr>\n";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Account net value') . "</td><td>";
             echo Html::formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n"));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization type') . "</td><td >";
             if ($withtemplate == 2) {
                 echo self::getAmortTypeName($ic->fields["sink_type"]);
             } else {
                 self::dropdownAmortType("sink_type", $ic->fields["sink_type"]);
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization duration') . "</td><td>";
             if ($withtemplate == 2) {
                 printf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]);
             } else {
                 Dropdown::showNumber("sink_time", array('value' => $ic->fields["sink_time"], 'max' => 15, 'unit' => 'year'));
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization coefficient') . "</td>";
             echo "<td>";
             Html::autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . __('TCO (value + tracking cost)') . "</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . __('Monthly TCO') . "</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             echo "<tr><th colspan='4'>" . __('Warranty information') . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Start date of warranty') . "</td><td>";
             Html::showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar);
             echo "</td>";
             echo "<td>" . __('Warranty duration') . "</td><td>";
             if ($withtemplate == 2) {
                 // -1 = life
                 if ($ic->fields["warranty_duration"] == -1) {
                     _e('Lifelong');
                 } else {
                     printf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]);
                 }
             } else {
                 Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => __('Lifelong')), array('unit' => 'month'));
             }
             $tmpdat = self::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"], 0, true);
             if ($tmpdat) {
                 echo "<span class='small_space'>" . sprintf(__('Valid to %s'), $tmpdat) . "</span>";
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Warranty information') . "</td>";
             echo "<td >";
             Html::autocompletionTextField($ic, "warranty_info", array('option' => $option));
             echo "</td>";
             if ($CFG_GLPI['use_mailing']) {
                 echo "<td>" . __('Alarms on financial and administrative information') . "</td>";
                 echo "<td>";
                 self::dropdownAlert(array('name' => "alert", 'value' => $ic->fields["alert"]));
                 Alert::displayLastAlert('Infocom', $ic->fields['id']);
                 echo "</td>";
             } else {
                 echo "</td><td colspan='2'>";
             }
             echo "</td></tr>";
             if ($canedit) {
                 echo "<tr>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>";
                 echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n                      class='submit'>";
                 echo "</td>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\"\n                      class='submit'>";
                 echo "</td></tr>";
                 echo "</table></div>";
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
         }
     }
 }
Example #8
0
include "../../../inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
if (!defined('GLPI_ROOT')) {
    die("Can not acces directly to this file");
}
Session::checkCentralAccess();
if ($_POST["plugin_order_references_id"] > 0) {
    $reference_supplier = new PluginOrderReference_Supplier();
    $price = $reference_supplier->getPriceByReferenceAndSupplier($_POST["plugin_order_references_id"], $_POST["suppliers_id"]);
    switch ($_POST["update"]) {
        case 'quantity':
            echo "<input type='text' name='quantity' size='5'>";
            break;
        case 'priceht':
            echo "<input type='text' name='price' value=\"" . Html::formatNumber($price, true) . "\" size='5'>";
            break;
        case 'pricediscounted':
            echo "<input type='text' name='discount' size='5' value='0'>";
            break;
        case 'taxe':
            $config = PluginOrderConfig::getConfig();
            PluginOrderOrderTax::Dropdown(array('name' => "plugin_order_ordertaxes_id", 'value' => $config->getDefaultTaxes(), 'display_emptychoice' => true, 'emptylabel' => __("No VAT", "order")));
            break;
        case 'validate':
            echo "<input type='hidden' name='itemtype' value='" . $_POST["itemtype"] . "' class='submit' >";
            echo "<input type='hidden' name='plugin_order_references_id' value='" . $_POST["plugin_order_references_id"] . "' class='submit' >";
            echo "<input type='submit' name='add_item' value=\"" . __("Add") . "\" class='submit' >";
            break;
    }
} else {
Example #9
0
 public static function showForBudget($budgets_id)
 {
     global $DB, $CFG_GLPI;
     $table = getTableForItemType(__CLASS__);
     $query = "SELECT *\n                FROM `{$table}`\n                WHERE `budgets_id` = '{$budgets_id}'\n                AND `is_template`='0'\n                ORDER BY `entities_id`, `name` ";
     $result = $DB->query($query);
     $nb = $DB->numrows($result);
     echo "<div class='center'>";
     if ($nb) {
         $start = isset($_REQUEST["start"]) ? $_REQUEST["start"] : 0;
         $query_limit = $query . " LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
         Html::printAjaxPager(__("Linked orders", "order"), $start, $nb);
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         echo "<th style='width:15%;'>" . _n("Action", "Actions", 2) . "</th>";
         echo "<th>" . __("Name") . "</th>";
         echo "<th>" . __("Order status", "order") . "</th>";
         echo "<th>" . __("Entity") . "</th>";
         echo "<th>" . __("Price tax free", "order") . "</th>";
         echo "<th>" . __("Price ATI", "order") . "</th>";
         echo "</tr>";
         $total = 0;
         foreach ($DB->request($query_limit) as $data) {
             $PluginOrderOrder_Item = new PluginOrderOrder_Item();
             $prices = $PluginOrderOrder_Item->getAllPrices($data["id"]);
             $postagewithTVA = $PluginOrderOrder_Item->getPricesATI($data["port_price"], Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $data["plugin_order_ordertaxes_id"]));
             $total += $prices["priceTTC"] + $postagewithTVA;
             $link = Toolbox::getItemTypeFormURL(__CLASS__);
             echo "<tr class='tab_bg_1' align='center'>";
             echo "<td>";
             echo "<a href=\"" . $link . "?unlink_order=unlink_order&id=" . $data["id"] . "\">" . __("Unlink", "order") . "</a>";
             echo "</td>";
             echo "<td>";
             if (self::canView()) {
                 echo "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $data["name"] . "</a>";
             } else {
                 echo $data["name"];
             }
             echo "</td>";
             echo "<td>";
             echo Dropdown::getDropdownName(getTableForItemType('PluginOrderOrderState'), $data["plugin_order_orderstates_id"]);
             echo "</td>";
             echo "<td>";
             echo Dropdown::getDropdownName("glpi_entities", $data["entities_id"]);
             echo "</td>";
             echo "<td>";
             echo Html::formatNumber($prices["priceHT"]);
             echo "</td>";
             echo "<td>";
             echo Html::formatNumber($prices["priceTTC"] + $postagewithTVA);
             echo "</td>";
             echo "</tr>";
         }
         echo "</table></div>";
         echo "<br><div class='center'>";
         echo "<table class='tab_cadre' width='15%'>";
         echo "<tr class='tab_bg_2'><td>" . __("Budget already used") . ": </td>";
         echo "<td>";
         echo Html::formatNumber($total) . "</td>";
         echo "</tr>";
         echo "</table></div>";
     } else {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><td class='center'>" . __("No item to display") . "</td></tr>";
         echo "</table>";
     }
 }
Example #10
0
include "../../../inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
if (!defined('GLPI_ROOT')) {
    die("Can not acces directly to this file");
}
Session::checkCentralAccess();
if ($_POST["plugin_order_references_id"] > 0) {
    $reference_supplier = new PluginOrderReference_Supplier();
    $price = $reference_supplier->getPriceByReferenceAndSupplier($_POST["plugin_order_references_id"], $_POST["suppliers_id"]);
    switch ($_POST["update"]) {
        case 'quantity':
            echo "<input type='number' name='quantity' class='quantity'>";
            break;
        case 'priceht':
            echo "<input type='number' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='price' value='" . Html::formatNumber($price, true) . "' class='decimal'>";
            break;
        case 'pricediscounted':
            echo "<input type='number' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='discount' class='smalldecimal' value='0'>";
            break;
        case 'taxe':
            $config = PluginOrderConfig::getConfig();
            PluginOrderOrderTax::Dropdown(array('name' => "plugin_order_ordertaxes_id", 'value' => $config->getDefaultTaxes(), 'display_emptychoice' => true, 'emptylabel' => __("No VAT", "order")));
            break;
        case 'validate':
            echo "<input type='hidden' name='itemtype' value='" . $_POST["itemtype"] . "' class='submit' >";
            echo "<input type='hidden' name='plugin_order_references_id' value='" . $_POST["plugin_order_references_id"] . "' class='submit' >";
            echo "<input type='submit' name='add_item' value=\"" . __("Add") . "\" class='submit' >";
            break;
    }
} else {
Example #11
0
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     $this->initForm($ID, $options);
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
     echo "<td>";
     $opt = array();
     if (isset($options['helpdesk_id']) && !empty($options['helpdesk_id'])) {
         $help = new $options['helpdesk_itemtype']();
         if ($help->getFromDB($options['helpdesk_id'])) {
             $opt['value'] = $help->fields["name"];
             echo "<input type='hidden' name='helpdesk_id' value='" . $options['helpdesk_id'] . "'>";
             echo "<input type='hidden' name='helpdesk_itemtype' value='" . $options['helpdesk_itemtype'] . "'>";
         }
     }
     Html::autocompletionTextField($this, "name", $opt);
     echo "</td>";
     //Projet parent
     echo "<td>" . __('Parent project', 'projet') . "</td>";
     echo "<td>";
     PluginProjetProjet_Projet::displayLinkedProjetsTo($ID, $options['withtemplate']);
     if ($this->canCreate() && $options['withtemplate'] < 2) {
         $rand_linked_projet = mt_rand();
         echo "&nbsp;";
         if (!PluginProjetProjet_Projet::getParentProjetsTo($ID)) {
             echo "<img onClick=\"Ext.get('linkedprojet{$rand_linked_projet}').setDisplayed('block')\"\n                       title=\"" . _x('button', 'Add') . "\" alt=\"" . _x('button', 'Add') . "\"\n                       class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         }
         echo "<div style='display:none' id='linkedprojet{$rand_linked_projet}'>";
         PluginProjetProjet_Projet::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : '');
         echo "&nbsp;";
         PluginProjetProjet_Projet::dropdownParent("_link[plugin_projet_projets_id_2]", isset($values["_link"]) ? $values["_link"]['plugin_projet_projets_id_2'] : '', array('id' => $this->fields["id"], 'entities_id' => $this->fields["entities_id"]));
         echo "<input type='hidden' name='_link[plugin_projet_projets_id_1]' value='{$ID}'>\n";
         echo "&nbsp;";
         echo "</div>";
         if (isset($values["_link"]) && !empty($values["_link"]['plugin_projet_projets_id_2'])) {
             echo "<script language='javascript'>Ext.get('linkedprojet{$rand_linked_projet}').\n                   setDisplayed('block');</script>";
         }
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td colspan='2'>" . _n('Responsible', 'Responsibles', 2, 'projet') . "</td>";
     echo "<td colspan='2'>" . __('Planification', 'projet') . "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('User') . "</td><td>";
     User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
     echo "</td>";
     echo "<td>" . __('Start date') . "</td><td>";
     Html::showDateFormItem("date_begin", $this->fields["date_begin"], true, true);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Group') . "</td><td>";
     Dropdown::show('Group', array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . __('End date') . "</td><td>";
     Html::showDateFormItem("date_end", $this->fields["date_end"], true, true);
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Estimated duration', 'projet');
     echo "</td>";
     echo "<td>";
     $toadd = array();
     for ($i = 9; $i <= 100; $i++) {
         $toadd[] = $i * DAY_TIMESTAMP;
     }
     Dropdown::showTimeStamp("estimatedtime", array('min' => 0, 'max' => 8 * DAY_TIMESTAMP, 'value' => $this->fields["estimatedtime"], 'addfirstminutes' => false, 'inhours' => false, 'toadd' => $toadd));
     echo "</td>\n";
     echo "<td>" . __('Effective duration', 'projet') . "&nbsp;";
     Html::showToolTip(nl2br(__('Total of effective duration of project tasks', 'projet')));
     echo "</td>";
     echo "<td>" . self::getProjectForecast($ID) . "</td></tr>";
     echo "<tr class='tab_bg_2'><td>";
     echo __('Estimated duration', 'projet') . "&nbsp;" . __('in hours', 'projet');
     echo "</td><td>";
     $time = floor($this->fields["estimatedtime"]);
     $out = Html::formatNumber($time / HOUR_TIMESTAMP, 2);
     echo sprintf(_n('%s hour', '%s hours', $out), $out);
     echo "</td><td>" . __('Linked tickets duration', 'projet') . "&nbsp;";
     Html::showToolTip(nl2br(__('Total of duration of linked tickets for project', 'projet')));
     echo "</td>";
     echo "<td>" . self::getProjectDuration($ID) . "</td></tr>";
     //status
     echo "<tr class='tab_bg_1'><td>" . __('State') . "</td><td>";
     Dropdown::show('PluginProjetProjetState', array('value' => $this->fields["plugin_projet_projetstates_id"]));
     echo "</td>";
     echo "<td>" . __('Display on the global Gantt', 'projet') . "</td><td>";
     Dropdown::showYesNo("show_gantt", $this->fields["show_gantt"]);
     echo "</td></tr>";
     //advance
     echo "<tr class='tab_bg_1'><td>" . __('Progress') . "</td><td>";
     $advance = floor($this->fields["advance"]);
     echo "<select name='advance'>";
     for ($i = 0; $i < 101; $i += 5) {
         echo "<option value='{$i}' ";
         if ($advance == $i) {
             echo "selected";
         }
         echo " >{$i}</option>";
     }
     echo "</select> %";
     echo "<td>" . __('Associable to a ticket') . "</td><td>";
     Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>" . __('Comments') . "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>";
     $value = $this->fields["comment"];
     if (isset($options['helpdesk_id']) && !empty($options['helpdesk_id'])) {
         $help = new $options['helpdesk_itemtype']();
         if ($help->getFromDB($options['helpdesk_id'])) {
             $value = $help->fields["content"];
         }
     }
     echo "<textarea cols='130' rows='4' name='comment' >" . $value . "</textarea>";
     echo "<input type='hidden' name='withtemplate' value='" . $options['withtemplate'] . "'>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>" . __('Description') . "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>";
     echo "<textarea cols='130' rows='4' name='description' >" . $this->fields["description"] . "</textarea>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . __('Send email', 'projet') . "</td><td>";
     echo "<input type='checkbox' name='send_notification' checked = true";
     echo " value='1'>";
     echo "</td>";
     echo "<td colspan='2'></td>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     if ((!isset($options['withtemplate']) || $options['withtemplate'] == 0) && !empty($this->fields['template_name'])) {
         echo "<span class='small_space'>";
         printf(__('Created from the template %s'), $this->fields['template_name']);
         echo "</span>";
     } else {
         echo "&nbsp;";
     }
     echo "</td><td colspan='4'>";
     if (isset($options['withtemplate']) && $options['withtemplate']) {
         //TRANS: %s is the datetime of insertion
         printf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"]));
     } else {
         //TRANS: %s is the datetime of update
         printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
     }
     echo "</td></tr>\n";
     echo "</tr>";
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
 function showModels($itemtype, $id, $rand)
 {
     global $DB;
     $PluginRacksConfig = new PluginRacksConfig();
     $link = Toolbox::getItemTypeFormURL($itemtype);
     $table = getTableForItemType($itemtype);
     $search = Toolbox::getItemTypeSearchURL($itemtype);
     echo "<table class='tab_cadre_fixe' cellpadding='5'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>&nbsp;</th>";
     echo "<th>" . __('Equipment', 'racks') . "</th>";
     echo "<th>" . __('Total Current', 'racks') . "<br>(" . __('amps', 'racks') . ")</th>";
     echo "<th>" . __('Power supplies number', 'racks') . "</th>";
     echo "<th>" . __('Calorific waste', 'racks') . "<br> (";
     // Dissipation calorifique
     $PluginRacksConfig->getUnit("dissipation");
     echo ")</th>";
     echo "<th>" . __('Flow Rate', 'racks') . "<br> (";
     // Débit d'air frais
     $PluginRacksConfig->getUnit("rate");
     echo ")</th>";
     echo "<th>" . __('Size') . " (" . __('U', 'racks') . ")</th>";
     echo "<th>" . __('Weight', 'racks') . "<br> (";
     // poids
     $PluginRacksConfig->getUnit("weight");
     echo ")</th>";
     echo "<th>" . __('Full-depth item', 'racks') . "</th>";
     echo "</tr>";
     $modelid = -1;
     $result = $DB->query("SELECT *\n                        FROM `" . $this->getTable() . "` " . ($itemtype != -1 ? "WHERE `itemtype` = '{$itemtype}'" : "") . " ");
     while ($data = $DB->fetch_assoc($result)) {
         $modelid = $data['model_id'];
         $id = $data['id'];
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         echo "<input type='checkbox' name='item[{$id}]' value='1'>";
         echo "</td>";
         echo "<td>";
         echo "<a href=\"" . $link . "?id=" . $modelid . "\">";
         echo Dropdown::getDropdownName($table, $modelid);
         echo "</a>";
         echo "</td>";
         echo "<td>" . Html::formatNumber($data['amps'], true) . "</td>";
         echo "<td>" . $data['nb_alim'] . "</td>";
         echo "<td>" . Html::formatNumber($data['dissipation'], true) . "</td>";
         echo "<td>" . Html::formatNumber($data['flow_rate'], true) . "</td>";
         echo "<td>" . $data['size'] . "</td>";
         echo "<td>" . Html::formatNumber($data['weight'], true) . "</td>";
         echo "<td>" . Dropdown::getYesNo($data['length']) . "</td>";
     }
     echo "<tr class='tab_bg_1'><td colspan='10'>";
     if ($this->canCreate()) {
         echo "<div align='center'><a onclick= \"if ( markCheckboxes('massiveaction_form{$rand}') ) return false;\" href='#'>" . __('Check all') . "</a>";
         echo " - <a onclick= \"if ( unMarkCheckboxes('massiveaction_form{$rand}') ) return false;\" href='#'>" . __('Uncheck all') . "</a> ";
         echo "<input type='submit' name='deleteSpec' value=\"" . __s('Delete permanently') . "\" class='submit' ></div></td></tr>";
         echo "<tr class='tab_bg_1 right'><td colspan='10'>";
         echo "<a href=\"" . $search . "\">";
         echo __('Add specifications for servers models', 'racks');
         echo "</a>";
         echo "</td></tr>";
     }
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
 function showItemFromPlugin($instID, $face)
 {
     global $DB, $CFG_GLPI;
     if (!$this->canView()) {
         return false;
     }
     $rand = mt_rand();
     $PluginRacksRack = new PluginRacksRack();
     $PluginRacksConfig = new PluginRacksConfig();
     if ($PluginRacksRack->getFromDB($instID)) {
         $canedit = $PluginRacksRack->can($instID, UPDATE);
         if ($canedit) {
             $this->AddItemToRack($PluginRacksRack, $instID, $face);
         }
         //LIST
         echo "<form method='post' name='racks_form{$rand}' id='racks_form{$rand}'  \n               action=\"" . PluginRacksRack::getFormURL(true) . "\">";
         echo "<div class='center'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='12'>" . __('Rack enclosure arrangement', 'racks') . ":</th></tr><tr>";
         if ($face == PluginRacksRack::FRONT_FACE) {
             $query = "SELECT `" . $this->getTable() . "`.*\n              FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\n              WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \n              AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\n              AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::FRONT_FACE . "' \n               OR (`" . $this->getTable() . "`.`faces_id` ='" . PluginRacksRack::BACK_FACE . "' \n                  AND `glpi_plugin_racks_itemspecifications`.`length` = 1 ))\n              ORDER BY `" . $this->getTable() . "`.`position` ASC";
         } else {
             $query = "SELECT `" . $this->getTable() . "`.*\n              FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\n              WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \n              AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\n              AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::BACK_FACE . "' \n               OR (`" . $this->getTable() . "`.`faces_id` ='" . PluginRacksRack::FRONT_FACE . "' \n                  AND `glpi_plugin_racks_itemspecifications`.`length` = 1 ))\n              ORDER BY `" . $this->getTable() . "`.`position` ASC";
         }
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         $amps_tot = 0;
         $flow_rate_tot = 0;
         $dissip_tot = 0;
         $weight_tot = $PluginRacksRack->fields["weight"];
         $nbcordons = 0;
         $nbcordons_tot = 0;
         $cordons_amps_tot = 0;
         $computer_tot = 0;
         $computer_size_tot = 0;
         $networking_tot = 0;
         $networking_size_tot = 0;
         $peripheral_tot = 0;
         $peripheral_size_tot = 0;
         $others_tot = 0;
         $others_size_tot = 0;
         $next = 0;
         $device_size = 0;
         echo "<th>&nbsp;</th>";
         echo "<th>" . __('Position', 'racks') . "</th>";
         echo "<th>" . __('Name') . "</th>";
         // nom
         echo "<th>" . __('Type') . "</th>";
         // type de materiel
         echo "<th>" . __('Model') . "</th>";
         echo "<th>" . __('Power supply 1', 'racks') . "</th>";
         //alim1
         echo "<th>" . __('Power supply 2', 'racks') . "</th>";
         //alim2
         echo "<th>" . __('C13 Power Cord Quantity', 'racks') . "</th>";
         // nb cordons
         echo "<th>" . __('Total Current', 'racks') . "<br>(" . __('amps', 'racks') . ")</th>";
         // Courant consommé
         echo "<th>" . __('Calorific waste', 'racks') . "<br>";
         // Dissipation calorifique
         echo " (";
         $PluginRacksConfig->getUnit("dissipation");
         echo ")</th>";
         echo "<th>" . __('Flow Rate', 'racks') . "<br>";
         // Débit d'air frais
         echo " (";
         $PluginRacksConfig->getUnit("dissipation");
         echo ")</th>";
         echo "<th>" . __('Weight', 'racks') . "<br>";
         // poids
         echo " (";
         $PluginRacksConfig->getUnit("weight");
         echo ")</th>";
         echo "</tr>";
         for ($i = $PluginRacksRack->fields['rack_size']; $i >= 1; $i--) {
             $alim1 = 0;
             $alim2 = 0;
             $j = $i;
             if ($i < 10) {
                 $j = "0" . $i;
             }
             if ($face == PluginRacksRack::FRONT_FACE) {
                 // recherche de l'equipement a la position courante
                 $query = "SELECT `" . $this->getTable() . "`.*\n              FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\n              WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \n              AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\n              AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::FRONT_FACE . "' \n                  OR (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::BACK_FACE . "' \n                     AND `glpi_plugin_racks_itemspecifications`.`length` = 1)) AND `position` ='{$j}'\n              ORDER BY `" . $this->getTable() . "`.`position` ASC";
             } else {
                 $query = "SELECT `" . $this->getTable() . "`.*\n              FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\n              WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \n               AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\n               AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::BACK_FACE . "' \n                  OR (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::FRONT_FACE . "' \n                     AND `glpi_plugin_racks_itemspecifications`.`length` = 1)) AND `position` ='{$j}'\n              ORDER BY `" . $this->getTable() . "`.`position` ASC";
             }
             $result = $DB->query($query);
             $number = $DB->numrows($result);
             // Si equipement
             if ($number != 0) {
                 $data = $DB->fetch_array($result);
                 $class = substr($data["itemtype"], 0, -5);
                 $item = new $class();
                 $table = getTableForItemType($class);
                 $r = $DB->query("SELECT * FROM `" . $table . "` WHERE `id` = '" . $data["items_id"] . "' ");
                 $device = $DB->fetch_array($r);
                 $modelclass = $data["itemtype"];
                 $model_table = getTableForItemType($modelclass);
                 $modelfield = getForeignKeyFieldForTable(getTableForItemType($modelclass));
                 $query = "SELECT `" . $model_table . "`.`name` AS model,`" . $model_table . "`.`id` AS modelid, `glpi_plugin_racks_itemspecifications`.* \n                        FROM `glpi_plugin_racks_itemspecifications` " . " LEFT JOIN `" . $model_table . "` \n                        ON (`glpi_plugin_racks_itemspecifications`.`model_id` = `" . $model_table . "`.`id`)" . " LEFT JOIN `" . $table . "` \n                        ON (`glpi_plugin_racks_itemspecifications`.`model_id` = `" . $table . "`.`" . $modelfield . "` \n                           AND `glpi_plugin_racks_itemspecifications`.`itemtype` = '" . $modelclass . "')" . " WHERE `" . $table . "`.`id` = '" . $data["items_id"] . "' ";
                 //Rack recursivity .getEntitiesRestrictRequest(" AND ",$table,'','',$item->maybeRecursive())
                 $res = $DB->query($query);
                 $device_spec = $DB->fetch_array($res);
                 $device_size = $device_spec["size"];
                 if ($data["first_powersupply"] > 0) {
                     $nbcordons += 1;
                     $nbcordons_tot += 1;
                 }
                 if ($data["second_powersupply"] > 0) {
                     $nbcordons += 1;
                     $nbcordons_tot += 1;
                 }
                 if ($data["itemtype"] == 'ComputerModel') {
                     $computer_tot += 1;
                     $computer_size_tot += $device_spec["size"];
                 } else {
                     if ($data["itemtype"] == 'PeripheralModel') {
                         $peripheral_tot += 1;
                         $peripheral_size_tot += $device_spec["size"];
                     } else {
                         if ($data["itemtype"] == 'NetworkEquipmentModel') {
                             $networking_tot += 1;
                             $networking_size_tot += $device_spec["size"];
                         } else {
                             if ($data["itemtype"] == 'PluginRacksOtherModel') {
                                 $others_tot += 1;
                                 $others_size_tot += $device_spec["size"];
                             }
                         }
                     }
                 }
                 for ($t = 0; $t < $device_size; $t++) {
                     if ($t == 0) {
                         if ($data["itemtype"] == 'ComputerModel') {
                             echo "<tr class='plugin_racks_device_computers_color'>";
                         } else {
                             if ($data["itemtype"] == 'PeripheralModel') {
                                 echo "<tr class='plugin_racks_device_peripherals_color'>";
                             } else {
                                 if ($data["itemtype"] == 'NetworkEquipmentModel') {
                                     echo "<tr class='plugin_racks_device_networking_color'>";
                                 } else {
                                     if ($data["itemtype"] == 'PluginRacksOtherModel') {
                                         echo "<tr class='plugin_racks_device_others_color'>";
                                     }
                                 }
                             }
                         }
                         echo "<td width='10' rowspan='" . $device_size . "'>";
                         $sel = "";
                         if (isset($_GET["select"]) && $_GET["select"] == "all") {
                             $sel = "checked";
                         }
                         echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>";
                         echo "</td>";
                         echo "<td class='center'>U";
                         if ($canedit) {
                             echo "<input type='text' size='3' name='position" . $data["id"] . "' value='{$j}'>";
                             echo "&nbsp;<input type='image' name='updateDevice[" . $data["id"] . "]' value=\"" . _sx('button', 'Save') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/actualiser.png' class='calendrier'>";
                         } else {
                             echo $j;
                         }
                         echo "</td>";
                         $link = Toolbox::getItemTypeFormURL(substr($data["itemtype"], 0, -5));
                         if ($data["itemtype"] != 'PluginRacksOtherModel') {
                             $name = "<a href=\"" . $link . "?id=" . $data["items_id"] . "\">" . $device["name"] . "</a>";
                         } else {
                             $name = $device["name"];
                         }
                         echo "<input type='hidden' name='plugin_racks_racks_id' value='" . $PluginRacksRack->fields['id'] . "'>";
                         echo "<input type='hidden' name='rack_size' value='" . $PluginRacksRack->fields['rack_size'] . "'>";
                         echo "<input type='hidden' name='type" . $data["id"] . "' value='" . $data["itemtype"] . "'>";
                         echo "<input type='hidden' name='items_id" . $data["id"] . "' value='" . $data["items_id"] . "'>";
                         echo "<input type='hidden' name='plugin_racks_itemspecifications_id" . $data["id"] . "' value='" . $data["plugin_racks_itemspecifications_id"] . "'>";
                         echo "<input type='hidden' name='update_server' value='1'>";
                         echo "<input type='hidden' name='faces_id' value='" . $face . "'>";
                         if ($data["itemtype"] != 'PluginRacksOtherModel') {
                             echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . " >" . $name . "</td>";
                         } else {
                             $PluginRacksOther = new PluginRacksOther();
                             $PluginRacksOther->GetfromDB($data["items_id"]);
                             echo "<td class='center'><input type='text' name='name" . $data["id"] . "' value='" . $PluginRacksOther->fields["name"] . "' size='10'></td>";
                         }
                         echo "<td class='center'>" . $item::getTypeName(2) . "</td>";
                         $linkmodel = Toolbox::getItemTypeFormURL($modelclass);
                         echo "<td class='center'><a href=\"" . $linkmodel . "?id=" . $device_spec["modelid"] . "\">" . $device_spec["model"] . " (" . $device_spec["size"] . "U)</a></td>";
                         echo "<td class='center'>";
                         echo Dropdown::getDropdownName("glpi_plugin_racks_connections", $data["first_powersupply"]);
                         echo "</td>";
                         echo "<td class='center'>";
                         echo Dropdown::getDropdownName("glpi_plugin_racks_connections", $data["second_powersupply"]);
                         echo "</td>";
                         echo "<td class='center'>" . $nbcordons . "</td>";
                         if ($data["amps"] == '0.0000') {
                             $amps = $device_spec["amps"];
                         } else {
                             $amps = $data["amps"];
                         }
                         $cordons_amps_tot += $amps * $nbcordons;
                         echo "<td class='center'>" . Html::formatNumber($amps, true) . "</td>";
                         if ($data["dissipation"] == '0.0000') {
                             $dissipation = $device_spec["dissipation"];
                         } else {
                             $dissipation = $data["dissipation"];
                         }
                         echo "<td class='center'>" . Html::formatNumber($dissipation, true) . "</td>";
                         if ($data["flow_rate"] == '0.0000') {
                             $flow_rate = $device_spec["flow_rate"];
                         } else {
                             $flow_rate = $data["flow_rate"];
                         }
                         echo "<td class='center'>" . Html::formatNumber($flow_rate, true) . "</td>";
                         if ($data["weight"] == '0.0000') {
                             $weight = $device_spec["weight"];
                         } else {
                             $weight = $data["weight"];
                         }
                         echo "<td class='center'>" . Html::formatNumber($weight, true) . "</td>";
                         echo "</tr>";
                         if ($data["amps"] == '0.0000') {
                             $amps_tot += $device_spec["amps"];
                         } else {
                             $amps_tot += $data["amps"];
                         }
                         if ($data["flow_rate"] == '0.0000') {
                             $flow_rate_tot += $device_spec["flow_rate"];
                         } else {
                             $flow_rate_tot += $data["flow_rate"];
                         }
                         if ($data["dissipation"] == '0.0000') {
                             $dissip_tot += $device_spec["dissipation"];
                         } else {
                             $dissip_tot += $data["dissipation"];
                         }
                         if ($data["weight"] == '0.0000') {
                             $weight_tot += $device_spec["weight"];
                         } else {
                             $weight_tot += $data["weight"];
                         }
                     } else {
                         $name = $j - $t;
                         if ($data["itemtype"] == 'ComputerModel') {
                             echo "<tr class='plugin_racks_device_computers_color'>";
                         } else {
                             if ($data["itemtype"] == 'PeripheralModel') {
                                 echo "<tr class='plugin_racks_device_peripherals_color'>";
                             } else {
                                 if ($data["itemtype"] == 'NetworkEquipmentModel') {
                                     echo "<tr class='plugin_racks_device_networking_color'>";
                                 } else {
                                     if ($data["itemtype"] == 'PluginRacksOtherModel') {
                                         echo "<tr class='plugin_racks_device_others_color'>";
                                     }
                                 }
                             }
                         }
                         echo "<td class='center'>U{$name}</td><td colspan='10'></td></tr>";
                     }
                 }
                 if ($device_size > 1) {
                     for ($d = 1; $d < $device_size; $d++) {
                         $i--;
                     }
                 }
             } else {
                 // Si pas d'equipement a la position courante
                 echo "<tr class='tab_bg_1'><td></td><td class='center'>" . __('U', 'racks') . $j;
                 echo "</td><td colspan='10'></td></tr>";
             }
             $nbcordons = 0;
         }
         echo "<tr class='tab_bg_1'>";
         echo "<td></td>";
         echo "<td class='center'><b>" . __('Total') . "</b></td>";
         echo "<td colspan='3' class='center'><b>";
         if ($computer_tot != 0) {
             echo __('Total Servers', 'racks') . " : " . $computer_tot . " (" . $computer_size_tot . __('U', 'racks') . ")<br>";
         }
         if ($networking_tot != 0) {
             echo __('Total Network equipements', 'racks') . " : " . $networking_tot . " (" . $networking_size_tot . __('U', 'racks') . ")<br>";
         }
         if ($peripheral_tot != 0) {
             echo __('Total Peripherals', 'racks') . " : " . $peripheral_tot . " (" . $peripheral_size_tot . __('U', 'racks') . ")<br>";
         }
         if ($others_tot != 0) {
             echo __('Total Others', 'racks') . " : " . $others_tot . " (" . $others_size_tot . __('U', 'racks') . ")<br>";
         }
         //number of U availables
         $available = $PluginRacksRack->fields['rack_size'] - $computer_size_tot - $networking_size_tot - $peripheral_size_tot - $others_size_tot;
         if ($available > 0) {
             echo "<font color='green'>" . $available . " " . __('U availables', 'racks') . "</font>";
         } else {
             echo "<font color='red'>" . $available . " " . __('U availables', 'racks') . "</font>";
         }
         echo "</b></td>";
         echo "<td colspan='3' class='center'><b>" . __('Total power Cords', 'racks') . " : " . $nbcordons_tot . "</b><br>";
         echo "<b>" . __('Amperage on power Cords', 'racks') . " : " . $cordons_amps_tot . " " . __('amps', 'racks') . "</b></td>";
         echo "<td class='center'><b>" . Html::formatNumber($amps_tot, true) . " " . __('amps', 'racks') . "</b></td>";
         echo "<td class='center'><b>" . Html::formatNumber($dissip_tot, true) . " ";
         $PluginRacksConfig->getUnit("dissipation");
         echo "</b></td>";
         echo "<td class='center'><b>" . Html::formatNumber($flow_rate_tot, true) . " ";
         $PluginRacksConfig->getUnit("rate");
         echo "</b></td>";
         echo "<td class='center'><b>" . Html::formatNumber($weight_tot, true) . " ";
         $PluginRacksConfig->getUnit("weight");
         echo "</b></td>";
         echo "</tr>";
         echo "</table></div>";
         if ($canedit) {
             Html::openArrowMassives("racks_form{$rand}", true);
             Html::closeArrowMassives(array('deleteDevice' => _sx('button', 'Delete permanently')));
         } else {
             echo "<input type='hidden' name='rack_size' value='" . $PluginRacksRack->fields['rack_size'] . "'>";
             echo "</table></div>";
         }
         Html::closeForm();
         ////////////////////////////////////////////////////
         // Recherche des racks a gauche et a droite
         // Recuperation de la rangee
         $qPos = "SELECT `name`\n                                                        FROM `glpi_plugin_racks_roomlocations`\n                                                        WHERE `id` = '" . $PluginRacksRack->fields['plugin_racks_roomlocations_id'] . "' ";
         $rPos = $DB->query($qPos);
         $nbPos = $DB->numrows($rPos);
         $pos = "";
         $next = "";
         $prev = "";
         if ($nbPos != 0) {
             $dataPos = $DB->fetch_array($rPos);
             $pos = $dataPos['name'];
         }
         // Incrementation & docrementation de la lettre de rang
         if (!empty($pos)) {
             // Z is the last letter...
             if ($pos[0] != "Z") {
                 $next = chr(ord($pos[0]) + 1);
                 for ($h = 1; $h < strlen($pos); $h++) {
                     $next .= $pos[$h];
                 }
             }
             // A is the first letter....
             if ($pos[0] != "A") {
                 $prev = chr(ord($pos[0]) - 1);
                 for ($h = 1; $h < strlen($pos); $h++) {
                     $prev .= $pos[$h];
                 }
             }
             $qLeft = "SELECT `glpi_plugin_racks_racks`.`id`, `glpi_plugin_racks_roomlocations`.`name`\n            FROM `glpi_plugin_racks_racks`\n            LEFT JOIN `glpi_plugin_racks_roomlocations`\n            ON (`glpi_plugin_racks_roomlocations`.`id` = `glpi_plugin_racks_racks`.`plugin_racks_roomlocations_id`)\n            WHERE `glpi_plugin_racks_racks`.`is_deleted` = '0' AND `glpi_plugin_racks_roomlocations`.`name` = '" . $prev . "' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_racks_racks", '', '', $PluginRacksRack->maybeRecursive());
             $rLeft = $DB->query($qLeft);
             $nb = $DB->numrows($rLeft);
             echo "<br><br>";
             echo "<div align='center'><table border='0' width='950px'><tr><td class='left'>";
             if ($nb != 0) {
                 $left_racks = $DB->fetch_array($rLeft);
                 echo "<a href =\"" . $CFG_GLPI["root_doc"] . "/plugins/racks/front/rack.form.php?id=" . $left_racks['id'] . "\">\n               <img src=\"" . $CFG_GLPI["root_doc"] . "/pics/left.png\" alt=''>&nbsp;" . __('Left rack enclosure', 'racks') . " " . $left_racks['name'] . "</a>";
             } else {
                 echo __('No rack enclosure on the left', 'racks');
             }
             echo "</td>";
             echo "<td>";
             echo "</td>";
             echo "<td class='right'>";
             $qRight = "SELECT `glpi_plugin_racks_racks`.`id`, `glpi_plugin_racks_roomlocations`.`name`\n            FROM `glpi_plugin_racks_racks`\n            LEFT JOIN `glpi_plugin_racks_roomlocations`\n            ON (`glpi_plugin_racks_roomlocations`.`id` = `glpi_plugin_racks_racks`.`plugin_racks_roomlocations_id`)\n            WHERE `glpi_plugin_racks_racks`.`is_deleted` = '0' AND `glpi_plugin_racks_roomlocations`.`name` = '" . $next . "' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_racks_racks", '', '', $PluginRacksRack->maybeRecursive());
             $rRight = $DB->query($qRight);
             $nb = $DB->numrows($rRight);
             if ($nb != 0) {
                 $right_racks = $DB->fetch_array($rRight);
                 echo "<a href =\"" . $CFG_GLPI["root_doc"] . "/plugins/racks/front/rack.form.php?id=" . $right_racks['id'] . "\">" . __('Right rack enclosure', 'racks') . " " . $right_racks['name'] . "&nbsp;<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/right.png\" alt=''></a>";
             } else {
                 echo __('No rack enclosure on the right', 'racks');
             }
             echo "</td></tr></table></div>";
         }
     }
 }
Example #14
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;
     $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);
 }
Example #15
0
 function generatePdf($itemtype, $data, $saveas)
 {
     global $CFG_GLPI, $PDF, $DB;
     $ID = $data["id"];
     //name
     if (!empty($data["name"])) {
         $name_item = Toolbox::decodeFromUtf8($data["name"]);
     } else {
         $name_item = "";
     }
     //user
     if (!empty($data["users_id"])) {
         $user_item = Toolbox::decodeFromUtf8(Html::clean(getUserName($data["users_id"])));
     } else {
         if (!empty($data["groups_id"])) {
             $user_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_groups", $data["groups_id"]));
         } else {
             $user_item = "";
         }
     }
     //fabricant
     if (!empty($data["manufacturers_id"])) {
         $fabricant_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]));
     } else {
         $fabricant_item = "";
     }
     //serial
     if (!empty($data["serial"])) {
         $serial_item = Toolbox::decodeFromUtf8($data["serial"]);
     } else {
         $serial_item = "";
     }
     $class = $itemtype . "Type";
     $item = new $class();
     $typefield = getForeignKeyFieldForTable(getTableForItemType($itemtype . "Type"));
     $item->getFromDB($data[$typefield]);
     if (!empty($typefield) && !empty($item->fields["name"])) {
         $type_item = Toolbox::decodeFromUtf8($item->fields["name"]);
     } else {
         $type_item = "";
     }
     //infocoms
     $ic = new Infocom();
     if ($ic->getfromDBforDevice($itemtype, $ID)) {
         //immobilizationsheets_item
         if (!empty($ic->fields["immo_number"])) {
             $immobilizationsheets_item = Toolbox::decodeFromUtf8($ic->fields["immo_number"]);
         } else {
             $immobilizationsheets_item = "";
         }
         //buy_date
         if (!empty($ic->fields["buy_date"])) {
             $buy_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["buy_date"]));
         } else {
             $buy_date_item = "";
         }
         //use_date
         if (!empty($ic->fields["use_date"])) {
             $use_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["use_date"]));
         } else {
             $use_date_item = "";
         }
         //order_number
         if (!empty($ic->fields["order_number"])) {
             $order_number_item = Toolbox::decodeFromUtf8($ic->fields["order_number"]);
         } else {
             $order_number_item = "";
         }
         //value_item
         if (!empty($ic->fields["value"])) {
             $value_item = Toolbox::decodeFromUtf8(Html::clean(Html::formatNumber($ic->fields["value"])));
         } else {
             $value_item = "";
         }
         //sink_time
         if (!empty($ic->fields["sink_time"])) {
             $sink_time_item = Toolbox::decodeFromUtf8(sprintf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]));
         } else {
             $sink_time_item = "";
         }
         //sink_type
         if (!empty($ic->fields["sink_type"])) {
             $sink_type_item = Toolbox::decodeFromUtf8(Infocom::getAmortTypeName($ic->fields["sink_type"]));
         } else {
             $sink_type_item = "";
         }
     } else {
         $immobilizationsheets_item = "";
         $buy_date_item = "";
         $use_date_item = "";
         $order_number_item = "";
         $value_item = "";
         $sink_time_item = "";
         $sink_type_item = "";
     }
     //composants
     $devtypes = self::getDeviceTypes();
     if ($itemtype == 'Computer') {
         $device2 = new $devtypes[2]();
         $query2 = "SELECT `deviceprocessors_id`\n                  FROM `" . getTableForItemType('items_' . $devtypes[2]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result2 = $DB->query($query2);
         $number2 = $DB->numrows($result2);
         $device3 = new $devtypes[3]();
         $query3 = "SELECT SUM(`size`) AS total\n                  FROM `" . getTableForItemType('items_' . $devtypes[3]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result3 = $DB->query($query3);
         $number3 = $DB->numrows($result3);
         $query3b = "SELECT `devicememories_id`\n                  FROM `" . getTableForItemType('items_' . $devtypes[3]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result3b = $DB->query($query3b);
         $number3b = $DB->numrows($result3b);
         $device4 = new $devtypes[4]();
         $query4 = "SELECT `deviceharddrives_id`,`capacity`\n                  FROM `" . getTableForItemType('items_' . $devtypes[4]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result4 = $DB->query($query4);
         $number4 = $DB->numrows($result4);
         $device5 = new $devtypes[6]();
         $query5 = "SELECT `devicedrives_id`\n                  FROM `" . getTableForItemType('items_' . $devtypes[6]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result5 = $DB->query($query5);
         $number5 = $DB->numrows($result5);
         if ($number2 != 0) {
             while ($data2 = $DB->fetch_array($result2)) {
                 //proc_item
                 if (!empty($data2["deviceprocessors_id"])) {
                     $query_proc = "SELECT `designation`\n                              FROM `glpi_deviceprocessors`\n                              WHERE `id` = '" . $data2["deviceprocessors_id"] . "'";
                     $result_proc = $DB->query($query_proc);
                     $number_proc = $DB->numrows($result_proc);
                     if ($number_proc != 0) {
                         while ($data_proc = $DB->fetch_array($result_proc)) {
                             $proc_item = Toolbox::decodeFromUtf8($data_proc["designation"]);
                         }
                     }
                 }
             }
         } else {
             $proc_item = "";
         }
         if ($number3 != 0) {
             while ($data3 = $DB->fetch_array($result3)) {
                 //ram_item
                 $ram_item = $data3["total"];
             }
         } else {
             $ram_item = "";
         }
         $ram_type_item = "";
         if ($number3b != 0) {
             while ($data3b = $DB->fetch_array($result3b)) {
                 //ram_type_item
                 if (!empty($data3b["devicememories_id"])) {
                     $query_ram = "SELECT `glpi_devicememorytypes`.`name`\n                              FROM `glpi_devicememories`,`glpi_devicememorytypes`\n                              WHERE `glpi_devicememories`.`id` = '" . $data3b["devicememories_id"] . "'\n                              AND `glpi_devicememorytypes`.`id` = `glpi_devicememories`.`devicememorytypes_id` ";
                     $result_ram = $DB->query($query_ram);
                     $number_ram = $DB->numrows($result_ram);
                     if ($number_ram != 0) {
                         while ($data_ram = $DB->fetch_array($result_ram)) {
                             $ram_type_item = Toolbox::decodeFromUtf8($data_ram["name"]);
                         }
                     } else {
                         $ram_type_item = "";
                     }
                 }
             }
         } else {
             $ram_type_item = "";
         }
         $hdd_item = "";
         $hdd_designation_item = "";
         $hdd_interface_item = "";
         if ($number4 != 0) {
             while ($data4 = $DB->fetch_array($result4)) {
                 //hdd_item
                 $hdd_size_item = Toolbox::decodeFromUtf8($data4["capacity"]);
                 if (!empty($data4["deviceharddrives_id"])) {
                     $query_hdd = "SELECT `designation`\n                              FROM `glpi_deviceharddrives`\n                              WHERE `id` = '" . $data4["deviceharddrives_id"] . "'";
                     $result_hdd = $DB->query($query_hdd);
                     $number_hdd = $DB->numrows($result_hdd);
                     if ($number_hdd != 0) {
                         while ($data_hdd = $DB->fetch_array($result_hdd)) {
                             $hdd_designation_item = Toolbox::decodeFromUtf8($data_hdd["designation"]);
                         }
                     } else {
                         $hdd_designation_item = "";
                     }
                     $query_hdd1 = "SELECT `glpi_interfacetypes`.`name`\n                              FROM `glpi_deviceharddrives`,`glpi_interfacetypes`\n                              WHERE `glpi_deviceharddrives`.`id` = '" . $data4["deviceharddrives_id"] . "'\n                              AND `glpi_interfacetypes`.`id` = `glpi_deviceharddrives`.`interfacetypes_id` ";
                     //replace interface by FK_interface 0.72.1
                     $result_hdd1 = $DB->query($query_hdd1);
                     $number_hdd1 = $DB->numrows($result_hdd1);
                     if ($number_hdd1 != 0) {
                         while ($data_hdd1 = $DB->fetch_array($result_hdd1)) {
                             $hdd_interface_item = Toolbox::decodeFromUtf8($data_hdd1["name"]);
                         }
                     }
                 } else {
                     $hdd_interface_item = "";
                 }
                 $hdd_item .= $hdd_designation_item . " " . $hdd_interface_item . " (" . $hdd_size_item . " Mo)";
                 if ($number4 > 1) {
                     $hdd_item .= " - ";
                 }
             }
         } else {
             $hdd_item = "";
         }
         $lecteur_item = "";
         if ($number5 != 0) {
             while ($data5 = $DB->fetch_array($result5)) {
                 //lecteur_item
                 if (!empty($data5["items_id"])) {
                     $query_lecteur = "SELECT `designation`\n                                 FROM `glpi_devicedrives`\n                                 WHERE `id` = '" . $data5["interfacetypes_id"] . "'";
                     $result_lecteur = $DB->query($query_lecteur);
                     $number_lecteur = $DB->numrows($result_lecteur);
                     if ($number_lecteur != 0) {
                         while ($data_lecteur = $DB->fetch_array($result_lecteur)) {
                             $lecteur_item .= Toolbox::decodeFromUtf8($data_lecteur["designation"]);
                             if ($number5 > 1) {
                                 $lecteur_item .= " - ";
                             }
                         }
                     }
                 }
             }
         } else {
             $lecteur_item = "";
         }
         //softwares
         $query6 = "SELECT `glpi_softwares`.`name`,`glpi_softwarelicenses`.`softwareversions_id_buy`,`glpi_softwarelicenses`.`serial`\n                  FROM `glpi_softwarelicenses`\n                  INNER JOIN `glpi_computers_softwarelicenses` ON (`glpi_softwarelicenses`.`id` = `glpi_computers_softwarelicenses`.`softwarelicenses_id` AND `glpi_computers_softwarelicenses`.`computers_id` = '{$ID}') \n                  INNER JOIN `glpi_softwares` ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`) ";
         $result6 = $DB->query($query6);
         $number6 = $DB->numrows($result6);
     }
     //Affichage
     //$PDF->addJpegFromFile('../pics/immobilizationsheets.jpg',285,785,32,32);
     //title
     $PDF->ezSetDy(-20);
     $title = array(array('' => Toolbox::decodeFromUtf8(__('IDENTIFICATION IMMOBILIZATION SHEET', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'center'));
     $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-10);
     //partie 1
     $PDF->ezSetDy(-20);
     $title1 = array(array('' => Toolbox::decodeFromUtf8(__('I - PART TO BE FILLED BY THE PERSON IN CHARGE FOR THE PURCHASES', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(transfer the original to the administrator network so computer equipement, the assistant of management in the other cases)', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-10);
     //Date mise en service
     $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Startup date')) . "</u> : " . $buy_date_item, 8, array("justification" => "left"));
     $PDF->ezSetDy(-10);
     //ligne1 (entreprise / fournisseur)
     $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('MY ENTERPRISE', 'immobilizationsheets')), '1' => Toolbox::decodeFromUtf8(strtoupper(__('Supplier')))));
     $cols1 = array('0' => array('width' => 265, 'justification' => 'center'), '1' => array('width' => 265, 'justification' => 'center'));
     $PDF->ezTable($data1, '', __('COMPUTER IDENTIFICATION', 'immobilizationsheets'), array('showHeadings' => 0, 'cols' => $cols1));
     //ligne2 (4 / 9)
     $data2 = array(array('0' => Toolbox::decodeFromUtf8(__('Assignment number (si non informatique)', 'immobilizationsheets')), '1' => '', '2' => Toolbox::decodeFromUtf8(__('Brand')), '3' => $fabricant_item));
     $cols2 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data2, '', '', array('showHeadings' => 0, 'cols' => $cols2, 'fontSize' => 8));
     //ligne3 (5 / 10)
     $data3 = array(array('0' => Toolbox::decodeFromUtf8(__('Invoice number')), '1' => $order_number_item, '2' => Toolbox::decodeFromUtf8(__('Type')), '3' => $type_item));
     $cols3 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data3, '', '', array('showHeadings' => 0, 'cols' => $cols3, 'fontSize' => 8));
     //ligne4 (6 / 11)
     $data4 = array(array('0' => Toolbox::decodeFromUtf8(__('Value')), '1' => $value_item, '2' => Toolbox::decodeFromUtf8(__('Serial Number')), '3' => $serial_item));
     $cols4 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data4, '', '', array('showHeadings' => 0, 'cols' => $cols4, 'fontSize' => 8));
     //ligne5 (7 / 12)
     $data5 = array(array('0' => Toolbox::decodeFromUtf8(__('Assignment (client / inv. …)', 'immobilizationsheets')), '1' => '', '2' => Toolbox::decodeFromUtf8(__('Permanent number', 'immobilizationsheets')), '3' => $immobilizationsheets_item));
     $cols5 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data5, '', '', array('showHeadings' => 0, 'cols' => $cols5, 'fontSize' => 8));
     $PDF->ezSetDy(-10);
     //trigramme
     $data6 = array(array('0' => Toolbox::decodeFromUtf8(__('Trigram and visa of the person in charge', 'immobilizationsheets')), '1' => ''));
     $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left'));
     $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8));
     //partie 2
     $PDF->ezSetDy(-20);
     $title1 = array(array('' => Toolbox::decodeFromUtf8(__('II - PART TO BE FILLED BY THE NETWORK ADMINISTRATOR', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(transfer to the assistant of management)', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-10);
     //ligne1 (name  / user)
     $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('User name / sector', 'immobilizationsheets')), '1' => $user_item, '2' => Toolbox::decodeFromUtf8(__('Name')), '3' => $name_item));
     $cols1 = array('0' => array('width' => 132.5, 'justification' => 'center'), '1' => array('width' => 132.5, 'justification' => 'center'), '2' => array('width' => 132.5, 'justification' => 'center'), '3' => array('width' => 132.5, 'justification' => 'center'));
     $PDF->ezTable($data1, '', __('PRINCIPAL ASSIGNMENT', 'immobilizationsheets'), array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
     $PDF->ezSetDy(-10);
     if ($itemtype == 'Computer') {
         //title config mat?ielle
         $title = array(array('' => Toolbox::decodeFromUtf8(__('HARDWARE CONFIGURATION', 'immobilizationsheets'))));
         $cols = array('' => array('width' => 530, 'justification' => 'center'));
         $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1));
         $PDF->ezSetDy(-10);
         //ligne1 (processeur  / ram quantit?/ ram type)
         $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('Processor')), '1' => $proc_item, '2' => Toolbox::decodeFromUtf8(__('Memory')), '3' => Toolbox::decodeFromUtf8(__('Quantity', 'immobilizationsheets')), '4' => $ram_item, '5' => Toolbox::decodeFromUtf8(__('Type')), '6' => $ram_type_item));
         $cols1 = array('0' => array('width' => 55, 'justification' => 'center'), '1' => array('width' => 200, 'justification' => 'left'), '2' => array('width' => 55, 'justification' => 'center'), '3' => array('width' => 55, 'justification' => 'center'), '4' => array('width' => 55, 'justification' => 'center'), '5' => array('width' => 55, 'justification' => 'center'), '6' => array('width' => 55, 'justification' => 'center'));
         $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
         //ligne2 (Disque dur / Lecteur)
         $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('Hard drive')), '1' => $hdd_item, '2' => Toolbox::decodeFromUtf8(__('Drive')), '3' => $lecteur_item));
         $cols1 = array('0' => array('width' => 55, 'justification' => 'center'), '1' => array('width' => 200, 'justification' => 'left'), '2' => array('width' => 55, 'justification' => 'center'), '3' => array('width' => 220, 'justification' => 'center'));
         $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
         $PDF->ezSetDy(-10);
         //titre suppl?ent
         $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Additional cards or peripherals', 'immobilizationsheets')) . "</u> : ", 8, array("justification" => "left"));
         $PDF->ezSetDy(-10);
         if ($number6 > 0) {
             //title config logicielle
             $title = array(array('' => Toolbox::decodeFromUtf8(__('SOFTWARE CONFIGURATION', 'immobilizationsheets'))));
             $cols = array('' => array('width' => 530, 'justification' => 'center'));
             $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1));
             $PDF->ezSetDy(-10);
             //titre logiciels
             $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Oem/Delivered software', 'immobilizationsheets')) . "</u> : ", 8, array("justification" => "left"));
             $PDF->ezSetDy(-10);
             //ligne1 (name  / version / licence)
             $data0 = array(array('0' => Toolbox::decodeFromUtf8(__('Name')), '1' => Toolbox::decodeFromUtf8(__('Version')), '2' => Toolbox::decodeFromUtf8(__('License number'))));
             $cols1 = array('0' => array('width' => 240, 'justification' => 'left'), '1' => array('width' => 50, 'justification' => 'center'), '2' => array('width' => 240, 'justification' => 'center'));
             $PDF->ezTable($data0, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
             while ($data6 = $DB->fetch_array($result6)) {
                 $soft_name_item = $data6["name"];
                 $soft_version_item = Dropdown::getDropdownName("glpi_softwareversions", $data6["softwareversions_id_buy"]);
                 $soft_license_item = $data6["serial"];
                 $data1 = array(array('0' => $soft_name_item, '1' => $soft_version_item, '2' => $soft_license_item));
                 $cols1 = array('0' => array('width' => 240, 'justification' => 'left'), '1' => array('width' => 50, 'justification' => 'center'), '2' => array('width' => 240, 'justification' => 'center'));
                 $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
             }
             $PDF->ezSetDy(-10);
         }
     }
     //trigramme
     $data6 = array(array('0' => Toolbox::decodeFromUtf8(__('Trigram and visa of the person in charge', 'immobilizationsheets')), '1' => ''));
     $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left'));
     $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8));
     //partie 3
     $PDF->ezSetDy(-20);
     $title1 = array(array('' => Toolbox::decodeFromUtf8(__('III - PART TO BE FILLED BY THE MANAGEMENT ASSISTANT', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(for checking, visa and classification)', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-20);
     //title
     $title = array(array('' => Toolbox::decodeFromUtf8(__('CALCULATION OF AMORTIZATION', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'center'));
     $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1));
     $PDF->ezSetDy(-10);
     //Base d'amortissement
     $amort0 = array(array('0' => Toolbox::decodeFromUtf8(__('Base amortization', 'immobilizationsheets')), '1' => $sink_type_item));
     $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left'));
     $PDF->ezTable($amort0, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0));
     $PDF->ezSetDy(-10);
     //Duree d'amortissement
     $amort1 = array(array('0' => Toolbox::decodeFromUtf8(__('Amortization duration')), '1' => $sink_time_item));
     $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left'));
     $PDF->ezTable($amort1, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0));
     $PDF->ezSetDy(-10);
     //Date de debut d'amortissement
     $amort2 = array(array('0' => Toolbox::decodeFromUtf8(__('Date of beginning of amortization', 'immobilizationsheets')), '1' => $use_date_item));
     $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left'));
     $PDF->ezTable($amort2, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0));
     $PDF->ezSetDy(-10);
     //visa
     $amort1 = array(array('0' => Toolbox::decodeFromUtf8(__('VISA A.G.', 'immobilizationsheets')), '1' => ""));
     $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left'));
     $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8));
     //end
     $PDF->addInfo('Author', Toolbox::decodeFromUtf8(Html::clean(getUserName(Session::getLoginUserID()))));
     $config = new PluginImmobilizationsheetsConfig();
     if ($config->getFromDB(1)) {
         if ($saveas == 1) {
             if ($config->fields["use_backup"] == 1) {
                 $path = GLPI_DOC_DIR . "/_uploads/";
                 $time_file = date("Y-m-d-H-i-s");
                 $filename = "immo_" . $time_file . "_" . $data["name"] . ".pdf";
                 $filepath = $path . $filename;
                 $fp = fopen($filepath, 'wb');
                 fwrite($fp, $PDF->output());
                 fclose($fp);
                 $doc = new document();
                 $input = array();
                 $input["entities_id"] = $data["entities_id"];
                 $input["name"] = addslashes(self::getTypeName(1) . " " . $data["name"] . " " . $time_file);
                 $input["upload_file"] = $filename;
                 $input["documentcategories_id"] = $config->fields["documentcategories_id"];
                 $input["type"] = "application/pdf";
                 $input["date_mod"] = date("Y-m-d H:i:s");
                 $input["users_id"] = Session::getLoginUserID();
                 $newdoc = $doc->add($input);
                 $docitem = new Document_Item();
                 $docitem->add(array('documents_id' => $newdoc, 'itemtype' => $itemtype, 'items_id' => $ID, 'entities_id' => $input["entities_id"]));
             }
         }
     }
 }
 @copyright Copyright (c) 2010-2015 Order plugin team
 @license   GPLv2+
            http://www.gnu.org/licenses/gpl.txt
 @link      https://forge.indepnet.net/projects/order
 @link      http://www.glpi-project.org/
 @since     2009
 ---------------------------------------------------------------------- */
include_once "../../../inc/includes.php";
Session::checkCentralAccess();
// Make a select box for references
if (isset($_POST["itemtype"])) {
    $query = "SELECT s.`plugin_order_references_id` as id, s.`price_taxfree`, s.`reference_code`, r.`name`\n             FROM `glpi_plugin_order_references_suppliers` s\n             LEFT JOIN `glpi_plugin_order_references` r ON (s.`plugin_order_references_id` = r.`id`)\n             WHERE r.`itemtype` = '{$_POST['itemtype']}' AND s.`suppliers_id` = '{$_POST['suppliers_id']}'\n             ORDER BY s.`reference_code`";
    $result = $DB->query($query);
    $number = $DB->numrows($result);
    $values = array(0 => Dropdown::EMPTY_VALUE);
    if ($number) {
        while ($data = $DB->fetch_assoc($result)) {
            $values[$data['id']] = !empty($data['reference_code']) ? $data['reference_code'] : $data['name'];
        }
    }
    Dropdown::showFromArray($_POST['fieldname'], $values, array('rand' => $_POST['rand']));
    $params = array('reference_id' => '__VALUE__');
    Ajax::updateItemOnSelectEvent('dropdown_plugin_order_references_id' . $_POST['rand'], 'show_priceht', '../ajax/dropdownReference.php', $params);
    // Get price
} elseif (isset($_POST['reference_id'])) {
    $query = "SELECT `price_taxfree`\n             FROM `glpi_plugin_order_references_suppliers`\n             WHERE `plugin_order_references_id` = '{$_POST['reference_id']}'";
    $result = $DB->query($query);
    $price = $DB->result($result, 0, 'price_taxfree');
    $price = Html::formatNumber($price);
    echo '<input type="text" name="price" value="' . $price . '" style="text-align:center" size="10" />';
}
}
$types = array('Cartridge', 'Consumable', 'SoftwareLicense');
$i = 0;
echo "<table width='90%'><tr><td class='center top'>";
while (count($types) > 0) {
    $type = array_shift($types);
    if (display_infocoms_report($type, $_POST["date1"], $_POST["date2"])) {
        echo "</td>";
        $i++;
        if ($i % 2 == 0) {
            echo "</tr><tr>";
        }
        echo "<td class='center top'>";
    }
}
if ($i % 2 == 0) {
    echo "&nbsp;</td><td>&nbsp;";
}
echo "&nbsp;</td></tr></table>";
//TRANS: %1$s and %2$s are values
$tmpmsg = sprintf(__('Total: Value=%1$s - Account net value=%2$s'), Html::formatNumber($valeurtot), Html::formatNumber($valeurnettetot));
echo "<div class='center'><h3>{$tmpmsg}</h3></div>\n";
if (count($valeurnettegraphtot) > 0) {
    $valeurnettegraphtotdisplay = array_map('round', $valeurnettegraphtot);
    Stat::showGraph(array(__('Account net value') => $valeurnettegraphtotdisplay), array('title' => __('Account net value')));
}
if (count($valeurgraphtot) > 0) {
    $valeurgraphtotdisplay = array_map('round', $valeurgraphtot);
    Stat::showGraph(array(_x('price', 'Value') => $valeurgraphtotdisplay), array('title' => _x('price', 'Value')));
}
Html::footer();
Example #18
0
 static function getFieldsValue($searchOption, $field, $itemclass)
 {
     global $CFG_GLPI;
     $display = $itemclass->fields[$field['Field']];
     echo "<h3><span class='title'>" . $searchOption['name'] . " : </span>";
     $type = self::getTypeFields($searchOption);
     if ($type == 'dropdown') {
         echo Dropdown::getDropdownName($searchOption['table'], $display);
     } else {
         if (isset($searchOption['datatype']) && $searchOption['datatype'] == 'decimal') {
             echo Html::formatNumber($display, 2);
         } else {
             if ($searchOption['table'] == 'glpi_users') {
                 echo getUserName($display);
             } else {
                 if ($searchOption['field'] == 'contact_num') {
                     echo "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/positions/pics/miniphones.png' title='" . $display . "'>&nbsp;\r\n         <a href=\"tel:" . $display . "\">" . $display . "</a>";
                 } else {
                     if ($searchOption['field'] == 'number_line') {
                         echo "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/positions/pics/miniphones.png' title='" . $display . "'>&nbsp;\r\n         <a href=\"tel:" . $display . "\">" . $display . "</a>";
                     } else {
                         echo $display;
                     }
                 }
             }
         }
     }
     echo "</h3></br>";
 }
Example #19
0
 /**
  * @covers Html::formatNumber
  */
 public function testFormatNumber()
 {
     $_SESSION['glpinumber_format'] = 0;
     $origin = '';
     $expected = 0;
     $this->assertEquals($expected, Html::formatNumber($origin));
     $origin = '1207.3';
     $expected = '1&nbsp;207.30';
     $this->assertEquals($expected, Html::formatNumber($origin));
     $expected = '1207.30';
     $this->assertEquals($expected, Html::formatNumber($origin, true));
     $origin = 124556.693;
     $expected = '124&nbsp;556.69';
     $this->assertEquals($expected, Html::formatNumber($origin));
     $origin = 120.123456789;
     $expected = '120.12';
     $this->assertEquals($expected, Html::formatNumber($origin));
     $expected = '120.12346';
     $this->assertEquals($expected, Html::formatNumber($origin, false, 5));
     $expected = '120';
     $this->assertEquals($expected, Html::formatNumber($origin, false, 0));
     $origin = 120.999;
     $expected = '121';
     $this->assertEquals($expected, Html::formatNumber($origin));
     $this->assertEquals($expected, Html::formatNumber($origin, false, 0));
     $this->assertEquals('-', Html::formatNumber('-'));
     $_SESSION['glpinumber_format'] = 2;
     $origin = '1207.3';
     $expected = '1&nbsp;207,30';
     $this->assertEquals($expected, Html::formatNumber($origin));
     $_SESSION['glpinumber_format'] = 3;
     $origin = '1207.3';
     $expected = '1207.30';
     $this->assertEquals($expected, Html::formatNumber($origin));
     $_SESSION['glpinumber_format'] = 4;
     $origin = '1207.3';
     $expected = '1207,30';
     $this->assertEquals($expected, Html::formatNumber($origin));
     $_SESSION['glpinumber_format'] = 1337;
     $origin = '1207.3';
     $expected = '1,207.30';
     $this->assertEquals($expected, Html::formatNumber($origin));
 }
Example #20
0
 public function showForm($ID, $options = array())
 {
     $this->initForm($ID, $options);
     $this->showFormHeader($options);
     $order_order = new PluginOrderOrder();
     $order_order->getFromDB($this->fields['plugin_order_orders_id']);
     $order_reference = new PluginOrderReference();
     $order_reference->getFromDB($this->fields["plugin_order_references_id"]);
     $canedit = $order_order->can($this->fields['plugin_order_orders_id'], UPDATE) && $order_order->canUpdateOrder() && !$order_order->isCanceled();
     $canedit_comment = $order_order->can($this->fields['plugin_order_orders_id'], UPDATE) && !$order_order->isCanceled();
     echo "<input type='hidden' name='plugin_order_orders_id' value='" . $this->fields['plugin_order_orders_id'] . "'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __("Order", "order") . ": </td>";
     echo "<td>";
     echo $order_order->getLink(true);
     echo "</td>";
     echo "<td>" . __("Reference") . ": </td>";
     echo "<td>";
     $data = array();
     $data["id"] = $this->fields["plugin_order_references_id"];
     $data["name"] = $order_reference->fields["name"];
     echo $order_reference->getReceptionReferenceLink($data);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __("Unit price tax free", "order") . ": </td>";
     if ($canedit) {
         echo "<td><input type='number' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='price_taxfree' value='" . $this->fields['price_taxfree'] . "' class='decimal'>";
     } else {
         echo "<td>" . Html::formatNumber($this->fields['price_taxfree']) . "</td>";
     }
     echo "<td>" . __("VAT", "order") . ": </td>";
     echo "<td>";
     if ($canedit) {
         PluginOrderOrderTax::Dropdown(array('value' => $this->fields['plugin_order_ordertaxes_id']));
     } else {
         echo Dropdown::getDropdownName('glpi_plugin_order_ordertaxes', $this->fields['plugin_order_ordertaxes_id']);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __("Discount (%)", "order") . ": </td>";
     if ($canedit) {
         echo "<td><input type='number' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='discount' \n                          value='" . $this->fields['discount'] . "' class='decimal'>";
     } else {
         echo "<td>" . Html::formatNumber($this->fields['discount']) . "</td>";
     }
     echo "<td>" . __("Discounted price tax free", "order") . ": </td>";
     echo "<td>" . Html::formatNumber($this->fields['price_discounted']) . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __("Price ATI", "order") . ": </td>";
     echo "<td>" . Html::formatNumber($this->fields['price_ati']) . "</td>";
     echo "<td>" . __("Status") . ": </td>";
     echo "<td>";
     echo Dropdown::getDropdownName('glpi_plugin_order_deliverystates', $this->fields['plugin_order_deliverystates_id']);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'><td>";
     //comments of order
     echo __("Description") . ":  </td>";
     echo "<td colspan='3'>";
     if ($canedit_comment) {
         echo "<textarea cols='50' rows='4' name='comment'>" . $this->fields["comment"] . "</textarea>";
     } else {
         echo $this->fields['comment'];
     }
     echo "</td></tr>";
     $this->showFormButtons(array('canedit' => $canedit || $canedit_comment, 'candel' => $canedit));
     return true;
 }
 /**
  * Print the computers disks
  *
  * @param $comp                  Computer object
  * @param $withtemplate boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForComputer(Computer $comp, $withtemplate = '')
 {
     global $DB;
     $ID = $comp->fields['id'];
     if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) {
         return false;
     }
     $canedit = $comp->canEdit($ID);
     if ($canedit && !(!empty($withtemplate) && $withtemplate == 2)) {
         echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='computerdisk.form.php?computers_id={$ID}&amp;withtemplate=" . $withtemplate . "'>";
         _e('Add a volume');
         echo "</a></div>\n";
     }
     echo "<div class='center'>";
     $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n                       `glpi_computerdisks`.*\n                FROM `glpi_computerdisks`\n                LEFT JOIN `glpi_filesystems`\n                          ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n                WHERE `computers_id` = '{$ID}'\n                      AND `is_deleted` = '0'";
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixehov table-striped table-hover'>";
         $colspan = 7;
         if (Plugin::haveImport()) {
             $colspan++;
         }
         echo "<tr class='noHover'><th colspan='{$colspan}'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>";
         if ($DB->numrows($result)) {
             $header = "<tr><th>" . __('Name') . "</th>";
             if (Plugin::haveImport()) {
                 $header .= "<th>" . __('Automatic inventory') . "</th>";
             }
             $header .= "<th>" . __('Partition') . "</th>";
             $header .= "<th>" . __('Mount point') . "</th>";
             $header .= "<th>" . __('File system') . "</th>";
             $header .= "<th>" . __('Global size') . "</th>";
             $header .= "<th>" . __('Free size') . "</th>";
             $header .= "<th>" . __('Free percentage') . "</th>";
             $header .= "</tr>";
             echo $header;
             Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
             $disk = new self();
             while ($data = $DB->fetch_assoc($result)) {
                 $disk->getFromDB($data['id']);
                 echo "<tr class='tab_bg_2'>";
                 echo "<td>" . $disk->getLink() . "</td>";
                 if (Plugin::haveImport()) {
                     echo "<td>" . Dropdown::getYesNo($data['is_dynamic']) . "</td>";
                 }
                 echo "<td>" . $data['device'] . "</td>";
                 echo "<td>" . $data['mountpoint'] . "</td>";
                 echo "<td>" . $data['fsname'] . "</td>";
                 //TRANS: %s is a size
                 $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['totalsize'], false, 0));
                 echo "<td class='right'>{$tmp}<span class='small_space'></span></td>";
                 $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['freesize'], false, 0));
                 echo "<td class='right'>{$tmp}<span class='small_space'></span></td>";
                 echo "<td>";
                 $percent = 0;
                 if ($data['totalsize'] > 0) {
                     $percent = round(100 * $data['freesize'] / $data['totalsize']);
                 }
                 Html::displayProgressBar('100', $percent, array('simple' => true, 'forcepadding' => false));
                 echo "</td>";
                 echo "</tr>";
                 Session::addToNavigateListItems(__CLASS__, $data['id']);
             }
             echo $header;
         } else {
             echo "<tr class='tab_bg_2'><th colspan='{$colspan}'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
     }
     echo "</div><br>";
 }
Example #22
0
 function displayField($canedit, $name, $value, $template, $description = array())
 {
     global $GO_BLACKLIST_FIELDS;
     $searchoption = PluginGenericobjectField::getOptionsWithGlobal($name, get_called_class());
     if (!empty($searchoption) && !in_array($name, self::getFieldsToHide())) {
         $this->startColumn();
         echo $searchoption['name'];
         if (isset($searchoption['autoname']) && $searchoption['autoname'] && $template) {
             echo "*&nbsp;";
         }
         $this->endColumn();
         $this->startColumn();
         switch ($description['Type']) {
             case "int(11)":
                 $fk_table = getTableNameForForeignKeyField($name);
                 if ($fk_table != '') {
                     $itemtype = getItemTypeForTable($fk_table);
                     $dropdown = new $itemtype();
                     $parameters = array('name' => $name, 'value' => $value, 'comments' => true);
                     if ($dropdown->isEntityAssign()) {
                         $parameters["entity"] = $this->fields['entities_id'];
                     }
                     if ($dropdown->maybeRecursive()) {
                         $parameters['entity_sons'] = true;
                     }
                     if (isset($searchoption['condition'])) {
                         $parameters['condition'] = $searchoption['condition'];
                     }
                     Dropdown::show($itemtype, $parameters);
                 } else {
                     $min = $max = $step = 0;
                     if (isset($searchoption['min'])) {
                         $min = $searchoption['min'];
                     } else {
                         $min = 0;
                     }
                     if (isset($searchoption['max'])) {
                         $max = $searchoption['max'];
                     } else {
                         $max = 100;
                     }
                     if (isset($searchoption['step'])) {
                         $step = $searchoption['step'];
                     } else {
                         $step = 1;
                     }
                     Dropdown::showInteger($name, $value, $min, $max, $step);
                 }
                 break;
             case "tinyint(1)":
                 Dropdown::showYesNo($name, $value);
                 break;
             case "varchar(255)":
                 if (isset($searchoption['autoname']) && $searchoption['autoname']) {
                     $objectName = autoName($this->fields[$name], $name, $template === "newcomp", $this->getType(), $this->fields["entities_id"]);
                 } else {
                     $objectName = $this->fields[$name];
                 }
                 Html::autocompletionTextField($this, $name, array('value' => $objectName));
                 break;
             case "longtext":
             case "text":
                 echo "<textarea cols='40' rows='4' name='" . $name . "'>" . $value . "</textarea>";
                 break;
             case "date":
                 Html::showDateFormItem($name, $value, false, true);
                 break;
             case "datetime":
                 Html::showDateTimeFormItem($name, $value, false, true);
                 break;
             default:
             case "float":
                 echo "<input type='text' name='{$name}' value='{$value}'>";
                 break;
             case 'decimal':
                 echo "<input type='text' name='{$name}' value='" . Html::formatNumber($value) . "'>";
                 break;
         }
         $this->endColumn();
     }
 }
 /**
  * Print the HTML array of value consumed for a budget
  *
  * @return Nothing (display)
  **/
 function showValuesByEntity()
 {
     global $DB;
     $budgets_id = $this->fields['id'];
     if (!$this->can($budgets_id, READ)) {
         return false;
     }
     // Type for which infocom are only template
     $ignore = array('CartridgeItem', 'ConsumableItem', 'Software');
     $query = "SELECT DISTINCT `itemtype`\n                FROM `glpi_infocoms`\n                WHERE `budgets_id` = '{$budgets_id}'\n                      AND `itemtype` NOT IN ('" . implode("','", $ignore) . "')" . getEntitiesRestrictRequest(" AND", 'glpi_infocoms', "entities_id") . "\n                GROUP BY `itemtype`";
     $result = $DB->query($query);
     $total = 0;
     $totalbytypes = array();
     $itemtypes = array();
     $entities_values = array();
     $entitiestype_values = array();
     $found_types = array();
     if ($DB->numrows($result)) {
         while ($types = $DB->fetch_assoc($result)) {
             $itemtypes[] = $types['itemtype'];
         }
     }
     $itemtypes[] = 'Contract';
     $itemtypes[] = 'Ticket';
     $itemtypes[] = 'Problem';
     $itemtypes[] = 'Change';
     foreach ($itemtypes as $itemtype) {
         if (!($item = getItemForItemtype($itemtype))) {
             continue;
         }
         $table = getTableForItemType($itemtype);
         switch ($itemtype) {
             case 'Contract':
                 $query_infos = "SELECT SUM(`glpi_contractcosts`.`cost`) AS `sumvalue`,\n                                       `{$table}`.`entities_id`\n                                FROM `glpi_contractcosts`\n                                INNER JOIN `{$table}`\n                                    ON (`glpi_contractcosts`.`contracts_id` = `{$table}`.`id`)\n                                WHERE `glpi_contractcosts`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $table, "entities_id") . "\n                                      AND `{$table}`.`is_template` = '0'\n                                GROUP BY `{$table}`.`entities_id`";
                 break;
             case 'Ticket':
             case 'Problem':
             case 'Change':
                 $costtable = getTableForItemType($item->getType() . 'Cost');
                 $query_infos = "SELECT SUM(`{$costtable}`.`actiontime`*`{$costtable}`.`cost_time`/" . HOUR_TIMESTAMP . "\n                                          + `{$costtable}`.`cost_fixed`\n                                          + `{$costtable}`.`cost_material`) AS `sumvalue`,\n                                       `{$table}`.`entities_id`\n                                FROM `{$costtable}`\n                                INNER JOIN `{$table}`\n                                    ON (`{$costtable}`.`" . $item->getForeignKeyField() . "` = `{$table}`.`id`)\n                                WHERE `{$costtable}`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $table, "entities_id") . "\n                                GROUP BY `{$table}`.`entities_id`";
                 break;
             default:
                 $query_infos = "SELECT SUM(`glpi_infocoms`.`value`) AS `sumvalue`,\n                                       `{$table}`.`entities_id`\n                                FROM `{$table}`\n                                INNER JOIN `glpi_infocoms`\n                                    ON (`glpi_infocoms`.`items_id` = `{$table}`.`id`\n                                        AND `glpi_infocoms`.`itemtype` = '{$itemtype}')\n                                WHERE `glpi_infocoms`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $table, "entities_id");
                 if ($item->maybeTemplate()) {
                     $query_infos .= " AND `{$table}`.`is_template` = '0' ";
                 }
                 $query_infos .= "GROUP BY `{$table}`.`entities_id`";
                 break;
         }
         if ($result_infos = $DB->query($query_infos)) {
             if ($DB->numrows($result_infos)) {
                 $found_types[$itemtype] = $item->getTypeName(1);
                 $totalbytypes[$itemtype] = 0;
                 //Store, for each entity, the budget spent
                 while ($values = $DB->fetch_assoc($result_infos)) {
                     if (!isset($entities_values[$values['entities_id']])) {
                         $entities_values[$values['entities_id']] = 0;
                     }
                     if (!isset($entitiestype_values[$values['entities_id']][$itemtype])) {
                         $entitiestype_values[$values['entities_id']][$itemtype] = 0;
                     }
                     $entities_values[$values['entities_id']] += $values['sumvalue'];
                     $entitiestype_values[$values['entities_id']][$itemtype] += $values['sumvalue'];
                     $total += $values['sumvalue'];
                     $totalbytypes[$itemtype] += $values['sumvalue'];
                 }
             }
         }
     }
     $budget = new self();
     $budget->getFromDB($budgets_id);
     $colspan = count($found_types) + 2;
     echo "<div class='spaced'><table class='tab_cadre_fixehov table-striped table-hover'>";
     echo "<tr class='noHover'><th colspan='{$colspan}'>" . __('Total spent on the budget') . "</th></tr>";
     echo "<tr><th>" . __('Entity') . "</th>";
     if (count($found_types)) {
         foreach ($found_types as $type => $typename) {
             echo "<th>{$typename}</th>";
         }
     }
     echo "<th>" . __('Total') . "</th>";
     echo "</tr>";
     // get all entities ordered by names
     $allentities = getAllDatasFromTable('glpi_entities', '', true, 'completename');
     foreach ($allentities as $entity => $data) {
         if (isset($entities_values[$entity])) {
             echo "<tr class='tab_bg_1'>";
             echo "<td class='b'>" . Dropdown::getDropdownName('glpi_entities', $entity) . "</td>";
             if (count($found_types)) {
                 foreach ($found_types as $type => $typename) {
                     echo "<td class='numeric'>";
                     $typevalue = 0;
                     if (isset($entitiestype_values[$entity][$type])) {
                         $typevalue = $entitiestype_values[$entity][$type];
                     }
                     echo Html::formatNumber($typevalue);
                     echo "</td>";
                 }
             }
             echo "<td class='right b'>" . Html::formatNumber($entities_values[$entity]) . "</td>";
             echo "</tr>";
         }
     }
     if (count($found_types)) {
         echo "<tr class='tab_bg_1'>";
         echo "<td class='right b'>" . __('Total') . "</td>";
         foreach ($found_types as $type => $typename) {
             echo "<td class='numeric b'>";
             echo Html::formatNumber($totalbytypes[$type]);
             echo "</td>";
         }
         echo "<td class='numeric b'>" . Html::formatNumber($total) . "</td>";
         echo "</tr>";
     }
     echo "<tr class='tab_bg_1 noHover'><th colspan='{$colspan}'><br></th></tr>";
     echo "<tr class='tab_bg_1 noHover'>";
     echo "<td class='right' colspan='" . ($colspan - 1) . "'>" . __('Total spent on the budget') . "</td>";
     echo "<td class='numeric b'>" . Html::formatNumber($total) . "</td></tr>";
     if ($_SESSION['glpiactive_entity'] == $budget->fields['entities_id']) {
         echo "<tr class='tab_bg_1 noHover'>";
         echo "<td class='right' colspan='" . ($colspan - 1) . "'>" . __('Total remaining on the budget') . "</td>";
         echo "<td class='numeric b'>" . Html::formatNumber($budget->fields['value'] - $total) . "</td></tr>";
     }
     echo "</table></div>";
 }
 /**
  * Computer total cost of a item
  *
  * @param $actiontime      float    actiontime
  * @param $cost_time       float    time cost
  * @param $cost_fixed      float    fixed cost
  * @param $cost_material   float    material cost
  * @param $edit            boolean  used for edit of computation ? (true by default)
  *
  * @return total cost formatted string
  **/
 static function computeTotalCost($actiontime, $cost_time, $cost_fixed, $cost_material, $edit = true)
 {
     return Html::formatNumber($actiontime * $cost_time / HOUR_TIMESTAMP + $cost_fixed + $cost_material, $edit);
 }
 function showTotal()
 {
     global $DB;
     $ID = $this->getID();
     $PluginRacksConfig = new PluginRacksConfig();
     $query = "SELECT SUM(`weight`) AS total_weight, SUM(`amps`) AS total_amps,\n                     SUM(`flow_rate`) AS total_flow_rate,\n                     SUM(`dissipation`) AS total_dissipation,\n                     COUNT(`first_powersupply`) AS total_alim1,\n                     COUNT(`second_powersupply`) AS total_alim2\n               FROM `glpi_plugin_racks_racks_items`\n               WHERE `plugin_racks_racks_id` = '{$ID}' ";
     $query_alim1 = "SELECT COUNT(`first_powersupply`) AS total_alim1\n                      FROM `glpi_plugin_racks_racks_items`\n                      WHERE `plugin_racks_racks_id` = '{$ID}' \n                        AND `first_powersupply` > 0 ";
     $result_alim1 = $DB->query($query_alim1);
     $query_alim2 = "SELECT COUNT(`second_powersupply`) AS total_alim2\n                      FROM `glpi_plugin_racks_racks_items`\n                      WHERE `plugin_racks_racks_id` = '{$ID}' \n                        AND `second_powersupply` > 0 ";
     $result_alim2 = $DB->query($query_alim2);
     echo "<form><div class='center'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='6'>" . __('Total') . "</th></tr><tr>";
     //echo "<th colspan='3'>".__('Equipment')."</th>";
     echo "<th>" . __('Power supplies number', 'racks') . "</th>";
     echo "<th>" . __('Total current', 'racks') . "</th>";
     // Courant consomme
     echo "<th>" . __('Calorific waste', 'racks') . "</th>";
     echo "<th>" . __('Flow rate', 'racks') . "</th>";
     echo "<th>" . __('Weight', 'racks') . "</th>";
     echo "</tr>";
     $total_cordons = 0;
     foreach ($DB->request($query_alim1) as $data_alim1) {
         $total_cordons += $data_alim1["total_alim1"];
     }
     foreach ($DB->request($query_alim2) as $data_alim2) {
         $total_cordons += $data_alim2["total_alim2"];
     }
     foreach ($DB->request($query) as $data) {
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>" . $total_cordons . "</td>";
         echo "<td class='center'><b>";
         echo Html::formatNumber($data["total_amps"], true);
         echo " " . __('amps', 'racks') . "</b></td>";
         echo "<td class='center'><b>";
         echo Html::formatNumber($data["total_dissipation"], true) . "&nbsp;";
         $PluginRacksConfig->getUnit("dissipation");
         echo "</b></td>";
         echo "<td class='center'><b>";
         echo Html::formatNumber($data["total_flow_rate"], true) . "&nbsp;";
         $PluginRacksConfig->getUnit("rate");
         echo "</b></td>";
         $total_weight = $data["total_weight"] + $this->fields['weight'];
         echo "<td class='center'><b>";
         echo Html::formatNumber($total_weight, true) . "&nbsp";
         $PluginRacksConfig->getUnit("weight");
         echo "</b></td>";
         echo "</tr>";
     }
     echo "</table></div>";
     Html::closeForm();
 }
Example #26
0
/** Display an infocom report
 *
 * @param $itemtype  item type
 * @param $begin     begin date
 * @param $end       end date
**/
function display_infocoms_report($itemtype, $begin, $end)
{
    global $DB, $valeurtot, $valeurnettetot, $valeurnettegraphtot, $valeurgraphtot, $CFG_GLPI;
    $itemtable = getTableForItemType($itemtype);
    $query = "SELECT `glpi_infocoms`.*,\n                    `{$itemtable}`.`name` AS name,\n                    `{$itemtable}`.`ticket_tco`,\n                    `glpi_entities`.`completename` AS entname,\n                    `glpi_entities`.`id` AS entID\n             FROM `glpi_infocoms`\n             INNER JOIN `{$itemtable}` ON (`{$itemtable}`.`id` = `glpi_infocoms`.`items_id`\n                                         AND `glpi_infocoms`.`itemtype` = '{$itemtype}')\n             LEFT JOIN `glpi_entities` ON (`{$itemtable}`.`entities_id` = `glpi_entities`.`id`)\n             WHERE `{$itemtable}`.`is_template` = '0' " . getEntitiesRestrictRequest("AND", $itemtable);
    if (!empty($begin)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` >= '{$begin}'\n                       OR `glpi_infocoms`.`use_date` >= '{$begin}') ";
    }
    if (!empty($end)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` <= '{$end}'\n                       OR `glpi_infocoms`.`use_date` <= '{$end}') ";
    }
    $query .= " ORDER BY entname ASC, `buy_date`, `use_date`";
    $display_entity = Session::isMultiEntitiesMode();
    $result = $DB->query($query);
    if ($DB->numrows($result) > 0 && ($item = getItemForItemtype($itemtype))) {
        echo "<h2>" . $item->getTypeName(1) . "</h2>";
        echo "<table class='tab_cadre'><tr><th>" . __('Name') . "</th>";
        if ($display_entity) {
            echo "<th>" . __('Entity') . "</th>";
        }
        echo "<th>" . _x('price', 'Value') . "</th><th>" . __('ANV') . "</th>";
        echo "<th>" . __('TCO') . "</th><th>" . __('Date of purchase') . "</th>";
        echo "<th>" . __('Startup date') . "</th><th>" . __('Warranty expiration date') . "</th></tr>";
        $valeursoustot = 0;
        $valeurnettesoustot = 0;
        $valeurnettegraph = array();
        $valeurgraph = array();
        while ($line = $DB->fetch_assoc($result)) {
            if (isset($line["is_global"]) && $line["is_global"] && $item->getFromDB($line["items_id"])) {
                $line["value"] *= Computer_Item::countForItem($item);
            }
            if ($line["value"] > 0) {
                $valeursoustot += $line["value"];
            }
            $valeurnette = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "n");
            $tmp = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "all");
            if (is_array($tmp) && count($tmp) > 0) {
                foreach ($tmp["annee"] as $key => $val) {
                    if ($tmp["vcnetfin"][$key] > 0) {
                        if (!isset($valeurnettegraph[$val])) {
                            $valeurnettegraph[$val] = 0;
                        }
                        $valeurnettegraph[$val] += $tmp["vcnetdeb"][$key];
                    }
                }
            }
            if (!empty($line["buy_date"])) {
                $year = substr($line["buy_date"], 0, 4);
                if ($line["value"] > 0) {
                    if (!isset($valeurgraph[$year])) {
                        $valeurgraph[$year] = 0;
                    }
                    $valeurgraph[$year] += $line["value"];
                }
            }
            $valeurnettesoustot += str_replace(" ", "", $valeurnette);
            echo "<tr class='tab_bg_1'><td>" . $line["name"] . "</td>";
            if ($display_entity) {
                echo "<td>" . $line['entname'] . "</td>";
            }
            echo "<td class='right'>" . Html::formatNumber($line["value"]) . "</td>" . "<td class='right'>" . Html::formatNumber($valeurnette) . "</td>" . "<td class='right'>" . Infocom::showTco($line["ticket_tco"], $line["value"]) . "</td>" . "<td>" . Html::convDate($line["buy_date"]) . "</td>" . "<td>" . Html::convDate($line["use_date"]) . "</td>" . "<td>" . Infocom::getWarrantyExpir($line["buy_date"], $line["warranty_duration"]) . "</td></tr>";
        }
        $valeurtot += $valeursoustot;
        $valeurnettetot += $valeurnettesoustot;
        $tmpmsg = sprintf(__('Total: Value=%1$s - Account net value=%2$s'), Html::formatNumber($valeursoustot), Html::formatNumber($valeurnettesoustot));
        echo "<tr><td colspan='6' class='center'><h3>{$tmpmsg}</h3></td></tr>";
        if (count($valeurnettegraph) > 0) {
            echo "<tr><td colspan='5' class='center'>";
            ksort($valeurnettegraph);
            $valeurnettegraphdisplay = array_map('round', $valeurnettegraph);
            foreach ($valeurnettegraph as $key => $val) {
                if (!isset($valeurnettegraphtot[$key])) {
                    $valeurnettegraphtot[$key] = 0;
                }
                $valeurnettegraphtot[$key] += $valeurnettegraph[$key];
            }
            Stat::showGraph(array(__('Account net value') => $valeurnettegraphdisplay), array('title' => __('Account net value'), 'width' => 400));
            echo "</td></tr>";
        }
        if (count($valeurgraph) > 0) {
            echo "<tr><td colspan='5' class='center'>";
            ksort($valeurgraph);
            $valeurgraphdisplay = array_map('round', $valeurgraph);
            foreach ($valeurgraph as $key => $val) {
                if (!isset($valeurgraphtot[$key])) {
                    $valeurgraphtot[$key] = 0;
                }
                $valeurgraphtot[$key] += $valeurgraph[$key];
            }
            Stat::showGraph(array(_x('price', 'Value') => $valeurgraphdisplay), array('title' => _x('price', 'Value'), 'width' => 400));
            echo "</td></tr>";
        }
        echo "</table>";
        return true;
    }
    return false;
}
Example #27
0
 @license   GPLv2+
            http://www.gnu.org/licenses/gpl.txt
 @link      https://forge.indepnet.net/projects/order
 @link      http://www.glpi-project.org/
 @since     2009
 ---------------------------------------------------------------------- */
include_once "../../../inc/includes.php";
Session::checkCentralAccess();
// Make a select box for references
if (isset($_POST["itemtype"])) {
    $entity_restrict = getEntitiesRestrictRequest("AND", 'r', '', $_POST['entities_id'], 1);
    $query = "SELECT s.`plugin_order_references_id` as id, s.`price_taxfree`, s.`reference_code`, r.`name`\n             FROM `glpi_plugin_order_references_suppliers` s\n             LEFT JOIN `glpi_plugin_order_references` r\n             ON (s.`plugin_order_references_id` = r.`id`\n               AND  r.`is_active` = 1\n               AND  r.`is_deleted` = 0)\n             WHERE s.`suppliers_id` = '{$_POST['suppliers_id']}'\n             AND r.`itemtype` = '{$_POST['itemtype']}'\n             {$entity_restrict}\n             ORDER BY s.`reference_code`";
    $result = $DB->query($query);
    $number = $DB->numrows($result);
    $values = array(0 => Dropdown::EMPTY_VALUE);
    if ($number) {
        while ($data = $DB->fetch_assoc($result)) {
            $values[$data['id']] = $data['name'] . " - " . $data['reference_code'];
        }
    }
    Dropdown::showFromArray($_POST['fieldname'], $values, array('rand' => $_POST['rand']));
    $params = array('reference_id' => '__VALUE__');
    Ajax::updateItemOnSelectEvent('dropdown_plugin_order_references_id' . $_POST['rand'], 'show_priceht', '../ajax/dropdownReference.php', $params);
    // Get price
} elseif (isset($_POST['reference_id'])) {
    $query = "SELECT `price_taxfree`\n             FROM `glpi_plugin_order_references_suppliers`\n             WHERE `plugin_order_references_id` = '{$_POST['reference_id']}'";
    $result = $DB->query($query);
    $price = $DB->result($result, 0, 'price_taxfree');
    $price = Html::formatNumber($price, true);
    echo "<input value='{$price}' type='number' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='price' />";
}
 function displayTotal($output_type)
 {
     return Html::formatNumber($this->total, false, $this->decimal);
 }
Example #29
0
/** Computer total cost of a ticket
 *
 * @param $realtime float : ticket realtime
 * @param $cost_time float : ticket time cost
 * @param $cost_fixed float : ticket fixed cost
 * @param $cost_material float : ticket material cost
 *
 * @return total cost formatted string
**/
function trackingTotalCost($realtime, $cost_time, $cost_fixed, $cost_material)
{
    return Html::formatNumber($realtime * $cost_time + $cost_fixed + $cost_material, true);
}
Example #30
0
/**  Restore a mysql dump
 *
 * @param $DB        DB object
 * @param $dumpFile  dump file
 * @param $duree     max delay before refresh
**/
function restoreMySqlDump($DB, $dumpFile, $duree)
{
    global $DB, $TPSCOUR, $offset, $cpt;
    // $dumpFile, fichier source
    // $duree=timeout pour changement de page (-1 = aucun)
    // Desactivation pour empecher les addslashes au niveau de la creation des tables
    // En plus, au niveau du dump on considere qu'on est bon
    // set_magic_quotes_runtime(0);
    if (!file_exists($dumpFile)) {
        echo sprintf(__('File %s not found.'), $dumpFile) . "<br>";
        return false;
    }
    if (substr($dumpFile, -2) == "gz") {
        $fileHandle = gzopen($dumpFile, "rb");
    } else {
        $fileHandle = fopen($dumpFile, "rb");
    }
    if (!$fileHandle) {
        //TRASN: %s is the name of the file
        echo sprintf(__('Unauthorized access to the file %s'), $dumpFile) . "<br>";
        return false;
    }
    if ($offset != 0) {
        if (substr($dumpFile, -2) == "gz") {
            if (gzseek($fileHandle, $offset, SEEK_SET) != 0) {
                //erreur
                //TRANS: %s is the number of the byte
                printf(__("Unable to find the byte %s"), Html::formatNumber($offset, false, 0));
                echo "<br>";
                return false;
            }
        } else {
            if (fseek($fileHandle, $offset, SEEK_SET) != 0) {
                //erreur
                //TRANS: %s is the number of the byte
                printf(__("Unable to find the byte %s"), Html::formatNumber($offset, false, 0));
                echo "<br>";
                return false;
            }
        }
        Html::glpi_flush();
    }
    $formattedQuery = "";
    if (substr($dumpFile, -2) == "gz") {
        while (!gzeof($fileHandle)) {
            current_time();
            if ($duree > 0 && $TPSCOUR >= $duree) {
                //on atteint la fin du temps imparti
                return true;
            }
            // specify read length to be able to read long lines
            $buffer = gzgets($fileHandle, 102400);
            // do not strip comments due to problems when # in begin of a data line
            $formattedQuery .= $buffer;
            if (substr(rtrim($formattedQuery), -1) == ";") {
                // Do not use the $DB->query
                if ($DB->query($formattedQuery)) {
                    //if no success continue to concatenate
                    $offset = gztell($fileHandle);
                    $formattedQuery = "";
                    $cpt++;
                }
            }
        }
    } else {
        while (!feof($fileHandle)) {
            current_time();
            if ($duree > 0 && $TPSCOUR >= $duree) {
                //on atteint la fin du temps imparti
                return true;
            }
            // specify read length to be able to read long lines
            $buffer = fgets($fileHandle, 102400);
            // do not strip comments due to problems when # in begin of a data line
            $formattedQuery .= $buffer;
            if (substr(rtrim($formattedQuery), -1) == ";") {
                // Do not use the $DB->query
                if ($DB->query($formattedQuery)) {
                    //if no success continue to concatenate
                    $offset = ftell($fileHandle);
                    $formattedQuery = "";
                    $cpt++;
                }
            }
        }
    }
    if ($DB->error) {
        echo "<hr>";
        //TRANS: %s is the SQL query which generates the error
        printf(__("SQL error starting from %s"), "[{$formattedQuery}]");
        echo "<br>" . $DB->error() . "<hr>";
    }
    if (substr($dumpFile, -2) == "gz") {
        gzclose($fileHandle);
    } else {
        fclose($fileHandle);
    }
    $offset = -1;
    return true;
}