2007-10-19 20:01:36 +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/>.
|
2007-10-19 20:01:36 +00:00
|
|
|
|
2007-11-18 22:17:39 +00:00
|
|
|
// TODO: convert to new DB interface; use caching to avoid
|
|
|
|
// repeated lookup for same userid
|
|
|
|
|
2007-11-18 21:22:11 +00:00
|
|
|
// TODO: merge vote_yes() and vote_no() (??????)
|
|
|
|
|
2007-11-20 23:18:54 +00:00
|
|
|
require_once("../inc/forum_email.inc");
|
|
|
|
|
2007-11-18 21:22:11 +00:00
|
|
|
db_init();
|
|
|
|
|
2007-10-19 20:01:36 +00:00
|
|
|
function current_tally($voteid) {
|
2007-10-30 18:16:29 +00:00
|
|
|
$query="select sum(yes) as ayes,count(id)-sum(yes) as nays from banishment_votes where voteid=".$voteid;
|
|
|
|
$result = mysql_query($query);
|
|
|
|
$foobar = mysql_fetch_object($result);
|
|
|
|
echo "<b>Current Tally</b> Ayes: ".$foobar->ayes." Nays: ".$foobar->nays."<p>";
|
|
|
|
return true;
|
2007-10-19 20:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function vote_is_in_progress($userid) {
|
2007-10-30 18:16:29 +00:00
|
|
|
// check whether a vote is already ongoing
|
|
|
|
$now=time();
|
|
|
|
$query="select count(id) as count from banishment_vote where userid=".$userid." and end_time>".$now;
|
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
|
|
|
echo "Database error attempting to read banishment_vote table 1.<p>";
|
2007-11-18 21:22:11 +00:00
|
|
|
echo "query: $query";
|
2007-10-30 18:16:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
$foobar = mysql_fetch_object($result);
|
|
|
|
if (!$foobar) {
|
|
|
|
echo "Database error attempting to read banishment_vote table 2.<p>";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return $foobar->count;
|
2007-10-19 20:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function start_vote($config,$logged_in_user,$user,$category,$reason) {
|
2007-10-30 18:16:29 +00:00
|
|
|
$now=time();
|
|
|
|
$fin=$now+21600;
|
2007-10-19 20:01:36 +00:00
|
|
|
|
|
|
|
|
2007-10-30 18:16:29 +00:00
|
|
|
if ( vote_is_in_progress($user->id) !=0 ) {
|
|
|
|
echo "A banishment vote is already underway for this user.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-19 05:14:37 +00:00
|
|
|
$query="insert into banishment_vote (userid,modid,start_time,end_time) values (".$user->id.",".$logged_in_user->id.",".$now.",".$fin.")";
|
2007-10-30 18:16:29 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
|
|
|
echo "Database error attempting to insert to banishment_vote table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-19 20:01:36 +00:00
|
|
|
|
2007-10-30 18:16:29 +00:00
|
|
|
$voteid=mysql_insert_id();
|
2007-11-19 05:14:37 +00:00
|
|
|
$query="insert into banishment_votes (voteid,modid,time,yes) values (". $voteid .",". $logged_in_user->id .",". $now .",1)";
|
2007-10-30 18:16:29 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
|
|
|
echo "Database error attempting to insert to banishment_votes table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-19 20:01:36 +00:00
|
|
|
|
2007-10-30 18:16:29 +00:00
|
|
|
$query="update forum_preferences set banished_until=".$fin." where userid=".$user->id;
|
|
|
|
$result = mysql_query($query);
|
2007-10-19 20:01:36 +00:00
|
|
|
|
2007-10-30 18:16:29 +00:00
|
|
|
echo "Banishment vote started.<p><p>";
|
|
|
|
current_tally($voteid);
|
|
|
|
return send_banish_vote_email($user, 86400*14, $reason, $now+21600);
|
|
|
|
}
|
2007-10-19 20:01:36 +00:00
|
|
|
|
|
|
|
function vote_yes($config,$logged_in_user,$user) {
|
2007-10-30 18:16:29 +00:00
|
|
|
$now=time();
|
|
|
|
// Check that a vote is underway.
|
|
|
|
if (vote_is_in_progress($user->id)<1) {
|
|
|
|
echo "No banishment vote is underway for this user.<p><p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Find the voteid
|
|
|
|
$query="select id as voteid from banishment_vote where userid=".$user->id." and end_time>".$now;
|
|
|
|
$result = mysql_query($query);
|
|
|
|
$foobar = mysql_fetch_object($result);
|
|
|
|
if (!$foobar) {
|
|
|
|
echo "Database error attempting to read banishment_vote table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$voteid=$foobar->voteid;
|
|
|
|
// Check whether mod has voted already.
|
2007-11-19 05:14:37 +00:00
|
|
|
$query="select count(id) as count from banishment_votes where voteid=".$voteid." and modid=".$logged_in_user->id;
|
2007-10-30 18:16:29 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
$foobar = mysql_fetch_object($result);
|
|
|
|
if (!$foobar) {
|
|
|
|
echo "Database error attempting to read banishment_vote table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ($foobar->count > 0) {
|
|
|
|
echo "You have already voted in this election.<p><p>";
|
|
|
|
current_tally($voteid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// insert the vote
|
2007-11-19 05:14:37 +00:00
|
|
|
$query="insert into banishment_votes (voteid,modid,time,yes) values (" . $voteid .",". $logged_in_user->id .",". $now .",1)";
|
2007-10-30 18:16:29 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
|
|
|
echo "Database error attempting to insert to banishment_votes table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
echo "Vote recorded: Aye<p><p>";
|
2007-10-19 20:01:36 +00:00
|
|
|
current_tally($voteid);
|
2007-10-30 18:16:29 +00:00
|
|
|
return 1;
|
2007-10-19 20:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function vote_no($config,$logged_in_user,$user) {
|
2007-10-30 18:16:29 +00:00
|
|
|
// Check that a vote is underway.
|
|
|
|
$now=time();
|
|
|
|
if (vote_is_in_progress($user->id)<1) {
|
|
|
|
echo "No banishment vote is underway for this user.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Find the voteid
|
|
|
|
$query="select id as voteid from banishment_vote where userid=".$user->id." and end_time>".$now;
|
|
|
|
$result = mysql_query($query);
|
|
|
|
$foobar = mysql_fetch_object($result);
|
|
|
|
if (!$foobar) {
|
|
|
|
echo "Database error attempting to read banishment_vote table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$voteid=$foobar->voteid;
|
|
|
|
// Check whether mod has voted already.
|
2007-11-19 05:14:37 +00:00
|
|
|
$query="select count(id) as count from banishment_votes where voteid=".$voteid ." and modid=".$logged_in_user->id;
|
2007-10-30 18:16:29 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
$foobar = mysql_fetch_object($result);
|
|
|
|
if (!$foobar) {
|
|
|
|
echo "Database error attempting to read banishment_vote table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ($foobar->count > 0) {
|
|
|
|
echo "You have already voted in this election.<p><p>";
|
|
|
|
current_tally($voteid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// insert the vote
|
2007-11-19 05:14:37 +00:00
|
|
|
$query="insert into banishment_votes (voteid,modid,time,yes) values (" . $voteid .",". $logged_in_user->id .",". $now .",0)";
|
2007-10-30 18:16:29 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
|
|
|
echo "Database error attempting to insert to banishment_votes table.<p>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
echo "Vote recorded: Nay<p><p>";
|
2007-10-19 20:01:36 +00:00
|
|
|
current_tally($voteid);
|
2007-10-30 18:16:29 +00:00
|
|
|
return 1;
|
2007-10-19 20:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|