Example #1
0
function plugin_init_racks()
{
    global $PLUGIN_HOOKS, $CFG_GLPI;
    $PLUGIN_HOOKS['csrf_compliant']['racks'] = true;
    $PLUGIN_HOOKS['change_profile']['racks'] = array('PluginRacksProfile', 'changeProfile');
    if (class_exists('PluginRacksRack')) {
        // only if plugin activated
        $PLUGIN_HOOKS['pre_item_purge']['racks'] = array('Profile' => array('PluginRacksProfile', 'purgeProfiles'));
    }
    Plugin::registerClass('PluginRacksRack', array('document_types' => true, 'unicity_types' => true, 'linkgroup_tech_types' => true, 'linkuser_tech_types' => true, 'infocom_types' => true));
    Plugin::registerClass('PluginRacksProfile', array('addtabon' => 'Profile'));
    if (class_exists('PluginAppliancesAppliance')) {
        PluginAppliancesAppliance::registerType('PluginRacksRack');
    }
    if (class_exists('PluginManufacturersimportsConfig')) {
        PluginManufacturersimportsConfig::registerType('PluginRacksRack');
    }
    if (class_exists('PluginTreeviewConfig')) {
        PluginTreeviewConfig::registerType('PluginRacksRack');
        $PLUGIN_HOOKS['treeview']['PluginRacksRack'] = '../racks/pics/racks.png';
    }
    if (class_exists('PluginPositionsPosition')) {
        PluginPositionsPosition::registerType('PluginRacksRack');
    }
    if (Session::getLoginUserID()) {
        // Display a menu entry ?
        if (plugin_racks_haveRight("racks", "r")) {
            $PLUGIN_HOOKS['menu_entry']['racks'] = 'front/rack.php';
            $PLUGIN_HOOKS['submenu_entry']['racks']['search'] = 'front/rack.php';
            $PLUGIN_HOOKS['submenu_entry']['racks']['add'] = 'front/setup.templates.php?add=1';
        }
        if (plugin_racks_haveRight("model", "r")) {
            $PLUGIN_HOOKS['submenu_entry']['racks']['template'] = 'front/setup.templates.php?add=0';
            $PLUGIN_HOOKS['submenu_entry']['racks']["<img  src='" . $CFG_GLPI["root_doc"] . "/pics/menu_showall.png' title=\"" . __('Equipments models specifications', 'racks') . "\" alt=\"" . __('Equipments models specifications', 'racks') . "\">"] = 'front/itemspecification.php';
        }
        if (plugin_racks_haveRight("racks", "r")) {
            $PLUGIN_HOOKS['submenu_entry']['racks']['config'] = 'front/config.form.php';
            $PLUGIN_HOOKS['use_massive_action']['racks'] = 1;
        }
        // Config page
        if (plugin_racks_haveRight("racks", "w") || Session::haveRight("config", "w")) {
            $PLUGIN_HOOKS['config_page']['racks'] = 'front/config.form.php';
        }
        // Add specific files to add to the header : javascript or css
        //$PLUGIN_HOOKS['add_javascript']['example']="example.js";
        $PLUGIN_HOOKS['add_css']['racks'] = "racks.css";
        $PLUGIN_HOOKS['post_init']['racks'] = 'plugin_racks_postinit';
        $PLUGIN_HOOKS['reports']['racks'] = array('front/report.php' => __("Report - Bays management", "racks"));
    }
}
 static function canView()
 {
     return plugin_racks_haveRight('model', 'r');
 }
Example #3
0
function plugin_racks_getAddSearchOptions($itemtype)
{
    $sopt = array();
    if (in_array($itemtype, PluginRacksRack::getTypes(true))) {
        if (plugin_racks_haveRight("racks", "r")) {
            $sopt[4460]['table'] = 'glpi_plugin_racks_racks';
            $sopt[4460]['field'] = 'name';
            $sopt[4460]['name'] = _n('Rack enclosure', 'Rack enclosures', 2, 'racks') . " - " . __('Name');
            $sopt[4460]['forcegroupby'] = '1';
            $sopt[4460]['datatype'] = 'itemlink';
            $sopt[4460]['itemlink_type'] = 'PluginRacksRack';
            $sopt[4460]['massiveaction'] = false;
        }
    }
    return $sopt;
}
Example #4
0
 /**
  * Show rack associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated rack 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_racks_haveRight('racks', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginRacksRack');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $itemtype = $item->getType() . "Model";
     $query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n                       `glpi_plugin_racks_racks_items`.`faces_id`,\n                       `glpi_plugin_racks_racks_items`.`position`,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_racks_racks`.`name` AS assocName,\n                       `glpi_plugin_racks_racks`.*\n                FROM `glpi_plugin_racks_racks_items`\n                LEFT JOIN `glpi_plugin_racks_racks`\n                 ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $racks = array();
     $rack = new PluginRacksRack();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $racks[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     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>" . __('Disposition', 'racks') . "</th>";
     echo "<th>" . __('Position', 'racks') . "</th>";
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . __('Place', 'racks') . "</th>";
     echo "<th>" . __('Manufacturer') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($racks as $data) {
             $rackID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($rack->getFromDB($rackID)) {
                 $link = $rack->getLink();
             }
             Session::addToNavigateListItems('PluginRacksRack', $rackID);
             $used[$rackID] = $rackID;
             $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>";
             }
             if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) {
                 $faces_id = __('Front', 'racks');
             } else {
                 $faces_id = _x('Rack enclosure', 'Back', 'racks');
             }
             echo "<td class='center'>" . $faces_id . "</td>";
             echo "<td class='center'>" . $data["position"] . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }