boinc/html/user/show_user.php

162 lines
4.7 KiB
PHP

<?php
// This page shows basic account details about a given user
// The page can be output as either XML or HTML.
// If output as xml the user may optionally
// also get a list of hosts in case the user provides his/her authenticator.
// Object-caching and full-file caching is used to speed up queries
// for data from this page.
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
require_once("../inc/cache.inc");
require_once("../inc/util.inc");
require_once("../inc/xml.inc");
require_once("../inc/db.inc");
require_once("../inc/user.inc");
require_once("../inc/forum.inc");
require_once("../project/project.inc");
$id = get_int("userid", true);
$format = get_str("format", true);
$auth = get_str("auth", true);
function parse_project($f) {
$p->total_credit = 0.0;
$p->expavg_credit = 0.0;
while (!feof($f)) {
$buf = fgets($f);
if (strstr($buf, "</project>")) break;
if ($x = parse_element($buf, "<name>")) {
$p->name = $x;
}
if ($x = parse_element($buf, "<name>")) {
$p->name = $x;
}
if ($x = parse_element($buf, "<url>")) {
$p->url = $x;
}
if ($x = parse_element($buf, "<total_credit>")) {
$p->total_credit = $x;
}
if ($x = parse_element($buf, "<expavg_credit>")) {
$p->expavg_credit = $x;
}
if ($x = parse_element($buf, "<id>")) {
$p->id = $x;
}
if ($x = parse_element($buf, "<country>")) {
$p->country = $x;
}
if ($x = parse_element($buf, "<team_id>")) {
$p->team_id = $x;
}
if ($x = parse_element($buf, "<team_name>")) {
$p->team_name = $x;
}
if ($x = parse_element($buf, "<create_time>")) {
$p->create_time = $x;
}
}
return $p;
}
function parse_user($f, $user) {
$user->projects = array();
while (!feof($f)) {
$buf = fgets($f);
if (strstr($buf, "</user>")) break;
if (strstr($buf, "<project>")) {
$user->projects[] = parse_project($f);
}
}
return $user;
}
function get_other_projects($user) {
$cpid = md5($user->cross_project_id . $user->email_addr);
$url = "http://boinc.netsoft-online.com/get_user.php?cpid=$cpid";
$f = fopen($url, "r");
if (!$f) {
return $user;
}
$u = parse_user($f, $user);
fclose($f);
return $u;
}
function show_project($project) {
row_array(array(
"<a href=$project->url/show_user.php?userid=$project->id>$project->name</a>",
number_format($project->total_credit, 0), number_format($project->expavg_credit, 0),
date_str($project->create_time)
));
}
if ($format=="xml"){
// XML doesn't need translating, so use the full-file cache for this
//
$cache_args="userid=".$id."&auth=".$auth;
start_cache(USER_PAGE_TTL, $cache_args);
xml_header();
$retval = db_init_xml();
if ($retval) xml_error($retval);
if ($auth){
$user = lookup_user_auth($auth);
$show_hosts = true;
} else {
$user = lookup_user_id($id);
$user = get_other_projects($user);
$show_hosts = false;
}
if (!$user) xml_error(-136);
show_user_xml($user, $show_hosts);
end_cache(USER_PAGE_TTL, $cache_args);
} else {
db_init(); // need to do this in any case,
// since show_user_summary_public() etc. accesses DB
// The page may be presented in many different languages,
// so here we cache the data instead
//
$cache_args="userid=".$id;
$cached_data = get_cached_data(TOP_PAGES_TTL, $cache_args);
if ($cached_data){
// We found some old but non-stale data, let's use it
$user = unserialize($cached_data);
} else {
// No data was found, generate new data for the cache and store it
$user = lookup_user_id($id);
$user = getForumPreferences($user);
$user = get_other_projects($user);
set_cache_data(serialize($user), $cache_args);
}
if (!$user->id) {
error_page("No such user found - please check the ID and try again.");
}
// Output:
page_head("Account data for $user->name");
start_table();
show_user_summary_public($user);
show_profile_link($user);
end_table();
project_user_summary($user);
if (count($user->projects) > 0) {
echo "<h3>Projects in which $user->name is participating</h3>";
start_table();
row_heading_array(array(
"Project<br><span class=note>Click for user page</span>", "Total credit", "Average credit", "Since"
));
foreach($user->projects as $project) {
show_project($project);
}
end_table();
}
page_tail(true);
}
?>