Put the award upload on one page. Make the default mappings a modal

dialog (so it's not ALWAYS on the screen).  Implement "upload all" for
SFIAB targets.
This commit is contained in:
dave 2010-04-18 22:40:08 +00:00
parent 530788e1c5
commit 8a5436a3b2
2 changed files with 256 additions and 210 deletions

View File

@ -95,7 +95,8 @@ function get_winners($awardid, $fairs_id, $catmap_str=NULL, $divmap_str=NULL)
foreach($awards as $award) {
$winners=array( 'award_name' => $award['name'],
$winners=array( 'id' => $award['id'],
'award_name' => $award['name'],
'external_identifier' => $award['external_identifier'],
'year' => $config['FAIRYEAR'],
'prizes' => array());
@ -155,10 +156,13 @@ function get_winners($awardid, $fairs_id, $catmap_str=NULL, $divmap_str=NULL)
'language'=>$project['language'],
'projectcategories_id'=>$cat_id,
'projectdivisions_id'=>$div_id,
'client_projectdivisions_id' => $project['projectdivisions_id'],
'students'=>$students );
}
/* Save the prize info => projects */
$winners['prizes'][$prize['prize']] = array(
'id' => $prize['id'],
'name' => $prize['prize'],
'xml_type'=>'prize', /* For ysc compatability */
'identifier'=>$prize['external_identifier'], /* for ysc compatability */
'projects'=>$prizewinners);
@ -168,10 +172,64 @@ function get_winners($awardid, $fairs_id, $catmap_str=NULL, $divmap_str=NULL)
return $all_winners;
}
function load_server_cats_divs($fairs_id)
{
global $config;
$q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id'");
$fair = mysql_fetch_assoc($q);
$req = array('get_categories' => array('year' => $config['FAIRYEAR']),
'get_divisions' => array('year' => $config['FAIRYEAR'])
);
$data = curl_query($fair, $req);
/* If selected mappings don't exist, try to discover some */
if(trim($fair['catmap']) != '') {
$catmap = unserialize($fair['catmap']);
} else {
$catmap = array();
/* Load ours */
$q=mysql_query("SELECT * FROM projectcategories WHERE year='{$config['FAIRYEAR']}' ORDER BY mingrade");
while($r=mysql_fetch_object($q)) {
foreach($data['categories'] as $id=>$c) {
if($c['mingrade'] == $r->mingrade) {
$catmap[$r->id] = $id;
break;
}
}
}
}
if(trim($fair['divmap']) != '') {
$divmap = unserialize($fair['divmap']);
} else {
$ret['divmap'] = array();
$q=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY id");
while($r=mysql_fetch_object($q)) {
$lowest = 999;
$lowest_id = 0;
foreach($data['divisions'] as $id=>$d) {
/* Who knew levenshtein was builtin to php as of PHP 4 */
$l = levenshtein($d['division'], $r->division);
if($l < $lowest) {
$lowest = $l;
$lowest_id = $id;
}
}
$divmap[$r->id] = $lowest_id;
}
}
return array($data['categories'], $data['divisions'], $catmap, $divmap);
}
switch($_GET['action']) {
case 'award_upload':
$award_awards_id = intval($_GET['id']);
$fairs_id = intval($_GET['fairs_id']);
$award_awards_id = intval($_POST['award_awards_id']);
$fairs_id = intval($_POST['fairs_id']);
$divs = $_POST['div'];
$cats = $_POST['cat'];
$all_winners = get_winners($award_awards_id, $fairs_id);
/* Get the fair */
@ -179,14 +237,21 @@ case 'award_upload':
$fair = mysql_fetch_assoc($q);
echo '<br />';
/* Check that we're going to upload something */
/* Check that we're going to upload something, and override the
* divisions/cats with the divisions taht were set, and the categories
* that were computed */
$upload_something = false;
foreach($all_winners as $w) {
foreach($w['prizes'] as $p) {
if(count($p['projects'])) {
$upload_something = true;
break;
foreach($all_winners as &$w) {
foreach($w['prizes'] as &$p) {
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;
}
}
@ -195,6 +260,7 @@ case 'award_upload':
exit;
}
if($fair['type'] == 'ysc') {
if($award_awards_id == -1) {
echo "Multiple uploads not supported for YSC targets.\n";
@ -243,64 +309,48 @@ case 'award_upload':
exit;
case 'catdiv_load':
$fairs_id = intval($_GET['id']);
$q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id'");
$fairs_id = intval($_GET['fairs_id']);
list($c, $d, $cm, $dm) = load_server_cats_divs($fairs_id);
$divs = projectdivisions_load();
$q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id}'");
$fair = mysql_fetch_assoc($q);
$req = array('get_categories' => array('year' => $config['FAIRYEAR']),
'get_divisions' => array('year' => $config['FAIRYEAR'])
);
$data = curl_query($fair, $req);
?> <h4><?=i18n("Division Mapping")?></h4>
<br />
$ret = array();
$ret['categories'] = $data['categories'];
$ret['divisions'] = $data['divisions'];
<form id="catdiv_form">
<input type="hidden" name="fairs_id" value="<?=$fairs_id?>" />
/* If selected mappings don't exist, try to discover some */
if(trim($fair['catmap']) != '') {
$ret['catmap'] = unserialize($fair['catmap']);
} else {
$ret['catmap'] = array();
/* Load ours */
$q=mysql_query("SELECT * FROM projectcategories WHERE year='{$config['FAIRYEAR']}' ORDER BY mingrade");
while($r=mysql_fetch_object($q)) {
foreach($data['categories'] as $id=>$c) {
if($c['mingrade'] == $r->mingrade) {
$ret['catmap'][$r->id] = $id;
break;
}
}
<table class="editor">
<tr><th><?=i18n("Our Division")?></th><th><?=i18n("%1 Division", array($fair['abbrv']))?></th></tr>
<?
foreach($divs as $div) {
echo "<tr><td class=\"label\">{$div['division']}&nbsp;=> </td>";
echo "<td><select name=\"div[{$div['id']}]\" class=\"upload_div\">";
$mapto = $dm[$div['id']];
foreach($d as $sdiv) {
$sel = ($sdiv['id'] == $mapto) ? 'selected="selected"' : '';
echo "<option $sel value=\"{$sdiv['id']}\">{$sdiv['division']}</option>";
}
echo '</select></td></tr>';
}
if(trim($fair['divmap']) != '') {
$ret['divmap'] = unserialize($fair['divmap']);
} else {
$ret['divmap'] = array();
$q=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY id");
while($r=mysql_fetch_object($q)) {
$lowest = 999;
$lowest_id = 0;
foreach($data['divisions'] as $id=>$d) {
/* Who knew levenshtein was builtin to php as of PHP 4 */
$l = levenshtein($d['division'], $r->division);
if($l < $lowest) {
$lowest = $l;
$lowest_id = $id;
}
}
$ret['divmap'][$r->id] = $lowest_id;
}
}
echo json_encode($ret);
?>
</table>
</form>
<br />
<?
exit;
case 'catdiv_save':
$fairs_id = intval($_POST['award_source_fairs_id']);
$fairs_id = intval($_POST['fairs_id']);
$cat = array();
foreach($_POST['cat'] AS $key=>$c) {
$cat[intval($key)] = intval($c);
}
// foreach($_POST['cat'] AS $key=>$c) {
// $cat[intval($key)] = intval($c);
// }
$div = array();
foreach($_POST['div'] AS $key=>$d) {
$div[intval($key)] = intval($d);
@ -312,14 +362,7 @@ case 'catdiv_save':
echo "UPDATE fairs SET catmap='$catmap',divmap='$divmap' WHERE id='$fairs_id'";
echo mysql_error();
// happy_("Category/Division mapping information saved");
exit;
case 'confirm_load':
$award_awards_id = intval($_GET['id']);
$fairs_id = intval($_GET['fairs_id']);
$winners = get_winners($award_awards_id, $fairs_id);
print_r($winners);
happy_("Category/Division mapping information saved");
exit;
case 'additional_materials':
@ -337,6 +380,92 @@ case 'additional_materials':
header($h);
echo base64_decode($data['award_additional_materials']['pdf']['data64']);
exit;
case 'load':
$award_awards_id = intval($_GET['id']);
$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}'");
$fair = mysql_fetch_assoc($q);
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']));
?>
<br />
<br />
<button onClick="popup_divmap(<?=$fairs_id?>);return false;"
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>";
foreach($w['prizes'] as &$p) {
echo "<tr><td style=\"border: 0px;\" colspan=\"3\">";
echo "<h4>{$p['name']}</h4>";
echo '</td></tr>';
foreach($p['projects'] as &$pr) {
?> <tr><td style="border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><b><?=$pr['projectnumber']?> - <?=$pr['title']?></b><br/>
<? $highest_grade = 0;
foreach($pr['students'] as &$s) {
echo i18n("Name").": ";
echo $s['firstname']." ".$s['lastname'];
echo "<br />";
echo "&nbsp;"; echo "&nbsp;"; echo "&nbsp;"; echo "&nbsp;";
echo i18n("Grade").": ".$s['grade'];
echo "<br />";
echo "&nbsp;"; echo "&nbsp;"; echo "&nbsp;"; echo "&nbsp;";
echo i18n("School").": ".$s['school']['schoolname'];
echo '<br />';
if($s['grade'] > $highest_grade) $highest_grade = $s['grade'];
}
$server_cat = '';
foreach($server_cats as $c) {
if($highest_grade >= $c['mingrade'] && $highest_grade <= $c['maxgrade']) {
$server_cat = $c['id'];
}
}
?>
</td>
<td>
<table class="default">
<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>
</td></tr>
<?
}
}
}
echo '</table></form><br />';
exit;
}
@ -352,81 +481,31 @@ case 'additional_materials':
var fairs_id = -1;
var award_awards_id = -1;
function catdiv_load()
{
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=catdiv_load&id="+fairs_id,
function(json) {
// alert(json.toSource());
$(".upload_cat").html("");
for(var i in json.categories ) {
var c = json.categories[i];
$(".upload_cat").append("<option value=\""+i+"\">"+c.category+" (grade "+c.mingrade+" - "+c.maxgrade+")</option>");
}
$(".upload_div").html("");
for(var i in json.divisions ) {
var d = json.divisions[i];
$(".upload_div").append("<option value=\""+i+"\">"+d.division+"</option>");
}
for(var i in json.catmap) {
var v = json.catmap[i];
$("#cat\\["+i+"\\]").val(v);
}
for(var i in json.divmap) {
var v = json.divmap[i];
$("#div\\["+i+"\\]").val(v);
}
});
}
function award_upload(id)
{
$("#award_upload_status").load("<?=$_SERVER['PHP_SELF']?>?action=award_upload&id="+id+"&fairs_id="+fairs_id);
}
function catdiv_save()
{
$("#award_source_fairs_id").val(fairs_id);
$("#debug").load("<?=$_SERVER['PHP_SELF']?>?action=catdiv_save",
$('#catdiv_form').serializeArray());
return false;
}
function catdiv_next()
{
$('#upload_tabs').tabs('option', 'selected', -1);
$('#upload_tabs').tabs('option', 'disabled', []);
$('#upload_tabs').tabs('select', 1);
return false;
}
function confirm_load()
function popup_upload_load()
{
$("#confirm_data").load("<?=$_SERVER['PHP_SELF']?>?action=confirm_load&id="+award_awards_id+"&fairs_id="+fairs_id);
}
function confirm_upload()
{
$("#popup_upload").dialog('close');
award_upload(award_awards_id);
var ids = "&id="+award_awards_id+"&fairs_id="+fairs_id;
$("#popup_upload").load("<?=$_SERVER['PHP_SELF']?>?action=load"+ids);
}
function popup_upload(fid,aaid)
{
var w = (document.documentElement.clientWidth * 0.7);
var w = (document.documentElement.clientWidth * 0.8);
var h = (document.documentElement.clientHeight * 0.8);
fairs_id = fid;
award_awards_id = aaid;
/* Force no tabs to be selected, need to set collapsible
* to true first */
$('#upload_tabs').tabs('option', 'collapsible', true);
$('#upload_tabs').tabs('option', 'selected', -1);
$('#upload_tabs').tabs('option', 'disabled', [1]);
$('#upload_tabs').tabs('select', 0);
/* Don't let anything collapse */
$('#upload_tabs').tabs('option', 'collapsible', false);
/* Load dialog content (it's in a function because we use it when
* the div editor closes too, to reload the content */
popup_upload_load();
/* Show the dialog */
$('#popup_upload').dialog('option', 'width', w);
@ -436,107 +515,66 @@ function popup_upload(fid,aaid)
return true;
}
function popup_divmap(fid)
{
var w = (document.documentElement.clientWidth * 0.4);
var h = (document.documentElement.clientHeight * 0.6);
/* Load dialog content */
$("#popup_divmap").load("<?=$_SERVER['PHP_SELF']?>?action=catdiv_load&fairs_id="+fairs_id);
/* Show the dialog */
$('#popup_divmap').dialog('option', 'width', w);
$('#popup_divmap').dialog('option', 'height', h);
$("#popup_divmap").dialog('open');
return true;
}
/* Setup the popup window */
$(document).ready(function() {
$("#popup_upload").dialog({
bgiframe: true, autoOpen: false,
modal: true, resizable: false,
draggable: false,
buttons: {
"<?=i18n('Cancel')?>": function() {
$(this).dialog("close");
},
"<?=i18n('Upload Winners')?>": function() {
$("#award_upload_status").load("<?=$_SERVER['PHP_SELF']?>?action=award_upload",
$('#winner_divs_form').serializeArray());
/* Don't need to wait for the .load to complete before closing */
$(this).dialog("close");
}
}
});
$("#upload_tabs").tabs({
show: function(event, ui) {
switch(ui.panel.id) {
case 'upload_tab_catdiv':
catdiv_load();
break;
case 'upload_tab_confirm':
confirm_load();
break;
$("#popup_divmap").dialog({
bgiframe: true, autoOpen: false,
modal: true, resizable: false,
draggable: false,
buttons: {
"<?=i18n('Cancel')?>": function() {
$(this).dialog("close");
},
"<?=i18n('Save Mappings')?>": function() {
$("#debug").load("<?=$_SERVER['PHP_SELF']?>?action=catdiv_save",
$('#catdiv_form').serializeArray(), function() {
popup_upload_load();
}
);
/* Don't need to wait for the .load to complete before closing */
$(this).dialog("close");
}
}
return true;
},
collapsible: true,
selected: -1, /* None selected */
});
});
</script>
<div id="popup_upload" title="Upload Award" style="display: none">
<div id="upload_tabs">
<ul><li><a href="#upload_tab_catdiv"><span><?=i18n('Category/Division Mapping')?></span></a></li>
<li><a href="#upload_tab_confirm"><span><?=i18n('Confirm Upload')?></span></a></li>
</ul>
<div id="upload_tab_catdiv">
<br />
<form id="catdiv_form">
<input type="hidden" name="award_source_fairs_id" id="award_source_fairs_id" value="0" />
<h4><?=i18n("Category Mapping")?></h4>
<br />
<table style="border-width:0; width:100%">
<tr><td></td>
<td width="30%"><input type="submit" onClick="#" disabled="disabled" value="<?=i18n("<< Prev")?>" /></td>
<td width="30%">&nbsp;</td>
<td width="40%"><input type="submit" onClick="catdiv_save();catdiv_next();return false;" value="<?=i18n("Next >>")?>" /></td>
</tr></table>
<br />
<table class="editor">
<tr><th><?=i18n("Our Category")?></th><th><?=i18n("Server Category")?></th></tr>
<?
$q = mysql_query("SELECT * FROM projectcategories WHERE year='{$config['FAIRYEAR']}' ORDER BY mingrade");
while($c = mysql_fetch_assoc($q)) {
echo "<tr><td>{$c['category']}&nbsp;=> </td>";
echo "<td><select id=\"cat[{$c['id']}]\" name=\"cat[{$c['id']}]\" class=\"upload_cat\">";
echo "<option value=\"-1\">Loading...</option>";
echo '</select></td></tr>';
}
?>
</table>
<br />
<h4><?=i18n("Division Mapping")?></h4>
<br />
<table class="editor">
<tr><th style="width: 50%;"><?=i18n("Our Division")?></th><th><?=i18n("Server Division")?></th></tr>
<?
$q = mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY division");
while($d = mysql_fetch_assoc($q)) {
echo "<tr><td>{$d['division']}&nbsp;=> </td>";
echo "<td><select id=\"div[{$d['id']}]\" name=\"div[{$d['id']}]\" class=\"upload_div\">";
echo "<option value=\"-1\">Loading...</option>";
echo '</select></td></tr>';
}
?>
</table>
<br />
<br />
<table style="border-width:0; width:100%">
<tr><td></td>
<td width="30%"><input type="submit" onClick="#" disabled="disabled" value="<?=i18n("<< Prev")?>" /></td>
<td width="30%">&nbsp;</td>
<td width="40%"><input type="submit" onClick="catdiv_save();catdiv_next();return false;" value="<?=i18n("Next >>")?>" /></td>
</tr></table>
<br />
</form>
</div>
<div id="upload_tab_confirm">
<br />
<h4><?=i18n("Confirm Upload")?></h4>
<br />
<table style="border-width:0; width:100%">
<tr><td></td>
<td width="30%"><input type="submit" onClick="confirm_prev();return false;" value="<?=i18n("<< Prev")?>" /></td>
<td width="30%"><input type="submit" onClick="confirm_upload();return false;" value="<?=i18n("Upload")?>" /></td>
<td width="40%"><input type="submit" onClick="#" disabled="disabled" value="<?=i18n("Next >>")?>" /></td>
</tr></table>
<br />
<p><?=i18n("The following data will be sent to the server:")?></p>
<pre id="confirm_data"></pre>
</div>
</div></div>
<div id="popup_upload" title="Upload Award" style="display: none"></div>
<div id="popup_divmap" title="Edit Mappings" style="display: none"></div>
<?
@ -571,7 +609,7 @@ echo mysql_error();
while($r=mysql_fetch_object($q)) {
echo "<tr><td>{$r->name}</td>\n";
echo "<td>{$r->AWARD_COUNT}</td>";
echo "<td align=\"center\">{$r->AWARD_COUNT}</td>";
echo "<td align=\"center\">";
if($r->type == 'sfiab')
echo "<a href=\"#\" onClick=\"popup_upload({$r->id},-1)\" >".i18n("Send All")."</a>";
@ -628,6 +666,8 @@ while($r=mysql_fetch_object($q)) {
<br />
<div id="award_upload_status"></div>
<?
/*<a href="award_upload.php?action=send<?=$sendurl?>"><?=i18n("Send all awards")?></a> */
send_footer();

View File

@ -131,6 +131,12 @@ input {
vertical-align: top;
}
/* A default class so we can nest tables (i know bad) but revert
* inheritance */
.default td {
border: 0px;
}