From 97c489646e4b6c9040e647a80bfcf19ffdabf63a Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 23 Sep 2009 05:53:33 +0000 Subject: [PATCH] - 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 --- admin/award_upload.php | 278 ++++++++++++++++++++++++++++++++++++++++- db/db.code.version.txt | 2 +- db/db.update.138.sql | 2 + sfiab.js | 4 +- 4 files changed, 279 insertions(+), 7 deletions(-) create mode 100644 db/db.update.138.sql diff --git a/admin/award_upload.php b/admin/award_upload.php index 5658033..a64f9ac 100644 --- a/admin/award_upload.php +++ b/admin/award_upload.php @@ -74,6 +74,12 @@ function get_winners($awardid) } $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(), 'award_name' => $award['name'], 'external_identifier' => $award['external_identifier'], @@ -116,12 +122,18 @@ function get_winners($awardid) $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 */ $prizewinners[]=array( 'xml_type' => 'project',/* for ysc compatability */ 'projectid'=>$project['id'], 'projectnumber'=>$project['projectnumber'], 'title'=>$project['title'], 'abstract'=>$project['summary'], + 'projectcategories_id'=>$cat_id, + 'projectdivisions_id'=>$div_id, 'students'=>$students ); } /* Save the prize info => projects */ @@ -174,11 +186,84 @@ case 'award_upload': echo notice("{$fair['name']} server said:
".join("\n", $data['notice'])."
"); echo happy(i18n("Upload completed successfully")); } - echo "
";
-		print_r($winners);
-		echo "
"; + } + exit; +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; } @@ -192,14 +277,192 @@ case 'award_upload': ?> + + + {$r->awardname}\n"; echo "{$r->fairname}"; echo ""; - echo "id})\" >".i18n("send").""; + if($r->fairtype == 'sfiab') + echo "award_source_fairs_id},{$r->id})\" >".i18n("send").""; + else + echo "id})\" >".i18n("send").""; echo ""; } ?> diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 065fd3e..93e7803 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -137 +138 diff --git a/db/db.update.138.sql b/db/db.update.138.sql new file mode 100644 index 0000000..4ca61dc --- /dev/null +++ b/db/db.update.138.sql @@ -0,0 +1,2 @@ +ALTER TABLE `fairs` ADD `catmap` TINYTEXT NOT NULL , + ADD `divmap` TINYTEXT NOT NULL ; diff --git a/sfiab.js b/sfiab.js index b7d1683..373e5cd 100644 --- a/sfiab.js +++ b/sfiab.js @@ -65,7 +65,9 @@ function notice_(str) /* Stuff to do after the document loads */ $(document).ready(function() { - + /* Do left/right on all tableedits */ + $(".tableedit tr td:even").addClass('left'); + $(".tableedit tr td:odd").addClass('right'); });