Dont check CURL support inside the loop and dont allow checking to be called without CURL support

Remove awards that were previously added but now dissappeared from the XML import
This commit is contained in:
james 2007-11-28 18:46:32 +00:00
parent 4917bc3a75
commit 325c909432
3 changed files with 240 additions and 201 deletions

View File

@ -30,13 +30,19 @@
'Administration' => 'admin/index.php', 'Administration' => 'admin/index.php',
'Awards Main' => 'admin/awards.php' )); 'Awards Main' => 'admin/awards.php' ));
function array_remove($needle,&$haystack) {
if(in_array($needle,$haystack))
unset($haystack[array_search($needle,$haystack)]);
}
if($_GET['action']=="check") if($_GET['action']=="check")
{ {
if(count($_GET['check'])) { if(count($_GET['check'])) {
require_once("xml.inc.php"); require_once("xml.inc.php");
foreach($_GET['check'] AS $ch) { foreach($_GET['check'] AS $checksource) {
$q=mysql_query("SELECT * FROM award_sources WHERE id='".intval($ch)."'"); $checksource=intval($checksource);
$q=mysql_query("SELECT * FROM award_sources WHERE id='$checksource'");
$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 />";
@ -52,8 +58,6 @@
xmlCreateRecurse($req); xmlCreateRecurse($req);
$xmldata=$output; $xmldata=$output;
if(function_exists('curl_init'))
{
$ch = curl_init(); /// initialize a cURL session $ch = curl_init(); /// initialize a cURL session
curl_setopt ($ch, CURLOPT_URL,"$r->url"); curl_setopt ($ch, CURLOPT_URL,"$r->url");
curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control
@ -73,6 +77,14 @@
$response=xml_parsexml($datastream); $response=xml_parsexml($datastream);
$keys=array_keys($response); $keys=array_keys($response);
if($keys[0]=="awardresponse") { if($keys[0]=="awardresponse") {
//get a list of all the existing awards for this external source
$aq=mysql_query("SELECT * FROM award_awards WHERE award_sources_id='$checksource' AND year='".$config['FAIRYEAR']."'");
$existingawards=array();
while($ar=mysql_fetch_object($aq)) {
$existingawards[]=$ar->id;
}
echo "<i>"; echo "<i>";
$ar=$response['awardresponse'][0]; $ar=$response['awardresponse'][0];
$postback=$ar['postback'][0]; $postback=$ar['postback'][0];
@ -84,11 +96,17 @@
$year=$award['year'][0]; $year=$award['year'][0];
echo i18n("Award Identifier: %1",array($identifier))." &nbsp; "; echo i18n("Award Identifier: %1",array($identifier))." &nbsp; ";
echo i18n("Award Year: %1",array($year))."<br />"; echo i18n("Award Year: %1",array($year))."<br />";
echo i18n("Award Name: %1",array($award['name_en'][0]))."<br />";
if($year==$config['FAIRYEAR']) { if($year==$config['FAIRYEAR']) {
$tq=mysql_query("SELECT * FROM award_awards WHERE external_identifier='$identifier' AND year='$year'"); $tq=mysql_query("SELECT * FROM award_awards WHERE external_identifier='$identifier' AND year='$year'");
if($awardrecord=mysql_fetch_object($tq)) { if($awardrecord=mysql_fetch_object($tq)) {
echo i18n("Award already exists, updating info")."<br />"; echo i18n("Award already exists, updating info")."<br />";
//remove it from the existingawards list
array_remove($awardrecord->id,$existingawards);
//check if the sponsor exists, if not, add them //check if the sponsor exists, if not, add them
$sponsorq=mysql_query("SELECT * FROM award_sponsors WHERE organization='".mysql_escape_string($award['sponsor'][0])."'"); $sponsorq=mysql_query("SELECT * FROM award_sponsors WHERE organization='".mysql_escape_string($award['sponsor'][0])."'");
if($sponsorr=mysql_fetch_object($sponsorq)) { if($sponsorr=mysql_fetch_object($sponsorq)) {
@ -199,7 +217,8 @@ echo mysql_error();
criteria, criteria,
year, year,
external_identifier, external_identifier,
external_postback external_postback,
award_sources_id
) )
VALUES ( VALUES (
2, 2,
@ -208,7 +227,8 @@ echo mysql_error();
'".mysql_escape_string($award['criteria_en'][0])."', '".mysql_escape_string($award['criteria_en'][0])."',
'".$year."', '".$year."',
'".mysql_escape_string($identifier)."', '".mysql_escape_string($identifier)."',
'".mysql_escape_string($postback)."' '".mysql_escape_string($postback)."',
'$checksource'
)"); )");
$award_id=mysql_insert_id(); $award_id=mysql_insert_id();
@ -252,19 +272,21 @@ echo mysql_error();
{ {
echo error(i18n("Award is not for the current fair year... skipping")); echo error(i18n("Award is not for the current fair year... skipping"));
} }
echo "<br />";
} }
echo "</i>"; echo "</i>";
//remove any awards that are left in the $existingawards array, they must have been removed from the source
foreach($existingawards AS $aid) {
echo i18n("Removing award id %1 that was removed from external source",array($aid));
mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$aid'");
mysql_query("DELETE FROM award_awards WHERE id='$aid'");
}
} }
else else
echo error(i18n("Invalid XML response. Expecting '%1', received '%2'",array("awardresponse",$keys[0]))); 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 />";
} }
} }
@ -273,6 +295,16 @@ echo mysql_error();
} }
else else
{ {
if(!function_exists('curl_init'))
{
echo error(i18n("CURL Support Missing"));
echo notice(i18n("Your PHP installation does not support CURL. You will need to have CURL support added by your system administrator before being able to access external award sources"));
$links=false;
}
else
$links=true;
$q=mysql_query("SELECT * FROM award_sources ORDER BY name"); $q=mysql_query("SELECT * FROM award_sources ORDER BY name");
echo "<table class=\"tableview\">"; echo "<table class=\"tableview\">";
echo "<tr><th>".i18n("Source Name")."</th>"; echo "<tr><th>".i18n("Source Name")."</th>";
@ -283,13 +315,19 @@ echo mysql_error();
echo "<tr>"; echo "<tr>";
echo "<td>$r->name</td>\n"; echo "<td>$r->name</td>\n";
echo "<td>$r->url</td>"; echo "<td>$r->url</td>";
echo "<td align=\"center\"><a href=\"award_download.php?action=check&check[]=$r->id\">".i18n("check")."</a></td>"; echo "<td align=\"center\">";
if($links)
echo "<a href=\"award_download.php?action=check&check[]=$r->id\">".i18n("check")."</a>";
else
echo "n/a";
echo "</td>";
echo "</tr>"; echo "</tr>";
$checkurl.="&check[]=$r->id"; $checkurl.="&check[]=$r->id";
} }
echo "</table>\n"; echo "</table>\n";
echo "<br />"; echo "<br />";
if($links)
echo "<a href=\"award_download.php?action=check$checkurl\">".i18n("Check all sources")."</a>"; echo "<a href=\"award_download.php?action=check$checkurl\">".i18n("Check all sources")."</a>";
} }

View File

@ -1 +1 @@
69 70

1
db/db.update.70.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE `award_awards` ADD `award_sources_id` INT UNSIGNED DEFAULT NULL ;