Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • osian/sucs-site
  • kais58/sucs-site
  • imranh/sucs-site
  • foshjedi2004/sucs-site
  • gigosaurus/sucs-site
  • matstn/sucs-site
  • ripp_/sucs-site
  • eggnog/sucs-site
  • sucssite/sucs-site
  • elbows/sucs-site
  • realitykiller/sucs-site
  • crox/sucs-site
  • vectre/sucs-site
  • welshbyte/sucs-site
  • paperclipman/sucs-site
15 results
Show changes
Commits on Source (361)
Showing with 612 additions and 595 deletions
# Some of the files that are generated by the setup script don't want to be version controlled.
# To that end I have added this .gitignore file to ignore the following files and folders
# This is the generated .htaccess
htdocs/.htaccess
# Generated settings.php file
settings.php
# Compiled templates_c
templates_c/
# Password file for the su-api thing
suapi.inc.php
# lastsnap.jpg from cam
htdocs/images/lastsnap.jpg
\ No newline at end of file
# specify what docker image
# go with the default image for now and mangle it
#image: debian:jessie
stages:
- test
- deploy
#before_script:
php-syntax-check:
stage: test
image: php:7.0-cli-jessie
script:
# - apt-get clean
# - apt-get update
# - apt-get install -y php-cli
- php -l htdocs/index.php
- find components -name *.php | xargs -n 1 php -l
- find plugins -name *.php | xargs -n 1 php -l
- find lib -name *.php | xargs -n 1 php -l
js-syntax-check:
stage: test
image:
name: node:16
#entrypoint: ["/bin/bash", "-c"]
script:
- npm install -g jshint
- find htdocs/js/ -name *.js ! -name jquery* | xargs -n 1 jshint --verbose
deploy-beta:
stage: deploy
script:
- apt update
- apt install -y curl
- curl https://beta.sucs.org/pull.php
only:
- beta
environment: beta
deploy-live:
stage: deploy
script:
- apt update
- apt install -y curl
- curl https://sucs.org/pull.php
only:
- sucs-site
environment: live
[submodule "htdocs/js/ckeditor"]
path = htdocs/js/ckeditor
url = git://github.com/ckeditor/ckeditor-releases.git
2008-01-29 - Version 0.3 "Logged Out"
Sessions now last a lot longer and are more secure to boot (chckens)
Library admin component allows adding books (chckens, eventually)
Bananas component shelved in favour of Members component for most things (chckens)
Fixes:
Don't list societies with no website in the societies website list (chckens)
Pastebin now redirects to url of pasted item to prevent confusion (chckens)
News article summary can now deal with new lines in the first paragraph (chckens)
2007-10-28 - Version 0.2 "Oktoberfest"
Options component now allows users to change their hackergotchi (aeternus)
Pastebin now lets you view a plaintext version of pastes (aeternus)
Simple password security checks added to hopefully prevent weak passwords (chckens)
Members page now displays this academic year's banana leaderboard (chckens)
2007-09-25 - Version 0.1 "Ferocious Freshers"
First actual version with a number, below are some recent changes:
New member options component!
- MAC registration, contact details editing (aeternus)
- Password changing (chckens)
- Groups display, hackergotchi display (dez)
Beginnings of generic error handling support (chckens)
Fixes:
Improved usability of ShortURI interface (patch from davea)
Layout tweaks to defend against long titles (dez)
Fix calculation for banana summaries on Member pages (chckens)
What's in these 'ere folders:
components/
PHP components of the site, each drives a separate element - e.g.
static content, the library, the help system, etc.
htdocs/
Where all served content is to be found:
css/
Cascading StyleSheets
files/
Files for download (e.g. Help examples)
images/
Images used by the site skin
js/
JavaScript
tinymce/
Placeholder dir for TinyMCE, which should not itself
be stored in SVN
pictures/
Images used in the content (e.g. /Help)
lib/
Custom libraries used by the site - e.g. session library
plugins/
Custom Smarty plugins used by the site - e.g. banana drawing
function
static/
Static content for the static content components (includes help)
fragments/
Any HTML fragments used to make up parts of pages (e.g.
secondary bars)
templates/
Smarty templates
templates_c/
Compiled Smarty templates - do not use this dir
# SUCS Site
[![build status](https://projects.sucs.org/ci/projects/2/status.png?ref=master)](https://projects.sucs.org/ci/projects/2?ref=master)
---
## Project Structure
<br>
| Directory | Description |
| --------- | ----------- |
| components | PHP components of the site, each drives a separate element - e.g. static content, the library, the help system, etc. |
| htdocs/css | Cascading StyleSheets |
| htdocs/files | Files for download (e.g. Help examples) |
| htdocs/images | Images used by the site skin |
| htdocs/js | JavaScript |
| htdocs/js/tinymce | Placeholder dir for TinyMCE, which should not itself be stored in SVN |
| htdocs/pictures | Images used in the content (e.g. /Help) |
| lib | Custom libraries used by the site - e.g. session library |
| plugins | Custom Smarty plugins used by the site - e.g. banana drawing function |
| static | Static content for the static content components (includes help) |
| static/fragments | Any HTML fragments used to make up parts of pages (e.g. secondary bars) |
| templates | Smarty templates |
| templates_c | Compiled Smarty templates - do not use this dir |
\ No newline at end of file
...@@ -8,35 +8,36 @@ $members = new Members; ...@@ -8,35 +8,36 @@ $members = new Members;
$banana_index = array_search("Bananas", $pathlist); $banana_index = array_search("Bananas", $pathlist);
if ((sizeof($pathlist) > $banana_index + 1) && (trim($pathlist[$banana_index + 1]) != "")) { if ((sizeof($pathlist) > $banana_index + 1) && (trim($pathlist[$banana_index + 1]) != "")) {
$mode = "detail"; $mode = "detail";
$who = $pathlist[$banana_index + 1]; $who = $pathlist[$banana_index + 1];
} else { } else {
// User wasn't looking for anything in particular, so bump them to the Members page // User wasn't looking for anything in particular, so bump them to the Members page
header("HTTP/1.1 301 Moved Permanently"); header("HTTP/1.1 301 Moved Permanently");
header("Location: https://$preferred_hostname$baseurl/Community/Members/"); header("Location: https://$preferred_hostname$baseurl/Community/Members/");
} }
/* redirect requests for members' bananas to Members component. Only serve banana info for non-members (e.g. LIS ;-)) */ /* redirect requests for members' bananas to Members component. Only serve banana info for non-members (e.g. LIS ;-)) */
if (count($members->memberView($who)) > 0) { if (count($members->memberView($who)) > 0) {
// this is actually a real member, so serve a redirect and let Members handle it // this is actually a real member, so serve a redirect and let Members handle it
header("HTTP/1.1 301 Moved Permanently"); header("HTTP/1.1 301 Moved Permanently");
header("Location: https://$preferred_hostname$baseurl/Community/Members/$who"); header("Location: https://$preferred_hostname$baseurl/Community/Members/$who");
} else { } else {
// banana admin bits // banana admin bits
if ($mode == "detail") { // Tell the banana library that the person/organisation/thing we're dealing with isn't a SUCS member
if ($session->loggedin) { $isnonmember = true;
include("../lib/banana-admin.php"); if ($mode == "detail") {
} if ($session->loggedin) {
} include("../lib/banana-admin.php");
// attempt to find some bananas for this name in the database }
$smarty->assign("awards",$DB->GetAll("SELECT *, date_trunc('second', whn) FROM awards WHERE username=? ORDER BY whn DESC", array($who))); }
// attempt to find some bananas for this name in the database
$smarty->assign("awards", $DB->GetAll("SELECT *, date_trunc('second', whn) FROM awards WHERE username=? ORDER BY whn DESC", array($who)));
} }
if (isset($who)) if (isset($who))
$smarty->assign('who', "$who"); $smarty->assign('who', "$who");
$smarty->assign('mode', "$mode"); $smarty->assign('mode', "$mode");
$smarty->assign('users', $users); $smarty->assign('users', $users);
...@@ -46,5 +47,4 @@ $smarty->assign('title', "Banana Awards"); ...@@ -46,5 +47,4 @@ $smarty->assign('title', "Banana Awards");
$smarty->assign('body', $result); $smarty->assign('body', $result);
?> ?>
<?php <?php
function listdir($mypath, $recurse, $summaries) { function listdir($mypath, $recurse, $summaries)
global $DB, $base; {
global $DB, $base;
$dirlist = @scandir($base."static".$mypath); $dirlist = @scandir($base . "static" . $mypath);
$output = array(); $output = array();
if (is_array($dirlist)) foreach($dirlist as $file) { if (is_array($dirlist)) foreach ($dirlist as $file) {
// Hide files starting with a . // Hide files starting with a .
if ($file[0]!=".") { if ($file[0] != ".") {
$element = array(); $element = array();
if (!is_dir($base."static".$mypath."/".$file)) { if (!is_dir($base . "static" . $mypath . "/" . $file)) {
$pagename = preg_replace("/\.txt/", "", $file); $pagename = preg_replace("/\.txt/", "", $file);
if ($summaries) $element['summary'] = $DB->GetOne("select summary from static where path=?", array($mypath."/".$pagename)); if ($summaries) $element['summary'] = $DB->GetOne("select summary from static where path=?", array($mypath . "/" . $pagename));
if ($pagename!=@$lastdir) $output[$pagename]=str_replace("_", " ", $element); if ($pagename != @$lastdir) $output[$pagename] = str_replace("_", " ", $element);
} else { } else {
if ($recurse) $element['file']=listdir($mypath."/".$file, $recurse, $summaries); if ($recurse) $element['file'] = listdir($mypath . "/" . $file, $recurse, $summaries);
if ($summaries) $element['summary'] = $DB->GetOne("select summary from static where path=?", array($mypath."/".$file)); if ($summaries) $element['summary'] = $DB->GetOne("select summary from static where path=?", array($mypath . "/" . $file));
$output[$file]=$element; $output[$file] = $element;
$lastdir=$file; $lastdir = $file;
} }
} }
} }
return $output; return $output;
} }
if ($path==$component['path']) { if ($path == $component['path']) {
$dirlist = listdir($component['path'], TRUE, TRUE); $dirlist = listdir($component['path'], TRUE, TRUE);
$smarty->assign('rootnode', $component['path']); $smarty->assign('rootnode', $component['path']);
$smarty->assign('dirlist', $dirlist); $smarty->assign('dirlist', $dirlist);
$output = $smarty->fetch('contents.tpl'); $output = $smarty->fetch('contents.tpl');
$smarty->assign('title', $pathlist[1]); $smarty->assign('title', $pathlist[1]);
$smarty->assign('body', $output); $smarty->assign('body', $output);
} else { } else {
include("static.php"); include("static.php");
if ($title!="File not found") { if ($title != "File not found") {
if (!is_dir($base."static".$path)) { if (!is_dir($base . "static" . $path)) {
$pos = strrpos($path, "/"); $pos = strrpos($path, "/");
$path = substr($path, 0, $pos); $path = substr($path, 0, $pos);
} }
$dirlist = listdir($path, FALSE, FALSE); $dirlist = listdir($path, FALSE, FALSE);
$smarty->assign('rootnode', $path); $smarty->assign('rootnode', $path);
$smarty->assign('data', $dirlist); $smarty->assign('data', $dirlist);
$smarty->assign('level', 0); $smarty->assign('level', 0);
if (!isset($_REQUEST['action'])) { if (!isset($_REQUEST['action'])) {
$output = $smarty->fetch('contents-loop.tpl'); $output = $smarty->fetch('contents-loop.tpl');
$smarty->assign("secondary", "<div class=\"cbb\"><h3>In this section</h3>".$output."</div>"); $smarty->assign("secondary", "<div class=\"cbb\"><h3>In this section</h3>" . $output . "</div>");
} }
} }
} }
?> ?>
<?php <?php
$output = "<pre>".print_r($session, true)."</pre>"; $output = "<pre>" . print_r($session, true) . "</pre>";
$smarty->assign("title", "Debug"); $smarty->assign("title", "Debug");
$smarty->assign("body", $output); $smarty->assign("body", $output);
?> ?>
<? <?php
exec("/usr/local/bin/shame.py -a", $Shame); exec("/usr/local/bin/shame.py -a", $Shame);
for ( $i=1 ; $i < (count($Shame) - 1); $i++) for ($i = 1; $i < (count($Shame) - 1); $i++) {
{ list($space, $place, $user, $size) = preg_split("/ +/", $Shame[$i]);
list($space, $place, $user, $size) = preg_split("/ +/", $Shame[$i]); if ($i <= 12) {
if ($i <= 12) $item[] = $user;
{ $slice[] = preg_replace('/M/', '', ${size});
$item[]=$user; } else {
$slice[]=preg_replace('/M/', '', ${size}); $otherSize += preg_replace('/M/', '', ${size});
} }
else { }
$otherSize += preg_replace('/M/', '', ${size});
}
}
// $itemName[]="Other"; // $itemName[]="Other";
// $sliceSize[]=$otherSize; // $sliceSize[]=$otherSize;
$slice = array_merge(array($otherSize),$slice); $slice = array_merge(array($otherSize), $slice);
$item = array_merge(array("Other"), $item); $item = array_merge(array("Other"), $item);
/* echo "<pre>"; /* echo "<pre>";
print_r($slice); print_r($slice);
print_r($item);*/ print_r($item);*/
include("../../lib/pieChart.php"); include("../../lib/pieChart.php");
piechart("Top 12 Users of disk space", $slice, $item, 1) piechart("Top 12 Users of disk space", $slice, $item, 1)
?> ?>
<? exec("/usr/local/bin/shame.py -a", $Shame); <?php exec("/usr/local/bin/shame.py -a", $Shame);
$max=10; //SET to number of users to display $max = 10; //SET to number of users to display
$smarty->assign('title',"The SUCS Hall of Shame"); $smarty->assign('title', "The SUCS Hall of Shame");
//$o="<div style='text-align: center;'><img src=\"/images/disk.graph.php\" alt=\"pie chart of top 12 disk users\"/></div>"; //$o="<div style='text-align: center;'><img src=\"/images/disk.graph.php\" alt=\"pie chart of top 12 disk users\"/></div>";
$o.="<table align=\"center\">\n"; $o .= "<table align=\"center\">\n";
$o.="\t<tr><th align=\"center\">User</th><th align=\"center\">Home Directory Size</th></tr>\n"; $o .= "\t<tr><th align=\"center\">User</th><th align=\"center\">Home Directory Size</th></tr>\n";
for ( $i=1 ; $i < 13 /*(count($Shame) - 1)*/; $i++) for ($i = 1; $i < 13 /*(count($Shame) - 1)*/; $i++) {
{ list($space, $place, $user, $size) = preg_split("/ +/", $Shame[$i]);
list($space, $place, $user, $size) = preg_split("/ +/", $Shame[$i]); if ($size > 0)
if ($size > 0) $o .= "\t<tr><td align=\"center\">$user</td><td align=\"center\">${size}B</td></tr>\n";
$o.="\t<tr><td align=\"center\">$user</td><td align=\"center\">${size}B</td></tr>\n"; }
} exec("df -m /home", $dfraw);
exec("df -m /home",$dfraw); $dfout = preg_split('/[ ]+/', $dfraw[1]);
$dfout = preg_split('/[ ]+/', $dfraw[1]); $o .= "\t<tr><td align=\"center\" colspan=\"2\">" . floor($dfout[2] / 1024) . "GB used of " . floor($dfout[1] / 1024) . "GB (" . floor($dfout[3] / 1024) . "GB available)</td></tr>\n";
$o.="\t<tr><td align=\"center\" colspan=\"2\">".floor($dfout[2]/1024)."GB used of ".floor($dfout[1]/1024). "GB (".floor($dfout[3]/1024)."GB available)</td></tr>\n"; $o .= "</table>\n";
$o.="</table>\n"; $o .= $Shame[count($Shame) - 1];
$o.=$Shame[count($Shame) - 1]; $o .= "<br />\n";
$o.="<br />\n"; //readfile("tail.html");
//readfile("tail.html"); $out = "<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>
$out="<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>
<script type=\"text/javascript\"> <script type=\"text/javascript\">
google.load(\"visualization\", \"1\", {packages:[\"corechart\"]}); google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});
google.setOnLoadCallback(drawChart); google.setOnLoadCallback(drawChart);
...@@ -26,26 +25,28 @@ ...@@ -26,26 +25,28 @@
var data = new google.visualization.DataTable(); var data = new google.visualization.DataTable();
data.addColumn('string', 'User'); data.addColumn('string', 'User');
data.addColumn('number', 'Megabytes in use'); data.addColumn('number', 'Megabytes in use');
data.addRows(".(count($Shame) - 1).");\n"; data.addRows(" . (count($Shame) - 1) . ");\n";
for( $i=0; $i<(count($Shame) - 3); $i++ ){ for ($i = 0; $i < (count($Shame) - 3); $i++) {
list($u,$d)=parseLine($Shame[$i+1]); list($u, $d) = parseLine($Shame[$i + 1]);
$out.="data.setValue(".($i+1).", 0, '".$u."');\n"; $out .= "data.setValue(" . ($i + 1) . ", 0, '" . $u . "');\n";
$out.="data.setValue(".($i+1).", 1,".$d.");\n"; $out .= "data.setValue(" . ($i + 1) . ", 1," . $d . ");\n";
} }
$others=0; $others = 0;
for ( $i=$max; $i<count($data); $i++ ) { for ($i = $max; $i < count($data); $i++) {
list($u,$d)=parseLine($Shame[$i+1]); list($u, $d) = parseLine($Shame[$i + 1]);
$others+=$d; $others += $d;
} }
$out.="data.setValue(0, 0, 'Free Space');\ndata.setValue(0,1,".$dfout[3]." );\n"; $out .= "data.setValue(0, 0, 'Free Space');\ndata.setValue(0,1," . $dfout[3] . " );\n";
$out.="\t\tvar chart = new google.visualization.PieChart(document.getElementById('chart_div')); $out .= "\t\tvar chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 500, height: 360, backgroundColor: 'none', is3D: true, title: 'Disk Usage',sliceVisibilityThreshold: 1/180}); chart.draw(data, {width: 500, height: 360, backgroundColor: 'none', is3D: true, title: 'Disk Usage',sliceVisibilityThreshold: 1/180});
} }
</script>"; </script>";
$out.="<div id='chart_div' align='center'></div>"; $out .= "<div id='chart_div' align='center'></div>";
$smarty->assign('body', ($out.$o)); $smarty->assign('body', ($out . $o));
function parseLine($l){ function parseLine($l)
$fields=explode("|",preg_filter("/[ ]+/","|",$l)); {
return array(trim($fields[2]),trim(str_replace("M","",$fields[3]))); $fields = explode("|", preg_filter("/[ ]+/", "|", $l));
return array(trim($fields[2]), trim(str_replace("M", "", $fields[3])));
} }
?> ?>
<?php <?php
$smarty->assign("election_year", ELECTION_YEAR); $smarty->assign("election_year", ELECTION_YEAR);
$smarty->assign("title", "Executive Election ".ELECTION_YEAR); $smarty->assign("title", "Executive Election " . ELECTION_YEAR);
function display_ballot() { function display_ballot()
global $DB, $smarty, $output; {
global $DB, $smarty, $output;
require_once("../lib/members.php");
$members = new Members; require_once("../lib/members.php");
$role = $DB->GetAll("SELECT post FROM election_candidates GROUP BY post"); $members = new Members;
$role = $DB->GetAll("SELECT post FROM election_candidates GROUP BY post");
foreach ($role as $post) {
$candidate[$post['post']] = $DB->GetAll("SELECT username, manifesto_link FROM election_candidates WHERE post=? ORDER BY username ASC", $post['post']); foreach ($role as $post) {
$candidate[$post['post']] = $DB->GetAll("SELECT username, manifesto_link FROM election_candidates WHERE post=? ORDER BY username ASC", $post['post']);
$i=0;
foreach ($candidate[$post['post']] as $person) { $i = 0;
$details = $members->memberView($person['username']); foreach ($candidate[$post['post']] as $person) {
$candidate[$post['post']][$i]['realname'] = $details[0]['cn']; $details = $members->memberView($person['username']);
if (empty($person['manifesto_link'])) $candidate[$post['post']][$i]['manifesto_link'] = ELECTION_NO_MANIFESTO; $candidate[$post['post']][$i]['realname'] = $details[0]['cn'];
$i++; if (empty($person['manifesto_link'])) $candidate[$post['post']][$i]['manifesto_link'] = ELECTION_NO_MANIFESTO;
} $i++;
} }
}
$smarty->assign("candidate", $candidate);
$output = $smarty->fetch('election-vote.tpl'); $smarty->assign("candidate", $candidate);
$output = $smarty->fetch('election-vote.tpl');
} }
if (!$session->loggedin) { if (!$session->loggedin) {
# You can't vote if you're not logged in! # You can't vote if you're not logged in!
trigger_error("You are not logged in.", E_USER_WARNING); trigger_error("You are not logged in.", E_USER_WARNING);
} else { } else {
# The election hasn't started yet # The election hasn't started yet
if (strtotime('now') < strtotime(ELECTION_START)) trigger_error("The polling station is not yet open. Voting begins on ".date('l jS F, Y \a\t H:i', strtotime(ELECTION_START))."."); if (strtotime('now') < strtotime(ELECTION_START)) trigger_error("The polling station is not yet open. Voting begins on " . date('l jS F, Y \a\t H:i', strtotime(ELECTION_START)) . ".");
# The election is over - display the results # The election is over - display the results
else if (strtotime('now') > strtotime(ELECTION_END)) { else if (strtotime('now') > strtotime(ELECTION_END)) {
require_once("../lib/members.php"); require_once("../lib/members.php");
$members = new Members; $members = new Members;
$role = $DB->GetAll("SELECT post FROM election_candidates GROUP BY post"); $role = $DB->GetAll("SELECT post FROM election_candidates GROUP BY post");
foreach ($role as $post) { foreach ($role as $post) {
$candidate[$post['post']] = $DB->GetAll("SELECT username, manifesto_link FROM election_candidates WHERE post=?", $post['post']); $candidate[$post['post']] = $DB->GetAll("SELECT username, manifesto_link FROM election_candidates WHERE post=?", $post['post']);
$i=0; $i = 0;
foreach ($candidate[$post['post']] as $person) { foreach ($candidate[$post['post']] as $person) {
$details = $members->memberView($person['username']); $details = $members->memberView($person['username']);
$candidate[$post['post']][$i]['realname'] = $details[0]['cn']; $candidate[$post['post']][$i]['realname'] = $details[0]['cn'];
if (empty($person['manifesto_link'])) $candidate[$post['post']][$i]['manifesto_link'] = ELECTION_NO_MANIFESTO; if (empty($person['manifesto_link'])) $candidate[$post['post']][$i]['manifesto_link'] = ELECTION_NO_MANIFESTO;
$candidate[$post['post']][$i]['votes'] = $DB->GetOne("SELECT count(username) FROM election_votes WHERE ".$post['post']."=?", array($person['username'])); $candidate[$post['post']][$i]['votes'] = $DB->GetOne("SELECT count(username) FROM election_votes WHERE " . $post['post'] . "=?", array($person['username']));
$i++; $i++;
} }
} }
$smarty->assign("candidate", $candidate); $smarty->assign("candidate", $candidate);
$output = $smarty->fetch('election-results.tpl'); $output = $smarty->fetch('election-results.tpl');
} else { } else {
# It's election time # It's election time
# Check the user hasn't already voted # Check the user hasn't already voted
$vote_details = $DB->GetRow("SELECT time, ipaddress FROM election_votes WHERE username=?", $session->username); $vote_details = $DB->GetRow("SELECT time, ipaddress FROM election_votes WHERE username=?", $session->username);
if (count($vote_details)>0) { if (count($vote_details) > 0) {
trigger_error("You already voted on ".date('l jS F, Y \a\t H:i', strtotime($vote_details['time']))." from IP address ".$vote_details['ipaddress'].".", E_USER_WARNING); trigger_error("You already voted on " . date('l jS F, Y \a\t H:i', strtotime($vote_details['time'])) . " from IP address " . $vote_details['ipaddress'] . ".", E_USER_WARNING);
$output = "<p>Please email the Returning Officer at <a href=\"mailto:vote@sucs.org\">vote@sucs.org</a> with any queries.</p>\n<p>Once polling has closed on ".date('l jS F, Y \a\t H:i', strtotime(ELECTION_END)).", the election results will be available on this page.</p>"; $output = "<p>Please email the Returning Officer at <a href=\"mailto:vote@sucs.org\">vote@sucs.org</a> with any queries.</p>\n<p>Once polling has closed on " . date('l jS F, Y \a\t H:i', strtotime(ELECTION_END)) . ", the election results will be available on this page.</p>";
} else { } else {
if ($_POST['submit']=="Cast Votes") { if ($_POST['submit'] == "Cast Votes") {
# We have a ballot paper to process # We have a ballot paper to process
$output = "<h2>Thank you for your vote</h2>\n<p>You will shortly receive an email confirming your vote.</p>\n<p>Once polling has closed on ".date('l jS F, Y \a\t H:i', strtotime(ELECTION_END)).", the election results will be available on this page.</p>"; $output = "<h2>Thank you for your vote</h2>\n<p>You will shortly receive an email confirming your vote.</p>\n<p>Once polling has closed on " . date('l jS F, Y \a\t H:i', strtotime(ELECTION_END)) . ", the election results will be available on this page.</p>";
# Establish which positions are contested # Establish which positions are contested
$role = $DB->GetCol("SELECT post FROM election_candidates GROUP BY post HAVING count(username) > 1"); $role = $DB->GetCol("SELECT post FROM election_candidates GROUP BY post HAVING count(username) > 1");
$fail = FALSE; $fail = FALSE;
$invalid_candidate = FALSE; $invalid_candidate = FALSE;
$abstain_count = 0; $abstain_count = 0;
foreach ($role as $post) { foreach ($role as $post) {
if ($_POST[$post] == "abstain") $abstain_count++; if ($_POST[$post] == "abstain") $abstain_count++;
# check that we have a valid option selected # check that we have a valid option selected
if (!($DB->GetOne("SELECT username FROM election_candidates WHERE post=? AND username=?", array($post, $_POST[$post])) || $_POST[$post]=="abstain")) $fail = TRUE; if (!($DB->GetOne("SELECT username FROM election_candidates WHERE post=? AND username=?", array($post, $_POST[$post])) || $_POST[$post] == "abstain")) $fail = TRUE;
} }
# Check their password first # Check their password first
if ($session->check_pass($session->username, $_POST['vote_passwd'])) { if ($session->check_pass($session->username, $_POST['vote_passwd'])) {
if ($fail) { if ($fail) {
# Either no option or an invalid candidate was supplied # Either no option or an invalid candidate was supplied
trigger_error("An invalid option was selected in at least one ballot. Please try again.", E_USER_WARNING); trigger_error("An invalid option was selected in at least one ballot. Please try again.", E_USER_WARNING);
display_ballot(); display_ballot();
} else { } else {
# User has abstained in all votes # User has abstained in all votes
if ($abstain_count == count($role)) { if ($abstain_count == count($role)) {
trigger_error("You have not selected any candidates in any ballots.", E_USER_WARNING); trigger_error("You have not selected any candidates in any ballots.", E_USER_WARNING);
display_ballot(); display_ballot();
} else { } else {
# The input is valid - record the vote # The input is valid - record the vote
$vote = array( $vote = array(
'username' => $session->username, 'username' => $session->username,
'time' => 'now', 'time' => 'now',
'ipaddress' => $_SERVER['REMOTE_ADDR']); 'ipaddress' => $_SERVER['REMOTE_ADDR']);
# Email the Returning Officer # Email the Returning Officer
$ro_message = "User: ".$vote['username']."\nIP: ".$vote['ipaddress']."\n\n"; $ro_message = "User: " . $vote['username'] . "\nIP: " . $vote['ipaddress'] . "\n\n";
# Email the voter with confirmation # Email the voter with confirmation
$voter_message = "Thank you for voting in the SUCS election this year. Here are the votes you cast:\n\n"; $voter_message = "Thank you for voting in the SUCS election this year. Here are the votes you cast:\n\n";
foreach ($role as $post) { foreach ($role as $post) {
# Don't add votes up as we go # Don't add votes up as we go
# $DB->Execute("UPDATE election_candidates SET votes=votes+1 WHERE post=? AND username=?", array($post, $_POST[$post])); # $DB->Execute("UPDATE election_candidates SET votes=votes+1 WHERE post=? AND username=?", array($post, $_POST[$post]));
$vote[$post] = $_POST[$post]; $vote[$post] = $_POST[$post];
$ro_message .= ucfirst($post).": ".$_POST[$post]."\n"; $ro_message .= ucfirst($post) . ": " . $_POST[$post] . "\n";
$voter_message .= ucfirst($post).": ".$_POST[$post]."\n"; $voter_message .= ucfirst($post) . ": " . $_POST[$post] . "\n";
} }
$voter_message .= "\nResults of the election will be announced on ".date('l jS F, Y \a\t H:i', strtotime(ELECTION_END))." at http://sucs.org/Vote\n"; $voter_message .= "\nResults of the election will be announced on " . date('l jS F, Y \a\t H:i', strtotime(ELECTION_END)) . " at http://sucs.org/Vote\n";
$DB->AutoExecute("election_votes", $vote, 'INSERT'); $DB->AutoExecute("election_votes", $vote, 'INSERT');
mail("SUCS Returning Officer <vote@sucs.org>", "[SUCS Election] Vote received from ".$vote['username'], $ro_message, "From: SUCS Election ".ELECTION_YEAR." <vote@sucs.org>"); mail("SUCS Returning Officer <vote@sucs.org>", "[SUCS Election] Vote received from " . $vote['username'], $ro_message, "From: SUCS Election " . ELECTION_YEAR . " <vote@sucs.org>");
mail($session->fullname." <".$session->username."@sucs.org>", "[SUCS Election] Thanks For Voting", $voter_message, "From: SUCS Election ".ELECTION_YEAR." <vote@sucs.org>"); mail($session->fullname . " <" . $session->username . "@sucs.org>", "[SUCS Election] Thanks For Voting", $voter_message, "From: SUCS Election " . ELECTION_YEAR . " <vote@sucs.org>");
} }
} }
} else { } else {
display_ballot(); display_ballot();
} }
} else { } else {
# Display the ballot paper # Display the ballot paper
display_ballot(); display_ballot();
} }
} }
} }
} }
$smarty->assign("body", $output); $smarty->assign("body", $output);
......
<?php <?php
if (strtotime('now') > strtotime(ELECTION_START) && strtotime('now') < strtotime(ELECTION_END) && !$DB->GetOne("SELECT username FROM election_votes where username=?", $session->username)) { if (strtotime('now') > strtotime(ELECTION_START) && strtotime('now') < strtotime(ELECTION_END) && !$DB->GetOne("SELECT username FROM election_votes where username=?", $session->username)) {
$messages['info'][] = "<strong>You haven't voted yet</strong><br />\nThe SUCS Executive Election is in progress. <a href=\"/Vote\">Vote now!</a>\n"; $messages['info'][] = "<strong>You haven't voted yet</strong><br />\nThe SUCS Executive Election is in progress. <a href=\"/Vote\">Vote now!</a>\n";
} }
......
...@@ -2,56 +2,56 @@ ...@@ -2,56 +2,56 @@
$body = ""; $body = "";
$email_to = "joinus@sucs.org"; $email_to = "joinus@sucs.org";
$_REQUEST['email'] = str_replace("\n", "", $_REQUEST['email']); $_REQUEST['email'] = str_replace("\n", "", $_REQUEST['email']);
$headers = "From: ".$_REQUEST['email']."\n"."Reply-to: ".$_REQUEST['email']; $headers = "From: " . $_REQUEST['email'] . "\n" . "Reply-to: " . $_REQUEST['email'];
$subject = "Join request for user ".$_REQUEST['uname']; $subject = "Join request for user " . $_REQUEST['uname'];
// Perform data integrity checks // Perform data integrity checks
// Full name // Full name
if (preg_match("/[^\p{L}- ]/iu", $_REQUEST['realname'])) { if (preg_match("/[^\p{L}- ]/iu", $_REQUEST['realname'])) {
$body .= "<p>That's a suspiciously unusual-looking name, <strong>" . htmlentities($_REQUEST['realname']) . "</strong>.</p>\n"; $body .= "<p>That's a suspiciously unusual-looking name, <strong>" . htmlentities($_REQUEST['realname']) . "</strong>.</p>\n";
$body .= "<p>Please click <em>Back</em> and correct it.</p>\n"; $body .= "<p>Please click <em>Back</em> and correct it.</p>\n";
} else { } else {
// Student number // Student number
if (!is_numeric($_REQUEST['student_number']) || strlen($_REQUEST['student_number']) <> 6) { if (!is_numeric($_REQUEST['student_number']) || strlen($_REQUEST['student_number']) <> 6) {
$body .= "<p>The student number <strong>" . htmlentities($_REQUEST['student_number']) . "</strong> appears not to be valid.</p>\n"; $body .= "<p>The student number <strong>" . htmlentities($_REQUEST['student_number']) . "</strong> appears not to be valid.</p>\n";
$body .= "<p>Please click <em>Back</em> and correct it.</p>\n"; $body .= "<p>Please click <em>Back</em> and correct it.</p>\n";
} else { } else {
// Email address // Email address
list($username, $maildomain) = preg_split("/@/", $_REQUEST['email']); list($username, $maildomain) = preg_split("/@/", $_REQUEST['email']);
if (!checkdnsrr($maildomain, "MX") && !checkdnsrr($maildomain)) { if (!checkdnsrr($maildomain, "MX") && !checkdnsrr($maildomain)) {
$body .= "<p>The email address <strong>" . htmlentities($_REQUEST['email']) . "</strong> appears not to be valid.</p>\n"; $body .= "<p>The email address <strong>" . htmlentities($_REQUEST['email']) . "</strong> appears not to be valid.</p>\n";
$body .= "<p>Please click <em>Back</em> and correct it.</p>\n"; $body .= "<p>Please click <em>Back</em> and correct it.</p>\n";
} else { } else {
// Username // Username
// This test is rather inadequate. Needs improving // This test is rather inadequate. Needs improving
if (!preg_match("/^[a-z0-9_]*$/i", $_REQUEST['uname'])) { if (!preg_match("/^[a-z0-9_]*$/i", $_REQUEST['uname'])) {
$body .= "<p>Usernames can only contain letters, numbers and underscores(_).</p>\n"; $body .= "<p>Usernames can only contain letters, numbers and underscores(_).</p>\n";
$body .= "<p>Please click <em>Back</em> and choose a different one.</p>\n"; $body .= "<p>Please click <em>Back</em> and choose a different one.</p>\n";
} else { } else {
// We're good to go // We're good to go
$address = "http"; $address = "http";
if ($_SERVER['HTTPS']) $address .= "s"; if ($_SERVER['HTTPS']) $address .= "s";
$address .= "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ; $address .= "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$email_body = "This email was automatically created by the SUCS Website.\n\n"; $email_body = "This email was automatically created by the SUCS Website.\n\n";
$email_body .= "It was created by " . $address . "\n"; $email_body .= "It was created by " . $address . "\n";
$email_body .= "from IP " . $_SERVER['REMOTE_ADDR'] . " on " . date("r") . "\n\n"; $email_body .= "from IP " . $_SERVER['REMOTE_ADDR'] . " on " . date("r") . "\n\n";
$email_body .= "The details of the request are as follows:\n\n"; $email_body .= "The details of the request are as follows:\n\n";
$email_body .= " Real name ............ {$_REQUEST['realname']}\n"; $email_body .= " Real name ............ {$_REQUEST['realname']}\n";
$email_body .= " Student number ....... {$_REQUEST['student_number']}\n"; $email_body .= " Student number ....... {$_REQUEST['student_number']}\n";
$email_body .= " Email address ........ {$_REQUEST['email']}\n"; $email_body .= " Email address ........ {$_REQUEST['email']}\n";
$email_body .= " Requested username ... {$_REQUEST['uname']}\n\n"; $email_body .= " Requested username ... {$_REQUEST['uname']}\n\n";
$email_body .= "Please reply to this email, providing the user with details of\n"; $email_body .= "Please reply to this email, providing the user with details of\n";
$email_body .= "how to join.\n\n"; $email_body .= "how to join.\n\n";
$email_body .= "-- \nSUCS Website\n"; $email_body .= "-- \nSUCS Website\n";
mail($email_to, $subject, $email_body, $headers); mail($email_to, $subject, $email_body, $headers);
$body .= "<p>Thank you for your request to join SUCS.</p>"; $body .= "<p>Thank you for your request to join SUCS.</p>";
$body .= "<p>Someone from our admin team will email you shortly.</p>"; $body .= "<p>Someone from our admin team will email you shortly.</p>";
} // username } // username
} // email } // email
} // student number } // student number
} // full name } // full name
$smarty->assign("body", $body); $smarty->assign("body", $body);
......
...@@ -6,97 +6,97 @@ ...@@ -6,97 +6,97 @@
$permission = "sucsstaff"; $permission = "sucsstaff";
$eventtable = "events"; $eventtable = "events";
$eventcategories = array("Technical","Talks","Gaming","Social","Misc"); $eventcategories = array("Technical", "Talks", "Gaming", "Social", "Misc");
$smarty->assign("event_categories", $eventcategories); $smarty->assign("event_categories", $eventcategories);
$events_index = array_search("Events", $pathlist); $events_index = array_search("Events", $pathlist);
if (isset($pathlist[$events_index + 1])) { if (isset($pathlist[$events_index + 1])) {
list($eventcat, $eventid) = preg_split("/_/", $pathlist[$events_index + 1]); list($eventcat, $eventid) = preg_split("/_/", $pathlist[$events_index + 1]);
if (!in_array($eventcat, $eventcategories)) { if (!in_array($eventcat, $eventcategories)) {
trigger_error("Invalid category specified", E_USER_ERROR); trigger_error("Invalid category specified", E_USER_ERROR);
unset($eventcat, $eventid); unset($eventcat, $eventid);
} elseif (!ctype_digit($eventid)) { } elseif (!ctype_digit($eventid)) {
trigger_error("Invalid event specified", E_USER_ERROR); trigger_error("Invalid event specified", E_USER_ERROR);
print_r($eventid); print_r($eventid);
unset($eventcat, $eventid); unset($eventcat, $eventid);
} }
} }
if (isset($session->groups[$permission])) { if (isset($session->groups[$permission])) {
$smarty->assign("editable", true); $smarty->assign("editable", true);
$action = @$_REQUEST['action']; $action = @$_REQUEST['action'];
// process form actions with side-effects first // process form actions with side-effects first
switch ($action) { switch ($action) {
case "save": case "save":
$record['name'] = $_REQUEST['name']; $record['name'] = $_REQUEST['name'];
$record['description'] = $_REQUEST['description']; $record['description'] = $_REQUEST['description'];
$record['location'] = $_REQUEST['location']; $record['location'] = $_REQUEST['location'];
// reconstruct date/time // reconstruct date/time
$datetime = $_REQUEST['Date_Year']; $datetime = $_REQUEST['Date_Year'];
$datetime .= str_pad((int) $_REQUEST['Date_Month'],2,'0',STR_PAD_LEFT); $datetime .= str_pad((int)$_REQUEST['Date_Month'], 2, '0', STR_PAD_LEFT);
$datetime .= str_pad((int) $_REQUEST['Date_Day'],2,'0',STR_PAD_LEFT); $datetime .= str_pad((int)$_REQUEST['Date_Day'], 2, '0', STR_PAD_LEFT);
$datetime .= " ".$_REQUEST['Time_Hour']; $datetime .= " " . $_REQUEST['Time_Hour'];
$datetime .= ":".$_REQUEST['Time_Minute']; $datetime .= ":" . $_REQUEST['Time_Minute'];
$record['whn'] = $datetime; $record['whn'] = $datetime;
$record['category'] = $_REQUEST['category']; $record['category'] = $_REQUEST['category'];
$id = @$_REQUEST['id']; $id = @$_REQUEST['id'];
// this may be an existing event which needs to be updated // this may be an existing event which needs to be updated
if (ctype_digit($id)) { if (ctype_digit($id)) {
$DB->AutoExecute($eventtable, $record, 'UPDATE', "id=".$id); $DB->AutoExecute($eventtable, $record, 'UPDATE', "id=" . $id);
} else { } else {
$DB->AutoExecute($eventtable, $record, 'INSERT'); $DB->AutoExecute($eventtable, $record, 'INSERT');
} }
unset($action); unset($action);
break; break;
} }
} }
if (isset($session->groups[$permission]) && isset($action)) { if (isset($session->groups[$permission]) && isset($action)) {
switch($action) { switch ($action) {
case "create": case "create":
$event = array("id" => "*"); $event = array("id" => "*");
$body = $smarty->fetch("event_edit.tpl"); $body = $smarty->fetch("event_edit.tpl");
break; break;
case "edit": case "edit":
if (isset($eventcat) && isset($eventid)) { if (isset($eventcat) && isset($eventid)) {
$event = $DB->GetRow("SELECT * FROM $eventtable WHERE id=?", array($eventid)); $event = $DB->GetRow("SELECT * FROM $eventtable WHERE id=?", array($eventid));
//make tastier breadcrumbs //make tastier breadcrumbs
$pathlist[$events_index + 1] = $event['name']; $pathlist[$events_index + 1] = $event['name'];
$smarty->assign("event", $event); $smarty->assign("event", $event);
$body = $smarty->fetch("event_edit.tpl"); $body = $smarty->fetch("event_edit.tpl");
} }
break; break;
} }
} else { } else {
// not logged in, or no special action required // not logged in, or no special action required
if (isset($eventcat) && isset($eventid)) { if (isset($eventcat) && isset($eventid)) {
$event = $DB->GetRow("SELECT * FROM $eventtable WHERE id=?", array($eventid)); $event = $DB->GetRow("SELECT * FROM $eventtable WHERE id=?", array($eventid));
//make tastier breadcrumbs //make tastier breadcrumbs
$pathlist[$events_index + 1] = $event['name']; $pathlist[$events_index + 1] = $event['name'];
$smarty->assign("event", $event); $smarty->assign("event", $event);
$body = $smarty->fetch("event.tpl"); $body = $smarty->fetch("event.tpl");
} else { } else {
$events = $DB->GetAll("SELECT *,date_part('epoch', whn) as whn_timestamp $events = $DB->GetAll("SELECT *,date_part('epoch', whn) as whn_timestamp
FROM $eventtable WHERE date_trunc('day', whn) >= date_trunc('day',NOW()) ORDER BY whn ASC"); FROM $eventtable WHERE date_trunc('day', whn) >= date_trunc('day',NOW()) ORDER BY whn ASC");
$oldevents = $DB->GetAll("SELECT *,date_part('epoch', whn) as whn_timestamp $oldevents = $DB->GetAll("SELECT *,date_part('epoch', whn) as whn_timestamp
FROM $eventtable WHERE date_trunc('day', whn) < date_trunc('day', NOW()) ORDER BY whn DESC LIMIT 3"); FROM $eventtable WHERE date_trunc('day', whn) < date_trunc('day', NOW()) ORDER BY whn DESC LIMIT 3");
$smarty->assign("events", $events); $smarty->assign("events", $events);
$smarty->assign("oldevents", $oldevents); $smarty->assign("oldevents", $oldevents);
$body = $smarty->fetch("events.tpl"); $body = $smarty->fetch("events.tpl");
} }
} }
$smarty->assign("body", $body); $smarty->assign("body", $body);
......
...@@ -9,22 +9,22 @@ $cal = new vcalendar(); ...@@ -9,22 +9,22 @@ $cal = new vcalendar();
$cal->setConfig('unique_id', 'sucs.org'); $cal->setConfig('unique_id', 'sucs.org');
$cal->setProperty('method', 'PUBLISH'); $cal->setProperty('method', 'PUBLISH');
$cal->setProperty('x-wr-calname', "SUCS Events Calendar"); $cal->setProperty('x-wr-calname', "SUCS Events Calendar");
$cal->setProperty('X-WR-CALDESC', $cal->setProperty('X-WR-CALDESC',
"Upcoming events for members of the Swansea University Computer Society"); "Upcoming events for members of the Swansea University Computer Society");
$cal->setProperty('X-WR-TIMEZONE', 'Europe/London'); $cal->setProperty('X-WR-TIMEZONE', 'Europe/London');
//populate with upcoming events //populate with upcoming events
$events = $DB->GetAll("SELECT * FROM events WHERE $events = $DB->GetAll("SELECT * FROM events WHERE
date_trunc('day', whn) >= date_trunc('day', NOW()) ORDER BY whn ASC"); date_trunc('day', whn) >= date_trunc('day', NOW()) ORDER BY whn ASC");
foreach($events as $event) { foreach ($events as $event) {
$vevent = new vevent(); $vevent = new vevent();
$vevent->setProperty('dtstart', $event['whn']); $vevent->setProperty('dtstart', $event['whn']);
$vevent->setProperty('LOCATION', $event['location']); $vevent->setProperty('LOCATION', $event['location']);
$vevent->setProperty('summary', $event['name']); $vevent->setProperty('summary', $event['name']);
$vevent->setProperty('description', $event['description']); $vevent->setProperty('description', $event['description']);
$vevent->setProperty('categories', $event['category']); $vevent->setProperty('categories', $event['category']);
$cal -> setComponent($vevent); $cal->setComponent($vevent);
} }
//spit out a shiny new iCal file //spit out a shiny new iCal file
......
<?php <?php
$smarty->assign("news",$DB->GetArray("(SELECT * FROM news WHERE expiry > now() ORDER BY date DESC LIMIT 3) UNION SELECT * FROM news WHERE sticky=true and expiry > now() ORDER BY date DESC")); $smarty->assign("news", $DB->GetArray("(SELECT * FROM news WHERE expiry > now() ORDER BY date DESC LIMIT 3) UNION SELECT * FROM news WHERE sticky=true and expiry > now() ORDER BY date DESC"));
$output = $smarty->fetch("front.tpl"); $output = $smarty->fetch("front.tpl");
$smarty->assign("title", "Home"); $smarty->assign("title", "Home");
$smarty->assign("body", $output); $smarty->assign("body", $output);
if (!$session->loggedin) { if (!$session->loggedin) {
$output = file_get_contents("../static/fragments/Join.txt"); $output = file_get_contents("../static/fragments/Join.txt");
} else { } else {
$output = "<div class=\"cbb\"><h3>You are logged in</h3><p>If you would like to contribute to the site or report a bug, please contact imranh.</p></div>"; $output = "<div class=\"cbb\"><h3>You are logged in</h3><p>If you would like to contribute to the site or report a bug, please contact imranh.</p></div>";
$output = "<div class=\"cbb\"><h3>You are logged in</h3><p style=\"text-align: center;\">Why not join our <a href=\"#\" onclick=\"window.open('/mw/','Milliways','height=600,width=800,menubar=no,resizable=yes,location=no,directories=no,scrollbars=yes,status=no,toolbar=no')\" style=\"font-size: 150%; font-weight: bold; color: #ffc62b;\">Live Chat</a>?</p></div>"; $output = "<div class=\"cbb\"><h3>You are logged in</h3><p style=\"text-align: center;\">Why not join our <a href=\"https://chat.sucs.org\" target=\"_blank\">Live Chat</a>?</p></div>";
//include('users.php'); //include('users.php');
//$output .= $result; //$output .= $result;
include('electionreminder.php'); include('electionreminder.php');
$output .= $result; $output .= $result;
} }
$output .= "<div class=\"cbb\"><h3>SUCS Tools</h3><p>Download the SUCS Tools to make it easier to access SUCS services from your computer.</p><ul><li><a href=\"/files/sucstools-latest.exe\">SUCS Tools for Windows</a></li><li><a href=\"/files/SUCS-latest.dmg\">SUCS Tools for Mac OS X</a></li></ul><p>More information about the tools is available in \"<a href=\"/Knowledge/Help/SUCS%20Services/Using%20the%20SUCS%20Tools\">Using the SUCS Tools</a>\".</p></div>"; $output .= "<div class=\"cbb\"><h3>SUCS Tools</h3><p>Download the SUCS Tools to make it easier to access SUCS services from your computer.</p><ul><li><a href=\"/files/sucstools-latest.exe\">SUCS Tools for Windows</a></li><li><a href=\"/files/SUCS-latest.dmg\">SUCS Tools for Mac OS X</a></li></ul><p>More information about the tools is available in \"<a href=\"/Knowledge/Help/SUCS%20Services/Using%20the%20SUCS%20Tools\">Using the SUCS Tools</a>\".</p></div>";
$smarty->assign("secondary",$output); $smarty->assign("secondary", $output);
?> ?>
...@@ -9,5 +9,5 @@ $smarty->assign("title", "Games"); ...@@ -9,5 +9,5 @@ $smarty->assign("title", "Games");
$smarty->assign("body", $output); $smarty->assign("body", $output);
$output = file_get_contents("../static/fragments/Games-secondary.txt"); $output = file_get_contents("../static/fragments/Games-secondary.txt");
$smarty->assign("secondary",$output); $smarty->assign("secondary", $output);
?> ?>
<? <?php
$out = exec("/usr/bin/id"); $out = exec("/usr/bin/id");
$smarty->assign("body",$out); $smarty->assign("body", $out);
?> ?>
...@@ -4,196 +4,187 @@ ...@@ -4,196 +4,187 @@
$mode = "list"; $mode = "list";
$admin = false; $admin = false;
$admin_group="sucsstaff"; $admin_group = "sucsstaff";
// who's notified of items being requested? // who's notified of items being requested?
$junk_contact="admin@sucs.org"; $junk_contact = "admin@sucs.org";
$admin = isset($session->groups[$admin_group]); $admin = isset($session->groups[$admin_group]);
// If you're an admin and the path ends in Edit/ then a number put it into edit mode // If you're an admin and the path ends in Edit/ then a number put it into edit mode
// create canedit rules // create canedit rules
$canedit=isset($pathlist[($component[depth]/2)+1]); $canedit = isset($pathlist[($component[depth] / 2) + 1]);
$canedit=$canedit && isset($pathlist[($component[depth]/2)+2]); $canedit = $canedit && isset($pathlist[($component[depth] / 2) + 2]);
$canedit=$canedit && $pathlist[($component[depth]/2)+1]=='Edit'; $canedit = $canedit && $pathlist[($component[depth] / 2) + 1] == 'Edit';
$canedit=$canedit && is_numeric($pathlist[($component[depth]/2)+2]); $canedit = $canedit && is_numeric($pathlist[($component[depth] / 2) + 2]);
$canedit=$canedit && $admin; $canedit = $canedit && $admin;
// Apply canedit rules // Apply canedit rules
if ($canedit){ if ($canedit) {
$id = $pathlist[($component[depth]/2)+2]; $id = $pathlist[($component[depth] / 2) + 2];
$items = $DB->GetAll("SELECT id, title, category, description, donated_by, status FROM inventory WHERE id=? AND requested_by IS NULL",$id); $items = $DB->GetAll("SELECT id, title, category, description, donated_by, status FROM inventory WHERE id=? AND requested_by IS NULL", $id);
if(sizeof($items) === 1){ if (sizeof($items) === 1) {
$item = $items[0]; $item = $items[0];
$smarty->assign("item", $item); $smarty->assign("item", $item);
$mode = "edit"; $mode = "edit";
} }
} }
// If you're an admin and the path ends in Add put it into add mode // If you're an admin and the path ends in Add put it into add mode
// create canadd rules // create canadd rules
$canadd=isset($pathlist[($component[depth]/2)+1]); $canadd = isset($pathlist[($component[depth] / 2) + 1]);
$canadd=$canadd && $pathlist[($component[depth]/2)+1]=='Add'; $canadd = $canadd && $pathlist[($component[depth] / 2) + 1] == 'Add';
$canadd=$canadd && $admin; $canadd = $canadd && $admin;
// Apply canadd rules // Apply canadd rules
if ($canadd){$mode = "add";} if ($canadd) {
$mode = "add";
}
// Process actions before retrieving the data // Process actions before retrieving the data
// List request data // List request data
if ($session->loggedin && isset($_REQUEST['action'])) { if ($session->loggedin && isset($_REQUEST['action'])) {
// Junk Requests // Junk Requests
if ($_REQUEST['action'] == "Request") { if ($_REQUEST['action'] == "Request") {
// Request Item if its available // Request Item if its available
$query = "UPDATE inventory SET requested_by=?, requested_on=now() WHERE id=? AND requested_by IS NULL"; $query = "UPDATE inventory SET requested_by=?, requested_on=now() WHERE id=? AND requested_by IS NULL";
$DB->Query($query, array($session->username, $_REQUEST['item'])); $DB->Query($query, array($session->username, $_REQUEST['item']));
// mail someone so we know that this has been requested // mail someone so we know that this has been requested
$iteminfo = $DB->GetRow("SELECT title, description FROM inventory WHERE id=?", array($_REQUEST['item'])); $iteminfo = $DB->GetRow("SELECT title, description FROM inventory WHERE id=?", array($_REQUEST['item']));
$msgbody = "User {$session->username} has requested the junk item:\n\n"; $msgbody = "User {$session->username} has requested the junk item:\n\n";
$msgbody .= "{$iteminfo['title']}: {$iteminfo['description']}\n\n"; $msgbody .= "{$iteminfo['title']}: {$iteminfo['description']}\n\n";
$msgbody .= "Please ensure this is taken away and never brought back."; $msgbody .= "Please ensure this is taken away and never brought back.";
mail($junk_contact,"Junk item requested",$msgbody); mail($junk_contact, "Junk item requested", $msgbody);
} elseif ($_REQUEST['action'] == "Un-Request") {
// Un-Request Item
if ($admin) {
// if you're admin just do it
$query = "UPDATE inventory SET requested_by=null, requested_on=null WHERE id=?";
$array = array($_REQUEST['item']);
} else {
// if not admin check if you requested it first
$query = "UPDATE inventory SET requested_by=null, requested_on=null WHERE id=? AND requested_by=?";
$array = array($_REQUEST['item'], $session->username);
}
$DB->Query($query, $array);
} elseif ($_REQUEST['action'] == "Take" && $admin) {
// Take item, if you're admin
$query = "UPDATE inventory SET taken_on=now() WHERE id=? AND requested_by IS NOT NULL";
$DB->Query($query, $_REQUEST['item']);
} elseif ($_REQUEST['action'] == "Remove" && $admin) {
// Remove item, if you're admin
$query = "DELETE FROM inventory WHERE id=?";
if ($DB->Query($query, $_REQUEST['item'])) {
message_flash("Item removed");
} else {
trigger_error("Failed to remove item");
} }
elseif ($_REQUEST['action'] == "Un-Request") { } elseif ($_REQUEST['action'] == "Not Junk" && $admin) {
// Un-Request Item // Mark item as not junk if it's not been requested and you're admin
if ($admin){ $query = "UPDATE inventory SET status='unknown' WHERE id=? AND requested_by IS NULL";
// if you're admin just do it $DB->Query($query, $_REQUEST['item']);
$query = "UPDATE inventory SET requested_by=null, requested_on=null WHERE id=?"; } elseif ($_REQUEST['action'] == "Junk" && $admin) {
$array = array($_REQUEST['item']); // Mark item as junk, if you're admin
} $query = "UPDATE inventory SET status='junk' WHERE id=?";
else{ $DB->Query($query, $_REQUEST['item']);
// if not admin check if you requested it first }
$query = "UPDATE inventory SET requested_by=null, requested_on=null WHERE id=? AND requested_by=?";
$array = array($_REQUEST['item'], $session->username);
}
$DB->Query($query, $array);
}
elseif ($_REQUEST['action'] == "Take" && $admin){
// Take item, if you're admin
$query = "UPDATE inventory SET taken_on=now() WHERE id=? AND requested_by IS NOT NULL";
$DB->Query($query, $_REQUEST['item']);
}
elseif ($_REQUEST['action'] == "Remove" && $admin){
// Remove item, if you're admin
$query = "DELETE FROM inventory WHERE id=?";
if ($DB->Query($query, $_REQUEST['item'])) {
message_flash("Item removed");
} else {
trigger_error("Failed to remove item");
}
}
elseif ($_REQUEST['action'] == "Not Junk" && $admin){
// Mark item as not junk if it's not been requested and you're admin
$query = "UPDATE inventory SET status='unknown' WHERE id=? AND requested_by IS NULL";
$DB->Query($query, $_REQUEST['item']);
}
elseif ($_REQUEST['action'] =="Junk" && $admin){
// Mark item as junk, if you're admin
$query = "UPDATE inventory SET status='junk' WHERE id=?";
$DB->Query($query, $_REQUEST['item']);
}
} }
// Update/Add item // Update/Add item
if ($session->loggedin && $admin && (isset($_REQUEST['update']) || isset($_REQUEST['add']))) { if ($session->loggedin && $admin && (isset($_REQUEST['update']) || isset($_REQUEST['add']))) {
// try to guess which category field the user meant us to see // try to guess which category field the user meant us to see
// ideally we'd use an html combo box, but since they don't exist... // ideally we'd use an html combo box, but since they don't exist...
if ($_REQUEST['categorymenu'] == "") { if ($_REQUEST['categorymenu'] == "") {
$category = $_REQUEST['category']; $category = $_REQUEST['category'];
} else { } else {
$category = $_REQUEST['categorymenu']; $category = $_REQUEST['categorymenu'];
} }
// Update/Add item if title and category are filled in else error // Update/Add item if title and category are filled in else error
if ($_REQUEST['title'] != "" && $category != "") { if ($_REQUEST['title'] != "" && $category != "") {
// if the description is blank, return null // if the description is blank, return null
if ($_REQUEST['description'] == ""){ if ($_REQUEST['description'] == "") {
$description = null; $description = null;
} } else {
else{ $description = $_REQUEST['description'];
$description = $_REQUEST['description']; }
} // if the donated_by is blank, return null
// if the donated_by is blank, return null if ($_REQUEST['donated_by'] == "") {
if ($_REQUEST['donated_by'] == ""){ $donated_by = null;
$donated_by = null; } else {
} $donated_by = $_REQUEST['donated_by'];
else{ }
$donated_by = $_REQUEST['donated_by']; // run the query
} if (isset($_REQUEST['update'])) {
// run the query $query = "UPDATE inventory SET title=?, category=?, description=?, donated_by=?, status=? WHERE id=?";
if(isset($_REQUEST['update'])){ $array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status'], $_REQUEST['id']);
$query = "UPDATE inventory SET title=?, category=?, description=?, donated_by=?, status=? WHERE id=?"; if ($DB->Query($query, $array)) {
$array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status'], $_REQUEST['id']); message_flash("Item Updated");
if ($DB->Query($query, $array)) { } else {
message_flash("Item Updated"); trigger_error("Item update failed :-(", E_USER_ERROR);
} else { }
trigger_error("Item update failed :-(", E_USER_ERROR); } elseif (isset($_REQUEST['add'])) {
} $query = "INSERT INTO inventory (title, category, description, donated_by, status) VALUES (?, ?, ?, ?, ?)";
} $array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status']);
elseif(isset($_REQUEST['add'])){ if ($DB->Query($query, $array)) {
$query = "INSERT INTO inventory (title, category, description, donated_by, status) VALUES (?, ?, ?, ?, ?)"; message_flash("Item Added");
$array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status']); } else {
if ($DB->Query($query, $array)) { trigger_error("Adding item failed :-( - " . $DB->ErrorMsg(), E_USER_ERROR);
message_flash("Item Added"); }
} else { }
trigger_error("Adding item failed :-( - ".$DB->ErrorMsg(), E_USER_ERROR); } else {
} trigger_error("Required field(s) missing", E_USER_WARNING);
} }
}
else{
trigger_error("Required field(s) missing", E_USER_WARNING);
}
} }
// Remove old taken junk // Remove old taken junk
$DB->Query("DELETE FROM inventory WHERE (taken_on + interval'7 days') < now()"); $DB->Query("DELETE FROM inventory WHERE (taken_on + interval'7 days') < now()");
if ($mode == 'list'){ if ($mode == 'list') {
// Get junk from database, and give admin the full list // Get junk from database, and give admin the full list
if ($admin == true){ if ($admin == true) {
$junk = $DB->GetAll("SELECT * FROM inventory ORDER BY category, title, id"); $junk = $DB->GetAll("SELECT * FROM inventory ORDER BY category, title, id");
} } else {
else{ $junk = $DB->GetAll("SELECT * FROM inventory WHERE status = 'junk' ORDER BY category, title, id");
$junk = $DB->GetAll("SELECT * FROM inventory WHERE status = 'junk' ORDER BY category, title, id"); }
} //
// // Check there is some junk
// Check there is some junk if (sizeof($junk) < 1) {
if (sizeof($junk) < 1) { $mode = "nojunk";
$mode = "nojunk"; } else {
} else {
// group the junk by status then by category
// group the junk by status then by category foreach ($junk as $junkitem) {
foreach($junk as $junkitem) { if ($junkitem['status'] != 'junk') {
if ($junkitem['status'] != 'junk') { $status = "unknown";
$status = "unknown"; } else if ($junkitem['requested_by'] == null) {
} else if ($junkitem['requested_by'] == null) { $status = "available";
$status = "available"; } else if ($junkitem['taken_on'] == null) {
} else if ($junkitem['taken_on'] == null) { $status = "requested";
$status = "requested"; } else {
} else { $status = "taken";
$status = "taken"; }
}
$sortedjunk[$status][$junkitem['category']][] = $junkitem;
$sortedjunk[$status][$junkitem['category']][] = $junkitem; }
} $smarty->assign("junk", $sortedjunk);
$smarty->assign("junk", $sortedjunk); }
}
} else { } else {
$categories = $DB->GetCol("SELECT DISTINCT category FROM inventory ORDER BY category ASC"); $categories = $DB->GetCol("SELECT DISTINCT category FROM inventory ORDER BY category ASC");
$smarty->assign("categories", $categories); $smarty->assign("categories", $categories);
} }
// Generate output // Generate output
$smarty->assign("statuses",array("unknown", "in use", "wanted", "junk")); $smarty->assign("statuses", array("unknown", "in use", "wanted", "junk"));
$smarty->assign("componentpath", $baseurl . $component[path]); $smarty->assign("componentpath", $baseurl . $component[path]);
$smarty->assign("mode", $mode); $smarty->assign("mode", $mode);
$smarty->assign("admin", $admin); $smarty->assign("admin", $admin);
$output = $smarty->fetch("junk.tpl"); $output = $smarty->fetch("junk.tpl");
$smarty->assign("title", "Junk List"); $smarty->assign("title", "Junk List");
$smarty->assign("body", $output); $smarty->assign("body", $output);
......