function getrightmodel($device_id, $type) { global $DB; // Get description (sysdescr) of device // And search in device_serials base $sysdescr = ''; switch ($type) { case NETWORKING_TYPE: $Netdevice = new Netdevice(); $Netdevice->check($device_id, 'r'); $sysdescr = $Netdevice->fields["comments"]; break; case PRINTER_TYPE: $Printer = new Printer(); $Printer->check($device_id, 'r'); $sysdescr = $Printer->fields["comments"]; break; } $sysdescr = str_replace("\r", "", $sysdescr); if (!empty($sysdescr)) { $xml = @simplexml_load_file(GLPI_ROOT . '/plugins/fusioninventory/tool/discovery.xml'); foreach ($xml->DEVICE as $device) { $device['SYSDESCR'] = str_replace("\r", "", $device['SYSDESCR']); if ($sysdescr == $device['SYSDESCR']) { if (isset($device['MODELSNMP'])) { $modelgetted = $device['MODELSNMP']; } break; } } if (!empty($modelgetted)) { $query = "SELECT * \n FROM `glpi_plugin_fusioninventory_model_infos`\n WHERE `discovery_key`='" . $modelgetted . "'\n LIMIT 0,1"; $result = $DB->query($query); $data = $DB->fetch_assoc($result); $FK_model = $data['ID']; // Udpate Device with this model switch ($type) { case NETWORKING_TYPE: $query = "UPDATE `glpi_plugin_fusioninventory_networking`\n SET `FK_model_infos`='" . $FK_model . "'\n WHERE `FK_networking`='" . $device_id . "'"; $DB->query($query); break; case PRINTER_TYPE: $query = "UPDATE `glpi_plugin_fusioninventory_printers`\n SET `FK_model_infos`='" . $FK_model . "'\n WHERE `FK_printers`='" . $device_id . "'"; $DB->query($query); break; } } } }
/** form for Cartridge * * @since version 0.84 * * @param $ID integer Id of the cartridge * @param $options array of possible options: * - parent Object : the printers where the cartridge is used **/ function showForm($ID, $options = array()) { global $DB, $CFG_GLPI; if (isset($options['parent']) && !empty($options['parent'])) { $printer = $options['parent']; } if (!$this->getFromDB($ID)) { return false; } $printer = new Printer(); $printer->check($this->getField('printers_id'), UPDATE); $cartitem = new CartridgeItem(); $cartitem->getFromDB($this->getField('cartridgeitems_id')); $is_old = !empty($this->fields['date_out']); $is_used = !empty($this->fields['date_use']); $options['colspan'] = 2; $options['candel'] = false; // Do not permit delete here $options['canedit'] = $is_used; // Do not permit edit if cart is not used $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<td>" . _n('Printer', 'Printers', 1) . "</td><td>"; echo $printer->getLink(); echo "<input type='hidden' name='printers_id' value='" . $this->getField('printers_id') . "'>\n"; echo "<input type='hidden' name='cartridgeitems_id' value='" . $this->getField('cartridgeitems_id') . "'>\n"; echo "</td>\n"; echo "<td>" . _n('Cartridge model', 'Cartridge models', 1) . "</td>"; echo "<td>" . $cartitem->getLink() . "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Add date') . "</td>"; echo "<td>" . Html::convDate($this->fields["date_in"]) . "</td>"; echo "<td>" . __('Use date') . "</td><td>"; if ($is_used && !$is_old) { Html::showDateField("date_use", array('value' => $this->fields["date_use"], 'maybeempty' => false, 'canedit' => true, 'min' => $this->fields["date_in"])); } else { echo Html::convDate($this->fields["date_use"]); } echo "</td></tr>\n"; if ($is_old) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('End date') . "</td><td>"; Html::showDateField("date_out", array('value' => $this->fields["date_out"], 'maybeempty' => false, 'canedit' => true, 'min' => $this->fields["date_use"])); echo "</td>"; echo "<td>" . __('Printer counter') . "</td><td>"; echo "<input type='text' name='pages' value=\"" . $this->fields['pages'] . "\">"; echo "</td></tr>\n"; } $this->showFormButtons($options); return true; }
include GLPI_ROOT . "/inc/includes.php"; if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["sort"])) { $_GET["sort"] = ""; } if (!isset($_GET["order"])) { $_GET["order"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $print = new Printer(); if (isset($_POST["add"])) { $print->check(-1, 'w', $_POST); if ($newID = $print->add($_POST)) { Event::log($newID, "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][20] . " " . $_POST["name"] . "."); } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["delete"])) { $print->check($_POST["id"], 'd'); $print->delete($_POST); Event::log($_POST["id"], "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][22]); $print->redirectToList(); } else { if (isset($_POST["restore"])) { $print->check($_POST["id"], 'd'); $print->restore($_POST); Event::log($_POST["id"], "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][23]);
-------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("printer", READ); if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $print = new Printer(); if (isset($_POST["add"])) { $print->check(-1, CREATE, $_POST); if ($newID = $print->add($_POST)) { Event::log($newID, "printers", 4, "inventory", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])); if ($_SESSION['glpibackcreated']) { Html::redirect($print->getFormURL() . "?id=" . $newID); } } Html::back(); } else { if (isset($_POST["delete"])) { $print->check($_POST["id"], DELETE); $print->delete($_POST); Event::log($_POST["id"], "printers", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); $print->redirectToList(); } else { if (isset($_POST["restore"])) {