. @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 "
"; echo ""; echo ""; echo ""; echo "
".__('Associate pictures with item types', 'archires')."
"; $PluginArchiresArchires = new PluginArchiresArchires(); $PluginArchiresArchires->showAllItems("type",0,0,$_SESSION["glpiactive_entity"]); echo ""; //file $rep = "../pics/"; $dir = opendir($rep); while ($f = readdir($dir)) { if (is_file($rep.$f)) { $values[$f] = $f; } } Dropdown::showFromArray('img', $values); closedir($dir); Html::showToolTip(nl2br(__('Some types of items must be created so that the association can exist', 'archires'))); echo ""; echo "
"; echo "
"; Html::closeForm(); $query = ['FROM' => $this->getTable(), 'ORDER' => ['itemtype ASC', 'type ASC']]; if ($result = $DB->request($query)) { $number = count($result); if ($number) { $rand = mt_rand(); echo "
"; Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['num_displayed' => $number, 'container' => 'mass'.__CLASS__.$rand]; Html::showMassiveActions($massiveactionparams); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; while ($ligne = $result->next()) { $ID = $ligne["id"]; echo ""; echo ""; $class = $ligne["itemtype"]."Type"; $typeclass = new $class(); $typeclass->getFromDB($ligne["type"]); $name = ''; if (isset($typeclass->fields["name"])) { $name = $typeclass->fields["name"]; } echo ""; echo ""; echo ""; } echo "
"; Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); echo "".__('Item')."".__('Item type')."".__('Picture', 'archires')."
"; $PluginArchiresArchires = new PluginArchiresArchires(); $item = new $ligne["itemtype"](); Html::showMassiveActionCheckBox(__CLASS__, $ID); echo "".$item->getTypeName()."".$name."\"".$ligne["img"]."\""; echo "
"; $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); echo "
"; Html::closeForm(); } } } function displayItemImage($type,$itemtype,$test) { global $DB; $path = ""; if ($test) $path="../"; $image_name = $path."pics/nothing.png"; $query = ['FROM' => 'glpi_plugin_archires_imageitems', 'WHERE' => ['itemtype' => $itemtype]]; if ($result = $DB->request($query)) { while ($ligne= $result->next()) { $config_img = $ligne["img"]; if ($type == $ligne["type"]) { $image_name = $path."pics/$config_img"; } } } return $image_name; } function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } }