diff --git a/admin/award_download.php b/admin/award_download.php
index 344d05b..d8491bb 100644
--- a/admin/award_download.php
+++ b/admin/award_download.php
@@ -88,7 +88,20 @@
$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")."
";
+
+ //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
+ award_sponsors_id='$sponsor_id',
name='".mysql_escape_string($award['name_en'][0])."',
criteria='".mysql_escape_string($award['criteria_en'][0])."',
postback='".mysql_escape_string($postback)."'
@@ -97,13 +110,15 @@
AND external_identifier='".mysql_escape_string($identifier)."'
AND year='$year'
");
- //FIXME: update the prizes
+
+ //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))."
";
$pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$awardrecord->id'");
+ //get a list of all the existing prizes
$existingprizes=array();
while($pr=mysql_fetch_object($pq)) {
$existingprizes[$pr->external_identifier]=$pr;
@@ -165,7 +180,7 @@
}
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'");
+ $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;
}