menu.php3 49.5 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2016, 2018 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     = ($TBMAINSITE ? 0 : 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
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.
152
function NavMenuButtonNew($text, $link = null, $divider = FALSE, $target = null)
153 154 155 156
{
    global $navmenu, $login_user;

    if ($login_user)
157
	NavMenuButton($text, $link, "&nbsp;<img src=\"/new.gif\">",
158
		      $target, $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, $currentusage;
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
		NavMenuButtonDivider("Node Status",
				     "$TBBASE/nodecontrol_list.php3");

574 575 576 577 578 579
                if (!$currentusage) {
                    NavMenuButtonNew("Resource Availability",
                                     "$TBBASE/portal/resinfo.php",
                                     false, "_blank");
                }

580 581
		NavMenuButton("List ImageIDs",
			      "$TBBASE/showimageid_list.php3");
582

583 584 585 586
		if (ISADMIN()) {
		    NavMenuButton("List OSIDs",
				  "$TBBASE/showosid_list.php3");
		}
587 588 589 590 591
                # Do we have a storage pool? Then we support datasets.
                if (HaveStoragePool()) {
                    NavMenuButton("List Datasets",
                                  "$TBBASE/list-datasets.php");
                }
592

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

function WRITEADMINMENU() {
624
    global $TBBASE, $TBDOCBASE, $TBMAINSITE;
625
    global $PROTOGENI, $ISALTDOMAIN;
626 627
    global $login_status;

628 629 630
    # Do we have a storage pool? The we support datasets.
    $havestoragepool = HaveStoragePool();

631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
    # 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");

652
	if ($TBMAINSITE && !$ISALTDOMAIN) {
653 654 655 656 657 658 659
	    NavMenuButton("Emulab Site List",
			  "$TBBASE/showsite_list.php");
	}

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

660
	if ($havestoragepool) {
661 662 663 664 665 666
	    NavMenuButton("Local Datasets",
			  "$TBBASE/list-datasets.php?all=1");
	    NavMenuButton("Remote Datasets",
			  "$TBBASE/apt/list-datasets.php?all=1");
	}

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
	$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.
#
688
function WRITEPNETSIDEBAR() {
689 690 691
    global $login_status, $login_user;
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $TBMAINSITE, $THISHOMEBASE;
692
    global $WIKIDOCURL, $FORUMURL;
693 694 695

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

696
    WRITEMIDTOPBAR($newsBase, $newNews);
697 698 699

    NavMenuStart();
    NavMenuSection("information", "Information");
Kirk Webb's avatar
Kirk Webb committed
700
    NavMenuButton("Home", "$TBDOCBASE/pnet-index.php?stayhome=1");
701 702 703 704 705 706 707 708

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

    NavMenuButton("Documentation", "$WIKIDOCURL");
709
    NavMenuButtonNew("Forums", "$FORUMURL");
710 711 712 713 714

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

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

    WRITELOGINBOX($lbox_content);
    WRITEEXPERIMENTMENU(0);
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
    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;
751
    global $CHECKLOGIN_WIKINAME, $TBMAINSITE, $ISALTDOMAIN;
752 753
    global $THISHOMEBASE;
    global $currentusage, $FANCYBANNER, $ELABINELAB, $PLABSUPPORT;
754
    global $WIKIDOCURL, $FORUMURL;
755 756 757 758
    $firstinitstate = TBGetFirstInitState();

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

759
    WRITEMIDTOPBAR($newsBase, $newNews);
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
   
    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");
784
    NavMenuButtonNew("Forums", "$FORUMURL");
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802

    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");
    }
803
    if ($TBMAINSITE && !$ISALTDOMAIN) {
804 805 806 807 808 809 810 811
	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();
812 813 814 815 816 817 818 819 820 821
	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>";
822 823
    }

824 825 826 827 828 829
    $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);
830
    WRITEEXPERIMENTMENU($firstinitstate);
Chad Barb's avatar
Chad Barb committed
831

832
    # And now the Collaboration menu.
Leigh Stoller's avatar
Leigh Stoller committed
833
    if (($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) &&
834
	($WIKISUPPORT || $BUGDBSUPPORT ||
Leigh Stoller's avatar
Leigh Stoller committed
835
	 $CVSSUPPORT  || $CHATSUPPORT)) {
836 837

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

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

891
    WRITEADMINMENU();
892

893 894 895
    if (0 && $login_user) {
	NavMenuSection("Status", "Status");
	
896
	$freepcs = TBFreePCs($login_user);
897 898 899 900 901 902 903 904 905
	$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");
    }
906

907 908 909 910 911 912 913 914 915
    # 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";
916
    }
917 918
}

919 920 921 922 923 924
#
# Simple version of above, that just writes the given menu.
# 
function WRITESIMPLESIDEBAR($menudefs) {
    $menutitle = $menudefs['title'];
    
925
    echo "<h3 class='menuheader'>$menutitle</h3>
926
          <ul class='navmenu'>";
927 928 929 930 931

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

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

947 948
    $MAINPAGE = !strcmp($TBDIR, "/usr/testbed/");

949 950 951 952 953
    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>
954
            <link rel=\"shortcut icon\" href=\"$BASEPATH/favicon.ico\" TYPE=\"image/vnd.microsoft.icon\">
955
            <link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"$THISHOMEBASE Search\" href=\"emusearch.xml\">
956
    	    <!-- dumbed-down style sheet for any browser that groks (eg NS47). -->
957
	    <link rel='stylesheet' href='$BASEPATH/common-style.css' type='text/css' />
958 959
    	    <!-- do not import full style sheet into NS47, since it does bad job
            of handling it. NS47 does not understand '@import'. -->
960
    	    <style type='text/css' media='all'>
961
            <!-- @import url($BASEPATH/style.css?version=1); -->
962
            <!-- @import url($BASEPATH/cssmenu-new.css); -->\n";
963 964 965 966
    # 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)) {
967
	    echo "            <!-- @import url($BASEPATH/$ovrfile); -->\n";
968 969 970
	}
    }
    elseif (1 && !$MAINPAGE) {
971
	echo "<!-- @import url($BASEPATH/style-nonmain.css); -->";
972
    }
973
    echo "</style>\n";
974 975
    echo "<!-- [if gt IE 6.0]><style type=\"text/css\">".
	".menu ul li a:hover ul { top: 18px; }</style><![endif]> -->\n";
976

977
    if ($TBMAINSITE && !$ISALTDOMAIN) {
978 979
	echo "<meta name=\"keywords\" ".
	           "content=\"network, emulation, internet, emulator, ".
Leigh Stoller's avatar
Leigh Stoller committed
980
	           "mobile, wireless, robotic\">\n";
981 982 983 984
	echo "<meta name=\"robots\" ".
	           "content=\"NOARCHIVE\">\n";
	echo "<meta name=\"description\" ".
                   "content=\"emulab - network emulation testbed home\">\n";
985
    }
986 987 988 989
    # 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";
990 991 992
    if ($extra_headers) {
        echo $extra_headers;
    }
993 994 995 996
    if ($javascript_debug) {
	echo "<script type='text/javascript'
                      src='${BASEPATH}/js/inline-console.js'></script>\n";
    }
997
    echo "</head><body>\n";
998

999
    if ($TBMAINSITE && !$noAnalytics && file_exists("google-analytics.php")) {
1000
	readfile("google-analytics.php");
1001 1002 1003 1004 1005

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

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

1036 1037 1038 1039 1040 1041 1042 1043
	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.
	    #
1044
	    if (!$TBMAINSITE || $ISALTDOMAIN) {
1045 1046 1047 1048
		echo "<a class='rightsidebuiltwith' ".
		    "href='http://www.emulab.net'>";
		echo "<img src='$BASEPATH/fancy-builtwith.png'></a>\n";
	    }
1049 1050 1051
	    echo "<table id=topcelltable ".
		     "cellspacing=0 cellpadding=0 border=0><tr>";
	    
1052 1053 1054 1055
	    echo "<td>\n";
	    echo "<a id='topcellimage' href='$TBDOCBASE/index.php3'>";
	    echo "<img border='0' ";
	    echo "alt='$THISHOMEBASE - the network testbed' ";
1056
	    if ($FANCYBANNER) {
1057
		echo "src='$BASEPATH/fancy-sheader-" .
1058 1059 1060
		    ($GENIRACK ? "genirack" : strtolower($THISHOMEBASE)) .
		    ".png' ";
	    }
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
	    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'>
1076 1077
                        <img height='100px' width='365px' border='0' ";
		echo "src='$BASEPATH/fancy-header-" .
1078 1079
		    ($GENIRACK ? "genirack" : strtolower($THISHOMEBASE)) .
		    ".png' ";
1080 1081 1082
		echo "></a>\n";
	    }
	    else {
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
		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";
1100
            }
1101 1102 1103 1104 1105 1106 1107
	}
        if (!$login_user) 
	    echo "</div>\n";
    }
    else {
	# Need this to force no top margin/padding. No idea why! 
	echo "<div id='nobannercell'></div>\n";
1108 1109
    }
    if (! $nocontent ) {
1110 1111 1112 1113 1114 1115 1116
	if ($login_user) {
	    ;
	}
	else {
	    echo "<div class='leftcell'>\n";
	    echo "<!-- sidebar begins -->\n";
	}
1117
    }
1118 1119 1120 1121 1122
}

#
# finishes sidebar td
#
1123
function FINISHSIDEBAR($nocontent = 0)
1124
{
1125
    global $TBMAINSITE, $TBBASE, $BASEPATH, $currentusage, $login_user;
1126
    global $ISALTDOMAIN;
1127 1128

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

1160 1161 1162
#
# Spit out a vanilla page header.
#
1163 1164
$PAGEHEADER_FUNCTION = function($title, $view = NULL, $extra_headers = NULL,
				$notice = NULL) {
1165 1166
    global $login_status, $login_user;
    global $TBBASE, $TBDOCBASE, $THISHOMEBASE;
1167
    global $BASEPATH, $drewheader, $autorefresh;
1168
    global $TBMAINSITE;
1169 1170

    $drewheader = 1;
1171 1172 1173
    if (isset($_GET['refreshrate']) && is_numeric($_GET['refreshrate'])) {
	$autorefresh = $_GET['refreshrate'];
    }
1174

1175
    #
1176
    # Figure out who is logged in, if anyone.
1177 1178 1179 1180
    #
    if (($login_user = CheckLogin($status)) != null) {
	$login_status = $status;
	$login_uid    = $login_user->uid();
1181 1182
    }

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

1196
    #
1197 1198
    # Check for NOLOGINS. 
    # We want to allow admin types to continue using the web interface,
1199 1200
    # and logout anyone else that is currently logged in!
    #
1201 1202
    if (NOLOGINS() && $login_user && !ISADMIN()) {
	DOLOGOUT($login_user);
1203
	$login_status = CHECKLOGIN_NOTLOGGEDIN;
1204
	$login_user   = null;
1205
    }
1206
    
1207
    header('Content-type: text/html; charset=utf-8');
1208 1209
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
1210
    if (1) {
1211 1212 1213 1214 1215 1216 1217
	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"); 
    }
1218

1219
    if (VIEWSET($view, 'hide_banner')) {
1220 1221 1222 1223
	$nobanner = 1;
    } else {
	$nobanner = 0;
    }
1224
    $contentname = ($login_user ? "content" : "rightcontent");
1225
    $nocontent = VIEWSET($view, 'hide_sidebar') && !VIEWSET($view, 'menu');
1226
    PAGEBEGINNING( $title, $nobanner,
1227
		   $nocontent,
1228
		   $extra_headers, $view );
1229 1230 1231 1232 1233 1234 1235 1236
    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";
    }
1237 1238 1239
    elseif (VIEWSET($view, 'show_pnet')) {
	WRITEPNETSIDEBAR();
    }
1240
    elseif (!VIEWSET($view, 'hide_sidebar')) {
1241 1242
	WRITESIDEBAR();
    }
1243
    elseif (VIEWSET($view, 'menu')) {
1244 1245
	WRITESIMPLESIDEBAR($view['menu']);
    }
1246 1247 1248
    else {
	$contentname = "fullcontent";
    }
1249
    FINISHSIDEBAR($nocontent);
1250

1251 1252 1253 1254 1255 1256
    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>";
1257
	    echo "Web Interface Temporarily Unavailable</div>\n";
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
	}
	else {
	    $message = TBGetSiteVar("web/message");
	    if ($message != "") {
		echo "<div class=webmessage>$message</div>\n";
	    }
	}
    }

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

1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
    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>";
1286
    
1287
	if ($login_user || VIEWSET($view, 'hide_versioninfo')) {
1288
	    $versioninfo = "";
1289 1290
	    $commithash  = "";
	}
1291 1292 1293 1294 1295
	else {
	    $major = "";
	    $minor = "";
	    $build = "";
	    TBGetVersionInfo($major, $minor, $build);
1296
	
1297
	    $versioninfo = "Vers: $major.$minor Build: $build";
Leigh Stoller's avatar
Leigh Stoller committed
1298 1299 1300
	    $commithash  = TBGetCommitHash();
	    if (!$commithash) {
		$commithash = "";
1301
	    }
1302
	}
1303 1304 1305 1306 1307 1308
	echo "<div id='versioninfo'>$versioninfo";
	if ($commithash != "") {
	    echo "<br>";
	    echo substr($commithash, 0, 24);
	}
	echo "</div>";
1309 1310 1311
	if ($notice) {
	    echo "<span class='headernotice'>$notice</span>";
	}
1312

1313 1314 1315 1316 1317 1318 1319
	if ($login_user)
	    echo "<h2 class='contenttitle'>\n";
	else
	    echo "<h2 class='rightcontenttitle'>\n";
	echo "$title</h2>";
        # Close off 'contentheader' (rightcontentheader);
	echo "</div>\n";
1320 1321 1322
	if ($commithash != "") {
	    echo "<!-- This site is running commit $commithash -->\n";
	}
1323 1324
	if ($login_user) {
        # And start the contentbody.
1325
	    echo "<div id='fullcontentbody'>\n";
1326
	    if (0 && $TBMAINSITE) {
1327 1328 1329
            echo "<center style='margin: 5px;'>";
            echo "<span class='blink_me'><a target=_blank href='https://gitlab.flux.utah.edu/emulab/emulab-devel/wikis/faq/Using%20the%20Testbed/Emulab%20Classic'>NEW WEB INTERFACE</a> coming on Sept 4th!</span>";
            echo "</center>\n";
1330
	    }
1331
	}
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, $currentusage;
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
    if ($currentusage && $login_user) {
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
	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";
		}