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";
     }
 }
 /**
  * Update model for HP for suppliertag plugin
  *
  * @param $items_id integer id of the computer
  * @param $partnumber value HP partnumber
  *
  * @return nothing
  *
  **/
 function Suppliertag($items_id, $partnumber)
 {
     if ($partnumber != 'Not Specified') {
         $a_partnumber = explode("#", $partnumber);
         $Plugin = new Plugin();
         if ($Plugin->isActivated('manufacturersimports')) {
             if (class_exists("PluginManufacturersimportsModel")) {
                 $PluginManufacturersimportsModel = new PluginManufacturersimportsModel();
                 $PluginManufacturersimportsModel->addModel(array('items_id' => $items_id, 'itemtype' => 'Computer', 'model_name' => $a_partnumber[0]));
             }
         }
     }
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case "add_model":
             $model = new PluginManufacturersimportsModel();
             $input = $ma->getInput();
             foreach ($ma->items as $itemtype => $myitem) {
                 foreach ($myitem as $key => $value) {
                     $input = array('model_name' => $ma->POST['model_name'], 'items_id' => $key, 'itemtype' => $itemtype);
                     if ($model->addModel($input)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             break;
     }
 }
 /**
  * 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>";
     }
 }
 static function showImport($row_num, $item_num, $line, $output_type, $configID, $status, $imported)
 {
     global $DB, $CFG_GLPI;
     $infocom = new Infocom();
     $canedit = Session::haveRight(static::$rightname, UPDATE) && $infocom->canUpdate();
     $config = new PluginManufacturersimportsConfig();
     $config->getFromDB($configID);
     $suppliername = $config->fields["name"];
     $supplierUrl = $config->fields["supplier_url"];
     $supplierId = $config->fields["suppliers_id"];
     $supplierWarranty = $config->fields["warranty_duration"];
     $supplierkey = $config->fields["supplier_key"];
     $supplierclass = "PluginManufacturersimports" . $suppliername;
     $supplier = new $supplierclass();
     $row_num++;
     if ($suppliername) {
         $model = new PluginManufacturersimportsModel();
         $otherSerial = $model->checkIfModelNeeds($line["itemtype"], $line["id"]);
         echo Search::showNewLine($output_type, $row_num % 2);
         $ic = new Infocom();
         $output_check = "";
         if ($canedit && $output_type == Search::HTML_OUTPUT) {
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             $output_check = $supplier->showCheckbox($line["id"], $sel, $otherSerial);
         }
         echo Search::showItem($output_type, $output_check, $item_num, $row_num);
         $link = Toolbox::getItemTypeFormURL($line["itemtype"]);
         $ID = "";
         if ($_SESSION["glpiis_ids_visible"] || empty($line["name"])) {
             $ID .= " (" . $line["id"] . ")";
         }
         $output_link = "<a href='" . $link . "?id=" . $line["id"] . "'>" . $line["name"] . $ID . "</a><br>" . $line["model_name"];
         echo Search::showItem($output_type, $output_link, $item_num, $row_num);
         if (Session::isMultiEntitiesMode()) {
             echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_entities", $line['entities_id']), $item_num, $row_num);
         }
         $url = self::selectSupplier($suppliername, $line["serial"], $otherSerial, $supplierkey);
         //serial
         echo Search::showItem($output_type, $line["serial"], $item_num, $row_num);
         //otherserial
         echo $supplier->showItem($output_type, $otherSerial, $item_num, $row_num);
         //display infocoms
         $output_ic = "";
         if ($ic->getfromDBforDevice($line["itemtype"], $line["id"])) {
             $output_ic .= _n('Supplier', 'Suppliers', 1) . ":" . Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]) . "<br>";
             $output_ic .= __('Date of purchase') . " : " . Html::convdate($ic->fields["buy_date"]) . "<br>";
             $output_ic .= __('Start date of warranty') . ":" . Html::convdate($ic->fields["warranty_date"]) . "<br>";
             if ($ic->fields["warranty_duration"] == -1) {
                 $output_ic .= __('Warranty duration') . ":" . __('Lifelong') . "<br>";
             } else {
                 $output_ic .= __('Warranty duration') . ":" . $ic->fields["warranty_duration"] . " " . __('month') . "<br>";
             }
             $tmpdat = Infocom::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"]);
             $output_ic .= sprintf(__('Valid to %s'), $tmpdat);
         } else {
             $output_ic .= "";
         }
         echo Search::showItem($output_type, $output_ic, $item_num, $row_num);
         if ($imported != self::IMPORTED) {
             //display enterprise and warranty selection
             echo "<td>";
             if (Session::isMultiEntitiesMode() && $supplierId) {
                 $item = new Supplier();
                 $item->getFromDB($supplierId);
                 if ($item->fields["is_recursive"] || $item->fields["entities_id"] == $line['entities_id']) {
                     Dropdown::show('Supplier', array('name' => "to_suppliers_id" . $line["id"], 'value' => $supplierId, 'comments' => 0, 'entity' => $line['entities_id']));
                 } else {
                     echo "<span class='plugin_manufacturersimports_import_KO'>";
                     echo __('The choosen supplier is not recursive', 'manufacturersimports') . "</span>";
                     echo "<input type='hidden' name='to_suppliers_id" . $line["id"] . "' value='-1'>";
                 }
             } else {
                 Dropdown::show('Supplier', array('name' => "to_suppliers_id" . $line["id"], 'value' => $supplierId, 'comments' => 0, 'entity' => $line['entities_id']));
             }
             echo "</td>";
             $supplier->showWarrantyItem($line["id"], $supplierWarranty);
         } else {
             //display enterprise and warranty selection
             echo "<td>" . Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]) . "</td>";
             if ($ic->fields["warranty_duration"] == -1) {
                 echo "<td>" . __('Lifelong') . "</td>";
             } else {
                 echo "<td>" . $ic->fields["warranty_duration"] . "</td>";
             }
         }
         //supplier url
         //url to supplier
         $output_url = "<a href='" . $url . "' target='_blank'>" . __('Manufacturer information', 'manufacturersimports') . "</a>";
         echo Search::showItem($output_type, $output_url, $item_num, $row_num);
         //status
         if ($imported != self::IMPORTED) {
             if ($status != 2) {
                 $output_doc = __('Not yet imported', 'manufacturersimports');
             } else {
                 $output_doc = "<span class='plugin_manufacturersimports_import_KO'>" . __('Problem during the importation', 'manufacturersimports');
                 if (!empty($data["date_import"])) {
                     $output_doc .= " (" . Html::convdate($data["date_import"]) . ")";
                 }
                 $output_doc .= "</span>";
             }
         } else {
             $output_doc = "<span class='plugin_manufacturersimports_import_OK'>" . __('Already imported', 'manufacturersimports');
             if (!empty($line["date_import"])) {
                 $output_doc .= " (" . Html::convdate($line["date_import"]) . ")";
             }
             $output_doc .= "</span>";
         }
         echo Search::showItem($output_type, $output_doc, $item_num, $row_num);
         //no associated doc
         echo $supplier->showDocItem($output_type, $item_num, $row_num, $line["documents_id"]);
     }
 }
Esempio n. 6
0
function plugin_manufacturersimports_MassiveActionsProcess($data)
{
    $model = new PluginManufacturersimportsModel();
    $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
    switch ($data['action']) {
        case "plugin_manufacturersimports_add_model":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    $input = array('model_name' => $data['model_name'], 'items_id' => $key, 'itemtype' => $data['itemtype']);
                    if ($model->addModel($input)) {
                        $res['ok']++;
                    } else {
                        $res['ko']++;
                    }
                }
            }
            break;
    }
    return $res;
}
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Manufacturersimports. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
if (!isset($_GET["id"])) {
    $_GET["id"] = 0;
}
if (!isset($_GET["preconfig"])) {
    $_GET["preconfig"] = -1;
}
$config = new PluginManufacturersimportsConfig();
$model = new PluginManufacturersimportsModel();
if (isset($_POST["add"])) {
    Session::checkRight("plugin_manufacturersimports", CREATE);
    $config->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        Session::checkRight("plugin_manufacturersimports", UPDATE);
        $config->update($_POST);
        Html::back();
    } else {
        if (isset($_POST["delete"])) {
            Session::checkRight("plugin_manufacturersimports", PURGE);
            $config->delete($_POST, true);
            Html::redirect("./config.form.php");
        } else {
Esempio n. 8
0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Manufacturersimports. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
if (!isset($_GET["id"])) {
    $_GET["id"] = 0;
}
if (!isset($_GET["preconfig"])) {
    $_GET["preconfig"] = -1;
}
$config = new PluginManufacturersimportsConfig();
$model = new PluginManufacturersimportsModel();
if (isset($_POST["add"])) {
    Session::checkRight("config", "w");
    $newID = $config->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        Session::checkRight("config", "w");
        $config->update($_POST);
        Html::back();
    } else {
        if (isset($_POST["delete"])) {
            Session::checkRight("config", "w");
            $config->delete($_POST, 1);
            Html::redirect("./config.form.php");
        } else {