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': ?> + + + @@ -211,7 +474,9 @@ if(!function_exists('curl_init')) { } $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 WHERE award_awards.award_source_fairs_id IS NOT NULL AND award_awards.year='{$config['FAIRYEAR']}' @@ -230,7 +495,10 @@ while($r=mysql_fetch_object($q)) { echo "