menu.php3 11.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
<?php

$STATUS_NOSTATUS  = 0;
$STATUS_LOGGEDIN  = 1;
$STATUS_LOGGEDOUT = 2;
$STATUS_LOGINFAIL = 3;
$STATUS_TIMEDOUT  = 4;
$login_status     = $STATUS_NOSTATUS;
$login_message    = "";
$error_message    = 0;

#
# WRITESIDEBARBUTTON(text, link): Write a button on the sidebar menu.
# We do not currently try to match the current selection so that its
# link looks different. Not sure its really necessary.
#
function WRITESIDEBARBUTTON($text, $base, $link) {
    $link = "$base" . "$link";
    
    echo "<!-- Table row for button $text -->
          <tr>
            <td valign=center align=left nowrap>
                <b>
         	 <a class=sidebarbutton href=\"$link\">$text</a>\n";
    #
    # XXX these blanks look bad in lynx, but add required
    #     spacing between menu and body
    #
    echo "       &nbsp;&nbsp;\n";

    echo "      </b>
            </td>
          </tr>\n";
}

#
# WRITESIDEBAR(): Write the menu. The actual menu options the user
# sees depends on the login status and the DB status.
#
function WRITESIDEBAR() {
    global $login_status, $login_message, $error_message, $uid, $TBDBNAME;
    global $STATUS_NOSTATUS, $STATUS_LOGGEDIN, $STATUS_LOGGEDOUT;
    global $STATUS_LOGINFAIL, $STATUS_TIMEDOUT;
    global $TBBASE, $TBDOCBASE;

    echo "<table cellspacing=2 cellpadding=2 border=0 width=150>\n";

    WRITESIDEBARBUTTON("Home", $TBBASE, "index.php3");
    WRITESIDEBARBUTTON("Publications", $TBDOCBASE, "pubs.php3");
    WRITESIDEBARBUTTON("Documentation", $TBDOCBASE, "doc.php3");
    WRITESIDEBARBUTTON("FAQ", $TBDOCBASE, "faq.php3");
    WRITESIDEBARBUTTON("Tutorial", $TBDOCBASE, "tutorial/tutorial.php3");
    WRITESIDEBARBUTTON("People", $TBDOCBASE, "people.php3");

    echo "<tr>
            <td height=30 valign=center align=center nowrap>
             <b><span class=sidebarbutton>
                  Web Interface Options
                </span>
             </b>
            </td>
          </tr>\n";

64 65 66 67 68 69 70 71 72 73
    if (NOLOGINS()) {
        WRITESIDEBARBUTTON("Web Interface Temporarily Unavailable",
			   $TBDOCBASE, "nologins.php3");
	
	echo "</table>
              <br>\n";

	return;
    }

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    if ($login_status == $STATUS_LOGGEDIN) {
	$query_result = mysql_db_query($TBDBNAME,
		"SELECT status,admin,stud FROM users WHERE uid='$uid'");
	$row = mysql_fetch_row($query_result);
	$status = $row[0];
	$admin  = $row[1];
	$stud   = $row[1];

        #
        # See if group_root in any projects, not just the last one in the DB!
        #
	$query_result = mysql_db_query($TBDBNAME,
		"SELECT trust FROM proj_memb ".
		"WHERE uid='$uid' and trust='group_root'");
	if (mysql_num_rows($query_result)) {
	    $trusted = 1;
	}
	else {
	    $trusted = 0;
	}

	if ($status == "active") {
	    if ($admin) {
		WRITESIDEBARBUTTON("New Project Approval",
				   $TBBASE, "approveproject_list.php3");
		WRITESIDEBARBUTTON("Node Control",
				   $TBBASE, "nodecontrol_list.php3");
		WRITESIDEBARBUTTON("User List",
				   $TBBASE, "showuser_list.php3");
	    }
	    if ($trusted) {
                # Only group leaders can do these options
		WRITESIDEBARBUTTON("New User Approval",
				   $TBBASE, "approveuser_form.php3");
	    }
	    #
            # Since a user can be a member of more than one project,
            # display this option, and let the form decide if the user is
            # allowed to do this.
	    #
	    WRITESIDEBARBUTTON("Project Information",
			       $TBBASE, "showproject_list.php3");
	    WRITESIDEBARBUTTON("Begin an Experiment",
			       $TBBASE, "beginexp_form.php3");
	    WRITESIDEBARBUTTON("Experiment Information",
			       $TBBASE, "showexp_list.php3");
120 121
	    WRITESIDEBARBUTTON("Create a Batch Experiment",
			       $TBBASE, "batchexp_form.php3");
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
	    WRITESIDEBARBUTTON("Update user information",
			       $TBBASE, "modusr_form.php3");
	    WRITESIDEBARBUTTON("Node Reservation Status",
			       $TBBASE, "reserved.php3");
	    WRITESIDEBARBUTTON("Node Up/Down Status",
			       $TBDOCBASE, "updown.php3");
                    
	}
	elseif (($status == "newuser") || ($status == "unverified")) {
	    WRITESIDEBARBUTTON("New User Verification",
			       $TBBASE, "verifyusr_form.php3");
	}
	elseif ($status == "unapproved") {
	    $error_message = "Your account has not been approved yet. ".
		             "Please try back later";
	}
    }
    #
    # Standard options for anyone.
    #
    WRITESIDEBARBUTTON("Start Project", $TBBASE, "newproject_form.php3");
    WRITESIDEBARBUTTON("Join Project",  $TBBASE, "addusr.php3");

    switch ($login_status) {
    case $STATUS_LOGGEDIN:
	$login_message = "$uid Logged In";
	break;
    case $STATUS_LOGGEDOUT:
	$login_message = "Logged Out";
	break;
    case $STATUS_LOGINFAIL:
	$login_message = "Login Failed";
	break;
    case $STATUS_TIMEDOUT:
	$login_message = "Login Timed Out";
	break;
    }

    #
    # Now the login/logout box. Remember, already inside a table.
    # 
    echo "<form action=\"index.php3\" method=post>\n";
    if ($login_status == $STATUS_LOGGEDIN) {
	echo "<tr>
                <td><input type=hidden name=uid value=\"$uid\"></td>
              </tr>
              <tr>
                <td align=center>
                    <b><input type=submit value=Logout name=logout></b>
                </td>
              </tr>\n";
    }
    else {
	#
	# Get the UID that came back in the cookie so that we can present a
	# default login name to the user.
	#
	if (($uid = GETUID()) == FALSE) {
	    $uid = "";
	}

	echo "<tr>
                <td>
                   Username:<br>
                            <input type=text value=\"$uid\" name=uid size=8>
                </td>
              </tr>
              <tr>
                <td>
                   Password:<br>
                            <input type=password name=password size=12>
                </td>
              </tr>
              <tr>
                <td align=center>
                    <b><input type=submit value=Login name=login></b>
                </td>
              </tr>\n";
    }
    echo "</form>\n";
    if ($login_message) {
	echo "<tr>
                <td align=center>
                 <b>
                   <span class=sidebarbutton>
                      $login_message
                   </span>
                 <b>
                </td>
              </tr>\n";
    }
    echo "</table>
          <br>\n";
}

#
# WRITEBANNER(): write the page banner for a page.
# Called by _STARTPAGE
#
function WRITEBANNER($title) {
    global $BANNERCOLOR, $THISPROJECT, $THISHOMEBASE;

    echo "<!-- This is the page Banner -->\n";
    echo "<table cellpadding=0 cellspacing=0 border=0 bgcolor=$BANNERCOLOR>";
    echo "<tr>
            <td align=left width=\"0%\">
             <table cellpadding=5 cellspacing=0 border=0 bgcolor=\"#880000\">
              <tr>
                <td>
                 <b><font size=15 color=white face=Helvetica>
                     $THISHOMEBASE
                    </font>
                 </b>
                </td>
              </tr>
             </table>
            </td>
            <td align=left width=\"100%\">
                <table cellpadding=5 cellspacing=0 border=0
                         bgcolor=$BANNERCOLOR>
                  <tr>
                   <td>
                     <b>
                       <font size=15 face=helvetica color=\"#000000\">
                            $THISPROJECT
                       </font>
                     </b>
                   </td>
                  <tr>
                </table>
            </td>
          </tr>
          </table>\n";
}

#
# _WRITETITLE(title): write the page title for a page.
# Called by _STARTPAGE
#
function WRITETITLE($title) {
    global $TITLECOLOR;
    
    echo "<!-- This is the page Title -->
          <table width=\"100%\">
            <tr>
               <td width=\"15%\" align=left>\n";
                 #
                 # Insert a small logo here if you like.
                 #
    echo "     </td>
               <td align=left>
                   <b><font size=\"+3\" color=$TITLECOLOR>$title</font></b>
               </td>
            </tr>
          </table>\n";
}

#
# Spit out a vanilla page header.
#
function PAGEHEADER($title) {
    global $login_status, $TBAUTHTIMEOUT, $uid;
    global $STATUS_NOSTATUS, $STATUS_LOGGEDIN, $STATUS_LOGGEDOUT;
    global $STATUS_LOGINFAIL, $STATUS_TIMEDOUT;
    global $TBBASE, $TBDOCBASE;

    if ($login_status == $STATUS_NOSTATUS) {
	if ($uid = GETUID()) {
            #
            # Check to make sure the UID is logged in (not timed out).
            #
            $status = CHECKLOGIN($uid);
            switch ($status) {
	    case 0:
		unset($uid);
		break;
	    case 1:
		$login_status = $STATUS_LOGGEDIN;
		break;
	    case -1:
		$login_status = $STATUS_TIMEDOUT;
		unset($uid);
		break;
	    }
	}
    }

    echo "<html>
          <head>
           <title>Emulab.Net - $title</title>\n";

    #
    # Shove the Jave code through to the output. 
    # 
    readfile("java.html");

    #
    # If logged in, initialize the refresh process.
    # 
    if ($login_status == $STATUS_LOGGEDIN) {
	$timeo = $TBAUTHTIMEOUT + 120;
	echo "<noscript>
                <META HTTP-EQUIV=\"refresh\" CONTENT=\"$timeo\">
              </noscript>\n";
	$timeo *= 1000;
	echo "<script language=\"JavaScript\">
                <!--
                  function doLoad() {
                    setTimeout(\"refresh()\", $timeo );
                  }
                //-->
              </script>\n";
    }
    
336
    echo " <link rel=\"stylesheet\" href=\"$TBBASE/tbstyle.css\"
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
                 type=\"text/css\">
          </head>\n";

    #
    # If logged in, start the refresh process.
    # 
    if ($login_status == $STATUS_LOGGEDIN) {
	echo "<body onload=\"doLoad()\">\n";
    }
    else {
	echo "<body>\n";
    }

    echo "<basefont size=4>\n";
    
    WRITEBANNER($title);
    WRITETITLE($title);

    echo "<br>
          <!-- Under banner is a table with two columns: menu and content -->
          <table cellpadding=3 width=\"100%\" height=\"60%\" border=2>
          <tr>
           <!-- everthing is in a single row: two tables side-by-side -->

           <!-- MENU -->
           <td valign=top>\n";
    
    WRITESIDEBAR();

    echo " </td>

           <!-- PAGE BODY -->
           <td valign=top align=left width=\"85%\">
               <basefont size=4>
               <!-- Content follows this macro ... -->\n";
}

#
# ENDPAGE(): This terminates the table started above.
# 
function ENDPAGE() {
    echo "     <!-- ... end of page content. -->
            </td>
           </tr>
          </table>
          <br>
          <hr size=2 noshade>\n";
}

#
# Spit out a vanilla page footer.
#
function PAGEFOOTER() {
    global $TBBASE;

    ENDPAGE();

    echo "<!-- Force full window! -->
	  <base target=_top>
          <center>[<a href=\"$TBBASE\">Emulab.Net Home</a>]</center>
          <center>
           [<a href=\"http://www.cs.utah.edu/flux/\">Flux Research Group</a>]
           [<a href=\"http://www.cs.utah.edu/\">School of Computing</a>]
           [<a href=\"http://www.utah.edu/\">University of Utah</a>]
          </center>
         <p align=right>
         <font size=-2>
          Problems? Contact
                    <a href=\"mailto:testbed-ops@flux.cs.utah.edu\"> 
                       Testbed Operations (testbed-ops@flux.cs.utah.edu)</a>
          </body>
          </html>\n";
}
?>