kb-browse.php3 3.62 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2005-2013 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25
#
require("defs.php3");

26 27 28
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
29
$optargs   = OptionalPageArguments("printable", PAGEARG_BOOLEAN);
30

31
# Some Knowledge Base entries are visible only to admins.
32
$admin_access = $isadmin || ISFOREIGN_ADMIN();
33

34 35 36
if (!isset($printable))
    $printable = 0;

37 38 39
#
# Standard Testbed Header
#
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
if (!$printable) {
    PAGEHEADER("Emulab Knowledge Base");
}

if ($printable) {
    #
    # Need to spit out some header stuff.
    #
    echo "<html>
          <head>
  	  <link rel='stylesheet' href='tbstyle-plain.css' type='text/css'>
          </head>
          <body>\n";
}
else {
55 56
    $REQUEST_URI = $_SERVER["REQUEST_URI"];
    echo "<b><a href='$REQUEST_URI?printable=1'>
57 58
                Printable version of this document</a></b><br>\n";
}
59 60

#
61
# Get all entries.  Only admins see section='Testbed Operations'.
62 63 64
# 
$search_result =
    DBQueryFatal("select * from knowledge_base_entries ".
65 66
		 ($admin_access ? "" : 
		  "where section != 'Testbed Operations' ").
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
		 "order by section,date_created");

if (! mysql_num_rows($search_result)) {
    USERERROR("There are no entries in the Emulab Knowledge Base!", 1);
    return;
}

echo "<center><h2>Browse Emulab Knowledge Base</h2></center>\n";
echo "<ul>\n";

#
# First the table of contents.
#
$lastsection = "";

while ($row = mysql_fetch_array($search_result)) {
    $section  = $row['section'];
    $title    = $row['title'];
    $idx      = $row['idx'];
86
    $xref_tag = $row['xref_tag'];
87 88 89 90 91 92 93 94 95 96 97

    if ($lastsection != $section) {
	if ($lastsection != "") {
	    echo "</ul><hr>\n";
	}
	$lastsection = $section;
	
	echo "<li><font size=+1><b>$section</b></font>\n";
	echo "<ul>\n";
    }
    echo "<li>";
98 99 100 101 102 103
    if (isset($xref_tag) && $xref_tag != "") {
	echo "<a href=#${xref_tag}>$title</a>\n";
    }
    else {
	echo "<a href=#${idx}>$title</a>\n";
    }
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
}
mysql_data_seek($search_result, 0);

echo "</ul></ul>\n";
echo "<hr size=4>\n";
echo "<ul>\n";

$lastsection = "";

while ($row = mysql_fetch_array($search_result)) {
    $section  = $row['section'];
    $title    = $row['title'];
    $body     = $row['body'];
    $idx      = $row['idx'];
    $xref_tag = $row['xref_tag'];

    if ($lastsection != $section) {
	if ($lastsection != "") {
	    echo "</ul><hr>\n";
	}
	$lastsection = $section;
	
	echo "<li><font size=+1><b>$section</b></font>\n";
	echo "<ul>\n";
    }
    echo "<li>";
    if (isset($xref_tag) && $xref_tag != "") {
	echo "<a NAME='$xref_tag'></a>";
132 133 134 135 136
	echo "<a href=kb-show.php3?xref_tag=$xref_tag>$title</a>\n";
    }
    else {
	echo "<a NAME='$idx'></a>";
	echo "<a href=kb-show.php3?idx=$idx>$title</a>\n";
137 138 139 140 141 142 143 144 145 146 147 148
    }

    echo "<blockquote>\n";
    echo $body;
    echo "<br>\n";
    echo "</blockquote>\n";
}

echo "</ul></ul>\n";

#
# Standard Testbed Footer
149 150 151 152 153 154 155 156
#
if ($printable) {
    echo "</body>
          </html>\n";
}
else {
    PAGEFOOTER();
}
157 158
?>