function plugin_init_routetables() { global $PLUGIN_HOOKS, $CFG_GLPI; $PLUGIN_HOOKS['csrf_compliant']['routetables'] = true; $PLUGIN_HOOKS['change_profile']['routetables'] = array('PluginRoutetablesProfile', 'changeProfile'); $PLUGIN_HOOKS['assign_to_ticket']['routetables'] = true; if (Session::getLoginUserID()) { Plugin::registerClass('PluginRoutetablesRoutetable', array('document_types' => true, 'ticket_types' => true, 'helpdesk_visible_types' => true)); Plugin::registerClass('PluginRoutetablesProfile', array('addtabon' => 'Profile')); // Display a menu entry ? if (plugin_routetables_haveRight("routetables", "r")) { $PLUGIN_HOOKS['menu_entry']['routetables'] = 'front/routetable.php'; $PLUGIN_HOOKS['submenu_entry']['routetables']['search'] = 'front/routetable.php'; } if (plugin_routetables_haveRight("routetables", "w")) { $PLUGIN_HOOKS['submenu_entry']['routetables']['add'] = 'front/routetable.form.php?new=1'; $PLUGIN_HOOKS['use_massive_action']['routetables'] = 1; } // Import from Data_Injection plugin $PLUGIN_HOOKS['migratetypes']['routetables'] = 'plugin_datainjection_migratetypes_routetables'; if (class_exists('PluginRoutetablesRoutetable_Item')) { // only if plugin activated $PLUGIN_HOOKS['pre_item_purge']['routetables'] = array('Profile' => array('PluginRoutetablesProfile', 'purgeProfiles')); $PLUGIN_HOOKS['plugin_datainjection_populate']['routetables'] = 'plugin_datainjection_populate_routetables'; } // End init, when all types are registered $PLUGIN_HOOKS['post_init']['routetables'] = 'plugin_routetables_postinit'; } }
/** * Show routetables associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated routetables must be displayed * @param $withtemplate (default '') * */ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_routetables_haveRight('routetables', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginRoutetablesRoutetable'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_routetables_routetables_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_routetables_routetables`.`name` AS assocName,\n `glpi_plugin_routetables_routetables`.*\n FROM `glpi_plugin_routetables_routetables_items`\n LEFT JOIN `glpi_plugin_routetables_routetables`\n ON (`glpi_plugin_routetables_routetables_items`.`plugin_routetables_routetables_id`=`glpi_plugin_routetables_routetables`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_routetables_routetables`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_routetables_routetables_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_routetables_routetables_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_routetables_routetables", '', '', false); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $routetables = array(); $routetable = new PluginRoutetablesRoutetable(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $routetables[$data['id']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_routetables_routetables", '', $entities, false); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_routetables_routetables`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_routetables_haveRight('routetables', 'r') && $nb > count($used)) { echo "<form name='routetable_form{$rand}' id='routetable_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginRoutetablesRoutetable') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } $routetable->dropdownRouteTables("plugin_routetables_routetables_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a routing table', 'routetables') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Network') . "</th>"; echo "<th>" . __('Subnet mask') . "</th>"; echo "<th>" . __('Gateway') . "</th>"; echo "<th>" . __('Metric', 'routetables') . "</th>"; echo "<th>" . __('Interface') . "</th>"; echo "<th>" . __('Persistance', 'routetables') . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginRoutetablesRoutetable', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($routetables as $data) { $routetableID = $data["id"]; $link = NOT_AVAILABLE; if ($routetable->getFromDB($routetableID)) { $link = $routetable->getLink(); } Session::addToNavigateListItems('PluginRoutetablesRoutetable', $routetable); $used[$routetableID] = $routetableID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["destination"] . "</td>"; echo "<td class='center'>" . $data["netmask"] . "</td>"; echo "<td class='center'>" . $data["gateway"] . "</td>"; echo "<td class='center'>" . $data["metric"] . "</td>"; echo "<td class='center'>" . $data["interface"] . "</td>"; echo "<td class='center'>" . Dropdown::getYesNo($data["persistence"]) . "</td>"; echo "<td class='center'>" . $data["comment"] . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
public static function canView() { return plugin_routetables_haveRight('routetables', 'r'); }
function plugin_routetables_getAddSearchOptions($itemtype) { $sopt = array(); if (in_array($itemtype, PluginRoutetablesRoutetable::getTypes(true))) { if (plugin_routetables_haveRight("routetables", "r")) { $sopt[5110]['table'] = 'glpi_plugin_routetables_routetables'; $sopt[5110]['field'] = 'name'; $sopt[5110]['name'] = PluginRoutetablesRoutetable::getTypeName(2) . " - " . __('Name'); $sopt[5110]['forcegroupby'] = true; $sopt[5110]['massiveaction'] = false; $sopt[5110]['datatype'] = 'itemlink'; $sopt[5110]['itemlink_type'] = 'PluginRoutetablesRoutetable'; $sopt[5110]['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_routetables_routetables_items', 'joinparams' => array('jointype' => 'itemtype_item'))); $sopt[5111]['table'] = 'glpi_plugin_routetables_routetables'; $sopt[5111]['field'] = 'destination'; $sopt[5111]['name'] = PluginRoutetablesRoutetable::getTypeName(2) . " - " . __('Network'); $sopt[5111]['forcegroupby'] = true; $sopt[5111]['massiveaction'] = false; $sopt[5111]['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_routetables_routetables_items', 'joinparams' => array('jointype' => 'itemtype_item'))); $sopt[5112]['table'] = 'glpi_plugin_routetables_routetables'; $sopt[5112]['field'] = 'gateway'; $sopt[5112]['name'] = PluginRoutetablesRoutetable::getTypeName(2) . " - " . __('Gateway'); $sopt[5112]['forcegroupby'] = true; $sopt[5112]['massiveaction'] = false; $sopt[5112]['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_routetables_routetables_items', 'joinparams' => array('jointype' => 'itemtype_item'))); } } return $sopt; }