Copyright (C) 2009 David Grant 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. */ ?> 'committee_main.php', 'Administration' => 'admin/index.php'), "fair_stats" ); echo "
"; /* SFIAB config options server side */ $server_config = array(); $server_config['participation'] = false; $server_config['schools_ext'] = false; $server_config['minorities'] = false; $server_config['guests'] = false; $server_config['sffbc_misc'] = false; $server_config['info'] = false; $server_config['next_chair'] = false; $server_config['scholarships'] = false; $server_config['delegates'] = false; if($_GET['year']) $year=intval($_GET['year']); else $year=$config['FAIRYEAR']; if($_GET['id']) $fairs_id=intval($_GET['id']); else if($_POST['id']) $fairs_id=intval($_POST['id']); else $fairs_id = -1; if($fairs_id != -1) { $q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id'"); $fair = mysql_fetch_assoc($q); } $action = $_POST['action']; if($action == 'sendstats') { foreach(array_keys($stats_data) as $k) { $stats[$k] = $_POST[$k]; } $stats['year'] = $year; if($fair['type'] == 'ysc') { $st = stats_to_ysc($fair, $stats); $req = array('affiliation' => array( "ysf_region_id"=>$fair['username'], "ysf_region_password"=>$fair['password'], "year"=>$year, 'stats'=>$st) ); } else { $req = array('stats'=>$stats); } if(function_exists('curl_init')) { $r = curl_query($fair, $req, 'https://secure.ysf-fsj.ca/registration/xmlaffiliation.php'); if($r['error'] == 0) echo happy(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message']); else echo error(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message']); // $fairs_id = -1; // $year = $config['FAIRYEAR']; } else { echo error("CURL Support Missing"); echo i18n("Your PHP installation does not support CURL. You will need to login to the YSC system as the regional coodinator and upload the XML data manually"); send_footer(); exit; } } echo "
"; $q=mysql_query("SELECT * FROM fairs WHERE `type`='sfiab' OR `type`='ysc' AND enable_stats='yes'"); echo "\n"; $q=mysql_query("SELECT DISTINCT(year) AS year FROM config WHERE year>0 ORDER BY year"); echo "\n"; echo ""; echo "
"; echo "
"; echo "
"; if($fairs_id == -1) { echo i18n('Statistics will be shown below this line before being sent. Please select a destination and year first.'); /* Wait for them to select somethign before generating stats */ send_footer(); exit; } $ok = true; if(trim($fair['username']) == '') { echo error(i18n("You have not yet specified a username for this server. Go to the Science Fair Management page to set it")); $ok=false; } if(trim($fair['password']) == '') { echo error(i18n("You have not yet specified a password for this server. Go to the Science Fair Management page to set it")); $ok=false; } if($fair['type'] == 'ysc') { $data['statconfig'] = array('participation'); } else { echo notice(i18n('Getting stats request and downloading existing stats from server %1', array($fair['url']))); /* Query the server to see what stats we need */ $q=array('getstats' => array('year' => $year)); $data = curl_query($fair, $q); if($data['error'] != 0) { echo error("Server said: {$data['message']}
"); send_footer(); exit; } echo notice(i18n('Server said: Success')); } echo '
'; echo i18n('This server has requested the following stats for your %1 fair:', array($year)); echo '

'; foreach($data['statconfig'] as $k) { $server_config[$k] = true; } /* Gather all stats, then we'll decide what to send */ $stats = array(); $stats['year'] = $year; /* Now, overwrite all the stats with what we pulled down from the server */ if(is_array($data['stats'])) { foreach($data['stats'] as $k=>$v) { $stats[$k] = $v; } } // print_r($data['stats'][0]); /* And now, overwrite all the stuff we pulled down with stats we can compute */ //number of schools $q=mysql_query("SELECT COUNT(id) AS num FROM schools WHERE year='$year'"); $r=mysql_fetch_object($q); $stats['schools_total']=$r->num; //number of schools participating $q=mysql_query("SELECT DISTINCT(students.schools_id) AS sid, schools.* FROM students LEFT JOIN registrations ON students.registrations_id=registrations.id LEFT JOIN schools ON students.schools_id=schools.id WHERE students.year='$year' AND registrations.year='$year' AND (registrations.status='complete' OR registrations.status='paymentpending')"); $stats['schools_active']=mysql_num_rows($q); $stats['schools_public'] = 0; $stats['schools_private'] = 0; $stats['schools_atrisk'] = 0; $districts = array(); while($si=mysql_fetch_assoc($q)) { if($si['designate'] == 'public') $stats['schools_public']++; if($si['designate'] == 'independent') $stats['schools_private']++; if($si['atrisk'] == 'yes') $stats['schools_atrisk']++; $bd = $si['board'].'~'.$si['district']; if(!in_array($bd, $districts)) $districts[] =$bd; } $stats['schools_districts'] = count($districts); //numbers of students: $q=mysql_query("SELECT students.*,schools.* FROM students LEFT JOIN registrations ON students.registrations_id=registrations.id LEFT JOIN schools on students.schools_id=schools.id WHERE students.year='$year' AND registrations.year='$year' AND (registrations.status='complete' OR registrations.status='paymentpending')"); echo mysql_error(); $stats['students_total'] = mysql_num_rows($q); $stats['students_public'] = 0; $stats['students_private'] = 0; $stats['students_atrisk'] = 0; $grademap = array(1=>1, 2=>1, 3=>1, 4=>4, 5=>4, 6=>4, 7=>7, 8=>7, 9=>9, 10=>9, 11=>11, 12=>11, 13=>11); foreach($grademap as $k=>$g) { $stats["male_$g"] = 0; $stats["female_$g"] = 0; $stats["projects_$g"] = 0; } $unknown = array(); while($s=mysql_fetch_assoc($q)) { if(!in_array($s['sex'], array('male','female'))) $unknown[$grademap[$s['grade']]]++; else $stats["{$s['sex']}_{$grademap[$s['grade']]}"]++; if($s['designate'] == 'public') $stats['students_public']++; if($s['designate'] == 'independent') $stats['students_private']++; if($s['atrisk'] == 'yes') $stats['students_atrisk']++; } foreach($unknown as $g=>$a) { $m = round($a/2); $f = $a - $m; $stats["male_$g"] += $m; $stats["female_$g"] += $f; } //projects $q=mysql_query("SELECT MAX(students.grade) AS grade FROM students LEFT JOIN registrations ON students.registrations_id=registrations.id LEFT JOIN projects ON projects.registrations_id=registrations.id WHERE students.year='$year' AND registrations.year='$year' AND projects.year='$year' AND (registrations.status='complete' OR registrations.status='paymentpending') GROUP BY projects.id"); echo mysql_error(); while($r=mysql_fetch_assoc($q)) { $stats["projects_{$grademap[$r['grade']]}"]++; } $q=mysql_query("SELECT COUNT(users.id) AS num FROM users JOIN user_roles ON user_roles.users_id = users.id JOIN roles ON roles.id = user_roles.roles_id WHERE roles.type = 'committee' AND users.conferences_id = '{$conference['id']}' AND users.deleted = 'no'"); $r = mysql_fetch_object($q); $stats['committee_members'] = $r->num; $q=mysql_query(" SELECT COUNT(users.id) AS num FROM users JOIN user_roles ON user_roles.users_id = users.id JOIN roles ON roles.id = user_roles.roles_id WHERE users.conferences_id = '{$conference['id']}' AND users.deleted = 'no' AND roles.type = 'judge' AND user_roles.complete='yes' AND user_roles.active='yes'"); $r=mysql_fetch_object($q); $stats['judges'] = $r->num; /* All stats have been gathered, print them */ /* Print all blocks the server requests */ echo "
"; echo ""; if($server_config['info']) { echo '

'.i18n('%1 Fair information', array($year)).'

'; echo ''; echo ''; echo ""; echo ''; echo ""; echo ''; echo ''; echo ''; echo ""; echo ''; echo ''; echo ''; echo ""; echo '
'.i18n('Fair Start Date').':(YYYY-MM-DD)
'.i18n('Fair End Date').':(YYYY-MM-DD)
'.i18n('Fair Location/Address').':
'.i18n('Fair Budget').':$
'.i18n('Youth Science Canada Affiliation Complete').'?
'.i18n('Charity Number or Information').'?
'; echo '
'; echo '
'; } if($server_config['next_chair']) { echo '

'.i18n('%1 - %2 Chairperson (if known)', array($year, $year+1)).'

'; echo ''; echo ''; echo ""; echo ''; echo ""; echo ''; echo ""; echo ''; echo ""; echo ''; echo ""; echo ''; echo '
'.i18n('Name').': '.i18n('Email').':
'.i18n('Tel. Bus').': '.i18n('Tel. Home').':
'.i18n('Fax').':
'; echo '

'; } if($server_config['delegates']) { echo '

'.i18n('%1 CWSF Delegates and Alternatives', array($year)).'

'; echo ''; echo ''; for($x=1;$x<=3;$x++) { $sizes = array('small'=>'Small', 'medium'=>'Medium', 'large'=>'Large', 'xlarge'=>'X-Large'); echo ""; echo ""; echo "'; } echo '
'.i18n('Delegate Name(s)').''.i18n('Email').''.i18n('Jacket Size').'
'; echo i18n('Remember, the jackets fit smaller than normal sizes.'); echo '

'; } if($server_config['scholarships']) { echo '

'.i18n('%1 Scholarships', array($year)).'

'; echo 'How many university/college scholarships are available at your fair? (use a format like:
6 - University of British Columbia - Entrance Scholarships
'; echo ''; echo '

'; } if($server_config['participation']) { $rangemap = array(1=>'1-3', 4=>'4-6', 7=>'7-8', 9=>'9-10', 11=>'11-12'); echo '

'.i18n('%1 Fair participation', array($year)).'

'; echo '
'; echo i18n("Number of students").": {$stats['students_total']}"; echo ''; echo ''; foreach($rangemap as $k=>$v) echo ""; echo ''; echo ''; foreach($rangemap as $k=>$v) echo ""; echo ''; echo ''; foreach($rangemap as $k=>$v) echo ""; echo ''; echo ''; foreach($rangemap as $k=>$v) echo ""; echo ''; echo '
'.i18n('Grade').'
$v
'.i18n('Male').'{$stats["male_$k"]}
'.i18n('Female').'{$stats["female_$k"]}
'.i18n('Projects').'{$stats["projects_$k"]}
'; echo '
'; echo i18n("Number of schools").": {$stats['schools_total']}"; echo '
'; echo i18n("Number of active schools").": {$stats['schools_active']}"; echo '
'; echo '
'; echo i18n("Number of committee members: %1 (note: this is number of committee members who logged in to SFIAB for the year, anyone who was active but didn't log in to SFIAB will NOT be counted)",array($stats['committee_members'])); echo '
'; echo i18n("Number of judges").": {$stats['judges']}"; echo '
'; echo '
'; echo '
'; } if($server_config['schools_ext']) { echo '

'.i18n('%1 Extended School/Participant data', array($year)).'

'; echo '
'; echo i18n('Public schools: %1 (%2 students).',array( $stats['schools_public'], $stats['students_public'])); echo '
'; echo i18n('Private/Independent schools: %1 (%2 students).',array( $stats['schools_private'], $stats['students_private'])); echo '
'; echo i18n('At-risk/inner city schools: %1 (%2 students).',array( $stats['schools_atrisk'], $stats['students_atrisk'])); echo '
'; echo i18n('Number of school boards/distrcits: %1',array( $stats['schools_districts'])); echo '
'; echo '
'; echo '
'; } if($server_config['minorities']) { echo '

'.i18n('%1 Data on minority groups', array($year)).'

'; echo '
'; echo ''; echo ''; echo '
'.i18n('Number of First Nations students'); echo ": "; echo '
'; echo '
'; echo '
'; } if($server_config['guests'] ) { echo '

'.i18n('%1 Guests visiting the fair', array($year)).'

'; echo '
'; echo ''; echo ''; echo ''; echo '
'.i18n('Number of Students that visited the fair (tours, etc.)'); echo ": "; echo '
'.i18n('Number of Public Guests that visited the fair'); echo ": "; echo '
'; echo '
'; echo '
'; } if($server_config['sffbc_misc']) { echo '

'.i18n('%1 Misc. SFFBC Questions', array($year)).'

'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'.i18n('Number of Teachers supporting student projects'); echo ": "; echo '
'.i18n('Number of Students indicating increased interest in science & technology'); echo ": "; echo '
'.i18n('Number of Students considering careers in science & technology'); echo ": "; echo '
'; echo '
'; echo '
'; } $keys = array_keys($stats_data); foreach($keys as $k) { if($stats_data[$k]['manual'] == true) continue; echo ""; } $d = ($ok == true) ? '' : 'disabled="disabled"'; echo ""; echo '
'; echo "
"; echo "
"; debug_("Fair Info: ".print_r($fair, true)); debug_("Server Config: ".print_r($server_config, true)); debug_("Stats: ".print_r($stats, true)); send_footer(); ?>