diff --git a/admin/award_download.php b/admin/award_download.php index cb341a2..f61a011 100644 --- a/admin/award_download.php +++ b/admin/award_download.php @@ -76,7 +76,6 @@ case 'check': } echo ""; - $ar=$response['awardresponse'][0]; $awards = $data['awards']; $postback = $data['postback']; echo i18n("Postback URL: %1",array($postback))."
"; diff --git a/admin/curl.inc.php b/admin/curl.inc.php index 81dccb3..e90f12b 100644 --- a/admin/curl.inc.php +++ b/admin/curl.inc.php @@ -27,6 +27,29 @@ user_auth_required('committee', 'admin'); require_once('xml.inc.php'); + function xml_dearray(&$array) + { +// echo "
";print_r($array);echo "
"; + $keys = array_keys($array); + foreach($keys as $k) { + if(!is_array($array[$k])) { + echo "Not array at key $k"; + exit; + } + + if(count($array[$k]) == 1) { + $array[$k] = $array[$k][0]; + } else { + /* Leave it alone */ + } + + if(is_array($array[$k])) { + xml_dearray($array[$k]); + } + } + } + + function curl_query($fair, $data, $ysc_url='') { @@ -55,7 +78,7 @@ break; } -// echo "
Curl Send: (type:{$fair['type']}=>$url) $str
"; +// echo "
Curl Send: (type:{$fair['type']}=>$url) ".htmlspecialchars($str)."
"; $ch = curl_init(); /// initialize a cURL session curl_setopt ($ch, CURLOPT_URL, $url); @@ -70,7 +93,7 @@ $datastream = curl_exec ($ch); /// execute the curl session and return the output to a variable $datastream curl_close ($ch); /// close the curl session -// echo "
Server Returned: ".urldecode($datastream)."
"; +// echo "
Server Returned: ".htmlspecialchars(urldecode($datastream))."
"; switch($fair['type']) { case 'sfiab': @@ -78,9 +101,36 @@ break; case 'ysc': $datastream = str_replace(" standalone=\"yes\"","",$datastream); - /* Return is plaintext, make a return array */ - $ret['error'] = 0; - $ret['message'] = $datastream; + /* Return is XML, make a return array */ + $response=xml_parsexml($datastream); + /* De-array everything */ + xml_dearray($response); + $key = array_keys($response); + +// echo "
";print_r($response);echo "
"; + + switch($key[0]) { + case 'awardresponse': + /* Full response */ + $ret = $response['awardresponse']; + + /* Undo variable to array */ + $ret['awards'] = $ret['awards']['award']; + + /* Turn the awards into an array if it was dearrayed (in the case there is only one */ + if(!is_array($ret['awards'])) { + $ret['awards'] = array($ret['awards']); + } + $ret['error'] = 0; + $ret['message'] = ''; + break; + case 'awardwinnersresponse': + /* Parse return */ + $ret['error'] = ($response['awardwinnersresponse']['status'] == 'failed') ? 1 : 0; + $ret['message'] = $response['awardwinnersresponse']['statusmessage']; + break; + + } break; } // echo "
Server Returned: ";print_r($ret);echo "

";