<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
  img {
    max-width: 100%;
    height: auto;
  }
  p.details {
    font-style:italic;
    color:#777
  }
  .footer p {
    font-size:small;
    color:#777
  }
  pre.commit-message {
    white-space: pre-wrap;
  }
  .file-stats a {
    text-decoration: none;
  }
  .file-stats .new-file {
    color: #090;
  }
  .file-stats .deleted-file {
    color: #B00;
  }
</style>
<body>
<div class='content'>
<h3>Imran Hussain pushed to branch master at <a href="https://projects.sucs.org/sucssite/sucs-site">sucssite / sucs-site</a></h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/b552813ab9c2221e597aa9b2b785d5400ca83470">b552813a</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-04T20:38:25Z</i>
</div>
<pre class='commit-message'>Start of the new php file for the suapiv2 fucntions and shit,</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/9fbcdfc2edd4635217137e89ae3ddd5a260d65da">9fbcdfc2</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-04T20:49:13Z</i>
</div>
<pre class='commit-message'>Finsihed the check_su_transid function</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/3984b0c2b460570058d302a7a53fc4c4e80b7ce2">3984b0c2</a></strong>
<div>
<span>by Laurence Sebastian Bowes</span>
<i>at 2015-10-04T20:57:47Z</i>
</div>
<pre class='commit-message'>working</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/5b66364e12110b6cdb7ecd443ebcd4a1e5db301c">5b66364e</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-04T21:08:16Z</i>
</div>
<pre class='commit-message'>Move the api key to a seperate file and move the orgid to a variable</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/54fbd6ee7193d98adee509d5e8c26601ace33bc4">54fbd6ee</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-04T21:13:43Z</i>
</div>
<pre class='commit-message'>Fixed some typos brought on by the last commit</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/1cb19191bd32e0f2df7ad13bcafee00f139487c8">1cb19191</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-04T21:26:21Z</i>
</div>
<pre class='commit-message'>add comments!</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/9a3bb018e323b3d12a965aab614b302a7133778a">9a3bb018</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-05T10:07:28Z</i>
</div>
<pre class='commit-message'>Add more comments on how to use the code.</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/7e587262bcd3cb6d8cd48e8d27a4e3c4d52f865b">7e587262</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-05T12:55:53Z</i>
</div>
<pre class='commit-message'>Rename a function so you can better guess what it does from the name</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/7daa80fb50709d410607810135599a25f4778486">7daa80fb</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-05T14:13:27Z</i>
</div>
<pre class='commit-message'>Working on the replacement for the susignup page</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/b73a6cb2959eebda4d00b4a0ba7c9fe1be50c99f">b73a6cb2</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-05T14:52:22Z</i>
</div>
<pre class='commit-message'>Finsihed the /susignup page</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/56d64cb6abc46405c683aba3b4d6094bb254570b">56d64cb6</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-05T15:08:03Z</i>
</div>
<pre class='commit-message'>Removed some cruft. Added some comments.</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/2f87eadb89fcd07572586b8092265cc9d8b7132a">2f87eadb</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-05T16:20:01Z</i>
</div>
<pre class='commit-message'>Remove extra "}"</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/8d63b5f1882812cd906ae1803ab3e5de7d728596">8d63b5f1</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-05T16:21:36Z</i>
</div>
<pre class='commit-message'>Turn off error reporting as smarty sucks</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/383ecf6339181556709552fdb0b6f32fee5be691">383ecf63</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T12:57:22Z</i>
</div>
<pre class='commit-message'>Add a new member renew function</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/71feb7426dee842860f2137584ff93b39e3e809a">71feb742</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T12:59:03Z</i>
</div>
<pre class='commit-message'>Make my redo of the su signup page use the new membership renew function</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/b9f47f2309cb19d9e9cb61c668b3d9c48ca37d5a">b9f47f23</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T13:02:26Z</i>
</div>
<pre class='commit-message'>I'm declaring a fucntion not calling it!</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/48437a35a2d7cf44069ce8783d857826eaacc284">48437a35</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T14:19:22Z</i>
</div>
<pre class='commit-message'>Make member options page (options.php) use the new renew function.

Also change the way messages are flashed to the user.</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/c6290f43d246dcf5d081366e736113f0be01eec9">c6290f43</a></strong>
<div>
<span>by Laurence Sebastian Bowes</span>
<i>at 2015-10-06T15:16:11Z</i>
</div>
<pre class='commit-message'>Put the library file in a sensible place.</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/b90e6082a6c884253a85a5b214e9e4d79ebfa89b">b90e6082</a></strong>
<div>
<span>by Laurence Sebastian Bowes</span>
<i>at 2015-10-06T15:22:43Z</i>
</div>
<pre class='commit-message'>make susignup.php point to the right file.</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/9da9071af8b87902d7aff09bf1e8e88b17a9e9ed">9da9071a</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T15:39:10Z</i>
</div>
<pre class='commit-message'>Redo part of susignup-admin (search) to use the new api</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/d6cd4954777f3acb5d569773b6cf1d7708ead7b2">d6cd4954</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T15:48:01Z</i>
</div>
<pre class='commit-message'>Users are idiots. add error handling</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/3544d1a3eca163d0a9b56ec4cfd8cb382dd2a9e4">3544d1a3</a></strong>
<div>
<span>by Laurence Sebastian Bowes</span>
<i>at 2015-10-06T15:51:10Z</i>
</div>
<pre class='commit-message'>Make the admin renew function use the member functions library.</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/665cce715770e91c97d56e94ad6f2c24000bfaf6">665cce71</a></strong>
<div>
<span>by Laurence Sebastian Bowes</span>
<i>at 2015-10-06T15:52:16Z</i>
</div>
<pre class='commit-message'>i merged

Merge branch 'suapiv2' of projects.sucs.org:imranh/sucs-site into suapiv2</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/c5a6661e2e9f00e2fdc506fd733dae71db8ebe2a">c5a6661e</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T16:11:41Z</i>
</div>
<pre class='commit-message'>Kill mode renew as it doesn't get called anymore</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/2bb5f20f75059d98b51636a1bcc66b7cbd2d0056">2bb5f20f</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T16:30:22Z</i>
</div>
<pre class='commit-message'>Redo bulk renewals to use the new api and fix elbows extra "}" shitting things up</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/8d535426b0984e518a7780ae9f21c9bbba9f55c9">8d535426</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T16:33:10Z</i>
</div>
<pre class='commit-message'>Remove extra debug info</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/2bf479150ce70f089a99ee96cd30292a56b848c4">2bf47915</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T16:48:07Z</i>
</div>
<pre class='commit-message'>Finsih converting susignup-admin.php to sue the new api</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/ba01da389060dee467cc3f74ac1670146db84f19">ba01da38</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-10-06T18:26:42Z</i>
</div>
<pre class='commit-message'>Merge branch 'suapiv2' into 'master'

Implement the new SU API Closes #5

See merge request !25</pre>
</li>
</ul>
<h4>7 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
components/options.php
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
components/susignup-admin.php
</a>
</li>
<li class='file-stats'>
<a href='#diff-2'>
components/susignup.php
</a>
</li>
<li class='file-stats'>
<a href='#diff-3'>
lib/member_functions.php
</a>
</li>
<li class='file-stats'>
<a href='#diff-4'>
<span class='new-file'>
+
lib/suapiv2.php
</span>
</a>
</li>
<li class='file-stats'>
<a href='#diff-5'>
templates/susignup-admin.tpl
</a>
</li>
<li class='file-stats'>
<a href='#diff-6'>
templates/susignup.tpl
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19#diff-0'>
<strong>
components/options.php
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/components/options.php
</span><span style="color: #000000;background-color: #ddffdd">+++ b/components/options.php
</span><span style="color: #aaaaaa">@@ -204,7 +204,8 @@ function updateRenew() {
</span>           return FALSE;
        }
 
-       $sucsDB->Execute("update members set paid=?, lastupdate=DEFAULT, lastedit=uid where uid=?", array($paydate, $member['uid']));
<span style="color: #000000;background-color: #ddffdd">+        include_once("../lib/member_functions.php");
+       renew_membership($member['username']);
</span>   $sucsDB->Execute("update signup set activated=NOW(), username=? where id=?", array($member['username'], $signup['id']));
        return TRUE;
 }
</code></pre>

<br>
</li>
<li id='diff-1'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19#diff-1'>
<strong>
components/susignup-admin.php
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/components/susignup-admin.php
</span><span style="color: #000000;background-color: #ddffdd">+++ b/components/susignup-admin.php
</span><span style="color: #aaaaaa">@@ -1,232 +1,92 @@
</span>-<?PHP
-/***
<span style="color: #000000;background-color: #ffdddd">- * SU Signup admin
- * Allows us to search the SU api for a given student number and checks if they're a SUCS member.
- * If they are - allows account renewal
- * If not - allows signup to be bootstrapped as per susignup component
- ***/
</span><span style="color: #000000;background-color: #ddffdd">+<?php
</span> 
<span style="color: #000000;background-color: #ddffdd">+// gib errars plox
+//error_reporting(E_ALL);
+//ini_set('display_errors', 1);
+
+// include functions and shit we need
</span> include("../lib/member_functions.php");
 include("../lib/date.php");
-include("../suapi.inc.php");
<span style="color: #000000;background-color: #ddffdd">+include("../lib/suapiv2.php");
</span> 
 //Restrict access to staff.
 $permission="sucsstaff";
-$apibaseurl="https://$suapi_user:$suapi_pass@su-api.sucs.org/memberships/Membership.asmx";
 
<span style="color: #000000;background-color: #ddffdd">+// if they have the right privs then lets do shit
</span> if (isset($session->groups[$permission])) {
        //Setup smarty magic, step 1
        $smarty->assign("staff", TRUE);
 
<span style="color: #000000;background-color: #ddffdd">+        // if no mode has been requested then show options
</span>   if(!isset($_REQUEST['mode'])) {
                $mode = 'menu';
        } else {
                $mode = urldecode($_REQUEST['mode']);
        }
 
<span style="color: #000000;background-color: #ddffdd">+        // We have a mode, lets try and work out wtf they want to do
+
+       // they have typed in a sid and want to bootstrap the signup processs
</span>   if ($mode == 'search') {
                if (empty($_REQUEST['sid']) || empty($_REQUEST['snsubmit'])) {
                        $mode = 'error';
-                       $smarty->assign("error_text", "Invalid search request"); 
<span style="color: #000000;background-color: #ddffdd">+                        $smarty->assign("error_text", "Invalid search request");
</span>           }else{
                        $pres=preg_match("/^[0-9]{6}$/",$_REQUEST['sid'],$sid);
                        if ($pres!=1) {
                                $mode = 'error';
                                $smarty->assign("error_text", "Search term doesn't look like a valid student ID");
                        } else {
-                               $url = "$apibaseurl/IsPersonMember?strCriteria=".$sid[0]."&GroupingId=6613";
-                               $apiReq = curl_init();
-                               curl_setopt($apiReq, CURLOPT_URL, $url);
-                               curl_setopt($apiReq, CURLOPT_RETURNTRANSFER, TRUE);
-                               curl_setopt($apiReq, CURLOPT_SSL_VERIFYPEER, false);
-                               curl_setopt($apiReq, CURLOPT_SSL_VERIFYHOST, false);
-
-                               $apiResult = curl_exec($apiReq);
-                               if ($apiResult === FALSE) {
-                                       $mode = 'error';
-                                       $smarty->assign("error_text", "An error occurred communicating with the SUSU API.");
-                               }else {
-                                       // Ostensibly we now have a valid search result from the SU - go to work
-                                       libxml_use_internal_errors(true);
-                                       $xml=simplexml_load_string($apiResult);
-                                       if (!$xml||isset($xml->head->title)) {
-                                               $mode='error';
-                                               $smarty->assign("error_text", "An error occurred communicating with the SUSU API");
-                                       } else {
-                                               $ismember = $xml[0];
-                                               if ($ismember=="true") {
-                                                       //Yay, we have a student who has paid and needs to be signed up.
-                                                       //Check they don't have a signup slip already
-                                                       $query = "SELECT transactionid, signupid FROM transactions WHERE cardNumber = ?;";
-                                                       $qres = $sucsDB->Execute($query, $sid);
-                                                       
-                                                       if ($qres->RecordCount()==0) {
-                                                               // No transaction, but might have unused signup slip. If so, retrieve values.
-                                                               $query = "SELECT id, username, password FROM signup WHERE sid=?;";
-                                                               $qres = $sucsDB->Execute($query, array($sid[0]));
-                                                               if ($qres && $qres->RecordCount() > 0) {
-                                                                       if ($qres->RecordCount() > 1) {
-                                                                               $mode='error';
-                                                                               $smarty->assign("error_text", "Student has multiple signup slips in the DB. Bork! Bork! Bork!");
-                                                                       } else if (!empty($qres->fields['username'])) {
-                                                                               $mode='error';
-                                                                               $smarty->assign("error_text", "Student hasn't tried to use the SU signup component (No transaction in DB), but has a previously used Signup Slip with username ".$qres->fields['username'].".<br />Is this a renewal? If not, ask an admin to generate a new signup slip for this student");
-                                                                               //TODO: Add option to generate new signup slip?
-                                                                       } else {
-                                                                               $id = $qres->fields['id'];
-                                                                               $pass = $qres->fields['password'];
-                                                                       }
-                                                               } else {
-                                                                       $pass = make_password();
-                                                                       $query = "INSERT INTO signup (password,sid,issuedby) VALUES ( ?, ?, ?) RETURNING id";
-                                                                       $attribs[]=$pass;
-                                                                       $attribs[]=$sid[0];
-                                                                       $attribs[]='99999'; //SUCS Magic internal use UID
-
-                                                                       $id = $sucsDB->Execute($query,$attribs);
-                                                                       $id = $id->fields['id'];
-                                                                       if (!$id) {
-                                                                               $mode="error";
-                                                                               $smarty->assign("error_text", "An error occurred generating a signup ID. Report the following message to the admins:<br /><pre>".$sucsDB->ErrorMsg()."</pre>");
-                                                                       } else {
-                                                                               $smarty->assign('slipid', $id);
-                                                                               $smarty->assign('slippass', $pass);
-                                                                               $smarty->assign('sid', $sid[0]);
-                                                                       }
-                                                               }
-                                                       } else {
-                                                               //Retrieve existing slip
-                                                               $id = $qres->fields['signupid'];
-                                                               $tid = $qres->fields['transactionid'];
-                                                               if (empty($id)) {
-                                                                       $pass = make_password();
-                                                                       $query = "INSERT INTO signup (password,sid,issuedby) VALUES ( ?, ?, ?) RETURNING id";
-                                                                       $attribs[]=$pass;
-                                                                       $attribs[]=$sid[0];
-                                                                       $attribs[]='99999'; //SUCS Magic internal use UID
-
-                                                                       $qres = $sucsDB->Execute($query,$attribs);
-                                                                       if (!$qres) {
-                                                                               $mode="error";
-                                                                               $smarty->assign("error_text", "An error occurred generating a signup ID. Report the following message to the admins:<br /><pre>".$sucsDB->ErrorMsg()."</pre>");
-                                                                       } else {
-                                                                               $id = $qres->fields['id'];
-                                                                               $query = "UPDATE transactions SET signupid=? WHERE transactionid=?;";
-                                                                               $qres = $sucsDB->Execute($query, array($id, $tid));
-                                                                               $smarty->assign('slipid', $id);
-                                                                               $smarty->assign('slippass', $pass);
-                                                                               $smarty->assign('sid', $sid[0]);
-                                                                       }
-
-                                                               }else {
-                                                                       $query = "SELECT username, password FROM signup WHERE id=?;";
-                                                                       $qres = $sucsDB->Execute($query, array($id));
-                                                                       if (!$qres) {
-                                                                               $mode="error";
-                                                                               $smarty->assign("error_text", "The user appears to have generated a signup ID using the SU Signup system (Slip ID: ".$id."), but the password for that slip can't be retrieved.<br />Request assistance.");
-                                                                       } else if ($qres->fields['username'] !== NULL) {
-                                                                               $mode="error";
-                                                                               $smarty->assign("error_text", "This user appears to have completed signup, with username <strong>".$qres->fields['username']."</strong><br />Check that this user exists, and offer to reset their password if necessary.");
-                                                                       }
-                                                                       $pass = $qres->fields['password'];
-                                                                       $smarty->assign('slipid', $id);
-                                                                       $smarty->assign('slippass', $pass);
-                                                                       $smarty->assign('sid', $sid[0]);
-                                                               }
-                                                       }
-
-                                                       if(!$mode=='error') {
-                                                               //Right, this should be the point where we hand off to signup
-                                                               $smarty->assign('slipid', $id);
-                                                               $smarty->assign('slippass', $pass);
-                                                               $smarty->assign('sid', $sid[0]);
-                                                       }
-
-                                               }else{
-                                                       $mode='error';
-                                                       $smarty->assign("error_text", "Student does not appear to have paid. Extract fees");
-                                               }
-                                       }
-                               }
-                       }
-               }
-       } else if ($mode=="renew") {
-               if (empty($_REQUEST['member'])){
-                       $mode='error';
-                       $smarty->assign('error_text',"Can't renew a member without knowing their username!");
-               } else if (!isset($_REQUEST['renewconf'])) {
-                       //Should be trying to renew $_REQUEST['member']
-                       $username=urldecode($_REQUEST['member']);
-                       $q = "SELECT username, typename, sid, paid, email FROM members, member_type WHERE username=?";
-                       $res = $sucsDB->Execute($q,array($username));
-                       if (!$res) {
-                               $mode='error';
-                               $smarty->assign('error_text', "A database error occurred while trying to retrieve member details");
-                       } else if ($res->fields['paid'] == paidUntil(time())) {
-                                       $mode='error';
-                                       $smarty->assign('error_text', 'User appears to have been renewed already?');
-                       } else {
-                               $smarty->assign('renew_user', $username);
-                               $smarty->assign('renew_paid', $res->fields['paid']);
-                               $smarty->assign('renew_type', $res->fields['typename']);
-                               $url = "$apibaseurl/IsPersonMember?strCriteria=".$res->fields['sid']."&GroupingId=6613";
<span style="color: #000000;background-color: #ffdddd">-                                $apiReq = curl_init();
-                                curl_setopt($apiReq, CURLOPT_URL, $url);
-                                curl_setopt($apiReq, CURLOPT_RETURNTRANSFER, TRUE);
</span>-                          curl_setopt($apiReq, CURLOPT_SSL_VERIFYPEER, false);
-                               curl_setopt($apiReq, CURLOPT_SSL_VERIFYHOST, false);
-
<span style="color: #000000;background-color: #ffdddd">-                                $apiResult = curl_exec($apiReq);
</span>-                          libxml_use_internal_errors(true);
-                               $xml=simplexml_load_string($apiResult);
-                               if (!$xml || isset($xml->head->title)) {
-                                       $mode='error';
-                                       $smarty->assign("error_text", "An error occurred communicating with the SUSU API.");
-                               } else {
-                                       $ismember = $xml[0];
-
-                                       $user = posix_getpwnam($session->username);
-
-                                       if ($ismember!="true") {
-                                               $mode='error';
-                                               $smarty->assign('error_text', 'Member does not appear to have paid via the SU system. Use the old renewals system if they have paid using some other method');;
-                                       } else {
-                                               if (renew_member($username, $user['uid'], $user['name'])) {
-                                                       message_flash("Successfully renewed");
-                                                       $mode='menu';
<span style="color: #000000;background-color: #ddffdd">+                                // they have given us a valid sid lets check to see if they have paid
+
+                               // make sure the user/admin/exec isn't an idiot
+                               // check if they are already signed up and tell them so
+                               $tmpresult = $sucsDB->Execute("SELECT * FROM members WHERE sid=?", array($_REQUEST['sid']));
+                               if($tmpresult->fields["sid"] == $sid && $tmpresult->fields["paid"] == paidUntil(time())){
+                                       // let them know they are already signed up and renewed
+                                       message_flash("You are a numpty and have already signed up and paid for this year.");
+                               // else if check to see if they have signedup and paid for the new year but haven't renewed
+                               } else if ($tmpresult->fields["sid"] == $sid && $tmpresult->fields["paid"] != paidUntil(time())){
+                                       // renew them!
+                                       renew_membership($tmpresult->fields["username"]);
+                                       // let them know that their account has been renewed
+                                       message_flash("Your SUCS account has been renewed.");
+                               }else{
+                                       if (check_su_sid($_REQUEST['sid'])) {
+                                               // lets make them a signup slip
+                                               $pass = make_password();
+                                               $query = "INSERT INTO signup (password,sid,issuedby) VALUES ( ?, ?, ?) RETURNING id";
+                                               $attribs[]=$pass;
+                                               $attribs[]=$_REQUEST['sid'];
+                                               $attribs[]='99999'; //SUCS Magic internal use UID
+
+                                               $id = $sucsDB->Execute($query,$attribs);
+                                               $id = $id->fields['id'];
+                                               if (!$id) {
+                                                       $mode="error";
+                                                       $smarty->assign("error_text", "An error occurred generating a signup ID. Report the following message to the admins:<br /><pre>".$sucsDB->ErrorMsg()."</pre>");
</span>                                           } else {
-                                                       $mode='error';
-                                                       $smarty->assign('error_text', 'An error occurred renewing account '.$username);
<span style="color: #000000;background-color: #ddffdd">+                                                        $smarty->assign('slipid', $id);
+                                                       $smarty->assign('slippass', $pass);
+                                                       $smarty->assign('sid', $_REQUEST['sid']);
</span>                                           }
-
<span style="color: #000000;background-color: #ddffdd">+                                        }else{
+                                               $mode='error';
+                                               $smarty->assign("error_text", "Student does not appear to have paid. Extract fees");
</span>                                   }
-
                                }
                        }
                }
-                       
<span style="color: #000000;background-color: #ddffdd">+        // mass renewals page
</span>   } else if ($mode == 'renewals') {
-               //Get list of members according to the SU
-               $url = "$apibaseurl/GetMemberListData?GroupingId=6613";
-               $apiReq = curl_init();
-               curl_setopt($apiReq, CURLOPT_URL, $url);
-               curl_setopt($apiReq, CURLOPT_RETURNTRANSFER, TRUE);
-               curl_setopt($apiReq, CURLOPT_SSL_VERIFYPEER, false);
-               curl_setopt($apiReq, CURLOPT_SSL_VERIFYHOST, false);
 
-               $apiResult = curl_exec($apiReq);
-               $sumembers = su_response_decode($apiResult);
-               if (!$sumembers) {
-                       $mode ='error';
-                       $smarty->assign("error_text", "An error occurred communicating with the SUSU API.");
-               } else {
                        $matches = array();
                        $others=0;
                        $paidup=0;
-                       foreach ($sumembers as $sumem) {
-                               $sucsmem = get_sucs_record($sumem['uni_card_number']);
<span style="color: #000000;background-color: #ddffdd">+                        foreach ($just_members as $sumem) {
+                               $sucsmem = get_sucs_record($sumem['card_number']);
</span>                           if ($sucsmem && $sucsmem['paid'] != paidUntil(time()) && $sucsmem['type']==1) {
-                                       $matches[]=array($sumem['firstName']." ".$sumem['lastName'], $sucsmem['realname'], $sumem['uni_card_number'], $sucsmem['username'], $sucsmem['paid']);
<span style="color: #000000;background-color: #ddffdd">+                                        $matches[]=array($sumem['purchaser'], $sucsmem['realname'], $sumem['card_number'], $sucsmem['username'], $sucsmem['paid']);
</span>                           } else if ($sucsmem && $sucsmem['paid'] == paidUntil(time())) {
                                        $others++;
                                        $paidup++;
<span style="color: #aaaaaa">@@ -238,7 +98,6 @@ if (isset($session->groups[$permission])) {
</span>                   $smarty->assign("others", $others);
                        $smarty->assign("paidup", $paidup);
                        $smarty->assign("pending", $others - $paidup);
-               }
        } else if ($mode == 'renewals2') {
                $failures = array();
                $successes = array();
<span style="color: #aaaaaa">@@ -248,8 +107,7 @@ if (isset($session->groups[$permission])) {
</span>                   $smarty->assign("error_text", "Can't renew an empty list!");
                } else {
                        foreach($_REQUEST['renew'] as $user) {
-                               $admin_user=posix_getpwnam($session->username);
-                               if (renew_member($user, $admin_user['uid'], $admin_user['name'])) {
<span style="color: #000000;background-color: #ddffdd">+                                if (admin_renew_member($user, $session->username)) {
</span>                                   $successes[]=$user;
                                } else {
                                        $failures[]=$user;
<span style="color: #aaaaaa">@@ -261,27 +119,13 @@ if (isset($session->groups[$permission])) {
</span>                   $smarty->assign("successes", count($successes));
                }
        } else if ($mode == 'list') {
-               //Get list of members according to the SU
-               $url="$apibaseurl/GetMemberListData?GroupingId=6613";
-               $apiReq = curl_init();
-               curl_setopt($apiReq, CURLOPT_URL, $url);
-               curl_setopt($apiReq, CURLOPT_RETURNTRANSFER, TRUE);
-               curl_setopt($apiReq, CURLOPT_SSL_VERIFYPEER, false);
-               curl_setopt($apiReq, CURLOPT_SSL_VERIFYHOST, false);
-
-               $apiResult = curl_exec($apiReq);
-               $sumembers = su_response_decode($apiResult);
-               if (!$sumembers) {
-                       $mode='error';
-                       $smarty->assign("error_text", "An error occurred communicating with the SUSU API.");
-               } else {
                        $matches = array();
-                       foreach ($sumembers as $sumem) {
-                               $sucsmem = get_sucs_record($sumem['uni_card_number']);
<span style="color: #000000;background-color: #ddffdd">+                        foreach ($just_members as $sumem) {
+                               $sucsmem = get_sucs_record($sumem['card_number']);
</span>                           if ($sucsmem) {
-                                       $matches[]=array($sumem['firstName']." ".$sumem['lastName'], $sucsmem['realname'], $sumem['uni_card_number'], $sucsmem['username'], $sucsmem['paid']);
<span style="color: #000000;background-color: #ddffdd">+                                        $matches[]=array($sumem['purchaser'], $sucsmem['realname'], $sumem['card_number'], $sucsmem['username'], $sucsmem['paid']);
</span>                           } else {
-                                       $matches[]=array($sumem['firstName']." ".$sumem['lastName'], "N/A", $sumem['uni_card_number'], "N/A", "Not signed up");
<span style="color: #000000;background-color: #ddffdd">+                                        $matches[]=array($sumem['purchaser'], "N/A", $sumem['card_number'], "N/A", "Not signed up");
</span>                           }
                        }
                        function sortbypaid($a, $b) {
<span style="color: #aaaaaa">@@ -290,7 +134,6 @@ if (isset($session->groups[$permission])) {
</span>                   }
                        usort($matches, 'sortbypaid');
                        $smarty->assign("matches", $matches);
-               }
        }
 $smarty->assign('renewables', get_renewable_members());
 }
<span style="color: #aaaaaa">@@ -302,17 +145,6 @@ $body = $smarty->fetch("susignup-admin.tpl");
</span> $smarty->assign('body', $body);
 $smarty->assign("extra_styles", array("$baseurl/css/susignup-admin.css"));
 
-function su_response_decode($text) {
-       global $smarty;
-       libxml_use_internal_errors(true);
-       $xml=simplexml_load_string($text);
-       if (!$xml || isset($xml->head->title)) {
-               return false;
-       } else {
-               return json_decode($xml[0],TRUE);
-       }
-} 
-
 function get_sucs_record($sid) {
        global $sucsDB;
 
<span style="color: #aaaaaa">@@ -338,37 +170,18 @@ function get_renewable_members() {
</span>   return $retvals;
 }
 
-function renew_member($renew_name, $admin_uid, $admin_name) {
-       global $sucsDB;
-
-       $q="UPDATE members SET paid=?, lastupdate=DEFAULT, lastedit=? WHERE username=?;";
-       $r=$sucsDB->Execute($q, array(paidUntil(time()), $admin_uid, $renew_name));
-       if (!$r) {
-               print $sucsDB->ErrorMsg();
-               return FALSE;
-       } else {        
<span style="color: #000000;background-color: #ddffdd">+function admin_renew_member($renew_name, $admin_name) {
+               global $sucsDB;
+               renew_member($renew_name);
</span>           $q="SELECT email, typename FROM members, member_type WHERE username=?  AND type=member_type.id;";
                $r=$sucsDB->Execute($q, array($renew_name));
-
                $message  = "Account Renewal notification\n\n";
                $message .= "Account   : ".$renew_name."\n";
                $message .= "User Type : ".$r->fields['typename']."\n";
                $message .= "Renewed by: ".$admin_name."\n\n";
                $message .= "**** Payment was made via the SU payments system ****\n";
                $message .= "Regards\n  The SU Renewals script";
-               mail("treasurer@sucs.org","Account Renewal",$message);
-               
-               $message = "Your Swansea University Computer Society (SUCS) membership has been renewed\n\n";
-               $message .= "Username: ".$renew_name."\n";
-               $message .= "If you do not know or have forgotten your password, please email admin@sucs.org to arrange for it to be changed.\n\n";
-               $message .= "Regards\n  The SUCS admin";
-               $header = "From: admin@sucs.org\r\n";
-               $header .= "Reply-To: admin@sucs.org";
-               // Personal account
-               mail($r->fields['email'],"SUCS account renewal",$message,$header);
-               // sucs account
-               mail($renew_name."@sucs.org","SUCS account renewal",$message,$header);
<span style="color: #000000;background-color: #ddffdd">+                mail("exec@sucs.org","Account Renewal",$message);
</span>           return TRUE;
-       }
-
 }
<span style="color: #000000;background-color: #ddffdd">+
</span></code></pre>

<br>
</li>
<li id='diff-2'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19#diff-2'>
<strong>
components/susignup.php
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/components/susignup.php
</span><span style="color: #000000;background-color: #ddffdd">+++ b/components/susignup.php
</span><span style="color: #aaaaaa">@@ -1,256 +1,72 @@
</span> <?php
 
-//unique society identifier
-$GroupingID = "6613";
<span style="color: #000000;background-color: #ddffdd">+// gib errars plox
+//error_reporting(E_ALL);
+//ini_set('display_errors', 1);
</span> 
<span style="color: #000000;background-color: #ddffdd">+// this is the php for sucs.org/susignup
+
+// Include shit we need. like the renew_membership fucntion
</span> include "../lib/member_functions.php";
 include "../lib/date.php";
-include "../suapi.inc.php";
 
<span style="color: #000000;background-color: #ddffdd">+// include the suapiv2 stuff like check_su_sid_and_trans()
+include "../lib/suapiv2.php";
+
+// since the rewrite by ~imranh this no longer sends out emails
+// feel free to add it
+// Where do errors go?
</span> $error_email = "admin@sucs.org";
<span style="color: #000000;background-color: #ddffdd">+
+// By default display a page asking for sid and transid
+// this is called "login"
</span> $mode = 'login';
-//login
<span style="color: #000000;background-color: #ddffdd">+
+// if somone has post'd data to the page then do shit
</span> if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){
-//set signup details
 
<span style="color: #000000;background-color: #ddffdd">+        // stick the post'd data in a variable we can call easily
</span>   $sid = $_REQUEST['sid'];
         $transactionID = $_REQUEST['transactionID'];
 
-       //set POST variables
-       $url = "https://$suapi_user:$suapi_pass@su-api.sucs.org/memberships/Membership.asmx/GetMemberByTransactionID";
-       $fields = array(
-              'transactionID'=>urlencode($transactionID),
-              'GroupingID'=>urlencode($GroupingID),
-              );
-       //url-ify the data for the POST
-       $field_string = "";
-       foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
-       rtrim($fields_string,'&');
-       //open connection
-       $ch = curl_init();
-
-       //set the url, number of POST vars, POST data
-       curl_setopt($ch,CURLOPT_URL,$url);
-       curl_setopt($ch,CURLOPT_POST,count($fields));
-       curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
-       curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
-       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
-       //execute post
-       $result = curl_exec($ch);
-
-       //close connection
-       curl_close($ch);
-       if(!$result){
-               $mode = "error";
-               $smarty->assign("error_text", "Invalid query returned");
-       } else {
-               libxml_use_internal_errors(true);
-               $xml=simplexml_load_string($result);
-               if (!$xml||isset($xml->head->title)) {
-                       $mode='error';
-                       $smarty->assign("error_text", "An error occurred communicating with the SUSU API");              
-               } else{
-                       $re1='.*?';
-                       $re2='(\\{.*?\\})';
-                       if ($c=preg_match_all ("/".$re1.$re2."/is", $result, $matches))
-                       {
-                               $json_string=$matches[1][0];
-                       } else{
-                         $mode = "error";
-                       }
-                       $array = json_decode($json_string,TRUE);
-                       if($array['cardNumber'] == $sid && $sid != ""){
-                               $mode = 'form';
-
-                               // SET THIS FOR DEBUG MODE
-                               // $sucsDB->debug = true;
-
-                               $fullName = $array['firstName']." ".$array['lastName'];
-                               $query = "INSERT INTO transactions (transactionID,fullName,emailAddress,cardNumber,personID) values(?, ?, ?, ?, ?)";
-                               $attribs[] = $transactionID;
-                               $attribs[] = $fullName;
-                               $attribs[] = $array['emailAddress'];
-                               $attribs[] = $array['cardNumber'];
-                               $attribs[] = $array['personID'];
-
-                               $valid = true;
-                               if(!$sucsDB->Execute($query,$attribs)) {
-                                       // We did this because Adodb ErrorNo command is broken
-                                       $query = "SELECT * FROM transactions WHERE transactionID = ?";
-                                       unset($attribs);
-                                       $attribs[]=$transactionID;
-                                       if($sucsDB->Execute($query,$attribs)) {
-
-                                               $query = "SELECT * FROM transactions WHERE transactionID = ?";
-                                               $attribs= array();
-                                               $attribs[]=$transactionID;
-                                               $data = $sucsDB->GetAll($query,$attribs);
-                                               if(is_array($data)&&sizeof($data)==1&&$data[0]['signupid']==NULL){
-                                                       // As it stands this shouldn't happen but if it does, no reason not to let them carry on
-                                                       $valid = true;
-                                               } elseif(is_array($data)&&sizeof($data)==1&&$data[0]['signupid']!=NULL) {
-                                                       $query = "SELECT * FROM signup WHERE sid = ?";
-                                                       unset($attribs);
-                                                       $attribs[]=$sid;
-                                                       $data = $sucsDB->Execute($query, $attribs);
-                                                       if(!$data) {
-                                                               mail(
-                                                                       $error_email,
-                                                                       "SUSignup Error",
-                                                                       "An error occured in the susignup system at stage 0\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(),
-                                                                       "From: \"SUCS Admin\" <admin@sucs.org>"
-                                                       );
-                                                               $valid=false;
-                                                       } else if($data->fields['username']!=NULL){
-                                                               $smarty->assign("username", $data->fields['username']);
-                                                               $mode='numpty2';                
-                                                               // This happens if they already ahve a SUCS account and are trying to create a new signupid
-                                                               $valid = false;
-                                                       } else {
-                                                               $smarty->assign("id", $data->fields['id']);
-                                                               $smarty->assign("pass", $data->fields['password']);
-                                                               $mode='numpty';
-                                                               // If this happens they tried to get a new signupid/pass after already getting one, and should get weekly reminders about it  
-                                                               $valid = false;
-                                                       }
-                                               } else {
-                                                       $mode="error";
-                                                       mail(
-                                                               $error_email,
-                                                               "SUSignup Error",
-                                                               "An error occured in the susignup system at stage 1\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(),
-                                                               "From: \"SUCS Admin\" <admin@sucs.org>"
-                                                       );
-
-                                                       $valid = false;
-                                               }
-
-                                       } else {
-                                               $mode="error";
-                                               mail(
-                                                       $error_email,
-                                                       "SUSignup Error",
-                                                       "An error occured in the susignup system at stage 2\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(),
-                                                       "From: \"SUCS Admin\" <admin@sucs.org>"
-                                               );
-
-                                               $valid = false;
-                                       }
-                               }
-
-                               if($valid)
-                               {
-                                       unset($attribs);
-                                       unset($query);
-                                       $query = "SELECT * FROM members WHERE sid = ?";
-                                       $attribs[] = $sid;
-                                       unset($data);
-                                       $data = $sucsDB->Execute($query, $attribs);
-                                       if (!$data) {
-                                               $mode = "error";
-                                               $smarty->assign("error_text", "Error in internal database check");
-                                       } elseif ($data->RecordCount()==1) {
-                                               $mode = "renew";
-                                               $q="UPDATE members SET paid=?, lastupdate=DEFAULT, lastedit=? WHERE username=?;";
<span style="color: #000000;background-color: #ffdddd">-                                                $r=$sucsDB->Execute($q, array(paidUntil(time()), '99999', $data->fields['username']));
</span>-                                          if (!$r) {
-                                                       mail(
-                                                               $error_email,
-                                                               "SUSignup Error",
-                                                               "An error occured in the susignup system at stage 2.5\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(),
-                                                               "From: \"SUCS Admin\" <admin@sucs.org>"
-                                                       );
-
-                                               } else {
-                                                       $q="SELECT email, typename FROM members, member_type WHERE username=?  AND type=member_type.id;";
-                                                       $r=$sucsDB->Execute($q, array($data->fields['username']));
-
-                                                       $message  = "Account Renewal notification\n\n";
-                                                       $message .= "Account   : ".$data->fields['username']."\n";
-                                                       $message .= "User Type : ".$r->fields['typename']."\n";
-                                                       $message .= "Renewed by: ".$data->fields['username'].".\n\n";
-                                                       $message .= "**** Payment was made via the SU payments system ****\n";
-                                                       $message .= "Regards\n  The SU Renewals script";
-                                                       mail("treasurer@sucs.org","Account Renewal",$message);
-
-                                                       $message = "Your Swansea University Computer Society (SUCS) membership has been renewed\n\n";
-                                                       $message .= "Username: ".$renew_name."\n";
-                                                       $message .= "If you do not know or have forgotten your password, please email admin@sucs.org to arrange for it to be changed.\n\n";
-                                                       $message .= "Regards\n  The SUCS admin";
-                                                       $header = "From: admin@sucs.org\r\n";
-                                                       $header .= "Reply-To: admin@sucs.org";
-                                                       // Personal account
-                                                       mail($r->fields['email'],"SUCS account renewal",$message,$header);
-                                                       // sucs account
-                                                       mail($data->fields['username']."@sucs.org","SUCS account renewal",$message,$header);
-                                                       unset($query);
-                                                       unset($attribs);
-                                                       $query = "UPDATE transactions set signupid=? WHERE transactionID=?";
-                                                       $attribs[]="000";
-                                                       $attribs[]=$transactionID;
-                                                       $data = $sucsDB->Execute($query,$attribs);
-                                                       if (!$data) { 
-                                                               $mode="error";
-                                                               mail(
-                                                                       $error_email,
-                                                                       "SUSignup Error",
-                                                                       "An error occured in the susignup system at stage 2.6\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(),
-                                                                       "From: \"SUCS Admin\" <admin@sucs.org>"
-                                                               );
-                                                       }
-                                               }
-                                       } else {
-                                               $pass = make_password();
-                                               unset($query);
-                                               $query = "insert into signup (password,sid,issuedby) values( ?, ?, ?) returning id";
-                                               unset($attribs);
-                                               $attribs[]=$pass;
-                                               $attribs[]=$array['cardNumber'];
-                                               $attribs[]='99999';
-
-                                               $iddata = $sucsDB->Execute($query,$attribs);
-                                               $id = $iddata->fields['id'];
-                                               if (!$iddata) {
-                                                       $mode="error";
-                                                       mail(
-                                                               $error_email,
-                                                               "SUSignup Error",
-                                                               "An error occured in the susignup system at stage 3\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(),
-                                                               "From: \"SUCS Admin\" <admin@sucs.org>"
-                                                       );
-                                               } else {
-                                                       $query = "update transactions set signupid=? WHERE transactionID=?";
-                                                       unset($attribs);
-                                                       $attribs[]=$id;
-                                                       $attribs[]=$transactionID;
-                                                       if(!$sucsDB->Execute($query,$attribs)) {
-                                                               $mode="error";
-                                                               mail(
-                                                                       $error_email,
-                                                                       "SUSignup Error",
-                                                                       "An error occured in the susignup system at stage 4\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(),
-                                                                       "From: \"SUCS Admin\" <admin@sucs.org>"
-                                                               );
-                                                               print($sucsDB->ErrorMsg());
-                                                       } else {
-                                                               $smarty->assign("id", $id);
-                                                               $smarty->assign("pass", $pass);
-                                                               mail(
-                                                                       $array['emailAddress'].','.$sid.'@swansea.ac.uk',
-                                                                       "SUCS Signup Information",
-                                                                       "Thankyou for joining Swansea University Computer Society, your signup details are below;\nSignupID: $id\nSignup Password: $pass\nIf you have successfully completed signup immediately then you can disregard this message.\n\nSUCS Admin Team.",
-                                                                       "From: \"SUCS Admin\" <admin@sucs.org>"
-                                                               );
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
<span style="color: #000000;background-color: #ddffdd">+        // check if the data posted is valid
+       if(check_su_sid_and_trans($sid,$transactionID)){
+
+               // check to see if they are already a valid and paid member
+               $tmpresult = $sucsDB->Execute("SELECT * FROM members WHERE sid=?", array($sid));
+               if($tmpresult->fields["sid"] == $sid && $tmpresult->fields["paid"] == paidUntil(time())){
+                       // let them know they are already signed up and renewed
+                       message_flash("You are a numpty and have already signed up and paid for this year.");
+               // else if check to see if they have signedup and paid for the new year but haven't renewed
+               }else if ($tmpresult->fields["sid"] == $sid && $tmpresult->fields["paid"] != paidUntil(time())){
+                       // renew them!
+                       renew_membership($tmpresult->fields["username"]);
+                       // let them know that their account has been renewed
+                       message_flash("Your SUCS account has been renewed.");
+               // else if they aren't in the SUCS DB but have a signup slip, take them back to that part of signup
+               $singuptmpresult = $sucsDB->Execute("SELECT * FROM signup WHERE sid=?", array($sid));
+               } else if ($tmpresult->fields == false && $signuptmpresult->fields["sid"] == $sid) {
+                       $mode = "form";
+                       $smarty->assign("id",$signuptmpresult->fields["id"]);
+                       $smarty->assign("pass",$signuptmpresult->fields["password"]);
+               // else if they aren't in the SUCS DB, then bootstrap signup process
+               } else if ($tmpresult->fields == false && $signuptmpresult->fields == false) {
+                       $mode = "form";
+                       $pass = make_password();
+                       $iddata = $sucsDB->Execute("insert into signup (password,sid,issuedby) values( ?, ?, ?) returning id",array($pass,$sid,"99999"));
+                       $id = $iddata->fields['id'];
+                       $smarty->assign("id", $id);
+                       $smarty->assign("pass", $pass);
+               } else {
+                       // they should never get here
+                       echo("fuck you");
</span>           }
<span style="color: #000000;background-color: #ddffdd">+        } else {
+               trigger_error("That Student Number and Transaction ID combo are invalid.", E_USER_ERROR);
</span>   }
 }
 
<span style="color: #000000;background-color: #ddffdd">+
</span> $smarty->assign("mode", $mode);
 $output = $smarty->fetch("susignup.tpl");
 
</code></pre>

<br>
</li>
<li id='diff-3'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19#diff-3'>
<strong>
lib/member_functions.php
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/lib/member_functions.php
</span><span style="color: #000000;background-color: #ddffdd">+++ b/lib/member_functions.php
</span><span style="color: #aaaaaa">@@ -107,4 +107,31 @@ function generateLdif($uid, $password, $type, $realname, $username){
</span>   return $ldif;
 }
 
<span style="color: #000000;background-color: #ddffdd">+// function to renew a persons sucs membership
+function renew_membership($username) {
+
+       // get their details from the sucs db
+       $userdata = $sucsDB->Execute("SELECT * FROM members WHERE username=?", array($username));
+
+       // include the date file so we can call the paidUntil function
+       include_once("date.php");
+
+       // Update their record in the DB
+       $sucsDB->Execute("UPDATE members SET paid=?, lastupdate=DEFAULT, lastedit=? WHERE username=?", array(paidUntil(time()), "99999", $username));
+
+       // Give them their 200 print credits
+       exec("/usr/local/sbin/printerrenew.apache ${username} 200");
+
+       // apprently sending them an email confirming so is nice
+       $message = "Your Swansea University Computer Society (SUCS) membership has been renewed\n\n";
+       $message .= "Username: ${username}\n";
+       $message .= "If you do not know or have forgotten your password, please email admin@sucs.org to arrange for it to be changed.\n\n";
+       $message .= "Regards\n  The SUCS admin";
+       $header = "From: admin@sucs.org\r\n";
+       $header .= "Reply-To: admin@sucs.org";
+       // send it to their personal account
+       mail($userdata->fields['email'],"SUCS account renewal",$message,$header);
+
+}
+
</span> ?>
</code></pre>

<br>
</li>
<li id='diff-4'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19#diff-4'>
<strong>
lib/suapiv2.php
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- /dev/null
</span><span style="color: #000000;background-color: #ddffdd">+++ b/lib/suapiv2.php
</span><span style="color: #aaaaaa">@@ -0,0 +1,78 @@
</span><span style="color: #000000;background-color: #ddffdd">+<?php
+
+// sorry
+
+
+// gib errars plox
+//error_reporting(E_ALL);
+//ini_set('display_errors', 1);
+
+// without this the entire thing doesn't work
+include_once("../suapiv2-key.php");
+
+//SUCS Org ID According to the SU
+$orgid = "6613";
+
+$apibaseurl = "http://su-apiv2.sucs.org/?apikey=${apikey}&orgid=${orgid}";
+
+// Get the shit json the suapiv2 spits out
+$ch = curl_init($apibaseurl);
+curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
+$raw_data = curl_exec($ch);
+curl_close($ch);
+$formated_raw_data = json_decode($raw_data, true); //convert it into php arrays
+/*
+* $membership_data is an array where each type of memebrship is it;s own array
+* Insdie each of those arrays the actual arrary of members is under ["Detail_Collection"]["Detail"]
+* So $membership_data[0]["Detail_Collection"]["Detail"][0] will get you the array containing the
+* first member in the data
+*/
+$membership_data = $formated_raw_data["table1"]["table1_Product_Collection"]["table1_Product"];
+
+// make a new array that just contains *every* member no matter what they bought
+$just_members = array();
+foreach ($membership_data as $typeOfMember) {
+       foreach ($typeOfMember["Detail_Collection"]["Detail"] as $member) {
+               array_push($just_members, $member["@attributes"]);
+       }
+}
+
+/* You can now use $just_members to probe member detials. It's an array of arrays which each contain:
+* transaction_id (recepit id)
+* purchaser (full name)
+* textbox6 (under 18 or not) NOT SURE OF THE FORMAT
+* card_number (student number)
+* shop_name (where they bought sucs memebrship)
+* qty (how many sucs memebrships they bought)
+* purchase_date (timestamp of when they bought memebrship)4
+*/
+
+/*
+* Used by /susignup to verify that the stduent number and transaction id combo are valid
+* returns true or false
+*/
+function check_su_sid_and_trans($sid, $transid) {
+       global $just_members;
+       foreach ($just_members as $member) {
+               if ($sid == $member["card_number"] && $transid == $member["transaction_id"]) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+/*
+* Used to verify taht a given stduent number has paid for membership via the su system.
+* returns false or true
+*/
+function check_su_sid($sid) {
+       global $just_members;
+       foreach ($just_members as $member) {
+               if ($sid == $member["card_number"]) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+?>
</span></code></pre>

<br>
</li>
<li id='diff-5'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19#diff-5'>
<strong>
templates/susignup-admin.tpl
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/templates/susignup-admin.tpl
</span><span style="color: #000000;background-color: #ddffdd">+++ b/templates/susignup-admin.tpl
</span><span style="color: #aaaaaa">@@ -67,7 +67,7 @@ The following accounts failed to renew:
</span>   The details are:<br />
        <strong>Slip ID: </strong> {$slipid}<br />
        <strong>Slip Password: </strong> {$slippass} <br />
-       <form action="https://sucs.org/signup/" method="post">
<span style="color: #000000;background-color: #ddffdd">+        <form action="{$baseurl}/signup/" method="post">
</span>           <input type=hidden name="signupid" id="id" value="{$slipid}" />
                <input type=hidden name="signuppw" id="pass" value="{$slippass}" />
                <input type=submit name="submit" value="Proceed" />
</code></pre>

<br>
</li>
<li id='diff-6'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19#diff-6'>
<strong>
templates/susignup.tpl
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/templates/susignup.tpl
</span><span style="color: #000000;background-color: #ddffdd">+++ b/templates/susignup.tpl
</span><span style="color: #aaaaaa">@@ -23,38 +23,18 @@
</span>         <div class="hollowfoot"><div><div></div></div></div>
     </div>
 </form>
-{elseif $mode=='form' || $mode=="re-form"}
<span style="color: #000000;background-color: #ddffdd">+{elseif $mode=='form'}
</span>   <h1>Signup</h1>
-               <p>To continue signup later please use the link below to dispay and print off your signup slip</p>
-               <form action="https://sucs.org/~kais58/sucstest/sucs/generate.php" method="post" target="_blank">
-                       <input type=hidden name="id" id="id" value="{$id}" />
-                       <input type=hidden name="pass" id="pass" value="{$pass}" />
-                       <input type=submit name="submit" value="Proceed" />
-               </form>
-               <p>To finish signup now click below to continue</p>
-               <form action="https://sucs.org/signup/" method="post">
<span style="color: #000000;background-color: #ddffdd">+                <p>To contiune signup now click below</p>
+               <form action="{$baseurl}/signup/" method="post">
</span>                   <input type=hidden name="signupid" id="id" value="{$id}" />
                        <input type=hidden name="signuppw" id="pass" value="{$pass}" />
                        <input type=submit name="submit" value="Proceed" />
                </form>
-{elseif $mode=='numpty'}
-               <p>You appear to have completed this part of signup before, please check your emails for your signup ID and password. Alternatively click below to continue.</p>
-               <form action="https://sucs.org/signup/" method="post">
-                       <input type=hidden name="signupid" id="id" value="{$id}" />
-                       <input type=hidden name="signuppw" id="pass" value="{$pass}" />
-                       <input type=submit name="submit" value="Proceed" />
-               </form>
-{elseif $mode=='numpty2'}
-               <p>You appear to have already completed this step and registered with SUCS with the username <strong>{$username}</strong>.<br/>If you have forgotten your login password please email <a href='mailto:admin@sucs.org'>admin@sucs.org</a> or drop by the SUCS room and find an admin.</p>
-               
-{elseif $mode=='renew'}
-       <h1>Renewed</h1>
-       <p>Thankyou for renewing your membership, it has completed succesfully</p>
 {else}
 <h1>Error</h1>
         <div class='errorbar'>
                 <strong>Error: </strong> {$error_text}
         </div>
 An error occured during signup, please email, with as much information as you can provide, <a href='mailto:admin@sucs.org'>admin@sucs.org</a> for assistance.
-{/if}
-
<span style="color: #000000;background-color: #ddffdd">+{/if}
</span>\ No newline at end of file
</code></pre>

<br>
</li>

</div>
<div class='footer' style='margin-top: 10px;'>
<p>

<br>
<a href="https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19">View it on GitLab</a>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":["merge_requests","issues","commit"],"url":"https://projects.sucs.org/sucssite/sucs-site/compare/61563af05ea7fd6373aecfd467ac0e039df18eb6...ba01da389060dee467cc3f74ac1670146db84f19"}}</script>
</p>
</div>
</body>
</html>