2003-03-17 22:37:49 +00:00
|
|
|
<?php
|
2008-03-06 00:40:48 +00:00
|
|
|
|
2005-12-04 23:39:09 +00:00
|
|
|
// show all the hosts for a user.
|
|
|
|
// if $userid is absent, show hosts of logged-in user
|
2003-03-19 21:01:32 +00:00
|
|
|
|
2007-10-28 15:03:14 +00:00
|
|
|
require_once("../inc/boinc_db.inc");
|
2005-12-04 23:39:09 +00:00
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../inc/host.inc");
|
|
|
|
require_once("../inc/cache.inc");
|
2003-03-17 22:37:49 +00:00
|
|
|
|
2008-03-06 00:40:48 +00:00
|
|
|
// This function takes as input a GET variable name X and value Y.
|
|
|
|
// It returns the corresponding text GET variable string, appended with
|
|
|
|
// any existing GET variable names and values, with &X=Y.
|
|
|
|
//
|
|
|
|
// This is useful for constructing urls for sorting a table by different
|
|
|
|
// columns.
|
|
|
|
//
|
|
|
|
function make_GET_list($variable_name, $variable_value) {
|
|
|
|
$retval="";
|
|
|
|
$sepchar='?';
|
|
|
|
$modified=false;
|
|
|
|
foreach ($_GET as $key => $value) {
|
|
|
|
$retval .= "$sepchar"."$key=";
|
|
|
|
$sepchar='&';
|
|
|
|
if ($key==$variable_name) {
|
|
|
|
$modified=true;
|
|
|
|
if ($value!=$variable_value) {
|
|
|
|
$retval .= "$variable_value";
|
|
|
|
} else {
|
|
|
|
$retval .= "$variable_value"."_reversed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$retval .= "$value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$modified) $retval .= "$sepchar$variable_name=$variable_value";
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
function link_with_GET_variables(
|
|
|
|
$text, $baseurl, $variable_name, $variable_value
|
|
|
|
) {
|
|
|
|
$list=make_GET_list($variable_name, $variable_value);
|
|
|
|
return "<a href=\"$baseurl$list\">$text</a>";
|
|
|
|
}
|
|
|
|
|
2006-02-20 19:11:51 +00:00
|
|
|
function more_or_less($show_all) {
|
|
|
|
if ($show_all) {
|
2008-03-06 00:40:48 +00:00
|
|
|
echo "<p>Show: All computers | ".link_with_GET_variables("Only computers active in past 30 days<p>", "hosts_user.php", 'show_all', '0');
|
2006-02-20 19:11:51 +00:00
|
|
|
} else {
|
2008-03-06 00:40:48 +00:00
|
|
|
echo "<p>Show: ".link_with_GET_variables("All computers", "hosts_user.php", 'show_all', '1')." | Only computers active in past 30 days<p>";;
|
2006-02-20 19:11:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following is used to show a user's hosts
|
|
|
|
//
|
|
|
|
function user_host_table_start($private) {
|
|
|
|
start_table();
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<th>".link_with_GET_variables("Computer ID", "hosts_user.php", 'sort', 'id')."<br><font size=-2>Click for more info</font></th>\n";
|
|
|
|
if ($private) {
|
2008-03-11 20:27:19 +00:00
|
|
|
echo "<th>".link_with_GET_variables("Name", "hosts_user.php", 'sort', 'name')."</th>\n";
|
|
|
|
echo "<th>".link_with_GET_variables("Location", "hosts_user.php", 'sort', 'venue')."</th>\n";
|
2006-02-20 19:11:51 +00:00
|
|
|
} else {
|
|
|
|
echo "<th>Rank</th>";
|
|
|
|
}
|
|
|
|
echo "
|
2008-03-11 20:27:19 +00:00
|
|
|
<th>".link_with_GET_variables("Avg. credit", "hosts_user.php", 'sort', 'expavg_credit')."</th>
|
2006-02-20 19:11:51 +00:00
|
|
|
<th>".link_with_GET_variables("Total credit", "hosts_user.php", 'sort', 'total_credit')."</th>
|
|
|
|
<th>".link_with_GET_variables("CPU type", "hosts_user.php", 'sort', 'cpu')."</th>
|
|
|
|
<th>".link_with_GET_variables("Operating system", "hosts_user.php", 'sort', 'os')."</th>
|
|
|
|
";
|
|
|
|
echo "<th>".link_with_GET_variables("Last contact", "hosts_user.php", 'sort', 'rpc_time')."</th>";
|
|
|
|
}
|
|
|
|
|
2006-02-22 06:19:54 +00:00
|
|
|
// get the _GET variables which determine how to display the page
|
|
|
|
//
|
2005-12-04 23:39:09 +00:00
|
|
|
$show_all = get_int("show_all", true);
|
2006-02-27 20:49:22 +00:00
|
|
|
if ($show_all != 1) {
|
|
|
|
// default value -- show last 30 days
|
|
|
|
$show_all = 0;
|
|
|
|
$_GET['show_all'] = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-22 06:19:54 +00:00
|
|
|
$sort = get_str("sort", true);
|
2008-03-06 00:40:48 +00:00
|
|
|
switch ($sort) {
|
|
|
|
case "total_credit": $sort_clause = "total_credit desc"; break;
|
|
|
|
case "total_credit_reversed": $sort_clause = "total_credit"; break;
|
|
|
|
case "expavg_credit": $sort_clause = "expavg_credit desc"; break;
|
|
|
|
case "expavg_credit_reversed": $sort_clause = "expavg_credit"; break;
|
|
|
|
case "name": $sort_clause = "domain_name"; break;
|
|
|
|
case "name_reversed": $sort_clause = "domain_name desc"; break;
|
|
|
|
case "id": $sort_clause = "id"; break;
|
|
|
|
case "id_reversed": $sort_clause = "id desc"; break;
|
|
|
|
case "expavg_credit": $sort_clause = "expavg_credit desc"; break;
|
|
|
|
case "expavg_credit_reversed": $sort_clause = "expavg_credit "; break;
|
2008-03-11 20:27:19 +00:00
|
|
|
case "cpu": $sort_clause = "p_vendor"; break;
|
|
|
|
case "cpu_reversed": $sort_clause = "p_vendor desc"; break;
|
|
|
|
case "os": $sort_clause = "os_name"; break;
|
|
|
|
case "os_reversed": $sort_clause = "os_name desc"; break;
|
|
|
|
case "venue": $sort_clause = "venue"; break;
|
|
|
|
case "venue_reversed": $sort_clause = "venue desc"; break;
|
2008-03-06 00:40:48 +00:00
|
|
|
case "rpc_time_reversed": $sort_clause = "rpc_time"; break;
|
|
|
|
default:
|
2006-02-27 20:49:22 +00:00
|
|
|
// default value -- sort by RPC time
|
|
|
|
$sort = "rpc_time";
|
|
|
|
$sort_clause = "rpc_time desc";
|
|
|
|
$_GET['sort']=$sort;
|
|
|
|
}
|
2005-12-04 23:39:09 +00:00
|
|
|
|
|
|
|
$user = get_logged_in_user(false);
|
2006-02-27 20:49:22 +00:00
|
|
|
$userid = get_int("userid", true);
|
|
|
|
|
2005-12-04 23:39:09 +00:00
|
|
|
if ($user && $user->id == $userid) {
|
|
|
|
$userid = 0;
|
|
|
|
}
|
|
|
|
if ($userid) {
|
|
|
|
$user = lookup_user_id($userid);
|
|
|
|
if (!$user) {
|
|
|
|
error_page("No such user");
|
2005-07-20 12:49:45 +00:00
|
|
|
}
|
2007-10-27 20:05:32 +00:00
|
|
|
$caching = true;
|
|
|
|
|
2007-10-24 17:35:28 +00:00
|
|
|
// At this point, we know that $userid, $show_all and $sort all have
|
2006-02-27 20:49:22 +00:00
|
|
|
// valid values.
|
2007-10-24 17:35:28 +00:00
|
|
|
//
|
2006-02-22 06:19:54 +00:00
|
|
|
$cache_args="userid=$userid&show_all=$show_all&sort=$sort";
|
2005-12-04 23:39:09 +00:00
|
|
|
start_cache(USER_PAGE_TTL, $cache_args);
|
|
|
|
if ($user->show_hosts) {
|
|
|
|
page_head("Computers belonging to $user->name");
|
2006-02-20 19:11:51 +00:00
|
|
|
more_or_less($show_all);
|
2005-12-04 23:39:09 +00:00
|
|
|
user_host_table_start(false);
|
2003-03-19 21:01:32 +00:00
|
|
|
} else {
|
2005-12-04 23:39:09 +00:00
|
|
|
page_head("Computers hidden");
|
|
|
|
echo "This user has chosen not to show information about their computers.\n";
|
|
|
|
page_tail();
|
|
|
|
end_cache(USER_PAGE_TTL, $cache_args);
|
|
|
|
exit();
|
2003-03-19 21:01:32 +00:00
|
|
|
}
|
2005-12-04 23:39:09 +00:00
|
|
|
$private = false;
|
|
|
|
} else {
|
2005-12-21 22:59:21 +00:00
|
|
|
$user = get_logged_in_user();
|
2007-10-27 20:05:32 +00:00
|
|
|
$caching = false;
|
2005-12-04 23:39:09 +00:00
|
|
|
$userid = $user->id;
|
|
|
|
page_head("Your computers");
|
2006-02-20 19:11:51 +00:00
|
|
|
more_or_less($show_all);
|
2005-12-04 23:39:09 +00:00
|
|
|
user_host_table_start(true);
|
|
|
|
$private = true;
|
|
|
|
}
|
2005-09-21 21:39:35 +00:00
|
|
|
|
2005-12-04 23:39:09 +00:00
|
|
|
$now = time();
|
2006-02-20 19:11:51 +00:00
|
|
|
$old_hosts=0;
|
|
|
|
$i = 1;
|
2007-10-28 15:03:14 +00:00
|
|
|
$hosts = BoincHost::enum("userid=$userid order by $sort_clause");
|
|
|
|
foreach ($hosts as $host) {
|
2006-02-20 19:11:51 +00:00
|
|
|
$is_old=false;
|
|
|
|
if (($now - $host->rpc_time) > 30*86400) {
|
|
|
|
$is_old=true;
|
|
|
|
$old_hosts++;
|
2004-11-18 20:01:12 +00:00
|
|
|
}
|
2006-02-20 19:11:51 +00:00
|
|
|
if (!$show_all && $is_old) continue;
|
2005-12-04 23:39:09 +00:00
|
|
|
show_host_row($host, $i, $private, false);
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
2006-02-20 19:11:51 +00:00
|
|
|
|
2007-10-24 17:35:28 +00:00
|
|
|
if ($old_hosts>0) {
|
|
|
|
more_or_less($show_all);
|
2007-06-20 16:27:27 +00:00
|
|
|
}
|
2007-05-30 20:30:28 +00:00
|
|
|
|
2007-10-28 15:03:14 +00:00
|
|
|
if ($private) {
|
2007-10-27 20:05:32 +00:00
|
|
|
echo "
|
|
|
|
<a href=merge_by_name.php>Merge computers by name</a>
|
|
|
|
";
|
|
|
|
}
|
2007-10-24 17:35:28 +00:00
|
|
|
|
2005-12-04 23:39:09 +00:00
|
|
|
if ($caching) {
|
|
|
|
page_tail(true);
|
|
|
|
end_cache(USER_PAGE_TTL, $cache_args);
|
|
|
|
} else {
|
|
|
|
page_tail();
|
|
|
|
}
|
2008-03-06 00:40:48 +00:00
|
|
|
|
2003-03-17 22:37:49 +00:00
|
|
|
?>
|