2007-10-03 21:03:46 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2007 James Grant < james @ lightbox . org >
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 ( " ../common.inc.php " );
2007-11-21 17:02:09 +00:00
require_once ( " ../user.inc.php " );
2007-11-18 23:50:23 +00:00
user_auth_required ( 'committee' , 'admin' );
2007-10-05 18:40:07 +00:00
include " xml.inc.php " ;
2007-11-18 23:50:23 +00:00
send_header ( " YSF Regional Affiliation Stats " ,
array ( 'Committee Main' => 'committee_main.php' ,
2008-08-22 20:50:38 +00:00
'Administration' => 'admin/index.php' ),
" one-click_ysf_affiliation_stats "
2007-11-18 23:50:23 +00:00
);
2007-10-05 18:44:48 +00:00
echo " <br /> " ;
2007-10-03 21:03:46 +00:00
2007-10-05 18:40:07 +00:00
if ( $_POST [ 'action' ] == " register " && $_POST [ 'xml' ])
{
if ( function_exists ( 'curl_init' ))
{
$ch = curl_init (); /// initialize a cURL session
curl_setopt ( $ch , CURLOPT_URL , " https://secure.ysf-fsj.ca/registration/xmlaffiliation.php " );
curl_setopt ( $ch , CURLOPT_HEADER , 0 ); /// Header control
curl_setopt ( $ch , CURLOPT_POST , 1 ); /// tell it to make a POST, not a GET
curl_setopt ( $ch , CURLOPT_POSTFIELDS , " xml= " . $_POST [ 'xml' ]); /// put the query string here starting with "?"
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ); /// This allows the output to be set into a variable $datastream
curl_setopt ( $ch , CURLOPT_POSTFIELDSIZE , 0 );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 360 );
curl_setopt ( $ch , CURLOPT_SSLVERSION , 3 );
$datastream = curl_exec ( $ch ); /// execute the curl session and return the output to a variable $datastream
$datastream = str_replace ( " standalone= \" yes \" " , " " , $datastream );
// echo "curl close <br />";
curl_close ( $ch ); /// close the curl session
echo i18n ( " The YSF Registration Server said: " ) . " <br /> " ;
echo notice ( $datastream );
2007-10-05 18:44:48 +00:00
echo " <a href= \" index.php \" > " . i18n ( " Return to admin " ) . " </a> \n " ;
2007-10-05 18:40:07 +00:00
}
else
{
echo error ( " CURL Support Missing " );
echo i18n ( " Your PHP installation does not support CURL. You will need to login to the YSF system as the regional coodinator and upload the XML data manually " );
}
send_footer ();
exit ;
}
$ok = true ;
//make sure we have the ysf_region_id and ysf_region_password
if ( ! $config [ 'ysf_region_id' ])
{
echo error ( i18n ( " You have not yet specified your YSF Region ID. Go to the Configuration Variables page to set it " ));
$ok = false ;
}
if ( ! $config [ 'ysf_region_password' ])
{
echo error ( i18n ( " You have not yet specified your YSF Region Password. Go to the Configuration Variables page to set it " ));
$ok = false ;
}
2007-10-03 21:03:46 +00:00
if ( $_GET [ 'year' ]) $year = $_GET [ 'year' ];
2007-10-05 18:40:07 +00:00
else if ( $_POST [ 'year' ]) $POST = $_GET [ 'year' ];
2007-10-03 21:03:46 +00:00
else $year = $config [ 'FAIRYEAR' ];
2007-10-05 18:40:07 +00:00
echo " <form name= \" yearselect \" action= \" ysfstats.php \" method= \" get \" > " ;
$q = mysql_query ( " SELECT DISTINCT(year) AS year FROM config WHERE year>0 ORDER BY year " );
echo " <select name= \" year \" onchange= \" document.forms.yearselect.submit() \" > " ;
echo " <option value= \" \" > " . i18n ( " Choose a year " ) . " </option> \n " ;
while ( $r = mysql_fetch_object ( $q )) {
if ( $year == $r -> year ) $sel = " selected= \" selected \" " ; else $sel = " " ;
echo " <option $sel value= \" $r->year\ " > $r -> year </ option > \n " ;
}
echo " </select> \n " ;
echo " </form> " ;
if ( $year )
{
echo i18n ( " The following information is collected by YSF Canada each year for all affiliated regions " );
echo " <br /> " ;
echo " <br /> " ;
$stats = array ();
2007-10-03 21:03:46 +00:00
//number of schools
$q = mysql_query ( " SELECT COUNT(id) AS num FROM schools WHERE year=' $year ' " );
$r = mysql_fetch_object ( $q );
$numberofschools = $r -> num ;
echo i18n ( " Number of schools: %1 " , array ( $numberofschools )) . " <br /> " ;
2007-10-05 18:40:07 +00:00
$stats [ " numschoolstotal " ] = $numberofschools ;
2007-10-03 21:03:46 +00:00
//number of schools
$q = mysql_query ( " SELECT DISTINCT(students.schools_id) AS sid FROM students,registrations WHERE students.registrations_id=registrations.id AND students.year=' $year ' AND registrations.year=' $year ' AND (registrations.status='complete' OR registrations.status='paymentpending') " );
echo mysql_error ();
$numberofactiveschools = mysql_num_rows ( $q );
echo i18n ( " Number of active schools: %1 " , array ( $numberofactiveschools )) . " <br /> " ;
2007-10-05 18:40:07 +00:00
$stats [ " numschoolsactive " ] = $numberofactiveschools ;
2007-10-03 21:03:46 +00:00
//total number of students:
$q = mysql_query ( " SELECT COUNT(students.id) AS num FROM students,registrations WHERE students.registrations_id=registrations.id AND students.year=' $year ' AND registrations.year=' $year ' AND (registrations.status='complete' OR registrations.status='paymentpending') " );
$r = mysql_fetch_object ( $q );
$numberofstudents = $r -> num ;
echo i18n ( " Number of students: %1 " , array ( $numberofstudents )) . " <br /> " ;
echo mysql_error ();
2007-10-05 18:40:07 +00:00
$stats [ " numstudents " ] = $numberofstudents ;
2007-10-03 21:03:46 +00:00
//number of students per grade per gender
$q = mysql_query ( " SELECT COUNT(students.id) AS num, students.grade, students.sex FROM students,registrations WHERE students.registrations_id=registrations.id AND students.year=' $year ' AND registrations.year=' $year ' AND (registrations.status='complete' OR registrations.status='paymentpending') GROUP BY students.grade, students.sex " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q )) {
if ( $r -> grade <= 6 )
$nums [ " 6down " ][ $r -> sex ] += $r -> num ;
else if ( $r -> grade > 6 && $r -> grade <= 8 )
$nums [ " 78 " ][ $r -> sex ] += $r -> num ;
else if ( $r -> grade > 8 && $r -> grade <= 10 )
$nums [ " 910 " ][ $r -> sex ] += $r -> num ;
else if ( $r -> grade > 10 )
$nums [ " 11up " ][ $r -> sex ] += $r -> num ;
}
2007-10-05 18:40:07 +00:00
echo " <br /> " ;
2007-10-03 21:03:46 +00:00
echo " Student participation (by age group/gender)<br /> " ;
echo i18n ( " K-6 Male: %1 " , array ( $nums [ " 6down " ][ " male " ] ? $nums [ " 6down " ][ " male " ] : 0 )) . " <br /> " ;
echo i18n ( " K-6 Female: %1 " , array ( $nums [ " 6down " ][ " female " ] ? $nums [ " 6down " ][ " female " ] : 0 )) . " <br /> " ;
if ( $nums [ " 6down " ][ " " ] > 0 )
echo i18n ( " K-6 Unknown: %1 " , array ( $nums [ " 6down " ][ " " ] ? $nums [ " 6down " ][ " " ] : 0 )) . " <br /> " ;
echo " <br /> " ;
echo i18n ( " 7-8 Male: %1 " , array ( $nums [ " 78 " ][ " male " ] ? $nums [ " 78 " ][ " male " ] : 0 )) . " <br /> " ;
echo i18n ( " 7-8 Female: %1 " , array ( $nums [ " 78 " ][ " female " ] ? $nums [ " 78 " ][ " female " ] : 0 )) . " <br /> " ;
if ( $nums [ " 78 " ][ " " ] > 0 )
echo i18n ( " 7-8 Unknown: %1 " , array ( $nums [ " 78 " ][ " " ] ? $nums [ " 78 " ][ " " ] : 0 )) . " <br /> " ;
echo " <br /> " ;
echo i18n ( " 9-10 Male: %1 " , array ( $nums [ " 910 " ][ " male " ] ? $nums [ " 910 " ][ " male " ] : 0 )) . " <br /> " ;
echo i18n ( " 9-10 Female: %1 " , array ( $nums [ " 910 " ][ " female " ] ? $nums [ " 910 " ][ " female " ] : 0 )) . " <br /> " ;
if ( $nums [ " 910 " ][ " " ] > 0 )
echo i18n ( " 9-10 Unknown: %1 " , array ( $nums [ " 910 " ][ " " ] ? $nums [ " 910 " ][ " " ] : 0 )) . " <br /> " ;
echo " <br /> " ;
echo i18n ( " 11 up Male: %1 " , array ( $nums [ " 11up " ][ " male " ] ? $nums [ " 11up " ][ " male " ] : 0 )) . " <br /> " ;
echo i18n ( " 11 up Female: %1 " , array ( $nums [ " 11up " ][ " female " ] ? $nums [ " 11up " ][ " female " ] : 0 )) . " <br /> " ;
if ( $nums [ " 11up " ][ " " ] > 0 )
echo i18n ( " 11 up Unknown: %1 " , array ( $nums [ " 11up " ][ " " ] ? $nums [ " 11up " ][ " " ] : 0 )) . " <br /> " ;
echo " <br /> " ;
2007-10-05 18:40:07 +00:00
$stats [ " numk6m " ] = $nums [ " 6down " ][ " male " ] ? $nums [ " 6down " ][ " male " ] : 0 ;
$stats [ " numk6f " ] = $nums [ " 6down " ][ " female " ] ? $nums [ " 6down " ][ " female " ] : 0 ;
//add on unknown genders split evenly
if ( $nums [ " 6down " ][ " " ] > 0 )
{
$m = ceil ( $nums [ " 6down " ][ " " ] / 2 );
$f = $nums [ " 6down " ][ " " ] - $m ;
$stats [ " numk6m " ] += $m ;
$stats [ " numk6f " ] += $f ;
}
$stats [ " num78m " ] = $nums [ " 78 " ][ " male " ] ? $nums [ " 78 " ][ " male " ] : 0 ;
$stats [ " num78f " ] = $nums [ " 78 " ][ " female " ] ? $nums [ " 78 " ][ " female " ] : 0 ;
if ( $nums [ " 78 " ][ " " ] > 0 )
{
$m = ceil ( $nums [ " 78 " ][ " " ] / 2 );
$f = $nums [ " 78 " ][ " " ] - $m ;
$stats [ " num78m " ] += $m ;
$stats [ " num78f " ] += $f ;
}
$stats [ " num910m " ] = $nums [ " 910 " ][ " male " ] ? $nums [ " 910 " ][ " male " ] : 0 ;
$stats [ " num910f " ] = $nums [ " 910 " ][ " female " ] ? $nums [ " 910 " ][ " female " ] : 0 ;
if ( $nums [ " 910 " ][ " " ] > 0 )
{
$m = ceil ( $nums [ " 910 " ][ " " ] / 2 );
$f = $nums [ " 910 " ][ " " ] - $m ;
$stats [ " num910m " ] += $m ;
$stats [ " num910f " ] += $f ;
}
$stats [ " num11upm " ] = $nums [ " 11up " ][ " male " ] ? $nums [ " 11up " ][ " male " ] : 0 ;
$stats [ " num11upf " ] = $nums [ " 11up " ][ " female " ] ? $nums [ " 11up " ][ " female " ] : 0 ;
if ( $nums [ " 11up " ][ " " ] > 0 )
{
$m = ceil ( $nums [ " 11up " ][ " " ] / 2 );
$f = $nums [ " 11up " ][ " " ] - $m ;
$stats [ " num11upm " ] += $m ;
$stats [ " num11upf " ] += $f ;
}
2007-10-05 17:34:06 +00:00
//number of students per grade per gender
$q = mysql_query ( " SELECT MAX(students.grade) grade FROM students,registrations,projects WHERE students.registrations_id=registrations.id AND projects.registrations_id=registrations.id AND 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_object ( $q )) {
if ( $r -> grade <= 6 )
$projs [ " 6down " ] ++ ;
else if ( $r -> grade > 6 && $r -> grade <= 8 )
$projs [ " 78 " ] ++ ;
else if ( $r -> grade > 8 && $r -> grade <= 10 )
$projs [ " 910 " ] ++ ;
else if ( $r -> grade > 10 )
$projs [ " 11up " ] ++ ;
}
echo " Project participation (by age group)<br /> " ;
echo i18n ( " K-6: %1 " , array ( $projs [ " 6down " ] ? $projs [ " 6down " ] : 0 )) . " <br /> " ;
echo i18n ( " 7-8: %1 " , array ( $projs [ " 78 " ] ? $projs [ " 78 " ] : 0 )) . " <br /> " ;
echo i18n ( " 9-10: %1 " , array ( $projs [ " 910 " ] ? $projs [ " 910 " ] : 0 )) . " <br /> " ;
echo i18n ( " 11 up: %1 " , array ( $projs [ " 11up " ] ? $projs [ " 11up " ] : 0 )) . " <br /> " ;
echo " <br /> " ;
2007-10-05 18:40:07 +00:00
$stats [ " projk6 " ] = $projs [ " 6down " ] ? $projs [ " 6down " ] : 0 ;
$stats [ " proj78 " ] = $projs [ " 78 " ] ? $projs [ " 78 " ] : 0 ;
$stats [ " proj910 " ] = $projs [ " 910 " ] ? $projs [ " 910 " ] : 0 ;
$stats [ " proj11up " ] = $projs [ " 11up " ] ? $projs [ " 11up " ] : 0 ;
2007-12-05 04:21:57 +00:00
$q = mysql_query ( " SELECT COUNT(id) AS num FROM users WHERE types LIKE '%committee%' AND deleted='no' " );
2007-10-05 17:34:06 +00:00
$r = mysql_fetch_object ( $q );
$numcommittee = $r -> num ;
echo i18n ( " Committee Members: %1 (note: this is CURRENT number of active committee members as of right now! There is no way to extract committee member numbers from previous years) " , array ( $r -> num ));
echo " <br /> " ;
2007-10-05 18:40:07 +00:00
$stats [ " committee " ] = $numcommittee ;
2007-10-05 17:34:06 +00:00
$q = mysql_query ( " SELECT COUNT(id) AS num FROM judges,judges_years WHERE judges_years.judges_id=judges.id AND judges_years.year=' $year ' AND judges.complete='yes' AND judges.deleted='no' " );
$r = mysql_fetch_object ( $q );
$numjudges = $r -> num ;
echo i18n ( " Judges: %1 " , array ( $r -> num ));
2007-10-05 18:40:07 +00:00
$stats [ " judges " ] = $numjudges ;
2007-10-05 17:34:06 +00:00
echo " <br /> " ;
2007-10-05 18:40:07 +00:00
if ( $ok )
{
$affil = array ( " affiliation " => array (
" ysf_region_id " => $config [ 'ysf_region_id' ],
" ysf_region_password " => $config [ 'ysf_region_password' ],
" year " => $year ,
" stats " => $stats
)
);
2007-10-05 17:34:06 +00:00
2007-10-05 18:40:07 +00:00
$output = " " ;
xmlCreateRecurse ( $affil );
$xmldata = $output ;
2007-10-05 17:34:06 +00:00
2007-10-05 18:40:07 +00:00
echo " <h3> " . i18n ( " The following data will be sent to YSF " ) . " </h3> " ;
echo " <form method= \" post \" action= \" ysfstats.php \" > " ;
echo " <input type= \" hidden \" name= \" action \" value= \" register \" > " ;
echo " <textarea rows= \" 15 \" cols= \" 80 \" name= \" xml \" > " ;
echo $xmldata ;
echo " </textarea> " ;
echo " <br /> " ;
echo " <br /> " ;
echo " <input type= \" submit \" value= \" " . i18n ( " Send Affiliation Stats to YSF " ) . " \" > " ;
echo " </form> " ;
}
}
2007-10-03 21:03:46 +00:00
send_footer ();
?>