Html::scriptEnd PHP Method

scriptEnd() static public method

Generates a script tag inline
static public scriptEnd ( ) : mixed
return mixed depending on the settings of scriptStart() either a script tag or null
    static function scriptEnd()
    {
        $buffer = ob_get_clean();
        $buffer = "\$( document ).ready(function() {\n" . $buffer . "\n});";
        return Html::scriptBlock($buffer);
    }

Usage Example

示例#1
0
 /**
  * Print a nice HTML head for every page
  *
  * @param $title     title of the page
  * @param $url       not used anymore (default '')
  * @param $sector    sector in which the page displayed is (default 'none')
  * @param $item      item corresponding to the page displayed (default 'none')
  * @param $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 (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;
             }
         }
         //  PLUGINS
         //          if (isset($PLUGIN_HOOKS["menu_entry"]) && count($PLUGIN_HOOKS["menu_entry"])) {
         //             $plugins = array();
         //
         //             foreach  ($PLUGIN_HOOKS["menu_entry"] as $plugin => $active) {
         //                if ($active) { // true or a string
         //                   $plugins[$plugin] = Plugin::getInfo($plugin);
         //                }
         //             }
         //
         //             if (count($plugins)) {
         //                $list = array();
         //
         //                foreach ($plugins as $key => $val) {
         //                   $list[$key] = $val["name"];
         //                }
         //                asort($list);
         //
         //                foreach ($list as $key => $val) {
         //                   $menu['plugins']['content'][$key]['title'] = $val;
         //                   $menu['plugins']['content'][$key]['page']  = '/plugins/'.$key.'/';
         //
         //                   if (is_string($PLUGIN_HOOKS["menu_entry"][$key])) {
         //                      $menu['plugins']['content'][$key]['page'] .= $PLUGIN_HOOKS["menu_entry"][$key];
         //                   }
         //
         //                   // Set default link for plugins
         //                   if (!isset($menu['plugins']['default'])) {
         //                      $menu['plugins']['default'] = $menu['plugins']['content'][$key]['page'];
         //                   }
         //
         //                   if (($sector == "plugins")
         //                      && ($item == $key)) {
         //
         //                      if (isset($PLUGIN_HOOKS["submenu_entry"][$key])
         //                         && is_array($PLUGIN_HOOKS["submenu_entry"][$key])) {
         //
         //                         foreach ($PLUGIN_HOOKS["submenu_entry"][$key] as $name => $link) {
         //                            // New complete option management
         //                            if ($name == "options") {
         //                               $menu['plugins']['content'][$key]['options'] = $link;
         //                            } else { // Keep it for compatibility
         //
         //                               if (is_array($link)) {
         //                                  // Simple link option
         //                                  if (isset($link[$option])) {
         //                                     $menu['plugins']['content'][$key]['links'][$name]
         //                                                    ='/plugins/'.$key.'/'.$link[$option];
         //                                  }
         //                               } else {
         //                                  $menu['plugins']['content'][$key]['links'][$name]
         //                                                    ='/plugins/'.$key.'/'.$link;
         //                               }
         //                            }
         //                         }
         //                      }
         //                   }
         //                }
         //             }
         //          }
         $_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') . "\"  alt=\"" . __s('Logout') . "\" class='button-icon' />";
     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') . "\"  alt=\"" . __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') . "\"  alt=\"" . __s('Load a bookmark') . "\" class='button-icon' />";
     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') . "\"  alt=\"" . __s('Help') . "\" class='button-icon' />";
     "</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
     echo "<div id='show_all_menu' class='invisible'>";
     $items_per_columns = 15;
     $i = -1;
     foreach ($menu as $part => $data) {
         if (isset($data['content']) && count($data['content'])) {
             echo "<table class='all_menu_block'>";
             $link = "#";
             if (isset($data['default']) && !empty($data['default'])) {
                 $link = $CFG_GLPI["root_doc"] . $data['default'];
             }
             echo "<tr><td class='tab_bg_1 b'>";
             echo "<a href='{$link}' title=\"" . $data['title'] . "\" class='itemP'>" . $data['title'] . "</a>";
             echo "</td></tr>";
             $i++;
             // list menu item
             foreach ($data['content'] as $key => $val) {
                 /*if ($i > $items_per_columns) {
                      $i = 0;
                      echo "</table></td><td class='top'><table>";
                   }*/
                 if (isset($val['page']) && isset($val['title'])) {
                     echo "<tr><td><a href='" . $CFG_GLPI["root_doc"] . $val['page'] . "'";
                     if (isset($data['shortcut']) && !empty($data['shortcut'])) {
                         echo " accesskey='" . $val['shortcut'] . "'";
                     }
                     echo ">" . $val['title'] . "</a></td></tr>\n";
                     $i++;
                 }
             }
             echo "</table>";
         }
     }
     echo "</div>";
     Html::scriptStart();
     echo self::jsGetElementbyID('show_all_menu') . ".dialog({\n         height: 'auto',\n         width: 'auto',\n         modal: true,\n         autoOpen: false\n         });";
     echo Html::scriptEnd();
     /// MENU ALL
     echo "<a href='#' onClick=\"" . self::jsGetElementbyID('show_all_menu') . ".dialog('open');\"\n            id='menu_all_button' class='button-icon'>";
     echo "</a>";
     echo "</div>";
     // 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'];
             // Without option case : only item links
         } else {
             if (isset($menu[$sector]['content'][$item]['links']) && is_array($menu[$sector]['content'][$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'>" . __('MySQL 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();
 }
All Usage Examples Of Html::scriptEnd
Html