From f0515a93bd44bca7835311f834fd25aa0bebc11d Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 18 Apr 2010 22:40:10 +0000 Subject: [PATCH] Fix uploading to STO: Make YSC targets use the same upload screen, but disable division selection. Count the number of winners on the main upload page and disable the send button if there are 0 winners. (also helps the user know which awards need uploading). --- admin/award_upload.php | 157 +++++++++++++++++++++++++++++++---------- 1 file changed, 119 insertions(+), 38 deletions(-) diff --git a/admin/award_upload.php b/admin/award_upload.php index f1eb48a..9515e29 100644 --- a/admin/award_upload.php +++ b/admin/award_upload.php @@ -27,7 +27,7 @@ require_once('curl.inc.php'); user_auth_required('committee', 'admin'); //function get_cwsf_award_winners() -function get_winners($awardid, $fairs_id, $catmap_str=NULL, $divmap_str=NULL) +function get_winners($awardid, $fairs_id) { global $config; @@ -172,6 +172,51 @@ function get_winners($awardid, $fairs_id, $catmap_str=NULL, $divmap_str=NULL) return $all_winners; } +function count_winners($awardid, $fairs_id) +{ + global $config; + $count = 0; + $awards = array(); + if($awardid == -1) { + /* Get all for this fair */ + $q=mysql_query("SELECT * FROM award_awards WHERE award_source_fairs_id='$fairs_id' AND year='{$config['FAIRYEAR']}'"); + if(mysql_num_rows($q) == 0) { + error_("Can't find award id $awardid"); + return 0; + } + while($a = mysql_fetch_assoc($q)) { + $awards[] = $a; + } + } else { + /* Get the award */ + $q=mysql_query("SELECT * FROM award_awards WHERE id='$awardid' AND year='{$config['FAIRYEAR']}'"); + if(mysql_num_rows($q)!=1) { + error_("Can't find award id $awardid"); + return 0; + } + $award=mysql_fetch_assoc($q); + $awards[] = $award; + } + + foreach($awards as $award) { + /* Get the prizes */ + $q=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='{$award['id']}'"); + while($prize=mysql_fetch_assoc($q)) { + $pid = $prize['id']; + $wq=mysql_query("SELECT COUNT(projects.id) as C FROM award_prizes + LEFT JOIN winners ON winners.awards_prizes_id=award_prizes.id + LEFT JOIN projects ON projects.id=winners.projects_id + WHERE + awards_prizes_id='$pid' AND + winners.year='{$config['FAIRYEAR']}'"); + $wc = mysql_fetch_assoc($wq); + $count += $wc['C']; + } + } + return $count; + +} + function load_server_cats_divs($fairs_id) { @@ -243,15 +288,21 @@ case 'award_upload': $upload_something = false; foreach($all_winners as &$w) { foreach($w['prizes'] as &$p) { + + if(count($p['projects'])) + $upload_something = true; + + /* Only update divs/cats for SFIAB fairs, the + * YSC/STO awards system doesn't care about divisions, but YSC + * registration does, but that's a different bit of code */ + if($fair['type'] != 'sfaib') continue; + foreach($p['projects'] as &$pr) { $div_id = intval($divs[$w['id']][$p['id']][$pr['projectid']]); $pr['projectdivisions_id'] = $div_id; $cat_id = intval($cats[$w['id']][$p['id']][$pr['projectid']]); $pr['projectcategories_id'] = $cat_id; } - - if(count($p['projects'])) - $upload_something = true; } } @@ -386,7 +437,6 @@ case 'load': $fairs_id = intval($_GET['fairs_id']); $winners = get_winners($award_awards_id, $fairs_id); - list($server_cats, $server_divs, $catmap, $divmap) = load_server_cats_divs($fairs_id); $divs = projectdivisions_load(); $q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id}'"); @@ -394,17 +444,30 @@ case 'load': echo i18n("The following list of winning projects/students will be sent to: %1. Use the 'Edit Default Division Assignments' button to change the default mappings for divisions. You can over-ride any division assignment by changing it in the list below. Category assignments are done automatically based on grade. When you are happy with the list below, click the 'Upload Winners' button.", array($fair['name'])); + if($fair['type'] != 'sfiab') { + echo '

'; + echo i18n('This server does not collection Division information, all division selection is disabled.'); + $server_cats = array(); + $server_divs = array(); + $catmap =array(); + $divmap = array(); + $division_disabled = true; + } else { + list($server_cats, $server_divs, $catmap, $divmap) = load_server_cats_divs($fairs_id); + $division_disabled = false; + } + ?> -
-
- +

+
'; + if(count($p['projects']) == 0) { + echo i18n('No winners to upload'); + continue; + } foreach($p['projects'] as &$pr) { ?> - - - - - - -
"; echo "

{$w['award_name']}

"; @@ -412,6 +475,10 @@ case 'load': echo "
"; echo "

{$p['name']}

"; echo '
     -
@@ -441,22 +508,25 @@ case 'load':
:
: - -
: ( - )
+ if($division_disabled == false) { +?> : + + + + + : + ( - ) + + +Assigned")?> {$r->name}\n"; - echo "{$r->AWARD_COUNT}"; - echo ""; + $count = count_winners(-1, $r->id); +?> + name?> + AWARD_COUNT?> + + +type == 'sfiab') echo "id},-1)\" >".i18n("Send All").""; else @@ -641,25 +716,31 @@ echo mysql_error(); +\n"; - echo ""; - echo " + + + "; + echo ''; } ?>
Assigned")?> Info")?>
{$r->awardname}{$r->fairname}"; - if($r->fairtype == 'sfiab') - echo "award_source_fairs_id},{$r->id})\" >".i18n("send").""; - else - echo "id})\" >".i18n("send").""; - echo ""; + $count = count_winners($r->id, $r->award_source_fairs_id); +?> +
awardname?>fairname?> + 0) + $onclick = "popup_upload({$r->award_source_fairs_id},{$r->id});return false;"; + else + $onclick = "alert('".i18n('Assign a winner first')."');return false;"; +?> + + - if($r->external_additional_materials) { +external_additional_materials) { echo "id}\" target=\"_blank\">".i18n("download").""; } - - echo "