. @package archires @author Nelly Mahu-Lasson, Xavier Caillaud @copyright Copyright (c) 2016-2018 Archires plugin team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link https://forge.glpi-project.org/projects/aarchires @since version 2.2 -------------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } class PluginArchiresImageItem extends CommonDBTM { static $rightname = "plugin_archires"; function getFromDBbyType($itemtype, $type) { global $DB; $query = ['FROM' => $this->getTable(), 'WHERE' => ['itemtype' => $itemtype, 'type' => $type]]; if ($result = $DB->request($query)) { if (count($result) != 1) { return false; } $this->fields = $result->next(); if (is_array($this->fields) && count($this->fields)) { return true; } } return false; } function addItemImage($type,$itemtype,$img) { global $DB; $dbu = new DbUtils(); if ($type != '-1') { if ($this->getfromDBbyType($itemtype, $type)) { $this->update(['id' => $this->fields['id'], 'img' => $img]); } else { $this->add(['itemtype' => $itemtype, 'type' => $type, 'img' => $img]); } } else { $query = ['FROM' => $dbu->getTableForItemType($itemtype."Type")]; $result = $DB->request($query); $i = 0; while ($i < count($result)) { $row = $result->next(); $type_table = $row['id']; if ($this->getfromDBbyType($itemtype,$type_table)) { $this->update(['id' => $this->fields['id'], 'img' => $img]); } else { $this->add(['itemtype' => $itemtype, 'type' => $type_table, 'img' => $img]); } $i++; } } } function showConfigForm() { global $DB, $CFG_GLPI; echo "