Example #1
0
function plugin_init_treeview()
{
    global $PLUGIN_HOOKS, $CFG_GLPI;
    $PLUGIN_HOOKS['csrf_compliant']['treeview'] = true;
    Plugin::registerClass('PluginTreeviewPreference', array('addtabon' => array('Preference')));
    Plugin::registerClass('PluginTreeviewProfile', array('addtabon' => array('Profile')));
    $PLUGIN_HOOKS['change_profile']['treeview'] = array('PluginTreeviewProfile', 'changeprofile');
    if (Session::getLoginUserID()) {
        Plugin::registerClass('PluginTreeviewProfile', array('addtabon' => 'Profile'));
        if (Session::haveRight("plugin_treeview", READ)) {
            $PLUGIN_HOOKS['menu_toadd']['treeview'] = array('tools' => 'PluginTreeviewConfig');
            $PLUGIN_HOOKS['pre_item_purge']['treeview'] = array('Profile' => array('PluginTreeviewProfile', 'cleanProfiles'));
            if (isset($_SESSION["glpi_plugin_treeview_loaded"]) && $_SESSION["glpi_plugin_treeview_loaded"] == 1 && class_exists('PluginTreeviewConfig')) {
                foreach (PluginTreeviewConfig::getTypes() as $type) {
                    $PLUGIN_HOOKS['item_update']['treeview'][$type] = 'plugin_item_update_treeview';
                    $PLUGIN_HOOKS['item_delete']['treeview'][$type] = 'plugin_treeview_reload';
                    $PLUGIN_HOOKS['item_restore']['treeview'][$type] = 'plugin_treeview_reload';
                }
            }
            if ($_SERVER['PHP_SELF'] == $CFG_GLPI["root_doc"] . "/front/central.php" && (!isset($_SESSION["glpi_plugin_treeview_loaded"]) || $_SESSION["glpi_plugin_treeview_loaded"] == 0) && isset($_SESSION["glpi_plugin_treeview_preference"]) && $_SESSION["glpi_plugin_treeview_preference"] == 1) {
                Html::redirect($CFG_GLPI["root_doc"] . "/plugins/treeview/index.php");
            }
            if ($_SERVER['PHP_SELF'] == $CFG_GLPI["root_doc"] . "/logout.php" && (isset($_SESSION["glpi_plugin_treeview_loaded"]) && $_SESSION["glpi_plugin_treeview_loaded"] == 1 && class_exists('PluginTreeviewConfig'))) {
                $config = new PluginTreeviewConfig();
                $config->hideTreeview();
            }
            // Add specific files to add to the header : javascript or css
            $PLUGIN_HOOKS['add_javascript']['treeview'] = "dtree.js";
            $PLUGIN_HOOKS['add_css']['treeview'] = "dtree.css";
            $PLUGIN_HOOKS['add_javascript']['treeview'] = "functions.js";
            $PLUGIN_HOOKS['add_css']['treeview'] = "style.css";
            $PLUGIN_HOOKS['add_javascript']['treeview'] = "treeview.js";
            $PLUGIN_HOOKS['add_css']['treeview'] = "treeview.css";
        }
        // Config page
        if (Session::haveRight("plugin_treeview", UPDATE) || Session::haveRight("config", UPDATE)) {
            $PLUGIN_HOOKS['config_page']['treeview'] = 'front/config.form.php';
        }
    }
}