2009-09-09 00:26:12 +00:00
|
|
|
<?
|
|
|
|
/*
|
|
|
|
This file is part of the 'Science Fair In A Box' project
|
|
|
|
SFIAB Website: http://www.sfiab.ca
|
|
|
|
|
|
|
|
Copyright (C) 2007 James Grant <james@lightbox.org>
|
|
|
|
Copyright (C) 2009 David Grant <dave@lightbox.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
|
|
|
License as published by the Free Software Foundation, version 2.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
?>
|
|
|
|
<?
|
|
|
|
require_once('../common.inc.php');
|
|
|
|
require_once('../user.inc.php');
|
|
|
|
user_auth_required('committee', 'admin');
|
|
|
|
require_once('xml.inc.php');
|
|
|
|
|
2010-02-12 05:34:12 +00:00
|
|
|
function xml_dearray(&$array)
|
|
|
|
{
|
|
|
|
// echo "<pre>";print_r($array);echo "</pre>";
|
|
|
|
$keys = array_keys($array);
|
|
|
|
foreach($keys as $k) {
|
|
|
|
if(!is_array($array[$k])) {
|
|
|
|
echo "Not array at key $k";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2010-02-12 14:16:19 +00:00
|
|
|
/* Special cases, leave these as arrays of entries */
|
|
|
|
if($k == 'award' || $k == 'prize') {
|
|
|
|
foreach($array[$k] as &$a) {
|
|
|
|
xml_dearray($a);
|
|
|
|
}
|
|
|
|
continue;
|
2010-02-12 05:34:12 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 14:16:19 +00:00
|
|
|
if(count($array[$k]) != 1) {
|
|
|
|
echo "Unexpected multielement array, stop.";
|
|
|
|
exit;
|
|
|
|
};
|
|
|
|
$array[$k] = $array[$k][0];
|
|
|
|
|
2010-02-12 05:34:12 +00:00
|
|
|
if(is_array($array[$k])) {
|
|
|
|
xml_dearray($array[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-09 00:26:12 +00:00
|
|
|
|
2009-09-19 06:13:22 +00:00
|
|
|
function curl_query($fair, $data, $ysc_url='')
|
2009-09-09 00:26:12 +00:00
|
|
|
{
|
|
|
|
global $output;
|
|
|
|
switch($fair['type']) {
|
|
|
|
case 'sfiab':
|
2009-09-22 06:35:49 +00:00
|
|
|
$url = $fair['url'].'/remote.php';
|
2009-09-09 00:26:12 +00:00
|
|
|
$var = 'json';
|
|
|
|
$d = array();
|
|
|
|
$d['auth'] = array('username' => $fair['username'],
|
|
|
|
'password' => $fair['password']);
|
|
|
|
$str = json_encode(array_merge($d, $data));
|
|
|
|
break;
|
2009-09-19 06:13:22 +00:00
|
|
|
case 'ysc':
|
|
|
|
if($ysc_url == '')
|
2009-09-09 00:26:12 +00:00
|
|
|
$url = $fair['url'];
|
|
|
|
else
|
2009-09-19 06:13:22 +00:00
|
|
|
$url = $ysc_url;
|
2009-09-09 00:26:12 +00:00
|
|
|
$var = 'xml';
|
|
|
|
$output="";
|
|
|
|
xmlCreateRecurse($data);
|
|
|
|
$str = $output;
|
|
|
|
break;
|
2010-01-12 06:43:22 +00:00
|
|
|
default:
|
|
|
|
echo "Unknown fair type {$fair['type']}";
|
|
|
|
break;
|
2009-09-09 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 05:34:12 +00:00
|
|
|
// echo "<pre>Curl Send: (type:{$fair['type']}=>$url) ".htmlspecialchars($str)."</pre>";
|
2009-09-09 00:26:12 +00:00
|
|
|
|
|
|
|
$ch = curl_init(); /// initialize a cURL session
|
|
|
|
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, "$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
|
|
|
|
curl_close ($ch); /// close the curl session
|
|
|
|
|
2010-02-12 05:34:12 +00:00
|
|
|
// echo "<pre>Server Returned: ".htmlspecialchars(urldecode($datastream))."</pre>";
|
2009-09-09 00:26:12 +00:00
|
|
|
|
|
|
|
switch($fair['type']) {
|
|
|
|
case 'sfiab':
|
|
|
|
$ret=json_decode(urldecode($datastream), true);
|
|
|
|
break;
|
2009-09-19 06:13:22 +00:00
|
|
|
case 'ysc':
|
2009-09-09 00:26:12 +00:00
|
|
|
$datastream = str_replace(" standalone=\"yes\"","",$datastream);
|
2010-02-12 05:34:12 +00:00
|
|
|
/* Return is XML, make a return array */
|
|
|
|
$response=xml_parsexml($datastream);
|
|
|
|
/* De-array everything */
|
|
|
|
xml_dearray($response);
|
|
|
|
$key = array_keys($response);
|
|
|
|
|
|
|
|
// echo "<pre>";print_r($response);echo "</pre>";
|
|
|
|
|
|
|
|
switch($key[0]) {
|
|
|
|
case 'awardresponse':
|
|
|
|
/* Full response */
|
|
|
|
$ret = $response['awardresponse'];
|
|
|
|
|
|
|
|
/* Undo variable to array */
|
|
|
|
$ret['awards'] = $ret['awards']['award'];
|
2010-02-12 14:16:19 +00:00
|
|
|
foreach($ret['awards'] as &$a)
|
|
|
|
$a['prizes'] = $a['prizes']['prize'];
|
2010-02-12 05:34:12 +00:00
|
|
|
|
|
|
|
$ret['error'] = 0;
|
|
|
|
$ret['message'] = '';
|
|
|
|
break;
|
|
|
|
case 'awardwinnersresponse':
|
|
|
|
/* Parse return */
|
|
|
|
$ret['error'] = ($response['awardwinnersresponse']['status'] == 'failed') ? 1 : 0;
|
|
|
|
$ret['message'] = $response['awardwinnersresponse']['statusmessage'];
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2009-09-09 00:26:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-17 07:13:51 +00:00
|
|
|
// echo "<pre>Server Returned: ";print_r($ret);echo "</pre><br>";
|
2009-09-09 00:26:12 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
?>
|