forked from science-ation/science-ation
- Convert fair stats to JSON
This commit is contained in:
parent
ee978816b2
commit
687d4ea875
@ -28,9 +28,8 @@
|
|||||||
require_once('xml.inc.php');
|
require_once('xml.inc.php');
|
||||||
require_once('stats.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') {
|
if($fair['type'] == 'ysf') {
|
||||||
/* Map data into YSF tags */
|
/* Map data into YSF tags */
|
||||||
$y=array();
|
$y=array();
|
||||||
@ -51,22 +50,9 @@
|
|||||||
$y["proj11up"]=$stats['projects_11'];
|
$y["proj11up"]=$stats['projects_11'];
|
||||||
$y["committee"]=$stats['committee_members'];
|
$y["committee"]=$stats['committee_members'];
|
||||||
$y["judges"]=$stats['judges'];
|
$y["judges"]=$stats['judges'];
|
||||||
$xmldata=array("affiliation"=>array(
|
return $y;
|
||||||
"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));
|
|
||||||
}
|
}
|
||||||
|
return $stats;
|
||||||
$output="";
|
|
||||||
xmlCreateRecurse($xmldata);
|
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,14 +75,30 @@
|
|||||||
$server_config['fair_stats_scholarships'] = 'no';
|
$server_config['fair_stats_scholarships'] = 'no';
|
||||||
$server_config['fair_stats_delegates'] = 'no';
|
$server_config['fair_stats_delegates'] = 'no';
|
||||||
|
|
||||||
function curl_query($fair, $xml)
|
function curl_query($fair, $data)
|
||||||
{
|
{
|
||||||
|
global $output;
|
||||||
switch($fair['type']) {
|
switch($fair['type']) {
|
||||||
case 'sfiab':
|
case 'sfiab':
|
||||||
$url = $fair['url'].'/xmltransport.php';
|
$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;
|
break;
|
||||||
case 'ysf':
|
case 'ysf':
|
||||||
$url = "https://secure.ysf-fsj.ca/registration/xmlaffiliation.php";
|
$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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,25 +106,30 @@
|
|||||||
curl_setopt ($ch, CURLOPT_URL, $url);
|
curl_setopt ($ch, CURLOPT_URL, $url);
|
||||||
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=".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_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);
|
||||||
curl_setopt ($ch, CURLOPT_SSLVERSION, 3);
|
curl_setopt ($ch, CURLOPT_SSLVERSION, 3);
|
||||||
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
$datastream = curl_exec ($ch); /// execute the curl session and return the output to a variable $datastream
|
$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
|
curl_close ($ch); /// close the curl session
|
||||||
|
|
||||||
|
// echo "<pre>$datastream</pre>";
|
||||||
|
|
||||||
switch($fair['type']) {
|
switch($fair['type']) {
|
||||||
case 'sfiab':
|
case 'sfiab':
|
||||||
$d=xml_parsexml(urldecode($datastream));
|
$ret=json_decode(urldecode($datastream), true);
|
||||||
$datastream = $d['sfiab'][0];
|
|
||||||
break;
|
break;
|
||||||
case 'ysf':
|
case 'ysf':
|
||||||
|
$datastream = str_replace(" standalone=\"yes\"","",$datastream);
|
||||||
|
/* Return is plaintext, make a return array */
|
||||||
|
$ret['error'] = 0;
|
||||||
|
$ret['message'] = $datastream;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $datastream;
|
// echo "ret: ";print_r($ret);echo "<br>";
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($_GET['year']) $year=intval($_GET['year']);
|
if($_GET['year']) $year=intval($_GET['year']);
|
||||||
@ -144,14 +151,18 @@
|
|||||||
$stats[$k] = $_POST[$k];
|
$stats[$k] = $_POST[$k];
|
||||||
}
|
}
|
||||||
$stats['year'] = $year;
|
$stats['year'] = $year;
|
||||||
$xml = stats_to_xml($fair, $stats);
|
if($fair['type'] == 'ysf') {
|
||||||
|
$st = stats_to_ysf($fair, $stats);
|
||||||
|
} else {
|
||||||
|
$st = $stats;
|
||||||
|
}
|
||||||
|
|
||||||
if(function_exists('curl_init')) {
|
if(function_exists('curl_init')) {
|
||||||
$r = curl_query($fair, $xml);
|
$r = curl_query($fair, array('stats'=>$st));
|
||||||
if($r['error'][0] == 0)
|
if($r['error'] == 0)
|
||||||
echo happy(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message'][0]);
|
echo happy(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message']);
|
||||||
else
|
else
|
||||||
echo error(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message'][0]);
|
echo error(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message']);
|
||||||
// $fairs_id = -1;
|
// $fairs_id = -1;
|
||||||
// $year = $config['FAIRYEAR'];
|
// $year = $config['FAIRYEAR'];
|
||||||
} else {
|
} else {
|
||||||
@ -195,19 +206,12 @@
|
|||||||
|
|
||||||
echo notice(i18n('Getting stats request and downloading existing stats from server %1', array($fair['url'])));
|
echo notice(i18n('Getting stats request and downloading existing stats from server %1', array($fair['url'])));
|
||||||
/* Query the server to see what stats we need */
|
/* Query the server to see what stats we need */
|
||||||
$xmldata=array("sfiab"=>array(
|
$q=array('getstats' => array('year' => $year));
|
||||||
"username"=>$fair['username'],
|
|
||||||
"password"=>$fair['password'],
|
|
||||||
"getstats"=>array('year'=>$year)));
|
|
||||||
|
|
||||||
$output="";
|
$data = curl_query($fair, $q);
|
||||||
xmlCreateRecurse($xmldata);
|
|
||||||
$xml=$output;
|
|
||||||
|
|
||||||
$data = curl_query($fair, $xml);
|
if($data['error'] != 0) {
|
||||||
|
echo error("Server said: {$data['message']}<br />");
|
||||||
if($data['error'][0] != 0) {
|
|
||||||
echo error("Server said: {$data['message'][0]}<br />");
|
|
||||||
send_footer();
|
send_footer();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -218,7 +222,7 @@
|
|||||||
echo '<br /><br />';
|
echo '<br /><br />';
|
||||||
|
|
||||||
foreach($server_config as $k=>$v) {
|
foreach($server_config as $k=>$v) {
|
||||||
$server_config[$k] = $data['statconfig'][0][$k][0];
|
$server_config[$k] = $data['statconfig'][$k];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gather all stats, then we'll decide what to send */
|
/* Gather all stats, then we'll decide what to send */
|
||||||
@ -226,9 +230,9 @@
|
|||||||
$stats['year'] = $year;
|
$stats['year'] = $year;
|
||||||
|
|
||||||
/* Now, overwrite all the stats with what we pulled down from the server */
|
/* Now, overwrite all the stats with what we pulled down from the server */
|
||||||
if(is_array($data['stats'][0])) {
|
if(is_array($data['stats'])) {
|
||||||
foreach($data['stats'][0] as $k=>$v) {
|
foreach($data['stats'] as $k=>$v) {
|
||||||
$stats[$k] = $v[0];
|
$stats[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// print_r($data['stats'][0]);
|
// print_r($data['stats'][0]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user