From 34c8a9cf80fa857f8024eacd65292cd015673165 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Mon, 6 Oct 2008 06:09:06 +0800 Subject: Major rearrangement of tu.php, strings setup for translation All the strings are set up to be translated now, HTML of tu.php has been moved to templates and the worst of it rewritten (there's no longer a massive function in it) Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/tu.php | 438 +++++++++----------------------------------------------- 1 file changed, 70 insertions(+), 368 deletions(-) (limited to 'web/html/tu.php') diff --git a/web/html/tu.php b/web/html/tu.php index 524e14d..e2e44b7 100644 --- a/web/html/tu.php +++ b/web/html/tu.php @@ -8,44 +8,30 @@ set_lang(); check_sid(); html_header(); -# get login privileges -# +# Default votes per page +$pp = 5; + +$atype = ""; if (isset($_COOKIE["AURSID"])) { - # Only logged in users can do stuff - # $atype = account_from_sid($_COOKIE["AURSID"]); -} else { - $atype = ""; } if ($atype == "Trusted User" OR $atype == "Developer") { - # Show the TU interface - # - - # Temp value for results per page $pp = 5; - if (isset($_REQUEST['id'])) { - # Show application details - # depending on action and time frame will show either - # sponsor button, comments and vote buttons - # - - if (intval($_REQUEST['id'])) { + if (isset($_GET['id'])) { + if (is_numeric($_GET['id'])) { $q = "SELECT * FROM TU_VoteInfo "; - $q.= "WHERE ID = " . $_REQUEST['id']; + $q.= "WHERE ID = " . $_GET['id']; $dbh = db_connect(); $results = db_query($q, $dbh); $row = mysql_fetch_assoc($results); if (empty($row)) { - print "Could not retrieve proposal details.\n"; + print __("Could not retrieve proposal details."); } else { - # Print out application details, thanks again AUR - # - $isrunning = $row['End'] > time() ? 1 : 0; $qvoted = "SELECT * FROM TU_Votes WHERE "; @@ -53,30 +39,27 @@ if ($atype == "Trusted User" OR $atype == "Developer") { $qvoted.= "UserID = " . uid_from_sid($_COOKIE["AURSID"]); $hasvoted = mysql_num_rows(db_query($qvoted, $dbh)); - # Can this person vote? - # - $canvote = 1; // we assume they can - $errorvote = ""; // error message to give + $canvote = 1; + $errorvote = ""; if ($isrunning == 0) { $canvote = 0; - $errorvote = "Voting is closed for this proposal."; + $errorvote = __("Voting is closed for this proposal."); } else if ($row['User'] == username_from_sid($_COOKIE["AURSID"])) { $canvote = 0; - $errorvote = "You cannot vote in an proposal regarding you."; + $errorvote = __("You cannot vote in an proposal about you."); } else if ($hasvoted != 0) { $canvote = 0; - $errorvote = "You've already voted in this proposal."; + $errorvote = __("You've already voted in this proposal."); } - # have to put this here so results are correct immediately after voting if ($canvote == 1) { if (isset($_POST['doVote'])) { if (isset($_POST['voteYes'])) { - $myvote = "Yes"; + $myvote = __("Yes"); } else if (isset($_POST['voteNo'])) { - $myvote = "No"; + $myvote = __("No"); } else if (isset($_POST['voteAbstain'])) { - $myvote = "Abstain"; + $myvote = __("Abstain"); } $qvote = "UPDATE TU_VoteInfo SET " . $myvote . " = " . ($row[$myvote] + 1) . " WHERE ID = " . $row['ID']; @@ -87,7 +70,7 @@ if ($atype == "Trusted User" OR $atype == "Developer") { # Can't vote anymore # $canvote = 0; - $errorvote = "You've already voted for this proposal."; + $errorvote = __("You've already voted for this proposal."); # Update if they voted $hasvoted = mysql_num_rows(db_query($qvoted, $dbh)); @@ -95,357 +78,76 @@ if ($atype == "Trusted User" OR $atype == "Developer") { $row = mysql_fetch_assoc($results); } } - - # I think I understand why MVC is good for this stuff.. - echo "
\n"; - echo "
Proposal Details
\n"; - echo "
\n"; - - if ($isrunning == 1) { - print "
This vote is still running.
"; - print "
"; - } - - print "User: "; - - if (!empty($row['User'])) { - print "" . $row['User'] . ""; - } else { - print "N/A"; - } - - print "
\n"; - - print "Submitted: " . gmdate("r", $row['Submitted']) . " by "; - print "" . username_from_id($row['SubmitterID']) . "
\n"; - - 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']); - - print "
\n"; - print "
\n"; - - print "
\n"; - print "\n"; - print "\n"; - print "\n"; - print "
\n"; - print "\n"; - - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print "\n"; - - $c = "data1"; - - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print "\n"; - - print "
"; - print "Yes"; - print ""; - print "No"; - print ""; - print "Abstain"; - print ""; - print "Total"; - print ""; - print "Voted?"; - print "
"; - print $row['Yes']; - print ""; - print $row['No']; - print ""; - print $row['Abstain']; - print ""; - print ($row['Yes'] + $row['No'] + $row['Abstain']); - print ""; - - if ($hasvoted == 0) { - print "No"; - } else { - print "Yes"; - } - - print "
\n"; - print "
\n"; - - echo "
\n"; - - # Actions, vote buttons - # - print "
\n"; - print "
\n"; - print "
Vote Actions
\n"; - print "
\n"; - - if ($canvote == 1) { - print "
\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "
\n"; - } else { - print "
$errorvote
"; - } - - print "
\n"; - print "
Back
\n"; - + include("tu_details.php"); } - } else { - print "Vote ID not valid.\n"; + print __("Vote ID not valid."); } } else { - # page listing applications being discussed, voted on and all those finished - # - - # I guess there should be a function since I use this a few times - function gen_results($offset, $limit, $sort, $by, $type="normal") { - - $dbh = db_connect(); - - if (!empty($offset) AND is_numeric($offset)) { - if ($offset >= 1) { - $off = $offset; - } else { - $off = 0; - } - } else { - $off = 0; - } - - $q = "SELECT * FROM TU_VoteInfo"; - - 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 - # way to do this - # - switch ($sort) { - case 'sub': - $q.= " ORDER BY Submitted $order"; - break; - default: - $q.= " ORDER BY Submitted $order"; - break; - } - - if ($limit != 0) { - $q.= " LIMIT " . $off . ", ". $limit; - } - - $result = db_query($q, $dbh); - - if ($by == "down") { - $by_next = "up"; - } else { - $by_next = "down"; - } - - print "
\n"; - print "\n"; - print "\n"; - print " \n"; - print "\n"; - print "\n"; - print "
\n"; - print " $application\n"; - print "
\n"; - print "\n"; - - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; -# I'm not sure if abstains are necessary inthis view, it's just extra clutter -# print " \n"; - print " \n"; - print "\n"; - - if (mysql_num_rows($result) == 0) { - print "\n"; - } else { - for ($i = 0; $row = mysql_fetch_assoc($result); $i++) { - # 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"; - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - # print " \n"; - print "\n"; - } - } + $dbh = db_connect(); - print "
"; - print "Proposal"; - print ""; - print "Start"; - print ""; - print "End"; - print ""; - print "User"; - print ""; - print "Yes"; - print ""; - print "No"; - print ""; -# print "Abstain"; -# print ""; - print "Voted?"; - print "
No results found.
"; - - $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 ""; - # why does the AUR use gmdate with formatting that includes the offset - # to GMT?! - print gmdate("j M y", $row["Submitted"]); - print ""; - print gmdate("j M y", $row["End"]); - print ""; - - if (!empty($row['User'])) { - print ""; - print $row['User'] . ""; - } else { - print "N/A"; - } - - print ""; - print $row['Yes']; - print ""; - print $row['No']; - print ""; - # See above - # print $row['Abstain']; - # print ""; - - $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)); - - if ($hasvoted == 0) { - print "No"; - } else { - print "Yes"; - } - - print "
\n"; - print "
\n"; + $offset = $_GET['off']; + $limit = $pp; + $by = $_GET['by']; - if ($type == "old" AND $limit != 0) { - $qnext = "SELECT ID FROM TU_VoteInfo"; - $nextresult = db_query($qnext, $dbh); + if (!empty($offset) AND is_numeric($offset)) { + if ($offset >= 1) { + $off = $offset; + } else { + $off = 0; + } + } else { + $off = 0; + } - print "\n"; + $order = ($by == 'down') ? 'DESC' : 'ASC'; + $lim = ($limit > 0) ? " LIMIT " . $off . ", " . $limit : ""; + $by_next = ($by == "down") ? "up" : "down"; - if (mysql_num_rows($result)) { - $sort = htmlentities($sort, ENT_QUOTES); - $by = htmlentities($by, ENT_QUOTES); + $prev_Len = 100; - print "\n"; - print "\n"; + $q = "SELECT * FROM TU_VoteInfo WHERE End > " . time() . " ORDER BY Submitted " . $order; + $result = db_query($q, $dbh); - print "\n"; - print "\n"; - } - print "
\n"; - if ($off != 0) { - $back = (($off - $limit) <= 0) ? 0 : $off - $limit; - print "Back"; - } - print "\n"; - if (($off + $limit) < mysql_num_rows($nextresult)) { - $forw = $off + $limit; - print "Next"; - } - print "
\n"; - } + $type = __("Current Votes"); + include("tu_list.php"); +?> - print "
\n"; - } +
+ +

- # stop notices, ythanku Xilon - if (empty($_REQUEST['sort'])) { $_REQUEST['sort'] = ""; } - if (empty($_REQUEST['by'])) { $_REQUEST['by'] = ""; } - if (empty($_REQUEST['off'])) { $_REQUEST['off'] = ""; } +Add
"; - gen_results($_REQUEST['off'], $pp, $_REQUEST['sort'], $_REQUEST['by'], "old"); + $type = __("All Votes"); + include("tu_list.php"); + $qnext = "SELECT ID FROM TU_VoteInfo"; + $nextresult = db_query($qnext, $dbh); +?> + + + + + + + +
+ + + + + + + +
+ -- cgit v1.2.3-70-g09d2