📄 layout.php
字号:
<?php/******************************************************************** * Copyright (c) 2006, Graham P Phillips * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************//* Compute $relPathToLaddieRoot and $scriptBase. * We compute these values to support PHP files being in arbitrary * sub-directories. The value $relPathToLaddieRoot is the relative path from * the user's URL to the Laddie Root directory. The value $scriptBase is the * sub-directory where the PHP files are relative to the laddie root directory. * For example, if the user's URL is * http://64.170.104.188/~graham/web/cgi-bin/howto/setup_email.php then * $relPathToLaddieRoot will be "../..", which is the relative path to 'web', * and $scriptBase will be 'cgi-bin', which gets us from 'web' to the first * level directory of PHP files. * * We assume the following file structure: * <LaddieRootDir>/alarmstyle.css * <LaddieRootDir>/cgi-bin/layout.php * <LaddieRootDir>/cgi-bin/xxx.php * <LaddieRootDir>/cgi-bin/subdir_xxx/xxx.php * where xxx.php are other PHP files and subdir_xxx are other sub-directories. */$scriptFile = $_SERVER['SCRIPT_FILENAME']; $scriptDir = dirname($scriptFile); $thisFile = __FILE__; $thisDir = dirname($thisFile);$scriptBase = basename($thisDir); /* typically 'cgi-bin' */$laddieRoot = dirname($thisDir);$relPathToLaddieRoot = calc_delta_dir($scriptDir, $laddieRoot);/* To create a new page in the menu system: * a) Modify the following data structure. * The data structure is an array of arrays. * The top-level array is the 1st level menu, * and the second-level arrays are the 2nd level menus * corresponding to each 1st level menu. * b) Add a new php page, eg, setup_wizard.php. * c) Modify the php page to call display_page() * with the key of the 1st level menu, eg 'Setup' * and the key of the 2nd level menu, eg 'Wizard'. * See setup_wizard.php for an example. */$menu_system = array( 'Setup' => array( 'Network' => "$relPathToLaddieRoot/$scriptBase/setup_network.php", 'SNMP' => "$relPathToLaddieRoot/$scriptBase/setup_snmp.php", 'Alarm' => "$relPathToLaddieRoot/$scriptBase/setup_alarm.php"), 'Status' => array( 'Zone Status' => "$relPathToLaddieRoot/$scriptBase/status.php"), 'Reports' => array( 'View Logs' => "$relPathToLaddieRoot/$scriptBase/reports_logs.php"), 'Table Editor' => array( 'daemons' => "$relPathToLaddieRoot/../rta/rta_apps.html"), 'Help' => array( 'HowTo' => "$relPathToLaddieRoot/$scriptBase/help_howto.php", 'WhatIf' => "$relPathToLaddieRoot/$scriptBase/help_whatif.php", 'Contact Us' => "$relPathToLaddieRoot/$scriptBase/help_contact_us.php") );function display_menu1($menu_item) { global $menu_system; $num = count($menu_system); foreach ($menu_system as $menu_key => $menu_array) { if ($menu_key == $menu_item) $display_str = "<strong>" . $menu_key . "</strong>"; else $display_str = $menu_key; reset($menu_array); $url = current($menu_array); print "<a href=\"" . $url . "\">" . $display_str . "</a>"; if ($num > 1) print " | "; $num--; } print "\n";}function display_menu2($menu1_item, $menu2_item) { global $menu_system; if (!array_key_exists($menu1_item, $menu_system)) { print " Programming error\n"; return; } $layout_menu = $menu_system[$menu1_item]; print " <td class=\"menu2\" style=\"width: 10%\"> \n"; print " <ul>\n"; foreach ($layout_menu as $menu_key => $menu_url) { if ($menu_key == $menu2_item) $display_str = "<strong>" . $menu_key . "</strong>"; else $display_str = $menu_key; print " <li> <a href=\"" . $menu_url . "\">" . $display_str . "</a> </li>\n"; } print " </ul>\n"; print " </td>\n"; return;}function display_page($menu1_item, $menu2_item, $widget, $javascript_head="", $javascript_onload="") { global $relPathToLaddieRoot; print <<< LAYOUT_PART1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en">LAYOUT_PART1; $styleSheet = "$relPathToLaddieRoot/alarmstyle.css"; print "<head> <link rel=\"stylesheet\" type=\"text/css\" href=\"$styleSheet\">\n<title>Laddie Alarm System</title>\n<meta http-equiv=\"Pragma\" content=\"no-cache\"> <meta http-equiv=\"Expires\" content=\"-1\">\n$javascript_head </head>\n"; print "<body $javascript_onload><h1>Laddie Alarm System</h1><table id=\"menu1\">\n"; print " <tr class=\"menu1\">\n"; print " <td colspan=\"2\">\n"; display_menu1($menu1_item); print " </td>\n"; print " </tr>\n"; print " <tr>\n"; display_menu2($menu1_item, $menu2_item); print " <td>\n"; print $widget; print " </td>\n"; print " </tr>\n"; print <<< LAYOUT_PART2 </table> </body></html>LAYOUT_PART2;}function display_error_msg($menu1_item, $menu2_item, $error) { $widget = "<h2>Error</h2>"; foreach ($error as $msg) { $widget .= "$msg <br>\n"; } display_page($menu1_item, $menu2_item, $widget);}function calc_delta_dir($fromDir, $toDir) { $len = min(strlen($fromDir),strlen($toDir)); $ii = 0; while ($ii < $len && $fromDir[$ii] == $toDir[$ii]) { $ii++; } $la = trim(substr($fromDir,$ii),'/'); $lb = trim(substr($toDir,$ii),'/'); $ca = substr_count($la,'/'); $cb = substr_count($lb,'/'); if (empty($la) && empty($lb)) return ""; $path = ".."; for ($ii = $ca; $ii > 0; $ii--) { $path .= "/.."; } if (!empty($lb)) { $path .= "/" . $lb; } return $path;}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -