showproject_list.php3 9.58 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
5 6
# All rights reserved.
#
7 8 9
include("defs.php3");

#
10
# Only known and logged in users can do this.
11
#
12 13 14
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
15

16 17 18
#
# Verify page arguments
#
19
$optargs = OptionalPageArguments("showtype",   PAGEARG_STRING);
20

21 22 23 24 25
#
# Standard Testbed Header
#
PAGEHEADER("Project Information List");

26
if (! isset($showtype)) {
27
    $showtype="Active";
28
}
29

30 31 32 33 34 35
if ($isadmin) {
    echo "<b>Show: ";
    
    if ($showtype != "Active") {
	echo "<a class='static'
                 href='showproject_list.php3?showtype=Active'>Active</a>, ";
36 37
    }
    else {
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
	echo "Active, ";
    }

    if ($showtype != "All") {
	echo "<a class='static'
                 href='showproject_list.php3?showtype=All'>All</a>, ";
    }
    else {
	echo "All, ";
    }

    if ($showtype != "Splitview") {
	echo "<a class='static'
               href='showproject_list.php3?showtype=Splitview'>Splitview</a>, ";
    }
    else {
	echo "Splitview, ";
    }

    if ($showtype != "ProtoGENI") {
	echo "<a class='static'
                 href='showproject_list.php3?showtype=ProtoGENI'>ProtoGENI</a>";
    }
    else {
	echo "ProtoGENI";
63
    }
64
}
65
echo "<br>\n";
66

67
$allproj_result =
68 69 70 71 72 73
    DBQueryFatal("SELECT p.pid,p.expt_count, ".
		 "       UNIX_TIMESTAMP(s.last_activity) as last_activity ".
		 "  FROM projects as p ".
		 "left join project_stats as s ".
		 "     on s.pid_idx=p.pid_idx");
		 
74 75 76 77 78 79
#
# This is summary info, indexed by the pid, so no need to alter it
# for admin vs non-admin. Thats handled in the project query below.
#
$ecounts = array();
$ncounts = array();
80
$pcounts = array();
81 82 83

$query_result =
    DBQueryFatal("select e.pid, count(distinct e.eid) as ecount ".
84 85
		 "from experiments as e where state!='$TB_EXPTSTATE_SWAPPED' ".
		 "group by e.pid");
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

while ($row = mysql_fetch_array($query_result)) {
    $pid   = $row[0];
    $count = $row[1];

    $ecounts[$pid] = $count;
}

$query_result =
    DBQueryFatal("select r.pid, count(distinct r.node_id) as ncount ".
		 "from reserved as r group by r.pid");

while ($row = mysql_fetch_array($query_result)) {
    $pid   = $row[0];
    $count = $row[1];

    $ncounts[$pid] = $count;
}

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
# Here we get just the PC counts.

$query_result =
    DBQueryFatal("select r.pid,nt.class,count(distinct r.node_id) as ncount ".
		 "  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' ".
		 "group by r.pid,nt.class");

while ($row = mysql_fetch_array($query_result)) {
    $pid   = $row[0];
    $count = $row[2];

    $pcounts[$pid] = $count;
}

122
while ($projectrow = mysql_fetch_array($allproj_result)) {
123
    $pid = $projectrow["pid"];
124 125 126 127 128 129

    if (!isset($ecounts[$pid])) 
	$ecounts[$pid] = 0;
	    
    if (!isset($ncounts[$pid])) 
	$ncounts[$pid] = 0;
130 131 132

    if (!isset($pcounts[$pid])) 
	$pcounts[$pid] = 0;
133 134
}

135
if ($isadmin) {
136
    mysql_data_seek($allproj_result, 0);
137
    
138 139 140 141
    #
    # Process the query results for active projects so I can generate a
    # summary block (as per Jays request).
    #
142
    $total_projects  = mysql_num_rows($allproj_result);
143
    $active_projects = 0;
144
    $recently_active = 0;
145

146
    while ($projectrow = mysql_fetch_array($allproj_result)) {
147 148
	$expt_count    = $projectrow["expt_count"];
	$last_activity = $projectrow["last_activity"];
149 150 151 152

	if ($expt_count > 0) {
	    $active_projects++;
	}
153 154 155
	if (time() - $last_activity < (24 * 3600 * 90)) {
	    $recently_active++;
	}
156 157 158
    }
    $never_active = $total_projects - $active_projects;

Chad Barb's avatar
Chad Barb committed
159
    echo "<table border=0 align=center cellpadding=0 cellspacing=2>
160 161 162 163
        <tr>
          <td align=right><b>Recently Active:</b></td>
          <td align=left>$recently_active</td>
        </tr>
164 165 166 167 168 169 170 171 172 173 174 175
        <tr>
          <td align=right><b>Been Active:</b></td>
          <td align=left>$active_projects</td>
        </tr>
        <tr>
          <td align=right><b>Never Active:</b></td>
          <td align=left>$never_active</td>
        </tr>
        <tr>
          <td align=right><b>Total:</b></td>
          <td align=left>$total_projects</td>
        </tr>
Chad Barb's avatar
Chad Barb committed
176
      </table><br />\n";
177
}
178

179 180
function GENPLIST ($query_result)
{
181
    global $isadmin, $ecounts, $ncounts, $pcounts, $showtype;
182 183

    $tablename = "SPL" . rand();
184

185
    echo "<table width='100%' border=2 id='$tablename'
Chad Barb's avatar
Chad Barb committed
186
                 cellpadding=2 cellspacing=2 align=center>
187
          <thead class='sort'>
188 189
          <tr>\n";

190 191
    echo "<th class='sorttable_alpha'>PID</th>\n";
    echo "<th class='sorttable_alpha'>(Approved?) Description</th>\n";
192 193 194 195
    if ($showtype != "ProtoGENI") {
	echo "<th>Leader</th>\n";
	echo "<th>Affil</th>\n";
    }
196 197
    echo "<th>Days<br>Idle</th>\n";
    echo "<th>Expts<br>Created</th>\n";
198
    echo "<th>Expts<br>Running</th>\n";
199 200
    echo "<th>Nodes<br>All</th>\n";
    echo "<th>Nodes<br>PCs</th>\n";
201

202
    #
203
    # Admin users get other fields.
204
    # 
205
    if ($isadmin && $showtype != "ProtoGENI") {
Chad Barb's avatar
Chad Barb committed
206
	echo "<th align=center>Pub?</th>\n";
207
    }
208
    echo "</tr>\n";
209
    echo "</thead>\n";
210

211 212
    while ($projectrow = mysql_fetch_array($query_result)) {
	$pid        = $projectrow["pid"];
213 214 215 216 217 218
	$headidx    = $projectrow["head_idx"];
	$Pname      = $projectrow["name"];
	$approved   = $projectrow["approved"];
	$expt_count = $projectrow["expt_count"];
	$public     = $projectrow["public"];
	$idle       = $projectrow["idle"];
219 220
	$ecount     = $ecounts[$pid];
	$ncount     = $ncounts[$pid];
221
	$pcount     = $pcounts[$pid];
222

223 224
	if (! ($head_user = User::Lookup($headidx))) {
	    TBERROR("Could not lookup object for user $headidx", 1);
225 226
	}
	$showuser_url = CreateURL("showuser", $head_user);
227
	$headuid      = $head_user->uid();
228
	$affil        = $head_user->affil_abbrev();
229
	
230 231 232 233 234 235 236 237 238
	echo "<tr>
                  <td><A href='showproject.php3?pid=$pid'>$pid</A></td>
                  <td>\n";
	if ($approved) {
	    echo "    <img alt='Y' src='greenball.gif'>";
	}
	else {
	    echo "    <img alt='N' src='redball.gif'>\n";
	}
239 240 241 242 243
	echo "             $Pname</td>";
	if ($showtype != "ProtoGENI") {
	    echo "<td><A href='$showuser_url'>$headuid</A></td>\n";
	    echo "<td>$affil</td>\n";
	}
244
	echo "<td>$idle</td>\n";
245
	echo "<td>$expt_count</td>\n";
246 247
	echo "<td>$ecount</td>\n";
	echo "<td>$ncount</td>\n";
248
	echo "<td>$pcount</td>\n";
249

250
	if ($isadmin && $showtype != "ProtoGENI") {
251
	    if ($public) {
252
		echo "<td align=center sorttable_customkey='1'><img alt='Y' src='greenball.gif'></td>";
253 254
	    }
	    else {
255
		echo "<td align=center sorttable_customkey='2'><img alt='N' src='redball.gif'></td>\n";
256
	    }
257 258
	}
	echo "</tr>\n";
259
    }
260
    echo "</table>\n";
261 262 263 264

    echo "<script type='text/javascript' language='javascript'>
	  sorttable.makeSortable(getObjbyName('$tablename'));
          </script>\n";
265 266 267 268 269 270
}

#
# Get the project list for non admins.
#
if (! $isadmin) {
271 272
    $uid_idx = $this_user->uid_idx();
    
273
    $query_result =
274
	DBQueryFatal("SELECT p.*, ".
275 276 277 278
		     "IF(p.expt_last, ".
		     "  TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
		     "  TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
		     "FROM projects as p ".
279
		     "left join group_membership as g on ".
280
		     " p.pid=g.pid and g.pid=g.gid ".
281
		     "where g.uid_idx='$uid_idx' and g.trust!='none' ".
282
		     "group by p.pid order by p.pid");
283 284 285
				   
    if (mysql_num_rows($query_result) == 0) {
	USERERROR("You are not a member of any projects!", 1);
286
    }
287 288 289 290
    
    GENPLIST($query_result);
}
else {
291
    if ($showtype == "Splitview") {
292
	$query_result =
293 294 295 296 297 298
	    DBQueryFatal("SELECT p.*, ".
			 "IF(p.expt_last, ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
			 "FROM projects as p ".
			 "where expt_count>0 ".
299
			 "group by p.pid order by p.pid");
300 301 302 303 304 305 306 307 308

	if (mysql_num_rows($query_result)) {
	    echo "<center>
                   <h3>Active Projects</h3>
                  </center>\n";
	    GENPLIST($query_result);
	}

	$query_result =
309 310 311 312 313 314
	    DBQueryFatal("SELECT p.*, ".
			 "IF(p.expt_last, ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
			 "FROM projects as p ".
			 "where expt_count=0 ".
315
			 "group by p.pid order by p.pid");
316 317 318 319 320 321 322

	if (mysql_num_rows($query_result)) {
	    echo "<br><center>
                   <h3>Inactive Projects</h3>
                  </center>\n";
	    GENPLIST($query_result);
	}
323

324
    }
325 326 327 328 329 330 331 332 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
    elseif ($showtype == "Active") {
	$query_result =
	    DBQueryFatal("select p.*, ".
			 "IF(p.expt_last, ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
			 " FROM projects as p ".
			 "left join project_stats as s ".
			 "     on s.pid_idx=p.pid_idx ".
			 "where (UNIX_TIMESTAMP(now()) - ".
			 "       UNIX_TIMESTAMP(s.last_activity)) < ".
			 "           (24 * 3600 * 90) ".
			 "group by p.pid order by p.pid");

	if (mysql_num_rows($query_result)) {
	    GENPLIST($query_result);
	}
    }
    elseif ($showtype == "ProtoGENI") {
	$query_result =
	    DBQueryFatal("select p.*, ".
			 "IF(p.expt_last, ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
			 " FROM projects as p ".
			 "where nonlocal_type is not null and ".
			 "      nonlocal_type='protogeni' ".
			 "group by p.pid order by p.pid");

	if (mysql_num_rows($query_result)) {
	    GENPLIST($query_result);
	}
    }
358
    else {
359
	$query_result =
360 361 362 363 364
	    DBQueryFatal("select p.*, ".
			 "IF(p.expt_last, ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.expt_last), ".
			 "  TO_DAYS(CURDATE()) - TO_DAYS(p.created)) as idle ".
			 " FROM projects as p ".
365
			 "group by p.pid order by p.pid");
366 367 368 369

	if (mysql_num_rows($query_result)) {
	    GENPLIST($query_result);
	}
370
    }
371
}
372 373 374 375 376

#
# Standard Testbed Footer
# 
PAGEFOOTER();
377
?>