menu.php3 41.1 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
# All rights reserved.
#
7

8
$login_user       = null;
9
$login_status     = CHECKLOGIN_NOTLOGGEDIN;
10
$drewheader       = 0;
11
$noheaders	  = 0;
12
$autorefresh      = 0;
13
$javascript_debug = 0;
14
$currentusage     = 1;
15
$currently_busy   = 0;
16
$sortedtables     = array();
17
$bodyclosestring  = "";
18
19
$navmenu          = null;
$navmenuopen      = FALSE;
20

21
22
23
24
25
26
#
# 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	  = "";

Timothy Stack's avatar
   
Timothy Stack committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#
# 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.
#
if (isset($SSL_PROTOCOL)) {
    $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.
45
46
$nextnavbarcl     = null;
$nextsubmenucl    = null;
Timothy Stack's avatar
   
Timothy Stack committed
47

48
49
50
51
52
53
54
# Add a table id to the list of sorted tables to initialize on current page.
function AddSortedTable($id) {
    global $sortedtables;

    $sortedtables[] = $id;
}

55
#
56
57
# TOPBARCELL - Make a cell for the topbar. Actually, the name lies, it can be
# used for cells in a bottombar too.
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
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\" />");
}

81
#
82
# Start the primary navmenu.
83
#
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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)
139
140
	NavMenuButton($text, $link, "&nbsp;<img src=\"/new.gif\">",
		      null, $divider);
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    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";
189
190
}

191
192
193
194
195
#
# 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.
#
196
function WRITESIDEBARBUTTON($text, $link, $extratext="") {
Timothy Stack's avatar
   
Timothy Stack committed
197
198
199
200
201
202
203
204
    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
205
}
206

Chad Barb's avatar
   
Chad Barb committed
207
# same as above with "new" gif next to it.
Timothy Stack's avatar
   
Timothy Stack committed
208
209
210
211
212
function WRITESIDEBARBUTTON_NEW($text, $base, $link) {
    WRITESIDEBARBUTTON($text,
		       $base,
		       $link,
		       "&nbsp;<img src=\"/new.gif\" />");
Chad Barb's avatar
   
Chad Barb committed
213
214
215
216
}

# writes a message to the sidebar, without clickability.
function WRITESIDEBARNOTICE($text) {
Timothy Stack's avatar
   
Timothy Stack committed
217
    echo "<span class='notice'>$text</span>\n";
218
219
220
221
222
223
224
225
226
}

#
# 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";
227
    global $login_status, $login_user;
228
229
230
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $THISHOMEBASE;

231
232
    WRITETOPBARBUTTON("Create a Slice",
        $TBBASE, "plab_ez.php3");
233

234
    WRITETOPBARBUTTON("Nodes",
235
236
237
        $TBBASE, "plabmetrics.php3");

    WRITETOPBARBUTTON("My Testbed",
238
		      $TBBASE, CreateURL("showuser", $login_user));
239
240

    WRITETOPBARBUTTON("Advanced Experiment",
241
        $TBBASE, "beginexp_html.php3");
242

243
244
    if ($login_status & CHECKLOGIN_TRUSTED && $login_user->ApprovalList(0)) {
	WRITESIDEBARBUTTON_NEW("Approve Users",
245
246
247
248
249
250
			       $TBBASE, "approveuser_form.php3");
    }

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

251
252
253
    echo "</table>\n";
    echo "<br>\n";

254
255
}

256
257
258
259
260
261

#
# 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() {
262
    global $login_status, $login_user;
263
264
265
    global $TBBASE, $TBDOCBASE, $BASEPATH;
    global $THISHOMEBASE;

266
    if ($login_user) {
267
268
269
270
271
272
	$newsBase = $TBBASE; 
    } else {
	$newsBase = $TBDOCBASE;
    }

    echo "
273
274
275
	   <center>
	   <br>
	   <font size=-1>
276
	   <form method=get action=$TBDOCBASE/search.php3>
277
278
279
280
	   [ <a href='$TBDOCBASE/doc.php3'>
		Documentation</a> : <input name=query size = 15/>
		  <input type=submit style='font-size:10px;' value='Search' /> ]
	   [ <a href='$newsBase/news.php3'>
281
		News</a> ]
282
283
284
285
	   </form>
	   </font>
	   <br>
	   </center>\n";
286
287
288

}

289
290
291
292
293
#
# WRITESIDEBAR(): Write the menu. The actual menu options the user
# sees depends on the login status and the DB status.
#
function WRITESIDEBAR() {
294
    global $login_status, $login_user, $pid, $gid;
295
    global $TBBASE, $TBDOCBASE, $BASEPATH, $WIKISUPPORT, $MAILMANSUPPORT;
296
    global $BUGDBSUPPORT, $BUGDBURL, $CVSSUPPORT, $CHATSUPPORT, $TRACSUPPORT;
297
    global $CHECKLOGIN_WIKINAME;
298
    global $THISHOMEBASE;
299
    global $EXPOSETEMPLATES;
300
    global $currentusage, $FANCYBANNER, $ELABINELAB;
301
    $firstinitstate = TBGetFirstInitState();
302

Chad Barb's avatar
   
Chad Barb committed
303
304
305
306
307
308
309
310
    #
    # 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 ".
311
		     "WHERE archived=0 ".
Chad Barb's avatar
   
Chad Barb committed
312
313
314
315
316
317
318
319
		     "ORDER BY date DESC ".
		     "LIMIT 1");
    $newsDate = "";
    $newNews  = 0;

    #
    # This is so an admin can use the editing features of news.
    #
320
    if ($login_user) {
Chad Barb's avatar
   
Chad Barb committed
321
322
323
324
325
326
	$newsBase = $TBBASE; 
    } else {
	$newsBase = $TBDOCBASE;
    }

    if ($row = mysql_fetch_array($query_result)) {
327
328
	$newsDate = "(".$row["prettydate"].")";
	if ($row["age"] < 7) {
Chad Barb's avatar
   
Chad Barb committed
329
330
331
332
	    $newNews = 1;
	}
    }

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    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) . "'>".
		"My Emulab</a>\n";

	    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 B. Stoller's avatar
Leigh B. Stoller committed
407
	echo "<tr id=spacer><td id=spacer></td></tr>";
408
409
410
411
412
413
	echo "<tr><td>";
    }
   
    NavMenuStart();
    NavMenuSection("information", "Information");
    NavMenuButton("Home", "$TBDOCBASE/index.php3?stayhome=1");
414

Chad Barb's avatar
   
Chad Barb committed
415
416
417
418
419
420
    if (0 == strcasecmp($THISHOMEBASE, "emulab.net")) {
	$rootEmulab = 1;
    } else {
	$rootEmulab = 0;
    }
    if ($rootEmulab) {
421
422
	NavMenuButton("Other Emulabs", 
		      "$TBDOCBASE/docwrapper.php3?docname=otheremulabs.html");
Chad Barb's avatar
   
Chad Barb committed
423
    } else {
424
	NavMenuButton("Utah Emulab", "http://www.emulab.net/");
Chad Barb's avatar
   
Chad Barb committed
425
    }
Chad Barb's avatar
   
Chad Barb committed
426

Chad Barb's avatar
   
Chad Barb committed
427
    if ($newNews) {
428
	NavMenuButtonNew("News $newsDate", "$newsBase/news.php3");
Chad Barb's avatar
   
Chad Barb committed
429
    } else {
430
	NavMenuButton("News $newsDate", "$newsBase/news.php3");
Chad Barb's avatar
   
Chad Barb committed
431
432
    }

433
    NavMenuButton("Documentation", "$TBDOCBASE/doc.php3");
Chad Barb's avatar
   
Chad Barb committed
434
435

    if ($rootEmulab) {
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
	# Leave New here about 2 weeks
        NavMenuButton("Papers and Talks (Mar 9)", "$TBDOCBASE/pubs.php3");
	NavMenuButton("Software (Jul 18)", "$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");
Chad Barb's avatar
   
Chad Barb committed
451
    }
Timothy Stack's avatar
   
Timothy Stack committed
452
453
454

    # The search box.  Placed in a table so the text input fills available
    # space.
455
456
457
    if (! $login_user) {
	NavMenuSectionEnd();
	echo "<div id='searchrow'>
458
459
460
        <form method='get' action='$newsBase/search.php3'>
        <table border='0' cellspacing='0' cellpadding='0'><tr>
             <td width='100%'><input class='textInputEmpty' name='query'
461
462
463
464
465
                        value='Search Documentation' id='searchbox'
                        onfocus='focus_text(this, \"Search Documentation\")'
                        onblur='blur_text(this, \"Search Documentation\")' />
               </td>
	     <td><input type='submit' id='searchsub' value=Go /></td>
Timothy Stack's avatar
   
Timothy Stack committed
466
467
468
        </table>
        </form>
	</div>\n";
469
470
    }
    
471
472
473
474
475
476
    #
    # Cons up a nice message.
    # 
    switch ($login_status & CHECKLOGIN_STATUSMASK) {
    case CHECKLOGIN_LOGGEDIN:
	if ($login_status & CHECKLOGIN_PSWDEXPIRED)
Timothy Stack's avatar
   
Timothy Stack committed
477
	    $login_message = "(Password Expired!)";
478
	elseif ($login_status & CHECKLOGIN_UNAPPROVED)
Timothy Stack's avatar
   
Timothy Stack committed
479
480
481
	    $login_message = "(Unapproved!)";
	else
	    $login_message = 0;
482
483
484
485
486
487
488
489
490
491
	break;
    case CHECKLOGIN_TIMEDOUT:
	$login_message = "Login Timed out.";
	break;
    default:
	$login_message = 0;
	break;
    }

    #
Timothy Stack's avatar
   
Timothy Stack committed
492
    # Now the login box.
493
    # We want the links to the login pages to always be https,
494
495
496
    # 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.
497
498
499
    #
    if (! ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) &&
	!NOLOGINS()) {
Timothy Stack's avatar
   
Timothy Stack committed
500
501
502
503
504
	echo "<div id='loginbox'>";

	if ($login_message) {
	    echo "<strong>$login_message</strong>";
	}
505
506
507
508

	if (!$firstinitstate) {
	    echo "<a href=\"$TBBASE/reqaccount.php3\">";
	    echo "<img alt=\"Request Account\" border=0 ";
509
	    echo "src=\"$BASEPATH/requestaccount.gif\" width=\"144\" height=\"32\"></a>";
510

Timothy Stack's avatar
   
Timothy Stack committed
511
	    echo "<strong>or</strong>";
512
513
514
515
	}

	echo "<a href=\"$TBBASE/login.php3\">";
	echo "<img alt=\"logon\" border=0 ";
516
	echo "src=\"$BASEPATH/logon.gif\" width=\"144\" height=\"32\"></a>\n";
517

Timothy Stack's avatar
   
Timothy Stack committed
518
	echo "</div>";
519
520
521
522
523
524
525
        #
        # Login message. Set via 'web/message' site variable
        #
        $message = TBGetSiteVar("web/message");
        if (0 != strcmp($message,"")) {
	    WRITESIDEBARNOTICE($message);
	}
526
527
    }

528
529
530
531
    #
    # 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.
532
533
    #
    if (!$login_user && NOLOGINS()) {
Timothy Stack's avatar
   
Timothy Stack committed
534
535
	echo "<a id='webdisabled' href='$TBDOCBASE/nologins.php3'>".
	    "Web Interface Temporarily Unavailable</a>";
536
	WRITESIDEBARNOTICE("Please Try Again Later");
Timothy Stack's avatar
   
Timothy Stack committed
537
538
539
540
    }

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

544
    if ($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) {
545
546
	if ($firstinitstate != null) {    
	    if ($firstinitstate == "createproject") {
Russ Fish's avatar
Russ Fish committed
547
		NavMenuButton("<font color=red> Create First Project </font>&nbsp",
548
			      "$TBBASE/newproject.php3");
549
550
551
552
	    }
	    elseif ($firstinitstate == "approveproject") {
		$firstinitpid = TBGetFirstInitPid();
		
553
554
555
		NavMenuButton("Approve First Project",
			      "$TBBASE/approveproject.php3?pid=$firstinitpid".
			      "&approval=approve");
556
557
558
	    }
	}
	elseif ($login_status & CHECKLOGIN_ACTIVE) {
559
	    if ($login_status & CHECKLOGIN_PSWDEXPIRED) {
560
561
		NavMenuButton("Change Your Password",
			      "$TBBASE/moduserinfo.php3");
562
	    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
563
	    elseif ($login_status & (CHECKLOGIN_WEBONLY|CHECKLOGIN_WIKIONLY)) {
564
565
566
		if ($WIKISUPPORT && $CHECKLOGIN_WIKINAME != "") {
		    $wikiname = $CHECKLOGIN_WIKINAME;
		
567
568
		    NavMenuButton("My Wikis",
				  "gotowiki.php3?redurl=Main/$wikiname");
569
		}
570
571
572
		NavMenuButton("Update User Information",
			      "$TBBASE/" .
			         CreateURL("moduserinfo", $login_user));
573
	    }
574
	    else {
575
576
		NavMenuButton("My Emulab",
			      "$TBBASE/" . CreateURL("showuser", $login_user));
577

578
		#
579
580
581
582
                # 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.
                #
583
584
 		NavMenuButton("Begin an Experiment",
			      "$TBBASE/beginexp_html.php3");
585
586

		if ($EXPOSETEMPLATES) {
587
588
		    NavMenuButton("Create a Template",
				  "$TBBASE/template_create.php");
589
		}
590
	
591
		# Put _NEW back when Plab is working again.
592
593
		NavMenuButton("Create a PlanetLab Slice",
			      "$TBBASE/plab_ez.php3");
594

595
		NavMenuButton("Experiment List", "$TBBASE/showexp_list.php3");
596

597
598
599
600
601
		NavMenuButtonDivider("Node Status",
				     "$TBBASE/nodecontrol_list.php3");

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

603
604
		NavMenuButton("List OSIDs",
			      "$TBBASE/showosid_list.php3");
605

606
607
		if ($login_status & CHECKLOGIN_TRUSTED &&
		    $login_user->ApprovalList(0)) {
608
609
610
		    # This includes a divider argument.
		    NavMenuButtonNew("New User Approval",
				     "$TBBASE/approveuser_form.php3", TRUE);
611
		}
612
	    }
613
	}
614
	elseif ($login_status & (CHECKLOGIN_UNVERIFIED|CHECKLOGIN_NEWUSER)) {
615
616
617
618
	    NavMenuButton("New User Verification",
			  "$TBBASE/verifyusr_form.php3");
	    NavMenuButton("Update User Information",
			  "$TBBASE/" . CreateURL("moduserinfo", $login_user));
619
	}
620
	elseif ($login_status & (CHECKLOGIN_UNAPPROVED)) {
621
622
	    NavMenuButton("Update User Information",
			  "$TBBASE/" . CreateURL("moduserinfo", $login_user));
623
	}
624
625
	#
	# Standard options for logged in users!
626
627
	#
	if (!$firstinitstate) {
628
629
630
631
	    NavMenuButtonDivider("Start New Project",
				 "$TBBASE/newproject.php3");
	    NavMenuButton("Join Existing Project",
			  "$TBBASE/joinproject.php3");
632
	}
633
    }
Chad Barb's avatar
Chad Barb committed
634

635
    # And now the Collaboration menu.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
636
637
638
    if (($login_status & (CHECKLOGIN_LOGGEDIN|CHECKLOGIN_MAYBEVALID)) &&
	($WIKISUPPORT || $MAILMANSUPPORT || $BUGDBSUPPORT ||
	 $CVSSUPPORT  || $CHATSUPPORT)) {
639
640

	NavMenuSection("collaboration", "Collaboration");
Timothy Stack's avatar
   
Timothy Stack committed
641

642
643
644
	if ($WIKISUPPORT && $CHECKLOGIN_WIKINAME != "") {
	    $wikiname = $CHECKLOGIN_WIKINAME;
		
645
646
	    NavMenuButton("My Wikis",
			  "$TBBASE/gotowiki.php3?redurl=Main/$wikiname");
647
	}
648
649
	if ($MAILMANSUPPORT || $BUGDBSUPPORT) {
	    if (!isset($pid) || $pid == "") {
650
651
		if (($project = $login_user->FirstApprovedProject())) {
		    $firstpid = $project->pid();
652
653
654
655
		}
	    }
	}
	if ($MAILMANSUPPORT) {
656
657
	     NavMenuButton("My Mailing Lists",
			   "$TBBASE/" . CreateURL("showmmlists", $login_user));
658
659
660
661
662
663
664
665
666
667
	}
	if ($BUGDBSUPPORT) {
	    $bugdburl = "gotobugdb.php3";
		    
	    if (isset($pid) && !empty($pid)) {
		$bugdburl .= "?project_title=$pid";
	    }
	    elseif (isset($firstpid)) {
		$bugdburl .= "?project_title=$firstpid";
	    }
668
	    NavMenuButton("My Bug Databases", "$TBBASE/$bugdburl");
669
670
	}
	if ($CVSSUPPORT) {
671
672
	    NavMenuButton("My CVS Repositories",
			  "$TBBASE/" . CreateURL("listrepos", $login_user));
673
	}
674
	if ($CHATSUPPORT) {
675
676
	    NavMenuButton("My Chat Buddies",
			  "$TBBASE/" . CreateURL("mychat", $login_user));
677
	}
678
679
680
681
	if ($TRACSUPPORT && STUDLY()) {
	    NavMenuButton("Trac Management",
			  "$TBBASE/" . CreateURL("gototrac", $login_user));
	}
682
    }
683

684
    # Optional ADMIN menu.
685
    if ($login_status & CHECKLOGIN_LOGGEDIN && ISADMIN()) {
686
	NavMenuSection("administration", "Administration");
687
	
688
689
690
691
	NavMenuButton("List Projects",
		      "$TBBASE/showproject_list.php3");
	NavMenuButton("List Users",
		      "$TBBASE/showuser_list.php3");
692

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

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

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

702
703
	NavMenuButton("Edit Knowledge Base",
		      "$TBBASE/kb-manage.php3");
704
705
706
		    
	$query_result = DBQUeryFatal("select new_node_id from new_nodes");
	if (mysql_num_rows($query_result) > 0) {
707
708
	    NavMenuButtonNew("Add Testbed Nodes",
			     "$TBBASE/newnodes_list.php3");
709
710
	}
	else {
711
712
	    NavMenuButtonNew("Add Testbed Nodes",
			     "$TBBASE/newnodes_list.php3");
713
	}
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
	NavMenuButtonNew("Approve Widearea User",
			 "$TBBASE/approvewauser_form.php3");
    }
    if (0 && $login_user) {
	NavMenuSection("Status", "Status");
	
	$freepcs = TBFreePCs();
	$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");
    }
    # 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";
739
    }
740
741
}

742
743
744
745
746
747
#
# Simple version of above, that just writes the given menu.
# 
function WRITESIMPLESIDEBAR($menudefs) {
    $menutitle = $menudefs['title'];
    
Timothy Stack's avatar
   
Timothy Stack committed
748
    echo "<h3 class='menuheader'>$menutitle</h3>
749
          <ul class='navmenu'>";
750
751
752
753
754

    each($menudefs);    
    while (list($key, $val) = each($menudefs)) {
	WRITESIDEBARBUTTON("$key", null, "$val");
    }
Timothy Stack's avatar
   
Timothy Stack committed
755
    echo "</ul>\n";
756
757
}

Chad Barb's avatar
   
Chad Barb committed
758
759
760
#
# spits out beginning part of page
#
761
762
function PAGEBEGINNING( $title, $nobanner = 0, $nocontent = 0,
        $extra_headers = NULL ) {
763
    global $BASEPATH, $TBMAINSITE, $THISHOMEBASE, $ELABINELAB, $FANCYBANNER;
Chad Barb's avatar
Chad Barb committed
764
    global $TBDIR, $WWW;
Chad Barb's avatar
   
Chad Barb committed
765
    global $MAINPAGE;
766
    global $TBDOCBASE;
767
    global $autorefresh, $currentusage, $javascript_debug, $login_user;
Chad Barb's avatar
   
Chad Barb committed
768

769
770
    $MAINPAGE = !strcmp($TBDIR, "/usr/testbed/");

Chad Barb's avatar
   
Chad Barb committed
771
772
773
774
775
    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>
776
            <link rel=\"shortcut icon\" href=\"favicon.ico\" TYPE=\"image/vnd.microsoft.icon\">
777
            <link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"$THISHOMEBASE Search\" href=\"emusearch.xml\">
Chad Barb's avatar
   
Chad Barb committed
778
    	    <!-- dumbed-down style sheet for any browser that groks (eg NS47). -->
779
	    <link rel='stylesheet' href='$BASEPATH/common-style.css' type='text/css' />
780
781
    	    <!-- do not import full style sheet into NS47, since it does bad job
            of handling it. NS47 does not understand '@import'. -->
Chad Barb's avatar
   
Chad Barb committed
782
    	    <style type='text/css' media='all'>
783
            <!-- @import url($BASEPATH/style.css); -->
784
            <!-- @import url($BASEPATH/cssmenu-new.css); -->";
785
    
786
    if (1 && !$MAINPAGE) {
Timothy Stack's avatar
   
Timothy Stack committed
787
	echo "<!-- @import url($BASEPATH/style-nonmain.css); -->";
788
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
789
    echo "</style>\n";
790
791
    echo "<!-- [if gt IE 6.0]><style type=\"text/css\">".
	".menu ul li a:hover ul { top: 18px; }</style><![endif]> -->\n";
Chad Barb's avatar
   
Chad Barb committed
792
793

    if ($TBMAINSITE) {
794
795
	echo "<meta name=\"keywords\" ".
	           "content=\"network, emulation, internet, emulator, ".
Leigh B. Stoller's avatar
Leigh B. Stoller committed
796
	           "mobile, wireless, robotic\">\n";
797
798
799
800
	echo "<meta name=\"robots\" ".
	           "content=\"NOARCHIVE\">\n";
	echo "<meta name=\"description\" ".
                   "content=\"emulab - network emulation testbed home\">\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
801
    }
802
803
804
    if ($extra_headers) {
        echo $extra_headers;
    }
805
806
807
808
    if ($javascript_debug) {
	echo "<script type='text/javascript'
                      src='${BASEPATH}/js/inline-console.js'></script>\n";
    }
809
    echo "</head><body>\n";
810
811
    
    if ($autorefresh) {
812
	echo "<meta HTTP-EQUIV=\"Refresh\" content=\"$autorefresh\">\n";
813
    }
814
815
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/emulab_sup.js'></script>\n";
816
817
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/sorttable.js'></script>\n";
818
819
    echo "<script type='text/javascript' language='javascript'
                  src='${BASEPATH}/textbox.js'></script>\n";
820

821
    if (!$nobanner) {
822
823
824
825
826
        #
        # We do the banner differently for the Utah site and other sites.
        # The process of generating the fancy Utah banner is kind of 
        # complicated
        #
827
828
829
830
831
832
833
834
835
836
837
	if ($login_user) {
		echo "<div class='topcell'>\n";
	}
	else {
	    if ($FANCYBANNER) {
		echo "<div id='fancybannercell'>\n";
	    }
	    else {
		echo "<div id='bannercell'>\n";
	    }
	}
838
839
840

        # NOTE: This has to come before any images in the div for the float to
        # work correctly.
841
842
843
844
845
846
847
	if ($currentusage && !$login_user) {
	    if ($FANCYBANNER) {
		$class = "transparentusageframe";
	    }
	    else {
		$class = "usageframe";
	    }
848
	    echo "<iframe src='$BASEPATH/currentusage.php3' class='$class'
849
                          scrolling='no' frameborder='0'></iframe>\n";
850
	}
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
	if ($login_user) {
	    echo "<table id=topcelltable ".
		     "cellspacing=0 cellpadding=0 border=0><tr>";
	    
	    #
	    # 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.
	    #
	    if (!$TBMAINSITE) {
		echo "<a class='rightsidebuiltwith' ".
		    "href='http://www.emulab.net'>";
		echo "<img src='$BASEPATH/fancy-builtwith.png'></a>\n";
	    }
	    echo "<td>\n";
	    echo "<a id='topcellimage' href='$TBDOCBASE/index.php3'>";
	    echo "<img border='0' ";
	    echo "alt='$THISHOMEBASE - the network testbed' ";
	    if ($FANCYBANNER)
		echo "src='$BASEPATH/fancy-banner-short.png' ";
	    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'>
                        <img height='100px' width='365px' border='0'
                           src='$BASEPATH/fancy-header.png' /></a>\n";
	    } else {
		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";
908
            }
909
910
911
912
913
914
915
	}
        if (!$login_user) 
	    echo "</div>\n";
    }
    else {
	# Need this to force no top margin/padding. No idea why! 
	echo "<div id='nobannercell'></div>\n";
916
917
    }
    if (! $nocontent ) {
918
919
920
921
922
923
924
	if ($login_user) {
	    ;
	}
	else {
	    echo "<div class='leftcell'>\n";
	    echo "<!-- sidebar begins -->\n";
	}
Chad Barb's avatar
   
Chad Barb committed
925
    }
Chad Barb's avatar
   
Chad Barb committed
926
927
928
929
930
}

#
# finishes sidebar td
#
931
function FINISHSIDEBAR($nocontent = 0)
Chad Barb's avatar
   
Chad Barb committed
932
{
933
    global $TBMAINSITE, $TBBASE, $BASEPATH, $currentusage, $login_user;
934
935
936
937
938
939
940

    if (!$nocontent) {
	if (!$TBMAINSITE) {
	    #
	    # It is a violation of Emulab licensing restrictions to remove
	    # this logo!
	    #
941
942
943
944
	    if (!$login_user) {
		echo "       <a class='builtwith' href='http://www.emulab.net'>
                             <img src='$BASEPATH/builtwith.png'></a>";
	    }
945
	}
946
947
948
	if ($currentusage && $login_user) {
	    $class = "navbarusageframe";
	    echo "<td>\n";
949
	    if (0) {
950
		echo "<iframe src='$BASEPATH/currentusage.php3' class='$class'
951
                              scrolling='no' frameborder='0'></iframe>\n";
952
953
	    }
	    else {
954
955
956
957
		echo "<div onclick=\"ToggleUsageTable();\" ".
		     "onmouseover='return escape(\"Click to toggle mode\")' ".
		     "id=usagefreenodes>\n";
		echo "</div>\n";
958
	    }
959
	    echo "</td></tr></table>\n";
960
	}
961
962
	echo "<!-- sidebar ends -->
              </div>";
963
    }
Chad Barb's avatar
   
Chad Barb committed
964
965
}

966
967
968
#
# Spit out a vanilla page header.
#
969
970
function PAGEHEADER($title, $view = NULL, $extra_headers = NULL,
		    $notice = NULL) {
971
972
    global $login_status, $login_user;
    global $TBBASE, $TBDOCBASE, $THISHOMEBASE;
973
    global $BASEPATH, $SSL_PROTOCOL, $drewheader, $autorefresh;
974
    global $TBMAINSITE;
975
976

    $drewheader = 1;
977
978
979
    if (isset($_GET['refreshrate']) && is_numeric($_GET['refreshrate'])) {
	$autorefresh = $_GET['refreshrate'];
    }
980

981
    #
982
    # Figure out who is logged in, if anyone.
983
984
985
986
    #
    if (($login_user = CheckLogin($status)) != null) {
	$login_status = $status;
	$login_uid    = $login_user->uid();
987
988
    }

989
990
991
992
993
994
995
    #
    # If no view options were specified, get the ones for the current user
    #
    if (!$view) {
	$view = GETUSERVIEW();
    }

996
    #
997
998
    # Check for NOLOGINS. 
    # We want to allow admin types to continue using the web interface,
999
1000
    # and logout anyone else that is currently logged in!
    #
For faster browsing, not all history is shown. View entire blame