2004-06-09 21:42:23 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC 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 Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-06-09 21:42:23 +00:00
|
|
|
|
2007-11-22 01:52:27 +00:00
|
|
|
require_once('../inc/email.inc');
|
2006-08-15 23:02:52 +00:00
|
|
|
require_once('../inc/profile.inc');
|
|
|
|
|
2004-06-09 21:42:23 +00:00
|
|
|
define('UOTD_THRESHOLD', 7);
|
2007-04-30 15:29:14 +00:00
|
|
|
// email sysadmin if # of UOTD candidates falls below this
|
2004-05-11 22:49:23 +00:00
|
|
|
|
|
|
|
function uotd_thumbnail($profile, $user) {
|
2004-07-21 22:19:21 +00:00
|
|
|
if ($profile->has_picture) {
|
2010-02-16 01:06:03 +00:00
|
|
|
return "<a href=\"".URL_BASE."view_profile.php?userid=$user->id\"><img border=0 vspace=4 hspace=8 align=left src=\"".profile_thumb_url($user->id)."\" alt=\"".tra("User profile")."\"></a>";
|
2004-07-21 22:19:21 +00:00
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 15:29:14 +00:00
|
|
|
// show UOTD in a small box
|
|
|
|
//
|
2007-12-24 21:34:21 +00:00
|
|
|
function show_uotd($profile) {
|
|
|
|
$user = lookup_user_id($profile->userid);
|
2008-01-15 22:14:07 +00:00
|
|
|
echo uotd_thumbnail($profile, $user);
|
2007-12-31 22:56:39 +00:00
|
|
|
echo user_links($user, true)."<br>";
|
2011-08-26 18:30:13 +00:00
|
|
|
echo sub_sentence(output_transform(sanitize_tags($profile->response1)), ' ', 150, true);
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return the last UOTD profile, or null
|
|
|
|
//
|
|
|
|
function get_current_uotd() {
|
2007-10-29 16:38:25 +00:00
|
|
|
$profiles = BoincProfile::enum(null, "ORDER BY uotd_time DESC LIMIT 1");
|
|
|
|
if (sizeof($profiles)) {
|
|
|
|
return $profiles[0];
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
2007-10-29 16:38:25 +00:00
|
|
|
return null;
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 15:29:14 +00:00
|
|
|
// Select a (possibly new) UOTD
|
2004-05-11 22:49:23 +00:00
|
|
|
//
|
2007-04-30 15:29:14 +00:00
|
|
|
function select_uotd() {
|
2012-05-12 15:13:43 +00:00
|
|
|
echo gmdate("F d Y", time())." UTC: Starting\n";
|
2004-05-11 22:49:23 +00:00
|
|
|
$current_uotd = get_current_uotd();
|
|
|
|
if ($current_uotd) {
|
|
|
|
$assigned = getdate($current_uotd->uotd_time);
|
|
|
|
$now = getdate(time());
|
|
|
|
if ($assigned['mday'] == $now['mday']) {
|
|
|
|
$user = lookup_user_id($current_uotd->userid);
|
2004-12-27 21:53:38 +00:00
|
|
|
echo "Already have UOTD for today\n";
|
- scheduler: add <workload_sim> config option.
If set, the scheduler will use EDF simulation,
together with the in-progress workload reported by the client,
to avoid sending results that
1) will miss their deadline, or
2) will cause an in-progress result to miss its deadline, or
3) will make an in-progress result miss its deadline
by more than is already predicted.
If this option is not set, or if the client request doesn't
include a workload description (i.e. the client is old)
use the existing approach, which assumes there's no workload.
NOTE: this is experimental. Production projects should not use it.
- EDF sim: write debug stuff to stderr instead of stdout
- Account manager:
- if an account is detach_when_done, set dont_request_more_work
- check done_request_more_work even for first-time projects
- update_uotd: generate a file for use by Google gadget
- user_links(): use full URLs (so can use in Google gadget)
client/
acct_mgr.C
work_fetch.C
html/
inc/
uotd.inc
util.inc
user/
uotd_gadget.php (new)
sched/
Makefile.am
edf_sim.C
sched_config.C,h
sched_resend.C
sched_send.C,h
server_types.C,h
svn path=/trunk/boinc/; revision=12639
2007-05-10 21:50:52 +00:00
|
|
|
generate_uotd_gadget($current_uotd, $user);
|
2004-05-11 22:49:23 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 22:11:53 +00:00
|
|
|
|
|
|
|
// get a list of profiles that have been 'approved' for UOTD,
|
|
|
|
// using a project-specific query if supplied in project.inc
|
|
|
|
//
|
2006-08-14 22:50:51 +00:00
|
|
|
if (function_exists('uotd_candidates_query')) {
|
|
|
|
$query = uotd_candidates_query();
|
2006-08-14 22:11:53 +00:00
|
|
|
} else {
|
2006-11-16 19:03:07 +00:00
|
|
|
$query = default_uotd_candidates_query();
|
2006-08-14 22:11:53 +00:00
|
|
|
}
|
|
|
|
$result = mysql_query($query);
|
2004-05-11 22:49:23 +00:00
|
|
|
|
|
|
|
// If the number of approved profiles dips below a threshold,
|
|
|
|
// email the sys admin every time we pick a new one.
|
|
|
|
//
|
|
|
|
if ($result && mysql_num_rows($result) < UOTD_THRESHOLD) {
|
2007-11-22 01:52:27 +00:00
|
|
|
$u = new BoincUser;
|
2007-12-10 22:13:48 +00:00
|
|
|
$u->email_addr = UOTD_ADMIN_EMAIL;
|
2007-11-22 01:52:27 +00:00
|
|
|
$u->name = "UOTD admin";
|
|
|
|
send_email($u,
|
2004-05-11 22:49:23 +00:00
|
|
|
PROJECT . ": User of the Day pool is running low!",
|
|
|
|
"The pool of approved candidates for User of the Day has".
|
2004-06-11 18:50:15 +00:00
|
|
|
" reached your assigned threshold: there are now only " . mysql_num_rows($result) . " approved users.\n\n".
|
2004-05-11 22:49:23 +00:00
|
|
|
"To approve more candidates for User of the Day,".
|
2011-03-20 07:04:32 +00:00
|
|
|
" go to the " . PROJECT . " administration page and click \"Screen user profiles\""
|
2004-05-11 22:49:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result && mysql_num_rows($result) == 0) {
|
2004-12-27 21:53:38 +00:00
|
|
|
// If all verified profiles have been selected as UOTD,
|
|
|
|
// reshow the one that was shown least recently.
|
|
|
|
//
|
2006-08-14 22:11:53 +00:00
|
|
|
$result = mysql_query("SELECT * FROM profile,user WHERE profile.userid=user.id AND verification=1 ORDER BY uotd_time ASC LIMIT 1");
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$result || mysql_num_rows($result) == 0) {
|
|
|
|
// No valid users of the day - do something.
|
2004-12-27 21:53:38 +00:00
|
|
|
echo "No screened users found\n";
|
2004-05-11 22:49:23 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$profile = mysql_fetch_object($result);
|
|
|
|
$user = lookup_user_id($profile->userid);
|
|
|
|
|
2008-10-22 15:49:01 +00:00
|
|
|
// if profile is "orphaned", delete it and try again
|
|
|
|
//
|
|
|
|
if (!$user) {
|
|
|
|
$profile->delete_aux("userid=$profile->userid");
|
|
|
|
select_uotd();
|
|
|
|
}
|
|
|
|
|
2006-08-14 22:11:53 +00:00
|
|
|
$sql = "UPDATE profile SET uotd_time = ".time()." WHERE userid=$user->id";
|
2004-05-11 22:49:23 +00:00
|
|
|
mysql_query($sql);
|
|
|
|
|
2007-11-22 01:52:27 +00:00
|
|
|
send_email($user,
|
2004-05-11 22:49:23 +00:00
|
|
|
"You're the " . PROJECT . " user of the day!",
|
|
|
|
"Congratulations!\n\nYou've been chosen as the "
|
|
|
|
. PROJECT . " user of the day!
|
|
|
|
Your profile will be featured on the " . PROJECT . " website for the next 24 hours."
|
|
|
|
);
|
2004-12-27 21:53:38 +00:00
|
|
|
echo "Chose user $user->id as UOTD\n";
|
- scheduler: add <workload_sim> config option.
If set, the scheduler will use EDF simulation,
together with the in-progress workload reported by the client,
to avoid sending results that
1) will miss their deadline, or
2) will cause an in-progress result to miss its deadline, or
3) will make an in-progress result miss its deadline
by more than is already predicted.
If this option is not set, or if the client request doesn't
include a workload description (i.e. the client is old)
use the existing approach, which assumes there's no workload.
NOTE: this is experimental. Production projects should not use it.
- EDF sim: write debug stuff to stderr instead of stdout
- Account manager:
- if an account is detach_when_done, set dont_request_more_work
- check done_request_more_work even for first-time projects
- update_uotd: generate a file for use by Google gadget
- user_links(): use full URLs (so can use in Google gadget)
client/
acct_mgr.C
work_fetch.C
html/
inc/
uotd.inc
util.inc
user/
uotd_gadget.php (new)
sched/
Makefile.am
edf_sim.C
sched_config.C,h
sched_resend.C
sched_send.C,h
server_types.C,h
svn path=/trunk/boinc/; revision=12639
2007-05-10 21:50:52 +00:00
|
|
|
$profile->uotd_time = time();
|
|
|
|
generate_uotd_gadget($profile, $user);
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 22:14:07 +00:00
|
|
|
// This query defines the set of users eligible to be UOTD.
|
2006-11-16 19:03:07 +00:00
|
|
|
// To override this with your own policy, create a similar function in
|
|
|
|
// your own project.inc called uotd_candidates_query()
|
2007-10-29 16:38:25 +00:00
|
|
|
//
|
2006-11-16 19:03:07 +00:00
|
|
|
function default_uotd_candidates_query(){
|
2008-01-15 22:14:07 +00:00
|
|
|
$query = "SELECT * FROM profile,user WHERE profile.userid=user.id ";
|
|
|
|
$query .= " AND verification=1 ";
|
|
|
|
$query .= " AND expavg_credit>1 ";
|
|
|
|
$query .= " AND uotd_time IS NULL ";
|
|
|
|
$query .= "ORDER BY RAND()";
|
2006-11-16 19:03:07 +00:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a list of profiles that have been 'approved' for UOTD,
|
|
|
|
// using a project-specific query if supplied in project.inc
|
2007-04-30 15:29:14 +00:00
|
|
|
//
|
2006-11-16 19:03:07 +00:00
|
|
|
function count_uotd_candidates(){
|
|
|
|
$n = -1; // negative value returned on error
|
|
|
|
if (function_exists('uotd_candidates_query')) {
|
|
|
|
$query = uotd_candidates_query();
|
|
|
|
} else {
|
|
|
|
$query = default_uotd_candidates_query();
|
|
|
|
}
|
2007-09-12 14:08:34 +00:00
|
|
|
|
2006-11-16 19:03:07 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
if($result) {
|
|
|
|
$n = mysql_num_rows($result);
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
2007-09-12 14:08:34 +00:00
|
|
|
|
2006-11-16 19:03:07 +00:00
|
|
|
return $n;
|
|
|
|
}
|
|
|
|
|
2007-05-10 16:23:10 +00:00
|
|
|
// iGoogle gadget - generate the gadget content page
|
|
|
|
//
|
|
|
|
function generate_uotd_gadget($profile, $user) {
|
|
|
|
$x = "<font size='2'>\n";
|
|
|
|
$gadget = PROFILE_PATH."uotd_gadget.html";
|
|
|
|
if( $h = fopen($gadget, "w") ){
|
- scheduler: add <workload_sim> config option.
If set, the scheduler will use EDF simulation,
together with the in-progress workload reported by the client,
to avoid sending results that
1) will miss their deadline, or
2) will cause an in-progress result to miss its deadline, or
3) will make an in-progress result miss its deadline
by more than is already predicted.
If this option is not set, or if the client request doesn't
include a workload description (i.e. the client is old)
use the existing approach, which assumes there's no workload.
NOTE: this is experimental. Production projects should not use it.
- EDF sim: write debug stuff to stderr instead of stdout
- Account manager:
- if an account is detach_when_done, set dont_request_more_work
- check done_request_more_work even for first-time projects
- update_uotd: generate a file for use by Google gadget
- user_links(): use full URLs (so can use in Google gadget)
client/
acct_mgr.C
work_fetch.C
html/
inc/
uotd.inc
util.inc
user/
uotd_gadget.php (new)
sched/
Makefile.am
edf_sim.C
sched_config.C,h
sched_resend.C
sched_send.C,h
server_types.C,h
svn path=/trunk/boinc/; revision=12639
2007-05-10 21:50:52 +00:00
|
|
|
$age = time()-$profile->uotd_time;
|
|
|
|
echo "age: $age";
|
|
|
|
if($age <= 86400+3600) { // allow for slop
|
2007-05-10 16:23:10 +00:00
|
|
|
$x .= uotd_thumbnail($profile, $user);
|
|
|
|
$x .= user_links($user);
|
|
|
|
$x .= " ".
|
2011-08-26 18:30:13 +00:00
|
|
|
sub_sentence(sanitize_tags(output_transform($profile->response1)), ' ',
|
2007-05-10 16:23:10 +00:00
|
|
|
250, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$x .= "<font color='fuscia'>
|
|
|
|
There is no User of the Day today.
|
|
|
|
Only volunteers who have created a Profile
|
|
|
|
(with a picture), and have recent credit,
|
|
|
|
are eligible to be chosen as User of the Day.
|
|
|
|
We have run out of these, so there isn't a
|
|
|
|
User of the Day.
|
|
|
|
</font>";
|
|
|
|
}
|
|
|
|
$x .= "\n</font>\n";
|
|
|
|
fwrite($h, $x);
|
|
|
|
fclose($h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-11 22:49:23 +00:00
|
|
|
?>
|