From b84ffd9f1b4c24743ca03af42ddde6108f24d432 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 7 Aug 2003 00:39:54 +0000 Subject: [PATCH] Added a function to recalculate the user of the day when necessary, and build an includeable html file from the result. svn path=/trunk/boinc/; revision=2003 --- html/ops/gallery.inc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/html/ops/gallery.inc b/html/ops/gallery.inc index f1d28b3421..5bfc8f6cc8 100644 --- a/html/ops/gallery.inc +++ b/html/ops/gallery.inc @@ -260,4 +260,46 @@ function build_alpha_summary_page($characters) { } +function build_uotd_page() { + // Check if the current UOTD has had their 24 hours of fame - if so, pick a new one. + + $result = mysql_query("SELECT * FROM profile ORDER BY uotd_time DESC LIMIT 1"); + if (mysql_num_rows($result) > 0) { + $current_uotd = mysql_fetch_assoc($result); + + if (time() - $current_uotd['uotd_time'] < 86400) { + exit(); + } + } + + $result = mysql_query("SELECT * FROM profile WHERE verification = 1 AND uotd_time IS NULL LIMIT 1"); + + if ($result && mysql_num_rows($result) == 0) { + // If all verified profiles have been selected as UOTD, reshow the one that was shown least recently. + $result = mysql_query("SELECT * FROM profile WHERE verification = 1 ORDER BY uotd_time ASC LIMIT 1"); + } + + if (!$result || mysql_num_rows($result) == 0) { + // No valid users of the day - do something. + exit(); + } + $profile = mysql_fetch_assoc($result); + + $sql = "SELECT * FROM user where id = " . $profile['userid']; + $result2 = mysql_query($sql); + $user = mysql_fetch_assoc($result2); + + $filename = "../html_user/uotd.html"; + $descriptor = fopen($filename, "w"); + + if ($profile['has_picture']) { + fwrite($descriptor, ""); + } + fwrite($descriptor, "The " . PROJECT . " User of the Day is " . $user['name'] . ""); + fclose($descriptor); + + $sql = "UPDATE profile SET uotd_time = " . time() . " WHERE userid = " . $user['id']; + mysql_query($sql); +} + ?>