";
-
- $this->initForm($ID, $options);
- $this->showFormHeader($options);
-
- echo "
";
- } else {
- echo Html::hidden('warranty_duration', ['value' => 0]);
- }
- if ($this->fields["name"] == self::HP) {
-
- echo "
";
-
- return true;
- }
-
- /**
- * For other plugins, add a type to the linkable types
- *
- * @param $type string class name
- **@since version 1.5.0
- *
- */
- static function registerType($type) {
- if (!in_array($type, self::$types)) {
- self::$types[] = $type;
- }
- }
-
-
- /**
- * Type than could be linked to a Rack
- *
- * @param $all boolean, all type, or only allowed ones
- *
- * @return array of types
- **/
- static function getTypes($all = false) {
-
- if ($all) {
- return self::$types;
- }
-
- // Only allowed types
- $types = self::$types;
-
- foreach ($types as $key => $itemtype) {
- if (!class_exists($itemtype)) {
- continue;
- }
-
- if (!$itemtype::canView()) {
- unset($types[$key]);
- }
- }
- return $types;
- }
-
- static function checkManufacturerName($itemtype, $items_id) {
-
- $item = new $itemtype();
- $name = false;
-
- if ($item->getFromDB($items_id)) {
- $dbu = new DbUtils();
- $configs = $dbu->getAllDataFromTable("glpi_plugin_manufacturersimports_configs");
- if (!empty($configs)) {
- foreach ($configs as $config) {
- if ($item->fields["manufacturers_id"] == $config['manufacturers_id']) {
- $name = $config["name"];
- }
+ $dbu->getEntitiesRestrictRequest(
+ 'AND',
+ $this->getTable(),
+ '',
+ $dbu->getSonsOf(
+ "glpi_entities",
+ $this->fields["entities_id"]
+ )
+ );
+ $DB->query($query);
+ }
+ }
+
+ public static function dropdownSupplier($name, $options = [])
+ {
+ $params['value'] = 0;
+ $params['toadd'] = [];
+ $params['on_change'] = '';
+
+ if (is_array($options) && count($options)) {
+ foreach ($options as $key => $val) {
+ $params[$key] = $val;
}
- }
- }
- return $name;
- }
-
- static function checkManufacturerID($itemtype, $items_id) {
-
- $item = new $itemtype();
- $id = false;
-
- if ($item->getFromDB($items_id)) {
- $dbu = new DbUtils();
- $configs = $dbu->getAllDataFromTable("glpi_plugin_manufacturersimports_configs");
- if (!empty($configs)) {
- foreach ($configs as $config) {
- if ($item->fields["manufacturers_id"] == $config['manufacturers_id']) {
- $id = $config["id"];
- }
+ }
+
+ $items = [];
+ if (count($params['toadd']) > 0) {
+ $items = $params['toadd'];
+ }
+
+ $items += self::getSuppliers();
+ return Dropdown::showFromArray($name, $items, $params);
+ }
+
+ public static function getSuppliers()
+ {
+ $options[-1] = Dropdown::EMPTY_VALUE;
+ $options[self::DELL] = self::DELL;
+ $options[self::HP] = self::HP;
+ $options[self::FUJITSU] = self::FUJITSU;
+ $options[self::TOSHIBA] = self::TOSHIBA;
+ $options[self::LENOVO] = self::LENOVO;
+ $options[self::WORTMANN_AG] = self::WORTMANN_AG;
+ return $options;
+ }
+
+ /**
+ * Provides search options configuration. Do not rely directly
+ * on this, @return array a *not indexed* array of search options
+ *
+ * @since 9.3
+ *
+ * This should be overloaded in Class
+ *
+ * @see CommonDBTM::searchOptions instead.
+ *
+ * @see https://glpi-developer-documentation.rtfd.io/en/master/devapi/search.html
+ **/
+ public function rawSearchOptions()
+ {
+ $tab = parent::rawSearchOptions();
+
+ $tab[] = [
+ 'id' => '2',
+ 'table' => 'glpi_manufacturers',
+ 'field' => 'name',
+ 'name' => __('Manufacturer'),
+ 'datatype' => 'dropdown',
+ 'massiveaction' => false
+ ];
+
+ $tab[] = [
+ 'id' => '3',
+ 'table' => $this->getTable(),
+ 'field' => 'supplier_url',
+ 'name' => __('Manufacturer web address', 'manufacturersimports'),
+ 'datatype' => 'weblink',
+ 'massiveaction' => false
+ ];
+
+ $tab[] = [
+ 'id' => '4',
+ 'table' => 'glpi_suppliers',
+ 'field' => 'name',
+ 'name' => __('Default supplier attached', 'manufacturersimports'),
+ 'datatype' => 'dropdown'
+ ];
+
+ $tab[] = [
+ 'id' => '5',
+ 'table' => $this->getTable(),
+ 'field' => 'warranty_duration',
+ 'name' => __('New warranty attached', 'manufacturersimports'),
+ 'datatype' => 'integer',
+ 'massiveaction' => false
+ ];
+
+ $tab[] = [
+ 'id' => '6',
+ 'table' => $this->getTable(),
+ 'field' => 'document_adding',
+ 'name' => __('Auto add of document', 'manufacturersimports'),
+ 'datatype' => 'bool',
+ 'massiveaction' => false
+ ];
+
+ $tab[] = [
+ 'id' => '7',
+ 'table' => 'glpi_documentcategories',
+ 'field' => 'name',
+ 'name' => __('Document heading'),
+ 'massiveaction' => false
+ ];
+
+ $tab[] = [
+ 'id' => '8',
+ 'table' => $this->getTable(),
+ 'field' => 'comment_adding',
+ 'name' => __('Add a comment line', 'manufacturersimports'),
+ 'datatype' => 'bool'
+ ];
+
+ $tab[] = [
+ 'id' => '30',
+ 'table' => $this->getTable(),
+ 'field' => 'id',
+ 'name' => __('ID')
+ ];
+
+ $tab[] = [
+ 'id' => '80',
+ 'table' => 'glpi_entities',
+ 'field' => 'completename',
+ 'name' => __('Entity'),
+ 'datatype' => 'dropdown'
+ ];
+
+ return $tab;
+ }
+
+ public function showForm($ID, $options = [])
+ {
+ if (!$this->canView()) {
+ return false;
+ }
+
+ if ($ID > 0) {
+ $this->check($ID, READ);
+ } else {
+ $this->check(-1, UPDATE);
+ $this->getEmpty();
+ if (isset($_GET['preconfig'])) {
+ $this->preconfig($_GET['preconfig']);
+ } else {
+ $_GET['preconfig'] = -1;
}
- }
- }
- return $id;
- }
+ }
+
+ echo "
";
+
+ if ($_GET['preconfig'] == -1 && $ID <= 0) {
+ $style = "style='display:none;'";
+ } else {
+ $style = "style='display:block;'";
+ }
+ echo "
";
+
+ $this->initForm($ID, $options);
+ $this->showFormHeader($options);
+
+ echo "
";
+ echo "" . __('Name') . " | ";
+ echo "";
+ echo $this->fields["name"];
+ echo Html::hidden('name', ['value' => $this->fields["name"]]);
+ echo " | ";
+
+ echo "" . __('Manufacturer') . " | ";
+ echo "";
+ Dropdown::show(
+ 'Manufacturer',
+ ['name' => "manufacturers_id",
+ 'value' => $this->fields["manufacturers_id"]]
+ );
+ echo " | ";
+ echo "
";
+
+ echo "
";
+ echo "" . __('Manufacturer web address', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('supplier_url', ['value' => $this->fields["supplier_url"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+
+ if ($this->fields["name"] == self::DELL) {
+ echo "
";
+ echo "" . __('Access token API address', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('token_url', ['value' => $this->fields["token_url"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+ echo "
";
+ echo "" . __('Warranty API address', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('warranty_url', ['value' => $this->fields["warranty_url"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+ }
+
+ echo "
";
+ echo "" . __('Default supplier attached', 'manufacturersimports') . " | ";
+ echo "";
+ Dropdown::show('Supplier', ['name' => "suppliers_id",
+ 'value' => $this->fields["suppliers_id"]]);
+ echo " | ";
+ echo "
";
+
+ if ($this->fields["name"] == self::FUJITSU) {
+ echo "
";
+ echo "" .
+ __(
+ 'New warranty affected by default (Replace if 0)',
+ 'manufacturersimports'
+ ) . " | ";
+ echo "";
+ Dropdown::showNumber("warranty_duration", ['value' => $this->fields["warranty_duration"],
+ 'min' => 0,
+ 'max' => 120]);
+ echo " | ";
+ echo "
";
+ } else {
+ echo Html::hidden('warranty_duration', ['value' => 0]);
+ }
+ if ($this->fields["name"] == self::HP) {
+ echo "
";
+ echo "" . __('Manufacturer API key', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('supplier_key', ['value' => $this->fields["supplier_key"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+
+ echo "
";
+ echo "" . __('Manufacturer API Secret', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('supplier_secret', ['value' => $this->fields["supplier_secret"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+ } elseif ($this->fields["name"] == self::DELL) {
+ echo "
";
+ echo "" . __('Client id', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('supplier_key', ['value' => $this->fields["supplier_key"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+ echo "
";
+ echo "" . __('Client secret', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('supplier_secret', ['value' => $this->fields["supplier_secret"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+ } elseif ($this->fields["name"] == self::LENOVO) {
+ echo "
";
+ echo "" . __('Client id', 'manufacturersimports') . " | ";
+ echo "";
+ echo Html::input('supplier_key', ['value' => $this->fields["supplier_key"], 'size' => 100]);
+ echo " | ";
+ echo "
";
+ } else {
+ echo "
";
+ echo "" . __('Auto add of document', 'manufacturersimports') . " | ";
+ echo "";
+ Dropdown::showYesNo("document_adding", $this->fields["document_adding"]);
+ echo " | ";
+ echo "
";
+
+ echo "
";
+ echo "" . __('Section for document records', 'manufacturersimports') . " | ";
+ echo "";
+ Dropdown::show('DocumentCategory', ['name' => "documentcategories_id",
+ 'value' => $this->fields["documentcategories_id"]]);
+ echo " | ";
+ echo "
";
+ }
+ echo "
";
+ echo "" . __('Add a comment line', 'manufacturersimports') . " | ";
+ echo "";
+ Dropdown::showYesNo("comment_adding", $this->fields["comment_adding"]);
+ echo " | ";
+ echo "
";
+
+ $this->showFormButtons($options);
+
+ echo "
";
+
+ return true;
+ }
+
+ /**
+ * For other plugins, add a type to the linkable types
+ *
+ * @param $type string class name
+ **@since version 1.5.0
+ *
+ */
+ public static function registerType($type)
+ {
+ if (!in_array($type, self::$types)) {
+ self::$types[] = $type;
+ }
+ }
+
+
+ /**
+ * Type than could be linked to a Rack
+ *
+ * @param $all boolean, all type, or only allowed ones
+ *
+ * @return array of types
+ **/
+ public static function getTypes($all = false)
+ {
+ if ($all) {
+ return self::$types;
+ }
+
+ // Only allowed types
+ $types = self::$types;
+
+ foreach ($types as $key => $itemtype) {
+ if (!class_exists($itemtype)) {
+ continue;
+ }
+
+ if (!$itemtype::canView()) {
+ unset($types[$key]);
+ }
+ }
+ return $types;
+ }
+
+ public static function checkManufacturerName($itemtype, $items_id)
+ {
+ $item = new $itemtype();
+ $name = false;
+
+ if ($item->getFromDB($items_id)) {
+ $dbu = new DbUtils();
+ $configs = $dbu->getAllDataFromTable("glpi_plugin_manufacturersimports_configs");
+ if (!empty($configs)) {
+ foreach ($configs as $config) {
+ if ($item->fields["manufacturers_id"] == $config['manufacturers_id']) {
+ $name = $config["name"];
+ }
+ }
+ }
+ }
+ return $name;
+ }
+
+ public static function checkManufacturerID($itemtype, $items_id)
+ {
+ $item = new $itemtype();
+ $id = false;
+
+ if ($item->getFromDB($items_id)) {
+ $dbu = new DbUtils();
+ $configs = $dbu->getAllDataFromTable("glpi_plugin_manufacturersimports_configs");
+ if (!empty($configs)) {
+ foreach ($configs as $config) {
+ if ($item->fields["manufacturers_id"] == $config['manufacturers_id']) {
+ $id = $config["id"];
+ }
+ }
+ }
+ }
+ return $id;
+ }
// }
- //Massive action
- function getSpecificMassiveActions($checkitem = null) {
- $isadmin = static::canUpdate();
- $actions = parent::getSpecificMassiveActions($checkitem);
-
- if ($isadmin) {
- if (Session::haveRight('transfer', READ)
- && Session::isMultiEntitiesMode()) {
- $actions['Transfert'] = __('Transfer');
- }
- }
-
- return $actions;
- }
-
- function showSpecificMassiveActionsParameters($input = []) {
-
- switch ($input['action']) {
- case "Transfert" :
- Dropdown::show('Entity');
- echo Html::submit(_sx('button', 'Post'), ['name' => 'massiveaction', 'class' => 'btn btn-primary']);
- return true;
- break;
-
- default :
- return parent::showSpecificMassiveActionsParameters($input);
- break;
- }
- return false;
- }
-
- function doSpecificMassiveActions($input = []) {
-
- $res = ['ok' => 0, 'ko' => 0, 'noright' => 0];
-
- switch ($input['action']) {
- case "Transfert" :
-
- if ($input['itemtype'] == 'PluginManufacturersimportsConfig') {
- foreach ($input["item"] as $key => $val) {
- if ($val == 1) {
-
- $values["id"] = $key;
- $values["entities_id"] = $input['entities_id'];
- if ($this->update($values)) {
- $res['ok']++;
- } else {
- $res['ko']++;
- }
- }
- }
+ //Massive action
+ public function getSpecificMassiveActions($checkitem = null)
+ {
+ $isadmin = static::canUpdate();
+ $actions = parent::getSpecificMassiveActions($checkitem);
+
+ if ($isadmin) {
+ if (Session::haveRight('transfer', READ)
+ && Session::isMultiEntitiesMode()) {
+ $actions['Transfert'] = __('Transfer');
+ }
+ }
+
+ return $actions;
+ }
+
+ public function showSpecificMassiveActionsParameters($input = [])
+ {
+ switch ($input['action']) {
+ case "Transfert":
+ Dropdown::show('Entity');
+ echo Html::submit(_sx('button', 'Post'), ['name' => 'massiveaction', 'class' => 'btn btn-primary']);
+ return true;
+ break;
+
+ default:
+ return parent::showSpecificMassiveActionsParameters($input);
+ break;
+ }
+ return false;
+ }
+
+ public function doSpecificMassiveActions($input = [])
+ {
+ $res = ['ok' => 0, 'ko' => 0, 'noright' => 0];
+
+ switch ($input['action']) {
+ case "Transfert":
+
+ if ($input['itemtype'] == 'PluginManufacturersimportsConfig') {
+ foreach ($input["item"] as $key => $val) {
+ if ($val == 1) {
+ $values["id"] = $key;
+ $values["entities_id"] = $input['entities_id'];
+ if ($this->update($values)) {
+ $res['ok']++;
+ } else {
+ $res['ko']++;
+ }
+ }
+ }
+ }
+ break;
+ default:
+ return parent::doSpecificMassiveActions($input);
+ break;
+ }
+ return $res;
+ }
+
+ /**
+ * Display the current tag dropdown in form header of items
+ *
+ * @param item the CommonDBTM object
+ *
+ * @return nothing
+ */
+ public static function showForInfocom($item)
+ {
+ if (in_array($item->getType(), self::getTypes(true))) {
+ $suppliername = PluginManufacturersimportsConfig::checkManufacturerName($item->getType(), $item->getID());
+
+ $model = new PluginManufacturersimportsModel();
+ $otherserial = $model->checkIfModelNeeds($item->getType(), $item->getID());
+
+ $configID = PluginManufacturersimportsConfig::checkManufacturerID($item->getType(), $item->getID());
+ $config = new PluginManufacturersimportsConfig();
+ $config->getFromDB($configID);
+ $supplierkey = (isset($config->fields["supplier_key"])) ? $config->fields["supplier_key"] : false;
+ $supplierurl = (isset($config->fields["supplier_url"])) ? $config->fields["supplier_url"] : false;
+
+ if ($suppliername == PluginManufacturersimportsConfig::LENOVO) {
+ $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $supplierurl, $item->fields['serial'], $otherserial, $supplierkey, null, true);
+ } else {
+ $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $supplierurl, $item->fields['serial'], $otherserial, $supplierkey);
+ }
+ echo "
";
+ echo "";
+ echo "" . PluginManufacturersimportsPreImport::getTypeName(2) . " | ";
+ echo "
";
+
+ echo "";
+ echo "";
+ echo _n('Link', 'Links', 1);
+ echo " | ";
+ echo "";
+ echo "" . __('Manufacturer information', 'manufacturersimports') . "";
+ echo " | ";
+ echo "";
+ $target = PluginManufacturersimportsConfig::getFormUrl(true);
+ Html::showSimpleForm(
+ $target,
+ 'retrieve_warranty',
+ _sx('button', 'Retrieve warranty from manufacturer', 'manufacturersimports'),
+ ['itemtype' => $item->getType(),
+ 'items_id' => $item->getID()]
+ );
+ echo " | ";
+ echo "
";
+ echo "
";
+ }
+ return $item;
+ }
+
+ public static function retrieveOneWarranty($itemtype, $items_id)
+ {
+ $item = new $itemtype();
+ if ($item->getFromDB($items_id)) {
+ $log = new PluginManufacturersimportsLog();
+ $log->reinitializeImport($itemtype, $items_id);
+
+ $config = new PluginManufacturersimportsConfig();
+ $suppliername = PluginManufacturersimportsConfig::checkManufacturerName($itemtype, $items_id);
+ $config->getFromDBByCrit(['name' => $suppliername]);
+ $suppliername = $config->fields["name"];
+ $supplierUrl = $config->fields["supplier_url"];
+ $supplierkey = $config->fields["supplier_key"];
+
+ $url = PluginManufacturersimportsPreImport::selectSupplier(
+ $suppliername,
+ $supplierUrl,
+ $item->fields['serial'],
+ $item->fields['otherserial'],
+ $supplierkey
+ );
+
+ $post = PluginManufacturersimportsPreImport::getSupplierPost(
+ $suppliername,
+ $item->fields['serial'],
+ $item->fields['otherserial']
+ );
+
+ $data = [];
+ $options = ["url" => $url,
+ "post" => $post,
+ "type" => $itemtype,
+ "ID" => $items_id,
+ "config" => $config,
+ "line" => $data,
+ "display" => false];
+
+
+ $supplierclass = "PluginManufacturersimports" . $suppliername;
+ $token = $supplierclass::getToken($config);
+ $warranty_url = $supplierclass::getWarrantyUrl($config, $item->fields['serial']);
+ $options['token'] = $token;
+ $options['line']['entities_id'] = $item->fields['entities_id'];
+ if (isset($warranty_url['url'])) {
+ $options['url'] = $warranty_url['url'];
+ }
+ if (
+ isset($_SESSION['glpi_use_mode'])
+ && ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE)
+ ) {
+ Toolbox::loginfo($options);
}
- break;
- default :
- return parent::doSpecificMassiveActions($input);
- break;
- }
- return $res;
- }
-
- /**
- * Display the current tag dropdown in form header of items
- *
- * @param item the CommonDBTM object
- *
- * @return nothing
- */
- public static function showForInfocom($item) {
-
- if (in_array($item->getType(), self::getTypes(true))) {
-
- $suppliername = PluginManufacturersimportsConfig::checkManufacturerName($item->getType(), $item->getID());
-
- $model = new PluginManufacturersimportsModel();
- $otherserial = $model->checkIfModelNeeds($item->getType(), $item->getID());
-
- $configID = PluginManufacturersimportsConfig::checkManufacturerID($item->getType(), $item->getID());
- $config = new PluginManufacturersimportsConfig();
- $config->getFromDB($configID);
- $supplierkey = (isset($config->fields["supplier_key"])) ? $config->fields["supplier_key"] : false;
- $supplierurl = (isset($config->fields["supplier_url"])) ? $config->fields["supplier_url"] : false;
-
- if ($suppliername == PluginManufacturersimportsConfig::LENOVO) {
- $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $supplierurl, $item->fields['serial'], $otherserial, $supplierkey, null, true);
- } else {
- $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $supplierurl, $item->fields['serial'], $otherserial, $supplierkey);
- }
- echo "
";
- echo "";
- echo "" . PluginManufacturersimportsPreImport::getTypeName(2) . " | ";
- echo "
";
-
- echo "";
- echo "";
- echo _n('Link', 'Links', 1);
- echo " | ";
- echo "";
- echo "" . __('Manufacturer information', 'manufacturersimports') . "";
- echo " | ";
- echo "";
- $target = PluginManufacturersimportsConfig::getFormUrl(true);
- Html::showSimpleForm($target, 'retrieve_warranty',
- _sx('button', 'Retrieve warranty from manufacturer', 'manufacturersimports'),
- ['itemtype' => $item->getType(),
- 'items_id' => $item->getID()]
- );
- echo " | ";
- echo "
";
- echo "
";
- }
- return $item;
- }
-
- static function retrieveOneWarranty($itemtype, $items_id) {
-
- $item = new $itemtype();
- if ($item->getFromDB($items_id)) {
-
- $log = new PluginManufacturersimportsLog();
- $log->reinitializeImport($itemtype, $items_id);
-
- $config = new PluginManufacturersimportsConfig();
- $suppliername = PluginManufacturersimportsConfig::checkManufacturerName($itemtype, $items_id);
- $config->getFromDBByCrit(['name' => $suppliername]);
- $suppliername = $config->fields["name"];
- $supplierUrl = $config->fields["supplier_url"];
- $supplierkey = $config->fields["supplier_key"];
-
- $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $supplierUrl,
- $item->fields['serial'], $item->fields['otherserial'], $supplierkey);
-
- $post = PluginManufacturersimportsPreImport::getSupplierPost($suppliername, $item->fields['serial'],
- $item->fields['otherserial']);
-
- $data = [];
- $options = ["url" => $url,
- "post" => $post,
- "type" => $itemtype,
- "ID" => $items_id,
- "config" => $config,
- "line" => $data,
- "display" => false];
-
-
- $supplierclass = "PluginManufacturersimports" . $suppliername;
- $token = $supplierclass::getToken($config);
- $warranty_url = $supplierclass::getWarrantyUrl($config, $item->fields['serial']);
- $options['token'] = $token;
- $options['line']['entities_id'] = $item->fields['entities_id'];
- if (isset($warranty_url['url'])) {
- $options['url'] = $warranty_url['url'];
- }
- if (
- isset($_SESSION['glpi_use_mode'])
- && ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE)
- ) {
- Toolbox::loginfo($options);
- }
- PluginManufacturersimportsPostImport::saveImport($options);
- }
- }
-
- public static function showItemImport($params) {
- $item = $params['item'];
-
- if ($item && in_array($item->getType(), self::getTypes(true))) {
-
- $config = new self();
- $log = new PluginManufacturersimportsLog();
-
- $suppliername = PluginManufacturersimportsConfig::checkManufacturerName($item->getType(), $item->getID());
- if (!empty($suppliername) && !empty($item->fields['serial'])) {
- $NotAlreadyImported = $log->checkIfAlreadyImported($item->getType(), $item->getID());
- if (!$NotAlreadyImported) {
- echo "
";
- echo __("You did not import the warranty for this item. Do you want to get it back?", "manufacturersimports");
- $target = PluginManufacturersimportsConfig::getFormUrl(true);
- echo " ";
- Html::showSimpleForm($target, 'retrieve_warranty',
- _sx('button', 'Retrieve warranty from manufacturer', 'manufacturersimports'),
- ['itemtype' => $item->getType(),
- 'items_id' => $item->getID()],
- 'fa-2x fa-cloud-download-alt');
- echo "
";
+ PluginManufacturersimportsPostImport::saveImport($options);
+ }
+ }
+
+ public static function showItemImport($params)
+ {
+ $item = $params['item'];
+
+ if ($item && in_array($item->getType(), self::getTypes(true))) {
+ $config = new self();
+ $log = new PluginManufacturersimportsLog();
+
+ $suppliername = PluginManufacturersimportsConfig::checkManufacturerName($item->getType(), $item->getID());
+ if (!empty($suppliername) && !empty($item->fields['serial'])) {
+ $NotAlreadyImported = $log->checkIfAlreadyImported($item->getType(), $item->getID());
+ if (!$NotAlreadyImported) {
+ echo "
";
+ echo __("You did not import the warranty for this item. Do you want to get it back?", "manufacturersimports");
+ $target = PluginManufacturersimportsConfig::getFormUrl(true);
+ echo " ";
+ Html::showSimpleForm(
+ $target,
+ 'retrieve_warranty',
+ _sx('button', 'Retrieve warranty from manufacturer', 'manufacturersimports'),
+ ['itemtype' => $item->getType(),
+ 'items_id' => $item->getID()],
+ 'fa-2x fa-cloud-download-alt'
+ );
+ echo "
";
+ }
}
- }
- }
- }
+ }
+ }
}
diff --git a/inc/dell.class.php b/inc/dell.class.php
index f65b5fd..5d6f7c0 100644
--- a/inc/dell.class.php
+++ b/inc/dell.class.php
@@ -28,7 +28,7 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
ini_set("max_execution_time", "0");
@@ -36,227 +36,244 @@
/**
* Class PluginManufacturersimportsDell
*/
-class PluginManufacturersimportsDell extends PluginManufacturersimportsManufacturer {
-
- /**
- * @see PluginManufacturersimportsManufacturer::showCheckbox()
- */
- function showCheckbox($ID, $sel, $otherSerial = false) {
- $name = "item[" . $ID . "]";
- return Html::getCheckbox(["name" => $name, "value" => 1, "selected" => $sel]);
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::showItem()
- */
- function showItem($output_type, $item_num, $row_num, $otherSerial = false) {
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::showItemTitle()
- */
- function showItemTitle($output_type, $header_num) {
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::showDocTitle()
- */
- function showDocTitle($output_type, $header_num) {
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::showDocItem()
- */
- function showDocItem($output_type, $item_num, $row_num, $doc = null) {
- return Search::showEndLine($output_type);
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
- */
- function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $apisecret = null,
- $supplierUrl = null) {
-
- if (!$compSerial) {
- // by default
- $info["name"] = PluginManufacturersimportsConfig::DELL;
- $info['supplier_url'] = "https://www.dell.com/support/home/product-support/servicetag/";
- $info['token_url'] = "https://apigtwb2c.us.dell.com/auth/oauth/v2/token";
- $info['warranty_url'] = "https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements?servicetags=";
- $info["supplier_key"] = "123456789";
- $info["supplier_secret"] = "987654321";
- return $info;
- }
-
- $info["url"] = $supplierUrl . "$compSerial";
- return $info;
- }
-
- /**
- * @return bool
- */
- function getSearchField() {
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getBuyDate()
- */
- function getBuyDate($contents) {
- $info = json_decode($contents, true);
- // v5
- if (isset($info[0]['shipDate'])) {
- $date = new \DateTime($info[0]['shipDate']);
- return $date->format('c');
- }
-
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getStartDate()
- */
- function getStartDate($contents) {
- $info = json_decode($contents, true);
- // v5
- $max_date = false;
- if (isset($info[0]['entitlements'])) {
- foreach ($info[0]['entitlements'] as $d) {
- $date = new \DateTime($d['startDate']);
- if ($max_date == false || $date > $max_date) {
- $max_date = $date;
+class PluginManufacturersimportsDell extends PluginManufacturersimportsManufacturer
+{
+ /**
+ * @see PluginManufacturersimportsManufacturer::showCheckbox()
+ */
+ public function showCheckbox($ID, $sel, $otherSerial = false)
+ {
+ $name = "item[" . $ID . "]";
+ return Html::getCheckbox(["name" => $name, "value" => 1, "selected" => $sel]);
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::showItem()
+ */
+ public function showItem($output_type, $item_num, $row_num, $otherSerial = false)
+ {
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::showItemTitle()
+ */
+ public function showItemTitle($output_type, $header_num)
+ {
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::showDocTitle()
+ */
+ public function showDocTitle($output_type, $header_num)
+ {
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::showDocItem()
+ */
+ public function showDocItem($output_type, $item_num, $row_num, $doc = null)
+ {
+ return Search::showEndLine($output_type);
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
+ */
+ public function getSupplierInfo(
+ $compSerial = null,
+ $otherSerial = null,
+ $key = null,
+ $apisecret = null,
+ $supplierUrl = null
+ )
+ {
+ if (!$compSerial) {
+ // by default
+ $info["name"] = PluginManufacturersimportsConfig::DELL;
+ $info['supplier_url'] = "https://www.dell.com/support/home/product-support/servicetag/";
+ $info['token_url'] = "https://apigtwb2c.us.dell.com/auth/oauth/v2/token";
+ $info['warranty_url'] = "https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements?servicetags=";
+ $info["supplier_key"] = "123456789";
+ $info["supplier_secret"] = "987654321";
+ return $info;
+ }
+
+ $info["url"] = $supplierUrl . "$compSerial";
+ return $info;
+ }
+
+ /**
+ * @return bool
+ */
+ public function getSearchField()
+ {
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getBuyDate()
+ */
+ public function getBuyDate($contents)
+ {
+ $info = json_decode($contents, true);
+ // v5
+ if (isset($info[0]['shipDate'])) {
+ $date = new \DateTime($info[0]['shipDate']);
+ return $date->format('c');
+ }
+
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getStartDate()
+ */
+ public function getStartDate($contents)
+ {
+ $info = json_decode($contents, true);
+ // v5
+ $max_date = false;
+ if (isset($info[0]['entitlements'])) {
+ foreach ($info[0]['entitlements'] as $d) {
+ $date = new \DateTime($d['startDate']);
+ if ($max_date == false || $date > $max_date) {
+ $max_date = $date;
+ }
}
- }
-
- if ($max_date) {
- return $max_date->format('c');
- }
- }
-
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getExpirationDate()
- */
- function getExpirationDate($contents) {
- $info = json_decode($contents, true);
- // v5
- // when several dates are available, will take the last one
- $max_date = false;
- if (isset($info[0]['entitlements'])) {
- foreach ($info[0]['entitlements'] as $d) {
- $date = new \DateTime($d['endDate']);
- if ($max_date == false || $date > $max_date) {
- $max_date = $date;
+
+ if ($max_date) {
+ return $max_date->format('c');
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getExpirationDate()
+ */
+ public function getExpirationDate($contents)
+ {
+ $info = json_decode($contents, true);
+ // v5
+ // when several dates are available, will take the last one
+ $max_date = false;
+ if (isset($info[0]['entitlements'])) {
+ foreach ($info[0]['entitlements'] as $d) {
+ $date = new \DateTime($d['endDate']);
+ if ($max_date == false || $date > $max_date) {
+ $max_date = $date;
+ }
+ }
+
+ if ($max_date) {
+ return $max_date->format('c');
}
- }
-
- if ($max_date) {
- return $max_date->format('c');
- }
- }
-
-
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getWarrantyInfo()
- */
- function getWarrantyInfo($contents) {
- $info = json_decode($contents, true);
-
- // v5
- // when several warranties are available, will take the last one
- $max_date = false;
- $i = false;
- if (isset($info[0]['entitlements'])) {
- foreach ($info[0]['entitlements'] as $k => $d) {
- $date = new \DateTime($d['endDate']);
- if ($max_date == false || $date > $max_date) {
- $max_date = $date;
- $i = $k;
+ }
+
+
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getWarrantyInfo()
+ */
+ public function getWarrantyInfo($contents)
+ {
+ $info = json_decode($contents, true);
+
+ // v5
+ // when several warranties are available, will take the last one
+ $max_date = false;
+ $i = false;
+ if (isset($info[0]['entitlements'])) {
+ foreach ($info[0]['entitlements'] as $k => $d) {
+ $date = new \DateTime($d['endDate']);
+ if ($max_date == false || $date > $max_date) {
+ $max_date = $date;
+ $i = $k;
+ }
}
- }
- }
-
- if ($max_date && $i) {
- return $info[0]['entitlements'][$i]['serviceLevelDescription'];
- }
-
- return false;
- }
-
- /**
- * @param $name
- *
- * @return array
- */
- static function cronInfo($name) {
-
- switch ($name) {
- case "DataRecoveryDELL" :
- return ['description' => PluginManufacturersimportsModel::getTypeName(1) . " - " . __('Data recovery DELL for computer', 'manufacturersimports')];
- }
- return [];
- }
-
-
- /**
- * Run for data recovery DELL
- *
- * @param $task : object of crontask
- *
- * @return integer : 0 (nothing to do)
- * >0 (endded)
- **/
- static function cronDataRecoveryDELL($task) {
-
- $cron_status = PluginManufacturersimportsImport::importCron($task, PluginManufacturersimportsConfig::DELL);
-
- return $cron_status;
- }
-
- /**
- * Summary of getToken
- *
- * @param $config
- *
- * @return mixed
- */
- static function getToken($config) {
- $token = false;
- // must manage token
- $options = ["url" => $config->fields["token_url"],
- "download" => false,
- "file" => false,
- "post" => ['client_id' => $config->fields["supplier_key"],
- 'client_secret' => $config->fields["supplier_secret"],
- 'grant_type' => 'client_credentials'],
- "suppliername" => $config->fields["name"]];
- $contents = PluginManufacturersimportsPostImport::cURLData($options);
- // must extract from $contents the token bearer
- $response = json_decode($contents, true);
- if (isset($response['access_token'])) {
- $token = $response['access_token'];
- }
- return $token;
- }
-
-
- /**
- * Summary of getWarrantyUrl
- *
- * @param $config
- * @param $compSerial
- *
- * @return string[]
- */
- static function getWarrantyUrl($config, $compSerial) {
- return ["url" => $config->fields['warranty_url'] . "$compSerial"];
- }
+ }
+
+ if ($max_date && $i) {
+ return $info[0]['entitlements'][$i]['serviceLevelDescription'];
+ }
+
+ return false;
+ }
+
+ /**
+ * @param $name
+ *
+ * @return array
+ */
+ public static function cronInfo($name)
+ {
+ switch ($name) {
+ case "DataRecoveryDELL":
+ return ['description' => PluginManufacturersimportsModel::getTypeName(1) . " - " . __('Warranty import for computer (dell, HP)', 'manufacturersimports')];
+ }
+ return [];
+ }
+
+
+ /**
+ * Run for data recovery DELL
+ *
+ * @param $task : object of crontask
+ *
+ * @return integer : 0 (nothing to do)
+ * >0 (endded)
+ **/
+ public static function cronDataRecoveryDELL($task)
+ {
+ $cron_status = PluginManufacturersimportsImport::importCron($task, PluginManufacturersimportsConfig::DELL);
+
+ return $cron_status;
+ }
+
+ /**
+ * Summary of getToken
+ *
+ * @param $config
+ *
+ * @return mixed
+ */
+ public static function getToken($config)
+ {
+ $token = false;
+ // must manage token
+ $options = ["url" => $config->fields["token_url"],
+ "download" => false,
+ "file" => false,
+ "post" => ['client_id' => $config->fields["supplier_key"],
+ 'client_secret' => $config->fields["supplier_secret"],
+ 'grant_type' => 'client_credentials'],
+ "suppliername" => $config->fields["name"]];
+ $contents = PluginManufacturersimportsPostImport::cURLData($options);
+ // must extract from $contents the token bearer
+ $response = json_decode($contents, true);
+ if (isset($response['access_token'])) {
+ $token = $response['access_token'];
+ }
+ return $token;
+ }
+
+
+ /**
+ * Summary of getWarrantyUrl
+ *
+ * @param $config
+ * @param $compSerial
+ *
+ * @return string[]
+ */
+ public static function getWarrantyUrl($config, $compSerial)
+ {
+ return ["url" => $config->fields['warranty_url'] . "$compSerial"];
+ }
}
diff --git a/inc/fujitsu.class.php b/inc/fujitsu.class.php
index a9ffedf..dc7aa78 100644
--- a/inc/fujitsu.class.php
+++ b/inc/fujitsu.class.php
@@ -28,81 +28,90 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* Class PluginManufacturersimportsFujitsu
*/
-class PluginManufacturersimportsFujitsu extends PluginManufacturersimportsManufacturer {
-
- /**
- * @see PluginManufacturersimportsManufacturer::showDocTitle()
- */
- function showDocTitle($output_type, $header_num) {
- return Search::showHeaderItem($output_type, __('File'), $header_num);
- }
-
- function getSearchField() {
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
- */
- function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $apisecret = null,
- $supplierUrl = null) {
- $info["name"] = PluginManufacturersimportsConfig::FUJITSU;
- $info["supplier_url"] = 'https://support.ts.fujitsu.com/ProductCheck/Default.aspx?Lng=en&GotoDiv=Warranty/WarrantyStatus&DivID=indexwarranty&GotoUrl=IndexWarranty&RegionID=1&Token=${$i$M$f$u&Ident=';
- $info["url"] = $supplierUrl.$compSerial;
- $info["url_web"] = "https://support.ts.fujitsu.com/IndexWarranty.asp?lng=FR";
- return $info;
- }
-
- /**
- * Summary of getWarrantyUrl
- *
- * @param $config
- * @param $compSerial
- *
- * @return string[]
- */
- static function getWarrantyUrl($config, $compSerial) {
- return ["url" => 'https://support.ts.fujitsu.com/ProductCheck/Default.aspx?Lng=en&GotoDiv=Warranty/WarrantyStatus&DivID=indexwarranty&GotoUrl=IndexWarranty&RegionID=1&Token=${$i$M$f$u&Ident=' . "$compSerial"];
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getBuyDate()
- */
- function getBuyDate($contents) {
-
- $matchesarray = [];
- preg_match_all("/value=\"(\d{4}\-\d{2}\-\d{2})\" id=\"Firstuse\"/", $contents, $matchesarray);
-
- $buydate = (isset($matchesarray[1][0])?trim($matchesarray[1][0]):'0000-00-00');
-
- return $buydate;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getStartDate()
- */
- function getStartDate($contents) {
-
- return self::getBuyDate($contents);
- }
-
-
- /**
- * @see PluginManufacturersimportsManufacturer::getExpirationDate()
- */
- function getExpirationDate($contents) {
-
- $matchesarray = [];
- preg_match_all("/value=\"(\d{4}\-\d{2}\-\d{2})\" id=\"WarrantyEndDate\"/", $contents, $matchesarray);
-
- $expirationdate = (isset($matchesarray[1][0])?trim($matchesarray[1][0]):'0000-00-00');
-
- return $expirationdate;
- }
+class PluginManufacturersimportsFujitsu extends PluginManufacturersimportsManufacturer
+{
+ /**
+ * @see PluginManufacturersimportsManufacturer::showDocTitle()
+ */
+ public function showDocTitle($output_type, $header_num)
+ {
+ return Search::showHeaderItem($output_type, __('File'), $header_num);
+ }
+
+ public function getSearchField()
+ {
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
+ */
+ public function getSupplierInfo(
+ $compSerial = null,
+ $otherSerial = null,
+ $key = null,
+ $apisecret = null,
+ $supplierUrl = null
+ )
+ {
+ $info["name"] = PluginManufacturersimportsConfig::FUJITSU;
+ $info["supplier_url"] = 'https://support.ts.fujitsu.com/ProductCheck/Default.aspx?Lng=en&GotoDiv=Warranty/WarrantyStatus&DivID=indexwarranty&GotoUrl=IndexWarranty&RegionID=1&Token=${$i$M$f$u&Ident=';
+ $info["url"] = $supplierUrl.$compSerial;
+ $info["url_web"] = "https://support.ts.fujitsu.com/IndexWarranty.asp?lng=FR";
+ return $info;
+ }
+
+ /**
+ * Summary of getWarrantyUrl
+ *
+ * @param $config
+ * @param $compSerial
+ *
+ * @return string[]
+ */
+ public static function getWarrantyUrl($config, $compSerial)
+ {
+ return ["url" => 'https://support.ts.fujitsu.com/ProductCheck/Default.aspx?Lng=en&GotoDiv=Warranty/WarrantyStatus&DivID=indexwarranty&GotoUrl=IndexWarranty&RegionID=1&Token=${$i$M$f$u&Ident=' . "$compSerial"];
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getBuyDate()
+ */
+ public function getBuyDate($contents)
+ {
+ $matchesarray = [];
+ preg_match_all("/value=\"(\d{4}\-\d{2}\-\d{2})\" id=\"Firstuse\"/", $contents, $matchesarray);
+
+ $buydate = (isset($matchesarray[1][0])?trim($matchesarray[1][0]):'0000-00-00');
+
+ return $buydate;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getStartDate()
+ */
+ public function getStartDate($contents)
+ {
+ return self::getBuyDate($contents);
+ }
+
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getExpirationDate()
+ */
+ public function getExpirationDate($contents)
+ {
+ $matchesarray = [];
+ preg_match_all("/value=\"(\d{4}\-\d{2}\-\d{2})\" id=\"WarrantyEndDate\"/", $contents, $matchesarray);
+
+ $expirationdate = (isset($matchesarray[1][0])?trim($matchesarray[1][0]):'0000-00-00');
+
+ return $expirationdate;
+ }
}
diff --git a/inc/hp.class.php b/inc/hp.class.php
index 66b2ebc..cfd688e 100644
--- a/inc/hp.class.php
+++ b/inc/hp.class.php
@@ -28,96 +28,85 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* Class PluginManufacturersimportsHP
*/
-class PluginManufacturersimportsHP extends PluginManufacturersimportsManufacturer {
-
- /**
- * @see PluginManufacturersimportsManufacturer::showDocTitle()
- */
- function showDocTitle($output_type, $header_num) {
- return Search::showHeaderItem($output_type, __('File'), $header_num);
- }
-
- function getSearchField() {
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
- */
- function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $apisecret = null,
- $supplierUrl = null) {
- $info["name"] = PluginManufacturersimportsConfig::HP;
- $info["supplier_url"] = "https://css.api.hp.com/oauth/v1/token";
-
- $info["url"] = $supplierUrl;
- $info['url_warranty'] = 'https://css.api.hp.com/productWarranty/v1/queries';
-
- $info['post'] = ['apiKey' => $key,
- 'apiSecret' => $apisecret,
- 'grantType' => 'client_credentials',
- 'scope' => 'warranty',
- 'sn' => rtrim($compSerial),
- ];
-
- if (!empty($otherSerial)) {
- $info['post']['pn'] = $otherSerial;
- }
-
- return $info;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getBuyDate()
- */
- function getBuyDate($contents) {
- $contents = json_decode($contents, true);
- $contents = reset($contents);
- if (isset($contents['startDate'])) {
- return $contents['startDate'];
- }
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getStartDate()
- */
- function getStartDate($contents) {
- return self::getBuyDate($contents);
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getExpirationDate()
- */
- function getExpirationDate($contents) {
-
- $contents = json_decode($contents, true);
- $contents = reset($contents);
- if (isset($contents['endDate'])) {
- return $contents['endDate'];
- }
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getWarrantyInfo()
- */
- function getWarrantyInfo($contents) {
- $contents = json_decode($contents, true);
- $contents = reset($contents);
-
- $warrantyInfo = "";
- if (isset($contents['status'])) {
- $warrantyInfo .= $contents['status'] . " ";
- }
- if (isset($contents['type'])) {
- $warrantyInfo .= $contents['type'] . " ";
- }
- return $warrantyInfo;
- }
+class PluginManufacturersimportsHP extends PluginManufacturersimportsManufacturer
+{
+ /**
+ * @see PluginManufacturersimportsManufacturer::showDocTitle()
+ */
+ public function showDocTitle($output_type, $header_num)
+ {
+ return Search::showHeaderItem($output_type, __('File'), $header_num);
+ }
+
+ public function getSearchField()
+ {
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
+ */
+ public function getSupplierInfo(
+ $compSerial = null,
+ $otherSerial = null,
+ $key = null,
+ $apisecret = null,
+ $supplierUrl = null
+ ) {
+ $info["name"] = PluginManufacturersimportsConfig::HP;
+ $info["supplier_url"] = "https://warrantyapiproxy.azurewebsites.net/api/HP?serial=";
+
+ $info['url_warranty'] = "https://warrantyapiproxy.azurewebsites.net/api/HP?serial=";
+ $info["url"] = $supplierUrl.$compSerial;
+
+ return $info;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getBuyDate()
+ */
+ public function getBuyDate($contents)
+ {
+ $info = json_decode($contents, true);
+
+ if (isset($info['StartDate'])) {
+ return $info['StartDate'];
+ }
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getStartDate()
+ */
+ public function getStartDate($contents)
+ {
+ return self::getBuyDate($contents);
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getExpirationDate()
+ */
+ public function getExpirationDate($contents)
+ {
+ $info = json_decode($contents, true);
+ if (isset($info['EndDate'])) {
+ return $info['EndDate'];
+ }
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getWarrantyInfo()
+ */
+ public function getWarrantyInfo($contents)
+ {
+ $warrantyInfo = "";
+
+ return $warrantyInfo;
+ }
}
diff --git a/inc/ibm.class.php b/inc/ibm.class.php
index 8cbb39d..71b2538 100644
--- a/inc/ibm.class.php
+++ b/inc/ibm.class.php
@@ -28,24 +28,28 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* Class PluginManufacturersimportsIBM
*/
-class PluginManufacturersimportsIBM extends CommonDBTM {
-
- /**
- * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
- */
- function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $apisecret = null,
- $supplierUrl = null) {
-
- $info["name"]="IBM";
- $info["supplier_url"] = "http://www-304.ibm.com/jct01004c/systems/support/supportsite.wss/warranty?";
- $info["url"] = $supplierUrl."type=".$otherSerial."&serial=".$compSerial."&brandind=5000008&Submit=Submit&action=warranty";
- return $info;
- }
-
+class PluginManufacturersimportsIBM extends CommonDBTM
+{
+ /**
+ * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
+ */
+ public function getSupplierInfo(
+ $compSerial = null,
+ $otherSerial = null,
+ $key = null,
+ $apisecret = null,
+ $supplierUrl = null
+ )
+ {
+ $info["name"]="IBM";
+ $info["supplier_url"] = "http://www-304.ibm.com/jct01004c/systems/support/supportsite.wss/warranty?";
+ $info["url"] = $supplierUrl."type=".$otherSerial."&serial=".$compSerial."&brandind=5000008&Submit=Submit&action=warranty";
+ return $info;
+ }
}
diff --git a/inc/import.class.php b/inc/import.class.php
index 2af2397..8cd3e1a 100644
--- a/inc/import.class.php
+++ b/inc/import.class.php
@@ -28,111 +28,121 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* Class PluginManufacturersimportsImport
*/
-class PluginManufacturersimportsImport extends CommonDBTM {
-
- /**
- * Import via le cron
- *
- * @param type $supplier
- *
- * @return int
- * @global type $DB
- *
- */
- static function importCron($task, $supplier) {
- global $DB;
-
- $config = new PluginManufacturersimportsConfig();
- $config->getFromDBByCrit(['name' => $supplier]);
-
- $log = new PluginManufacturersimportsLog();
-
- $suppliername = $config->fields["name"];
- $supplierUrl = $config->fields["supplier_url"];
- $supplierkey = $config->fields["supplier_key"];
- $supplierId = $config->fields["suppliers_id"];
-
- $toview = ["name" => 1];
-
- $params = [];
- $params['manufacturers_id'] = $config->getID();
- $params['imported'] = 1;
- $params['sort'] = 1;
- $params['order'] = "ASC";
- $params['start'] = 0;
+class PluginManufacturersimportsImport extends CommonDBTM
+{
+ /**
+ * Import via le cron
+ *
+ * @param type $supplier
+ *
+ * @return int
+ * @global type $DB
+ *
+ */
+ public static function importCron($task, $supplier)
+ {
+ global $DB;
+
+ $config = new PluginManufacturersimportsConfig();
+ $config->getFromDBByCrit(['name' => $supplier]);
+
+ $log = new PluginManufacturersimportsLog();
+
+ $suppliername = $config->fields["name"];
+ $supplierUrl = $config->fields["supplier_url"];
+ $supplierkey = $config->fields["supplier_key"];
+ $supplierId = $config->fields["suppliers_id"];
+
+ $toview = ["name" => 1];
+
+ $params = [];
+ $params['manufacturers_id'] = $config->getID();
+ $params['imported'] = 1;
+ $params['sort'] = 1;
+ $params['order'] = "ASC";
+ $params['start'] = 0;
// $types = PluginManufacturersimportsConfig::getTypes();
- $nb_import_error = 0;
- $msg = "";
+ $nb_import_error = 0;
+ $msg = "";
// foreach ($types as $type) {
- $type = "Computer";
- $params['itemtype'] = $type;
- $query = PluginManufacturersimportsPreImport::queryImport($params, $config, $toview, true);
-
- $result = $DB->query($query);
-
- if ($DB->numrows($result) > 0) {
- while ($data = $DB->fetchArray($result)) {
-
- $log->reinitializeImport($type, $data['id']);
-
- $compSerial = $data['serial'];
- $ID = $data['id'];
-
- $model = new PluginManufacturersimportsModel();
- $otherSerial = $model->checkIfModelNeeds($type, $ID);
-
- $url = PluginManufacturersimportsPreImport::selectSupplier($suppliername, $supplierUrl,
- $compSerial, $otherSerial, $supplierkey);
- $post = PluginManufacturersimportsPreImport::getSupplierPost($suppliername, $compSerial,
- $otherSerial);
-
- $options = ["url" => $url,
- "post" => $post,
- "type" => $type,
- "ID" => $ID,
- "config" => $config,
- "line" => $data,
- "display" => false];
-
- if ($suppliername == PluginManufacturersimportsConfig::LENOVO) {
- $options['ClientID'] = $supplierkey;
- }
-
- if ($suppliername == PluginManufacturersimportsConfig::DELL) {
- $supplierclass = "PluginManufacturersimports" . $suppliername;
- $token = $supplierclass::getToken($config);
- $warranty_url = $supplierclass::getWarrantyUrl($config, $compSerial);
- $options['token'] = $token;
- if (isset($warranty_url)) {
- $options['url'] = $warranty_url['url'];
- }
+ $type = "Computer";
+ $params['itemtype'] = $type;
+ $query = PluginManufacturersimportsPreImport::queryImport($params, $config, $toview, true);
+
+ $result = $DB->query($query);
+
+ if ($DB->numrows($result) > 0) {
+ while ($data = $DB->fetchArray($result)) {
+ $log->reinitializeImport($type, $data['id']);
+
+ $compSerial = $data['serial'];
+ $ID = $data['id'];
+
+ $model = new PluginManufacturersimportsModel();
+ $otherSerial = $model->checkIfModelNeeds($type, $ID);
+
+ $url = PluginManufacturersimportsPreImport::selectSupplier(
+ $suppliername,
+ $supplierUrl,
+ $compSerial,
+ $otherSerial,
+ $supplierkey
+ );
+ $post = PluginManufacturersimportsPreImport::getSupplierPost(
+ $suppliername,
+ $compSerial,
+ $otherSerial
+ );
+
+ $options = ["url" => $url,
+ "post" => $post,
+ "type" => $type,
+ "ID" => $ID,
+ "config" => $config,
+ "line" => $data,
+ "display" => false];
+
+ if ($suppliername == PluginManufacturersimportsConfig::DELL) {
+ $supplierclass = "PluginManufacturersimports" . $suppliername;
+ $token = $supplierclass::getToken($config);
+ $warranty_url = $supplierclass::getWarrantyUrl($config, $compSerial);
+ $options['token'] = $token;
+ if (isset($warranty_url)) {
+ $options['url'] = $warranty_url['url'];
+ }
+ }
+ if ($suppliername == PluginManufacturersimportsConfig::HP) {
+ $supplierclass = "PluginManufacturersimports" . $suppliername;
+ $warranty_url = $supplierclass::getWarrantyUrl($config, $compSerial);
+ if (isset($warranty_url)) {
+ $options['url'] = $warranty_url['url'];
+ }
+ }
+
+ if (PluginManufacturersimportsPostImport::saveImport($options)) {
+ $task->addVolume(1);
+ } else {
+ $nb_import_error += 1;
+ }
}
-
- if (PluginManufacturersimportsPostImport::saveImport($options)) {
- $task->addVolume(1);
- } else {
- $nb_import_error += 1;
- }
- }
- }
+ }
// }
- if ($task) {
- $task->log(__('Import OK', 'manufacturersimports'));
-
- $task->addVolume($nb_import_error);
- $task->log(__('Import failed', 'manufacturersimports'));
- }
- return true;
-
- }
+ if ($task) {
+ $task->log(__('Import OK', 'manufacturersimports'));
+
+ $task->addVolume($nb_import_error);
+ $task->log(__('Import failed', 'manufacturersimports'));
+ }
+ return true;
+ }
}
diff --git a/inc/lenovo.class.php b/inc/lenovo.class.php
index 0bd213a..1dda4f6 100644
--- a/inc/lenovo.class.php
+++ b/inc/lenovo.class.php
@@ -28,7 +28,7 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
ini_set("max_execution_time", "0");
@@ -38,179 +38,207 @@
*/
class PluginManufacturersimportsLenovo extends PluginManufacturersimportsManufacturer {
- /**
- * @see PluginManufacturersimportsManufacturer::showCheckbox()
- */
- function showCheckbox($ID, $sel, $otherSerial = false) {
- $name = "item[" . $ID . "]";
- return Html::getCheckbox(["name" => $name, "value" => 1, "selected" => $sel]);
-
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::showItemTitle()
- */
- function showItemTitle($output_type, $header_num) {
- return Search::showHeaderItem($output_type, __('Model number', 'manufacturersimports'), $header_num);
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::showDocTitle()
- */
- function showDocTitle($output_type, $header_num) {
- return Search::showHeaderItem($output_type, __('File'), $header_num);
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::showItem()
- */
- function showItem($output_type, $item_num, $row_num, $otherSerial = false) {
- return false;
- }
-
- function getSearchField() {
- return false;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
- */
- function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $apisecret = null,
- $supplierUrl = null) {
-
- $info["name"] = PluginManufacturersimportsConfig::LENOVO;
- $info["supplier_url"] = "https://SupportAPI.lenovo.com/v2.5/Warranty";
- // $info["url"] = $supplierUrl . $compSerial."?machineType=&btnSubmit";
- $info["url"] = $supplierUrl . "?Serial=".$compSerial;
- $info["url_web"] = "https://pcsupport.lenovo.com/products/$compSerial/warranty";
- return $info;
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getBuyDate()
- */
- function getBuyDate($contents) {
-
- $contents = json_decode($contents, true);
-
- if (isset($contents['Purchased'])) {
-
- if(strpos($contents['Purchased'], '0001-01-01') !== false){
- if(strpos($contents['Shipped'], '0001-01-01') !== false) {
- if(isset($contents['Warranty']) && !empty($contents['Warranty'])){
- $minStart = 0;
- $start = 0;
- $n = 0;
- foreach ($contents['Warranty'] as $id => $warranty){
- $myDate= trim($warranty['start']);
- $dateStart = strtotime($myDate);
- if($n === 0){
- $minStart = $dateStart;
- $myDate = strtotime(trim($warranty['Start']));
- }
- if($dateStart > $minStart){
- $minStart = $dateStart;
- $myDate = strtotime(trim($warranty['Start']));
- }
- $n++;
- }
- }
- }else{
- $myDate = trim($contents['Shipped']);
- }
- }else{
- $myDate = trim($contents['Purchased']);
- }
- // $myDate = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
- $myDate = date("Y-m-d", strtotime($myDate));
-
-
- return PluginManufacturersimportsPostImport::checkDate($myDate);
- }
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getStartDate()
- */
- function getStartDate($contents) {
- //TODO change to have good start date with new json
- $contents = json_decode($contents, true);
- if(isset($contents['Warranty']) && !empty($contents['Warranty'])){
- $maxEnd = 0;
- $start = 0;
- foreach ($contents['Warranty'] as $id => $warranty){
- $myDate = trim($warranty['End']);
- $dateEnd = strtotime($myDate);
- if($dateEnd > $maxEnd){
- $maxEnd = $dateEnd;
- $start = strtotime(trim($warranty['Start']));
- }
- }
-
- }
-
- if(isset($start)) {
- $myDate = date("Y-m-d", $start);
-
- return PluginManufacturersimportsPostImport::checkDate($myDate);
- }
-
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getExpirationDate()
- */
- function getExpirationDate($contents) {
- $contents = json_decode($contents, true);
- //TODO change to have good expiration date with new json
- if(isset($contents['Warranty']) && !empty($contents['Warranty'])){
- $maxEnd = 0;
-
- foreach ($contents['Warranty'] as $id => $warranty){
- $myDate = trim($warranty['End']);
- $dateEnd = strtotime($myDate);
- if($dateEnd > $maxEnd){
- $maxEnd = $dateEnd;
- }
- }
-
- }
-
- if(isset($maxEnd)) {
- $myDate = date("Y-m-d", $maxEnd);
-
- return PluginManufacturersimportsPostImport::checkDate($myDate);
- }
- }
-
- /**
- * @see PluginManufacturersimportsManufacturer::getWarrantyInfo()
- */
- function getWarrantyInfo($contents) {
- $contents = json_decode($contents, true);
-
- //TODO change to have good information with new json
- $warranty_info = false;
- if(isset($contents['Warranty']) && !empty($contents['Warranty'])){
- $maxEnd = 0;
-
- foreach ($contents['Warranty'] as $id => $warranty){
- $myDate = trim($warranty['End']);
- $dateEnd = strtotime($myDate);
- if($dateEnd > $maxEnd){
- $maxEnd = $dateEnd;
- if(isset($warranty["Description"])){
- $warranty_info = $warranty["Description"];
- }else{
- $warranty_info = $warranty["Type"]." - ".$warranty["Name"];
- }
- }
- }
-
- }
- if (strlen($warranty_info) > 255) {
- $warranty_info = substr($warranty_info, 0, 254);
- }
- return $warranty_info;
- }
+ /**
+ * @see PluginManufacturersimportsManufacturer::showCheckbox()
+ */
+ function showCheckbox($ID, $sel, $otherSerial = false) {
+ $name = "item[" . $ID . "]";
+ return Html::getCheckbox(["name" => $name, "value" => 1, "selected" => $sel]);
+
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::showItemTitle()
+ */
+ function showItemTitle($output_type, $header_num) {
+ return Search::showHeaderItem($output_type, __('Model number', 'manufacturersimports'), $header_num);
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::showDocTitle()
+ */
+ function showDocTitle($output_type, $header_num) {
+ return Search::showHeaderItem($output_type, __('File'), $header_num);
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::showItem()
+ */
+ function showItem($output_type, $item_num, $row_num, $otherSerial = false) {
+ return false;
+ }
+
+ function getSearchField() {
+ return false;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getSupplierInfo()
+ */
+ function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $apisecret = null,
+ $supplierUrl = null) {
+
+ $info["name"] = PluginManufacturersimportsConfig::LENOVO;
+ $info["supplier_url"] = "https://pcsupport.lenovo.com/products/$compSerial/warranty";
+ // $info["url"] = $supplierUrl . $compSerial."?machineType=&btnSubmit";
+ $info["url"] = "https://pcsupport.lenovo.com/products/$compSerial/warranty";
+ $info["url_web"] = "https://pcsupport.lenovo.com/products/$compSerial/warranty";
+ return $info;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getBuyDate()
+ */
+ function getBuyDate($contents) {
+
+// $contents = json_decode($contents, true);
+ $field = "POPDate";
+ $search = stristr($contents, $field);
+ $myDate = substr($search, 10, 10);
+ $myDate = trim($myDate);
+ $myDate = PluginManufacturersimportsPostImport::checkDate($myDate);
+
+ return $myDate;
+
+// if (isset($contents['POPDate'])) {
+//
+// Toolbox::loginfo($contents['POPDate']);
+//
+// if (strpos($contents['POPDate'], '0001-01-01') !== false) {
+// if (strpos($contents['Shipped'], '0001-01-01') !== false) {
+// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
+// $minStart = 0;
+// $start = 0;
+// $n = 0;
+// foreach ($contents['Warranty'] as $id => $warranty) {
+// $myDate = trim($warranty['start']);
+// $dateStart = strtotime($myDate);
+// if ($n === 0) {
+// $minStart = $dateStart;
+// $myDate = strtotime(trim($warranty['Start']));
+// }
+// if ($dateStart > $minStart) {
+// $minStart = $dateStart;
+// $myDate = strtotime(trim($warranty['Start']));
+// }
+// $n++;
+// }
+// }
+// } else {
+// $myDate = trim($contents['POPDate']);
+// }
+// } else {
+// $myDate = trim($contents['POPDate']);
+// }
+// Toolbox::loginfo($myDate);
+// // $myDate = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
+// $myDate = date("Y-m-d", strtotime($myDate));
+//
+//
+// return PluginManufacturersimportsPostImport::checkDate($myDate);
+// }
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getStartDate()
+ */
+ function getStartDate($contents) {
+
+ $field = "POPDate";
+ $search = stristr($contents, $field);
+ $myDate = substr($search, 10, 10);
+ $myDate = trim($myDate);
+ $myDate = PluginManufacturersimportsPostImport::checkDate($myDate);
+
+ return $myDate;
+
+// //TODO change to have good start date with new json
+// $contents = json_decode($contents, true);
+// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
+// $maxEnd = 0;
+// $start = 0;
+// foreach ($contents['Warranty'] as $id => $warranty) {
+// $myDate = trim($warranty['End']);
+// $dateEnd = strtotime($myDate);
+// if ($dateEnd > $maxEnd) {
+// $maxEnd = $dateEnd;
+// $start = strtotime(trim($warranty['Start']));
+// }
+// }
+//
+// }
+//
+// if (isset($start)) {
+// $myDate = date("Y-m-d", $start);
+//
+// return PluginManufacturersimportsPostImport::checkDate($myDate);
+// }
+
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getExpirationDate()
+ */
+ function getExpirationDate($contents) {
+// $contents = json_decode($contents, true);
+// //TODO change to have good expiration date with new json
+// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
+// $maxEnd = 0;
+//
+// foreach ($contents['Warranty'] as $id => $warranty) {
+// $myDate = trim($warranty['End']);
+// $dateEnd = strtotime($myDate);
+// if ($dateEnd > $maxEnd) {
+// $maxEnd = $dateEnd;
+// }
+// }
+//
+// }
+//
+// if (isset($maxEnd)) {
+// $myDate = date("Y-m-d", $maxEnd);
+//
+// return PluginManufacturersimportsPostImport::checkDate($myDate);
+// }
+
+ $field = "BaseUpmaWarranties";
+ $search = stristr($contents, $field);
+
+ $myEndDate = substr($search, 29, 10);
+
+ $myEndDate = trim($myEndDate);
+ $myEndDate = PluginManufacturersimportsPostImport::checkDate($myEndDate);
+ return $myEndDate;
+ }
+
+ /**
+ * @see PluginManufacturersimportsManufacturer::getWarrantyInfo()
+ */
+ function getWarrantyInfo($contents) {
+// $contents = json_decode($contents, true);
+//
+// //TODO change to have good information with new json
+// $warranty_info = false;
+// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
+// $maxEnd = 0;
+//
+// foreach ($contents['Warranty'] as $id => $warranty) {
+// $myDate = trim($warranty['End']);
+// $dateEnd = strtotime($myDate);
+// if ($dateEnd > $maxEnd) {
+// $maxEnd = $dateEnd;
+// if (isset($warranty["Description"])) {
+// $warranty_info = $warranty["Description"];
+// } else {
+// $warranty_info = $warranty["Type"] . " - " . $warranty["Name"];
+// }
+// }
+// }
+//
+// }
+// if (strlen($warranty_info) > 255) {
+// $warranty_info = substr($warranty_info, 0, 254);
+// }
+// return $warranty_info;
+ }
}
diff --git a/inc/manufacturer.class.php b/inc/manufacturer.class.php
index 5cf7048..925bff7 100644
--- a/inc/manufacturer.class.php
+++ b/inc/manufacturer.class.php
@@ -28,154 +28,168 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* Class PluginManufacturersimportsManufacturer
*/
-class PluginManufacturersimportsManufacturer extends CommonDBTM {
-
- /**
- * @param $ID
- * @param $sel
- * @param bool $otherSerial
- * @return string
- */
- function showCheckbox($ID, $sel, $otherSerial = false) {
- $name = "item[" . $ID . "]";
- return Html::getCheckbox(["name" => $name, "value" => 1, "selected" => $sel]);
- }
-
- /**
- * @param $output_type
- * @param $header_num
- * @return bool
- */
- function showItemTitle($output_type, $header_num) {
- return false;
- }
-
- /**
- * @param $output_type
- * @param bool $otherSerial
- * @param $item_num
- * @param $row_num
- * @return bool
- */
- function showItem($output_type, $item_num, $row_num, $otherSerial = false) {
- return false;
- }
-
- /**
- * @param $output_type
- * @param $header_num
- * @return bool
- */
- function showDocTitle($output_type, $header_num) {
- return false;
-
- }
-
- /**
- * @param $output_type
- * @param $item_num
- * @param $row_num
- * @param null $doc
- * @return string
- */
- function showDocItem($output_type, $item_num, $row_num, $documents_id = null) {
- $doc = new document();
- if ($doc->getFromDB($documents_id)) {
- return Search::showItem($output_type,
- $doc->getDownloadLink(),
- $item_num, $row_num);
- }
- return Search::showItem($output_type, "", $item_num, $row_num);
-
- }
-
- /**
- *
- * @param type $ID
- * @param type $supplierWarranty
- */
- function showWarrantyItem($ID, $supplierWarranty) {
- echo "
".__('Automatic');
- $name = "to_warranty_duration".$ID;
- echo Html::hidden($name, ['value' => 0]);
- echo " | ";
- }
-
- /**
- * Get supplier information with url
- *
- * @param null $compSerial
- * @param null $otherserial
- * @param null $key
- * @param null $supplierUrl
- * @return mixed
- */
- function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $apisecret = null,
- $supplierUrl = null) {
-
- }
-
- /**
- * Get buy date of object
- *
- * @param $contents
- */
- function getBuyDate($contents) {
-
- }
-
- /**
- * Get start date of warranty
- *
- * @param $contents
- * @return mixed
- */
- function getStartDate($contents) {
- return false;
- }
-
- /**
- * Get expiration date of warranty
- *
- * @param $contents
- */
- function getExpirationDate($contents) {
-
- }
-
- /**
- * Get warranty info
- *
- * @param $contents
- */
- function getWarrantyInfo($contents) {
-
- }
-
- /**
- * Summary of getToken
- * @param $config
- * @return mixed
- */
- static function getToken($config) {
- return false;
- }
-
-
- /**
- * Summary of getWarrantyUrl
- * @param $config
- * @param $compSerial
- * @return string[]|boolean
- */
- static function getWarrantyUrl($config, $compSerial) {
- return false;
- }
-
+class PluginManufacturersimportsManufacturer extends CommonDBTM
+{
+ /**
+ * @param $ID
+ * @param $sel
+ * @param bool $otherSerial
+ * @return string
+ */
+ public function showCheckbox($ID, $sel, $otherSerial = false)
+ {
+ $name = "item[" . $ID . "]";
+ return Html::getCheckbox(["name" => $name, "value" => 1, "selected" => $sel]);
+ }
+
+ /**
+ * @param $output_type
+ * @param $header_num
+ * @return bool
+ */
+ public function showItemTitle($output_type, $header_num)
+ {
+ return false;
+ }
+
+ /**
+ * @param $output_type
+ * @param bool $otherSerial
+ * @param $item_num
+ * @param $row_num
+ * @return bool
+ */
+ public function showItem($output_type, $item_num, $row_num, $otherSerial = false)
+ {
+ return false;
+ }
+
+ /**
+ * @param $output_type
+ * @param $header_num
+ * @return bool
+ */
+ public function showDocTitle($output_type, $header_num)
+ {
+ return false;
+ }
+
+ /**
+ * @param $output_type
+ * @param $item_num
+ * @param $row_num
+ * @param null $doc
+ * @return string
+ */
+ public function showDocItem($output_type, $item_num, $row_num, $documents_id = null)
+ {
+ $doc = new document();
+ if ($doc->getFromDB($documents_id)) {
+ return Search::showItem(
+ $output_type,
+ $doc->getDownloadLink(),
+ $item_num,
+ $row_num
+ );
+ }
+ return Search::showItem($output_type, "", $item_num, $row_num);
+ }
+
+ /**
+ *
+ * @param type $ID
+ * @param type $supplierWarranty
+ */
+ public function showWarrantyItem($ID, $supplierWarranty)
+ {
+ echo "
".__('Automatic');
+ $name = "to_warranty_duration".$ID;
+ echo Html::hidden($name, ['value' => 0]);
+ echo " | ";
+ }
+
+ /**
+ * Get supplier information with url
+ *
+ * @param null $compSerial
+ * @param null $otherserial
+ * @param null $key
+ * @param null $supplierUrl
+ * @return mixed
+ */
+ public function getSupplierInfo(
+ $compSerial = null,
+ $otherSerial = null,
+ $key = null,
+ $apisecret = null,
+ $supplierUrl = null
+ )
+ {
+ }
+
+ /**
+ * Get buy date of object
+ *
+ * @param $contents
+ */
+ public function getBuyDate($contents)
+ {
+ }
+
+ /**
+ * Get start date of warranty
+ *
+ * @param $contents
+ * @return mixed
+ */
+ public function getStartDate($contents)
+ {
+ return false;
+ }
+
+ /**
+ * Get expiration date of warranty
+ *
+ * @param $contents
+ */
+ public function getExpirationDate($contents)
+ {
+ }
+
+ /**
+ * Get warranty info
+ *
+ * @param $contents
+ */
+ public function getWarrantyInfo($contents)
+ {
+ }
+
+ /**
+ * Summary of getToken
+ * @param $config
+ * @return mixed
+ */
+ public static function getToken($config)
+ {
+ return false;
+ }
+
+
+ /**
+ * Summary of getWarrantyUrl
+ * @param $config
+ * @param $compSerial
+ * @return string[]|boolean
+ */
+ public static function getWarrantyUrl($config, $compSerial)
+ {
+ return false;
+ }
}
diff --git a/inc/model.class.php b/inc/model.class.php
index 20506a4..85443f3 100644
--- a/inc/model.class.php
+++ b/inc/model.class.php
@@ -28,199 +28,216 @@
*/
if (!defined('GLPI_ROOT')) {
- die("Sorry. You can't access directly to this file");
+ die("Sorry. You can't access directly to this file");
}
/**
* Class PluginManufacturersimportsModel
*/
-class PluginManufacturersimportsModel extends CommonDBTM {
-
- static $rightname = "plugin_manufacturersimports";
-
- /**
- * Return the localized name of the current Type
- * Should be overloaded in each new class
- *
- * @return string
- **/
- static function getTypeName($nb = 0) {
- return _n('Suppliers import', 'Suppliers imports',
- $nb, 'manufacturersimports');
- }
-
-
- /**
- * @param $items_id
- * @param $itemtype
- *
- * @return bool
- */
- function getFromDBbyDevice($items_id, $itemtype) {
- global $DB;
-
- $query = "SELECT * FROM `" . $this->getTable() . "` " .
- "WHERE `items_id` = '" . $items_id . "'
+class PluginManufacturersimportsModel extends CommonDBTM
+{
+ public static $rightname = "plugin_manufacturersimports";
+
+ /**
+ * Return the localized name of the current Type
+ * Should be overloaded in each new class
+ *
+ * @return string
+ **/
+ public static function getTypeName($nb = 0)
+ {
+ return _n(
+ 'Suppliers import',
+ 'Suppliers imports',
+ $nb,
+ 'manufacturersimports'
+ );
+ }
+
+
+ /**
+ * @param $items_id
+ * @param $itemtype
+ *
+ * @return bool
+ */
+ public function getFromDBbyDevice($items_id, $itemtype)
+ {
+ global $DB;
+
+ $query = "SELECT * FROM `" . $this->getTable() . "` " .
+ "WHERE `items_id` = '" . $items_id . "'
AND `itemtype` = '" . $itemtype . "' ";
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result) != 1) {
- return false;
- }
- $this->fields = $DB->fetchAssoc($result);
- if (is_array($this->fields) && count($this->fields)) {
- return true;
- } else {
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result) != 1) {
+ return false;
+ }
+ $this->fields = $DB->fetchAssoc($result);
+ if (is_array($this->fields) && count($this->fields)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param $itemtype
+ * @param $items_id
+ *
+ * @return bool
+ */
+ public function checkIfModelNeeds($itemtype, $items_id)
+ {
+ if ($this->getFromDBbyDevice($items_id, $itemtype)) {
+ return $this->fields["model_name"];
+ } else {
return false;
- }
- }
- return false;
- }
-
- /**
- * @param $itemtype
- * @param $items_id
- *
- * @return bool
- */
- function checkIfModelNeeds($itemtype, $items_id) {
- if ($this->getFromDBbyDevice($items_id, $itemtype)) {
- return $this->fields["model_name"];
- } else {
- return false;
- }
- }
-
- /**
- * @param $values
- *
- * @return bool
- */
- function addModel($values) {
- $tmp['model_name'] = $values['model_name'];
- $tmp['itemtype'] = $values['itemtype'];
- $tmp['items_id'] = $values['items_id'];
- if ($this->getFromDBbyDevice($values['items_id'],
- $values['itemtype'])) {
- $tmp['id'] = $this->getID();
- $this->update($tmp);
- } else {
- $this->add($tmp);
- }
- return true;
- }
-
- /**
- * Prints the model add form (into devices)
- *
- * @param $device the device ID
- * @param $type the device type
- *
- * @return nothing (print out a table)
- *
- */
- static function showModelForm($itemtype, $items_id) {
- global $DB;
-
- $canedit = Session::haveRight(static::$rightname, UPDATE);
-
- $query = "SELECT *
+ }
+ }
+
+ /**
+ * @param $values
+ *
+ * @return bool
+ */
+ public function addModel($values)
+ {
+ $tmp['model_name'] = $values['model_name'];
+ $tmp['itemtype'] = $values['itemtype'];
+ $tmp['items_id'] = $values['items_id'];
+ if ($this->getFromDBbyDevice(
+ $values['items_id'],
+ $values['itemtype']
+ )) {
+ $tmp['id'] = $this->getID();
+ $this->update($tmp);
+ } else {
+ $this->add($tmp);
+ }
+ return true;
+ }
+
+ /**
+ * Prints the model add form (into devices)
+ *
+ * @param $device the device ID
+ * @param $type the device type
+ *
+ * @return nothing (print out a table)
+ *
+ */
+ public static function showModelForm($itemtype, $items_id)
+ {
+ global $DB;
+
+ $canedit = Session::haveRight(static::$rightname, UPDATE);
+
+ $query = "SELECT *
FROM `glpi_plugin_manufacturersimports_models`
WHERE `itemtype` = '" . $itemtype . "'
AND `items_id` = '" . $items_id . "'";
- $result = $DB->query($query);
- $number = $DB->numrows($result);
-
- $config_url = PluginManufacturersimportsConfig::getFormUrl(true);
- echo "
";
- }
-
- //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;
-
- 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, '', $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 Search::showHeaderItem($output_type, __('Model Number', 'manufacturersimports'), $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->dataSeek($result, $i);
- }
-
- $row_num = 1;
-
- while ($i < $numrows && $i < $end_display) {
- $i++;
-
- $item_num = 1;
- $line = $DB->fetchArray($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 "";
- echo sprintf(__('Total number of devices to import %s',
- 'manufacturersimports'), $total);
- echo " |
";
-
- // Close Table
- $title = "";
- // Create title
- if ($output_type == Search::PDF_OUTPUT_PORTRAIT
- || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
- $title .=
- PluginManufacturersimportsPreImport::getTypeName(2)
- . " " . $suppliername;
+ /**
+ * 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)
+ *
+ */
+ public static function seePreImport($params)
+ {
+ global $DB, $CFG_GLPI;
+
+ // Default values of parameters
+ $p['link'] = [];
+ $p['field'] = [];
+ $p['contains'] = [];
+ $p['searchtype'] = [];
+ $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;
+ }
+
+ $target = PLUGIN_MANUFACTURERSIMPORTS_WEBDIR . "/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;
}
- echo Search::showFooter($output_type, $title);
-
- //massive action
- if ($canedit && $output_type == Search::HTML_OUTPUT) {
- if ($_SESSION['glpilist_limit'] < Toolbox::get_max_input_vars()) {
- self::openArrowMassives("massiveaction_form", false);
- self::dropdownMassiveAction($compId, $p['itemtype'],
- $p['manufacturers_id'],
- $p['start'], $p['imported']);
- self::closeArrowMassives([]);
- } else {
- echo "" .
- "";
- echo __('Selection too large, massive action disabled.') . "";
- if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
- echo " " . __('To increase the limit: change max_input_vars or suhosin.post.max_vars in php configuration.');
- }
- echo " |
";
- }
- Html::closeForm();
+ $toview = ["name" => 1];
+
+ $query = self::queryImport($p, $config, $toview);
+
+ $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']
+ );
+ }
+
+
+ if (Session::isMultiEntitiesMode()) {
+ $colsup = 1;
+ } else {
+ $colsup = 0;
+ }
+ //////////////////////HEADER///////////////
+ if ($output_type == Search::HTML_OUTPUT) {
+ echo "";
+ }
+
+ //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;
+
+ 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,
+ '',
+ $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 Search::showHeaderItem($output_type, __('Model Number', 'manufacturersimports'), $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->dataSeek($result, $i);
+ }
+
+ $row_num = 1;
+
+ while ($i < $numrows && $i < $end_display) {
+ $i++;
+
+ $item_num = 1;
+ $line = $DB->fetchArray($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 "";
+ echo sprintf(__(
+ 'Total number of devices to import %s',
+ 'manufacturersimports'
+ ), $total);
+ echo " |
";
+
+ // 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()) {
+ self::openArrowMassives("massiveaction_form", false);
+ self::dropdownMassiveAction(
+ $compId,
+ $p['itemtype'],
+ $p['manufacturers_id'],
+ $p['start'],
+ $p['imported']
+ );
+ self::closeArrowMassives([]);
+ } else {
+ echo "" .
+ "";
+ echo __('Selection too large, massive action disabled.') . "";
+ if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
+ echo " " . __('To increase the limit: change max_input_vars or suhosin.post.max_vars in php configuration.');
+ }
+ echo " |
";
+ }
+ Html::closeForm();
+ } else {
+ echo "";
+ echo "";
+ if ($output_type == Search::HTML_OUTPUT) {
+ self::printPager(
+ $p['start'],
+ $numrows,
+ $target,
+ $parameters,
+ $p['itemtype']
+ );
+ }
} else {
- echo "";
- echo "