forked from science-ation/science-ation
- Turn the uploader into a popup window
- Add the ability to select category/division mappings specific for each upstream server - Add some auto-determining code if the cat/div mappings don't exist
This commit is contained in:
parent
32752f6e4e
commit
97c489646e
@ -74,6 +74,12 @@ function get_winners($awardid)
|
|||||||
}
|
}
|
||||||
$award=mysql_fetch_assoc($q);
|
$award=mysql_fetch_assoc($q);
|
||||||
|
|
||||||
|
/* Get the fair for the div/cat mappings */
|
||||||
|
$q = mysql_query("SELECT * FROM fairs WHERE id='{$award['award_source_fairs_id']}'");
|
||||||
|
$fair = mysql_fetch_assoc($q);
|
||||||
|
$catmap = unserialize($fair['catmap']);
|
||||||
|
$divmap = unserialize($fair['divmap']);
|
||||||
|
|
||||||
$winners=array( 'prizes' => array(),
|
$winners=array( 'prizes' => array(),
|
||||||
'award_name' => $award['name'],
|
'award_name' => $award['name'],
|
||||||
'external_identifier' => $award['external_identifier'],
|
'external_identifier' => $award['external_identifier'],
|
||||||
@ -116,12 +122,18 @@ function get_winners($awardid)
|
|||||||
$students[] = $student;
|
$students[] = $student;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/* Turn our load ID into a server-side cat/div id */
|
||||||
|
$cat_id = $catmap[$project['projectcategories_id']];
|
||||||
|
$div_id = $divmap[$project['projectdivisions_id']];
|
||||||
|
|
||||||
/* Save the project info => students */
|
/* Save the project info => students */
|
||||||
$prizewinners[]=array( 'xml_type' => 'project',/* for ysc compatability */
|
$prizewinners[]=array( 'xml_type' => 'project',/* for ysc compatability */
|
||||||
'projectid'=>$project['id'],
|
'projectid'=>$project['id'],
|
||||||
'projectnumber'=>$project['projectnumber'],
|
'projectnumber'=>$project['projectnumber'],
|
||||||
'title'=>$project['title'],
|
'title'=>$project['title'],
|
||||||
'abstract'=>$project['summary'],
|
'abstract'=>$project['summary'],
|
||||||
|
'projectcategories_id'=>$cat_id,
|
||||||
|
'projectdivisions_id'=>$div_id,
|
||||||
'students'=>$students );
|
'students'=>$students );
|
||||||
}
|
}
|
||||||
/* Save the prize info => projects */
|
/* Save the prize info => projects */
|
||||||
@ -174,11 +186,84 @@ case 'award_upload':
|
|||||||
echo notice("{$fair['name']} server said: <pre>".join("\n", $data['notice'])."</pre>");
|
echo notice("{$fair['name']} server said: <pre>".join("\n", $data['notice'])."</pre>");
|
||||||
echo happy(i18n("Upload completed successfully"));
|
echo happy(i18n("Upload completed successfully"));
|
||||||
}
|
}
|
||||||
echo "<pre>";
|
}
|
||||||
print_r($winners);
|
exit;
|
||||||
echo "</pre>";
|
case 'catdiv_load':
|
||||||
|
$fairs_id = intval($_GET['id']);
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$ret = array();
|
||||||
|
$ret['categories'] = $data['categories'];
|
||||||
|
$ret['divisions'] = $data['divisions'];
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
case 'catdiv_save':
|
||||||
|
$fairs_id = intval($_POST['award_source_fairs_id']);
|
||||||
|
|
||||||
|
$cat = array();
|
||||||
|
foreach($_POST['cat'] AS $key=>$c) {
|
||||||
|
$cat[intval($key)] = intval($c);
|
||||||
|
}
|
||||||
|
$div = array();
|
||||||
|
foreach($_POST['div'] AS $key=>$d) {
|
||||||
|
$div[intval($key)] = intval($d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$catmap = mysql_real_escape_string(serialize($cat));
|
||||||
|
$divmap = mysql_real_escape_string(serialize($div));
|
||||||
|
mysql_query("UPDATE fairs SET catmap='$catmap',divmap='$divmap' WHERE id='$fairs_id'");
|
||||||
|
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']);
|
||||||
|
$winners = get_winners($award_awards_id);
|
||||||
|
print_r($winners);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,14 +277,192 @@ case 'award_upload':
|
|||||||
|
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
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)
|
function award_upload(id)
|
||||||
{
|
{
|
||||||
$("#award_upload_status").load("<?=$_SERVER['PHP_SELF']?>?action=award_upload&id="+id);
|
$("#award_upload_status").load("<?=$_SERVER['PHP_SELF']?>?action=award_upload&id="+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()
|
||||||
|
{
|
||||||
|
$("#confirm_data").load("<?=$_SERVER['PHP_SELF']?>?action=confirm_load&id="+award_awards_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirm_upload()
|
||||||
|
{
|
||||||
|
$("#popup_upload").dialog('close');
|
||||||
|
award_upload(award_awards_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function popup_upload(fid,aaid)
|
||||||
|
{
|
||||||
|
var w = (document.documentElement.clientWidth * 0.7);
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Show the dialog */
|
||||||
|
$('#popup_upload').dialog('option', 'width', w);
|
||||||
|
$('#popup_upload').dialog('option', 'height', h);
|
||||||
|
$("#popup_upload").dialog('open');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup the popup window */
|
||||||
|
$(document).ready(function() {
|
||||||
|
$("#popup_upload").dialog({
|
||||||
|
bgiframe: true, autoOpen: false,
|
||||||
|
modal: true, resizable: false,
|
||||||
|
draggable: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#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;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
collapsible: true,
|
||||||
|
selected: -1, /* None selected */
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</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 class="tableedit">
|
||||||
|
<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']} => </td>";
|
||||||
|
echo "<td><select id=\"cat[{$c['id']}]\" name=\"cat[{$c['id']}]\" class=\"upload_cat\">";
|
||||||
|
while($sr=mysql_fetch_object($sq)) {
|
||||||
|
echo "<option value=\"-1\">Loading...</option>";
|
||||||
|
}
|
||||||
|
echo '</select></td></tr>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
<br />
|
||||||
|
<h4><?=i18n("Division Mapping")?></h4>
|
||||||
|
<br />
|
||||||
|
<table class="tableedit">
|
||||||
|
<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']} => </td>";
|
||||||
|
echo "<td><select id=\"div[{$d['id']}]\" name=\"div[{$d['id']}]\" class=\"upload_div\">";
|
||||||
|
while($sr=mysql_fetch_object($sq)) {
|
||||||
|
echo "<option value=\"-1\">Loading...</option>";
|
||||||
|
}
|
||||||
|
echo '</select></td></tr>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<table style="border-width:0; width:100%">
|
||||||
|
<tr><td></td>
|
||||||
|
<td><input type="submit" onClick="#" disabled="disabled" value="<?=i18n("<< Prev")?>" /></td>
|
||||||
|
<td><input type="submit" onClick="catdiv_save();return false;" value="<?=i18n("Save")?>" /></td>
|
||||||
|
<td><input type="submit" onClick="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><input type="submit" onClick="confirm_prev();return false;" value="<?=i18n("<< Prev")?>" /></td>
|
||||||
|
<td><input type="submit" onClick="confirm_upload();return false;" value="<?=i18n("Upload")?>" /></td>
|
||||||
|
<td><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>
|
||||||
|
|
||||||
<?
|
<?
|
||||||
|
|
||||||
|
|
||||||
@ -211,7 +474,9 @@ if(!function_exists('curl_init')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$q = mysql_query("SELECT award_awards.id, award_awards.name AS awardname,
|
$q = mysql_query("SELECT award_awards.id, award_awards.name AS awardname,
|
||||||
fairs.name as fairname, award_sourcE_fairs_id FROM award_awards
|
fairs.name as fairname, award_source_fairs_id,
|
||||||
|
fairs.type as fairtype
|
||||||
|
FROM award_awards
|
||||||
LEFT JOIN fairs ON fairs.id=award_awards.award_source_fairs_id
|
LEFT JOIN fairs ON fairs.id=award_awards.award_source_fairs_id
|
||||||
WHERE award_awards.award_source_fairs_id IS NOT NULL
|
WHERE award_awards.award_source_fairs_id IS NOT NULL
|
||||||
AND award_awards.year='{$config['FAIRYEAR']}'
|
AND award_awards.year='{$config['FAIRYEAR']}'
|
||||||
@ -230,6 +495,9 @@ while($r=mysql_fetch_object($q)) {
|
|||||||
echo "<tr><td>{$r->awardname}</td>\n";
|
echo "<tr><td>{$r->awardname}</td>\n";
|
||||||
echo "<td>{$r->fairname}</td>";
|
echo "<td>{$r->fairname}</td>";
|
||||||
echo "<td align=\"center\">";
|
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 "<a href=\"#\" onClick=\"award_upload({$r->id})\" >".i18n("send")."</a>";
|
||||||
echo "</td></tr>";
|
echo "</td></tr>";
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
137
|
138
|
||||||
|
2
db/db.update.138.sql
Normal file
2
db/db.update.138.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `fairs` ADD `catmap` TINYTEXT NOT NULL ,
|
||||||
|
ADD `divmap` TINYTEXT NOT NULL ;
|
4
sfiab.js
4
sfiab.js
@ -65,7 +65,9 @@ function notice_(str)
|
|||||||
/* Stuff to do after the document loads */
|
/* Stuff to do after the document loads */
|
||||||
$(document).ready(function()
|
$(document).ready(function()
|
||||||
{
|
{
|
||||||
|
/* Do left/right on all tableedits */
|
||||||
|
$(".tableedit tr td:even").addClass('left');
|
||||||
|
$(".tableedit tr td:odd").addClass('right');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user