From 6242b9ef5e7afe3099d50d8efaa8dc2140422039 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 18 Apr 2010 22:41:23 +0000 Subject: [PATCH] Handle multiple awards in the winner postback --- remote.php | 85 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/remote.php b/remote.php index 02413ce..0f60b5a 100644 --- a/remote.php +++ b/remote.php @@ -80,7 +80,7 @@ function handle_getawards(&$u, $fair, &$data, &$response) /* Load the awards this fair is allowed to download */ $where = "id='".join("' OR id='", $ids)."'"; - $q = mysql_query("SELECT * FROM award_awards WHERE $where"); + $q = mysql_query("SELECT * FROM award_awards WHERE $where" ); while($a = mysql_fetch_assoc($q)) { $award = array(); @@ -294,10 +294,10 @@ function award_upload_assign(&$fair, &$award, &$prize, &$project, $year, &$respo if($award['external_register_winners'] == 1 && $new_reg == true) { /* This award is for students who are participating in this fair, we need * to get their reg number to them if this is a new registration */ - email_send("new_participant",$student['email'],array(), - array( "EMAIL"=>$student['email'], - "REGNUM"=>$registration['num']) - ); +// email_send("new_participant",$student['email'],array(), +// array( "EMAIL"=>$student['email'], +// "REGNUM"=>$registration['num']) +// ); $response['notice'][] = " - Sent welcome registration email to: {$student['firstname']} {$student['lastname']} <{$student['email']}>"; } } @@ -311,44 +311,56 @@ function award_upload_assign(&$fair, &$award, &$prize, &$project, $year, &$respo function handle_award_upload(&$u, &$fair, &$data, &$response) { - $external_identifier = $data['award_upload']['external_identifier']; - $year = intval($data['award_upload']['year']); - $prizes = $data['award_upload']['prizes']; + $response['notice'][] = 'Handle Award Upload deprecated , please upgrade your SFIAB'; + $response['error'] = 1; +} - /* Find the award */ - $eid = mysql_real_escape_string($external_identifier); +function handle_awards_upload(&$u, &$fair, &$data, &$response) +{ - $q = mysql_query("SELECT * FROM award_awards WHERE external_identifier='$eid' AND year='$year'"); - if(mysql_num_rows($q) != 1) { - $response['message'] = "Unknown award identifier '$eid'"; - $response['error'] = 1; - return; - } - $award = mysql_fetch_assoc($q); - $aaid = $award['id']; +// $response['debug'] = array_keys($data['awards_upload']); +// $response['error'] = 0; +// return; + foreach($data['awards_upload'] as $award_data) { + $external_identifier = $award_data['external_identifier']; + $year = intval($award_data['year']); + + /* Find the award */ + $eid = mysql_real_escape_string($external_identifier); - $response['notice'][] = "Found award: {$award['name']}"; + $q = mysql_query("SELECT * FROM award_awards WHERE external_identifier='$eid' AND year='$year'"); + if(mysql_num_rows($q) != 1) { + $response['message'] = "Unknown award identifier '$eid' for year $year"; + $response['error'] = 1; + return; + } + $award = mysql_fetch_assoc($q); + $aaid = $award['id']; - /* Load prizes, we fetched the right award by year, so we don't need to - * check the year as long as we query by aaid */ - $prizes = array(); - $q = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$aaid'"); - while($prize = mysql_fetch_assoc($q)) { - $response['notice'][] = " - Prize: {$prize['prize']}"; - /* Clean out existing winners for this prize */ - mysql_query("DELETE FROM winners WHERE - award_prize_id='{$prize['id']}' - AND fairs_id='{$fair['id']}'"); + $response['notice'][] = "Found award: {$award_data['name']}"; - /* Assign projects to this prize */ - $ul_p =& $data['award_upload']['prizes'][$prize['prize']]; - if(!is_array($ul_p['projects'])) continue; + /* Load prizes, we fetched the right award by year, so we don't need to + * check the year as long as we query by aaid */ + $prizes = array(); + $q = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$aaid'"); + while($prize = mysql_fetch_assoc($q)) { + $response['notice'][] = " - Prize: {$prize['prize']}"; - foreach($ul_p['projects'] as &$project) { - award_upload_assign($fair, $award, $prize, $project, $year, $response); + /* Clean out existing winners for this prize */ + mysql_query("DELETE FROM winners WHERE + award_prize_id='{$prize['id']}' + AND fairs_id='{$fair['id']}'"); + + /* Assign projects to this prize */ + $ul_p =& $award_data['prizes'][$prize['prize']]; + if(!is_array($ul_p['projects'])) continue; + + foreach($ul_p['projects'] as &$project) { + award_upload_assign($fair, $award, $prize, $project, $year, $response); + } } } - $response['notice'][] = 'Award winners saved'; + $response['notice'][] = 'All awards and winners saved'; $response['error'] = 0; } @@ -449,11 +461,12 @@ function handle_award_additional_materials(&$u, &$fair, &$data, &$response) if(array_key_exists('getstats', $data)) handle_getstats($u,$fair, $data, $response); if(array_key_exists('stats', $data)) handle_stats($u,$fair, $data, $response); if(array_key_exists('getawards', $data)) handle_getawards($u,$fair,$data, $response); + if(array_key_exists('awards_upload', $data)) handle_awards_upload($u,$fair,$data, $response); if(array_key_exists('award_upload', $data)) handle_award_upload($u,$fair,$data, $response); if(array_key_exists('get_categories', $data)) handle_get_categories($u,$fair,$data, $response); if(array_key_exists('get_divisions', $data)) handle_get_divisions($u,$fair,$data, $response); if(array_key_exists('award_additional_materials', $data)) handle_award_additional_materials($u,$fair,$data, $response); - $response['hi'] = 'hi'; +// $response['hi'] = 'hi'; echo urlencode(json_encode($response)); // echo "Success!
";