Handle error cases when uploading award data to external sources

This commit is contained in:
james 2007-11-30 18:20:02 +00:00
parent 389a3660c4
commit 7a6294cb95

View File

@ -181,7 +181,7 @@
curl_setopt ($ch, CURLOPT_URL,$r->external_postback); curl_setopt ($ch, CURLOPT_URL,$r->external_postback);
curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control 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_POST, 1); /// tell it to make a POST, not a GET
curl_setopt ($ch, CURLOPT_POSTFIELDS, "xml=".$_POST['xmldata']); /// put the query string here starting with "?" curl_setopt ($ch, CURLOPT_POSTFIELDS, "xml=$xmldata"); /// 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_RETURNTRANSFER, 1); /// This allows the output to be set into a variable $datastream
curl_setopt ($ch, CURLOPT_POSTFIELDSIZE, 0); curl_setopt ($ch, CURLOPT_POSTFIELDSIZE, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 360); curl_setopt ($ch, CURLOPT_TIMEOUT, 360);
@ -192,16 +192,29 @@
curl_close ($ch); /// close the curl session curl_close ($ch); /// close the curl session
echo i18n("Response from server:"); echo i18n("Response from server:");
$response=xml_parsexml($datastream); $response=xml_parsexml($datastream);
$keys=array_keys($response); if($response && is_array($response)) {
if($keys[0]=="awardwinnersresponse") { $keys=array_keys($response);
$status=$response['awardwinnersresponse'][0]['status'][0]; if($keys[0]=="awardwinnersresponse") {
if($status=="success") $status=$response['awardwinnersresponse'][0]['status'][0];
echo happy(i18n("Success")); $statusmessage=$response['awardwinnersresponse'][0]['statusmessage'][0];
if($status=="success")
echo happy(i18n("Success: %1",array($statusmessage)));
else
echo error(ucfirst($status).": ".$statusmessage); //not translated, because it came right from the server!
}
else else
echo error(ucfirst($status)); //not translated, because it came right from the server! {
echo error(i18n("Invalid XML response. Expecting '%1', received '%2'",array("awardwinnersresponse",$keys[0])));
echo "datastream: ".htmlspecialchars($datastream);
}
} }
else else
echo error(i18n("Invalid XML response. Expecting '%1', received '%2'",array("awardwinnersresponse",$keys[0]))); {
echo error(i18n("Invalid response. Couldn't parse XML or no data returned",array("awardwinnersresponse",$keys[0])));
echo "datastream: ".htmlspecialchars($datastream);
}
} }
echo "<br />"; echo "<br />";
} }