/** * Prints display post import * * @param $type the type of device * @param $ID the ID of device * @param $fromsupplier selection on pre import * @param $fromwarranty selection on pre import * @param $configID ID of supplier plugin config * @return results of data import * */ static function seePostImport($type, $ID, $fromsupplier, $fromwarranty, $configID) { global $DB, $CFG_GLPI; $config = new PluginManufacturersimportsConfig(); $config->getFromDB($configID); $manufacturerId = $config->fields["manufacturers_id"]; if ($fromsupplier) { $supplierId = $fromsupplier; } else { $supplierId = $config->fields["suppliers_id"]; } $suppliername = $config->fields["name"]; $supplierkey = $config->fields["supplier_key"]; $adddoc = $config->fields["document_adding"]; $rubrique = $config->fields["documentcategories_id"]; $addcomments = $config->fields["comment_adding"]; if ($fromwarranty) { $warranty = $fromwarranty; } else { $warranty = $config->fields["warranty_duration"]; } $itemtable = getTableForItemType($type); $query = "SELECT `" . $itemtable . "`.`id`,\n `" . $itemtable . "`.`name`,\n `" . $itemtable . "`.`entities_id`,\n `" . $itemtable . "`.`serial`\n FROM `" . $itemtable . "`, `glpi_manufacturers`\n WHERE `" . $itemtable . "`.`manufacturers_id` = `glpi_manufacturers`.`id`\n AND `" . $itemtable . "`.`is_deleted` = '0'\n AND `" . $itemtable . "`.`is_template` = '0'\n AND `glpi_manufacturers`.`id` = '" . $manufacturerId . "'\n AND `" . $itemtable . "`.`serial` != ''\n AND `" . $itemtable . "`.`id` = '" . $ID . "' "; $query .= " ORDER BY `" . $itemtable . "`.`name`"; $result = $DB->query($query); while ($line = $DB->fetch_array($result)) { $compSerial = $line['serial']; $ID = $line['id']; echo "<tr class='tab_bg_1' ><td>"; $link = Toolbox::getItemTypeFormURL($type); $dID = ""; $model = new PluginManufacturersimportsModel(); $otherSerial = $model->checkIfModelNeeds($type, $ID); if ($_SESSION["glpiis_ids_visible"] || empty($line["name"])) { $dID .= " (" . $line["id"] . ")"; } echo "<a href='" . $link . "?id=" . $ID . "'>" . $line["name"] . $dID . "</a><br>" . $otherSerial . "</td>"; $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $compSerial, $otherSerial, $supplierkey); $post = PluginManufacturersimportsPreImport::getSupplierPost($suppliername, $compSerial, $otherSerial); //On complete l url du support du fournisseur avec le serial echo "<td>" . $compSerial . "</td>"; echo "<td>"; echo "<a href='" . $url . "' target='_blank'>" . _n('Manufacturer', 'Manufacturers', 1) . "</a>"; echo "</td>"; $contents = ""; $msgerr = ""; $options = array("url" => $url, "download" => false, "file" => false, "post" => $post, "suppliername" => $suppliername); $contents = self::cURLData($options); $allcontents = $contents; // On extrait la date de garantie de la variable contents. $field = self::selectSupplierfield($suppliername); if ($suppliername != PluginManufacturersimportsConfig::DELL) { $contents = stristr($contents, $field); } if (!$contents === FALSE) { $maDate = self::importDate($suppliername, $contents); if ($suppliername == PluginManufacturersimportsConfig::FUJITSU) { $contents = $allcontents; } $maDateFin = self::importDateFin($suppliername, $contents); } else { self::isInError($type, $ID); } if ($maDateFin != "0000-00-00") { list($adebut, $mdebut, $jdebut) = explode('-', $maDate); list($afin, $mfin, $jfin) = explode('-', $maDateFin); $warranty = 0; $warranty = 12 - $mdebut; for ($year = $adebut + 1; $year < $afin; $year++) { $warranty += 12; } $warranty += $mfin; } if ($maDate != "0000-00-00") { //warranty for life if ($warranty > 120) { $warranty = -1; } $date = date("Y-m-d"); $options = array("itemtype" => $type, "ID" => $ID, "date" => $date, "supplierId" => $supplierId, "warranty" => $warranty, "suppliername" => $suppliername, "addcomments" => $addcomments, "maDate" => $maDate); self::saveInfocoms($options); // on cree un doc dans GLPI qu'on va lier au materiel if ($adddoc != 0 && $suppliername != PluginManufacturersimportsConfig::DELL) { $options = array("itemtype" => $type, "ID" => $ID, "url" => $url, "entities_id" => $line["entities_id"], "rubrique" => $rubrique, "suppliername" => $suppliername); $values["documents_id"] = self::addDocument($options); } //insert base locale $values["import_status"] = 1; $values["items_id"] = $ID; $values["itemtype"] = $type; $values["date_import"] = $date; $log = new PluginManufacturersimportsLog(); $log->add($values); $_SESSION["glpi_plugin_manufacturersimports_total"] += 1; } else { // Failed check contents self::isInError($type, $ID); } echo "</tr>\n"; } }
static function massiveimport($values) { global $DB, $CFG_GLPI; $config = new PluginManufacturersimportsConfig(); $log = new PluginManufacturersimportsLog(); $_SESSION["glpi_plugin_manufacturersimports_total"] = 0; echo "<table class='tab_cadre' width='70%' cellpadding='2'>"; echo "<tr><th colspan='6'>" . __('Post import', 'manufacturersimports') . "</th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; $config->getFromDB($values["manufacturers_id"]); $suppliername = $config->fields["name"]; echo "<th>" . _n('Link', 'Links', 1) . "</th>"; echo "<th>" . __('Result', 'manufacturersimports') . "</th>"; echo "<th>" . __('Details', 'manufacturersimports') . "</th>"; echo "</tr>"; foreach ($values["item"] as $key => $val) { if ($val == 1) { $NotAlreadyImported = $log->checkIfAlreadyImported($values["itemtype"], $key); if (!$NotAlreadyImported) { self::seePostImport($values["itemtype"], $key, $values["to_suppliers_id{$key}"], $values["to_warranty_duration{$key}"], $values["manufacturers_id"]); } } } echo "<tr class='tab_bg_1'><td colspan='6'>"; $total = $_SESSION["glpi_plugin_manufacturersimports_total"]; echo sprintf(__('Total number of devices imported %s', 'manufacturersimports'), $total); echo "</td></tr>"; echo "</table>"; echo "<br><div align='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/manufacturersimports/front/import.php?back=back&itemtype=" . $values["itemtype"] . "&manufacturers_id=" . $values["manufacturers_id"] . "&start=" . $values["start"] . "&imported=" . $values["imported"] . "'>"; echo __('Back'); echo "</a>"; echo "</div>"; }
/** * Prints display pre import * * @param $type the type of device * @param $configID the ID of the supplier config * @param $start for pager display * @param $complete to see all device (already imported and not) * @return nothing (print out a table) * */ static function seePreImport($params) { global $DB, $CFG_GLPI; // Default values of parameters $p['link'] = array(); $p['field'] = array(); $p['contains'] = array(); $p['searchtype'] = array(); $p['sort'] = '1'; $p['order'] = 'ASC'; $p['start'] = 0; $p['export_all'] = 0; $p['link2'] = ''; $p['contains2'] = ''; $p['field2'] = ''; $p['itemtype2'] = ''; $p['searchtype2'] = ''; $p['itemtype'] = ''; $p['manufacturers_id'] = ''; $p['imported'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } $globallinkto = self::getArrayUrlLink("field", $p['field']) . self::getArrayUrlLink("link", $p['link']) . self::getArrayUrlLink("contains", $p['contains']) . self::getArrayUrlLink("searchtype", $p['searchtype']) . self::getArrayUrlLink("field2", $p['field2']) . self::getArrayUrlLink("contains2", $p['contains2']) . self::getArrayUrlLink("searchtype2", $p['searchtype2']) . self::getArrayUrlLink("itemtype2", $p['itemtype2']) . self::getArrayUrlLink("link2", $p['link2']); $modeltable = ""; $target = $CFG_GLPI["root_doc"] . "/plugins/manufacturersimports/front/import.php"; if ($p['itemtype'] && $p['manufacturers_id']) { $config = new PluginManufacturersimportsConfig(); $config->getFromDB($p['manufacturers_id']); $suppliername = $config->fields["name"]; $supplierclass = "PluginManufacturersimports" . $suppliername; $supplier = new $supplierclass(); $infocom = new Infocom(); $canedit = Session::haveRight(static::$rightname, UPDATE) && $infocom->canUpdate(); if (!$p['start']) { $p['start'] = 0; } $modeltable = getTableForItemType($p['itemtype'] . "Model"); $modelfield = getForeignKeyFieldForTable(getTableForItemType($p['itemtype'] . "Model")); $item = new $p['itemtype'](); $itemtable = getTableForItemType($p['itemtype']); $query = "SELECT `" . $itemtable . "`.`id`,\n `" . $itemtable . "`.`name`, \n `" . $itemtable . "`.`serial`,\n `" . $itemtable . "`.`entities_id`,\n `glpi_plugin_manufacturersimports_logs`.`import_status`,\n `glpi_plugin_manufacturersimports_logs`.`items_id`,\n `glpi_plugin_manufacturersimports_logs`.`itemtype`, \n `glpi_plugin_manufacturersimports_logs`.`documents_id`,\n `glpi_plugin_manufacturersimports_logs`.`date_import`, \n '" . $p['itemtype'] . "' AS type,\n `{$modeltable}`.`name` AS model_name\n FROM `" . $itemtable . "` "; //model device left join $query .= "LEFT JOIN `{$modeltable}` ON (`{$modeltable}`.`id` = `" . $itemtable . "`.`" . $modelfield . "`) "; $query .= " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemtable . "`.`entities_id`)"; $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_configs` \n ON (`glpi_plugin_manufacturersimports_configs`.`manufacturers_id` = `" . $itemtable . "`.`manufacturers_id`)"; $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_logs` \n ON (`glpi_plugin_manufacturersimports_logs`.`items_id` = `" . $itemtable . "`.`id` \n AND `glpi_plugin_manufacturersimports_logs`.`itemtype` = '" . $p['itemtype'] . "')"; $query .= " LEFT JOIN `glpi_plugin_manufacturersimports_models` \n ON (`glpi_plugin_manufacturersimports_models`.`items_id` = `" . $itemtable . "`.`id` \n AND `glpi_plugin_manufacturersimports_models`.`itemtype` = '" . $p['itemtype'] . "')"; //serial must be not empty $query .= " WHERE `" . $itemtable . "`.`is_deleted` = '0'\n AND `" . $itemtable . "`.`is_template` = '0'\n AND `glpi_plugin_manufacturersimports_configs`.`id` = '" . $p['manufacturers_id'] . "'\n AND `" . $itemtable . "`.`serial` != '' "; //already imported if ($p['imported'] == self::IMPORTED) { $query .= " AND `import_status` != " . self::IMPORTED . ""; //not imported } else { if ($p['imported'] == self::NOT_IMPORTED) { $query .= " AND (`date_import` IS NULL OR `import_status` = " . self::IMPORTED . " "; $query .= ") "; } } $entities = ""; if ($config->isRecursive()) { $entities = getSonsOf('glpi_entities', $config->getEntityID()); } else { $entities = $config->getEntityID(); } $query .= "" . getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive()); //// 4 - ORDER $ORDER = " ORDER BY `entities_id`,`" . $itemtable . "`.`name` "; $toview = array("name" => 1); foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = self::addOrderBy($p['itemtype'], $p['sort'], $p['order'], $key); } } $query .= $ORDER; $result = $DB->query($query); $numrows = $DB->numrows($result); if ($p['start'] < $numrows) { // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET["display_type"])) { $output_type = $_GET["display_type"]; } $parameters = "itemtype=" . $p['itemtype'] . "&manufacturers_id=" . $p['manufacturers_id'] . "&imported=" . $p['imported']; $total = 0; if ($output_type == Search::HTML_OUTPUT) { self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']); } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $_SESSION["glpilist_limit"]; // Export All case if (isset($_GET['export_all'])) { $begin_display = 0; $end_display = $numrows; } if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //////////////////////HEADER/////////////// if ($output_type == Search::HTML_OUTPUT) { echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"../ajax/massiveaction.php\">"; } //echo Search::displaySearchHeader($output_type,0); //table + div if ($canedit) { $nbcols = 11 + $colsup; } else { $nbcols = 10 + $colsup; } $LIST_LIMIT = $_SESSION['glpilist_limit']; $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) || !$searchopt["PluginManufacturersimportsPreImport"][$val]['nosort']) { $linkto = "{$target}?itemtype=" . $p['itemtype'] . "&manufacturers_id=" . $p['manufacturers_id'] . "&imported=" . $p['imported'] . "&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } } echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); echo Search::showNewLine($output_type); $header_num = 1; echo Search::showHeaderItem($output_type, "", $header_num); echo Search::showHeaderItem($output_type, __('Name'), $header_num, $linkto, $p['sort'] == $val, $p['order']); if (Session::isMultiEntitiesMode()) { echo Search::showHeaderItem($output_type, __('Entity'), $header_num); } echo Search::showHeaderItem($output_type, __('Serial number'), $header_num); echo $supplier->showItemTitle($output_type, $header_num); echo Search::showHeaderItem($output_type, __('Financial and administrative information'), $header_num); echo Search::showHeaderItem($output_type, __('Supplier attached', 'manufacturersimports'), $header_num); echo Search::showHeaderItem($output_type, __('New warranty attached', 'manufacturersimports'), $header_num); echo Search::showHeaderItem($output_type, _n('Link', 'Links', 1), $header_num); echo Search::showHeaderItem($output_type, _n('Status', 'Statuses', 1), $header_num); echo $supplier->showDocTitle($output_type, $header_num); // End Line for column headers echo Search::showEndLine($output_type); $i = $p['start']; if (isset($_GET['export_all'])) { $i = 0; } if ($i > 0) { $DB->data_seek($result, $i); } $row_num = 1; while ($i < $numrows && $i < $end_display) { $i++; $item_num = 1; $line = $DB->fetch_array($result); $compSerial = $line['serial']; $compId = $line['id']; $model = $line["model_name"]; if (!$line["itemtype"]) { $line["itemtype"] = $p['itemtype']; } self::showImport($row_num, $item_num, $line, $output_type, $p['manufacturers_id'], $line["import_status"], $p['imported']); //1.show already imported items && import_status not failed if ($p['imported'] == 1) { $total += 1; } } echo "<tr class='tab_bg_1'><td colspan='" . ($canedit ? 11 + $colsup : 10 + $colsup) . "'>"; echo sprintf(__('Total number of devices to import %s', 'manufacturersimports'), $total); echo "</td></tr>"; // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= PluginManufacturersimportsPreImport::getTypeName(2) . " " . $suppliername; } echo Search::showFooter($output_type, $title); //massive action if ($canedit && $output_type == Search::HTML_OUTPUT) { if ($_SESSION['glpilist_limit'] < Toolbox::get_max_input_vars()) { Html::openArrowMassives("massiveaction_form", false); self::dropdownMassiveAction($compId, $p['itemtype'], $p['manufacturers_id'], $p['start'], $p['imported']); Html::closeArrowMassives(array()); } else { echo "<table class='tab_cadre' width='80%'><tr class='tab_bg_1'>" . "<td><span class='b'>"; echo __('Selection too large, massive action disabled.') . "</span>"; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { echo "<br>" . __('To increase the limit: change max_input_vars or suhosin.post.max_vars in php configuration.'); } echo "</td></tr></table>"; } Html::closeForm(); } else { echo "</table>"; echo "</div>"; } echo "<br>"; if ($output_type == Search::HTML_OUTPUT) { self::printPager($p['start'], $numrows, $target, $parameters, $p['itemtype']); } } else { echo "<div align='center'><b>" . __('No device finded', 'manufacturersimports') . "</b></div>"; } } }