From 5f4afcc8cb6dcc5dcbe4d5161fad5372eb5f6435 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 30 Dec 2007 08:56:33 +0900 Subject: Add support for variable length votes in voting application Signed-off-by: Callan Barrett --- web/html/addvote.php | 38 ++++++++++----- web/html/tu.php | 131 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 103 insertions(+), 66 deletions(-) (limited to 'web/html') diff --git a/web/html/addvote.php b/web/html/addvote.php index 91a0658..ef1c6c3 100644 --- a/web/html/addvote.php +++ b/web/html/addvote.php @@ -18,36 +18,48 @@ if ($atype == "Trusted User" OR $atype == "Developer") { $dbh = db_connect(); if (!empty($_POST['addVote'])) { - $aweek = 60*60*24*7; $error = ""; - if (!empty($_REQUEST['user'])) { - $qcheck = "SELECT * FROM Users WHERE Username = '" . mysql_real_escape_string($_REQUEST['user']) . "'"; + if (!empty($_POST['user'])) { + $qcheck = "SELECT * FROM Users WHERE Username = '" . mysql_real_escape_string($_POST['user']) . "'"; $check = mysql_num_rows(db_query($qcheck, $dbh)); if ($check == 0) { $error.= "
Username does not exist.
"; } else { - $qcheck = "SELECT * FROM TU_VoteInfo WHERE User = '" . mysql_real_escape_string($_REQUEST['user']) . "'"; - $qcheck.= " AND Submitted + " . $aweek . " > UNIX_TIMESTAMP()"; + $qcheck = "SELECT * FROM TU_VoteInfo WHERE User = '" . mysql_real_escape_string($_POST['user']) . "'"; + $qcheck.= " AND End > UNIX_TIMESTAMP()"; $check = mysql_num_rows(db_query($qcheck, $dbh)); if ($check != 0) { - $error.= "
" . mysql_real_escape_string($_REQUEST['user']) . " already has proposal running for them.
"; + $error.= "
" . htmlentities($_POST['user']) . " already has proposal running for them.
"; } } } - if (empty($_REQUEST['agenda'])) { + if (!empty($_POST['length'])) { + if (!is_numeric($_POST['length'])) { + $error.= "
Length must be a number.
"; + } else if ($_POST['length'] < 1) { + $error.= "
Length must be at least 1.
"; + } else { + $len = (60*60*24)*$_POST['length']; + } + } else { + $len = 60*60*24*7; + } + + if (empty($_POST['agenda'])) { $error.= "
Proposal cannot be empty.
"; } } if (!empty($_POST['addVote']) && empty($error)) { - $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, SubmitterID) VALUES "; - $q.= "('" . mysql_real_escape_string($_REQUEST['agenda']) . "', "; - $q.= "'" . mysql_real_escape_string($_REQUEST['user']) . "', "; - $q.= "UNIX_TIMESTAMP(), " . uid_from_sid($_COOKIE["AURSID"]) . ")"; + $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, SubmitterID) VALUES "; + $q.= "('" . mysql_real_escape_string($_POST['agenda']) . "', "; + $q.= "'" . mysql_real_escape_string($_POST['user']) . "', "; + $q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . mysql_real_escape_string($len); + $q.= ", " . uid_from_sid($_COOKIE["AURSID"]) . ")"; db_query($q, $dbh); print "

New proposal submitted.

\n"; @@ -60,6 +72,10 @@ if ($atype == "Trusted User" OR $atype == "Developer") { '> (empty if not applicable)
+Length in days: +'> +(defaults to 7 if empty) +
Proposal:

diff --git a/web/html/tu.php b/web/html/tu.php index 9ed00bc..7ddec1a 100644 --- a/web/html/tu.php +++ b/web/html/tu.php @@ -24,8 +24,6 @@ if ($atype == "Trusted User" OR $atype == "Developer") { # Temp value for results per page $pp = 5; - # This needs to be changed for variable length votes I guess, TODO - $aweek = 60*60*24*7; if (isset($_REQUEST['id'])) { # Show application details @@ -48,7 +46,7 @@ if ($atype == "Trusted User" OR $atype == "Developer") { # Print out application details, thanks again AUR # - $isrunning = (($row['Submitted'] + $aweek) > time()) ? 1 : 0; + $isrunning = $row['End'] > time() ? 1 : 0; $qvoted = "SELECT * FROM TU_Votes WHERE "; $qvoted.= "VoteID = " . $row['ID'] . " AND "; @@ -98,6 +96,7 @@ if ($atype == "Trusted User" OR $atype == "Developer") { } } + # I think I understand why MVC is good for this stuff.. echo "
\n"; echo "
Proposal Details
\n"; echo "
\n"; @@ -119,9 +118,17 @@ if ($atype == "Trusted User" OR $atype == "Developer") { print "Submitted: " . gmdate("r", $row['Submitted']) . " by "; print "" . username_from_id($row['SubmitterID']) . "
\n"; - print "
\n"; - $row['Agenda'] = htmlentities($row['Agenda']); + if ($isrunning == 0) { + print "Ended: "; + } else { + print "Ends: "; + } + print "" . gmdate("r", $row['End']) . "
\n"; + + print "
\n"; + + $row['Agenda'] = htmlentities($row['Agenda']); # str_replace seems better than
 because it still maintains word wrapping
 				print str_replace("\n", "
\n", $row['Agenda']); @@ -224,9 +231,8 @@ if ($atype == "Trusted User" OR $atype == "Developer") { function gen_results($offset, $limit, $sort, $by, $type="normal") { $dbh = db_connect(); - $aweek = 60*60*24*7; - if (!empty($offset) AND is_numeric($offset)) { + if (!empty($offset) AND is_numeric($offset)) { if ($offset >= 1) { $off = $offset; } else { @@ -236,16 +242,16 @@ if ($atype == "Trusted User" OR $atype == "Developer") { $off = 0; } - $q = "SELECT * FROM TU_VoteInfo"; - if ($type == "new") { - $q.= " WHERE Submitted + " . $aweek . " > " . time(); - $application = "Current Votes"; - } else { - $q.= " WHERE Submitted + " . $aweek . " < " . time(); - $application = "Old Votes"; - } + $q = "SELECT * FROM TU_VoteInfo"; - $order = ($by == 'down') ? 'DESC' : 'ASC'; + if ($type == "new") { + $q.= " WHERE End > " . time(); + $application = "Current Votes"; + } else { + $application = "All Votes"; + } + + $order = ($by == 'down') ? 'DESC' : 'ASC'; # not much to sort, I'm unsure how to sort by username # when we only store the userid, someone come up with a nifty @@ -262,7 +268,7 @@ if ($atype == "Trusted User" OR $atype == "Developer") { if ($limit != 0) { $q.= " LIMIT " . $off . ", ". $limit; - } + } $result = db_query($q, $dbh); @@ -288,9 +294,13 @@ if ($atype == "Trusted User" OR $atype == "Developer") { print " bottom'>"; print "Proposal"; print "\n"; + print " "; + print "Start"; + print "\n"; print " "; - print "Submitted"; + print "End"; print "\n"; print " "; @@ -320,59 +330,70 @@ if ($atype == "Trusted User" OR $atype == "Developer") { } else { for ($i = 0; $row = mysql_fetch_assoc($result); $i++) { # Thankyou AUR - (($i % 2) == 0) ? $c = "data1" : $c = "data2"; - print "\n"; - print " "; - - $prev_Len = 100; - - if (strlen($row["Agenda"]) >= $prev_Len) { - $row["Agenda"] = htmlentities(substr($row["Agenda"], 0, $prev_Len)) . "..."; - } else { - $row["Agenda"] = htmlentities($row["Agenda"]); - } - - print $row["Agenda"]; - print " [More]"; - print "\n"; - print " "; - print gmdate("r", intval($row["Submitted"])); - print "\n"; - print " "; - - if (!empty($row['User'])) { - print ""; - print $row['User'] . ""; - } else { - print "N/A"; - } - print "\n"; + # alright, I'm going to just have a "new" table and the + # "old" table can just have every vote, works just as well + # and probably saves on doing some crap + # + + (($i % 2) == 0) ? $c = "data1" : $c = "data2"; + print "\n"; + print " "; + + $prev_Len = 100; + + if (strlen($row["Agenda"]) >= $prev_Len) { + $row["Agenda"] = htmlentities(substr($row["Agenda"], 0, $prev_Len)) . "... -"; + } else { + $row["Agenda"] = htmlentities($row["Agenda"]) . " -"; + } + + print $row["Agenda"]; + print " [More]"; + print "\n"; + print " "; + # why does the AUR use gmdate with formatting that includes the offset + # to GMT?! + print gmdate("j M y", $row["Submitted"]); + print "\n"; + print " "; + print gmdate("j M y", $row["End"]); + print "\n"; + print " "; + + if (!empty($row['User'])) { + print ""; + print $row['User'] . ""; + } else { + print "N/A"; + } + + print "\n"; print " "; print $row['Yes']; print "\n"; print " "; print $row['No']; print "\n"; - print " "; - # See above + print " "; + # See above # print $row['Abstain']; # print "\n"; # print " "; - $qvoted = "SELECT * FROM TU_Votes WHERE "; + $qvoted = "SELECT * FROM TU_Votes WHERE "; $qvoted.= "VoteID = " . $row['ID'] . " AND "; $qvoted.= "UserID = " . uid_from_sid($_COOKIE["AURSID"]); - $hasvoted = mysql_num_rows(db_query($qvoted, $dbh)); + $hasvoted = mysql_num_rows(db_query($qvoted, $dbh)); - if ($hasvoted == 0) { - print "No"; - } else { - print "Yes"; - } + if ($hasvoted == 0) { + print "No"; + } else { + print "Yes"; + } print "\n"; - print "\n"; + print "\n"; } } -- cgit v1.2.3-70-g09d2