menu.php3 48.9 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2016 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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24

25
$login_user       = null;
26
$login_status     = CHECKLOGIN_NOTLOGGEDIN;
27
$drewheader       = 0;
28
$noheaders	  = 0;
29
$autorefresh      = 0;
30
$javascript_debug = 0;
31
$currentusage     = 1;
32
$currently_busy   = 0;
33
$sortedtables     = array();
34
$bodyclosestring  = "";
35 36
$navmenu          = null;
$navmenuopen      = FALSE;
37
$noAnalytics      = 0;
38

39 40 41 42 43 44
#
# This has to be set so we can spit out http or https paths properly!
# Thats because browsers do not like a mix of secure and nonsecure.
# 
$BASEPATH	  = "";

45 46 47 48 49 50 51 52 53
#
# Determine the proper basepath, which depends on whether the page
# was loaded as http or https. This lets us be consistent in the URLs
# we spit back, so that users do not get those pesky warnings. These
# warnings are generated when a page *loads* (say, images, style files),
# a mix of http and https. Links can be mixed, and in fact when there
# is no login active, we want to spit back http for the documentation,
# but https for the start/join pages.
#
54
if (isset($_SERVER["SSL_PROTOCOL"])) {
55 56 57 58 59 60 61 62
    $BASEPATH = $TBBASE;
}
else {
    $BASEPATH = $TBDOCBASE;
}

# Blank space dividers in the menus are handled by adding a class to the menu
# item that starts a new group.
63 64
$nextnavbarcl     = null;
$nextsubmenucl    = null;
65

66 67 68 69 70 71 72
# Add a table id to the list of sorted tables to initialize on current page.
function AddSortedTable($id) {
    global $sortedtables;

    $sortedtables[] = $id;
}

73
#
74 75
# TOPBARCELL - Make a cell for the topbar. Actually, the name lies, it can be
# used for cells in a bottombar too.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#
function TOPBARCELL($contents) {
    echo "<td class=\"topbaropt\">";
    echo "<span class=\"topbaroption\">&nbsp;";
    echo $contents;
    echo "&nbsp;</span>";
    echo "</td>";
    echo "\n";
}

#
# WRITETOPBARBUTTON(text, base, link): Write a button in the topbar
#
function WRITETOPBARBUTTON($text, $base, $link ) {
    $link = "$base/$link";
    TOPBARCELL("<a href=\"$link\">$text</a>");
}
# same as above with "new" gif next to it.
function WRITETOPBARBUTTON_NEW($text, $base, $link ) {
    $link = "$base/$link";
    TOPBARCELL("<a href=\"$link\">$text</a>&nbsp;<img src=\"/new.gif\" />");
}

99
#
100
# Start the primary navmenu.
101
#
102 103 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 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
function NavMenuStart() {
    global $navmenu, $login_user;

    if ($login_user) 
	$navmenu = new menuBar();
}

#
# Start a new navmenu section (a new dropdown menu).
#
function NavMenuSection($id, $title) {
    global $navmenu, $login_user, $navmenuopen;

    if ($login_user)
	$navmenu->addMenu($title, $id);
    else {
	if ($navmenuopen) {
	    echo "</ul>\n";
	}
	$navmenuopen = TRUE;
	STARTSIDEBARMENU($id, $title);
    }
}
function NavMenuSectionEnd() {
    global $navmenu, $login_user, $navmenuopen;

    if (! $login_user) {
	if ($navmenuopen) {
	    echo "</ul>\n";
	}
	$navmenuopen = FALSE;
    }
}

#
# Add a new button to the current dropdown menu.
# 
function NavMenuButton($text, $link = null, $extratext = null,
		       $target = null, $divider = FALSE, $mouseover = null)
{
    global $navmenu, $login_user;

    if ($login_user)
	$navmenu->addItem($link, $text, $target, $divider,
			  $extratext, $mouseover);
    else
	WRITESIDEBARBUTTON($text, $link, $extratext);
	
}
# Ditto, but with a new icon.
function NavMenuButtonNew($text, $link = null, $divider = FALSE)
{
    global $navmenu, $login_user;

    if ($login_user)
157 158
	NavMenuButton($text, $link, "&nbsp;<img src=\"/new.gif\">",
		      null, $divider);
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
    else
	WRITESIDEBARBUTTON($text, $link, "&nbsp;<img src=\"/new.gif\" />");
}
# Ditto, but with a divider
function NavMenuButtonDivider($text, $link = null)
{
    global $navmenu, $login_user;

    if ($login_user) 
	NavMenuButton($text, $link, null, null, TRUE);
    else {
	WRITESIDEBARDIVIDER();
	WRITESIDEBARBUTTON($text, $link);
    }
}

#
# Render the menu ...
# 
function NavMenuRender()
{
    global $navmenu, $navmenuopen, $BASEPATH, $TBBASE, $login_user;

    if (!$login_user) {
	if ($navmenuopen)
	    echo "</ul>\n";
	$navmenuopen = FALSE;
	return;
    }

    $navmenu->writeMenuBar();
}

#
# STARTSIDEBARMENU(). Start a menu section.
#
function STARTSIDEBARMENU($id, $title, $visible = true) {
    $arrow = "";
    $class = "navmenu";
    if (0) {
	$png   = ($visible ? 'menu-expanded.png' : 'menu-collapsed.png');
	$class = ($visible ? 'navmenu' : 'navmenu-collapsed');
	$arrow = "<img class=menuarrow src='$png' ".
	    "onclick=\"return toggle_menu('${id}_list', '${id}_arrow');\" ".
	    "id='${id}_arrow'>";
    }
    echo "<h3 class='menuheader' id='${id}_header'>$arrow $title</h3>";
    echo "<ul class='$class' id='${id}_list'>\n";
207 208
}

209 210 211 212 213
#
# 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.
#
214
function WRITESIDEBARBUTTON($text, $link, $extratext="") {
215 216 217 218 219 220 221 222
    global $nextsidebarcl;
    
    $cl = "";
    if ($nextsidebarcl != "") {
	$cl = "class='$nextsidebarcl'";
	$nextsidebarcl = "";
    }
    echo "<li $cl><a href=\"$link\">$text</a>$extratext</li>\n";
Chad Barb's avatar
Chad Barb committed
223
}
224

Chad Barb's avatar
Chad Barb committed
225
# same as above with "new" gif next to it.
226 227 228 229 230
function WRITESIDEBARBUTTON_NEW($text, $base, $link) {
    WRITESIDEBARBUTTON($text,
		       $base,
		       $link,
		       "&nbsp;<img src=\"/new.gif\" />");
Chad Barb's avatar
Chad Barb committed
231 232 233 234
}

# writes a message to the sidebar, without clickability.
function WRITESIDEBARNOTICE($text) {
235
    echo "<span class='notice'>$text</span>\n";
236 237 238 239 240 241 242 243 244
}

#
# Something like the sidebar, but across the top, with only a few options.
# Think Google. For PlanetLab users, but it would be easy enough to make
# others. Still a work in progress.
#
function WRITEPLABTOPBAR() {
    echo "<table class=\"topbar\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\">\n";
245
    global $login_status, $login_user;
246 247 248
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $THISHOMEBASE;

249 250
    WRITETOPBARBUTTON("Create a Slice",
        $TBBASE, "plab_ez.php3");
251

252
    WRITETOPBARBUTTON("Nodes",
253 254 255
        $TBBASE, "plabmetrics.php3");

    WRITETOPBARBUTTON("My Testbed",
256
		      $TBBASE, CreateURL("showuser", $login_user));
257 258

    WRITETOPBARBUTTON("Advanced Experiment",
259
        $TBBASE, "beginexp.php");
260

261 262
    if ($login_status & CHECKLOGIN_TRUSTED && $login_user->ApprovalList(0)) {
	WRITESIDEBARBUTTON_NEW("Approve Users",
263 264 265 266 267 268
			       $TBBASE, "approveuser_form.php3");
    }

    WRITETOPBARBUTTON("Log Out", $TBBASE, "logout.php3?next_page=" .
	urlencode($TBBASE . "/login_plab.php3"));

269 270 271
    echo "</table>\n";
    echo "<br>\n";

272 273
}

274 275 276 277 278 279

#
# Put a few things that PlanetLab users should see, but are non-essential,
# across the bottom of the page rather than the top
#
function WRITEPLABBOTTOMBAR() {
280
    global $login_status, $login_user;
281 282
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $THISHOMEBASE;
283
    global $WIKIDOCURL;
284

285
    if ($login_user) {
286 287 288 289 290 291
	$newsBase = $TBBASE; 
    } else {
	$newsBase = $TBDOCBASE;
    }

    echo "
292 293 294
	   <center>
	   <br>
	   <font size=-1>
295
	   <form method='get' action='$TBDOCBASE/search.php3'>
296
	   [ <a href='$WIKIDOCURL'>
297 298 299
		Documentation</a> : <input name=query size = 15/>
		  <input type=submit style='font-size:10px;' value='Search' /> ]
	   [ <a href='$newsBase/news.php3'>
300
		News</a> ]
301 302 303 304
	   </form>
	   </font>
	   <br>
	   </center>\n";
305 306 307

}

308 309 310
function GETNEWSINFO() {
    global $TBBASE, $TBDOCBASE;
    global $login_user;
311

Chad Barb's avatar
Chad Barb committed
312 313 314 315 316 317 318 319
    #
    # get post time of most recent news;
    # get both displayable version and age in days.
    #
    $query_result = 
	DBQueryFatal("SELECT DATE_FORMAT(date, '%M&nbsp;%e') AS prettydate, ".
		     " (TO_DAYS(NOW()) - TO_DAYS(date)) AS age ".
		     "FROM webnews ".
320
		     "WHERE archived=0 ".
Chad Barb's avatar
Chad Barb committed
321 322 323 324 325 326 327 328
		     "ORDER BY date DESC ".
		     "LIMIT 1");
    $newsDate = "";
    $newNews  = 0;

    #
    # This is so an admin can use the editing features of news.
    #
329
    if ($login_user) {
Chad Barb's avatar
Chad Barb committed
330 331 332 333 334 335
	$newsBase = $TBBASE; 
    } else {
	$newsBase = $TBDOCBASE;
    }

    if ($row = mysql_fetch_array($query_result)) {
336 337
	$newsDate = "(".$row["prettydate"].")";
	if ($row["age"] < 7) {
Chad Barb's avatar
Chad Barb committed
338 339 340 341
	    $newNews = 1;
	}
    }

342 343 344 345

    return array($newsBase, $newsDate, $newNews);
}

346 347
function WRITEMIDTOPBAR($newsBase, $newNews) {
    global $TBBASE, $FLAVOR;
348 349
    global $login_user, $login_status;

350 351 352 353 354 355 356 357 358 359 360 361
    if ($login_user) {
	echo "<td>\n";
	echo "<div class='midtopcell'>\n";
	echo "<!-- main navigation menu begins -->\n";

	echo "<table id='navmenus' cellspacing='0' cellpadding='0'>".
	    "<tr><td>\n";

	# Logout option on first row.
	if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
	    echo "<a class=midtopcell ".
		"href='$TBBASE/" . CreateURL("showuser", $login_user) . "'>".
362
		"My $FLAVOR</a>\n";
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 411 412 413 414 415 416 417 418 419 420 421 422 423

	    echo " <font color=grey>|</font> ";

            # Logout option. No longer take up space with an image.
	    echo "<a class=midtopcell ".
		"href='$TBBASE/" . CreateURL("logout", $login_user) . "'>".
		"Logout</a>\n";
	    
	    echo " <font color=grey>|</font> ";

	    # News
	    echo "<a class=midtopcell ".
		"href='$newsBase/news.php3'>News</a>";
	    if ($newNews) {
		echo "&nbsp;<img src=\"/new.gif\">\n";
	    }
	    
	    echo " <font color=grey>|</font> ";

	    echo "<a class=midtopcell href='$TBBASE/emailus.php3'>".
		"Contact Us</a>\n";

	    if (ISADMINISTRATOR()) {
		echo " <font color=grey>|</font> ";

		if (ISADMIN()) {
		    $url = CreateURL("toggle", $login_user,
				     "type", "adminon", "value", 0);
		
		    echo "<a href=\"$TBBASE/$url\">
                             <img src='/redball.gif'
                                  border='0' alt='Admin On'></a>\n";
		}
		else {
		    $url = CreateURL("toggle", $login_user,
				     "type", "adminon", "value", 1);

		    echo "<a href=\"$TBBASE/$url\">
                              <img src='/greenball.gif'
                                   border='0' alt='Admin Off'></a>\n";
		}
	    }
        }
        # The search box.
	echo "<span id='topcellsearchrow'>";
	echo "<table id='topcellsearchtable' cellspacing='0' cellpadding='0'>";
	echo "<form method='get' action='$newsBase/search.php3'>";
	echo "<tr><td>";
	echo "<input class='textInputEmpty' name='query'
                     value='Search Documentation' id='searchbox'
                     onfocus='focus_text(this, \"Search Documentation\")'
                     onblur='blur_text(this, \"Search Documentation\")' />";
	echo "</td><td>";
	echo "<input type='submit' id='searchsub' value=Go />";
	echo "</td></tr>";
        echo "</form>";
        echo "</table>";
	echo "</span>";
	echo "</td></tr>";
	# Extra row to force two rows to top and bottom of midtopcell.
	# See height value for tr/td in the style file.
Leigh Stoller's avatar
Leigh Stoller committed
424
	echo "<tr id=spacer><td id=spacer></td></tr>";
425 426
	echo "<tr><td>";
    }
427
}
428

429 430
function PUTSEARCHBOX($newsBase) {
    echo "<div id='searchrow'>
431 432 433
        <form method='get' action='$newsBase/search.php3'>
        <table border='0' cellspacing='0' cellpadding='0'><tr>
             <td width='100%'><input class='textInputEmpty' name='query'
434 435 436
                        value='Search Documentation' id='searchbox'
                        onfocus='focus_text(this, \"Search Documentation\")'
                        onblur='blur_text(this, \"Search Documentation\")' />
437
             </td>
438
	     <td><input type='submit' id='searchsub' value=Go /></td>
439 440 441
        </table>
        </form>
	</div>\n";
442 443
}

444
function WRITELOGINBOX($loginbox_content) {
445 446 447
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $login_status;

448 449 450 451 452 453
    #
    # Cons up a nice message.
    # 
    switch ($login_status & CHECKLOGIN_STATUSMASK) {
    case CHECKLOGIN_LOGGEDIN:
	if ($login_status & CHECKLOGIN_PSWDEXPIRED)
454
	    $login_message = "(Password Expired!)";
455
	elseif ($login_status & CHECKLOGIN_UNAPPROVED)
456 457 458
	    $login_message = "(Unapproved!)";
	else
	    $login_message = 0;
459 460 461 462 463 464 465 466 467 468
	break;
    case CHECKLOGIN_TIMEDOUT:
	$login_message = "Login Timed out.";
	break;
    default:
	$login_message = 0;
	break;
    }

    #
469
    # Now the login box.
470
    # We want the links to the login pages to always be https,
471 472 473
    # but the images path depends on whether the page was loaded as
    # http or https, since we do not want to mix them, since they
    # cause warnings.
474 475 476
    #
    if (! ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) &&
	!NOLOGINS()) {
477 478 479 480 481
	echo "<div id='loginbox'>";

	if ($login_message) {
	    echo "<strong>$login_message</strong>";
	}
482

483
	echo $loginbox_content;
484
	echo "</div>";
485

486 487 488 489 490 491 492
        #
        # Login message. Set via 'web/message' site variable
        #
        $message = TBGetSiteVar("web/message");
        if (0 != strcmp($message,"")) {
	    WRITESIDEBARNOTICE($message);
	}
493 494
    }

495 496 497 498
    #
    # Basically, we want to let admin people continue to use
    # the web interface even when nologins set. But, we want to make
    # it clear its disabled.
499 500
    #
    if (!$login_user && NOLOGINS()) {
501 502
	echo "<a id='webdisabled' href='$TBDOCBASE/nologins.php3'>".
	    "Web Interface Temporarily Unavailable</a>";
503
	WRITESIDEBARNOTICE("Please Try Again Later");
504 505 506 507 508
	
        $message = TBGetSiteVar("web/message");
        if ($message != "") {
	    WRITESIDEBARNOTICE($message);
	}
509
    }
510 511
}

512
function WRITEEXPERIMENTMENU($firstinitstate) {
513
    global $TBBASE, $TBDOCBASE, $TBMAINSITE;
514
    global $WIKISUPPORT, $CHECKLOGIN_WIKINAME, $EXPOSETEMPLATES, $FLAVOR;
515
    global $login_status, $login_user;
516 517 518

    # Start Interaction section if going to spit out interaction options.
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
519
	NavMenuSection("experimentation", "Experimentation");
520
    }
Chad Barb's avatar
Chad Barb committed
521

522
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
523 524
	if ($firstinitstate != null) {    
	    if ($firstinitstate == "createproject") {
Russ Fish's avatar
Russ Fish committed
525
		NavMenuButton("<font color=red> Create First Project </font>&nbsp",
526
			      "$TBBASE/newproject.php3");
527 528 529 530
	    }
	    elseif ($firstinitstate == "approveproject") {
		$firstinitpid = TBGetFirstInitPid();
		
531 532 533
		NavMenuButton("Approve First Project",
			      "$TBBASE/approveproject.php3?pid=$firstinitpid".
			      "&approval=approve");
534 535 536
	    }
	}
	elseif ($login_status & CHECKLOGIN_ACTIVE) {
537
	    if ($login_status & CHECKLOGIN_PSWDEXPIRED) {
538 539
		NavMenuButton("Change Your Password",
			      "$TBBASE/moduserinfo.php3");
540
	    }
Leigh Stoller's avatar
Leigh Stoller committed
541
	    elseif ($login_status & (CHECKLOGIN_WEBONLY|CHECKLOGIN_WIKIONLY)) {
542 543 544
		if ($WIKISUPPORT && $CHECKLOGIN_WIKINAME != "") {
		    $wikiname = $CHECKLOGIN_WIKINAME;
		
545 546
		    NavMenuButton("My Wikis",
				  "gotowiki.php3?redurl=Main/$wikiname");
547
		}
548 549 550
		NavMenuButton("Update User Information",
			      "$TBBASE/" .
			         CreateURL("moduserinfo", $login_user));
551
	    }
552
	    else {
553
		NavMenuButton("My $FLAVOR",
554
			      "$TBBASE/" . CreateURL("showuser", $login_user));
555

556
		#
557 558 559 560
                # 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.
                #
561
 		NavMenuButton("Begin an Experiment",
562
			      "$TBBASE/beginexp.php");
563 564

		if ($EXPOSETEMPLATES) {
565 566
		    NavMenuButton("Create a Template",
				  "$TBBASE/template_create.php");
567
		}
568

569
		NavMenuButton("Experiment List", "$TBBASE/showexp_list.php3");
570

571 572 573 574 575
		NavMenuButtonDivider("Node Status",
				     "$TBBASE/nodecontrol_list.php3");

		NavMenuButton("List ImageIDs",
			      "$TBBASE/showimageid_list.php3");
576

577 578 579 580
		if (ISADMIN()) {
		    NavMenuButton("List OSIDs",
				  "$TBBASE/showosid_list.php3");
		}
581 582 583 584 585
                # Do we have a storage pool? Then we support datasets.
                if (HaveStoragePool()) {
                    NavMenuButton("List Datasets",
                                  "$TBBASE/list-datasets.php");
                }
586

587 588
		if ($login_status & CHECKLOGIN_TRUSTED &&
		    $login_user->ApprovalList(0)) {
589 590 591
		    # This includes a divider argument.
		    NavMenuButtonNew("New User Approval",
				     "$TBBASE/approveuser_form.php3", TRUE);
592
		}
593
	    }
594
	}
595
	elseif ($login_status & (CHECKLOGIN_UNVERIFIED|CHECKLOGIN_NEWUSER)) {
596 597 598 599
	    NavMenuButton("New User Verification",
			  "$TBBASE/verifyusr_form.php3");
	    NavMenuButton("Update User Information",
			  "$TBBASE/" . CreateURL("moduserinfo", $login_user));
600
	}
601
	elseif ($login_status & (CHECKLOGIN_UNAPPROVED)) {
602 603
	    NavMenuButton("Update User Information",
			  "$TBBASE/" . CreateURL("moduserinfo", $login_user));
604
	}
605 606
	#
	# Standard options for logged in users!
607 608
	#
	if (!$firstinitstate) {
609 610 611 612
	    NavMenuButtonDivider("Start New Project",
				 "$TBBASE/newproject.php3");
	    NavMenuButton("Join Existing Project",
			  "$TBBASE/joinproject.php3");
613
	}
614
    }
615 616 617
}

function WRITEADMINMENU() {
618
    global $TBBASE, $TBDOCBASE, $TBMAINSITE;
619
    global $PROTOGENI, $ISALTDOMAIN;
620 621
    global $login_status;

622 623 624
    # Do we have a storage pool? The we support datasets.
    $havestoragepool = HaveStoragePool();

625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
    # Optional ADMIN menu.
    if ($login_status & CHECKLOGIN_LOGGEDIN && ISADMIN()) {
	NavMenuSection("administration", "Administration");
	
	NavMenuButton("List Projects",
		      "$TBBASE/showproject_list.php3");
	NavMenuButton("List Users",
		      "$TBBASE/showuser_list.php3");

	NavMenuButton("View Testbed Stats",
		      "$TBBASE/showstats.php3");

	NavMenuButton("Resource Usage Visualization",
		      "$TBBASE/rusage_viz.php");

	NavMenuButton("Approve New Projects",
		      "$TBBASE/approveproject_list.php3");

	NavMenuButton("Edit Site Variables",
		      "$TBBASE/editsitevars.php3");

646
	if ($TBMAINSITE && !$ISALTDOMAIN) {
647 648 649 650 651 652 653
	    NavMenuButton("Emulab Site List",
			  "$TBBASE/showsite_list.php");
	}

	NavMenuButton("Show Shared Node Pool",
		      "$TBBASE/showpool.php");

654
	if ($havestoragepool) {
655 656 657 658 659 660
	    NavMenuButton("Local Datasets",
			  "$TBBASE/list-datasets.php?all=1");
	    NavMenuButton("Remote Datasets",
			  "$TBBASE/apt/list-datasets.php?all=1");
	}

661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
	$query_result = DBQUeryFatal("select new_node_id from new_nodes");
	if (mysql_num_rows($query_result) > 0) {
	    NavMenuButtonNew("Add Testbed Nodes",
			     "$TBBASE/newnodes_list.php3");
	}
	else {
	    NavMenuButtonNew("Add Testbed Nodes",
			     "$TBBASE/newnodes_list.php3");
	}
	if ($PROTOGENI) {
	    NavMenuButton("ProtoGeni Slices",
			  "$TBBASE/genislices.php");
	    NavMenuButton("ProtoGeni History",
			  "$TBBASE/genihistory.php");
	}
    }
}

#
# WRITESIDEBARPNET(): Write the "sidebar" menu for PhantomNet.
#
682
function WRITEPNETSIDEBAR() {
683 684 685
    global $login_status, $login_user;
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $TBMAINSITE, $THISHOMEBASE;
686
    global $WIKIDOCURL, $FORUMURL;
687 688 689

    list($newsBase, $newsDate, $newNews) = GETNEWSINFO();

690
    WRITEMIDTOPBAR($newsBase, $newNews);
691 692 693

    NavMenuStart();
    NavMenuSection("information", "Information");
Kirk Webb's avatar
Kirk Webb committed
694
    NavMenuButton("Home", "$TBDOCBASE/pnet-index.php?stayhome=1");
695 696 697 698 699 700 701 702

    if ($newNews) {
	NavMenuButtonNew("News $newsDate", "$newsBase/news.php3");
    } else {
	NavMenuButton("News $newsDate", "$newsBase/news.php3");
    }

    NavMenuButton("Documentation", "$WIKIDOCURL");
703
    NavMenuButtonNew("Forums", "$FORUMURL");
704 705 706 707 708

    # The search box.  Placed in a table so the text input fills available
    # space.
    if (! $login_user) {
	NavMenuSectionEnd();
709
	PUTSEARCHBOX($newsBase);
710 711
    }

712 713 714
    $lbox_content = 
	"<a href=\"$TBBASE/reqpnetaccount.php\">".
	"<img alt=\"Request Account\" border=0 ".
Kirk Webb's avatar
Kirk Webb committed
715
	"src=\"$BASEPATH/pnet-rqaccount.png\" width=\"144\" height=\"32\"></a>".
716 717 718
	"<strong>or</strong>".
	"<a href=\"$TBBASE/login.php3\">".
        "<img alt=\"logon\" border=0 ".
Kirk Webb's avatar
Kirk Webb committed
719
	"src=\"$BASEPATH/pnet-login.png\" width=\"144\" height=\"32\"></a>\n";
720 721 722

    WRITELOGINBOX($lbox_content);
    WRITEEXPERIMENTMENU(0);
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
    WRITEADMINMENU();

    # Terminate Interaction menu and render.
    NavMenuRender();
    
    if ($login_user) {
	echo "</td></tr></table>\n";
	
	# Close up div at start of navmenu
	echo "</div>\n";
	echo "</td>\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_user, $pid, $gid;
    global $TBBASE, $TBDOCBASE, $BASEPATH, $WIKISUPPORT, $MAILMANSUPPORT;
    global $BUGDBSUPPORT, $BUGDBURL, $CVSSUPPORT, $CHATSUPPORT, $TRACSUPPORT;
745
    global $CHECKLOGIN_WIKINAME, $TBMAINSITE, $ISALTDOMAIN;
746 747
    global $THISHOMEBASE;
    global $currentusage, $FANCYBANNER, $ELABINELAB, $PLABSUPPORT;
748
    global $WIKIDOCURL, $FORUMURL;
749 750 751 752
    $firstinitstate = TBGetFirstInitState();

    list($newsBase, $newsDate, $newNews) = GETNEWSINFO();

753
    WRITEMIDTOPBAR($newsBase, $newNews);
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
   
    NavMenuStart();
    NavMenuSection("information", "Information");
    NavMenuButton("Home", "$TBDOCBASE/index.php3?stayhome=1");

    if (0 == strcasecmp($THISHOMEBASE, "emulab.net")) {
	$rootEmulab = 1;
    } else {
	$rootEmulab = 0;
    }
    if ($rootEmulab) {
	NavMenuButton("Other Emulabs", 
		      "$WIKIDOCURL/OtherEmulabs");
    } else {
	NavMenuButton("Utah Emulab", "http://www.emulab.net/");
    }

    if ($newNews) {
	NavMenuButtonNew("News $newsDate", "$newsBase/news.php3");
    } else {
	NavMenuButton("News $newsDate", "$newsBase/news.php3");
    }

    NavMenuButton("Documentation", "$WIKIDOCURL");
778
    NavMenuButtonNew("Forums", "$FORUMURL");
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796

    if ($rootEmulab) {
	# Leave New here about 2 weeks
        NavMenuButton("Papers and Talks (Jul 18)", "$TBDOCBASE/pubs.php3");
	NavMenuButton("Emulab Software (Sep 1)", "$TBDOCBASE/software.php3");

	NavMenuButton("List People",
		      "$TBDOCBASE/people.php3");
	NavMenuButton("Photo Gallery",
		      "$TBDOCBASE/gallery/gallery.php3");
	NavMenuButton("Emulab Users",
		      "$TBDOCBASE/doc/docwrapper.php3?docname=users.html");
	NavMenuButton("Emulab Sponsors",
		      "$TBDOCBASE/docwrapper.php3?docname=sponsors.html");
    }
    else {
	NavMenuButton("Projects on Emulab", "$TBDOCBASE/projectlist.php3");
    }
797
    if ($TBMAINSITE && !$ISALTDOMAIN) {
798 799 800 801 802 803 804 805
	NavMenuButton("<font color=red>In Memoriam</font>",
		      "$TBDOCBASE/jay.php");
    }

    # The search box.  Placed in a table so the text input fills available
    # space.
    if (! $login_user) {
	NavMenuSectionEnd();
806 807 808 809 810 811 812 813 814 815
	PUTSEARCHBOX($newsBase);
    }

    $lbox_content = "";
    if (!$firstinitstate) {
	$lbox_content .= 
	    "<a href=\"$TBBASE/reqaccount.php3\">".
	    "<img alt=\"Request Account\" border=0 ".
	    "src=\"$BASEPATH/requestaccount.gif\" width=\"144\" height=\"32\"></a>".
	    "<strong>or</strong>";
816 817
    }

818 819 820 821 822 823
    $lbox_content .= 
	"<a href=\"$TBBASE/login.php3\">".
	"<img alt=\"logon\" border=0 ".
	"src=\"$BASEPATH/logon.gif\" width=\"144\" height=\"32\"></a>\n";

    WRITELOGINBOX($lbox_content);
824
    WRITEEXPERIMENTMENU($firstinitstate);
Chad Barb's avatar
Chad Barb committed
825

826
    # And now the Collaboration menu.
Leigh Stoller's avatar
Leigh Stoller committed
827
    if (($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) &&
828
	($WIKISUPPORT || $BUGDBSUPPORT ||
Leigh Stoller's avatar
Leigh Stoller committed
829
	 $CVSSUPPORT  || $CHATSUPPORT)) {
830 831

	NavMenuSection("collaboration", "Collaboration");
832

833 834 835
	if ($WIKISUPPORT && $CHECKLOGIN_WIKINAME != "") {
	    $wikiname = $CHECKLOGIN_WIKINAME;
		
836 837
	    NavMenuButton("My Wikis",
			  "$TBBASE/gotowiki.php3?redurl=Main/$wikiname");
838
	}
839 840
	if ($MAILMANSUPPORT || $BUGDBSUPPORT) {
	    if (!isset($pid) || $pid == "") {
841 842
		if (($project = $login_user->FirstApprovedProject())) {
		    $firstpid = $project->pid();
843 844 845 846 847 848 849 850 851 852 853 854
		}
	    }
	}
	if ($BUGDBSUPPORT) {
	    $bugdburl = "gotobugdb.php3";
		    
	    if (isset($pid) && !empty($pid)) {
		$bugdburl .= "?project_title=$pid";
	    }
	    elseif (isset($firstpid)) {
		$bugdburl .= "?project_title=$firstpid";
	    }
855
	    NavMenuButton("My Bug Databases", "$TBBASE/$bugdburl");
856 857
	}
	if ($CVSSUPPORT) {
858 859
	    NavMenuButton("My CVS Repositories",
			  "$TBBASE/" . CreateURL("listrepos", $login_user));
860
	}
861
	if ($CHATSUPPORT) {
862 863
	    NavMenuButton("My Chat Buddies",
			  "$TBBASE/" . CreateURL("mychat", $login_user));
864
	}
865 866 867 868 869
	if ($TBMAINSITE && $TRACSUPPORT) {
	    $geniproject = Project::Lookup("geni");
	    $approved    = 0;
	    
	    if ($geniproject &&
870 871 872
		(ISADMIN() ||
		 ($geniproject->IsMember($login_user, $approved) &&
		  $approved))) {
873
		NavMenuButton("ProtoGENI Trac Wiki",
874 875 876 877 878 879 880
			      "$TBBASE/" . CreateURL("gototrac", $login_user,
						     "wiki", "geni"));
	    }
	    if (STUDLY()) {
		NavMenuButton("Emulab Trac Wiki",
			      "$TBBASE/" . CreateURL("gototrac", $login_user,
						     "wiki", "emulab"));
881
	    }
882
	}
883
    }
884

885
    WRITEADMINMENU();
886

887 888 889
    if (0 && $login_user) {
	NavMenuSection("Status", "Status");
	
890
	$freepcs = TBFreePCs($login_user);
891 892 893 894 895 896 897 898 899
	$reload  = TBReloadingPCs();
	$users   = TBLoggedIn();
	$active  = TBActiveExperiments();
	NavMenuButton("Status",
		      "$TBBASE/nodecontrol_list.php3",
		      null, null, FALSE,
		      "$freepcs Free PCs, $reload PCs reloading<br> ".
		      "$users users logged in, $active active experiments");
    }
900

901 902 903 904 905 906 907 908 909
    # Terminate Interaction menu and render.
    NavMenuRender();
    
    if ($login_user) {
	echo "</td></tr></table>\n";
	
	# Close up div at start of navmenu
	echo "</div>\n";
	echo "</td>\n";
910
    }
911 912
}

913 914 915 916 917 918
#
# Simple version of above, that just writes the given menu.
# 
function WRITESIMPLESIDEBAR($menudefs) {
    $menutitle = $menudefs['title'];
    
919
    echo "<h3 class='menuheader'>$menutitle</h3>
920
          <ul class='navmenu'>";
921 922 923 924 925

    each($menudefs);    
    while (list($key, $val) = each($menudefs)) {
	WRITESIDEBARBUTTON("$key", null, "$val");
    }
926
    echo "</ul>\n";
927 928
}

929 930 931
#
# spits out beginning part of page
#
932
function PAGEBEGINNING( $title, $nobanner = 0, $nocontent = 0,
933
			$extra_headers = NULL, $view = NULL ) {
934
    global $BASEPATH, $TBMAINSITE, $THISHOMEBASE, $ELABINELAB, $FANCYBANNER;
Chad Barb's avatar
Chad Barb committed
935
    global $TBDIR, $WWW;
936
    global $MAINPAGE, $ISALTDOMAIN;
937
    global $TBDOCBASE, $GENIRACK;
938
    global $autorefresh, $currentusage, $javascript_debug, $login_user;
939
    global $noAnalytics;
940

941 942
    $MAINPAGE = !strcmp($TBDIR, "/usr/testbed/");

943 944 945 946 947
    echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 
          'http://www.w3.org/TR/html4/loose.dtd'>
	<html>
	  <head>
	    <title>$THISHOMEBASE - $title</title>
948
            <link rel=\"shortcut icon\" href=\"$BASEPATH/favicon.ico\" TYPE=\"image/vnd.microsoft.icon\">
949
            <link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"$THISHOMEBASE Search\" href=\"emusearch.xml\">
950
    	    <!-- dumbed-down style sheet for any browser that groks (eg NS47). -->
951
	    <link rel='stylesheet' href='$BASEPATH/common-style.css' type='text/css' />
952 953
    	    <!-- do not import full style sheet into NS47, since it does bad job
            of handling it. NS47 does not understand '@import'. -->
954
    	    <style type='text/css' media='all'>
955
            <!-- @import url($BASEPATH/style.css?version=1); -->
956
            <!-- @import url($BASEPATH/cssmenu-new.css); -->\n";
957 958 959 960
    # Is this an alternate view with it's own style overrides?
    if (isset($view) && VIEWSET($view, 'css-override')) {
	$ovrfile = "override-". strtolower($THISHOMEBASE) .".css";
	if (file_exists($ovrfile)) {
961
	    echo "            <!-- @import url($BASEPATH/$ovrfile); -->\n";
962 963 964
	}
    }
    elseif (1 && !$MAINPAGE) {
965
	echo "<!-- @import url($BASEPATH/style-nonmain.css); -->";
966
    }
967
    echo "</style>\n";
968 969
    echo "<!-- [if gt IE 6.0]><style type=\"text/css\">".
	".menu ul li a:hover ul { top: 18px; }</style><![endif]> -->\n";
970

971
    if ($TBMAINSITE && !$ISALTDOMAIN) {
972 973
	echo "<meta name=\"keywords\" ".
	           "content=\"network, emulation, internet, emulator, ".
Leigh Stoller's avatar
Leigh Stoller committed
974
	           "mobile, wireless, robotic\">\n";
975 976 977 978
	echo "<meta name=\"robots\" ".
	           "content=\"NOARCHIVE\">\n";
	echo "<meta name=\"description\" ".
                   "content=\"emulab - network emulation testbed home\">\n";
979
    }
980 981 982 983
    # This needs to stay first! It defines things that might get used by
    # later scripts
    echo "<script type='text/javascript'
                  src='${BASEPATH}/onload.js'></script>\n";
984 985 986
    if ($extra_headers) {
        echo $extra_headers;
    }
987 988 989 990
    if ($javascript_debug) {
	echo "<script type='text/javascript'
                      src='${BASEPATH}/js/inline-console.js'></script>\n";
    }
991
    echo "</head><body>\n";
992

993
    if ($TBMAINSITE && !$noAnalytics && file_exists("google-analytics.php")) {
994
	readfile("google-analytics.php");
995 996 997 998 999

	echo "<script type='text/javascript'>\n
                ga('create', 'UA-45161989-1', 'emulab.net');\n
                ga('send', 'pageview');\n
              </script>\n";
1000
    }
1001 1002
    
    if ($autorefresh) {
1003
	echo "<meta HTTP-EQUIV=\"Refresh\" content=\"$autorefresh\">\n";
1004
    }
1005 1006
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/emulab_sup.js'></script>\n";
1007 1008
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/sorttable.js'></script>\n";
1009 1010
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/textbox.js'></script>\n";
1011

1012
    if (!$nobanner) {
1013 1014 1015 1016 1017
        #
        # We do the banner differently for the Utah site and other sites.
        # The process of generating the fancy Utah banner is kind of 
        # complicated
        #
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
	if ($login_user) {
		echo "<div class='topcell'>\n";
	}
	else {
	    if ($FANCYBANNER) {
		echo "<div id='fancybannercell'>\n";
	    }
	    else {
		echo "<div id='bannercell'>\n";
	    }
	}
1029 1030 1031

        # NOTE: This has to come before any images in the div for the float to
        # work correctly.
1032 1033 1034 1035 1036 1037 1038
	if ($currentusage && !$login_user) {
	    if ($FANCYBANNER) {
		$class = "transparentusageframe";
	    }
	    else {
		$class = "usageframe";
	    }
1039
	    echo "<iframe src='$BASEPATH/currentusage.php3' class='$class'
1040
                          scrolling='no' frameborder='0'></iframe>\n";
1041
	}
1042 1043 1044 1045 1046 1047 1048 1049
	if ($login_user) {
	    #
	    # It is a violation of Emulab licensing restrictions to remove
	    # this logo!
            #
            # NOTE: This has to come before any images in the div for the
	    # float to work correctly.
	    #
1050
	    if (!$TBMAINSITE || $ISALTDOMAIN) {
1051 1052 1053 1054
		echo "<a class='rightsidebuiltwith' ".
		    "href='http://www.emulab.net'>";
		echo "<img src='$BASEPATH/fancy-builtwith.png'></a>\n";
	    }
1055 1056 1057
	    echo "<table id=topcelltable ".
		     "cellspacing=0 cellpadding=0 border=0><tr>";
	    
1058 1059 1060 1061
	    echo "<td>\n";
	    echo "<a id='topcellimage' href='$TBDOCBASE/index.php3'>";
	    echo "<img border='0' ";
	    echo "alt='$THISHOMEBASE - the network testbed' ";
1062
	    if ($FANCYBANNER) {
1063
		echo "src='$BASEPATH/fancy-sheader-" .
1064 1065 1066
		    ($GENIRACK ? "genirack" : strtolower($THISHOMEBASE)) .
		    ".png' ";
	    }
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
	    elseif ($ELABINELAB) {
		echo "height='54' ";
		echo "src='$BASEPATH/overlay.elabinelab.gif' ";
	    }
	    else {
		echo "height='54' ";
		echo "src='$BASEPATH/overlay." .
			strtolower($THISHOMEBASE) . ".gif' ";
	    }
	    echo "></a>\n";
	    echo "</td>\n";
	}
	else {
	    if ($FANCYBANNER) {
		echo "<a href='$TBDOCBASE/index.php3'>
1082 1083
                        <img height='100px' width='365px' border='0' ";
		echo "src='$BASEPATH/fancy-header-" .
1084 1085
		    ($GENIRACK ? "genirack" : strtolower($THISHOMEBASE)) .
		    ".png' ";
1086 1087 1088
		echo "></a>\n";
	    }
	    else {
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
		echo "<map name='overlaymap'>
                         <area shape=\"rect\" coords=\"100,60,339,100\"
                               href='http://www.emulab.net/index.php3'>
                         <area shape=\"rect\" coords=\"0,0,339,100\"
                               href='$TBDOCBASE/index.php3'>
                      </map>\n";
		echo "<img height='100' border='0' usemap=\"#overlaymap\" ";
		if ($ELABINELAB) {
		    echo "width='239' ";
		    echo "src='$BASEPATH/overlay.elabinelab.gif' ";
		}
		else {
		    echo "width='339' ";
		    echo "src='$BASEPATH/overlay." .
			strtolower($THISHOMEBASE) . ".gif' ";
		}
		echo "alt='$THISHOMEBASE - the network testbed'>\n";
1106
            }
1107 1108 1109 1110 1111 1112 1113
	}
        if (!$login_user) 
	    echo "</div>\n";
    }
    else {
	# Need this to force no top margin/padding. No idea why! 
	echo "<div id='nobannercell'></div>\n";
1114 1115
    }
    if (! $nocontent ) {
1116 1117 1118 1119 1120 1121 1122
	if ($login_user) {
	    ;
	}
	else {
	    echo "<div class='leftcell'>\n";
	    echo "<!-- sidebar begins -->\n";
	}
1123
    }
1124 1125 1126 1127 1128
}

#
# finishes sidebar td
#
1129
function FINISHSIDEBAR($nocontent = 0)
1130
{
1131
    global $TBMAINSITE, $TBBASE, $BASEPATH, $currentusage, $login_user;
1132
    global $ISALTDOMAIN;
1133 1134

    if (!$nocontent) {
1135
	if (!$TBMAINSITE || $ISALTDOMAIN) {
1136 1137 1138 1139
	    #
	    # It is a violation of Emulab licensing restrictions to remove
	    # this logo!
	    #
1140 1141 1142 1143
	    if (!$login_user) {
		echo "       <a class='builtwith' href='http://www.emulab.net'>
                             <img src='$BASEPATH/builtwith.png'></a>";
	    }
1144
	}
1145 1146 1147
	if ($currentusage && $login_user) {
	    $class = "navbarusageframe";
	    echo "<td>\n";
1148
	    if (0) {
1149
		echo "<iframe src='$BASEPATH/currentusage.php3' class='$class'
1150
                              scrolling='no' frameborder='0'></iframe>\n";
1151 1152
	    }
	    else {
1153 1154 1155 1156
		echo "<div onclick=\"ToggleUsageTable();\" ".
		     "onmouseover='return escape(\"Click to toggle mode\")' ".
		     "id=usagefreenodes>\n";
		echo "</div>\n";
1157
	    }
1158
	    echo "</td></tr></table>\n";
1159
	}
1160 1161
	echo "<!-- sidebar ends -->
              </div>";
1162
    }
1163 1164
}

1165 1166 1167
#
# Spit out a vanilla page header.
#
1168 1169
$PAGEHEADER_FUNCTION = function($title, $view = NULL, $extra_headers = NULL,
				$notice = NULL) {
1170 1171
    global $login_status, $login_user;
    global $TBBASE, $TBDOCBASE, $THISHOMEBASE;
1172
    global $BASEPATH, $drewheader, $autorefresh;
1173
    global $TBMAINSITE;
1174 1175

    $drewheader = 1;
1176 1177 1178
    if (isset($_GET['refreshrate']) && is_numeric($_GET['refreshrate'])) {
	$autorefresh = $_GET['refreshrate'];
    }
1179

1180
    #
1181
    # Figure out who is logged in, if anyone.
1182 1183 1184 1185
    #
    if (($login_user = CheckLogin($status)) != null) {
	$login_status = $status;
	$login_uid    = $login_user->uid();
1186 1187
    }

1188
    #
1189
    # If no view options were specified, get the ones for the current user.
1190 1191
    # if no user specific view, see if we are coming in via a virtual domain
    # with an alternate view.
1192 1193 1194
    #
    if (!$view) {
	$view = GETUSERVIEW();
1195 1196 1197
	# See if there is a domain override.
	if (empty($view)) {
	    $view = GETDOMVIEW();
1198
	}
1199 1200
    }

1201
    #
1202 1203
    # Check for NOLOGINS. 
    # We want to allow admin types to continue using the web interface,
1204 1205
    # and logout anyone else that is currently logged in!
    #
1206 1207
    if (NOLOGINS() && $login_user && !ISADMIN()) {
	DOLOGOUT($login_user);
1208
	$login_status = CHECKLOGIN_NOTLOGGEDIN;
1209
	$login_user   = null;
1210
    }
1211
    
1212
    header('Content-type: text/html; charset=utf-8');
1213 1214
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
1215
    if (1) {
1216 1217 1218 1219 1220 1221 1222
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header("Cache-Control: no-cache, must-revalidate");
	header("Pragma: no-cache");
    }
    else {
	header("Expires: " . gmdate("D, d M Y H:i:s", time() + 300) . " GMT"); 
    }
1223

1224
    if (VIEWSET($view, 'hide_banner')) {
1225 1226 1227 1228
	$nobanner = 1;
    } else {
	$nobanner = 0;
    }
1229
    $contentname = ($login_user ? "content" : "rightcontent");
1230
    $nocontent = VIEWSET($view, 'hide_sidebar') && !VIEWSET($view, 'menu');
1231
    PAGEBEGINNING( $title, $nobanner,
1232
		   $nocontent,
1233
		   $extra_headers, $view );
1234 1235 1236 1237 1238 1239 1240 1241
    if (VIEWSET($view, 'show_protogeni')) {
	echo "<table id=topcelltablefoo ".
	    "cellspacing=0 cellpadding=0 border=0><tr>".
	    "<td>".
	    "<img border='0' alt='ProtoGENI' src='$BASEPATH/protogeni.png'>".
	    "</td></tr></table>\n";
	$contentname = "fullcontent";
    }
1242 1243 1244
    elseif (VIEWSET($view, 'show_pnet')) {
	WRITEPNETSIDEBAR();
    }
1245
    elseif (!VIEWSET($view, 'hide_sidebar')) {
1246 1247
	WRITESIDEBAR();
    }
1248
    elseif (VIEWSET($view, 'menu')) {
1249 1250
	WRITESIMPLESIDEBAR($view['menu']);
    }
1251 1252 1253
    else {
	$contentname = "fullcontent";
    }
1254
    FINISHSIDEBAR($nocontent);
1255

1256 1257 1258 1259 1260 1261
    if ($login_user) {
	# This is only going to happen when its an admin person
	# still logged in while web interface disabled. Want to make it
	# clear that the web interface is disabled.
	if (NOLOGINS() && ISADMIN()) {
	    echo "<div class=webmessage>";
1262
	    echo "Web Interface Temporarily Unavailable</div>\n";
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
	}
	else {
	    $message = TBGetSiteVar("web/message");
	    if ($message != "") {
		echo "<div class=webmessage>$message</div>\n";
	    }
	}
    }

    echo "<div class='$contentname'>\n";
    echo "<!-- content body -->\n";

1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
    if (! VIEWSET($view, 'hide_title')) {
	if ($login_user)
	    echo "<div id='contentheader'>";
	else {
	    echo "<div class='contentbody'>";
	    echo "<div id='rightcontentheader'>";
	}
	echo "<div id='logintime'>";
	echo "<span class='loggedin'>";
	$now = date("D M d g:ia T");
	if ($login_user) {
	    echo "<span class='uid'>$login_uid</span> Logged in.";
	}
	echo "</span>";
	echo "<span class='timestamp'>$now</span>\n";
	echo "</div>";
1291
    
1292
	if ($login_user || VIEWSET($view, 'hide_versioninfo')) {
1293
	    $versioninfo = "";
1294 1295
	    $commithash  = "";
	}
1296 1297 1298 1299 1300
	else {
	    $major = "";
	    $minor = "";
	    $build = "";
	    TBGetVersionInfo($major, $minor, $build);
1301
	
1302
	    $versioninfo = "Vers: $major.$minor Build: $build";
Leigh Stoller's avatar
Leigh Stoller committed
1303 1304 1305
	    $commithash  = TBGetCommitHash();
	    if (!$commithash) {
		$commithash = "";
1306
	    }
1307
	}
1308 1309 1310 1311 1312 1313
	echo "<div id='versioninfo'>$versioninfo";
	if ($commithash != "") {
	    echo "<br>";
	    echo substr($commithash, 0, 24);
	}
	echo "</div>";
1314 1315 1316
	if ($notice) {
	    echo "<span class='headernotice'>$notice</span>";
	}
1317

1318 1319 1320 1321 1322 1323 1324
	if ($login_user)
	    echo "<h2 class='contenttitle'>\n";
	else
	    echo "<h2 class='rightcontenttitle'>\n";
	echo "$title</h2>";
        # Close off 'contentheader' (rightcontentheader);
	echo "</div>\n";
1325 1326 1327
	if ($commithash != "") {
	    echo "<!-- This site is running commit $commithash -->\n";
	}
1328 1329 1330 1331
	if ($login_user) {
        # And start the contentbody.
	    echo "<div id='fullcontentbody'>";
	}
1332
    }
1333
    echo "<!-- begin content -->";
1334
    if (VIEWSET($view, 'show_topbar', "plab")) {
1335 1336
	WRITEPLABTOPBAR();
    }
1337 1338 1339 1340 1341 1342 1343
};

function PAGEHEADER($title, $view = NULL, $extra_headers = NULL,
			$notice = NULL) {
    global $PAGEHEADER_FUNCTION;
    
    $PAGEHEADER_FUNCTION($title, $view, $extra_headers, $notice);
1344 1345 1346 1347 1348
}

#
# Spit out a vanilla page footer.
#
1349
$PAGEFOOTER_FUNCTION = function($view = NULL) {
1350
    global $TBDOCBASE, $TBMAILADDR, $THISHOMEBASE, $BASEPATH, $TBBASE;
1351
    global $TBMAINSITE, $bodyclosestring, $currently_busy;
1352
    global $login_user, $javascript_debug, $sortedtables;
1353
    global $FORUMURL;
1354 1355 1356 1357 1358

    if ($currently_busy) {
	CLEARBUSY();
	$currently_busy = 0;
    }
1359

1360 1361
    #
    # If no view options were specified, get the ones for the current user.
1362 1363
    # if no user specific view, see if we are coming in via a virtual
    # domain with an alternate view.
1364
    #
1365 1366
    if (!$view) {
	$view = GETUSERVIEW();
1367 1368
	if (empty($view)) {
	    $view = GETDOMVIEW();
1369
	}
1370 1371
    }

1372 1373
    $today = getdate();
    $year  = $today["year"];
Chad Barb's avatar
Chad Barb committed
1374

1375
    if (VIEWSET($view, 'show_bottombar', "plab")) {
1376 1377 1378 1379
	WRITEPLABBOTTOMBAR();
    }

    echo "
1380
              <div class='contentfooter'>\n";
1381
    if (!VIEWSET($view, 'hide_copyright')) {
1382
	echo "
1383
                <ul class='navlist'>
1384 1385 1386 1387 1388 1389
		<li>[&nbsp;<a href=\"http://www.cs.utah.edu/flux/\"
                    >Flux&nbsp;Research&nbsp;Group</a>&nbsp;]</li>
	        <li>[&nbsp;<a href=\"http://www.cs.utah.edu/\"
                    >School&nbsp;of&nbsp;Computing</a>&nbsp;]</li>
		<li>[&nbsp;<a href=\"http://www.utah.edu/\"
                    >University&nbsp;of&nbsp;Utah</a>&nbsp;]</li>
1390
                </ul>
Chad Barb's avatar
Chad Barb committed
1391
                <!-- begin copyright -->
1392
                <span class='copyright'>
1393
                <a href=$TBDOCBASE/copyright.php>
1394
                    Copyright &copy; 2000-$year The University of Utah</a>
1395
                </span>\n";
1396
    }
1397 1398 1399 1400 1401
    echo "      <br>\n";
    echo "      <table class=stealth width=100% ".
	               "border='0' cellspacing='0' cellpadding='0'>";
    echo "       <tr>\n";
    
1402
    if ($login_user) {
1403
	echo "    <td class=reportbug>Questions? Join the ";
1404
	echo "      <a href='$FORUMURL'>";
1405
	echo "        Help Forum</a>";
1406 1407
	echo "    </td>";
    }
1408
    echo "        <td class=contact>Bug? Join the ";
1409
    echo "          <a href='$FORUMURL'>";
1410 1411
    echo "             Help Forum</a>";
    echo "        </td>";
1412
    echo "       </tr>\n";
1413
    echo "      </table>\n";
1414
    echo "      <!-- end copyright -->\n";
1415 1416
    echo "</div>";
    echo "</div>";
Chad Barb's avatar
Chad Barb committed
1417

1418 1419 1420 1421
    if ($javascript_debug) {
	echo "<div id='inline-console'></div>\n";
    }

1422
    # Plug the home site from all others.
1423
    echo "\n<a href=\"www.emulab.net/netemu.php3\"></a>\n";
1424

1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
    if ($login_user) {
	echo "<script>\n";
	sajax_show_javascript();
	?>
	    var cookieresults =
		document.cookie.match('usagetablemode=(.*?)(;|$)');
	    var usagetablemode =
		(cookieresults ? cookieresults[1] : "status");
	    
	    function x_FreeNodeHtml() {
		sajax_do_call("<?php echo $TBBASE; ?>/currentusage.php3",
			      "FreeNodeHtml",
			      x_FreeNodeHtml.arguments);
	    }
	    function FreeNodeHtml_CB(stuff) {
		getObjbyName('usagefreenodes').innerHTML = stuff;
		setTimeout('GetFreeNodeHtml()', 60000);
	    }
	    function GetFreeNodeHtml() {
		x_FreeNodeHtml(usagetablemode, FreeNodeHtml_CB);
	    }
            function ToggleUsageTable() {
1447 1448 1449 1450 1451 1452 1453 1454 1455
		if (usagetablemode == "status") {
		    usagetablemode = "freenodes";
		}
		else if (usagetablemode == "freenodes") {
		    usagetablemode = "stats";
		}
		else {
		    usagetablemode = "status";
		}
1456 1457 1458 1459 1460 1461 1462 1463
		document.cookie = "usagetablemode=" + usagetablemode;
		GetFreeNodeHtml();
            }
	    GetFreeNodeHtml();
	<?php
	echo "</script>\n";
    }
    
1464 1465 1466 1467 1468 1469 1470 1471 1472
    # Prime all the sortable tables.
    if (count($sortedtables)) {
	echo "<script type='text/javascript' language='javascript'>\n";
	foreach ($sortedtables as $i => $id) {
	    echo "sorttable.makeSortable(getObjbyName('$id'));\n";
	}
	echo "</script>\n";
    }

1473
    # This has to be after all the tooltip definitions.
1474 1475
    echo "<script type='text/javascript' src='${TBBASE}/js/wz_tooltip.js'>".
	"</script>";
Leigh Stoller's avatar