Update the sponsor if it changes for an existing award

Dont check year on the sponsors table
This commit is contained in:
james 2007-11-27 22:55:45 +00:00
parent 0f198346aa
commit c7a3628f4a

View File

@ -88,7 +88,20 @@
$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 />";
//check if the sponsor exists, if not, add them
$sponsorq=mysql_query("SELECT * FROM award_sponsors WHERE organization='".mysql_escape_string($award['sponsor'][0])."'");
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();
}
mysql_query("UPDATE award_awards SET mysql_query("UPDATE award_awards SET
award_sponsors_id='$sponsor_id',
name='".mysql_escape_string($award['name_en'][0])."', name='".mysql_escape_string($award['name_en'][0])."',
criteria='".mysql_escape_string($award['criteria_en'][0])."', criteria='".mysql_escape_string($award['criteria_en'][0])."',
postback='".mysql_escape_string($postback)."' postback='".mysql_escape_string($postback)."'
@ -97,13 +110,15 @@
AND external_identifier='".mysql_escape_string($identifier)."' AND external_identifier='".mysql_escape_string($identifier)."'
AND year='$year' AND year='$year'
"); ");
//FIXME: update the prizes
//update the prizes
if(is_array($award['prizes'][0]) && count($award['prizes'][0]['prize']>0)) if(is_array($award['prizes'][0]) && count($award['prizes'][0]['prize']>0))
{ {
$prizes=$award['prizes'][0]['prize']; $prizes=$award['prizes'][0]['prize'];
$numprizes=count($prizes); $numprizes=count($prizes);
echo i18n("Number of prizes: %1",array($numprizes))."<br />"; echo i18n("Number of prizes: %1",array($numprizes))."<br />";
$pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$awardrecord->id'"); $pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$awardrecord->id'");
//get a list of all the existing prizes
$existingprizes=array(); $existingprizes=array();
while($pr=mysql_fetch_object($pq)) { while($pr=mysql_fetch_object($pq)) {
$existingprizes[$pr->external_identifier]=$pr; $existingprizes[$pr->external_identifier]=$pr;
@ -165,7 +180,7 @@
} }
else { else {
//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])."' AND year='$year'"); $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)) {
$sponsor_id=$sponsorr->id; $sponsor_id=$sponsorr->id;
} }