All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

project_defs.php 24.7 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2006-2010 University of Utah and the Flux Group.
5 6
# All rights reserved.
#
7 8 9 10
# A cache of groups to avoid lookups. Indexed by pid_idx;
#
$project_cache = array();

11 12
class Project
{
13 14
    var	$project;
    var $group;
15 16
    var $_grouplist;		# All subgroups
    var $tempdata;		# For temporary data values ...
17

18 19 20 21 22 23 24 25 26 27 28 29 30 31
    #
    # Constructor by lookup on unique index.
    #
    function Project($pid_idx) {
	$safe_pid_idx = addslashes($pid_idx);

	$query_result =
	    DBQueryWarn("select * from projects ".
			"where pid_idx='$safe_pid_idx'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    $this->project = NULL;
	    return;
	}
32 33 34
	$this->project   = mysql_fetch_array($query_result);
	$this->group     = null;
	$this->_grouplist = null;
35 36 37 38 39 40 41 42 43
    }

    # Hmm, how does one cause an error in a php constructor?
    function IsValid() {
	return !is_null($this->project);
    }

    # Lookup by pid_idx.
    function Lookup($pid_idx) {
44 45 46 47 48 49
	global $project_cache;

        # Look in cache first
	if (array_key_exists("$pid_idx", $project_cache))
	    return $project_cache["$pid_idx"];
	
50 51
	$foo = new Project($pid_idx);

52 53 54 55
	if (! $foo->IsValid()) {
	    # Try lookup by plain uid.
	    $foo = Project::LookupByPid($pid_idx);
	    
Leigh B. Stoller's avatar
Leigh B. Stoller committed
56
	    if (!$foo || !$foo->IsValid())
57 58
		return null;

59
	    # Return here, already in the cache.
60
	    return $foo;
61
	}
62 63
	# Insert into cache.
	$project_cache["$pid_idx"] = $foo;
64
	return $foo;
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    }

    # Backwards compatable lookup by pid. Will eventually flush this.
    function LookupByPid($pid) {
	$safe_pid = addslashes($pid);

	$query_result =
	    DBQueryWarn("select pid_idx from projects where pid='$safe_pid'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    return null;
	}
	$row = mysql_fetch_array($query_result);
	$idx = $row['pid_idx'];

	$foo = new Project($idx); 

	if ($foo->IsValid())
	    return $foo;
	
	return null;
    }
    
    #
    # Refresh an instance by reloading from the DB.
    #
    function Refresh() {
	if (! $this->IsValid())
	    return -1;

	$pid_idx = $this->pid_idx();

	$query_result =
	    DBQueryWarn("select * from projects where pid_idx='$pid_idx'");
    
	if (!$query_result || !mysql_num_rows($query_result)) {
	    $this->project = NULL;
	    return -1;
	}
104 105 106 107 108 109 110
	$this->project   = mysql_fetch_array($query_result);

	if ($this->group) {
	    $foo = $this->group;
	    $foo->Refresh();
	}
	$this->_grouplist = null;
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
	return 0;
    }

    # accessors
    function field($name) {
	return (is_null($this->project) ? -1 : $this->project[$name]);
    }
    function pid_idx()	     { return $this->field("pid_idx"); }
    function pid()	     { return $this->field("pid"); }
    function created()       { return $this->field("created"); }
    function expires()       { return $this->field("expires"); }
    function name()          { return $this->field("name"); }
    function URL()           { return $this->field("URL"); }
    function funders()       { return $this->field("funders"); }
    function addr()          { return $this->field("addr"); }
    function head_uid()      { return $this->field("head_uid"); }
127
    function head_idx()      { return $this->field("head_idx"); }
128 129 130 131 132 133 134 135 136 137
    function num_members()   { return $this->field("num_members"); }
    function num_pcs()       { return $this->field("num_pcs"); }
    function num_sharks()    { return $this->field("num_sharks"); }
    function num_pcplab()    { return $this->field("num_pcplab"); }
    function num_ron()       { return $this->field("num_ron"); }
    function why()           { return $this->field("why"); }
    function control_node()  { return $this->field("control_node"); }
    function approved()      { return $this->field("approved"); }
    function inactive()      { return $this->field("inactive"); }
    function date_inactive() { return $this->field("date_inactive"); }
138
    function ispublic()      { return $this->field("public"); }
139 140 141 142 143 144 145 146
    function public_whynot() { return $this->field("public_whynot"); }
    function expt_count()    { return $this->field("expt_count"); }
    function expt_last()     { return $this->field("expt_last"); }
    function pcremote_ok()   { return $this->field("pcremote_ok"); }
    function default_user_interface()
	                     { return $this->field("default_user_interface"); }
    function linked_to_us()  { return $this->field("linked_to_us"); }
    function cvsrepo_public(){ return $this->field("cvsrepo_public"); }
147
    function allow_workbench(){ return $this->field("allow_workbench"); }
148

149
    function unix_gid() {
150
	$group = $this->DefaultGroup();
151 152 153 154
	
	return $group->unix_gid();
    }
    function unix_name() {
155
	$group = $this->DefaultGroup();
156 157 158

	return $group->unix_name();
    }
159 160 161 162 163 164 165
    # Temporary data storage ... useful.
    function SetTempData($value) {
	$this->tempdata = $value;
    }
    function GetTempData() {
	return $this->tempdata;
    }
166

167 168 169 170 171 172 173 174
    #
    # At some point we will stop passing pid and start using pid_idx.
    # Use this function to avoid having to change a bunch of code twice.
    #
    function URLParam() {
	return $this->pid();
    }

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
    #
    # Class function to create new project and return object.
    #
    function NewProject($pid, $leader, $args) {
	global $TBBASE, $TBMAIL_APPROVAL, $TBMAIL_AUDIT, $TBMAIL_WWW;
	
	#
	# The array of inserts is assumed to be safe already. Generate
	# a list of actual insert clauses to be joined below.
	#
	$insert_data = array();
	
	foreach ($args as $name => $value) {
	    $insert_data[] = "$name='$value'";
	}

	# First create the underlying default group for the project.
	if (! ($newgroup = Group::NewGroup(null, $pid, $leader,
					   'Default Group', $pid))) {
	    return null;
	}

	# Every project gets a new unique index, which comes from the group.
	$pid_idx = $newgroup->gid_idx();

	# Now tack on other stuff we need.
	$insert_data[] = "pid='$pid'";
	$insert_data[] = "pid_idx='$pid_idx'";
	$insert_data[] = "head_uid='" . $leader->uid() . "'";
204
	$insert_data[] = "head_idx='" . $leader->uid_idx() . "'";
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
	$insert_data[] = "created=now()";

	# Insert into DB. Should probably lock the table ...
	if (!DBQuerywarn("insert into projects set ".
			 implode(",", $insert_data))) {
	    $newgroup->Delete();
	    return null;
	}

	if (! DBQueryWarn("insert into project_stats (pid, pid_idx) ".
			  "values ('$pid', $pid_idx)")) {
	    $newgroup->Delete();
	    DBQueryFatal("delete from projects where pid_idx='$pid_idx'");
	    return null;
	}
	$newproject = Project::Lookup($pid_idx);
	if (! $newproject)
	    return null;

	#
	# The creator of a group is not automatically added to the group,
	# but we do want that for a new project. 
	#
	if ($newgroup->AddNewMember($leader) < 0) {
	    $newgroup->Delete();
	    DBQueryWarn("delete from project_stats where pid_idx=$pid_idx");
	    DBQueryWarn("delete from projects where pid_idx=$pid_idx");
	    return null;
	}

	return $newproject;
    }

238
    function NewNewProject($args, &$error) {
239 240 241 242 243 244 245 246
	global $suexec_output, $suexec_output_array;

        #
        # Generate a temporary file and write in the XML goo.
        #
	$xmlname = tempnam("/tmp", "newproj");
	if (! $xmlname) {
	    TBERROR("Could not create temporary filename", 0);
247
	    $error = "Transient error(1); please try again later.";
248 249 250 251
	    return null;
	}
	if (! ($fp = fopen($xmlname, "w"))) {
	    TBERROR("Could not open temp file $xmlname", 0);
252
	    $error = "Transient error(2); please try again later.";
253 254 255 256 257 258 259 260 261 262 263 264 265 266
	    return null;
	}

	fwrite($fp, "<project>\n");
	foreach ($args as $name => $value) {
	    fwrite($fp, "<attribute name=\"$name\">");
	    fwrite($fp, "  <value>" . htmlspecialchars($value) . "</value>");
	    fwrite($fp, "</attribute>\n");
	}
	fwrite($fp, "</project>\n");
	fclose($fp);
	chmod($xmlname, 0666);

	$retval = SUEXEC("nobody", "nobody", "webnewproj $xmlname",
267
			 SUEXEC_ACTION_IGNORE | SUEXEC_ACTION_MAIL_TBLOGS);
268 269 270

	if ($retval) {
	    if ($retval < 0) {
271
		$error = "Transient error(3, $retval); please try again later.";
272 273 274 275 276 277 278 279 280 281 282 283 284
		SUEXECERROR(SUEXEC_ACTION_CONTINUE);
	    }
	    else {
		$error = $suexec_output;
	    }
	    return null;
	}

        #
        # Parse the last line of output. Ick.
        #
	unset($matches);
	
285
	if (!preg_match("/^Project\s+([-\w]+)\/(\d+)\s+/",
286 287
			$suexec_output_array[count($suexec_output_array)-1],
			$matches)) {
288
	    $error = "Transient error(4, $retval); please try again later.";
289 290 291 292 293 294
	    SUEXECERROR(SUEXEC_ACTION_CONTINUE);
	    return null;
	}
	$pid_idx = $matches[2];
	$newproj = Project::Lookup($pid_idx);
	if (! $newproj) {
295
	    $error = "Transient error(5); please try again later.";
296 297 298 299 300 301 302
	    TBERROR("Could not lookup new project $pid_idx", 0);
	    return null;
	}
	# Unlink this here, so that the file is left behind in case of error.
	# We can then create the project by hand from the xmlfile, if desired.
	unlink($xmlname);
	return $newproj;
303
    }
304

305
    #
306
    # Class function to return a list of pending (unapproved) projects.
307
    #
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    function PendingProjectList() {
	$result     = array();

	$query_result =
	    DBQueryFatal("select pid_idx, ".
			 " DATE_FORMAT(created, '%m/%d/%y') as day_created ".
			 " from projects ".
			 "where approved='0' order by created desc");
			     
	while ($row = mysql_fetch_array($query_result)) {
	    $pid_idx = $row["pid_idx"];
	    $created = $row["day_created"];

	    if (! ($project = Project::Lookup($pid_idx))) {
		TBERROR("Project::PendingProjectList: ".
			"Could not load project $pid_idx!", 1);
	    }
	    $project->SetTempData($created);
	    
	    $result[] = $project;
	}
	return $result;
    }
    
332
    function AccessCheck($user, $access_type) {
333 334 335 336 337 338 339 340 341 342 343
	$group = $this->DefaultGroup();
	
	return $group->AccessCheck($user, $access_type);
    }

    # Return the user trust within the project, which is really for the
    # default group.
    function UserTrust($user) {
	$group = $this->DefaultGroup();
	
	return $group->UserTrust($user);
344 345
    }

346 347 348
    #
    # Load the default group for a project lazily.
    #
349 350 351 352 353
    function LoadDefaultGroup() {
	if ($this->group) {
	    return $this->group;
	}
	
354 355 356 357
	# Note: pid_idx=gid_idx for the default group
	$gid_idx = $this->pid_idx();

	if (! ($group = Group::Lookup($gid_idx))) {
358 359
	    TBERROR("Project::LoadDefaultGroup: ".
		    "Could not load group $gid_idx!", 1);
360 361
	}
	$this->group = $group;
362
	return $group;
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
    function DefaultGroup() { return $this->LoadDefaultGroup(); }
    function Group()        { return $this->DefaultGroup(); }

    #
    # Lookup a project subgroup by its name.
    #
    function LookupSubgroupByName($name) {
	$pid = $this->pid();

	return Group::LookupByPidGid($pid, $name);
    }

    #
    # Load all subgroups for this project.
    #
    function LoadSubGroups() {
	if ($this->_grouplist)
	    return 0;
	
	$pid_idx = $this->pid_idx();
	$result  = array();

	$query_result =
	    DBQueryFatal("select gid_idx from groups ".
			 "where pid_idx='$pid_idx'");

	while ($row = mysql_fetch_array($query_result)) {
	    $gid_idx = $row["gid_idx"];

	    if (! ($group = Group::Lookup($gid_idx))) {
		TBERROR("Project::LoadSubGroups: ".
			"Could not load group $gid_idx!", 1);
	    }
	    $result[] = $group;
	}
	$this->_grouplist = $result;
	return 0;
    }
    function SubGroups() {
	$this->LoadSubGroups();
	return $this->_grouplist;
405
    }
406

407 408 409 410
    #
    # Return user object for leader.
    #
    function GetLeader() {
411
	$head_idx = $this->head_idx();
412

413 414
	if (! ($leader = User::Lookup($head_idx))) {
	    TBERROR("Could not find user object for $head_idx", 1);
415 416 417 418
	}
	return $leader;
    }

419 420 421 422
    #
    # Add *new* member to project group; starts out with trust=none.
    #
    function AddNewMember($user) {
423
	$group = $this->DefaultGroup();
424 425 426 427 428 429 430

	return $group->AddNewMember($user);
    }

    #
    # Check if user is a member of this project (well, group)
    #
431
    function IsMember($user, &$approved) {
432
	$group = $this->DefaultGroup();
433

434
	return $group->IsMember($user, $approved);
435 436
    }

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
    #
    # Lookup an experiment within a project.
    #
    function LookupExperiment($eid) {
	return Experiment::LookupByPidEid($this->pid(), $eid);
    }

    #
    # How many PCs is project using. 
    #
    function PCsInUse() {
	$pid = $this->pid();
	
	$query_result =
	    DBQueryFatal("select count(r.node_id) from reserved as r ".
			 "left join nodes as n on n.node_id=r.node_id ".
			 "left join node_types as nt on nt.type=n.type ".
			 "where nt.class='pc' and r.pid='$pid'");
    
	if (mysql_num_rows($query_result) == 0) {
	    return 0;
	}
	$row = mysql_fetch_row($query_result);
	return $row[0];
    }
    
463
    #
464
    # Member list for a group.
465
    #
466 467 468
    function MemberList() {
	$pid_idx = $this->pid_idx();
	$result  = array();
469

470 471 472 473 474 475 476
	$query_result =
	    DBQueryFatal("select uid_idx from group_membership ".
			 "where pid_idx='$pid_idx' and gid_idx=pid_idx");

	while ($row = mysql_fetch_array($query_result)) {
	    $uid_idx = $row["uid_idx"];

Leigh B. Stoller's avatar
Leigh B. Stoller committed
477
	    if (! ($user = User::Lookup($uid_idx))) {
478 479 480
		TBERROR("Project::MemberList: ".
			"Could not load user $uid_idx!", 1);
	    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
481
	    $result[] = $user;
482
	}
483 484 485
	return $result;
    }

486 487 488 489 490
    #
    # Return an array of any users in the project who are admins.
    #
    function GetAdmins() {
	$pid_idx = $this->pid_idx();
David Johnson's avatar
David Johnson committed
491
	$result  = array();
492 493
	$query_result =
	    DBQueryFatal("select distinct u.uid_idx from users as u".
494 495
			 " left join group_membership as gm on ".
			 "      u.uid_idx=gm.uid_idx".
496 497 498 499 500 501 502 503 504 505 506 507 508 509
			 " where gm.pid_idx='$pid_idx' and u.admin=1");

	while ($row = mysql_fetch_array($query_result)) {
	    $uid_idx = $row["uid_idx"];

	    if (! ($user = User::Lookup($uid_idx))) {
		TBERROR("Project::GetAdmins: ".
			"Could not load user $uid_idx!", 1);
	    }
	    $result[] = $user;
	}
	return $result;
    }

510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
    #
    # List of subgroups for a project member (not including default group).
    #
    function GroupList($user) {
	$pid_idx = $this->pid_idx();
	$uid_idx = $user->uid_idx();
	$result  = array();

	$query_result =
	    DBQueryFatal("select gid_idx from group_membership ".
			 "where pid_idx='$pid_idx' and pid_idx!=gid_idx and ".
			 "      uid_idx='$uid_idx'");

	while ($row = mysql_fetch_array($query_result)) {
	    $gid_idx = $row["gid_idx"];

	    if (! ($group = Group::Lookup($gid_idx))) {
		TBERROR("Project::GroupList: ".
			"Could not load group $gid_idx!", 1);
	    }
	    $result[] = $group;
	}
	return $result;
    }

535 536 537 538 539 540 541 542 543
    #
    # List of experiments for a project, or just the count.
    #
    function ExperimentList($listify = 1) {
	$group = $this->DefaultGroup();

	return $group->ExperimentList($listify);
    }

544 545 546 547 548
    #
    # Change the leader for a project. Done *only* before project is
    # approved.
    #
    function ChangeLeader($leader) {
549
	$group   = $this->DefaultGroup();
550 551 552
	$idx     = $this->pid_idx();
	$uid     = $leader->uid();
	$uid_idx = $leader->uid_idx();
553

554 555
	DBQueryFatal("update projects set ".
		     "  head_uid='$uid',head_idx='$uid_idx' ".
556 557 558
		     "where pid_idx='$idx'");

	$this->project["head_uid"] = $uid;
559
	$this->project["head_idx"] = $uid_idx;
560
	return $group->ChangeLeader($leader);
561 562
    }
    
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
    #
    # Change various fields.
    #
    function SetApproved($approved) {
	$idx   = $this->pid_idx();

	if ($approved)
	    $approved = 1;
	else
	    $approved = 0;
	
	DBQueryFatal("update projects set approved='$approved' ".
		     "where pid_idx='$idx'");

	$this->project["approved"] = $approved;
	return 0;
    }
    function SetRemoteOK($ok) {
	$idx    = $this->pid_idx();
	$safeok = addslashes($ok);

	DBQueryFatal("update projects set pcremote_ok='$safeok' ".
		     "where pid_idx='$idx'");

	$this->project["pcremote_ok"] = $ok;
	return 0;
589 590
    }

591 592 593 594 595 596 597 598 599
    function SetCVSRepoPublic($public) {
	$idx    = $this->pid_idx();
	$public = ($public ? 1 : 0);

	DBQueryFatal("update projects set cvsrepo_public='$public' ".
		     "where pid_idx='$idx'");

	return 0;
    }
600 601 602 603 604 605 606 607 608
    function SetAllowWorkbench($onoff) {
	$idx    = $this->pid_idx();
	$onofff = ($onoff ? 1 : 0);

	DBQueryFatal("update projects set allow_workbench='$onoff' ".
		     "where pid_idx='$idx'");

	return 0;
    }
609

610 611 612 613
    function Show() {
	global $WIKISUPPORT, $CVSSUPPORT, $TBPROJ_DIR, $TBCVSREPO_DIR;
	global $MAILMANSUPPORT, $OPSCVSURL, $USERNODE;

614
	$group = $this->DefaultGroup();
615 616 617 618 619 620

	$pid                    = $this->pid();
	$proj_idx		= $this->pid_idx();
	$proj_created		= $this->created();
	$proj_name		= $this->name();
	$proj_URL		= $this->URL();
621
	$proj_public		= YesNo($this->ispublic());
622 623 624 625 626 627 628 629 630 631 632 633
	$proj_funders		= $this->funders();
	$proj_head_idx		= $this->head_idx();
	$proj_members		= $this->num_members();
	$proj_pcs		= $this->num_pcs();
        # These are now booleans, not actual counts.
	$proj_linked		= YesNo($this->linked_to_us());
	$proj_why		= nl2br($this->why());
	$approved		= YesNo($this->approved());
	$expt_count		= $this->expt_count();
	$expt_last		= $this->expt_last();
	$wikiname		= $group->wikiname();
	$cvsrepo_public		= $this->cvsrepo_public();
634
	$allow_workbench	= $this->allow_workbench();
635

636
	# Before project approval, display ron/plab request status.
637
	if ($this->approved()) {
638 639 640 641 642 643 644 645 646 647
	    $proj_ronpcs   =
		YesNo(strpos($this->pcremote_ok(), "pcron") !== false);
	    $proj_plabpcs  = 
		YesNo(strpos($this->pcremote_ok(), "pcplabphys") !== false);
	}
	else {
	    $proj_ronpcs   = YesNo($this->num_ron());
	    $proj_plabpcs  = YesNo($this->num_pcplab());
	}

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
	if (! ($head_user = User::Lookup($proj_head_idx))) {
	    TBERROR("Could not lookup object for user $proj_head_idx", 1);
	}
	$showuser_url  = CreateURL("showuser", $head_user);
	$showproj_url  = CreateURL("showproject", $this);
	$proj_head_uid = $head_user->uid();

	if (!$expt_last) {
	    $expt_last = "&nbsp;";
	}

	echo "<center>
              <h3>Project Profile</h3>
              </center>
              <table align=center cellpadding=2 border=1>\n";
    
        #
        # Generate the table.
        # 
	echo "<tr>
                  <td>Name: </td>
                  <td class=\"left\">
Leigh B. Stoller's avatar
Leigh B. Stoller committed
670
                      <a href='$showproj_url'>$pid ($proj_idx)</a></td>
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
              </tr>\n";
    
	echo "<tr>
                  <td>Description: </td>
                  <td class=\"left\">$proj_name</td>
              </tr>\n";
    
	echo "<tr>
                  <td>Project Head: </td>
                  <td class=\"left\">
                      <a href='$showuser_url'>$proj_head_uid</a></td>
              </tr>\n";
    
	echo "<tr>
              <td>URL: </td>
                  <td class=\"left\">
                      <a href='$proj_URL'>$proj_URL</a></td>
              </tr>\n";

	if ($WIKISUPPORT && isset($wikiname)) {
	    $wikiurl = "gotowiki.php3?redurl=$wikiname/WebHome";
692
	
693 694 695 696 697 698 699 700
	    echo "<tr>
                      <td>Project Wiki:</td>
                      <td class=\"left\">
                          <a href='$wikiurl'>$wikiname</a></td>
                  </tr>\n";
	}
	if ($CVSSUPPORT) {
	    $cvsdir = "$TBCVSREPO_DIR/$pid";
Robert Ricci's avatar
Robert Ricci committed
701
	    $cvsurl = "cvsweb/cvswebwrap.php3?pid=$pid";
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
	
	    echo "<tr>
                      <td>Project CVS Repository:</td>
                      <td class=\"left\">
                          $cvsdir <a href='$cvsurl'>(CVSweb)</a></td>
                  </tr>\n";

	    $YesNo = YesNo($cvsrepo_public);
	    $flip  = ($cvsrepo_public ? 0 : 1);
	    echo "<tr>
                      <td>CVS Repository Publically Readable?:</td>
                      <td><a href=toggle.php?pid=$pid&type=cvsrepo_public".
		          "&value=$flip>$YesNo</a> (Click to toggle)</td>
                  </tr>\n";

	    if ($cvsrepo_public) {
		$puburl  = "$OPSCVSURL/?cvsroot=$pid";
		$pserver = ":pserver:anoncvs@$USERNODE:/cvsrepos/$pid";
		
		echo "<tr>
                          <td>Public CVSWeb Address:</td>
                          <td><a href=$puburl>" .
		                 htmlspecialchars($puburl) . "</a></td>
                      </tr>\n";

		echo "<tr>
                          <td>CVS pserver Address:</td>
                          <td>" . htmlspecialchars($pserver) . "</td>
                      </tr>\n";
	    }
	}

	if ($MAILMANSUPPORT) {
	    $mmurl   = "gotommlist.php3?pid=$pid";
736

737 738 739 740 741 742 743 744 745 746
	    echo "<tr>
                      <td>Project Mailing List:</td>
                      <td class=\"left\">
                          <a href='$mmurl'>${pid}-users</a> ";
	    if (ISADMIN()) {
		$mmurl .= "&wantadmin=1";
		echo "<a href='$mmurl'>(admin access)</a>";
	    }
	    echo "    </td>
                  </tr>\n";
747 748 749 750 751 752 753 754 755 756 757 758 759

	    if (ISADMIN()) {
		$mmurl   = "gotommlist.php3?listname=${pid}-admin&asadmin=1";

		echo "<tr>
                         <td>Project Admin Mailing List:</td>
                         <td class=\"left\">
                             <a href='$mmurl'>${pid}-admin</a> ";
		$mmurl   = "gotommlist.php3?listname=${pid}-admin&wantadmin=1";
		echo "<a href='$mmurl'>(admin access)</a>";
		echo "    </td>
                     </tr>\n";
	    }
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
	}

	echo "<tr>
                  <td>Publicly Visible: </td>
                  <td class=\"left\">$proj_public</td>
              </tr>\n";
    
	echo "<tr>
                  <td>Link to Us?: </td>
                  <td class=\"left\">$proj_linked</td>
              </tr>\n";
    
	echo "<tr>
                  <td>Funders: </td>
                  <td class=\"left\">$proj_funders</td>
              </tr>\n";

	echo "<tr>
                  <td>#Project Members: </td>
                  <td class=\"left\">$proj_members</td>
              </tr>\n";
    
	echo "<tr>
                  <td>#PCs: </td>
                  <td class=\"left\">$proj_pcs</td>
              </tr>\n";
    
	echo "<tr>
                  <td>Planetlab Access: </td>
                  <td class=\"left\">$proj_plabpcs</td>
              </tr>\n";
    
	echo "<tr>
                  <td>RON Access: </td>
                  <td class=\"left\">$proj_ronpcs</td>
              </tr>\n";
796 797 798

	# Fine-grained Datapository access: show node_ids over all sub-groups.
	# Should probably do likewise in individual sub-group pages.
799
	# "dp_projects" node_attributes are lists of group gid_idxs.
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
        $query_result =
	    DBQueryFatal("select distinct g.gid_idx, a.node_id ".
			 "  from groups as g, node_attributes as a ".
			 "where g.pid_idx='$proj_idx' ".
			 "  and a.attrkey='dp_projects' ".
                         "  and FIND_IN_SET(g.gid_idx, a.attrvalue) ".
			 "order by g.gid_idx, a.node_id");
	$proj_dp_nodes = "";
	while ($row = mysql_fetch_array($query_result)) {
	    $node_id = $row["node_id"];

	    if ($proj_dp_nodes) $proj_dp_nodes .= ", ";
	    $proj_dp_nodes .= $node_id;
	}
	if ($proj_dp_nodes) {
	    echo "<tr>
		      <td>Datapository Access: </td>
		      <td class=\"left\">$proj_dp_nodes</td>
		  </tr>\n";
	}

821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
	echo "<tr>
                  <td>Created: </td>
                  <td class=\"left\">$proj_created</td>
              </tr>\n";
    
	echo "<tr>
                  <td>Experiments Created:</td>
                  <td class=\"left\">$expt_count</td>
              </tr>\n";
    
	echo "<tr>
                  <td>Date of last experiment:</td>
                  <td class=\"left\">$expt_last</td>
              </tr>\n";
    
	echo "<tr>
                  <td>Approved?: </td>
                  <td class=\"left\">$approved</td>
	      </tr>\n";

841 842 843 844 845 846 847 848 849 850 851
	if (ISADMIN()) {
	    $YesNo = YesNo($allow_workbench);
	    $flip  = ($allow_workbench ? 0 : 1);
	    
	    echo "<tr>
                      <td>Allow Workbench:</td>
                      <td><a href=toggle.php?pid=$pid&type=workbench".
		          "&value=$flip>$YesNo</a> (Click to toggle)</td>
                  </tr>\n";
	}

852 853 854 855 856 857 858 859 860 861 862 863
	echo "<tr>
                  <td colspan='2'>Why?:</td>
              </tr>\n";
    
	echo "<tr>
                  <td colspan='2' width=600>$proj_why</td>
              </tr>\n";
    
	echo "</table>\n";
    }

    function ShowGroupList() {
864
	$groups    = $this->SubGroups();
865

866
	echo "<center><h3>Project Groups</h3></center>\n";
867 868
	echo "<table id='grouplist' align=center border=1>\n";
	echo "<thead class='sort'>";
869 870 871 872
	echo "<tr>
               <th>GID</th>
               <th>Description</th>
               <th>Leader</th>
873
              </tr></thead>\n";
874

875 876 877 878 879
	foreach ($groups as $group) {
	    $gid         = $group->gid();
	    $desc        = $group->description();
	    $leader      = $group->leader();
	    $leader_user = $group->GetLeader();
880

881 882
	    $showuser_url  = CreateURL("showuser", $leader_user);
	    $showgroup_url = CreateURL("showgroup", $group);
883 884

	    echo "<tr>
885
                   <td><A href='$showgroup_url'>$gid</a></td>
886 887 888 889 890
                   <td>$desc</td>
                   <td><A href='$showuser_url'>$leader</A></td>
                 </tr>\n";
	}
	echo "</table>\n";
891 892 893 894

        echo "<script type='text/javascript' language='javascript'>
	       sorttable.makeSortable(getObjbyName('grouplist'));
             </script>\n";
895 896
    }

897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
    function ShowStats() {
	$pid_idx  = $this->pid_idx();

	$query_result =
	    DBQueryFatal("select * from project_stats ".
			 "where pid_idx='$pid_idx'");

	if (! mysql_num_rows($query_result)) {
	    return;
	}
	$row = mysql_fetch_assoc($query_result);

        #
        # Not pretty printed yet.
        #
	echo "<table align=center border=1>\n";
    
	foreach($row as $key => $value) {
	    echo "<tr>
                      <td>$key:</td>
                      <td>$value</td>
                  </tr>\n";
	}
	echo "</table>\n";
    }
922

923
}
924
?>