diff --git a/admin/fair_stats.php b/admin/fair_stats.php index cd57523..0e40f63 100644 --- a/admin/fair_stats.php +++ b/admin/fair_stats.php @@ -28,9 +28,8 @@ require_once('xml.inc.php'); require_once('stats.inc.php'); - function stats_to_xml($fair, $stats) + function stats_to_ysf($fair, $stats) { - global $output; if($fair['type'] == 'ysf') { /* Map data into YSF tags */ $y=array(); @@ -51,22 +50,9 @@ $y["proj11up"]=$stats['projects_11']; $y["committee"]=$stats['committee_members']; $y["judges"]=$stats['judges']; - $xmldata=array("affiliation"=>array( - "ysf_region_id"=>$fair['username'], - "ysf_region_password"=>$fair['password'], - "year"=>$year, - "stats"=>$y) - ); - } else { - $xmldata=array("sfiab"=>array( - "username"=>$fair['username'], - "password"=>$fair['password'], - "stats"=>$stats)); - } - - $output=""; - xmlCreateRecurse($xmldata); - return $output; + return $y; + } + return $stats; } @@ -89,14 +75,30 @@ $server_config['fair_stats_scholarships'] = 'no'; $server_config['fair_stats_delegates'] = 'no'; - function curl_query($fair, $xml) + function curl_query($fair, $data) { + global $output; switch($fair['type']) { case 'sfiab': $url = $fair['url'].'/xmltransport.php'; + $var = 'json'; + $d = array(); + $d['auth'] = array('username' => $fair['username'], + 'password' => $fair['password']); + $str = json_encode(array_merge($d, $data)); break; case 'ysf': $url = "https://secure.ysf-fsj.ca/registration/xmlaffiliation.php"; + $var = 'xml'; + $d = array(); + $d['affiliation'] = array( + "ysf_region_id"=>$fair['username'], + "ysf_region_password"=>$fair['password'], + "year"=>$year); + foreach($data as $k=>$v) $d['affiliation'][$k] = $v; + $output=""; + xmlCreateRecurse($d); + $str = $output; break; } @@ -104,25 +106,30 @@ curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control curl_setopt ($ch, CURLOPT_POST, 1); /// tell it to make a POST, not a GET - curl_setopt ($ch, CURLOPT_POSTFIELDS, "xml=".urlencode($xml)); /// put the query string here starting with "?" + curl_setopt ($ch, CURLOPT_POSTFIELDS, "$var=".urlencode($str)); /// put the query string here starting with "?" curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); /// This allows the output to be set into a variable $datastream curl_setopt ($ch, CURLOPT_POSTFIELDSIZE, 0); curl_setopt ($ch, CURLOPT_TIMEOUT, 360); curl_setopt ($ch, CURLOPT_SSLVERSION, 3); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); $datastream = curl_exec ($ch); /// execute the curl session and return the output to a variable $datastream - $datastream = str_replace(" standalone=\"yes\"","",$datastream); curl_close ($ch); /// close the curl session +// echo "
$datastream"; + switch($fair['type']) { case 'sfiab': - $d=xml_parsexml(urldecode($datastream)); - $datastream = $d['sfiab'][0]; + $ret=json_decode(urldecode($datastream), true); break; case 'ysf': + $datastream = str_replace(" standalone=\"yes\"","",$datastream); + /* Return is plaintext, make a return array */ + $ret['error'] = 0; + $ret['message'] = $datastream; break; } - return $datastream; +// echo "ret: ";print_r($ret);echo "