/** * Get all data needed for template processing **/ function getDatasForTemplate($event, $options = array()) { global $LANG, $CFG_GLPI; $events = $this->getAllEvents(); $this->datas['##license.action##'] = $events[$event]; $this->datas['##license.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']); foreach ($options['licenses'] as $id => $license) { $tmp = array(); $tmp['##license.item##'] = $license['softname']; $tmp['##license.name##'] = $license['name']; $tmp['##license.serial##'] = $license['serial']; $tmp['##license.expirationdate##'] = convDate($license["expire"]); $tmp['##license.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=softwarelicense_" . $id); $this->datas['licenses'][] = $tmp; } $this->getTags(); foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { if (!isset($this->datas[$tag])) { $this->datas[$tag] = $values['label']; } } }
/** 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, $LANG, $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 = isMultiEntitiesMode(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { $item = new $itemtype(); echo "<h2>" . $item->getTypeName() . "</h2>"; echo "<table class='tab_cadre'><tr><th>" . $LANG['common'][16] . "</th>"; if ($display_entity) { echo "<th>" . $LANG['entity'][0] . "</th>"; } echo "<th>" . $LANG['financial'][21] . "</th><th>" . $LANG['financial'][92] . "</th>"; echo "<th>" . $LANG['financial'][91] . "</th><th>" . $LANG['financial'][14] . "</th>"; echo "<th>" . $LANG['financial'][76] . "</th><th>" . $LANG['financial'][80] . "</th></tr>"; $valeursoustot = 0; $valeurnettesoustot = 0; $valeurnettegraph = array(); $valeurgraph = array(); while ($line = $DB->fetch_array($result)) { if (isset($line["is_global"]) && $line["is_global"]) { $line["value"] *= Computer_Item::countForItem($itemtype, $line["items_id"]); } 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) { if ($line['entID'] == 0) { echo "<td>" . $LANG['entity'][2] . "</td>"; } else { echo "<td>" . $line['entname'] . "</td>"; } } echo "<td class='right'>" . formatNumber($line["value"]) . "</td><td class='right'>" . formatNumber($valeurnette) . "</td><td class='right'>" . Infocom::showTco($line["ticket_tco"], $line["value"]) . "</td><td>" . convDate($line["buy_date"]) . "</td><td>" . convDate($line["use_date"]) . "</td><td>" . getWarrantyExpir($line["buy_date"], $line["warranty_duration"]) . "</td></tr>"; } $valeurtot += $valeursoustot; $valeurnettetot += $valeurnettesoustot; echo "<tr><td colspan='6' class='center'><h3>" . $LANG['common'][33] . " : " . $LANG['financial'][21] . "=" . formatNumber($valeursoustot) . " - " . $LANG['financial'][81] . "=" . formatNumber($valeurnettesoustot) . "</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($LANG['financial'][81] => $valeurnettegraphdisplay), array('title' => $LANG['financial'][81], '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($LANG['financial'][21] => $valeurgraphdisplay), array('title' => $LANG['financial'][21], 'width' => 400)); echo "</td></tr>"; } echo "</table>"; return true; } return false; }
static function displayLine($data, $displayhost = 1) { global $DB, $CFG_GLPI, $LANG; $pMonitoringService = new PluginMonitoringService(); $networkPort = new NetworkPort(); $pMonitoringComponent = new PluginMonitoringComponent(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmServicegraph = new PluginMonitoringServicegraph(); $entity = new Entity(); $pMonitoringService->getFromDB($data['id']); echo "<td width='32' class='center'>"; $shortstate = self::getState($data['state'], $data['state_type']); echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/box_" . $shortstate . "_32.png'/>"; echo "</td>"; echo "<td>"; $entity->getFromDB($data['entities_id']); echo $entity->fields['completename']; echo "</td>"; $pMonitoringComponent->getFromDB($data['plugin_monitoring_components_id']); echo "<td class='center'>"; $img = ''; $timezone = '0'; if (isset($_SESSION['plugin_monitoring_timezone'])) { $timezone = $_SESSION['plugin_monitoring_timezone']; } $timezone_file = str_replace("+", ".", $timezone); $img = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png'/>"; echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['id'] . "'>"; if (file_exists(GLPI_ROOT . "/files/_plugins/monitoring/PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png") or $pMonitoringComponent->fields['graph_template'] != '') { $img = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png'/>"; showToolTip($img, array('img' => $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/stats_32.png")); } else { } echo "</a>"; echo "</td>"; if ($displayhost == '1') { $pmComponentscatalog_Host->getFromDB($data["plugin_monitoring_componentscatalogs_hosts_id"]); if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') { $itemtype = $pmComponentscatalog_Host->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmComponentscatalog_Host->fields['items_id']); echo "<td>"; echo $item->getTypeName() . " : " . $item->getLink(); if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) { $networkPort->getFromDB($pMonitoringService->fields['networkports_id']); echo " [" . $networkPort->getLink() . "]"; } echo "</td>"; } else { echo "<td>" . $LANG['plugin_monitoring']['service'][0] . "</td>"; } } echo "<td>" . $pMonitoringComponent->getLink(); if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) { $networkPort->getFromDB($pMonitoringService->fields['networkports_id']); echo " [" . $networkPort->getLink() . "]"; } echo "</td>"; // $nameitem = ''; // if (isset($itemmat->fields['name'])) { // $nameitem = "[".$itemmat->getLink(1)."]"; // } //if ($pMonitoringService->fields['plugin_monitoring_services_id'] == '0') { //echo "<td>".$itemmat->getLink(1)."</td>"; // } else { // $pMonitoringServiceH->getFromDB($pMonitoringService->fields['plugin_monitoring_services_id']); // $itemtypemat = $pMonitoringServiceH->fields['itemtype']; // $itemmat = new $itemtypemat(); // $itemmat->getFromDB($pMonitoringServiceH->fields['items_id']); // echo "<td>".$pMonitoringService->getLink(1).$nameitem." ".$LANG['networking'][25]." ".$itemmat->getLink(1)."</td>"; // } // unset($itemmat); echo "<td class='center'>"; echo $data['state']; echo "</td>"; echo "<td>"; echo convDate($data['last_check']) . ' ' . substr($data['last_check'], 11, 8); echo "</td>"; echo "<td>"; echo $data['event']; echo "</td>"; echo "<td align='center'>"; $segments = CalendarSegment::getSegmentsBetween($pMonitoringComponent->fields['calendars_id'], date('w', date('U')), date('H:i:s'), date('w', date('U')), date('H:i:s')); if (count($segments) == '0') { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_pause.png' />"; } else { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_run.png' />"; } echo "</td>"; if ($displayhost == '0') { $pmUnavaibility = new PluginMonitoringUnavaibility(); $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentmonth', 1); $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'lastmonth', 1); $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentyear', 1); echo "<td>"; $a_arg = importArrayFromDB($pMonitoringService->fields['arguments']); $cnt = ''; if (count($a_arg) > 0) { $cnt = " (" . count($a_arg) . ")"; } echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/servicearg.form.php?id=" . $data['id'] . "'>" . $LANG['plugin_monitoring']['service'][25] . $cnt . "</a>"; echo "</td>"; } }
/** * Show Licenses of a software * * @param $software software object * * @return nothing **/ static function showForSoftware($software) { global $DB, $CFG_GLPI, $LANG; $softwares_id = $software->getField('id'); $license = new SoftwareLicense(); $computer = new Computer(); if (!$software->can($softwares_id, "r")) { return false; } if (isset($_REQUEST["start"])) { $start = $_REQUEST["start"]; } else { $start = 0; } if (isset($_REQUEST["order"]) && $_REQUEST["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_REQUEST["sort"]) && !empty($_REQUEST["sort"])) { $sort = "`" . $_REQUEST["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = haveRight("software", "w"); // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['search'][15] . "</th></tr>\n"; if ($canedit) { echo "<tr class='tab_bg_2'><td class='center'>"; echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>"; echo "</td></tr>\n"; } echo "</table></div>\n"; return; } // Display the pager printAjaxPager($LANG['software'][11], $start, $number); $rand = mt_rand(); $query = "SELECT `glpi_softwarelicenses`.*,\n `buyvers`.`name` AS buyname,\n `usevers`.`name` AS usename,\n `glpi_entities`.`completename` AS entity,\n `glpi_softwarelicensetypes`.`name` AS typename\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_softwareversions` AS buyvers\n ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n LEFT JOIN `glpi_softwareversions` AS usevers\n ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n LEFT JOIN `glpi_softwarelicensetypes`\n ON (`glpi_softwarelicensetypes`.`id`\n = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); initNavigateListItems('SoftwareLicense', $LANG['help'][31] . " = " . $software->fields["name"]); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { if ($canedit) { echo "<form method='post' name='massiveactionlicense_form{$rand}' id='" . "massiveactionlicense_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">"; } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th> </th>"; echo "<th>" . ($sort == "`name`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=name&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][16] . "</a></th>"; if ($software->isRecursive()) { // Ereg to search entity in string for match default order echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['entity'][0] . "</a></th>"; } echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][19] . "</a></th>"; echo "<th>" . ($sort == "`number`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=number&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['tracking'][29] . "</a></th>"; echo "<th>" . $LANG['software'][9] . "</th>"; echo "<th>" . ($sort == "`typename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=typename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][17] . "</a></th>"; echo "<th>" . ($sort == "`buyname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=buyname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][1] . "</a></th>"; echo "<th>" . ($sort == "`usename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=usename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][2] . "</a></th>"; echo "<th>" . ($sort == "`expire`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=expire&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][32] . "</a></th>"; echo "</tr>\n"; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { addToNavigateListItems('SoftwareLicense', $data['id']); echo "<tr class='tab_bg_2'>"; if ($license->can($data['id'], "w")) { echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>"; } else { echo "<td> </td>"; } echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? $data['id'] : "") . "</a></td>"; if ($software->isRecursive()) { echo "<td>" . $data['entity'] . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='right'>" . ($data['number'] > 0 ? $data['number'] . " " : $LANG['software'][4]) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; echo "<td class='right'>{$nb_assoc} </td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Not illimited, add the current number $tot += $data['number']; } } } echo "<tr class='tab_bg_1'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . $LANG['common'][33] . "</td>"; echo "<td class='right b'>" . ($tot > 0 ? $tot . " " : $LANG['software'][4]) . "</td>"; echo "<td class='right b'>{$tot_assoc} </td>"; echo "<td colspan='4' class='center'>"; if ($canedit) { echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>"; } echo "</td></tr>"; echo "</table>\n"; if ($canedit) { openArrowMassive("massiveactionlicense_form{$rand}", true); Dropdown::showForMassiveAction('SoftwareLicense', 0, array('softwares_id' => $softwares_id)); closeArrowMassive(); echo "</form>"; } } else { echo $LANG['search'][15]; } } echo "</div>"; }
/** * Retrieve last history Data for an item * * @param $item CommonDBTM object * @param $start interger first line to retrieve * @param $limit interfer max number of line to retrive (0 for all) * @param $sqlfilter string to add an SQL filter * * @return array of localized log entry (TEXT only, no HTML) **/ static function getHistoryData(CommonDBTM $item, $start = 0, $limit = 0, $sqlfilter = '') { global $DB, $LANG; $itemtype = $item->getType(); $items_id = $item->getField('id'); $SEARCHOPTION = Search::getOptions($itemtype); $query = "SELECT *\n FROM `glpi_logs`\n WHERE `items_id` = '{$items_id}'\n AND `itemtype` = '{$itemtype}' "; if ($sqlfilter) { $query .= "AND ({$sqlfilter}) "; } $query .= "ORDER BY `id` DESC"; if ($limit) { $query .= " LIMIT " . intval($start) . "," . intval($limit); } $changes = array(); foreach ($DB->request($query) as $data) { $tmp = array(); $tmp['display_history'] = true; $tmp['id'] = $data["id"]; $tmp['date_mod'] = convDateTime($data["date_mod"]); $tmp['user_name'] = $data["user_name"]; $tmp['field'] = ""; $tmp['change'] = ""; $tmp['datatype'] = ""; // This is an internal device ? if ($data["linked_action"]) { // Yes it is an internal device switch ($data["linked_action"]) { case HISTORY_CREATE_ITEM: $tmp['change'] = $LANG['log'][20]; break; case HISTORY_DELETE_ITEM: $tmp['change'] = $LANG['log'][22]; break; case HISTORY_RESTORE_ITEM: $tmp['change'] = $LANG['log'][23]; break; case HISTORY_ADD_DEVICE: $tmp['field'] = NOT_AVAILABLE; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['devices'][25] . " : " . "\"" . $data["new_value"] . "\""; break; case HISTORY_UPDATE_DEVICE: $tmp['field'] = NOT_AVAILABLE; $change = ''; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); $specif_fields = $item->getSpecifityLabel(); $tmp['change'] = $specif_fields['specificity'] . " : "; } $tmp['change'] .= $data["old_value"] . " --> " . "\"" . $data["new_value"] . "\""; break; case HISTORY_DELETE_DEVICE: $tmp['field'] = NOT_AVAILABLE; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['devices'][26] . " : " . "\"" . $data["old_value"] . "\""; break; case HISTORY_INSTALL_SOFTWARE: $tmp['field'] = $LANG['help'][31]; $tmp['change'] = $LANG['software'][44] . " : " . "\"" . $data["new_value"] . "\""; break; case HISTORY_UNINSTALL_SOFTWARE: $tmp['field'] = $LANG['help'][31]; $tmp['change'] = $LANG['software'][45] . " : " . "\"" . $data["old_value"] . "\""; break; case HISTORY_DISCONNECT_DEVICE: $tmp['field'] = NOT_AVAILABLE; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['log'][26] . " : " . "\"" . $data["old_value"] . "\""; break; case HISTORY_CONNECT_DEVICE: $tmp['field'] = NOT_AVAILABLE; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['log'][27] . " : " . "\"" . $data["new_value"] . "\""; break; case HISTORY_OCS_IMPORT: if (haveRight("view_ocsng", "r")) { $tmp['field'] = ""; $tmp['change'] = $LANG['ocsng'][7] . " " . $LANG['ocsng'][45] . " :"; $tmp['change'] .= " " . "\"" . $data["new_value"] . "\""; } else { $tmp['display_history'] = false; } break; case HISTORY_OCS_DELETE: if (haveRight("view_ocsng", "r")) { $tmp['field'] = ""; $tmp['change'] = $LANG['ocsng'][46] . " " . $LANG['ocsng'][45] . " :"; $tmp['change'] .= " " . "\"" . $data["old_value"] . "\""; } else { $tmp['display_history'] = false; } break; case HISTORY_OCS_LINK: if (haveRight("view_ocsng", "r")) { $tmp['field'] = NOT_AVAILABLE; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['ocsng'][47] . " " . $LANG['ocsng'][45] . " :"; $tmp['change'] .= " " . "\"" . $data["new_value"] . "\""; } else { $tmp['display_history'] = false; } break; case HISTORY_OCS_IDCHANGED: if (haveRight("view_ocsng", "r")) { $tmp['field'] = ""; $tmp['change'] = $LANG['ocsng'][48] . " " . " : " . "\"" . $data["old_value"] . "\" --> : " . "\"" . $data["new_value"] . "\""; } else { $tmp['display_history'] = false; } break; case HISTORY_LOG_SIMPLE_MESSAGE: $tmp['field'] = ""; $tmp['change'] = $data["new_value"]; break; case HISTORY_ADD_RELATION: $tmp['field'] = NOT_AVAILABLE; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['log'][32] . " : " . "\"" . $data["new_value"] . "\""; break; case HISTORY_DEL_RELATION: $tmp['field'] = NOT_AVAILABLE; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['log'][33] . " : " . "\"" . $data["old_value"] . "\""; break; case HISTORY_ADD_SUBITEM: $tmp['field'] = ''; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['log'][98] . " : " . $tmp['field'] . " (" . $data["new_value"] . ")"; break; case HISTORY_UPDATE_SUBITEM: $tmp['field'] = ''; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['log'][99] . " : " . $tmp['field'] . " (" . $data["new_value"] . ")"; break; case HISTORY_DELETE_SUBITEM: $tmp['field'] = ''; if (class_exists($data["itemtype_link"])) { $item = new $data["itemtype_link"](); $tmp['field'] = $item->getTypeName(); } $tmp['change'] = $LANG['log'][100] . " : " . $tmp['field'] . " (" . $data["old_value"] . ")"; break; } } else { $fieldname = ""; // It's not an internal device foreach ($SEARCHOPTION as $key2 => $val2) { if ($key2 == $data["id_search_option"]) { $tmp['field'] = $val2["name"]; $fieldname = $val2["field"]; if (isset($val2['datatype'])) { $tmp['datatype'] = $val2["datatype"]; } } } switch ($tmp['datatype']) { case "bool": $data["old_value"] = Dropdown::getYesNo($data["old_value"]); $data["new_value"] = Dropdown::getYesNo($data["new_value"]); break; case "datetime": $data["old_value"] = convDateTime($data["old_value"]); $data["new_value"] = convDateTime($data["new_value"]); break; case "date": $data["old_value"] = convDate($data["old_value"]); $data["new_value"] = convDate($data["new_value"]); break; case "timestamp": $data["old_value"] = timestampToString($data["old_value"]); $data["new_value"] = timestampToString($data["new_value"]); break; case "actiontime": $data["old_value"] = Ticket::getActionTime($data["old_value"]); $data["new_value"] = Ticket::getActionTime($data["new_value"]); break; case "number": $data["old_value"] = formatNumber($data["old_value"], false, 0); $data["new_value"] = formatNumber($data["new_value"], false, 0); break; case "decimal": $data["old_value"] = formatNumber($data["old_value"]); $data["new_value"] = formatNumber($data["new_value"]); break; case "right": $data["old_value"] = Profile::getRightValue($data["old_value"]); $data["new_value"] = Profile::getRightValue($data["new_value"]); break; case "text": $tmp['change'] = $LANG['log'][64]; break; } if (empty($tmp['change'])) { $tmp['change'] = "\"" . $data["old_value"] . "\" --> \"" . $data["new_value"] . "\""; } } $changes[] = $tmp; } return $changes; }
/** * Print an HTML array with contracts associated to the enterprise * *@return Nothing (display) **/ function showContracts() { global $DB, $CFG_GLPI, $LANG; $ID = $this->fields['id']; if (!haveRight("contract", "r") || !$this->can($ID, 'r')) { return false; } $canedit = $this->can($ID, 'w'); $query = "SELECT `glpi_contracts`.*,\n `glpi_contracts_suppliers`.`id` AS assocID,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contracts_suppliers`, `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contracts`.`entities_id`)\n WHERE `glpi_contracts_suppliers`.`suppliers_id` = '{$ID}'\n AND `glpi_contracts_suppliers`.`contracts_id`=`glpi_contracts`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`,\n `glpi_contracts`.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='7'>"; if ($DB->numrows($result) == 0) { echo $LANG['financial'][58]; } else { if ($DB->numrows($result) == 1) { echo $LANG['financial'][63]; } else { echo $LANG['financial'][66]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][4] . "</th>"; echo "<th>" . $LANG['financial'][6] . "</th>"; echo "<th>" . $LANG['search'][8] . "</th>"; echo "<th>" . $LANG['financial'][8] . "</th>"; echo "<th> </th>"; echo "</tr>"; $used = array(); while ($data = $DB->fetch_array($result)) { $cID = $data["id"]; $used[$cID] = $cID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>\n <a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>"; echo "<strong>" . $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { echo " (" . $data["id"] . ")"; } echo "</strong></a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "</td><td class='center'>" . $data["num"] . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"]) . "</td>"; echo "<td class='center'>" . convDate($data["begin_date"]) . "</td>"; echo "<td class='center'>" . $data["duration"] . " " . $LANG['financial'][57]; if ($data["begin_date"] != '' && !empty($data["begin_date"])) { echo " -> " . getWarrantyExpir($data["begin_date"], $data["duration"]); } echo "</td>"; echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deletecontractsupplier=" . "1&id={$assocID}&contracts_id={$cID}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td></tr>"; $i++; } if ($canedit) { if ($this->fields["is_recursive"]) { $nb = countElementsInTableForEntity("glpi_contracts", getSonsOf("glpi_entities", $this->fields["entities_id"])); } else { $nb = countElementsInTableForEntity("glpi_contracts", $this->fields["entities_id"]); } if ($nb > count($used)) { echo "<tr class='tab_bg_1'><td class='center' colspan='5'>"; echo "<input type='hidden' name='suppliers_id' value='{$ID}'>"; Contract::dropdown(array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"], 'nochecklimit' => true)); echo "</td><td class='center'>"; echo "<input type='submit' name='addcontractsupplier' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td>"; echo "<td> </td></tr>"; } } echo "</table></div></form>"; }
/** * Get date using a begin date and a period in month * * @param $from date: begin date * @param $addwarranty integer: period in months * @param $deletenotice integer: period in months of notice * * @return expiration date string **/ function getWarrantyExpir($from, $addwarranty, $deletenotice = 0) { global $LANG; // Life warranty if ($addwarranty == -1 && $deletenotice == 0) { return $LANG['setup'][307]; } if ($from == NULL || empty($from)) { return ""; } return convDate(date("Y-m-d", strtotime("{$from}+{$addwarranty} month -{$deletenotice} month"))); }
/** * Print an HTML array of contract associated to an object * * *@param $item CommonDBTM : object wanted *@param $withtemplate='' not used (to be deleted) * *@return Nothing (display) * **/ static function showAssociated(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; $itemtype = $item->getType(); $ID = $item->fields['id']; if (!haveRight("contract", "r") || !$item->can($ID, "r")) { return false; } $canedit = $item->can($ID, "w"); $query = "SELECT `glpi_contracts_items`.*\n FROM `glpi_contracts_items`,\n `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '{$ID}'\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<div class='spaced'>"; if ($withtemplate != 2) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contract.form.php\">"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='8'>"; if ($number == 0) { echo $LANG['financial'][58]; } else { if ($number == 1) { echo $LANG['financial'][63]; } else { echo $LANG['financial'][66]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][4] . "</th>"; echo "<th>" . $LANG['financial'][6] . "</th>"; echo "<th>" . $LANG['financial'][26] . "</th>"; echo "<th>" . $LANG['search'][8] . "</th>"; echo "<th>" . $LANG['financial'][8] . "</th>"; if ($withtemplate != 2) { echo "<th> </th>"; } echo "</tr>"; if ($number > 0) { initNavigateListItems('Contract', $item->getTypeName() . " = " . $item->getName()); } $contracts = array(); while ($i < $number) { $cID = $DB->result($result, $i, "contracts_id"); addToNavigateListItems('Contract', $cID); $contracts[] = $cID; $assocID = $DB->result($result, $i, "id"); $con = new Contract(); $con->getFromDB($cID); echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>"; echo "<strong>" . $con->fields["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) { echo " (" . $con->fields["id"] . ")"; } echo "</strong></a></td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>"; echo "<td class='center'>" . $con->fields["num"] . "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"]) . "</td>"; echo "<td class='center'>" . $con->getSuppliersNames() . "</td>"; echo "<td class='center'>" . convDate($con->fields["begin_date"]) . "</td>"; echo "<td class='center'>" . $con->fields["duration"] . " " . $LANG['financial'][57]; if ($con->fields["begin_date"] != '' && !empty($con->fields["begin_date"])) { echo " -> " . getWarrantyExpir($con->fields["begin_date"], $con->fields["duration"]); } echo "</td>"; if ($withtemplate != 2) { echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deleteitem=deleteitem&id={$assocID}&contracts_id={$cID}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td>"; } echo "</tr>"; $i++; } $q = "SELECT *\n FROM `glpi_contracts`\n WHERE `is_deleted` = '0' " . getEntitiesRestrictRequest("AND", "glpi_contracts", "entities_id", $item->getEntityID(), true); $result = $DB->query($q); $nb = $DB->numrows($result); if ($canedit) { if ($withtemplate != 2 && $nb > count($contracts)) { echo "<tr class='tab_bg_1'><td class='right' colspan='3'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; self::dropdown(array('entity' => $item->getEntityID(), 'used' => $contracts)); echo "</td><td class='center'>"; echo "<input type='submit' name='additem' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td>"; echo "<td> </td><td> </td><td> </td><td> </td></tr>"; } } echo "</table>"; if ($withtemplate != 2) { echo "</form>"; } echo "</div>"; }
/** * Print generic footer * * @param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV) * @param $title title of file : used for PDF * * @return string to display **/ static function showFooter($type, $title = "") { global $LANG; $out = ""; switch ($type) { case PDF_OUTPUT_LANDSCAPE: //pdf global $PDF_HEADER, $PDF_ARRAY; $pdf = new Cezpdf('a4', 'landscape'); $pdf->selectFont(GLPI_ROOT . "/lib/ezpdf/fonts/Helvetica.afm"); $pdf->ezStartPageNumbers(750, 10, 10, 'left', "GLPI PDF export - " . convDate(date("Y-m-d")) . " - " . count($PDF_ARRAY) . " " . decodeFromUtf8($LANG['pager'][5], 'windows-1252') . " - {PAGENUM}/{TOTALPAGENUM}"); $options = array('fontSize' => 8, 'colGap' => 2, 'maxWidth' => 800, 'titleFontSize' => 8); $pdf->ezTable($PDF_ARRAY, $PDF_HEADER, decodeFromUtf8($title, 'windows-1252'), $options); $pdf->ezStream(); break; case PDF_OUTPUT_PORTRAIT: //pdf global $PDF_HEADER, $PDF_ARRAY; $pdf = new Cezpdf('a4', 'portrait'); $pdf->selectFont(GLPI_ROOT . "/lib/ezpdf/fonts/Helvetica.afm"); $pdf->ezStartPageNumbers(550, 10, 10, 'left', "GLPI PDF export - " . convDate(date("Y-m-d")) . " - " . count($PDF_ARRAY) . " " . decodeFromUtf8($LANG['pager'][5], 'windows-1252') . " - {PAGENUM}/{TOTALPAGENUM}"); $options = array('fontSize' => 8, 'colGap' => 2, 'maxWidth' => 565, 'titleFontSize' => 8); $pdf->ezTable($PDF_ARRAY, $PDF_HEADER, decodeFromUtf8($title, 'windows-1252'), $options); $pdf->ezStream(); break; case SYLK_OUTPUT: //sylk global $SYLK_HEADER, $SYLK_ARRAY, $SYLK_SIZE; // largeurs des colonnes foreach ($SYLK_SIZE as $num => $val) { $out .= "F;W" . $num . " " . $num . " " . min(50, $val) . "\n"; } $out .= "\n"; // Header foreach ($SYLK_HEADER as $num => $val) { $out .= "F;SDM4;FG0C;" . ($num == 1 ? "Y1;" : "") . "X{$num}\n"; $out .= "C;N;K\"" . sylk_clean($val) . "\"\n"; $out .= "\n"; } // Datas foreach ($SYLK_ARRAY as $row => $tab) { foreach ($tab as $num => $val) { $out .= "F;P3;FG0L;" . ($num == 1 ? "Y" . $row . ";" : "") . "X{$num}\n"; $out .= "C;N;K\"" . sylk_clean($val) . "\"\n"; } } $out .= "E\n"; break; case CSV_OUTPUT: //csv break; default: $out = "</table></div>\n"; } return $out; }
/** * Show holidays for a calendar * * @param $calendar Calendar object **/ static function showForCalendar(Calendar $calendar) { global $DB, $CFG_GLPI, $LANG; $ID = $calendar->getField('id'); if (!$calendar->can($ID, 'r')) { return false; } $canedit = $calendar->can($ID, 'w'); $rand = mt_rand(); echo "<form name='calendarholiday_form{$rand}' id='calendarholiday_form{$rand}' method='post'\n action='"; echo getItemTypeFormURL(__CLASS__) . "'>"; echo "<div class='center'><table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='2'>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['buttons'][33] . "</th>"; echo "<th>" . $LANG['buttons'][32] . "</th>"; echo "<th>" . $LANG['calendar'][3] . "</th>"; echo "</tr>"; $query = "SELECT DISTINCT `glpi_calendars_holidays`.`id` AS linkID,\n `glpi_holidays`.*\n FROM `glpi_calendars_holidays`\n LEFT JOIN `glpi_holidays`\n ON (`glpi_calendars_holidays`.`holidays_id` = `glpi_holidays`.`id`)\n WHERE `glpi_calendars_holidays`.`calendars_id` = '{$ID}'\n ORDER BY `glpi_holidays`.`name`"; $result = $DB->query($query); $used = array(); if ($DB->numrows($result) > 0) { initNavigateListItems('Holiday', $LANG['buttons'][15] . " = " . $calendar->fields["name"]); while ($data = $DB->fetch_array($result)) { addToNavigateListItems('Holiday', $data["id"]); echo "<tr class='tab_bg_1'>"; echo "<td width='10'>"; if ($canedit) { echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1'>"; } else { echo " "; } echo "</td>"; $used[] = $data['id']; echo "<td><a href='" . getItemTypeFormURL('Holiday') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>"; echo "<td>" . convDate($data["begin_date"]) . "</td>"; echo "<td>" . convDate($data["end_date"]) . "</td>"; echo "<td>" . Dropdown::getYesNo($data["is_perpetual"]) . "</td>"; echo "</tr>"; } } if ($canedit) { echo "<tr class='tab_bg_2'><td class='right' colspan='4'>"; echo "<input type='hidden' name='calendars_id' value='{$ID}'>"; Dropdown::show('Holiday', array('used' => $used, 'entity' => $calendar->fields["entities_id"])); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>"; } echo "</table></div>"; if ($canedit) { openArrowMassive("calendarholiday_form{$rand}", true); closeArrowMassive('delete', $LANG['buttons'][6]); } echo "</form>"; }
if ($data["warranty_duration"]) { echo "<td class='center'>" . getWarrantyExpir($data["buy_date"], $data["warranty_duration"]) . "</td>"; } else { echo "<td class='center'>" . NOT_AVAILABLE . "</td>"; } } else { echo "<td class='center'>" . NOT_AVAILABLE . "</td>"; echo "<td class='center'>" . NOT_AVAILABLE . "</td>"; } if ($data['type']) { echo "<td>" . $data['type'] . "</td>"; } else { echo "<td>" . NOT_AVAILABLE . "</td>"; } if ($data['begin_date']) { echo "<td class='center'>" . convDate($data['begin_date']) . "</td>"; if ($data["duration"]) { echo "<td class='center'>" . getWarrantyExpir($data["begin_date"], $data["duration"]) . "</td>"; } else { echo "<td class='center'>" . NOT_AVAILABLE . "</td>"; } } else { echo "<td class='center'>" . NOT_AVAILABLE . "</td>"; echo "<td class='center'>" . NOT_AVAILABLE . "</td>"; } echo "</tr>\n"; } echo "</table><br><hr><br>"; } } }
INSERT INTO tv1304isa_comments(comment_post_ID, comment_author_email , comment_author, comment_author_url, comment_author_IP, comment_date, comment_date_gmt , comment_content , comment_karma , comment_approved , comment_agent , comment_type , comment_parent , user_id ) VALUES ({$lastid},'{$autor[0]}','{$autor_mail}','','','{$pubDate2}','{$pubDate2}','{$description}',0,1,'','',0,0) SQL; //echo $sql_comentario1; $wpdb->query($sql_comentario1); $lastid_comment = $wpdb->insert_id; if ($comments != "") { $sitemap2 = simplexml_load_file($comments, 'SimpleXMLElement', LIBXML_NOCDATA); if (sizeof($sitemap2->channel->item) > 1) { foreach ($sitemap2->channel->item as $each_comment2) { $autor2 = explode("(", $each_comment2->author); $autor_mail2 = str_replace(")", "", $autor2[1]); $description2 = $each_comment2->description; $pubDate2 = explode(" ", $each_comment2->pubDate); //YYYY-mm-dd H:m:s $pubDate3 = $pubDate2[3] . "-" . convDate($pubDate2[2]) . "-" . $pubDate2[1] . " " . $pubDate2[4]; //$comments2 = $each_comment2->comments; $sql_comentario2 = <<<SQL INSERT INTO tv1304isa_comments(comment_post_ID, comment_author_email , comment_author, comment_author_url, comment_author_IP, comment_date, comment_date_gmt , comment_content , comment_karma , comment_approved , comment_agent , comment_type , comment_parent , user_id ) VALUES ({$lastid},'{$autor2[0]}','{$autor_mail2}','','','{$pubDate3}','{$pubDate3}','{$description2}',0,1,'','',{$lastid_comment},0) SQL; $wpdb->query($sql_comentario2); } } } //echo "<pre>".print_r($each_comment,true)."</pre>"; } $i++; } } }
/** * Print out the consumables of a defined type * *@param $consitem oject of ConsumableItem class *@param $show_old boolean : show old consumables or not. * *@return Nothing (displays) **/ static function showForItem(ConsumableItem $consitem, $show_old = 0) { global $DB, $CFG_GLPI, $LANG; $tID = $consitem->getField('id'); if (!$consitem->can($tID, 'r')) { return false; } $canedit = $consitem->can($tID, 'w'); $query = "SELECT count(*) AS COUNT\n FROM `glpi_consumables`\n WHERE (`consumableitems_id` = '{$tID}')"; if ($result = $DB->query($query)) { if (!$show_old && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/consumable.form.php'>"; echo "<input type='hidden' name='tID' value='{$tID}'>\n"; } echo "<div class='spaced'><table class='tab_cadre_fixe'>"; if (!$show_old) { echo "<tr><th colspan='7'>"; echo self::getCount($tID, -1); echo "</th></tr>"; } else { // Old echo "<tr><th colspan='8'>" . $LANG['consumables'][35] . "</th></tr>"; } $i = 0; echo "<tr><th>" . $LANG['common'][2] . "</th><th>" . $LANG['consumables'][23] . "</th>"; echo "<th>" . $LANG['cartridges'][24] . "</th><th>" . $LANG['consumables'][26] . "</th>"; if ($show_old) { echo "<th>" . $LANG['common'][34] . "</th>"; } echo "<th>" . $LANG['financial'][3] . "</th>"; if (!$show_old && $canedit && $DB->result($result, 0, 0) != 0) { echo "<th>"; User::dropdown(array('value' => $consitem->fields["entities_id"], 'right' => 'all')); echo " <input type='submit' class='submit' name='give' value='" . $LANG['consumables'][32] . "'>"; echo "</th>"; } else { echo "<th> </th>"; } if ($canedit) { echo "<th> </th>"; } echo "</tr>"; } $where = ""; $leftjoin = ""; $addselect = ""; if (!$show_old) { // NEW $where = " AND `date_out` IS NULL\n ORDER BY `date_in`, `id`"; } else { //OLD $where = " AND `date_out` IS NOT NULL\n ORDER BY `date_out` DESC,\n `date_in`,\n `id`"; $leftjoin = " LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_consumables`.`users_id`) "; $addselect = ", `glpi_users`.`realname` AS REALNAME,\n `glpi_users`.`firstname` AS FIRSTNAME,\n `glpi_users`.`id` AS USERID,\n `glpi_users`.`name` AS USERNAME "; } $query = "SELECT `glpi_consumables`.*\n {$addselect}\n FROM `glpi_consumables`\n {$leftjoin}\n WHERE `consumableitems_id` = '{$tID}'\n {$where}"; if ($result = $DB->query($query)) { $number = $DB->numrows($result); while ($data = $DB->fetch_array($result)) { $date_in = convDate($data["date_in"]); $date_out = convDate($data["date_out"]); echo "<tr class='tab_bg_1'><td class='center'>" . $data["id"] . "</td>"; echo "<td class='center'>" . self::getStatus($data["id"]) . "</td>"; echo "<td class='center'>" . $date_in . "</td>"; echo "<td class='center'>" . $date_out . "</td>"; if ($show_old) { echo "<td class='center'>"; echo formatUserName($data["USERID"], $data["USERNAME"], $data["REALNAME"], $data["FIRSTNAME"]); echo "</td>"; } echo "<td class='center'>"; Infocom::showDisplayLink('Consumable', $data["id"], 1); echo "</td>"; if (!$show_old && $canedit) { echo "<td class='center'>"; echo "<input type='checkbox' name='out[" . $data["id"] . "]'>"; echo "</td>"; } if ($show_old && $canedit) { echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/consumable.form.php?restore=restore&id=" . $data["id"] . "&tID={$tID}'>" . $LANG['consumables'][37] . "</a>"; echo "</td>"; } echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/consumable.form.php?delete=delete&id=" . $data["id"] . "&tID={$tID}'>" . $LANG['buttons'][6] . "</a>"; echo "</td></tr>"; } } echo "</table></div>"; if (!$show_old && $canedit) { echo "</form>"; } }
/** * Display Date form with calendar * * @param $element name of the element * @param $value default value to display * @param $maybeempty may be empty ? * @param $can_edit could not modify element * @param $minDate minimum allowed date * @param $maxDate maximum allowed date * @param $displayYear should we set/diplay the year? * * @return rand value used **/ function showDateFormItem($element, $value = '', $maybeempty = true, $can_edit = true, $minDate = '', $maxDate = '', $displayYear = true) { global $CFG_GLPI; $rand = mt_rand(); echo "<input id='showdate{$rand}' type='text' size='10' name='{$element}'>"; $output = "<script type='text/javascript'>\n"; $output .= "Ext.onReady(function() {\n var md{$rand} = new Ext.ux.form.XDateField({\n name: '{$element}'\n ,value: '" . convDate($value) . "'\n ,applyTo: 'showdate{$rand}'\n ,id: 'date{$rand}'\n ,submitFormat:'Y-m-d'\n ,startDay: 1"; switch ($_SESSION['glpidate_format']) { case 1: $displayYear ? $format = 'd-m-Y' : ($format = 'd-m'); break; case 2: $displayYear ? $format = 'm-d-Y' : ($format = 'm-d'); break; default: $displayYear ? $format = 'Y-m-d' : ($format = 'm-d'); } $output .= ",format: '" . $format . "'"; if ($maybeempty) { $output .= ",allowBlank: true"; } else { $output .= ",allowBlank: false"; } if (!$can_edit) { $output .= ",disabled: true"; } if (!empty($minDate)) { $output .= ",minValue: '" . convDate($minDate) . "'"; } if (!empty($maxDate)) { $output .= ",maxValue: '" . convDate($maxDate) . "'"; } $output .= " });\n });"; $output .= "</script>\n"; echo $output; return $rand; }
static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array()) { global $CFG_GLPI, $LANG, $PLUGIN_HOOKS; $searchopt =& Search::getOptions($itemtype); if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) { return PluginMobileSearch::giveItem($data["TYPE"], $ID, $data, $num, $meta); } // 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"]; switch ($table . '.' . $field) { case "glpi_users_validation.name": 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 = getUserNameMobile($split[$k], 2); $out .= $userdata['name'] . " "; } else { $out .= getUserNameMobile($split[$k], 1); } } } return $out; } else { if (!empty($linkfield)) { $toadd = ''; if ($itemtype == 'Ticket' && $data[$NAME . $num . "_3"] > 0) { $userdata = getUserNameMobile($data[$NAME . $num . "_3"], 2); $toadd = " "; } //Stevenes $name1 = explode("\$\$", $data[$NAME . $num]); // return $name1['0'].' ('.$name1['1'].')'; $link_user = $_SESSION['mobileSearchLastLink'] = "<a href=" . $CFG_GLPI["root_doc"] . "/plugins/mobile/front/item.php?itemtype=user&menu=admin&ssmenu=user&id=" . $name1['1'] . ">" . $name1['0'] . " (" . $name1['1'] . ")</a>"; return $link_user; // return formatUserNameMobile($data[$NAME.$num."_3"],$data[$NAME.$num],$data[$NAME.$num."_2"], $data[$NAME.$num."_4"],1).$toadd; } } break; case "glpi_profiles.interface": return Profile::getInterfaceName($data[$NAME . $num]); break; case "glpi_profiles.name": if ($itemtype == 'User') { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]); $count_display = 0; $added = array(); for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . $split2[$k]; if ($split3[$k]) { $text .= " (R)"; } 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"]); $added = array(); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . $split2[$k]; if ($split3[$k]) { $text .= " (R)"; } if (!in_array($text, $added)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } else { if ($data[$NAME . $num . "_2"] == 0) { // Set name for Root entity $data[$NAME . $num] = $LANG['entity'][2]; } } 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 " "; 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 = utf8_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 = utf8_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>') . $duration . " " . $LANG['financial'][57]; } return $output; } return " "; 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) { $out .= $val . " " . $LANG['financial'][9]; } } return $out; } return " "; 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 .= $val . " " . $LANG['financial'][57]; } if ($val < 0) { $out .= $LANG['financial'][2]; } } return $out; } return " "; 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 $LANG['financial'][80]; } return ""; case "glpi_contracts.alert": switch ($data[$NAME . $num]) { case pow(2, Alert::END): return $LANG['buttons'][32]; case pow(2, Alert::NOTICE): return $LANG['financial'][10]; case pow(2, Alert::END) + pow(2, Alert::NOTICE): return $LANG['buttons'][32] . " + " . $LANG['financial'][10]; } return ""; case "glpi_tickets.count": if ($data[$NAME . $num] > 0 && Session::haveRight("ticket", Ticket::READALL)) { $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 href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options) . "\" data-back='false'>"; $out .= $data[$NAME . $num]; $out .= "</a>"; } else { $out = $data[$NAME . $num]; } return $out; case "glpi_softwarelicenses.number": if ($data[$NAME . $num . "_2"] == -1) { return $LANG['software'][4]; } 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='" . $LANG['reservation'][22] . "'\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' data-back='false'>" . $LANG['common'][49] . "</a>"; } return "<a title='" . $LANG['reservation'][22] . "'\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' data-back='false'>" . 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(); return $events[$data[$NAME . $num]]; } return ''; 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_tickets.status': $status = Ticket::getStatus($data[$NAME . $num]); // status Stevenes Donato if ($data[$NAME . $num] == "1") { $data[$NAME . $num] = "new"; } if ($data[$NAME . $num] == "2") { $data[$NAME . $num] = "assign"; } if ($data[$NAME . $num] == "3") { $data[$NAME . $num] = "plan"; } if ($data[$NAME . $num] == "4") { $data[$NAME . $num] = "waiting"; } if ($data[$NAME . $num] == "5") { $data[$NAME . $num] = "solved"; } if ($data[$NAME . $num] == "6") { $data[$NAME . $num] = "closed"; } // return "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . $data[$NAME . $num] . ".png\"\n alt='{$status}' title='{$status}'> {$status}"; case 'glpi_tickets.priority': return Ticket::getPriorityName($data[$NAME . $num]); case 'glpi_tickets.urgency': return Ticket::getUrgencyName($data[$NAME . $num]); case 'glpi_tickets.impact': return Ticket::getImpactName($data[$NAME . $num]); case 'glpi_tickets.items_id': if (!empty($data[$NAME . $num . "_2"]) && class_exists($data[$NAME . $num . "_2"])) { $item = new $data[$NAME . $num . "_2"](); if ($item->getFromDB($data[$NAME . $num])) { return $item->getLink(true); } } return ' '; case 'glpi_tickets.id': $link = getItemTypeFormURLMobile('Ticket'); $out = "<a id='ticket" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num]; //$out .= 'id='.$data[$NAME.$num."_2"]; $out .= "\" data-back='false'>" . $data[$NAME . $num]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { //$out .= " (".$data[$NAME.$num."_2"].")"; $out .= $data[$NAME . $num . "_2"]; } $out .= "</a>"; return $out; case 'glpi_ticketvalidations.status': case "glpi_tickets.global_validation": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $status = TicketValidation::getStatus($val); $bgcolor = TicketValidation::getStatusColor($val); $out .= (empty($out) ? '' : '<br>') . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>'; } return $out; 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']; } // Preformat items if (isset($searchopt[$ID]["datatype"])) { switch ($searchopt[$ID]["datatype"]) { case "itemlink": if (!empty($data[$NAME . $num . "_2"])) { if (isset($searchopt[$ID]["itemlink_type"])) { $link = getItemTypeFormURLMobile($searchopt[$ID]["itemlink_type"]); } else { $link = getItemTypeFormURLMobile($itemtype); } $out = "<a id='" . $itemtype . "_" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num . "_2"] . "\" data-back='false'>"; $out .= $data[$NAME . $num] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $out .= " (" . $data[$NAME . $num . "_2"] . ")"; } $out .= "</a>"; return $out; } else { if (isset($searchopt[$ID]["itemlink_type"])) { $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 = explode("\$\$", $split[$k]); if (isset($split2[1]) && $split2[1] > 0) { if ($count_display) { $out .= $separate; } $count_display++; $page = getItemTypeFormURLMobile($searchopt[$ID]["itemlink_type"]); $page .= strpos($page, '?') ? '&id' : '?id'; $out .= "<a id='" . $searchopt[$ID]["itemlink_type"] . "_" . $split2[1] . "'\n href='{$page}=" . $split2[1] . "' data-back='false'>"; $out .= $split2[0] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $out .= " (" . $split2[1] . ")"; } $out .= "</a>"; } } } return $out; } } break; case "text": $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } return str_replace('$$$$', $separate, nl2br($data[$NAME . $num])); case "date": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . 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": return timestampToString($data[$NAME . $num]); case "realtime": return Ticket::getRealtime($data[$NAME . $num]); case "date_delay": $split = explode('$$$$', $data[$NAME . $num]); $out = ''; foreach ($split as $val) { if (strpos($val, ',')) { list($dat, $dur) = explode(',', $val); if (!empty($dat)) { $out .= (empty($out) ? '' : '<br>') . getWarrantyExpir($dat, $dur); } } } return empty($out) ? " " : $out; case "email": // Stevenes // $email=trim($data[$NAME.$num]); $email = explode('$$', $data[$NAME . $num]); if (!empty($email['0'])) { return $email['0']; //return "<a href='mailto:$email'>$email</a>"; } return " "; 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 (utf8_strlen($link) > 30) { $link = Toolbox::substr($link, 0, 30) . "..."; } //return "<a href=\"".formatOutputWebLink($orig_link)."\" target='_blank'>$link</a>"; return $orig_link; } return " "; 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) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', Html::formatNumber($split[$k], false, 0)) . $unit; } } return $out; } return str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num], false, 0)) . $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) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', Html::formatNumber($split[$k])) . $unit; } } return $out; } return str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num])) . $unit; case "bool": return Dropdown::getYesNo($data[$NAME . $num]) . $unit; case "right": return Profile::getRightValue($data[$NAME . $num]); case "itemtypename": if (class_exists($data[$NAME . $num])) { $obj = new $data[$NAME . $num](); return $obj->getTypeName(); } else { return ""; } case "language": if (isset($CFG_GLPI['languages'][$data[$NAME . $num]])) { return $CFG_GLPI['languages'][$data[$NAME . $num]][0]; } else { return $LANG['setup'][46]; } break; } } // 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; } $count_display++; $out .= $split[$k] . $unit; } } return $out; } return $data[$NAME . $num] . $unit; }
echo "<td> " . convDate($data['buy_date']) . " </td>"; if ($data["warranty_duration"]) { echo "<td> " . getWarrantyExpir($data["buy_date"], $data["warranty_duration"]) . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } } else { echo "<td> " . NOT_AVAILABLE . " </td><td> " . NOT_AVAILABLE . " </td>"; } if ($data['type']) { echo "<td class='b'> " . $data['type'] . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } if ($data['begin_date']) { echo "<td> " . convDate($data['begin_date']) . " </td>"; if ($data["duration"]) { echo "<td> " . getWarrantyExpir($data["begin_date"], $data["duration"]) . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } } else { echo "<td> " . NOT_AVAILABLE . " </td><td> " . NOT_AVAILABLE . " </td>"; } echo "</tr>\n"; } echo "</table><br><hr><br>"; } } } commonFooter();
/** * Show installed cartridges * *@param $printer object Printer *@param $old boolean : old cartridges or not ? * *@return nothing (display) **/ static function showInstalled(Printer $printer, $old = 0) { global $DB, $CFG_GLPI, $LANG; $instID = $printer->getField('id'); if (!haveRight("cartridge", "r")) { return false; } $canedit = haveRight("cartridge", "w"); $query = "SELECT `glpi_cartridgeitems`.`id` AS tID,\n `glpi_cartridgeitems`.`is_deleted`,\n `glpi_cartridgeitems`.`ref` AS ref,\n `glpi_cartridgeitems`.`name` AS type,\n `glpi_cartridges`.`id`,\n `glpi_cartridges`.`pages` AS pages,\n `glpi_cartridges`.`date_use` AS date_use,\n `glpi_cartridges`.`date_out` AS date_out,\n `glpi_cartridges`.`date_in` AS date_in\n FROM `glpi_cartridges`,\n `glpi_cartridgeitems`\n WHERE (`glpi_cartridges`.`date_out` IS " . ($old ? "NOT" : "") . " NULL\n AND `glpi_cartridges`.`printers_id` = '{$instID}'\n AND `glpi_cartridges`.`cartridgeitems_id` = `glpi_cartridgeitems`.`id`)\n ORDER BY `glpi_cartridges`.`date_out` ASC,\n `glpi_cartridges`.`date_use` DESC,\n `glpi_cartridges`.`date_in`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $pages = $printer->fields['init_pages_counter']; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; if ($old == 0) { echo "<tr><th colspan='5'>" . $LANG['cartridges'][33] . " :</th></tr>"; } else { echo "<tr><th colspan='7'>" . $LANG['cartridges'][35] . " :</th></tr>"; } echo "<tr><th>" . $LANG['common'][2] . "</th><th>" . $LANG['cartridges'][12] . "</th>"; echo "<th>" . $LANG['cartridges'][24] . "</th>"; echo "<th>" . $LANG['consumables'][26] . "</th>"; if ($old != 0) { echo "<th>" . $LANG['search'][9] . "</th><th>" . $LANG['cartridges'][39] . "</th>"; } echo "<th> </th></tr>"; $stock_time = 0; $use_time = 0; $pages_printed = 0; $nb_pages_printed = 0; while ($data = $DB->fetch_array($result)) { $date_in = convDate($data["date_in"]); $date_use = convDate($data["date_use"]); $date_out = convDate($data["date_out"]); echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>" . $data["id"] . "</td>"; echo "<td class='center b'>"; echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/cartridgeitem.form.php?id=" . $data["tID"] . "\">" . $data["type"] . " - " . $data["ref"] . "</a></td>"; echo "<td class='center'>" . $date_in . "</td>"; echo "<td class='center'>" . $date_use; $tmp_dbeg = explode("-", $data["date_in"]); $tmp_dend = explode("-", $data["date_use"]); $stock_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0]) - mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]); $stock_time += $stock_time_tmp; if ($old != 0) { echo "</td>"; echo "<td class='center'>" . $date_out; } if ($old != 0) { $tmp_dbeg = explode("-", $data["date_use"]); $tmp_dend = explode("-", $data["date_out"]); $use_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0]) - mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]); $use_time += $use_time_tmp; } echo "</td><td class='center'>"; if ($old != 0) { if ($canedit) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/cartridge.form.php\">"; echo "<input type='hidden' name='cID' value='" . $data['id'] . "'>"; echo "<input type='text' name='pages' value=\"" . $data['pages'] . "\" size='10'>"; echo "<input type='image' name='update_pages' value='update_pages'\n src='" . $CFG_GLPI["root_doc"] . "/pics/actualiser.png' class='calendrier'>"; echo "</form>"; } else { echo "<input type='text' name='pages' value=\"" . $data['pages'] . "\" size='10'>"; } if ($pages < $data['pages']) { $pages_printed += $data['pages'] - $pages; $nb_pages_printed++; echo $data['pages'] - $pages . " " . $LANG['printers'][31]; $pages = $data['pages']; } echo "</td><td class='center'>"; } if ($canedit) { echo "<span class='small_space'>"; if (is_null($date_out)) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/cartridge.form.php?uninstall=uninstall&id=" . $data["id"] . "&tID=" . $data["tID"] . "'>" . $LANG['cartridges'][29] . "</a>"; } else { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/cartridge.form.php?delete=delete&id=" . $data["id"] . "&tID=" . $data["tID"] . "'>" . $LANG['buttons'][6] . "</a>"; } echo "</span></td></tr>"; } } if ($old == 0 && $canedit) { echo "<tr class='tab_bg_1'><td> </td><td class='center' colspan='3'>"; echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/cartridge.form.php\">"; echo "<input type='hidden' name='pID' value='{$instID}'>"; if (CartridgeItem::dropdownForPrinter($printer)) { echo " <input type='submit' name='install' value=\"" . $LANG['buttons'][4] . "\"\n class='submit'>"; } echo "</form></td><td class='tab_bg_2 center'> "; echo "</td></tr>"; } else { // Print average if ($number > 0) { if ($nb_pages_printed == 0) { $nb_pages_printed = 1; } echo "<tr class='tab_bg_2'><td> </td><td> </td><td> </td>"; echo "<td class='center'>" . $LANG['cartridges'][40] . " :<br>"; echo round($stock_time / $number / 60 / 60 / 24 / 30.5, 1) . " " . $LANG['financial'][57] . "</td>"; echo "<td class='center'>" . $LANG['cartridges'][41] . ":<br>"; echo round($use_time / $number / 60 / 60 / 24 / 30.5, 1) . " " . $LANG['financial'][57] . "</td>"; echo "<td class='center'>" . $LANG['cartridges'][42] . ":<br>"; echo round($pages_printed / $nb_pages_printed) . "</td>"; echo "<td> </td></tr>"; } } echo "</table></div>"; }