function showForm($id, $options = array())
 {
     global $DB;
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='3'>";
     echo __('List of fields to history', 'fusioninventory') . " :";
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     $options = "";
     $mapping = new PluginFusioninventoryMapping();
     $maps = $mapping->find();
     $listName = array();
     foreach ($maps as $mapfields) {
         # TODO: untested
         $listName[$mapfields['itemtype'] . "-" . $mapfields['name']] = $mapping->getTranslation($mapfields);
     }
     if (!empty($listName)) {
         asort($listName);
     }
     // Get list of fields configured for history
     $query = "SELECT *\n                FROM `glpi_plugin_fusioninventory_configlogfields`;";
     $result = $DB->query($query);
     if ($result) {
         while ($data = $DB->fetch_array($result)) {
             $type = '';
             $name = '';
             list($type, $name) = explode("-", $data['field']);
             if (!isset($listName[$type . "-" . $name])) {
                 $query_del = "DELETE FROM `glpi_plugin_fusioninventory_configlogfields`\n                  WHERE id='" . $data['id'] . "' ";
                 $DB->query($query_del);
             } else {
                 $options[$data['field']] = $listName[$type . "-" . $name];
             }
             unset($listName[$data['field']]);
         }
     }
     if (!empty($options)) {
         asort($options);
     }
     echo "<td class='right' width='350'>";
     if (count($listName)) {
         echo "<select name='plugin_fusioninventory_extraction_to_add[]' multiple size='15'>";
         foreach ($listName as $key => $val) {
             //list ($item_type, $item) = explode("_", $key);
             echo "<option value='{$key}'>" . $val . "</option>\n";
         }
         echo "</select>";
     }
     echo "</td><td class='center'>";
     if (count($listName)) {
         if (Session::haveRight('plugin_fusioninventory_configuration', UPDATE)) {
             echo "<input type='submit'  class=\"submit\" " . "name='plugin_fusioninventory_extraction_add' value='" . __('Add') . " >>'>";
         }
     }
     echo "<br /><br />";
     if (!empty($options)) {
         if (Session::haveRight('plugin_fusioninventory_configuration', UPDATE)) {
             echo "<input type='submit'  class=\"submit\" " . "name='plugin_fusioninventory_extraction_delete' value='<< " . __('Delete', 'fusioninventory') . "'>";
         }
     }
     echo "</td><td class='left'>";
     if (!empty($options)) {
         echo "<select name='plugin_fusioninventory_extraction_to_delete[]' multiple size='15'>";
         foreach ($options as $key => $val) {
             //list ($item_type, $item) = explode("_", $key);
             echo "<option value='{$key}'>" . $val . "</option>\n";
         }
         echo "</select>";
     } else {
         echo "&nbsp;";
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<th colspan='3'>";
     echo __('Clean history', 'fusioninventory') . " :";
     echo "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='3' class='center'>";
     if (Session::haveRight('plugin_fusioninventory_configuration', UPDATE)) {
         echo "<input type='submit' class=\"submit\" name='Clean_history' " . "value='" . __('Clean') . "' >";
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<th colspan='3'>";
     echo "&nbsp;";
     echo "</th>";
     echo "</tr>";
     $this->showFormButtons($options);
     echo "<div id='tabcontent'></div>";
     echo "<script type='text/javascript'>loadDefaultTab();</script>";
     return TRUE;
 }
    /**
     * 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') . "&nbsp;:</td>";
        echo "<td class='left'>";
        Html::showDateFormItem("graph_begin", $begin);
        echo "</td>";
        echo "<td class='left'>" . __('Time unit', 'fusioninventory') . "&nbsp;:</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') . "&nbsp;:</td>";
        echo "<td class='left'>";
        Html::showDateFormItem("graph_end", $end);
        echo "</td>";
        echo "<td class='left'>" . __('Display', 'fusioninventory') . "&nbsp;:</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') . "&nbsp;:</td>";
        echo "<td class='left' rowspan='3'>";
        echo $printersList;
        echo "</td>";
        echo "<td class='left'>" . __('Add a printer', 'fusioninventory') . "&nbsp;:</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 "&nbsp;<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') . "&nbsp;:</td>";
        echo "<td class='left'>";
        $printersTmp = $printersView;
        $printersTmp[0] = "-----";
        asort($printersTmp);
        Dropdown::showFromArray('graph_printerCompRemove', $printersTmp);
        echo "&nbsp;<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>';
    }