- Move the curl query to its own file, and modify the two spots that it's used

to just call the function
- Rework the fair editor for user friendliness.
- Beginnings of sfiab->sfiab award download (and winner upload)
This commit is contained in:
dave 2009-09-05 23:04:14 +00:00
parent fd95489426
commit dbff1e0bbc
7 changed files with 249 additions and 140 deletions

View File

@ -21,65 +21,62 @@
*/
?>
<?
require("../common.inc.php");
require_once("../user.inc.php");
require_once('../common.inc.php');
require_once('../user.inc.php');
user_auth_required('committee', 'admin');
require_once('curl.inc.php');
send_header("Download Awards",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Awards Main' => 'admin/awards.php' ));
function array_remove($needle,&$haystack) {
function array_remove($needle,&$haystack)
{
if(in_array($needle,$haystack))
unset($haystack[array_search($needle,$haystack)]);
}
if($_GET['action']=="check")
function check_source($source)
{
}
if($_GET['action']=="check") {
if(count($_GET['check'])) {
require_once("xml.inc.php");
foreach($_GET['check'] AS $checksource) {
$checksource=intval($checksource);
$q=mysql_query("SELECT * FROM award_sources WHERE id='$checksource' AND enabled='yes'");
$r=mysql_fetch_object($q);
if(!($r->username && $r->password)) {
$q=mysql_query("SELECT * FROM fairs WHERE id='$checksource'");
$fair=mysql_fetch_assoc($q);
if(!($fair['username'] && $fair['password'])) {
echo error(i18n("Username and Password are not set for source '%1'. Please set them in the SFIAB Configuration/External Award Sources editor first",array($r->name)));
continue;
}
echo i18n("Checking %1 for awards...",array($r->name));
echo i18n("Checking %1 for awards...",array($fair['name']));
echo "<br />";
$req=array("awardrequest"=>array(
"username"=>$r->username,
"password"=>$r->password,
"year"=>$config['FAIRYEAR'],
)
);
if($fair['type'] == 'ysf') {
$req=array("awardrequest"=>array(
"username"=>$r->username,
"password"=>$r->password,
"year"=>$config['FAIRYEAR'],
)
);
} else {
$req['getawards'] = array('year'=>$config['FAIRYEAR']);
}
$output="";
xmlCreateRecurse($req);
$xmldata=$output;
$data = curl_query($fair, $req);
$ch = curl_init(); /// initialize a cURL session
curl_setopt ($ch, CURLOPT_URL,"$r->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=".$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_POSTFIELDSIZE, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 360);
curl_setopt ($ch, CURLOPT_SSLVERSION, 3);
$datastream = curl_exec ($ch); /// execute the curl session and return the output to a variable $datastream
$datastream = str_replace(" standalone=\"yes\"","",$datastream);
// echo "curl close <br />";
curl_close ($ch); /// close the curl session
if($data['error'] != 0) {
echo error("Server said: {$data['message']}<br />");
send_footer();
exit;
}
echo notice(i18n('Server said: Success'));
echo i18n("The Remote Server said:")."<br />";
//echo notice($datastream);
$response=xml_parsexml($datastream);
$keys=array_keys($response);
if($keys[0]=="awardresponse") {
@ -318,7 +315,7 @@ echo mysql_error();
else
$links=true;
$q=mysql_query("SELECT * FROM award_sources WHERE enabled='yes' ORDER BY name");
$q=mysql_query("SELECT * FROM fairs WHERE enable_awards='yes' ORDER BY name");
echo "<table class=\"tableview\">";
echo "<tr><th>".i18n("Source Name")."</th>";
echo "<th>".i18n("Source Location URL")."</th>";
@ -326,16 +323,16 @@ echo mysql_error();
echo "</tr>";
while($r=mysql_fetch_object($q)) {
echo "<tr>";
echo "<td>$r->name</td>\n";
echo "<td>$r->url</td>";
echo "<td>{$r->name}</td>\n";
echo "<td>{$r->url}</td>";
echo "<td align=\"center\">";
if($links)
echo "<a href=\"award_download.php?action=check&check[]=$r->id\">".i18n("check")."</a>";
echo "<a href=\"award_download.php?action=check&check[]={$r->id}\">".i18n("check")."</a>";
else
echo "n/a";
echo "</td>";
echo "</tr>";
$checkurl.="&check[]=$r->id";
$checkurl.="&check[]={$r->id}";
}
echo "</table>\n";
echo "<br />";

84
admin/curl.inc.php Normal file
View File

@ -0,0 +1,84 @@
<?
/*
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');
function curl_query($fair, $data, $ysf_url='')
{
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':
if($ysf_url == '')
$url = $fair['url'];
else
$url = $ysf_url;
$var = 'xml';
$output="";
xmlCreateRecurse($data);
$str = $output;
break;
}
$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
// echo "<pre>$datastream</pre>";
switch($fair['type']) {
case 'sfiab':
$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;
}
// echo "ret: ";print_r($ret);echo "<br>";
return $ret;
}
?>

View File

@ -27,6 +27,7 @@
user_auth_required('committee', 'admin');
require_once('xml.inc.php');
require_once('stats.inc.php');
require_once('curl.inc.php');
function stats_to_ysf($fair, $stats)
{
@ -75,63 +76,6 @@
$server_config['fair_stats_scholarships'] = 'no';
$server_config['fair_stats_delegates'] = 'no';
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;
}
$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
// echo "<pre>$datastream</pre>";
switch($fair['type']) {
case 'sfiab':
$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;
}
// echo "ret: ";print_r($ret);echo "<br>";
return $ret;
}
if($_GET['year']) $year=intval($_GET['year']);
else $year=$config['FAIRYEAR'];
@ -153,12 +97,19 @@
$stats['year'] = $year;
if($fair['type'] == 'ysf') {
$st = stats_to_ysf($fair, $stats);
$req = array('affiliation' => array(
"ysf_region_id"=>$fair['username'],
"ysf_region_password"=>$fair['password'],
"year"=>$year,
'stats'=>$st)
);
} else {
$st = $stats;
$req = array('stats'=>$stats);
}
if(function_exists('curl_init')) {
$r = curl_query($fair, array('stats'=>$st));
$r = curl_query($fair, $req,
'https://secure.ysf-fsj.ca/registration/xmlaffiliation.php');
if($r['error'] == 0)
echo happy(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message']);
else
@ -203,20 +154,22 @@
exit;
}
if($fair['type'] == 'ysf') {
$data['statconfig'] = array('fair_stats_participation');
} else {
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 */
$q=array('getstats' => array('year' => $year));
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 */
$q=array('getstats' => array('year' => $year));
$data = curl_query($fair, $q);
$data = curl_query($fair, $q);
if($data['error'] != 0) {
echo error("Server said: {$data['message']}<br />");
send_footer();
exit;
if($data['error'] != 0) {
echo error("Server said: {$data['message']}<br />");
send_footer();
exit;
}
echo notice(i18n('Server said: Success'));
}
echo notice(i18n('Server said: Success'));
echo '<hr />';
echo i18n('This server has requested the following stats for your %1 fair:', array($year));
echo '<br /><br />';

View File

@ -27,7 +27,12 @@
user_auth_required('committee', 'admin');
$tabs = array('personal' => array(
$tabs = array( 'fairinfo' => array(
'name' => 'Fair Information',
'types' => array('fair'),
'file' => '../fair_info.php',
'enabled' => true,),
'personal' => array(
'name' => 'Personal',
'types' => array('student','judge','committee','volunteer','sponsor','fair'),
'file' => '../user_personal.php',
@ -63,16 +68,9 @@ $tabs = array('personal' => array(
'file' => '../volunteer_position.php',
'enabled' => true,),
'fairinfo' => array(
'name' => 'Fair Information',
'types' => array('fair'),
'file' => '../fair_info.php',
'enabled' => true,),
);
$selected = $_GET['tab'];
if(!array_key_exists($selected, $tabs)) $selected = 'personal';
if(array_key_exists('username',$_GET)) {
$username = $_GET['username'];
@ -97,6 +95,16 @@ echo mysql_error();
}
$u = user_load($id);
$selected = $_GET['tab'];
if(!array_key_exists($selected, $tabs)) {
if(in_array('fair', $u['types']) )
$selected = 'fairinfo';
else
$selected = 'personal';
}
send_popup_header(i18n("User Editor").": {$u['name']}");
?>

View File

@ -1 +1 @@
128
129

View File

@ -27,6 +27,8 @@
require_once("user.inc.php");
require_once("fair.inc.php");
$fair_type = array('feeder' => 'Feeder Fair', 'sfiab' => 'SFIAB Upstream', 'ysf' => 'YSF/CWSF Upstream');
function yesno($name, $val)
{
echo "<select name=\"$name\">";
@ -45,7 +47,6 @@
$u = user_load($_SESSION['users_id']);
}
$fair_type = array('feeder' => 'Feeder Fair', 'sfiab' => 'SFIAB Upstream', 'ysf' => 'YSF/CWSF Upstream');
if($_POST['action']=="save")
{
@ -115,52 +116,97 @@ if($_SESSION['embed'] == true) {
}
$s = ($_SESSION['embed'] == true) ? $_SESSION['embed_submit_url'] : 'fair_info.php';
echo "<form name=\"personalform\" method=\"post\" action=\"$s\">\n";
echo "<form name=\"fairinfo\" method=\"post\" action=\"$s\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save\" />\n";
echo "<input type=\"hidden\" name=\"id\" value=\"{$f['id']}\" />\n";
echo "<table>\n";
echo '<tr><td>'.i18n('Fair Name').'</td><td>';
echo "<input type=\"text\" name=\"name\" value=\"{$f['name']}\" size=\"40\" />";
echo '<tr><td>'.i18n('Fair Abbreviation').'</td><td>';
echo "<input type=\"text\" name=\"abbrv\" value=\"{$f['abbrv']}\" size=\"7\" />";
echo '<tr><td>'.i18n('Fair Type').'</td><td>';
echo "<select name=\"type\">";
echo "<table class=\"usereditor\">\n";
echo '<tr><td class="left">'.i18n('Fair Type').':</td><td class="right">';
echo "<select name=\"type\" id=\"type\" >";
foreach($fair_type as $k=>$o) {
$s = ($f['type'] == $k) ? 'selected="selected"' : '';
echo "<option value=\"$k\" $s >".i18n($o)."</option>";
}
echo "</select></td></tr>";
echo '<tr><td>'.i18n('URL').'</td><td>';
echo '<tr><td class="left">'.i18n('Fair Name').':</td><td class="right">';
echo "<input type=\"text\" name=\"name\" value=\"{$f['name']}\" size=\"40\" />";
echo '<tr><td class="left">'.i18n('Fair Abbreviation').':</td><td class="right">';
echo "<input type=\"text\" name=\"abbrv\" value=\"{$f['abbrv']}\" size=\"7\" />";
echo '<tr><td class="left">'.i18n('Fair Website').':</td><td class="right">';
if($f['website'] == '') $f['website'] = 'http://';
echo "<input type=\"text\" name=\"website\" value=\"{$f['website']}\" size=\"40\" />";
echo '</td></tr>';
echo '</table>';
/* All upstream stuff */
echo '<div id="upstream">';
echo "<table class=\"usereditor\">\n";
echo '<tr><td class="left">'.i18n('Upstream URL').':</td><td class="right">';
if($f['url'] == '') $f['url'] = 'http://';
echo "<input type=\"text\" name=\"url\" value=\"{$f['url']}\" size=\"40\" />";
echo '</td></tr>';
echo '<tr><td>'.i18n('Website').'</td><td>';
if($f['website'] == '') $f['website'] = 'http://';
echo "<input type=\"text\" name=\"webiste\" value=\"{$f['webiste']}\" size=\"40\" />";
echo '</td></tr>';
echo '<tr><td>'.i18n('Username').'</td><td>';
echo '<tr><td class="left">'.i18n('Upstream Username').':</td><td class="right">';
echo "<input type=\"text\" name=\"username\" value=\"{$f['username']}\" size=\"20\" />";
echo '</td></tr>';
echo '<tr><td>'.i18n('Password').'</td><td>';
echo '<tr><td class="left">'.i18n('Upstream Password').':</td><td class="right">';
echo "<input type=\"text\" name=\"password\" value=\"{$f['password']}\" size=\"15\" />";
echo '</td></tr>';
echo '<tr><td>'.i18n('Enable stats').'</td><td>';
echo '<tr><td class="left">'.i18n('Enable stats upload').':</td><td class="right">';
yesno('enable_stats', $f['enable_stats']);
echo '</td></tr>';
echo '<tr><td>'.i18n('Enable awards download').'</td><td>';
echo '<tr><td class="left">'.i18n('Enable awards download').':</td><td class="right">';
yesno('enable_awards', $f['enable_awards']);
echo '</td></tr>';
echo '<tr><td>'.i18n('Enable winners upload').'</td><td>';
echo '<tr><td class="left">'.i18n('Enable winners upload').':</td><td class="right">';
yesno('enable_winners', $f['enable_winners']);
echo '</td></tr>';
/* End upstream stuff */
echo "</table>";
echo i18n('* Use the \'Personal\' tab to specify contact information for someone at this fair.');
echo '</div>';
echo '<div id="feeder">';
echo i18n('* The feeder fair must login to this SFIAB to download award lists
and upload statistics and winners. Use the \'Personal\' tab to specify an
email and password for the feeder fair, use the email address of a contact at
the feeder fair. Then give the email/password to that person so they can configure
their own SFIAB to upload data to this SFIAB.'); echo '</div>';
echo "</table>";
echo "<br />";
echo "<input type=\"submit\" value=\"".i18n("Save Fair Information")."\" />\n";
echo "</form>";
echo "<br />";
if($_SESSION['embed'] != true) send_footer();
?>
<script language="javascript" type="text/javascript">
<!--
var fairtype=document.getElementById("type");
fairtype.onchange=function() { /* Hook onto the onchange */
var type = this.options[this.selectedIndex].value;
var upstream_div = document.getElementById("upstream");
var feeder_div = document.getElementById("feeder");
if(type == "feeder") {
upstream_div.style.display="none";
feeder_div.style.display="block";
} else if(type == "sfiab") {
upstream_div.style.display="block";
feeder_div.style.display="none";
} else {
upstream_div.style.display="block";
feeder_div.style.display="none";
}
return true;
}
fairtype.onchange();
-->
</script>
<?
?>

View File

@ -458,3 +458,24 @@ ul#htabs a:hover {
background: #EEEEFF; /* Should match selected tab background */
border-color: #A5B5C6;/* Should match UL border */
}
table.usereditor {
width: 100%;
}
table.usereditor td.left {
width: 30%;
vertical-align: middle;
text-align: right;
padding-right: 5px;
}
table.usereditor td.right {
width: 70%;
vertical-align: middle;
text-align: left;
}