Ejemplo 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";
     }
 }
 /**
  * Prints the url to manufacturer informations on items
  *
  * @param $device the device ID
  * @param $type the device type
  * @return nothing (print out a table)
  *
  */
 static function showInformationsForm($itemtype, $items_id)
 {
     global $DB, $CFG_GLPI;
     $item = new $itemtype();
     if ($item->getFromDB($items_id)) {
         $suppliername = PluginManufacturersimportsConfig::checkManufacturerName($itemtype, $items_id);
         $model = new PluginManufacturersimportsModel();
         $otherserial = $model->checkIfModelNeeds($itemtype, $items_id);
         $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $item->fields['serial'], $otherserial);
         echo "<div align=\"center\"><table class=\"tab_cadre_fixe\"  cellspacing=\"2\" cellpadding=\"2\">";
         echo "<tr>";
         echo "<th colspan='2'>" . PluginManufacturersimportsPreImport::getTypeName(2) . "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>";
         echo _n('Link', 'Links', 1);
         echo "</td>";
         echo "<td>";
         echo "<a href='" . $url . "' target='_blank'>" . __('Manufacturer information', 'manufacturersimports') . "</a>";
         echo "</td></tr>";
         echo "</table></div>";
     }
 }