project_defs.php 27.9 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2006-2017 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/>.
# 
# }}}
23
#
24 25 26 27
# A cache of groups to avoid lookups. Indexed by pid_idx;
#
$project_cache = array();

28 29
class Project
{
30 31
    var	$project;
    var $group;
32 33
    var $_grouplist;		# All subgroups
    var $tempdata;		# For temporary data values ...
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48
    #
    # 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;
	}
49 50 51
	$this->project   = mysql_fetch_array($query_result);
	$this->group     = null;
	$this->_grouplist = null;
52 53 54 55 56 57 58 59 60
    }

    # 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) {
61 62 63 64 65 66
	global $project_cache;

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

69 70 71 72
	if (! $foo->IsValid()) {
	    # Try lookup by plain uid.
	    $foo = Project::LookupByPid($pid_idx);
	    
73
	    if (!$foo || !$foo->IsValid())
74 75
		return null;

76
	    # Return here, already in the cache.
77
	    return $foo;
78
	}
79 80
	# Insert into cache.
	$project_cache["$pid_idx"] = $foo;
81
	return $foo;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    }

    # 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;
	}
121 122 123 124 125 126 127
	$this->project   = mysql_fetch_array($query_result);

	if ($this->group) {
	    $foo = $this->group;
	    $foo->Refresh();
	}
	$this->_grouplist = null;
128 129 130 131 132 133 134 135 136 137 138
	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"); }
139
    function nagged()        { return $this->field("nagged"); }
140 141 142 143 144
    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"); }
145
    function head_idx()      { return $this->field("head_idx"); }
146 147 148 149 150 151 152 153 154 155
    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"); }
156
    function ispublic()      { return $this->field("public"); }
157 158 159 160 161 162 163 164
    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"); }
165
    function allow_workbench(){ return $this->field("allow_workbench"); }
166
    function nonlocal_id()   { return $this->field("nonlocal_id"); }
167 168 169 170 171 172 173 174 175 176 177 178
    function portal()	     { return $this->field("portal"); }
    function isAPT()	     { return ($this->portal() &&
                                       $this->portal() == "aptlab" ? 1 : 0); }
    function isCloud()	     { return ($this->portal() &&
                                       $this->portal() == "cloudlab" ? 1 : 0); }
    function isPNet()	     { return ($this->portal() &&
                                       $this->portal() == "phantomnet" ? 1 : 0);}
    function isEmulab()	     { return ($this->portal() &&
                                       $this->portal() == "emulab" ? 1 : 0); }
    # Not via the Portal interface.
    function isClassic()     { return ($this->portal() ? 0 : 1); }
    
Leigh B Stoller's avatar
Leigh B Stoller committed
179 180 181
    function IsNonLocal() {
	return ($this->field("nonlocal_id") ? 1 : 0);
    }
182

183
    function wwwBase() {
184
	global $TBBASE;
185 186
	
	return ($this->isAPT() ? "https://www.aptlab.net" :
187 188
		($this->isCloud() ? "https://www.cloudlab.us" : 
		 ($this->isPNet() ? "https://www.phantomnet.org" :
189
		  $TBBASE)));
190 191
    }
    function ApprovalEmailAddress() {
192
	global $TBMAILADDR_APPROVAL;
193 194

	return ($this->isAPT() ? "aptlab-approval@aptlab.net" :
195 196
		($this->isCloud() ? "cloudlab-approval@cloudlab.us" :
		 ($this->isPNet() ? "phantomnet-approval@phantomnet.org" :
197
		  $TBMAILADDR_APPROVAL)));
198 199 200 201 202
    }
    function EmailTag() {
	global $THISHOMEBASE;
	
	return ($this->isAPT() ? "aptlab.net" :
203 204 205
		($this->isCloud() ? "cloudlab.us" : 
		 ($this->isPNet() ? "phantomnet.org" :
		  $THISHOMEBASE)));
206 207
    }

208
    function unix_gid() {
209
	$group = $this->DefaultGroup();
210 211 212 213
	
	return $group->unix_gid();
    }
    function unix_name() {
214
	$group = $this->DefaultGroup();
215 216 217

	return $group->unix_name();
    }
218 219 220 221 222 223 224
    # Temporary data storage ... useful.
    function SetTempData($value) {
	$this->tempdata = $value;
    }
    function GetTempData() {
	return $this->tempdata;
    }
225

226 227 228 229 230 231 232 233
    #
    # 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();
    }

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    #
    # 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() . "'";
263
	$insert_data[] = "head_idx='" . $leader->uid_idx() . "'";
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
	$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;
    }

297
    function NewNewProject($args, &$error) {
298 299 300 301 302 303 304 305
	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);
306
	    $error = "Transient error(1); please try again later.";
307 308 309 310
	    return null;
	}
	if (! ($fp = fopen($xmlname, "w"))) {
	    TBERROR("Could not open temp file $xmlname", 0);
311
	    $error = "Transient error(2); please try again later.";
312 313 314 315 316 317 318 319 320 321 322 323 324 325
	    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",
326
			 SUEXEC_ACTION_IGNORE | SUEXEC_ACTION_MAIL_TBLOGS);
327 328 329

	if ($retval) {
	    if ($retval < 0) {
330
		$error = "Transient error(3, $retval); please try again later.";
331 332 333 334 335 336 337 338 339 340 341 342 343
		SUEXECERROR(SUEXEC_ACTION_CONTINUE);
	    }
	    else {
		$error = $suexec_output;
	    }
	    return null;
	}

        #
        # Parse the last line of output. Ick.
        #
	unset($matches);
	
344
	if (!preg_match("/^Project\s+([-\w]+)\/(\d+)\s+/",
345 346
			$suexec_output_array[count($suexec_output_array)-1],
			$matches)) {
347
	    $error = "Transient error(4, $retval); please try again later.";
348 349 350 351 352 353
	    SUEXECERROR(SUEXEC_ACTION_CONTINUE);
	    return null;
	}
	$pid_idx = $matches[2];
	$newproj = Project::Lookup($pid_idx);
	if (! $newproj) {
354
	    $error = "Transient error(5); please try again later.";
355 356 357 358 359 360 361
	    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;
362
    }
363

364
    #
365
    # Class function to return a list of pending (unapproved) projects.
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
    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;
    }
    
391
    function AccessCheck($user, $access_type) {
392 393 394 395 396 397 398 399 400 401 402
	$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);
403 404
    }

405 406 407 408 409 410 411
    # Return membership info in the default group.
    function MemberShipInfo($user) {
	$group = $this->DefaultGroup();

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

412 413 414
    #
    # Load the default group for a project lazily.
    #
415 416 417 418 419
    function LoadDefaultGroup() {
	if ($this->group) {
	    return $this->group;
	}
	
420 421 422 423
	# Note: pid_idx=gid_idx for the default group
	$gid_idx = $this->pid_idx();

	if (! ($group = Group::Lookup($gid_idx))) {
424 425
	    TBERROR("Project::LoadDefaultGroup: ".
		    "Could not load group $gid_idx!", 1);
426 427
	}
	$this->group = $group;
428
	return $group;
429
    }
430 431 432 433 434 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 463 464 465 466 467 468 469 470
    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;
471
    }
472

473 474 475 476
    #
    # Return user object for leader.
    #
    function GetLeader() {
477
	$head_idx = $this->head_idx();
478

479 480
	if (! ($leader = User::Lookup($head_idx))) {
	    TBERROR("Could not find user object for $head_idx", 1);
481 482 483
	}
	return $leader;
    }
484 485 486 487 488 489 490 491
    # Boolean test.
    function IsLeader($user) {
        $leader = $this->GetLeader();
        if ($user->SameUser($leader)) {
            return 1;
        }
        return 0;
    }
492

493 494 495
    #
    # Add *new* member to project group; starts out with trust=none.
    #
496
    function AddNewMember($user, $trust = TBDB_TRUSTSTRING_NONE) {
497
	$group = $this->DefaultGroup();
498

499
	return $group->AddNewMember($user, $trust);
500 501
    }

502 503 504 505 506 507 508 509 510
    #
    # Delete.
    #  
    function DeleteMember($user) {
	$group = $this->DefaultGroup();

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

511 512 513
    #
    # Check if user is a member of this project (well, group)
    #
514
    function IsMember($user, &$approved) {
515
	$group = $this->DefaultGroup();
516

517
	return $group->IsMember($user, $approved);
518 519
    }

520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
    #
    # 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];
    }
    
546
    #
547
    # Member list for a group.
548
    #
549 550 551
    function MemberList() {
	$pid_idx = $this->pid_idx();
	$result  = array();
552

553 554 555 556 557 558 559
	$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
560
	    if (! ($user = User::Lookup($uid_idx))) {
561 562 563
		TBERROR("Project::MemberList: ".
			"Could not load user $uid_idx!", 1);
	    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
564
	    $result[] = $user;
565
	}
566 567 568
	return $result;
    }

569 570 571 572 573
    #
    # 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
574
	$result  = array();
575 576
	$query_result =
	    DBQueryFatal("select distinct u.uid_idx from users as u".
577 578
			 " left join group_membership as gm on ".
			 "      u.uid_idx=gm.uid_idx".
579 580 581 582 583 584 585 586 587 588 589 590 591 592
			 " 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;
    }

593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
    #
    # 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;
    }

618 619 620 621 622 623 624 625 626
    #
    # List of experiments for a project, or just the count.
    #
    function ExperimentList($listify = 1) {
	$group = $this->DefaultGroup();

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

627 628 629 630 631
    #
    # Change the leader for a project. Done *only* before project is
    # approved.
    #
    function ChangeLeader($leader) {
632
	$group   = $this->DefaultGroup();
633 634 635
	$idx     = $this->pid_idx();
	$uid     = $leader->uid();
	$uid_idx = $leader->uid_idx();
636

637 638
	DBQueryFatal("update projects set ".
		     "  head_uid='$uid',head_idx='$uid_idx' ".
639 640 641
		     "where pid_idx='$idx'");

	$this->project["head_uid"] = $uid;
642
	$this->project["head_idx"] = $uid_idx;
643
	return $group->ChangeLeader($leader);
644 645
    }
    
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
    #
    # 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;
672 673
    }

674 675 676 677 678 679 680 681 682
    function SetCVSRepoPublic($public) {
	$idx    = $this->pid_idx();
	$public = ($public ? 1 : 0);

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

	return 0;
    }
683 684 685 686 687 688 689 690 691
    function SetAllowWorkbench($onoff) {
	$idx    = $this->pid_idx();
	$onofff = ($onoff ? 1 : 0);

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

	return 0;
    }
692

693 694 695 696
    function Show() {
	global $WIKISUPPORT, $CVSSUPPORT, $TBPROJ_DIR, $TBCVSREPO_DIR;
	global $MAILMANSUPPORT, $OPSCVSURL, $USERNODE;

697
	$group = $this->DefaultGroup();
698 699 700 701 702 703

	$pid                    = $this->pid();
	$proj_idx		= $this->pid_idx();
	$proj_created		= $this->created();
	$proj_name		= $this->name();
	$proj_URL		= $this->URL();
704
	$proj_public		= YesNo($this->ispublic());
705 706 707 708 709 710 711 712 713 714 715 716
	$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();
717
	$allow_workbench	= $this->allow_workbench();
718
	$portal                 = $this->portal();
719
        $nonlocal_id            = $this->nonlocal_id();
720

721
	# Before project approval, display ron/plab request status.
722
	if ($this->approved()) {
723 724 725 726 727 728 729 730 731 732
	    $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());
	}

733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
	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
755
                      <a href='$showproj_url'>$pid ($proj_idx)</a></td>
756 757
              </tr>\n";
    
758 759 760 761 762 763 764
        if ($nonlocal_id) {
            echo "<tr>
                      <td>Nonlocal ID:</td>
                      <td>$nonlocal_id</td>
                      </tr>\n";
        }
    
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
	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";

782
	if (isset($portal)) {
783
	    echo "<tr>
784 785
                  <td>Portal: </td>
                  <td class=\"left\">$portal</td>
786 787 788
              </tr>\n";
	}

789 790
	if ($WIKISUPPORT && isset($wikiname)) {
	    $wikiurl = "gotowiki.php3?redurl=$wikiname/WebHome";
791
	
792 793 794 795 796 797 798 799
	    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
800
	    $cvsurl = "cvsweb/cvswebwrap.php3?pid=$pid";
801 802 803 804 805 806 807 808 809 810 811
	
	    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>
812 813
                      <td><a href='toggle.php?pid=$pid&type=cvsrepo_public".
		          "&value=$flip'>$YesNo</a> (Click to toggle)</td>
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
                  </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";
835

836 837 838 839 840 841 842 843 844 845
	    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";
846 847 848 849 850 851 852 853 854 855 856 857 858

	    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";
	    }
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
	}

	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";
895 896 897

	# Fine-grained Datapository access: show node_ids over all sub-groups.
	# Should probably do likewise in individual sub-group pages.
898
	# "dp_projects" node_attributes are lists of group gid_idxs.
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
        $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";
	}

920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
	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";

940 941 942 943 944 945
	if (ISADMIN()) {
	    $YesNo = YesNo($allow_workbench);
	    $flip  = ($allow_workbench ? 0 : 1);
	    
	    echo "<tr>
                      <td>Allow Workbench:</td>
946 947
                      <td><a href='toggle.php?pid=$pid&type=workbench".
		          "&value=$flip'>$YesNo</a> (Click to toggle)</td>
948 949 950
                  </tr>\n";
	}

951 952 953 954 955 956 957 958 959 960 961 962
	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() {
963
	$groups    = $this->SubGroups();
964

965
	echo "<center><h3>Project Groups</h3></center>\n";
966 967
	echo "<table id='grouplist' align=center border=1>\n";
	echo "<thead class='sort'>";
968 969 970 971
	echo "<tr>
               <th>GID</th>
               <th>Description</th>
               <th>Leader</th>
972
              </tr></thead>\n";
973

974 975 976 977 978
	foreach ($groups as $group) {
	    $gid         = $group->gid();
	    $desc        = $group->description();
	    $leader      = $group->leader();
	    $leader_user = $group->GetLeader();
979

980 981
	    $showuser_url  = CreateURL("showuser", $leader_user);
	    $showgroup_url = CreateURL("showgroup", $group);
982 983

	    echo "<tr>
984
                   <td><A href='$showgroup_url'>$gid</a></td>
985 986 987 988 989
                   <td>$desc</td>
                   <td><A href='$showuser_url'>$leader</A></td>
                 </tr>\n";
	}
	echo "</table>\n";
990 991 992 993

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

996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
    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";
    }
1021

1022
}
1023
?>