forked from science-ation/science-ation
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).
This commit is contained in:
parent
8a5436a3b2
commit
f0515a93bd
@ -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: <b>%1</b>. 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 '<br /><br />';
|
||||
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;
|
||||
}
|
||||
|
||||
?>
|
||||
<br />
|
||||
<br />
|
||||
<button onClick="popup_divmap(<?=$fairs_id?>);return false;"
|
||||
title="<?=i18n("Edit Default Division Assignments")?>"><?=i18n("Edit Default Division Assignments")?></button>
|
||||
<br /><br />
|
||||
<button onClick="popup_divmap(<?=$fairs_id?>);return false;" <?=$division_disabled ? 'disabled="disabled' : ''?>
|
||||
title="<?=i18n("Edit Default Division Assignments")?>"><?=i18n("Edit Default Division Assignments")?></button>
|
||||
|
||||
<form id="winner_divs_form">
|
||||
<input type="hidden" name="fairs_id" value="<?=$fairs_id?>" />
|
||||
<input type="hidden" name="award_awards_id" value="<?=$award_awards_id?>" />
|
||||
<table class="tableview">
|
||||
<?
|
||||
|
||||
foreach($winners as &$w) {
|
||||
echo "<tr><td style=\"border: 0px;\" colspan=\"3\">";
|
||||
echo "<br /><h3>{$w['award_name']}</h3>";
|
||||
@ -412,6 +475,10 @@ case 'load':
|
||||
echo "<tr><td style=\"border: 0px;\" colspan=\"3\">";
|
||||
echo "<h4>{$p['name']}</h4>";
|
||||
echo '</td></tr>';
|
||||
if(count($p['projects']) == 0) {
|
||||
echo i18n('No winners to upload');
|
||||
continue;
|
||||
}
|
||||
foreach($p['projects'] as &$pr) {
|
||||
?> <tr><td style="border: 0px;"> </td>
|
||||
<td><b><?=$pr['projectnumber']?> - <?=$pr['title']?></b><br/>
|
||||
@ -441,22 +508,25 @@ case 'load':
|
||||
<tr> <td align="right" style="border: 0px;"><?=i18n('Our division')?>:</td>
|
||||
<td><b><?=$divs[$pr['client_projectdivisions_id']]['division']?></td>
|
||||
</tr>
|
||||
<tr> <td align="right"><?=i18n('%1 Division', array($fair['abbrv']))?>:</td>
|
||||
<td><select name="div[<?=$w['id']?>][<?=$p['id']?>][<?=$pr['projectid']?>]">
|
||||
<?
|
||||
$mapto = $divmap[$pr['client_projectdivisions_id']];
|
||||
foreach($server_divs as $d) {
|
||||
$sel = ($mapto == $d['id']) ? 'selected="selected"' : '';
|
||||
echo "<option $sel value=\"{$d['id']}\">{$d['division']}</option>";
|
||||
}
|
||||
?> </select>
|
||||
<input type="hidden" name="cat[<?=$w['id']?>][<?=$p['id']?>][<?=$pr['projectid']?>]" value="<?=$server_cat?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr> <td align="right"><?=i18n('%1 Category', array($fair['abbrv']))?>:</td>
|
||||
<td><b><?=$server_cats[$server_cat]['category']?> (<?=i18n('Grade')?> <?=$server_cats[$server_cat]['mingrade']?> - <?=$server_cats[$server_cat]['maxgrade']?>)</td>
|
||||
</tr>
|
||||
</table>
|
||||
if($division_disabled == false) {
|
||||
?> <tr> <td align="right"><?=i18n('%1 Division', array($fair['abbrv']))?>:</td>
|
||||
<td><select name="div[<?=$w['id']?>][<?=$p['id']?>][<?=$pr['projectid']?>]">
|
||||
<?
|
||||
$mapto = $divmap[$pr['client_projectdivisions_id']];
|
||||
foreach($server_divs as $d) {
|
||||
$sel = ($mapto == $d['id']) ? 'selected="selected"' : '';
|
||||
echo "<option $sel value=\"{$d['id']}\">{$d['division']}</option>";
|
||||
}
|
||||
?> </select>
|
||||
<input type="hidden" name="cat[<?=$w['id']?>][<?=$p['id']?>][<?=$pr['projectid']?>]" value="<?=$server_cat?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr> <td align="right"><?=i18n('%1 Category', array($fair['abbrv']))?>:</td>
|
||||
<td><b><?=$server_cats[$server_cat]['category']?> (<?=i18n('Grade')?> <?=$server_cats[$server_cat]['mingrade']?> - <?=$server_cats[$server_cat]['maxgrade']?>)</td>
|
||||
</tr>
|
||||
<? }
|
||||
?> </table>
|
||||
</td></tr>
|
||||
<?
|
||||
}
|
||||
@ -603,14 +673,19 @@ echo mysql_error();
|
||||
<table class="tableview"><thead>
|
||||
<tr><th><?=i18n("Source Name")?></th>
|
||||
<th><?=i18n("Number of Awards")?></th>
|
||||
<th><?=i18n("Winners<br />Assigned")?></th>
|
||||
<th><?=i18n("Send All")?></th>
|
||||
</tr></thead>
|
||||
<?
|
||||
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<tr><td>{$r->name}</td>\n";
|
||||
echo "<td align=\"center\">{$r->AWARD_COUNT}</td>";
|
||||
echo "<td align=\"center\">";
|
||||
$count = count_winners(-1, $r->id);
|
||||
?>
|
||||
<tr><td><?=$r->name?></td>
|
||||
<td align="center"><?=$r->AWARD_COUNT?></td>
|
||||
<td align="center"><?=$count?></td>
|
||||
<td align="center">
|
||||
<?
|
||||
if($r->type == 'sfiab')
|
||||
echo "<a href=\"#\" onClick=\"popup_upload({$r->id},-1)\" >".i18n("Send All")."</a>";
|
||||
else
|
||||
@ -641,25 +716,31 @@ echo mysql_error();
|
||||
<table class="tableview"><thead>
|
||||
<tr><th><?=i18n("Award Name")?></th>
|
||||
<th><?=i18n("Source Name")?></th>
|
||||
<th><?=i18n("Winners<br />Assigned")?></th>
|
||||
<th><?=i18n("Send")?></th>
|
||||
<th><?=i18n("Additional<br />Info")?></th>
|
||||
</tr></thead>
|
||||
<?
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<tr><td>{$r->awardname}</td>\n";
|
||||
echo "<td>{$r->fairname}</td>";
|
||||
echo "<td align=\"center\">";
|
||||
if($r->fairtype == 'sfiab')
|
||||
echo "<a href=\"#\" onClick=\"popup_upload({$r->award_source_fairs_id},{$r->id})\" >".i18n("send")."</a>";
|
||||
else
|
||||
echo "<a href=\"#\" onClick=\"award_upload({$r->id})\" >".i18n("send")."</a>";
|
||||
echo "</td><td>";
|
||||
$count = count_winners($r->id, $r->award_source_fairs_id);
|
||||
?>
|
||||
<tr><td><?=$r->awardname?></td>
|
||||
<td><?=$r->fairname?></td>
|
||||
<td align="center"><?=$count?></td>
|
||||
<td align="center">
|
||||
<?
|
||||
if($count > 0)
|
||||
$onclick = "popup_upload({$r->award_source_fairs_id},{$r->id});return false;";
|
||||
else
|
||||
$onclick = "alert('".i18n('Assign a winner first')."');return false;";
|
||||
?>
|
||||
<a href="#" onClick="<?=$onclick?>"><?=i18n("send")?></a>
|
||||
</td><td>
|
||||
|
||||
if($r->external_additional_materials) {
|
||||
<? if($r->external_additional_materials) {
|
||||
echo "<a href=\"{$_SERVER['PHP_SELF']}?action=additional_materials&award_awards_id={$r->id}\" target=\"_blank\">".i18n("download")."</a>";
|
||||
}
|
||||
|
||||
echo "</td></tr>";
|
||||
echo '</td></tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user