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/tu.php | 131 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 55 deletions(-) (limited to 'web/html/tu.php') 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-54-g00ecf