Esempio n. 1
0
 /**
  * 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"];
     $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);
         //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, "suppliername" => $suppliername);
         $contents = self::cURLData($options);
         // On extrait la date de garantie de la variable contents.
         $field = self::selectSupplierfield($suppliername);
         if ($suppliername == "Dell" || $suppliername != "Dell" && !stristr($contents, $field) === FALSE) {
             if ($suppliername != "Dell") {
                 $finduhtml = stristr($contents, $field);
             } else {
                 $finduhtml = $compSerial;
                 $contents = $compSerial;
             }
             $maDate = self::importDate($suppliername, $finduhtml);
             $warranty = self::importWarranty($suppliername, $maDate, $contents, $warranty);
             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 != "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 date
                 self::isInError($type, $ID, $contents);
             }
         } else {
             // Failed checj contents
             self::isInError($type, $ID);
         }
         echo "</tr>\n";
     }
 }
Esempio n. 2
0
 /**
  * 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 = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("searchtype", $p['searchtype']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("searchtype2", $p['searchtype2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::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 = plugin_manufacturersimports_haveRight("manufacturersimports", "w") && $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'] . "&amp;manufacturers_id=" . $p['manufacturers_id'] . "&amp;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'] . "&amp;manufacturers_id=" . $p['manufacturers_id'] . "&amp;imported=" . $p['imported'] . "&amp;sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;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, __('Entity'), $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) {
                 Html::openArrowMassives("massiveaction_form", false);
                 self::dropdownMassiveAction($compId, $p['itemtype'], $p['manufacturers_id'], $p['start'], $p['imported']);
                 Html::closeArrowMassives(array());
                 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>";
         }
     }
 }