. @package archires @author Nelly Mahu-Lasson, Xavier Caillaud @copyright Copyright (c) 2016-2021 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/archires @since version 2.2 -------------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } class PluginArchiresVlanColor extends CommonDBTM { static $rightname = "plugin_archires"; function getFromDBbyVlan($vlan) { global $DB; $query = ['FROM' => $this->getTable(), 'WHERE' => ['vlans_id' => $vlan]]; 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; } return false; } function addVlanColor($vlan,$color) { global $DB; if ($vlan != '-1') { if ($this->getfromDBbyVlan($vlan)) { $this->update(['id' => $this->fields['id'], 'color' => $color]); } else { $this->add(['vlans_id' => $vlan, 'color' => $color]); } } else { $query = ['FROM' => 'glpi_vlans']; $result = $DB->request($query); $i = 0; while ($i < count($result)) { $vlan_table=$DB->result($result, $i, "id"); if ($this->getfromDBbyVlan($vlan_table)) { $this->update(['id' => $this->fields['id'], 'color' => $color]); } else { $this->add(['vlans_id' => $vlan_table, 'color' => $color]); } $i++; } } } function showConfigForm($canupdate=false) { global $DB; if ($canupdate) { echo "
"; echo "
"; echo ""; echo ""; echo ""; echo "
"; echo __('Associate colors to VLANs', 'archires')."
"; $this->dropdownVlan(); echo ""; echo " "; Html::showToolTip(nl2br(__('Please use this color format', 'archires')), ['link' => 'http://www.graphviz.org/doc/info/colors.html', 'linktarget' => '_blank']); echo "
"; Html::closeForm(); } $query = ['FROM' => $this->getTable(), 'ORDER' => 'vlans_id ASC']; if ($result = $DB->request($query)) { $number = count($result); if ($number != 0) { echo "
"; if ($canupdate) { $rand = mt_rand(); Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['num_displayed' => $number, 'container' => 'mass'.__CLASS__.$rand]; Html::showMassiveActions($massiveactionparams); } echo ""; echo ""; if ($canupdate) { echo ""; } echo ""; echo ""; echo ""; while($ligne = $result->next()) { $ID = $ligne["id"]; echo ""; if ($canupdate) { echo ""; } echo ""; echo ""; echo ""; } echo "
"; Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); echo "".__('VLAN')."".__('Color', 'archires')."
"; Html::showMassiveActionCheckBox(__CLASS__, $ID); echo "".Dropdown::getDropdownName("glpi_vlans", $ligne["vlans_id"])."".$ligne["color"]."
"; if ($canupdate) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); } echo "
"; Html::closeForm(); } } } function dropdownVlan() { global $DB; $colors = []; foreach($DB->request("glpi_plugin_archires_vlancolors") as $color) { $colors[] = $color['vlans_id']; } $query = ['FROM' => 'glpi_vlans', 'WHERE' => ['NOT' => ['id' => [implode("','",$colors)]]], 'ORDER' => 'name']; $result = $DB->request($query); if (count($result)) { $values = [1 => __('All VLANs', 'archires')]; while ($data = $result->next()) { $values[$data['id']] = $data["name"]; } Dropdown::showFromArray('vlans_id', $values, ['width' => '80%', 'display_emptychoice' => true]); } } function getVlanbyNetworkPort ($ID) { global $DB; $query = ['SELECT' => 'glpi_vlans.id', 'FROM' => ['glpi_vlans', 'glpi_networkports_vlans'], 'WHERE' => ['vlans_id' => 'glpi_vlans.id', 'networkports_id' => $ID]]; if ($result = $DB->request($query)) { $data_vlan = $result->next(); $vlan = $data_vlan["id"] ; } return $vlan; } function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } }