This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ require_once('../common.inc.php'); require_once('../user.inc.php'); require_once('../projects.inc.php'); require_once('curl.inc.php'); user_auth_required('committee', 'admin'); //function get_cwsf_award_winners() function get_winners($awardid, $catmap_str=NULL, $divmap_str=NULL) { global $config; /* Mappings of the name we want => to the column name returned in MYSQL */ $school_fields = array( 'schoolname'=>'school', 'schoollang'=>'schoollang', 'schoollevel'=>'schoollevel', 'board'=>'board', 'district'=>'district', 'phone'=>'phone', 'fax'=>'fax', 'address'=>'address', 'city'=>'city', 'province_code'=>'province_code', 'postalcode'=>'postalcode', 'schoolemail'=>'schoolemail'); /* 'principal'=>'principal', 'sciencehead'=>'sciencehead', 'scienceheademail'=>'scienceheademail', 'scienceheadphone'=>'scienceheadphone');*/ $student_fields = array('firstname'=>'firstname', 'lastname'=>'lastname', 'email'=>'email', 'gender'=>'sex', 'grade'=>'grade', 'language'=>'lang', 'birthdate'=>'dateofbirth', 'address'=>'address', 'city'=>'city', 'province'=>'province', 'postalcode'=>'postalcode', 'phone'=>'phone', 'teachername'=>'teachername', 'teacheremail'=>'teacheremail'); /* 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 false; } $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(($catmap_str != NULL) ? $catmap_str : $fair['catmap']); $divmap = unserialize(($divmap_str != NULL) ? $divmap_str : $fair['divmap']); $winners=array( 'prizes' => array(), 'award_name' => $award['name'], 'external_identifier' => $award['external_identifier'], 'external_postback' => $award['external_postback']); /* 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 projects.* 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']}'"); echo mysql_error(); /* Get all projects assigned to this prize */ $prizewinners = array(); while($project=mysql_fetch_assoc($wq)) { /* Get the students */ $sq=mysql_query("SELECT * FROM students WHERE registrations_id='{$project['registrations_id']}' AND year='{$config['FAIRYEAR']}'"); $students=array(); while($s=mysql_fetch_assoc($sq)) { /* Get the student's school */ $schoolq=mysql_query("SELECT * FROM schools WHERE id='{$s['schools_id']}'"); $schoolr=mysql_fetch_assoc($schoolq); $school = array("xml_type"=>"school");/* for ysc compatability */ foreach($school_fields as $k=>$v) $school[$k] = $schoolr[$v]; /* Pack up the student data too */ $student = array('xml_type'=>'student',/* for ysc compatability */ 'school' => $school); foreach($student_fields as $k=>$v) $student[$k] = $s[$v]; $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'], 'language'=>$project['language'], 'projectcategories_id'=>$cat_id, 'projectdivisions_id'=>$div_id, 'students'=>$students ); } /* Save the prize info => projects */ $winners['prizes'][$prize['prize']] = array( 'xml_type'=>'prize', /* For ysc compatability */ 'identifier'=>$prize['external_identifier'], /* for ysc compatability */ 'projects'=>$prizewinners); } return $winners; } switch($_GET['action']) { case 'award_upload': $award_awards_id = intval($_GET['id']); $winners = get_winners($award_awards_id); /* Get the fair */ $q = mysql_query("SELECT award_source_fairs_id FROM award_awards WHERE id='$award_awards_id'"); $a = mysql_fetch_assoc($q); $q = mysql_query("SELECT * FROM fairs WHERE id='{$a['award_source_fairs_id']}'"); $fair = mysql_fetch_assoc($q); echo '
'; if($winners == false) { echo notice(i18n('No winners selected for this award')); } else { if($fair['type'] == 'ysc') { $w = array(); foreach($winners['prizes'] as $prize_name=>$prize) { $w[] = $prize; } $req=array("awardwinners"=>array( "username"=>$fair['username'], "password"=>$fair['password'], "identifier"=>$winners['external_identifier'], "prizes"=>$w, ) ); $url = $winners['external_postback']; } else { $req = array('award_upload' => $winners); $req['award_upload']['year'] = $config['FAIRYEAR']; $url = ''; /* url is ignored for type = sfiab */ } echo i18n("Sending %1 winners to %2...", array(''.$winners['award_name'].'', ''.$fair['name'].'')); echo '
'; // echo "
"; print_r($req); echo "
"; $data = curl_query($fair, $req, $url); if($data['error'] != 0) { echo error("Server said: ".htmlspecialchars(print_r($data,true))); } else { if(is_array($data['notice'])) echo notice("{$fair['name']} server said:
".join("\n", $data['notice'])."
"); else if(is_array($data['message'])) echo notice("{$fair['name']} server said:
".join("\n", $data['message'])."
"); else if($data['message']) { echo notice("{$fair['name']} server said:
".$data['message']."
"); } else echo notice("{$fair['name']} server said:
".htmlspecialchars(print_r($data,true))."
"); echo happy(i18n("Upload completed successfully")); } } 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; case 'additional_materials': $award_awards_id = intval($_GET['award_awards_id']); $q = mysql_query("SELECT award_source_fairs_id,external_identifier FROM award_awards WHERE id='$award_awards_id'"); $a = mysql_fetch_assoc($q); $q = mysql_query("SELECT * FROM fairs WHERE id='{$a['award_source_fairs_id']}'"); $fair = mysql_fetch_assoc($q); $req = array('award_additional_materials' => array( 'year'=>$config['FAIRYEAR'], 'identifier'=>$a['external_identifier']) ); $data = curl_query($fair, $req, $url); foreach($data['award_additional_materials']['pdf']['header'] as $h) header($h); echo base64_decode($data['award_additional_materials']['pdf']['data64']); exit; } send_header("Award Upload", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', 'Awards Main' => 'admin/awards.php') ); echo "
"; ?> \n"; echo ""; echo ""; } ?>
Info")?>
{$r->awardname}{$r->fairname}"; if($r->fairtype == 'sfiab') echo "award_source_fairs_id},{$r->id})\" >".i18n("send").""; else echo "id})\" >".i18n("send").""; echo ""; if($r->external_additional_materials) { echo "id}\" target=\"_blank\">".i18n("download").""; } echo "

"> */ send_footer(); ?>