Html::header PHP Method

header() static public method

Print a nice HTML head for every page
static public header ( $title, $url = '', $sector = "none", $item = "none", $option = "" )
$title title of the page
$url not used anymore (default '')
$sector sector in which the page displayed is (default 'none')
$item item corresponding to the page displayed (default 'none')
$option option corresponding to the page displayed (default '')
    static function header($title, $url = '', $sector = "none", $item = "none", $option = "")
    {
        global $CFG_GLPI, $PLUGIN_HOOKS, $HEADER_LOADED, $DB;
        // If in modal : display popHeader
        if (isset($_REQUEST['_in_modal']) && $_REQUEST['_in_modal']) {
            return self::popHeader($title, $url);
        }
        // Print a nice HTML-head for every page
        if ($HEADER_LOADED) {
            return;
        }
        $HEADER_LOADED = true;
        // Force lower case for sector and item
        $sector = strtolower($sector);
        $item = strtolower($item);
        self::includeHeader($title);
        $body_class = "layout_" . $_SESSION['glpilayout'];
        if (strpos($_SERVER['REQUEST_URI'], ".form.php") !== false && isset($_GET['id']) && $_GET['id'] > 0) {
            if (!CommonGLPI::isLayoutExcludedPage()) {
                $body_class .= " form";
            } else {
                $body_class = "";
            }
        }
        // Body
        echo "<body class='{$body_class}'>";
        // Generate array for menu and check right
        if (!isset($_SESSION['glpimenu']) || !is_array($_SESSION['glpimenu']) || count($_SESSION['glpimenu']) == 0) {
            // INVENTORY
            //don't change order in array
            $showallassets = false;
            $menu = self::getMenuInfos();
            // Permit to plugins to add entry to others sector !
            if (isset($PLUGIN_HOOKS["menu_toadd"]) && count($PLUGIN_HOOKS["menu_toadd"])) {
                foreach ($PLUGIN_HOOKS["menu_toadd"] as $plugin => $items) {
                    if (count($items)) {
                        foreach ($items as $key => $val) {
                            if (is_array($val)) {
                                foreach ($val as $k => $object) {
                                    $menu[$key]['types'][] = $object;
                                }
                            } else {
                                if (isset($menu[$key])) {
                                    $menu[$key]['types'][] = $val;
                                }
                            }
                        }
                    }
                }
            }
            foreach ($menu as $category => $datas) {
                if (isset($datas['types']) && count($datas['types'])) {
                    foreach ($datas['types'] as $type) {
                        if ($data = $type::getMenuContent()) {
                            // Multi menu entries management
                            if (isset($data['is_multi_entries']) && $data['is_multi_entries']) {
                                if (!isset($menu[$category]['content'])) {
                                    $menu[$category]['content'] = array();
                                }
                                $menu[$category]['content'] += $data;
                            } else {
                                $menu[$category]['content'][strtolower($type)] = $data;
                            }
                        }
                    }
                }
                // Define default link :
                if (isset($menu[$category]['content']) && count($menu[$category]['content'])) {
                    foreach ($menu[$category]['content'] as $val) {
                        if (isset($val['page'])) {
                            $menu[$category]['default'] = $val['page'];
                            break;
                        }
                    }
                }
            }
            $allassets = array('Computer', 'Monitor', 'Peripheral', 'NetworkEquipment', 'Phone', 'Printer');
            foreach ($allassets as $type) {
                if (isset($menu['assets']['content'][strtolower($type)])) {
                    $menu['assets']['content']['allassets']['title'] = __('Global');
                    $menu['assets']['content']['allassets']['shortcut'] = '';
                    $menu['assets']['content']['allassets']['page'] = '/front/allassets.php';
                    $menu['assets']['content']['allassets']['links']['search'] = '/front/allassets.php';
                    break;
                }
            }
            $_SESSION['glpimenu'] = $menu;
            // echo 'menu load';
        } else {
            $menu = $_SESSION['glpimenu'];
        }
        $already_used_shortcut = array('1');
        echo "<div id='header'>";
        echo "<div id='header_top'>";
        echo "<div id='c_logo'>";
        echo Html::link('', $CFG_GLPI["root_doc"] . "/front/central.php", array('accesskey' => '1', 'title' => __('Home')));
        echo "</div>";
        /// Prefs / Logout link
        echo "<div id='c_preference' >";
        echo "<ul>";
        echo "<li id='deconnexion'>";
        echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/logout.php";
        /// logout witout noAuto login for extauth
        if (isset($_SESSION['glpiextauth']) && $_SESSION['glpiextauth']) {
            echo "?noAUTO=1";
        }
        echo "' title=\"" . __s('Logout') . "\">";
        echo "<span id='logout_icon' title=\"" . __s('Logout') . "\"  class='button-icon'></span>";
        echo "</a>";
        echo "</li>\n";
        echo "<li id='preferences_link'><a href='" . $CFG_GLPI["root_doc"] . "/front/preference.php' title=\"" . __s('My settings') . "\">";
        echo "<span id='preferences_icon' title=\"" . __s('My settings') . "\"  class='button-icon'></span>";
        // check user id : header used for display messages when session logout
        if (Session::getLoginUserID()) {
            echo "<span id='myname'>";
            echo formatUserName(0, $_SESSION["glpiname"], $_SESSION["glpirealname"], $_SESSION["glpifirstname"], 0, 20);
            echo "</span>";
        }
        echo "</a></li>";
        /// Bookmark load
        echo "<li id='bookmark_link'>";
        Ajax::createIframeModalWindow('loadbookmark', $CFG_GLPI["root_doc"] . "/front/bookmark.php?action=load", array('title' => __('Load a bookmark'), 'reloadonclose' => true));
        echo "<a href='#' onClick=\"" . Html::jsGetElementbyID('loadbookmark') . ".dialog('open');\">";
        echo "<span id='bookmark_icon' title=\"" . __s('Load a bookmark') . "\"  class='button-icon'></span>";
        echo "</a></li>";
        echo "<li id='help_link'><a href='" . (empty($CFG_GLPI["central_doc_url"]) ? "http://glpi-project.org/help-central" : $CFG_GLPI["central_doc_url"]) . "' target='_blank' title=\"" . __s('Help') . "\">" . "<span id='help_icon' title=\"" . __s('Help') . "\"  class='button-icon'></span>";
        echo "</a></li>";
        echo "<li id='language_link'><a href='" . $CFG_GLPI["root_doc"] . "/front/preference.php?forcetab=User\$1' title=\"" . addslashes(Dropdown::getLanguageName($_SESSION['glpilanguage'])) . "\">" . Dropdown::getLanguageName($_SESSION['glpilanguage']) . "</a></li>";
        /// Search engine
        echo "<li id='c_recherche'>\n";
        if ($CFG_GLPI['allow_search_global']) {
            echo "<form method='get' action='" . $CFG_GLPI["root_doc"] . "/front/search.php'>\n";
            echo "<span id='champRecherche'><input size='15' type='text' name='globalsearch'\n                                         placeholder='" . __s('Search') . "'>";
            echo "</span>";
            Html::closeForm();
        }
        echo "</li>";
        echo "</ul>";
        echo "</div>\n";
        echo "</div>";
        ///Main menu
        echo "<div id='c_menu'>";
        echo "<ul id='menu'>";
        // Get object-variables and build the navigation-elements
        $i = 1;
        foreach ($menu as $part => $data) {
            if (isset($data['content']) && count($data['content'])) {
                $menu_class = "";
                if (isset($menu[$sector]) && $menu[$sector]['title'] == $data['title']) {
                    $menu_class = "active";
                }
                echo "<li id='menu{$i}' class='{$menu_class}' onmouseover=\"javascript:menuAff('menu{$i}','menu');\" >";
                $link = "#";
                if (isset($data['default']) && !empty($data['default'])) {
                    $link = $CFG_GLPI["root_doc"] . $data['default'];
                }
                if (Toolbox::strlen($data['title']) > 14) {
                    $data['title'] = Toolbox::substr($data['title'], 0, 14) . "...";
                }
                echo "<a href='{$link}' class='itemP'>" . $data['title'] . "</a>";
                echo "<ul class='ssmenu'>";
                // list menu item
                foreach ($data['content'] as $key => $val) {
                    $menu_class = "";
                    $tmp_active_item = explode("/", $item);
                    $active_item = array_pop($tmp_active_item);
                    if (isset($menu[$sector]['content']) && isset($menu[$sector]['content'][$active_item]) && isset($val['title']) && $menu[$sector]['content'][$active_item]['title'] == $val['title']) {
                        $menu_class = "active";
                    }
                    if (isset($val['page']) && isset($val['title'])) {
                        echo "<li class='{$menu_class}'><a href='" . $CFG_GLPI["root_doc"] . $val['page'] . "'";
                        if (isset($val['shortcut']) && !empty($val['shortcut'])) {
                            if (!isset($already_used_shortcut[$val['shortcut']])) {
                                echo " accesskey='" . $val['shortcut'] . "'";
                                $already_used_shortcut[$val['shortcut']] = $val['shortcut'];
                            }
                            echo ">" . Toolbox::shortcut($val['title'], $val['shortcut']) . "</a></li>\n";
                        } else {
                            echo ">" . $val['title'] . "</a></li>\n";
                        }
                    }
                }
                echo "</ul></li>";
                $i++;
            }
        }
        echo "</ul>";
        // #menu
        // Display MENU ALL
        self::displayMenuAll($menu);
        // End navigation bar
        // End headline
        //  Le fil d ariane
        echo "<div id='c_ssmenu2' >";
        echo "<ul>";
        // Display item
        echo "<li class='breadcrumb_item'><a href='" . $CFG_GLPI["root_doc"] . "/front/central.php' title=\"" . __s('Home') . "\">" . __('Home') . "</a></li>";
        if (isset($menu[$sector])) {
            $link = "/front/central.php";
            if (isset($menu[$sector]['default'])) {
                $link = $menu[$sector]['default'];
            }
            echo "<li class='breadcrumb_item'><a href='" . $CFG_GLPI["root_doc"] . $link . "' title=\"" . $menu[$sector]['title'] . "\">" . $menu[$sector]['title'] . "</a></li>";
        }
        if (isset($menu[$sector]['content'][$item])) {
            // Title
            $with_option = false;
            if (!empty($option) && isset($menu[$sector]['content'][$item]['options'][$option]['title']) && isset($menu[$sector]['content'][$item]['options'][$option]['page'])) {
                $with_option = true;
            }
            if (isset($menu[$sector]['content'][$item]['page'])) {
                echo "<li class='breadcrumb_item'><a href='" . $CFG_GLPI["root_doc"] . $menu[$sector]['content'][$item]['page'] . "' " . ($with_option ? "" : "class='here'") . " title=\"" . $menu[$sector]['content'][$item]['title'] . "\" >" . $menu[$sector]['content'][$item]['title'] . "</a>" . "</li>";
            }
            if ($with_option) {
                echo "<li class='breadcrumb_item'><a href='" . $CFG_GLPI["root_doc"] . $menu[$sector]['content'][$item]['options'][$option]['page'] . "' class='here' title=\"" . $menu[$sector]['content'][$item]['options'][$option]['title'] . "\" >";
                echo self::resume_name($menu[$sector]['content'][$item]['options'][$option]['title'], 17);
                echo "</a></li>";
            }
            $links = array();
            // Item with Option case
            if (!empty($option) && isset($menu[$sector]['content'][$item]['options'][$option]['links']) && is_array($menu[$sector]['content'][$item]['options'][$option]['links'])) {
                $links = $menu[$sector]['content'][$item]['options'][$option]['links'];
            } else {
                if (isset($menu[$sector]['content'][$item]['links']) && is_array($menu[$sector]['content'][$item]['links'])) {
                    // Without option case : only item links
                    $links = $menu[$sector]['content'][$item]['links'];
                }
            }
            // Add item
            echo "<li class='icons_block'>";
            echo "<span>";
            if (isset($links['add'])) {
                echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_add.png", array('alt' => __('Add'), 'url' => $CFG_GLPI["root_doc"] . $links['add']));
            } else {
                echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_add_off.png", array('alt' => __('Add')));
            }
            echo "</span>";
            // Search Item
            echo "<span>";
            if (isset($links['search'])) {
                echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_search.png", array('alt' => __('Search'), 'url' => $CFG_GLPI["root_doc"] . $links['search']));
            } else {
                echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_search_off.png", array('alt' => __('Search')));
            }
            echo "</span>";
            // Links
            if (count($links) > 0) {
                foreach ($links as $key => $val) {
                    switch ($key) {
                        case "add":
                        case "search":
                            break;
                        case "template":
                            echo "<span>";
                            echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_addtemplate.png", array('alt' => __('Manage templates...'), 'url' => $CFG_GLPI["root_doc"] . $val));
                            echo "</span>";
                            break;
                        case "showall":
                            echo "<span>";
                            echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_showall.png", array('alt' => __('Show all'), 'url' => $CFG_GLPI["root_doc"] . $val));
                            echo "</span>";
                            break;
                        case "summary":
                            echo "<span>";
                            echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_show.png", array('alt' => __('Summary'), 'url' => $CFG_GLPI["root_doc"] . $val));
                            echo "</span>";
                            break;
                        case "config":
                            echo "<span>";
                            echo Html::image($CFG_GLPI["root_doc"] . "/pics/menu_config.png", array('alt' => __('Setup'), 'url' => $CFG_GLPI["root_doc"] . $val));
                            echo "</span>";
                            break;
                        default:
                            echo "<span>" . Html::link($key, $CFG_GLPI["root_doc"] . $val) . "</span>";
                            break;
                    }
                }
            }
            echo "</li>";
        } else {
            echo "<li>&nbsp;</li>";
        }
        // Add common items
        // Profile selector
        // check user id : header used for display messages when session logout
        if (Session::getLoginUserID()) {
            self::showProfileSelecter($CFG_GLPI["root_doc"] . "/front/central.php");
        }
        echo "</ul>";
        echo "</div>";
        echo "</div>\n";
        // fin header
        echo "<div id='page' >";
        if ($DB->isSlave() && !$DB->first_connection) {
            echo "<div id='dbslave-float'>";
            echo "<a href='#see_debug'>" . __('SQL replica: read only') . "</a>";
            echo "</div>";
        }
        // Back to top
        Html::scriptStart();
        echo "\$(document).ready(function(){\n               BackToTop({\n               text : '^',\n               class: 'vsubmit',\n               autoShow : true,\n               timeEffect : 100,\n               autoShowOffset : '0',\n               appearMethod : '',\n               effectScroll : 'linear'\n               });\n            });";
        echo Html::scriptEnd();
        // call static function callcron() every 5min
        CronTask::callCron();
        self::displayMessageAfterRedirect();
    }

Usage Example

Esempio n. 1
0
    /**
     *  HTML for logged in users
     */
    private function loggendIn($css, $data)
    {
        $mail = '';
        if (isset($_SESSION['__sessiondata']['email'])) {
            $mail = '<span style="font-size:10px;">';
            $mail .= $_SESSION['__sessiondata']['email'];
            $mail .= '</span>';
        }
        $twitterUserForm = '';
        $shortenerForm = 'URL shortener: ';
        if ($data) {
            if (isset($data->twitter) && $data->twitter) {
                foreach ($data->twitter as $tw) {
                    $twitterUserForm .= '<input type="checkbox" name="postdata[twitterUser][]" value="' . $tw['username'] . '" style="float:none;" ><span style="margin-right:3px;">' . $tw['username'] . '</span>';
                    // . '<br />';
                }
            }
            if (isset($data->shortener) && $data->shortener) {
                $i = 1;
                foreach ($data->shortener as $sh) {
                    $shortenerForm .= '<input type="radio" name="postdata[shortener]" value="' . $sh['service'] . '|' . $sh['username'] . '" ' . ($i === 1 ? 'checked=checked' : '') . ' style="margin:0;float:left;" /><span style="margin-right:3px;">' . $sh['username'] . ' ' . $sh['service'] . '</span>';
                    $i++;
                }
            }
        }
        // get Header
        $html = Html::header($css, $mail);
        $html .= <<<HTMLSTUFF
<div id="socialRouter_main">
    <form id="socialRouterForm" name="socialRouterForm" accept-charset="utf-8" action="http://sr2.soluch.at/load/delegateMessage/" method="post" target="_blank" >
        <textarea id="sr_textarea" name="postdata[message]" cols="35" rows="3" >
    
    {$data->shorturl}
    
    </textarea>
    
    {$shortenerForm}
    
    <div style="float:right;">chars used: <span id="sr_charCount" style="color:#D94432;font-weight:bold;"></span></div>
    <hr />
        <!--input id="twitteruser" type="text" maxlength="30" name="postdata[twitteruser]" value="php_live" /-->
        <a href="http://sr2.soluch.at/twitter/add/" target="_blank" >add a twitter account</a><br />
    
        {$twitterUserForm}
    
        <br />
        <hr />
    \t<input type="submit" value="Route" id="submitSocial" />
    </form>
    
    
    <div id="otherContent">
    </div>
</div>
HTMLSTUFF;
        // get Footer
        $html .= Html::footer();
        return $html;
    }
All Usage Examples Of Html::header
Html