Skip to content
Snippets Groups Projects
suapiv2.php 2.94 KiB
Newer Older
  • Learn to ignore specific revisions
  • 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
    
    
    function filter_array($data){
    	global $just_members;
    	// we have more than one type of member if this is true
    	if (count($data[0]["Detail_Collection"]["Detail"][0]["@attributes"]) == 7){
    		//split them up then feed them back
    		foreach ($data as $membershipType){
    		 	filter_array($membershipType);
     		}
     	// we have more then 1 of the same type of member if this is true
     	} else if (count($data["Detail_Collection"]["Detail"][0]["@attributes"]) == 7) {
     		//wack them onto the used array
     		foreach ($data["Detail_Collection"]["Detail"] as $member) {
    	 	 	array_push($just_members, $member["@attributes"]);
     	 	}
      	// we have 1 member :(
     	} else if (count($data["Detail_Collection"]["Detail"]["@attributes"]) == 7) {
    		array_push($just_members, $data["Detail_Collection"]["Detail"]["@attributes"]);
    
    Imran Hussain's avatar
    Imran Hussain committed
    	}
    
    filter_array($membership_data);
    
    
    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)
    {
        global $just_members;
        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)
    {
        global $just_members;
        foreach ($just_members as $member) {
            if ($sid == $member["card_number"]) {
                return true;
            }
        }
        return false;
    
    Laurence Sebastian Bowes's avatar
    Laurence Sebastian Bowes committed
    }
    
    Laurence Sebastian Bowes's avatar
    Laurence Sebastian Bowes committed
    ?>