science-ation/schedule.inc.php
james e55a6f901a fix schedule display boxes to be the same for FF/IE/Chrome
Add min/max judges/volunteers/teams
Add defaults
Update science olympic tab display
Add Teams/Volunteers/Judges status to admin schedule view
2010-10-14 15:11:52 +00:00

183 lines
6.2 KiB
PHP

<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2010 Youth Science Ontario <info@youthscienceontario.ca>
Copyright (C) 2010 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.
*/
$ROWHEIGHT=32;
$BORDERSIZE=2;
function getTeamEventStatus($teamid,$scheduleid) {
global $conference;
$q=mysql_query("SELECT * FROM schedule_registrations WHERE so_teams_id='$teamid' AND schedule_id='$scheduleid' AND conferences_id='{$conference['id']}'");
//we use registered/notregistered insetad of true/false becuase we might haevf other statuses down the line, like "waitinglist"
if(mysql_num_rows($q)) {
return "registered";
}
else
return "notregistered";
}
function getNumRegistrations($scheduleid) {
global $conference;
$q=mysql_query("SELECT COUNT(*) AS num FROM schedule_registrations WHERE schedule_id='$scheduleid' AND conferences_id='{$conference['id']}'");
$r=mysql_fetch_object($q);
return $r->num;
}
//FIXME: implement getNumJudges
function getNumJudges($scheduleid) {
global $conference;
return 0;
}
//FIXME: implement getNumVolunteers
function getNumVolunteers($scheduleid) {
global $conference;
return 0;
}
function getEventList($conferencesId, $school_id){
global $conference;
$events = array();
$q=mysql_query("SELECT schedule.*, events.name, events.eventtype FROM schedule JOIN events ON schedule.events_id=events.id WHERE schedule.conferences_id='{$conference['id']}'");
$err = mysql_error();
if($err != "") return($err);
while($event = mysql_fetch_assoc($q)) {
if($event['eventtype'] == "scienceolympic") {
$regteams = getNumRegistrations($event['id']);
$maxteams = $event['somaxteams'];
$regq = mysql_query("SELECT so_teams.name, schedule_registrations.id
FROM schedule_registrations
JOIN so_teams ON so_teams_id=so_teams.id
WHERE schedule_registrations.conferences_id='{$conferencesId}'
AND so_teams.schools_id=$school_id
AND schedule_registrations.schedule_id='{$event['id']}'");
$err = mysql_error();
if($err != "") break;
$event['registrations'] = array();
while($regr = mysql_fetch_assoc($regq)) {
$event['registrations'][] = $regr;
}
}
$events[] = $event;
}
if($err != "") return($err);
return $events;
}
function getLocationList($conferencesId){
global $conference;
$q=mysql_query("SELECT * FROM locations WHERE conferences_id='{$conference['id']}' ORDER BY name");
while($r=mysql_fetch_object($q)) {
$locations[$r->id]=$r->name;
}
return $locations;
}
function registerTeamInEvent($conferenceid, $scheduleid, $teamid){
$q=mysql_query("SELECT schedule.*,
events.eventtype,
events.website,
events.summary,
events.name,
locations.name AS location
FROM schedule
JOIN events ON schedule.events_id=events.id
JOIN locations ON schedule.locations_id=locations.id
WHERE schedule.conferences_id='{$conferenceid}'
AND schedule.id='{$scheduleid}'");
$schedule=mysql_fetch_object($q);
echo mysql_error();
$q=mysql_query("SELECT * FROM schedule_registrations WHERE so_teams_id=$teamid AND schedule_id=$scheduleid AND conferences_id=$conferenceid");
if(mysql_num_rows($q)) {
$returnval = array('success' => false, 'message' => "This team is already registered for this scheduled event");
}
else {
$regteams=getNumRegistrations($scheduleid);
if($regteams<$schedule->somaxteams) {
mysql_query("INSERT INTO schedule_registrations (schedule_id, so_teams_id, conferences_id, dt) VALUES ('$scheduleid','$teamid','$conferenceid',NOW())");
$returnval = array('success' => true, 'message' => "successfully registered");
}
else {
$returnval = array('success' => false, 'message' => "This event has reached its capacity and can no longer be registered for");
}
}
return $returnval;
}
function unregisterTeamInEvent($conferenceid, $scheduleid, $teamid){
$q=mysql_query("SELECT schedule.*,
events.eventtype,
events.website,
events.summary,
events.name,
locations.name AS location
FROM schedule
JOIN events ON schedule.events_id=events.id
JOIN locations ON schedule.locations_id=locations.id
WHERE schedule.conferences_id='{$conferenceid}'
AND schedule.id='{$scheduleid}'");
$schedule=mysql_fetch_object($q);
echo mysql_error();
$q=mysql_query("SELECT * FROM schedule_registrations WHERE so_teams_id=$teamid AND schedule_id=$scheduleid AND conferences_id=$conferenceid");
if(mysql_num_rows($q)) {
// delete any links between students and this registrationa
$q = mysql_query(
" SELECT users_uid, schedule_registrations_id" .
" FROM schedule_registrations_users_link srul" .
" JOIN schedule_registrations sr ON sr.id = srul.schedule_registrations_id" .
" WHERE sr.so_teams_id = '$teamid'" .
" AND sr.schedule_id='$scheduleid'" .
" AND sr.conferences_id='$conferenceid'"
);
while($r = mysql_fetch_array($q)){
$idSet[] = $r['users_uid'];
$srid = $r['schedule_registrations_id'];
}
if(is_array($idSet)){
$query =
" DELETE FROM schedule_registrations_users_link" .
" WHERE schedule_registrations_id = $srid" .
" AND users_uid IN(" . implode(',', $idSet) . ")";
$q = mysql_query($query);
}
// delete the registrations themselves
mysql_query("DELETE FROM schedule_registrations WHERE so_teams_id='$teamid' AND schedule_id='$scheduleid' AND conferences_id='$conferenceid'");
$returnval = array('success' => true, 'message' => "successfully unregistered");
}
else {
$returnval = array('success' => false, 'message' => "This team is not registered for this scheduled event, and thus, cannot be unregistered");
}
return $returnval;
}
?>