Skip to content
Snippets Groups Projects
suapiv2.php 2.23 KiB
Newer Older
Imran Hussain's avatar
Imran Hussain committed

// gib errars plox
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
Imran Hussain's avatar
Imran Hussain committed
// 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}";
Imran Hussain's avatar
Imran Hussain committed
// 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);
Imran Hussain's avatar
Imran Hussain committed
$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"];
Imran Hussain's avatar
Imran Hussain committed
// 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"]);
	}
}

Imran Hussain's avatar
Imran Hussain committed
/* 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) {
	foreach ($just_members as $member) {
		if ($sid == $member["card_number"] && $transid == $member["transaction_id"]) {
			return true;
		}
	}
	return false;
Imran Hussain's avatar
Imran Hussain committed
/*
* 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) {
Laurence Sebastian Bowes's avatar
Laurence Sebastian Bowes committed
	global $just_members;
	foreach ($just_members as $member) {
		if ($sid == $member["card_number"]) {
Laurence Sebastian Bowes's avatar
Laurence Sebastian Bowes committed
			return true;
		}
	}
	return false;
}
Laurence Sebastian Bowes's avatar
Laurence Sebastian Bowes committed
?>