showproject_list.php3 10.3 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24 25 26
include("defs.php3");

#
27
# Only known and logged in users can do this.
28
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32

33 34 35
#
# Verify page arguments
#
36
$optargs = OptionalPageArguments("showtype",   PAGEARG_STRING);
37

38 39 40 41 42
#
# Standard Testbed Header
#
PAGEHEADER("Project Information List");

43
if (! isset($showtype)) {
44
    $showtype="Active";
45
}
46

47 48 49 50 51 52
if ($isadmin) {
    echo "<b>Show: ";
    
    if ($showtype != "Active") {
	echo "<a class='static'
                 href='showproject_list.php3?showtype=Active'>Active</a>, ";
53 54
    }
    else {
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
	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";
80
    }
81
}
82
echo "<br>\n";
83

84
$allproj_result =
85 86 87 88 89 90
    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");
		 
91 92 93 94 95 96
#
# 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();
97
$pcounts = array();
98 99 100

$query_result =
    DBQueryFatal("select e.pid, count(distinct e.eid) as ecount ".
101 102
		 "from experiments as e where state!='$TB_EXPTSTATE_SWAPPED' ".
		 "group by e.pid");
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

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

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
# 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;
}

139
while ($projectrow = mysql_fetch_array($allproj_result)) {
140
    $pid = $projectrow["pid"];
141 142 143 144 145 146

    if (!isset($ecounts[$pid])) 
	$ecounts[$pid] = 0;
	    
    if (!isset($ncounts[$pid])) 
	$ncounts[$pid] = 0;
147 148 149

    if (!isset($pcounts[$pid])) 
	$pcounts[$pid] = 0;
150 151
}

152
if ($isadmin) {
153
    mysql_data_seek($allproj_result, 0);
154
    
155 156 157 158
    #
    # Process the query results for active projects so I can generate a
    # summary block (as per Jays request).
    #
159
    $total_projects  = mysql_num_rows($allproj_result);
160
    $active_projects = 0;
161
    $recently_active = 0;
162

163
    while ($projectrow = mysql_fetch_array($allproj_result)) {
164 165
	$expt_count    = $projectrow["expt_count"];
	$last_activity = $projectrow["last_activity"];
166 167 168 169

	if ($expt_count > 0) {
	    $active_projects++;
	}
170 171 172
	if (time() - $last_activity < (24 * 3600 * 90)) {
	    $recently_active++;
	}
173 174 175
    }
    $never_active = $total_projects - $active_projects;

Chad Barb's avatar
Chad Barb committed
176
    echo "<table border=0 align=center cellpadding=0 cellspacing=2>
177 178 179 180
        <tr>
          <td align=right><b>Recently Active:</b></td>
          <td align=left>$recently_active</td>
        </tr>
181 182 183 184 185 186 187 188 189 190 191 192
        <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
193
      </table><br />\n";
194
}
195

196 197
function GENPLIST ($query_result)
{
198
    global $isadmin, $ecounts, $ncounts, $pcounts, $showtype;
199 200

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

202
    echo "<table width='100%' border=2 id='$tablename'
Chad Barb's avatar
Chad Barb committed
203
                 cellpadding=2 cellspacing=2 align=center>
204
          <thead class='sort'>
205 206
          <tr>\n";

207 208
    echo "<th class='sorttable_alpha'>PID</th>\n";
    echo "<th class='sorttable_alpha'>(Approved?) Description</th>\n";
209 210 211 212
    if ($showtype != "ProtoGENI") {
	echo "<th>Leader</th>\n";
	echo "<th>Affil</th>\n";
    }
213 214
    echo "<th>Days<br>Idle</th>\n";
    echo "<th>Expts<br>Created</th>\n";
215
    echo "<th>Expts<br>Running</th>\n";
216 217
    echo "<th>Nodes<br>All</th>\n";
    echo "<th>Nodes<br>PCs</th>\n";
218

219
    #
220
    # Admin users get other fields.
221
    # 
222
    if ($isadmin && $showtype != "ProtoGENI") {
Chad Barb's avatar
Chad Barb committed
223
	echo "<th align=center>Pub?</th>\n";
224
    }
225
    echo "</tr>\n";
226
    echo "</thead>\n";
227

228 229
    while ($projectrow = mysql_fetch_array($query_result)) {
	$pid        = $projectrow["pid"];
230 231 232 233 234 235
	$headidx    = $projectrow["head_idx"];
	$Pname      = $projectrow["name"];
	$approved   = $projectrow["approved"];
	$expt_count = $projectrow["expt_count"];
	$public     = $projectrow["public"];
	$idle       = $projectrow["idle"];
236 237
	$ecount     = $ecounts[$pid];
	$ncount     = $ncounts[$pid];
238
	$pcount     = $pcounts[$pid];
239

240 241
	if (! ($head_user = User::Lookup($headidx))) {
	    TBERROR("Could not lookup object for user $headidx", 1);
242 243
	}
	$showuser_url = CreateURL("showuser", $head_user);
244
	$headuid      = $head_user->uid();
245
	$affil        = $head_user->affil_abbrev();
246
	
247 248 249 250 251 252 253 254 255
	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";
	}
256 257 258 259 260
	echo "             $Pname</td>";
	if ($showtype != "ProtoGENI") {
	    echo "<td><A href='$showuser_url'>$headuid</A></td>\n";
	    echo "<td>$affil</td>\n";
	}
261
	echo "<td>$idle</td>\n";
262
	echo "<td>$expt_count</td>\n";
263 264
	echo "<td>$ecount</td>\n";
	echo "<td>$ncount</td>\n";
265
	echo "<td>$pcount</td>\n";
266

267
	if ($isadmin && $showtype != "ProtoGENI") {
268
	    if ($public) {
269
		echo "<td align=center sorttable_customkey='1'><img alt='Y' src='greenball.gif'></td>";
270 271
	    }
	    else {
272
		echo "<td align=center sorttable_customkey='2'><img alt='N' src='redball.gif'></td>\n";
273
	    }
274 275
	}
	echo "</tr>\n";
276
    }
277
    echo "</table>\n";
278 279 280 281

    echo "<script type='text/javascript' language='javascript'>
	  sorttable.makeSortable(getObjbyName('$tablename'));
          </script>\n";
282 283 284 285 286 287
}

#
# Get the project list for non admins.
#
if (! $isadmin) {
288 289
    $uid_idx = $this_user->uid_idx();
    
290
    $query_result =
291
	DBQueryFatal("SELECT p.*, ".
292 293 294 295
		     "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 ".
296
		     "left join group_membership as g on ".
297
		     " p.pid=g.pid and g.pid=g.gid ".
298
		     "where g.uid_idx='$uid_idx' and g.trust!='none' ".
299
		     "group by p.pid order by p.pid");
300 301 302
				   
    if (mysql_num_rows($query_result) == 0) {
	USERERROR("You are not a member of any projects!", 1);
303
    }
304 305 306 307
    
    GENPLIST($query_result);
}
else {
308
    if ($showtype == "Splitview") {
309
	$query_result =
310 311 312 313 314 315
	    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 ".
316
			 "group by p.pid order by p.pid");
317 318 319 320 321 322 323 324 325

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

	$query_result =
326 327 328 329 330 331
	    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 ".
332
			 "group by p.pid order by p.pid");
333 334 335 336 337 338 339

	if (mysql_num_rows($query_result)) {
	    echo "<br><center>
                   <h3>Inactive Projects</h3>
                  </center>\n";
	    GENPLIST($query_result);
	}
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
    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);
	}
    }
375
    else {
376
	$query_result =
377 378 379 380 381
	    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 ".
382
			 "group by p.pid order by p.pid");
383 384 385 386

	if (mysql_num_rows($query_result)) {
	    GENPLIST($query_result);
	}
387
    }
388
}
389 390 391 392 393

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