diff --git a/components/disk.graph/index.php b/components/disk.graph.php similarity index 84% rename from components/disk.graph/index.php rename to components/disk.graph.php index 598e360f173601909fa8f93c45e8ff0be3e3905b..a91e2f472b5cad2c820defdd20da7b908055dac0 100644 --- a/components/disk.graph/index.php +++ b/components/disk.graph.php @@ -21,6 +21,6 @@ print_r($slice); print_r($item);*/ - include("pieChart.php"); - piechart("Top 12 Users of disk space", $slice, $item) + include("../../lib/pieChart.php"); + piechart("Top 12 Users of disk space", $slice, $item, 1) ?> diff --git a/components/shame.php b/components/disk.php similarity index 86% rename from components/shame.php rename to components/disk.php index 6119770cfb21944ca999569a91a106d155c05066..ad5b7fb56b5c733178ed94e06d91af0b5595113b 100644 --- a/components/shame.php +++ b/components/disk.php @@ -1,6 +1,6 @@ <? exec("/usr/local/bin/shame.py -a", $Shame); $smarty->assign('title',"The SUCS Hall of Shame"); - $o="<div style='text-align: center;'><img src=\"/images/shame.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.="\t<tr><th align=\"center\">User</th><th align=\"center\">Home Directory Size</th></tr>\n"; diff --git a/components/membershiprenew.php b/components/membershiprenew.php index 54d77a1cb844fb5d5178ed3524da4bb0ab10a0cc..04a33ed4c7bbdaf796d620983b1269f5b8601491 100644 --- a/components/membershiprenew.php +++ b/components/membershiprenew.php @@ -109,8 +109,8 @@ if (isset($session->groups[$permission])) { $getrefresh=$refreshval; } else{ - // otherwise use 10 - $refreshval="10"; + // If no valid value assigned, default to OFF + $refreshval="n"; } $optrefresh=$refreshval; $smarty->assign("refresh", $refreshval); diff --git a/components/printer.graph.php b/components/printer.graph.php new file mode 100644 index 0000000000000000000000000000000000000000..5375f474b2f03cc2889db1a9e8489bbb267b4089 --- /dev/null +++ b/components/printer.graph.php @@ -0,0 +1,32 @@ +<? +include("adodb/adodb.inc.php"); +$sucsDB = NewADOConnection('postgres8'); +$sucsDB->Connect('dbname=sucs user=apache'); +$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); + +$res = $sucsDB->Execute("select username, sum(pages) as pages from printer where username != 'old' group by username order by sum(pages) desc"); +$num = $res->RecordCount(); + for ($i=0;$i<$num;$i++) { + $row[$i] = $res->FetchRow(); + if ($i < 12) + { + $item[]=$row[$i]['username']; + $slice[]=$row[$i]['pages']; + } + else { + $otherSize += $row[$i]['pages']; + } + } +// $itemName[]="Other"; +// $sliceSize[]=$otherSize; + + $slice = array_merge(array($otherSize),$slice); + $item = array_merge(array("Other"), $item); + +/* echo "<pre>"; + print_r($slice); + print_r($item);*/ + + include("../../lib/pieChart.php"); + piechart("Top 12, Users of Printing", $slice, $item,0) +?> diff --git a/components/printer.php b/components/printer.php new file mode 100644 index 0000000000000000000000000000000000000000..4f742421b2fd826bafda0bbd9f0921919d5f4fd5 --- /dev/null +++ b/components/printer.php @@ -0,0 +1,131 @@ +<?PHP +/****** + * Printer Shame List + * Ported from old site by tswsl1989 + * + */ + +$smarty->assign('title',"Printer Statistics"); +$sucsDB = NewADOConnection('postgres8'); +$sucsDB->Connect('dbname=sucs user=apache'); +$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); + +$out="<img src=\"/images/printer.graph.php\" alt=\"pie chart of top 12 printer users\"/>"; +$table="<table border=1 cellpadding=3>\n<tr>\n<th>Username</th>\n<th>Pages</th>\n<th>Projected Monthly Usage</th>\n<th>Printed This Month</th>\n<th>What it would cost in the library</th></tr>\n"; + +//pull in all the current users (ie not old) who have printed stuff +$res = $sucsDB->Execute("select username, sum(pages) as pages from printer where username != 'old' group by username order by sum(pages) desc"); +$num = $res->RecordCount(); +//for each row stuff the infomation into an array, then free up the database resorces +for ($i=0;$i<$num;$i++) { + $data[$i] = $res->FetchRow(); + $data[$i]['month'] = 0; +} +$res->Close(); + +//get the second since epoch +$thisSecond = gmmktime(); +//for each user who has printed stuff add the first printed time (since epoch) to the array +for ($i=0;$i<$num;$i++) { + $res = $sucsDB->Execute("select date_part('epoch',start) as first from printer where username ='".$data[$i]['username']."' order by start asc limit 1;"); + $temp = $res->FetchRow(); + $data[$i]['first'] = $temp['first']; + $res->Close(); +} + +$res = $sucsDB->Execute("select username, pages, start from printer where username != 'old'"); +$datesnum = $res->RecordCount();//for each row stuff the infomation into an array, then free up the database resorces +for ($i=0;$i<$datesnum;$i++) { + $dates[$i] = $res->FetchRow($res, $i); +} +$res->Close(); + + +// get the current month +$theMonth = date("m"); +$theYear = date("Y"); +for ($i=0;$i<$datesnum;$i++) { + $userMonth = substr($dates[$i]['start'], 5, 2); + $userYear = substr($dates[$i]['start'], 0, 4); + if (($userMonth == $theMonth) && ($userYear == $theYear)) { + for ($j=0;$j<$num;$j++) { + if ($data[$j]['username'] == $dates[$i]['username']) { + $data[$j]['month'] += $dates[$i]['pages']; + } + } + } +} + +//start the total counter +$total = 0; +//for each user.. print a row in the table +for ($i=0;$i<$num;$i++) { + $table.="<tr align=\"center\">\n"; + $table.="<td>{$data[$i]['username']}</td>\n"; + $table.="<td>{$data[$i]['pages']}</td>\n"; + //avg pages per month = seconds in a month / (now - first print) * pages + $crazyGuess = round((2629743.83/($thisSecond-$data[$i]['first']))*$data[$i]['pages']); + //if the user has only started printing in the last month its not sensible to give a guess of average useage + if ($thisSecond-$data[$i]['first'] <= 2629743.83) { + $table.="<td>Not enough data</td>\n"; + } + //traffic lights for pinter useage, adjust values as required + elseif($crazyGuess <= 25) { + $table.="<td BGCOLOR=\"Green\">".$crazyGuess."</td>\n"; + } + elseif($crazyGuess <= 33) { + $table.="<td BGCOLOR=\"Orange\">".$crazyGuess."</td>\n"; + } + else{ + $table.="<td BGCOLOR=\"Red\">".$crazyGuess."</td>\n"; + } + if ($data[$i]['month'] >= 300) { + $table.="<td BGCOLOR=\"Red\">{$data[$i]['month']}</td>\n"; + } else { + $table.="<td>{$data[$i]['month']}</td>\n"; + } + $table.="<td>".sprintf("£ %01.2f",round(0.1*$data[$i]['pages'],2))."</td>\n"; + //add this users useage to the total + $total += $data[$i]['pages']; + $table.="</tr>\n"; +} + +//get the first print date +$res = $sucsDB->Execute("select date_part('epoch',start) as first from printer order by start asc limit 1;"); +$temp = $res->FetchRow(); +$date['first'] = getdate($temp['first']); +$res->Close(); +//get the last print date +$res = $sucsDB->Execute("select date_part('epoch',start) as last from printer order by start desc limit 1;"); +$temp = $res->FetchRow(); +$date['last'] = getdate($temp['last']); +$res->Close(); +//get the number of pages printed by "old" users and add it to the total +$res = $sucsDB->Execute("select sum(pages) as pages from printer where username = 'old' group by username order by sum(pages) desc"); +$old = $res->FetchRow(); +$old = $old[0]; +$res->Close(); +$total += $old; +//Output two lines at the bottem of the table, one for "old" users and the other for the total +$table.="<tr align=\"center\">\n\t<th>Old Users</th>\n\t<th>$old</th>\n\t<th>n/a</th>\n</tr>"; +$table.="<tr align=\"center\">\n\t<th>Total</th>\n\t<th>$total</th>\n\t<th>".round((2629743.83/($thisSecond-$date['first'][0]))*$total)."</th>\n</tr>"; +$table.="</table>\n"; + +//output the dates of the first and last prints recorded +$out.="<p>First Data - ".$date['first'][weekday].", ".$date['first'][mday]." ".$date['first'][month]." ".$date['first'][year].", at ".$date['first'][hours].":".$date['first'][minutes].":".$date['first'][seconds]."<br />"; +$out.="Last Data - ".$date['last'][weekday].", ".$date['last'][mday]." ".$date['last'][month]." ".$date['last'][year].", at ".$date['last'][hours].":".$date['last'][minutes].":".$date['last'][seconds]."</p>"; +//do some silly maths to work out lots of silly things +$paperarea = round(0.21*0.297*$total,3); //area of paper +$paperweight = round($paperarea*.08, 3); //how much that would weigh +$numtrees = round($paperweight/730.296, 6); //*very* roughly how many trees that would be +$cost = round(0.1*$total,2); +$out.="<p>That's ".$paperarea."m<sup>2</sup> of paper, weighing ".$paperweight."kg!<br>\n"; +$out.="This is equivalent to approximately ".$numtrees." trees.<br>\n"; +$out.="That would have cost our members a grand total of £".$cost." if it were printed in the library.. not bad for £5!"; + +//done +$out.="<p>Note: The number of pages is the number spooled and may be more than the actual number printed</p>"; +$out.=$table; +$sucsDB->Close(); +$smarty->assign('body',$out); +?> diff --git a/components/signup.php b/components/signup.php index d86e24dc58d7231d5aa92b2405bc4e763eedb406..d2534d0edf041f469932d3cb309589e186260055 100644 --- a/components/signup.php +++ b/components/signup.php @@ -183,7 +183,7 @@ if(isset($_REQUEST['signupid'])&&isset($_REQUEST['signuppw'])){ mail( $error_email, "Signup Error", - "User ".$fields['username']." already exsists in the databse, THIS SHOULD NEVER HAPPERN\n Love the signup system.\n\nP.S. the signup id is: ".$signupid, + "User ".$fields['username']." already exists in the databse, THIS SHOULD NEVER HAPPEN\n Love the signup system.\n\nP.S. the signup id is: ".$signupid, "From: \"SUCS Admin\" <admin@sucs.org>" ); $failed=true; @@ -323,8 +323,11 @@ if(isset($_REQUEST['signupid'])&&isset($_REQUEST['signuppw'])){ } } - - $addtolist ="".$fields['email']."\n".$fields['studentid']."@swan.ac.uk"; + if ($row['type']!=2){ + $addtolist ="".$fields['email']."\n".$fields['studentid']."@swan.ac.uk"; + }else{ + $addtolist="".$fields['email']."\n"; //Societies don't have student email addresses + } file_put_contents('/tmp/listadd.'.$fields['username'],$addtolist); unset($execoutputarr); exec( @@ -353,7 +356,7 @@ if(isset($_REQUEST['signupid'])&&isset($_REQUEST['signuppw'])){ $errorreparray=$_POST; unset($errorroparray[signuppw]); $errorreparray[uid]=$uid; - $errorreport = "User inputed detailes:\n\n"; + $errorreport = "User input details:\n\n"; foreach ($errorreparray as $key => $value){ $errorreport .= $key.": ".$value."\n"; } diff --git a/components/disk.graph/pieChart.php b/lib/pieChart.php similarity index 91% rename from components/disk.graph/pieChart.php rename to lib/pieChart.php index 7edcc68ac4aaa25ea98e9e0f2385c824beb1d2a1..2b38c0995420a5c0c6ff39f0c51bb13635037894 100644 --- a/components/disk.graph/pieChart.php +++ b/lib/pieChart.php @@ -1,6 +1,6 @@ <? -function piechart($title, $slice, $itemName) { +function piechart($title, $slice, $itemName, $fsizes=0) { function matchset($xx) { @@ -132,13 +132,15 @@ function piechart($title, $slice, $itemName) { ImageFilledRectangle($im, 340, $adjPosition, 350, ($adjPosition+10), $black); ImageFilledRectangle($im, 341, ($adjPosition+1), 349, ($adjPosition+9), $WedgeColor); - if($sliced[$z] >= "1000" && $sliced[$z] < "1000000") - { - $sliced[$z] = $sliced[$z]/1000; - $sliced[$z] = sprintf("%01.2f", "$sliced[$z]")."G"; + if($fsizes){ + if($sliced[$z] >= "1000" && $sliced[$z] < "1000000") + { + $sliced[$z] = $sliced[$z]/1000; + $sliced[$z] = sprintf("%01.2f", "$sliced[$z]")."G"; + } + else + $sliced[$z] = "$sliced[$z]"."M"; } - else - $sliced[$z] = "$sliced[$z]"."M"; $sliceLen = strlen($sliced[$z]); if($sliceLen == '5'){$sliced[$z] = " "."$sliced[$z]";} if($sliceLen == '4'){$sliced[$z] = " "."$sliced[$z]";} diff --git a/lib/punbb/include/common.php b/lib/punbb/include/common.php index 75aaa7ab696aa6643411e473a34c2215a47063aa..26af9e618d2fea7484c0567ce77ba1975e6bbf0f 100644 --- a/lib/punbb/include/common.php +++ b/lib/punbb/include/common.php @@ -54,7 +54,6 @@ $pun_start = ((float)$usec + (float)$sec); // Make sure PHP reports all errors except E_NOTICE. PunBB supports E_ALL, but a lot of scripts it may interact with, do not. error_reporting(E_ALL ^ E_NOTICE); -// Turn off magic_quotes_runtime if (get_magic_quotes_runtime()) set_magic_quotes_runtime(0); diff --git a/lib/validation.php b/lib/validation.php index 076ecb5ee301c6ee8811dae5cf97b45ce68bb2fc..7aad3c67045c6e35da81158200ab5b0efb024436 100644 --- a/lib/validation.php +++ b/lib/validation.php @@ -253,8 +253,9 @@ function validSocName($socname,$override){ function validAddress($address){ global $error; - $address = sanitizeAddress($address); - if(!preg_match("/^([A-Z0-9]([[:alnum:]]|[ ./'-])*\n)+[A-Z0-9]([[:alnum:]]|[ ./'-])*$/",$address)){ + $address = sanitizeAddress($address); + $regex="/^([A-Z0-9]([[:alnum:]]|[ .\/'-])*\n)+[A-Z0-9]([[:alnum:]]|[ .\/'-])*$/"; + if(!preg_match($regex,$address)){ $error = "Please supply at least two valid lines of address."; return false; }