forked from science-ation/science-ation
Update fake scripts for 2008
Add external award downloader functionality
This commit is contained in:
parent
55983aca38
commit
0f198346aa
@ -34,17 +34,222 @@
|
|||||||
if($_GET['action']=="check")
|
if($_GET['action']=="check")
|
||||||
{
|
{
|
||||||
if(count($_GET['check'])) {
|
if(count($_GET['check'])) {
|
||||||
|
require_once("xml.inc.php");
|
||||||
foreach($_GET['check'] AS $ch) {
|
foreach($_GET['check'] AS $ch) {
|
||||||
$q=mysql_query("SELECT * FROM award_sources WHERE id='".intval($ch)."'");
|
$q=mysql_query("SELECT * FROM award_sources WHERE id='".intval($ch)."'");
|
||||||
$r=mysql_fetch_object($q);
|
$r=mysql_fetch_object($q);
|
||||||
echo i18n("Checking %1 for awards...",array($r->name));
|
echo i18n("Checking %1 for awards...",array($r->name));
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
|
|
||||||
|
$req=array("awardrequest"=>array(
|
||||||
|
"username"=>$r->username,
|
||||||
|
"password"=>$r->password,
|
||||||
|
"year"=>$config['FAIRYEAR'],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$output="";
|
||||||
|
xmlCreateRecurse($req);
|
||||||
|
$xmldata=$output;
|
||||||
|
|
||||||
|
if(function_exists('curl_init'))
|
||||||
|
{
|
||||||
|
$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
|
||||||
|
|
||||||
|
echo i18n("The Remote Server said:")."<br />";
|
||||||
|
//echo notice($datastream);
|
||||||
|
$response=xml_parsexml($datastream);
|
||||||
|
$keys=array_keys($response);
|
||||||
|
if($keys[0]=="awardresponse") {
|
||||||
|
echo "<i>";
|
||||||
|
$ar=$response['awardresponse'][0];
|
||||||
|
$postback=$ar['postback'][0];
|
||||||
|
echo i18n("Postback URL: %1",array($postback))." <br />";
|
||||||
|
$numawards=count($ar['awards'][0]['award']);
|
||||||
|
echo i18n("Number of Awards: %1",array($numawards))." <br />";
|
||||||
|
foreach($ar['awards'][0]['award'] AS $award) {
|
||||||
|
$identifier=$award['identifier'][0];
|
||||||
|
$year=$award['year'][0];
|
||||||
|
echo i18n("Award Identifier: %1",array($identifier))." ";
|
||||||
|
echo i18n("Award Year: %1",array($year))."<br />";
|
||||||
|
if($year==$config['FAIRYEAR']) {
|
||||||
|
$tq=mysql_query("SELECT * FROM award_awards WHERE external_identifier='$identifier' AND year='$year'");
|
||||||
|
if($awardrecord=mysql_fetch_object($tq)) {
|
||||||
|
echo i18n("Award already exists, updating info")."<br />";
|
||||||
|
mysql_query("UPDATE award_awards SET
|
||||||
|
name='".mysql_escape_string($award['name_en'][0])."',
|
||||||
|
criteria='".mysql_escape_string($award['criteria_en'][0])."',
|
||||||
|
postback='".mysql_escape_string($postback)."'
|
||||||
|
WHERE
|
||||||
|
id='$awardrecord->id'
|
||||||
|
AND external_identifier='".mysql_escape_string($identifier)."'
|
||||||
|
AND year='$year'
|
||||||
|
");
|
||||||
|
//FIXME: update the prizes
|
||||||
|
if(is_array($award['prizes'][0]) && count($award['prizes'][0]['prize']>0))
|
||||||
|
{
|
||||||
|
$prizes=$award['prizes'][0]['prize'];
|
||||||
|
$numprizes=count($prizes);
|
||||||
|
echo i18n("Number of prizes: %1",array($numprizes))."<br />";
|
||||||
|
$pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$awardrecord->id'");
|
||||||
|
$existingprizes=array();
|
||||||
|
while($pr=mysql_fetch_object($pq)) {
|
||||||
|
$existingprizes[$pr->external_identifier]=$pr;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($prizes AS $prize) {
|
||||||
|
//if it exists -> update it
|
||||||
|
if(array_key_exists($prize['identifier'][0],$existingprizes)) {
|
||||||
|
$ep=$existingprizes[$prize['identifier'][0]];
|
||||||
|
|
||||||
|
echo " ".i18n("Updating prize %1",array($ep->external_identifier))."<br />";
|
||||||
|
mysql_query("UPDATE award_prizes SET
|
||||||
|
cash='".intval($prize['cash'][0])."',
|
||||||
|
scholarship='".intval($prize['scholarship'][0])."',
|
||||||
|
value='".intval($prize['value'][0])."',
|
||||||
|
prize='".mysql_escape_string($prize['prize_en'][0])."',
|
||||||
|
number='".intval($prize['number'][0])."',
|
||||||
|
`order`='".intval($prize['ord'][0])."'
|
||||||
|
WHERE
|
||||||
|
id='$ep->id'");
|
||||||
|
|
||||||
|
//remove it from the list
|
||||||
|
unset($existingprizes[$ep->external_identifier]);
|
||||||
|
}
|
||||||
|
else { //if it doesnt exist -> add it
|
||||||
|
echo " ".i18n("Adding prize %1",array($prize['identifier'][0]))."<br />";
|
||||||
|
|
||||||
|
mysql_query("INSERT INTO award_prizes (
|
||||||
|
award_awards_id,
|
||||||
|
cash,
|
||||||
|
scholarship,
|
||||||
|
value,
|
||||||
|
prize,
|
||||||
|
number,
|
||||||
|
`order`,
|
||||||
|
`year`,
|
||||||
|
external_identifier
|
||||||
|
) VALUES (
|
||||||
|
'$awardrecord->id',
|
||||||
|
'".intval($prize['cash'][0])."',
|
||||||
|
'".intval($prize['scholarship'][0])."',
|
||||||
|
'".intval($prize['value'][0])."',
|
||||||
|
'".mysql_escape_string($prize['prize_en'][0])."',
|
||||||
|
'".intval($prize['number'][0])."',
|
||||||
|
'".intval($prize['ord'][0])."',
|
||||||
|
'$year',
|
||||||
|
'".mysql_escape_string($prize['identifier'][0])."'
|
||||||
|
)");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if an entry exists thats not in the xml -> delete it
|
||||||
|
foreach($existingprizes AS $ep) {
|
||||||
|
echo " ".i18n("Removing prize %1",array($ep->external_identifier))."<br />";
|
||||||
|
mysql_query("DELETE FROM award_prizes WHERE id='$ep->id'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//FIXME: update the translations
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//check if the sponsor exists, if not, add them
|
||||||
|
$sponsorq=mysql_query("SELECT * FROM award_sponsors WHERE organization='".mysql_escape_string($award['sponsor'][0])."' AND year='$year'");
|
||||||
|
if($sponsorr=mysql_fetch_object($sponsorq)) {
|
||||||
|
$sponsor_id=$sponsorr->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mysql_query("INSERT INTO award_sponsors (organization,year,notes,confirmed) VALUES ('".mysql_escape_string($award['sponsor'][0])."','$year','".mysql_escape_string("Imported from external source: $r->name")."','yes')");
|
||||||
|
$sponsor_id=mysql_insert_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
echo i18n("Award does not exists, adding...")."<br />";
|
||||||
|
mysql_query("INSERT INTO award_awards (
|
||||||
|
award_types_id,
|
||||||
|
award_sponsors_id,
|
||||||
|
name,
|
||||||
|
criteria,
|
||||||
|
year,
|
||||||
|
external_identifier,
|
||||||
|
external_postback
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
2,
|
||||||
|
$sponsor_id,
|
||||||
|
'".mysql_escape_string($award['name_en'][0])."',
|
||||||
|
'".mysql_escape_string($award['criteria_en'][0])."',
|
||||||
|
'".$year."',
|
||||||
|
'".mysql_escape_string($identifier)."',
|
||||||
|
'".mysql_escape_string($postback)."'
|
||||||
|
)");
|
||||||
|
$award_id=mysql_insert_id();
|
||||||
|
|
||||||
|
//import the prizes
|
||||||
|
if(is_array($award['prizes'][0]) && count($award['prizes'][0]['prize']>0))
|
||||||
|
{
|
||||||
|
$prizes=$award['prizes'][0]['prize'];
|
||||||
|
$numprizes=count($prizes);
|
||||||
|
echo i18n("Number of prizes: %1",array($numprizes))."<br />";
|
||||||
|
foreach($prizes AS $prize) {
|
||||||
|
mysql_query("INSERT INTO award_prizes (
|
||||||
|
award_awards_id,
|
||||||
|
cash,
|
||||||
|
scholarship,
|
||||||
|
value,
|
||||||
|
prize,
|
||||||
|
number,
|
||||||
|
`order`,
|
||||||
|
`year`,
|
||||||
|
external_identifier
|
||||||
|
) VALUES (
|
||||||
|
'$award_id',
|
||||||
|
'".intval($prize['cash'][0])."',
|
||||||
|
'".intval($prize['scholarship'][0])."',
|
||||||
|
'".intval($prize['value'][0])."',
|
||||||
|
'".mysql_escape_string($prize['prize_en'][0])."',
|
||||||
|
'".intval($prize['number'][0])."',
|
||||||
|
'".intval($prize['ord'][0])."',
|
||||||
|
'$year',
|
||||||
|
'".mysql_escape_string($prize['identifier'][0])."'
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
echo error(i18n("No prizes associated with this award"));
|
||||||
|
|
||||||
|
//FIXME: import the translations & prize translations
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo error(i18n("Award is not for the current fair year... skipping"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
echo "</i>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
echo error(i18n("Invalid XML response. Expecting '%1', received '%2'",array("awardresponse",$keys[0])));
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo error("CURL Support Missing");
|
||||||
|
echo i18n("Your PHP installation does not support CURL. You will need to login to the YSF system as the regional coodinator and upload the XML data manually");
|
||||||
|
}
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
|
|
||||||
|
|
||||||
//FIXME: do the check!
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -71,4 +71,83 @@ function xmlCreateRecurse($d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Mainfunction to parse the XML defined by URL
|
||||||
|
function xml_parsexml ($String) {
|
||||||
|
$Encoding=xml_encoding($String);
|
||||||
|
$String=xml_deleteelements($String,"?");
|
||||||
|
$String=xml_deleteelements($String,"!");
|
||||||
|
$Data=xml_readxml($String,$Data,$Encoding);
|
||||||
|
return($Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get encoding of xml
|
||||||
|
function xml_encoding($String) {
|
||||||
|
if(substr_count($String,"<?xml")) {
|
||||||
|
$Start=strpos($String,"<?xml")+5;
|
||||||
|
$End=strpos($String,">",$Start);
|
||||||
|
$Content=substr($String,$Start,$End-$Start);
|
||||||
|
$EncodingStart=strpos($Content,"encoding=\"")+10;
|
||||||
|
$EncodingEnd=strpos($Content,"\"",$EncodingStart);
|
||||||
|
$Encoding=substr($Content,$EncodingStart,$EncodingEnd-$EncodingStart);
|
||||||
|
}else {
|
||||||
|
$Encoding="";
|
||||||
|
}
|
||||||
|
return $Encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Delete elements
|
||||||
|
function xml_deleteelements($String,$Char) {
|
||||||
|
while(substr_count($String,"<$Char")) {
|
||||||
|
$Start=strpos($String,"<$Char");
|
||||||
|
$End=strpos($String,">",$Start+1)+1;
|
||||||
|
$String=substr($String,0,$Start).substr($String,$End);
|
||||||
|
}
|
||||||
|
return $String;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Read XML and transform into array
|
||||||
|
function xml_readxml($String,$Data,$Encoding='') {
|
||||||
|
while($Node=xml_nextnode($String)) {
|
||||||
|
$TmpData="";
|
||||||
|
$Start=strpos($String,">",strpos($String,"<$Node"))+1;
|
||||||
|
$End=strpos($String,"</$Node>",$Start);
|
||||||
|
$ThisContent=trim(substr($String,$Start,$End-$Start));
|
||||||
|
$String=trim(substr($String,$End+strlen($Node)+3));
|
||||||
|
if(substr_count($ThisContent,"<")) {
|
||||||
|
$TmpData=xml_readxml($ThisContent,$TmpData,$Encoding);
|
||||||
|
$Data[$Node][]=$TmpData;
|
||||||
|
}else {
|
||||||
|
if($Encoding=="UTF-8") { $ThisContent=utf8_decode($ThisContent); }
|
||||||
|
$ThisContent=str_replace(">",">",$ThisContent);
|
||||||
|
$ThisContent=str_replace("<","<",$ThisContent);
|
||||||
|
$ThisContent=str_replace(""e;","\"",$ThisContent);
|
||||||
|
$ThisContent=str_replace("'","'",$ThisContent);
|
||||||
|
$ThisContent=str_replace("&","&",$ThisContent);
|
||||||
|
$Data[$Node][]=$ThisContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get next node
|
||||||
|
function xml_nextnode($String) {
|
||||||
|
if(substr_count($String,"<") != substr_count($String,"/>")) {
|
||||||
|
$Start=strpos($String,"<")+1;
|
||||||
|
while(substr($String,$Start,1)=="/") {
|
||||||
|
if(substr_count($String,"<")) { return ""; }
|
||||||
|
$Start=strpos($String,"<",$Start)+1;
|
||||||
|
}
|
||||||
|
$End=strpos($String,">",$Start);
|
||||||
|
$Node=substr($String,$Start,$End-$Start);
|
||||||
|
if($Node[strlen($Node)-1]=="/") {
|
||||||
|
$String=substr($String,$End+1);
|
||||||
|
$Node=xml_nextnode($String);
|
||||||
|
}else {
|
||||||
|
if(substr_count($Node," ")){ $Node=substr($Node,0,strpos($String," ",$Start)-$Start); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $Node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1 +1 @@
|
|||||||
68
|
69
|
||||||
|
3
db/db.update.69.sql
Normal file
3
db/db.update.69.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE `award_awards` ADD `external_identifier` VARCHAR( 32 ) DEFAULT NULL ,
|
||||||
|
ADD `external_postback` VARCHAR( 128 ) DEFAULT NULL ;
|
||||||
|
ALTER TABLE `award_prizes` ADD `external_identifier` VARCHAR( 32 ) DEFAULT NULL ;
|
@ -24,7 +24,7 @@
|
|||||||
<?
|
<?
|
||||||
include "../common.inc.php";
|
include "../common.inc.php";
|
||||||
|
|
||||||
$projq=mysql_query("SELECT id FROM registrations WHERE status='complete' OR status='paymentpending' AND year='2007'");
|
$projq=mysql_query("SELECT id FROM registrations WHERE status='complete' OR status='paymentpending' AND year='2008'");
|
||||||
while($projr=mysql_fetch_object($projq))
|
while($projr=mysql_fetch_object($projq))
|
||||||
{
|
{
|
||||||
$reg_id=$projr->id;
|
$reg_id=$projr->id;
|
||||||
|
@ -41,13 +41,13 @@ $firstnames=array("James","Bob","Ali","Erin","Julia","Dave","Steve","Bryan","Jan
|
|||||||
|
|
||||||
$lastnames=array("Grant","Browning","Mehdi","Borque","Temple","Culhane","Sargent","Sing","Belanger","Desjardin","Jones","Smith","Brown","Johnson","Williams","White","Thompson","Baker");
|
$lastnames=array("Grant","Browning","Mehdi","Borque","Temple","Culhane","Sargent","Sing","Belanger","Desjardin","Jones","Smith","Brown","Johnson","Williams","White","Thompson","Baker");
|
||||||
|
|
||||||
$domains=array("lightbox.org","microsoft.com","yahoo.com","msn.com","gmail.com","reach.net","slicer.ca","cwsf.ca"."sfiab.ca");
|
$domains=array("lightbox.org","microsoft.com","yahoo.com","msn.com","gmail.com","reach.net","slicer.ca","cwsf.ca","sfiab.ca");
|
||||||
|
|
||||||
$nouns=array("age","animal","arm","baby","ball","bat","bear","boat","camp","car","child","circle","city","cotton","design","dog","dress","duck","ear","egg","enemy");
|
$nouns=array("age","animal","arm","baby","ball","bat","bear","boat","camp","car","child","circle","city","cotton","design","dog","dress","duck","ear","egg","enemy");
|
||||||
$starters=array("effects of","study of","analysis of");
|
$starters=array("effects of","study of","analysis of");
|
||||||
$joiners=array("on","combined with","broken apart by","burned with","attacked by","left alone with");
|
$joiners=array("on","combined with","broken apart by","burned with","attacked by","left alone with");
|
||||||
|
|
||||||
$numschools=mysql_query("SELECT id FROM schools WHERE year='2007'");
|
$numschools=mysql_query("SELECT id FROM schools WHERE year='2008'");
|
||||||
while($s=mysql_fetch_object($numschools))
|
while($s=mysql_fetch_object($numschools))
|
||||||
{
|
{
|
||||||
//1 in 4 chance of actually using this school
|
//1 in 4 chance of actually using this school
|
||||||
@ -65,7 +65,7 @@ for($x=0;$x<$numprojects;$x++)
|
|||||||
$pd=rand(1,$prob_unpaid);
|
$pd=rand(1,$prob_unpaid);
|
||||||
if($pd==1) $status='paymentpending'; else $status='complete';
|
if($pd==1) $status='paymentpending'; else $status='complete';
|
||||||
|
|
||||||
$q=mysql_query("INSERT INTO registrations (num,email,start,status,year) VALUES ('$regnum','$email',NOW(),'$status',2007)");
|
$q=mysql_query("INSERT INTO registrations (num,email,start,status,year) VALUES ('$regnum','$email',NOW(),'$status',2008)");
|
||||||
if($id=mysql_insert_id())
|
if($id=mysql_insert_id())
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ for($x=0;$x<$numprojects;$x++)
|
|||||||
|
|
||||||
$firstname=getrand($firstnames);
|
$firstname=getrand($firstnames);
|
||||||
$email=strtolower($firstname)."@".getrand($domains);
|
$email=strtolower($firstname)."@".getrand($domains);
|
||||||
mysql_query("INSERT INTO students (registrations_id,firstname,lastname,email,sex,grade,year,schools_id) VALUES ('$id','$firstname','".getrand($lastnames)."','$email','$sex','$grade','2007','$schools_id')");
|
mysql_query("INSERT INTO students (registrations_id,firstname,lastname,email,sex,grade,year,schools_id) VALUES ('$id','$firstname','".getrand($lastnames)."','$email','$sex','$grade','2008','$schools_id')");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ for($x=0;$x<$numprojects;$x++)
|
|||||||
if($langnum<4) $lang="fr"; else $lang="en";
|
if($langnum<4) $lang="fr"; else $lang="en";
|
||||||
|
|
||||||
|
|
||||||
mysql_query("INSERT INTO projects (registrations_id,projectcategories_id,projectdivisions_id,title,year,req_electricity,req_table,language) VALUES ('$id','$cat','$div','$title $lang',2007,'$req_e','$req_t','$lang')");
|
mysql_query("INSERT INTO projects (registrations_id,projectcategories_id,projectdivisions_id,title,year,req_electricity,req_table,language) VALUES ('$id','$cat','$div','$title $lang',2008,'$req_e','$req_t','$lang')");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user