mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Add support for variable length votes in voting application
Signed-off-by: Callan Barrett <wizzomafizzo@gmail.com>
This commit is contained in:
parent
a8e574ef28
commit
5f4afcc8cb
3 changed files with 101 additions and 63 deletions
|
@ -217,6 +217,7 @@ CREATE TABLE IF NOT EXISTS TU_VoteInfo (
|
||||||
Agenda text collate latin1_general_ci NOT NULL,
|
Agenda text collate latin1_general_ci NOT NULL,
|
||||||
User char(32) collate latin1_general_ci NOT NULL,
|
User char(32) collate latin1_general_ci NOT NULL,
|
||||||
Submitted bigint(20) unsigned NOT NULL,
|
Submitted bigint(20) unsigned NOT NULL,
|
||||||
|
End bigint(20) unsigned NOT NULL,
|
||||||
SubmitterID int(10) unsigned NOT NULL,
|
SubmitterID int(10) unsigned NOT NULL,
|
||||||
Yes tinyint(3) unsigned NOT NULL default '0',
|
Yes tinyint(3) unsigned NOT NULL default '0',
|
||||||
No tinyint(3) unsigned NOT NULL default '0',
|
No tinyint(3) unsigned NOT NULL default '0',
|
||||||
|
|
|
@ -18,36 +18,48 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
$dbh = db_connect();
|
$dbh = db_connect();
|
||||||
|
|
||||||
if (!empty($_POST['addVote'])) {
|
if (!empty($_POST['addVote'])) {
|
||||||
$aweek = 60*60*24*7;
|
|
||||||
$error = "";
|
$error = "";
|
||||||
|
|
||||||
if (!empty($_REQUEST['user'])) {
|
if (!empty($_POST['user'])) {
|
||||||
$qcheck = "SELECT * FROM Users WHERE Username = '" . mysql_real_escape_string($_REQUEST['user']) . "'";
|
$qcheck = "SELECT * FROM Users WHERE Username = '" . mysql_real_escape_string($_POST['user']) . "'";
|
||||||
$check = mysql_num_rows(db_query($qcheck, $dbh));
|
$check = mysql_num_rows(db_query($qcheck, $dbh));
|
||||||
|
|
||||||
if ($check == 0) {
|
if ($check == 0) {
|
||||||
$error.= "<div style='color: red; font-weight: bold'>Username does not exist.</div>";
|
$error.= "<div style='color: red; font-weight: bold'>Username does not exist.</div>";
|
||||||
} else {
|
} else {
|
||||||
$qcheck = "SELECT * FROM TU_VoteInfo WHERE User = '" . mysql_real_escape_string($_REQUEST['user']) . "'";
|
$qcheck = "SELECT * FROM TU_VoteInfo WHERE User = '" . mysql_real_escape_string($_POST['user']) . "'";
|
||||||
$qcheck.= " AND Submitted + " . $aweek . " > UNIX_TIMESTAMP()";
|
$qcheck.= " AND End > UNIX_TIMESTAMP()";
|
||||||
$check = mysql_num_rows(db_query($qcheck, $dbh));
|
$check = mysql_num_rows(db_query($qcheck, $dbh));
|
||||||
|
|
||||||
if ($check != 0) {
|
if ($check != 0) {
|
||||||
$error.= "<div style='color: red; font-weight: bold'>" . mysql_real_escape_string($_REQUEST['user']) . " already has proposal running for them.</div>";
|
$error.= "<div style='color: red; font-weight: bold'>" . htmlentities($_POST['user']) . " already has proposal running for them.</div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($_REQUEST['agenda'])) {
|
if (!empty($_POST['length'])) {
|
||||||
|
if (!is_numeric($_POST['length'])) {
|
||||||
|
$error.= "<div style='color: red; font-weight: bold'>Length must be a number.</div>";
|
||||||
|
} else if ($_POST['length'] < 1) {
|
||||||
|
$error.= "<div style='color: red; font-weight: bold'>Length must be at least 1.</div>";
|
||||||
|
} else {
|
||||||
|
$len = (60*60*24)*$_POST['length'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$len = 60*60*24*7;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($_POST['agenda'])) {
|
||||||
$error.= "<div style='color: red; font-weight: bold'>Proposal cannot be empty.</div>";
|
$error.= "<div style='color: red; font-weight: bold'>Proposal cannot be empty.</div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_POST['addVote']) && empty($error)) {
|
if (!empty($_POST['addVote']) && empty($error)) {
|
||||||
$q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, SubmitterID) VALUES ";
|
$q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, SubmitterID) VALUES ";
|
||||||
$q.= "('" . mysql_real_escape_string($_REQUEST['agenda']) . "', ";
|
$q.= "('" . mysql_real_escape_string($_POST['agenda']) . "', ";
|
||||||
$q.= "'" . mysql_real_escape_string($_REQUEST['user']) . "', ";
|
$q.= "'" . mysql_real_escape_string($_POST['user']) . "', ";
|
||||||
$q.= "UNIX_TIMESTAMP(), " . uid_from_sid($_COOKIE["AURSID"]) . ")";
|
$q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . mysql_real_escape_string($len);
|
||||||
|
$q.= ", " . uid_from_sid($_COOKIE["AURSID"]) . ")";
|
||||||
|
|
||||||
db_query($q, $dbh);
|
db_query($q, $dbh);
|
||||||
print "<p>New proposal submitted.</p>\n";
|
print "<p>New proposal submitted.</p>\n";
|
||||||
|
@ -60,6 +72,10 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
<input type='text' name='user' value='<?php if (!empty($_POST['user'])) { print htmlentities($_POST['user'], ENT_QUOTES); } ?>'>
|
<input type='text' name='user' value='<?php if (!empty($_POST['user'])) { print htmlentities($_POST['user'], ENT_QUOTES); } ?>'>
|
||||||
(empty if not applicable)
|
(empty if not applicable)
|
||||||
<br />
|
<br />
|
||||||
|
<b>Length in days:</b>
|
||||||
|
<input type='text' name='length' value='<?php if (!empty($_POST['length'])) { print htmlentities($_POST['length'], ENT_QUOTES); } ?>'>
|
||||||
|
(defaults to 7 if empty)
|
||||||
|
<br />
|
||||||
<b>Proposal:</b><br />
|
<b>Proposal:</b><br />
|
||||||
<textarea name='agenda' rows='10' cols='50'><?php if (!empty($_POST['agenda'])) { print htmlentities($_POST['agenda']); } ?></textarea><br />
|
<textarea name='agenda' rows='10' cols='50'><?php if (!empty($_POST['agenda'])) { print htmlentities($_POST['agenda']); } ?></textarea><br />
|
||||||
<input type='hidden' name='addVote' value='1'>
|
<input type='hidden' name='addVote' value='1'>
|
||||||
|
|
|
@ -24,8 +24,6 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
|
|
||||||
# Temp value for results per page
|
# Temp value for results per page
|
||||||
$pp = 5;
|
$pp = 5;
|
||||||
# This needs to be changed for variable length votes I guess, TODO
|
|
||||||
$aweek = 60*60*24*7;
|
|
||||||
|
|
||||||
if (isset($_REQUEST['id'])) {
|
if (isset($_REQUEST['id'])) {
|
||||||
# Show application details
|
# Show application details
|
||||||
|
@ -48,7 +46,7 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
# Print out application details, thanks again AUR
|
# 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 = "SELECT * FROM TU_Votes WHERE ";
|
||||||
$qvoted.= "VoteID = " . $row['ID'] . " AND ";
|
$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 "<div class=\"pgbox\">\n";
|
echo "<div class=\"pgbox\">\n";
|
||||||
echo " <div class=\"pgboxtitle\"><span class=\"f3\">Proposal Details</span></div>\n";
|
echo " <div class=\"pgboxtitle\"><span class=\"f3\">Proposal Details</span></div>\n";
|
||||||
echo " <div class=\"pgboxbody\">\n";
|
echo " <div class=\"pgboxbody\">\n";
|
||||||
|
@ -119,6 +118,14 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
|
|
||||||
print "Submitted: <b>" . gmdate("r", $row['Submitted']) . "</b> by ";
|
print "Submitted: <b>" . gmdate("r", $row['Submitted']) . "</b> by ";
|
||||||
print "<b>" . username_from_id($row['SubmitterID']) . "</b><br />\n";
|
print "<b>" . username_from_id($row['SubmitterID']) . "</b><br />\n";
|
||||||
|
|
||||||
|
if ($isrunning == 0) {
|
||||||
|
print "Ended: ";
|
||||||
|
} else {
|
||||||
|
print "Ends: ";
|
||||||
|
}
|
||||||
|
print "<b>" . gmdate("r", $row['End']) . "</b><br />\n";
|
||||||
|
|
||||||
print "<br />\n";
|
print "<br />\n";
|
||||||
|
|
||||||
$row['Agenda'] = htmlentities($row['Agenda']);
|
$row['Agenda'] = htmlentities($row['Agenda']);
|
||||||
|
@ -224,7 +231,6 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
function gen_results($offset, $limit, $sort, $by, $type="normal") {
|
function gen_results($offset, $limit, $sort, $by, $type="normal") {
|
||||||
|
|
||||||
$dbh = db_connect();
|
$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) {
|
if ($offset >= 1) {
|
||||||
|
@ -237,12 +243,12 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "SELECT * FROM TU_VoteInfo";
|
$q = "SELECT * FROM TU_VoteInfo";
|
||||||
|
|
||||||
if ($type == "new") {
|
if ($type == "new") {
|
||||||
$q.= " WHERE Submitted + " . $aweek . " > " . time();
|
$q.= " WHERE End > " . time();
|
||||||
$application = "Current Votes";
|
$application = "Current Votes";
|
||||||
} else {
|
} else {
|
||||||
$q.= " WHERE Submitted + " . $aweek . " < " . time();
|
$application = "All Votes";
|
||||||
$application = "Old Votes";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = ($by == 'down') ? 'DESC' : 'ASC';
|
$order = ($by == 'down') ? 'DESC' : 'ASC';
|
||||||
|
@ -290,7 +296,11 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
print "</span></th>\n";
|
print "</span></th>\n";
|
||||||
print " <th style='border-bottom: #666 1px solid; vertical-align:";
|
print " <th style='border-bottom: #666 1px solid; vertical-align:";
|
||||||
print " bottom'><span class='f2'>";
|
print " bottom'><span class='f2'>";
|
||||||
print "<a href='?off=$off&sort=sub&by=$by_next'>Submitted</a>";
|
print "<a href='?off=$off&sort=sub&by=$by_next'>Start</a>";
|
||||||
|
print "</span></th>\n";
|
||||||
|
print " <th style='border-bottom: #666 1px solid; vertical-align:";
|
||||||
|
print " bottom'><span class='f2'>";
|
||||||
|
print "End";
|
||||||
print "</span></th>\n";
|
print "</span></th>\n";
|
||||||
print " <th style='border-bottom: #666 1px solid; vertical-align:";
|
print " <th style='border-bottom: #666 1px solid; vertical-align:";
|
||||||
print " bottom'><span class='f2'>";
|
print " bottom'><span class='f2'>";
|
||||||
|
@ -320,6 +330,12 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
} else {
|
} else {
|
||||||
for ($i = 0; $row = mysql_fetch_assoc($result); $i++) {
|
for ($i = 0; $row = mysql_fetch_assoc($result); $i++) {
|
||||||
# Thankyou AUR
|
# Thankyou AUR
|
||||||
|
|
||||||
|
# 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";
|
(($i % 2) == 0) ? $c = "data1" : $c = "data2";
|
||||||
print "<tr>\n";
|
print "<tr>\n";
|
||||||
print " <td class='".$c."'><span class='f4'><span class='blue'>";
|
print " <td class='".$c."'><span class='f4'><span class='blue'>";
|
||||||
|
@ -327,16 +343,21 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
|
||||||
$prev_Len = 100;
|
$prev_Len = 100;
|
||||||
|
|
||||||
if (strlen($row["Agenda"]) >= $prev_Len) {
|
if (strlen($row["Agenda"]) >= $prev_Len) {
|
||||||
$row["Agenda"] = htmlentities(substr($row["Agenda"], 0, $prev_Len)) . "...";
|
$row["Agenda"] = htmlentities(substr($row["Agenda"], 0, $prev_Len)) . "... -";
|
||||||
} else {
|
} else {
|
||||||
$row["Agenda"] = htmlentities($row["Agenda"]);
|
$row["Agenda"] = htmlentities($row["Agenda"]) . " -";
|
||||||
}
|
}
|
||||||
|
|
||||||
print $row["Agenda"];
|
print $row["Agenda"];
|
||||||
print " <a href='/tu.php?id=" . $row['ID'] . "'>[More]</a>";
|
print " <a href='/tu.php?id=" . $row['ID'] . "'>[More]</a>";
|
||||||
print "</span></span></td>\n";
|
print "</span></span></td>\n";
|
||||||
print " <td class='".$c."'><span class='f5'><span class='blue'>";
|
print " <td class='".$c."'><span class='f5'><span class='blue'>";
|
||||||
print gmdate("r", intval($row["Submitted"]));
|
# why does the AUR use gmdate with formatting that includes the offset
|
||||||
|
# to GMT?!
|
||||||
|
print gmdate("j M y", $row["Submitted"]);
|
||||||
|
print "</span></span></td>\n";
|
||||||
|
print " <td class='".$c."'><span class='f5'><span class='blue'>";
|
||||||
|
print gmdate("j M y", $row["End"]);
|
||||||
print "</span></span></td>\n";
|
print "</span></span></td>\n";
|
||||||
print " <td class='".$c."'><span class='f6'><span class='blue'>";
|
print " <td class='".$c."'><span class='f6'><span class='blue'>";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue