function showForm(Printer $item, $options = array()) { // ** Get link OID fields $mapping_name = array(); $id = $item->getID(); $a_cartridges = $this->find("`printers_id`='" . $id . "'"); echo "<div align='center'><form method='post' name='snmp_form' id='snmp_form'\n action=\"" . $options['target'] . "\">"; echo "<table class='tab_cadre' cellpadding='5' width='950'>"; echo "<tr class='tab_bg_1'>"; echo "<th align='center' colspan='3'>"; echo __('Cartridge(s)', 'fusioninventory'); echo "</th>"; echo "</tr>"; asort($mapping_name); $mapping = new PluginFusioninventoryMapping(); foreach ($a_cartridges as $a_cartridge) { echo "<tr class='tab_bg_1'>"; echo "<td align='center'>"; $mapping->getFromDB($a_cartridge['plugin_fusioninventory_mappings_id']); echo $mapping->getTranslation($mapping->fields); echo " : "; echo "</td>"; echo "<td align='center'>"; echo "</td>"; echo "<td align='center'>"; if ($a_cartridge['state'] == 100000) { echo __('OK'); } else { if ($a_cartridge['state'] < 0) { $a_cartridge['state'] = $a_cartridge['state'] * -1; echo $a_cartridge['state']; echo ' ' . __('remaining pages', 'fusioninventory'); } else { PluginFusioninventoryDisplay::bar($a_cartridge['state']); } } echo "</td>"; echo "</tr>"; } echo "</table>"; Html::closeForm(); echo "</div>"; }
static function showHistory($ID_port) { global $DB, $CFG_GLPI; $np = new NetworkPort(); $query = "\n SELECT * FROM(\n SELECT * FROM (\n SELECT `id`, `date_mod`, `plugin_fusioninventory_agentprocesses_id`,\n `networkports_id_source`, `networkports_id_destination`,\n `creation` as `field`, NULL as `value_old`, NULL as `value_new`\n FROM `glpi_plugin_fusioninventory_networkportconnectionlogs`\n WHERE `networkports_id_source`='" . $ID_port . "'\n OR `networkports_id_destination`='" . $ID_port . "'\n ORDER BY `date_mod` DESC\n )\n AS `DerivedTable1`\n UNION ALL\n SELECT * FROM (\n SELECT `glpi_plugin_fusioninventory_networkportlogs`.`id`,\n `date_mod` as `date_mod`, `plugin_fusioninventory_agentprocesses_id`,\n `networkports_id` AS `networkports_id_source`,\n NULL as `networkports_id_destination`,\n `name` AS `field`, `value_old`, `value_new`\n FROM `glpi_plugin_fusioninventory_networkportlogs`\n LEFT JOIN `glpi_plugin_fusioninventory_mappings`\n ON `glpi_plugin_fusioninventory_networkportlogs`." . "`plugin_fusioninventory_mappings_id` =\n `glpi_plugin_fusioninventory_mappings`.`id`\n WHERE `networkports_id`='" . $ID_port . "'\n ORDER BY `date_mod` DESC\n )\n AS `DerivedTable2`)\n AS `MainTable`\n ORDER BY `date_mod` DESC, `id` DESC"; $text = "<table class='tab_cadre' cellpadding='5' width='950'>"; $text .= "<tr class='tab_bg_1'>"; $text .= "<th colspan='8'>"; $text .= "Historique"; $text .= "</th>"; $text .= "</tr>"; $text .= "<tr class='tab_bg_1'>"; $text .= "<th>" . __('Connection') . "</th>"; $text .= "<th>" . __('Item') . "</th>"; $text .= "<th>" . __('Field') . "</th>"; $text .= "<th></th>"; $text .= "<th></th>"; $text .= "<th></th>"; $text .= "<th>" . __('Date') . "</th>"; $text .= "</tr>"; $result = $DB->query($query); if ($result) { while ($data = $DB->fetch_array($result)) { $text .= "<tr class='tab_bg_1'>"; if (!empty($data["networkports_id_destination"])) { // Connections and disconnections $imgfolder = $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics"; if ($data['field'] == '1') { $text .= "<td align='center'><img src='" . $imgfolder . "/connection_ok.png'/></td>"; } else { $text .= "<td align='center'><img src='" . $imgfolder . "/connection_notok.png'/></td>"; } if ($ID_port == $data["networkports_id_source"]) { if ($np->getFromDB($data["networkports_id_destination"])) { //if (isset($np->fields["items_id"])) { $item = new $np->fields["itemtype"](); $item->getFromDB($np->fields["items_id"]); $link1 = $item->getLink(1); $link = "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $np->fields["id"] . "\">"; if (rtrim($np->fields["name"]) != "") { $link .= $np->fields["name"]; } else { $link .= __('Without name'); } $link .= "</a>"; $text .= "<td align='center'>" . $link . " " . __('on', 'fusioninventory') . " " . $link1 . "</td>"; } else { $text .= "<td align='center'><font color='#ff0000'>" . __('Deleted') . "</font></td>"; } } else { if ($ID_port == $data["networkports_id_destination"]) { $np->getFromDB($data["networkports_id_source"]); if (isset($np->fields["items_id"])) { $item = new $np->fields["itemtype"](); $item->getFromDB($np->fields["items_id"]); $link1 = $item->getLink(1); $link = "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $np->fields["id"] . "\">"; if (rtrim($np->fields["name"]) != "") { $link .= $np->fields["name"]; } else { $link .= __('Without name'); } $link .= "</a>"; $text .= "<td align='center'>" . $link . " " . __('on', 'fusioninventory') . " " . $link1 . "</td>"; } else { $text .= "<td align='center'><font color='#ff0000'>" . __('Deleted') . "</font></td>"; } } } $text .= "<td align='center' colspan='4'></td>"; $text .= "<td align='center'>" . Html::convDateTime($data["date_mod"]) . "</td>"; } else { // Changes values $text .= "<td align='center' colspan='2'></td>"; // $text .= "<td align='center'>". // $FUSIONINVENTORY_MAPPING[NETWORKING_TYPE][$data["field"]]['name']."</td>"; $mapping = new PluginFusioninventoryMapping(); $mapfields = $mapping->get('NetworkEquipment', $data["field"]); if ($mapfields != FALSE) { $text .= "<td align='center'>" . $mapping->getTranslation($mapfields) . "</td>"; } else { $text .= "<td align='center'></td>"; } $text .= "<td align='center'>" . $data["value_old"] . "</td>"; $text .= "<td align='center'>-></td>"; $text .= "<td align='center'>" . $data["value_new"] . "</td>"; $text .= "<td align='center'>" . Html::convDateTime($data["date_mod"]) . "</td>"; } $text .= "</tr>"; } } $text .= "</table>"; return $text; }
/** * Show printer graph form **/ function showGraph($id, $options = array()) { global $DB, $CFG_GLPI; $printer = new Printer(); $where = ''; $begin = ''; $end = ''; $timeUnit = 'day'; $graphField = 'pages_total'; $pagecounters = array(); $graphType = 'day'; if (isset($_SESSION['glpi_plugin_fusioninventory_graph_begin'])) { $begin = $_SESSION['glpi_plugin_fusioninventory_graph_begin']; } if ($begin == 'NULL' or $begin == '') { $begin = date("Y-m-01"); // first day of current month } if (isset($_SESSION['glpi_plugin_fusioninventory_graph_end'])) { $end = $_SESSION['glpi_plugin_fusioninventory_graph_end']; } if (isset($_SESSION['glpi_plugin_fusioninventory_graph_type'])) { $graphType = $_SESSION['glpi_plugin_fusioninventory_graph_type']; } if ($end == 'NULL' or $end == '') { $end = date("Y-m-d"); // today } if (isset($_SESSION['glpi_plugin_fusioninventory_graph_timeUnit'])) { $timeUnit = $_SESSION['glpi_plugin_fusioninventory_graph_timeUnit']; } if (!isset($_SESSION['glpi_plugin_fusioninventory_graph_printersComp'])) { $_SESSION['glpi_plugin_fusioninventory_graph_printersComp'] = array(); } if (isset($_SESSION['glpi_plugin_fusioninventory_graph_printerCompAdd'])) { $printerCompAdd = $_SESSION['glpi_plugin_fusioninventory_graph_printerCompAdd']; if (!key_exists($printerCompAdd, $_SESSION['glpi_plugin_fusioninventory_graph_printersComp'])) { $oPrinter = new Printer(); if ($oPrinter->getFromDB($printerCompAdd)) { $_SESSION['glpi_plugin_fusioninventory_graph_printersComp'][$printerCompAdd] = $oPrinter->getField('name'); } } } elseif (isset($_SESSION['glpi_plugin_fusioninventory_graph_printerCompRemove'])) { unset($_SESSION['glpi_plugin_fusioninventory_graph_printersComp'][$_SESSION['glpi_plugin_fusioninventory_graph_printerCompRemove']]); } $oPrinter = new Printer(); $printers = $_SESSION['glpi_plugin_fusioninventory_graph_printersComp']; $printersView = $printers; // printers without the current printer if (isset($printersView[$id])) { unset($printersView[$id]); } else { if ($oPrinter->getFromDB($id)) { $printers[$id] = $oPrinter->getField('name'); } } $printersList = ''; foreach ($printers as $printers_id => $printername) { if ($printersList != '') { $printersList .= '<br/>'; } if ($printers_id == $id) { $printersList .= $printername; } else { $oPrinter->getFromDB($printers_id); $printersList .= $oPrinter->getLink(1); } } $printersIds = ""; foreach (array_keys($printers) as $printerId) { if ($printersIds != '') { $printersIds .= ', '; } $printersIds .= $printerId; } $where = " WHERE `printers_id` IN(" . $printersIds . ")"; if ($begin != '' || $end != '') { $where .= " AND " . getDateRequest("`date`", $begin, $end); } $group = ''; switch ($timeUnit) { case 'day': $group = "GROUP BY `printers_id`, `year`, `month`, `day`"; break; case 'week': $group = "GROUP BY `printers_id`, `year`, `month`, `week`"; break; case 'month': $group = "GROUP BY `printers_id`, `year`, `month`"; break; case 'year': $group = "GROUP BY `printers_id`, `year`"; break; } echo "<form method='post' name='snmp_form' id='snmp_form' action='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/printer_info.form.php'>"; echo "<table class='tab_cadre' cellpadding='5' width='950'>"; $mapping = new PluginFusioninventoryMapping(); $maps = $mapping->find("`itemtype`='Printer'"); foreach ($maps as $mapfields) { if (!isset($mapfields["shortlocale"])) { $mapfields["shortlocale"] = $mapfields["locale"]; } $pagecounters[$mapfields['name']] = $mapping->getTranslation($mapfields); } echo "<tr class='tab_bg_1'>"; echo "<th colspan='4'>"; echo __('Printed page counter', 'fusioninventory'); echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td class='left'>" . __('Start date') . " :</td>"; echo "<td class='left'>"; Html::showDateFormItem("graph_begin", $begin); echo "</td>"; echo "<td class='left'>" . __('Time unit', 'fusioninventory') . " :</td>"; echo "<td class='left'>"; $elementsTime = array('day' => _n('Day', 'Days', 1), 'week' => __('Week'), 'month' => _n('Month', 'Months', 1), 'year' => __('Year', 'fusioninventory')); Dropdown::showFromArray('graph_timeUnit', $elementsTime, array('value' => $timeUnit)); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td class='left'>" . __('End date') . " :</td>"; echo "<td class='left'>"; Html::showDateFormItem("graph_end", $end); echo "</td>"; echo "<td class='left'>" . __('Display', 'fusioninventory') . " :</td>"; echo "<td class='left'>"; $elements = array('total' => __('Total counter', 'fusioninventory'), 'day' => __('pages per day', 'fusioninventory')); Dropdown::showFromArray('graph_type', $elements, array('value' => $graphType)); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='4'>\n <input type='submit' class='submit' name='graph_plugin_fusioninventory_printer_period'\n value='" . __('Update') . "'/>"; echo "</td>"; echo "</tr>\n"; echo "<tr>"; echo "<th colspan='4'>" . __('Printers to compare', 'fusioninventory') . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td class='left' rowspan='3'>" . __('Printer') . " :</td>"; echo "<td class='left' rowspan='3'>"; echo $printersList; echo "</td>"; echo "<td class='left'>" . __('Add a printer', 'fusioninventory') . " :</td>"; echo "<td class='left'>"; $printersused = array(); foreach ($printersView as $printer_id => $name) { $printersused[] = $printer_id; } $printer->getFromDB($id); Dropdown::show('Printer', array('name' => 'graph_printerCompAdd', 'entity' => $printer->fields['entities_id'], 'used' => $printersused)); echo " <input type='submit' value=\"" . __('Add') . "\" class='submit' " . "name='graph_plugin_fusioninventory_printer_add'>"; echo "</td>"; echo "</tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='left'>" . __('Remove a printer', 'fusioninventory') . " :</td>"; echo "<td class='left'>"; $printersTmp = $printersView; $printersTmp[0] = "-----"; asort($printersTmp); Dropdown::showFromArray('graph_printerCompRemove', $printersTmp); echo " <input type='submit' value=\"" . __('Delete', 'fusioninventory') . "\" " . "class='submit' name='graph_plugin_fusioninventory_printer_remove'>"; echo "</td>"; echo "</tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'></td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); $elementsField = array('pages_total' => $pagecounters['pagecountertotalpages'], 'pages_n_b' => $pagecounters['pagecounterblackpages'], 'pages_color' => $pagecounters['pagecountercolorpages'], 'pages_recto_verso' => $pagecounters['pagecounterrectoversopages'], 'scanned' => $pagecounters['pagecounterscannedpages'], 'pages_total_print' => $pagecounters['pagecountertotalpages_print'], 'pages_n_b_print' => $pagecounters['pagecounterblackpages_print'], 'pages_color_print' => $pagecounters['pagecountercolorpages_print'], 'pages_total_copy' => $pagecounters['pagecountertotalpages_copy'], 'pages_n_b_copy' => $pagecounters['pagecounterblackpages_copy'], 'pages_color_copy' => $pagecounters['pagecountercolorpages_copy'], 'pages_total_fax' => $pagecounters['pagecountertotalpages_fax']); echo "<br/>"; $a_graph = array(); foreach ($elementsField as $graphField => $name) { $query = "SELECT `printers_id`, DAY(`date`)-1 AS `day`, WEEK(`date`) AS `week`,\n MONTH(`date`) AS `month`, YEAR(`date`) AS `year`, `date`,\n `{$graphField}`\n FROM `glpi_plugin_fusioninventory_printerlogs`" . $where . " AND `" . $graphField . "` > 0 " . $group; $result = $DB->query($query); if ($DB->numrows($result) == 0) { unset($elementsField[$graphField]); } } foreach ($elementsField as $graphField => $name) { $query = "SELECT `printers_id`, DAY(`date`)-1 AS `day`, WEEK(`date`) AS `week`,\n MONTH(`date`) AS `month`, YEAR(`date`) AS `year`, `date`,\n `{$graphField}`\n FROM `glpi_plugin_fusioninventory_printerlogs`" . $where . $group . "\n ORDER BY `year`, `month`, `day`, `printers_id`"; $input = array(); $result = $DB->query($query); if ($result) { if ($DB->numrows($result) != 0) { $pages = array(); $data = array(); $date = ''; while ($data = $DB->fetch_assoc($result)) { switch ($timeUnit) { case 'day': $split = explode(" ", $data['date']); $date = $split[0]; break; case 'week': $split = explode(" ", $data['date']); $date = $split[0]; break; case 'month': $split = explode(" ", $data['date']); $split2 = explode("-", $split[0]); $date = $split2[0] . "-" . $split2[1]; break; case 'year': $split = explode(" ", $data['date']); $split2 = explode("-", $split[0]); $date = $split2[0]; break; } if ($graphType == 'day') { if (!isset($pages[$data['printers_id']])) { $pages[$data['printers_id']] = $data[$graphField]; } else { $y = $data[$graphField] - $pages[$data['printers_id']]; if ($y < 0) { $y = 0; } $input[] = array('x' => $date, 'y' => $y); if ($data[$graphField] > 0) { $pages[$data['printers_id']] = $data[$graphField]; } } } else { $input[] = array('x' => $date, 'y' => $data[$graphField]); } } } } $continue = 1; if ($continue == '0' or $continue == '-1') { echo "<table class='tab_cadre' cellpadding='5' width='900'>"; echo "<tr class='tab_bg_1'>"; echo "<th>"; echo $name; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>"; if ($continue == '0') { echo __('Too datas to display', 'fusioninventory'); } echo "</td>"; echo "</tr>"; echo "</table><br/>"; } else { if (count($input > 0)) { $split = explode(' > ', $name); $a_graph[] = array('key' => $split[count($split) - 1], 'values' => $input); } } } // Display graph echo '<div id="chartPrinter">' . '<svg style="height: 400px; width: 950px;"></svg>' . '</div>'; echo "<script type='text/javascript'>\n function drawGraph() {\n var chart = nv.models.multiBarChart();\n\n chart.yAxis\n .tickFormat(d3.format(',0f'));\n\n d3.select('#chartPrinter svg')\n .datum(exampleData())\n .transition().duration(500).call(chart);\n\n nv.utils.windowResize(chart.update);\n }\n "; echo ' function exampleData() { return ' . json_encode($a_graph) . ' } drawGraph(); </script>'; }
function showForm($options = array()) { global $DB; $mapping = new PluginFusioninventoryMapping(); echo "<form name='form' method='post' action='" . $options['target'] . "'>"; echo "<div class='center' id='tabsbody'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='2'>"; echo __('History configuration', 'fusioninventory'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<th>"; echo __('List of fields for which to keep history', 'fusioninventory'); echo "</th>"; echo "<th>"; echo __('Retention in days', 'fusioninventory'); echo "</th>"; echo "</tr>"; $days = array(); $days[-1] = __('Never'); $days[0] = __('Always'); for ($i = 1; $i < 366; $i++) { $days[$i] = "{$i}"; } $query = "SELECT `" . $this->getTable() . "`.`id`, `locale`, `days`, `itemtype`, `name`\n FROM `" . $this->getTable() . "`, `glpi_plugin_fusioninventory_mappings`\n WHERE `" . $this->getTable() . "`.`plugin_fusioninventory_mappings_id`=\n `glpi_plugin_fusioninventory_mappings`.`id`\n ORDER BY `itemtype`, `name`;"; $result = $DB->query($query); if ($result) { while ($data = $DB->fetch_array($result)) { echo "<tr class='tab_bg_1'>"; echo "<td align='left'>"; echo $mapping->getTranslation($data); echo "</td>"; echo "<td align='center'>"; Dropdown::showFromArray('field-' . $data['id'], $days, array('value' => $data['days'])); echo "</td>"; echo "</tr>"; } } if (Session::haveRight('plugin_fusioninventory_configuration', UPDATE)) { echo "<tr class='tab_bg_2'><td align='center' colspan='4'>\n <input type='hidden' name='tabs' value='history'/>\n <input class='submit' type='submit' name='update'\n value='" . __('Update') . "'></td></tr>"; } echo "</table>"; echo "<br/>"; echo "<table class='tab_cadre_fixe' cellpadding='2'>"; echo "<tr class='tab_bg_2'>"; echo "<td colspan='1' class='center' height='30'>"; if (Session::haveRight('plugin_fusioninventory_configuration', UPDATE)) { echo "<input type='submit' class=\"submit\" name='Clean_history' " . "value='" . __('Clean') . "' >"; } echo "</td>"; echo "</tr>"; echo "</table></div>"; Html::closeForm(); return TRUE; }