Skip to content
Snippets Groups Projects
Commit 83d91a6d authored by Callum Massey's avatar Callum Massey
Browse files

Added initial version of SU API implementation for freshers fayre, still needs...

Added initial version of SU API implementation for freshers fayre, still needs error checking adding, though now ready for testing, improvements welcome.
parent 7d206903
No related branches found
No related tags found
No related merge requests found
<?php
//unique society identifier
$GroupingID = "6613";
include "../lib/member_functions.php";
include "../suapi.inc.php";
$mode = 'login';
//login
if(isset($_REQUEST['sid'])&&isset($_REQUEST['transactionID'])&&$_REQUEST['sid']!=''&&$_REQUEST['transactionID']!=''){
//set signup details
$sid = $_REQUEST['sid'];
$transactionID = $_REQUEST['transactionID'];
//set POST variables
$url = "https://'$suapi_user':'$suapi_pass'@hap.swansea-union.co.uk/memberships/Membership.asmx/GetMemberByTransactionID";
$fields = array(
'transactionID'=>urlencode($transactionID),
'GroupingID'=>urlencode($GroupingID),
);
//url-ify the data for the POST
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);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
if(!result){
//HTTP Error
}else{
$re1='.*?';
$re2='(\\{.*?\\})';
if ($c=preg_match_all ("/".$re1.$re2."/is", $result, $matches))
{
$json_string=$matches[1][0];
}else{
//ERROR
}
$array = json_decode($json_string,TRUE);
if($array['cardNumber'] == $sid && $sid != ""){
$mode = 'form';
// connect to sucs database
$sucsDB = NewADOConnection('postgres8');
// SET THIS FOR DEBUG MODE
$sucsDB->debug = true;
// SET THIS TO YOUR DB FOR TESTING
$sucsDB->Connect('dbname=sucs');
$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC);
$query = "INSERT INTO transactions (transactionID,fullName,emailAddress,cardNumber,personID) values(?, ? ?, ?, ?, ?)";
$attribs[]=$transactionID;
$attribs[]=$array['firstName'];
$attribs[]=$array['lastName'];
$attribs[]=$array['emailAddress'];
$attribs[]=$array['cardNumber'];
$attribs[]=$array['personID'];
if(!$sucsDB->Execute($query,$attribs)) {
unset($query);
unset($attribs);
$query = "SELECT * FROM transactions WHERE transactionID = ? AND signupid IS NULL";
$attribs[]=$transactionID;
$data = $sucsDB->GetAll($query,$attribs);
if(is_array($data)&&sizeof($data)==1){
//ERROR SOMEONE TRIED TO USE SAME TRANSACTIONID TWICE SIGNUP SLIP ALREADY GENERATED
// MAIL ERROR MESSAGE THEN DIE
die();
}
}
$pass = make_password();
unset($query);
$query = "insert into signup (password,sid,issuedby) values( ?, ?, ?) returning id";
unset($attribs);
$attribs[]=addslashes($pass);
$attribs[]=$array['cardNumber'];
$attribs[]='SUSU API';
$id = $sucsDB->Execute($query,$attribs);
if (!$id) {
echo "Entering id $id failed.<br>\n";
} else {
unset($query);
$query = "update transactions set signupid = ? WHERE transactionID = ?";
unset($attribs);
$attribs[]=$id;
$attribs[]=$transactionID;
if(!$sucsDB->Execute($query,$attibs)) {
//ERROR
} else {
$smarty->assign("id", $id);
$smarty->assign("pass", $pass);
}
}
}
}
}
$smarty->assign("mode", $mode);
$output = $smarty->fetch("susignup.tpl");
$smarty->assign("title", "Join");
$smarty->assign("body", $output);
?>
{if $mode=='login'}
<form action="{$componentpath}" method="post">
<div class="box" style="width: 70%; margin: auto;">
<div class="boxhead"><h2>Membership Signup</h2></div>
<div class="boxcontent">
<p>Please enter the details from your transaction receipt</p>
<div class="row">
<label for="sid">Student Number:</label>
<span class="textinput"><input type="text" size="20" name="sid" id="sid" /></span>
</div>
<div class="row">
<label for="transactionID">Transaction ID:</label>
<span class="textinput"><input type="text" size="20" name="transactionID" id="transactionID" /></span>
</div>
<div class="row"><span class="textinput">
<input type="submit" name="submit" value="Join" /></span>
</div>
<div class="clear"></div>
<div class="note">If you wish to renew an existing account instead, please login to <a href="https://sucs.org/Options">Membership Options</a> using your existing account details.</div>
</div>
<div class="hollowfoot"><div><div></div></div></div>
</div>
</form>
{elseif $mode=='form' || $mode=="re-form"}
<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" value={$id}/>
<input type=hidden name="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">
<input type=hidden name="signupid" value={$id}/>
<input type=hidden name="signuppw" value={$pass}/>
<input type=submit name="submit" value="Proceed" />
</form>
{else}
<h1>Error</h1>
An error occured during signup, please email <a href='mailto:admin@sucs.org'>admin@sucs.org</a> for assistance.
{/if}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment