forked from science-ation/science-ation
Added some API functionality used in schoolschedule.php
This commit is contained in:
parent
eb3c8f0d77
commit
0a02525d14
56
api.php
56
api.php
@ -25,6 +25,7 @@
|
||||
include "common.inc.php";
|
||||
require_once("account.inc.php");
|
||||
require_once("user.inc.php");
|
||||
require_once("schedule.inc.php");
|
||||
|
||||
if($_SERVER['HTTPS']!="on") {
|
||||
$ret['status']="error";
|
||||
@ -37,6 +38,61 @@ $request=explode("/",$_GET['request']);
|
||||
$ret=array();
|
||||
|
||||
switch($request[0]) {
|
||||
case 'locations':
|
||||
switch($request[1]){
|
||||
case 'list':
|
||||
/* APIDOC: locations/list
|
||||
description(lists locations at the current conference)
|
||||
return(list array)
|
||||
*/
|
||||
$locationData = getLocationList($_SESSION['conferences_id']);
|
||||
if(is_array($locationData)){
|
||||
$ret['status'] = 'ok';
|
||||
$ret['list'] = $locationData;
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = $locationData;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$ret['status'] = 'error';
|
||||
$ret['error']="Invalid API command ({$request[1]})";
|
||||
}
|
||||
break;
|
||||
case "schedule":
|
||||
$u = user_load($_SESSION['users_id']);
|
||||
$school_id = null;
|
||||
if($u['schools_id']) {
|
||||
$school_id=$u['schools_id'];
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error']="Not connected to a school";
|
||||
break;
|
||||
}
|
||||
|
||||
switch($request[1]){
|
||||
case 'list':
|
||||
/* APIDOC: events/list
|
||||
description(gets a list of all events at the current conference, and team information if applicable)
|
||||
return(list array)
|
||||
*/
|
||||
$eventData = getEventList($_SESSION['conferences_id'], $school_id);
|
||||
if(is_array($eventData)){
|
||||
$ret['status'] = 'ok';
|
||||
$ret['list'] = $eventData;
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = $eventData;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$ret['status'] = 'error';
|
||||
$ret['error']="Invalid API command ({$request[1]})";
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case "conferences":
|
||||
/* APIDOC: conferences/switch
|
||||
description(switches the active conference)
|
||||
|
@ -44,5 +44,45 @@ function getNumRegistrations($scheduleid) {
|
||||
return $r->num;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
@ -22,27 +22,37 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
require("common.inc.php");
|
||||
require_once("schedule.inc.php");
|
||||
require_once("user.inc.php");
|
||||
require("common.inc.php");
|
||||
require_once("schedule.inc.php");
|
||||
require_once("user.inc.php");
|
||||
|
||||
user_auth_required("teacher");
|
||||
$schoolid=user_field_required("schools_id","user_edit.php?tab=school");
|
||||
user_auth_required("teacher");
|
||||
$schoolid=user_field_required("schools_id","user_edit.php?tab=school");
|
||||
|
||||
$q=mysql_query("SELECT * FROM schools WHERE id='".$schoolid."'");
|
||||
echo mysql_error();
|
||||
$school=mysql_fetch_object($q);
|
||||
if($school) {
|
||||
$q=mysql_query("SELECT * FROM schools WHERE id='".$schoolid."'");
|
||||
echo mysql_error();
|
||||
$school=mysql_fetch_object($q);
|
||||
if(!$school) exit;
|
||||
|
||||
if($_GET['action']=="loadschedule") {
|
||||
$date=$_POST['date'];
|
||||
if($_GET['action']=="loadschedule") {
|
||||
$date = $_POST['date'];
|
||||
if(!eregi("[0-9]{4}-[0-9]{2}-[0-9]{2}",$date)) {
|
||||
echo "Invalid date";
|
||||
exit;
|
||||
}
|
||||
|
||||
//cant change this
|
||||
$q=mysql_query("SELECT MIN(hour) AS minhour, MAX(hour) AS maxhour, CEIL(MAX(hour)+duration/60) AS maxfinish FROM schedule WHERE conferences_id='{$conference['id']}' AND date='{$date}'");
|
||||
$parameters=mysql_fetch_object($q);
|
||||
$eventList = getEventList($conference['id'], $school->id);
|
||||
|
||||
$starthour=$parameters->minhour;
|
||||
$endhour=$parameters->maxfinish;
|
||||
// get the minimum and maximum hours from the schedule
|
||||
$starthour = $endhour = null;
|
||||
foreach($eventList as $event){
|
||||
if($event['date'] == $date){
|
||||
$sh = $event['hour'];
|
||||
$eh = $sh + ceil($event['duration'] / 60);
|
||||
if($endhour === null || $endhour < $eh) $endhour = $eh;
|
||||
if($starthour === null || $starthour > $sh) $starthour = $sh;
|
||||
}
|
||||
}
|
||||
|
||||
//do some sanity checks
|
||||
if($starthour<0 || $starthour>24) $starthour=8;
|
||||
@ -53,10 +63,6 @@
|
||||
//minute increment
|
||||
$increment=15;
|
||||
|
||||
if(!eregi("[0-9]{4}-[0-9]{2}-[0-9]{2}",$date)) {
|
||||
echo "Invalid date";
|
||||
exit;
|
||||
}
|
||||
echo "<h3>".i18n("Schedule for %1",array(format_date($date)))."</h3>";
|
||||
$q=mysql_query("SELECT * FROM locations WHERE conferences_id='{$conference['id']}' ORDER BY name");
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
@ -93,69 +99,74 @@
|
||||
$js="var eventdivs=new Array();\n";
|
||||
|
||||
//now make all our DIV's for the events that are scheduled in the database
|
||||
$x=0;
|
||||
//they will be moved by javascript after the fact
|
||||
$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']}' AND date='{$date}'");
|
||||
echo mysql_error();
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<div class=\"scheduleevent scheduleevent_{$r->eventtype}\" id=\"event_{$r->id}\" onclick=\"viewEvent($r->id)\">";
|
||||
if(is_array($eventList)){
|
||||
foreach($eventList as $event){
|
||||
// skip this event if it's not on the day we're looking at
|
||||
if($event['date'] != $date) continue;
|
||||
|
||||
// some variables for convenience. Used repeatedly
|
||||
$eid = $event['id'];
|
||||
$hour = $event['hour'];
|
||||
$minute = $event['minute'];
|
||||
$location = $event['locations_id'];
|
||||
$duration = $event['duration'];
|
||||
$eventType = $event['eventtype'];
|
||||
$title = $event['title'];
|
||||
$starttime = strtotime($hour . ":" . $minute);
|
||||
$endtime = $starttime + $duration * 60;
|
||||
|
||||
echo "<div class=\"scheduleevent scheduleevent_$eventType\" id=\"event_$eid\" onclick=\"viewEvent($eid)\">";
|
||||
echo "<span class=\"scheduleevent_title\">";
|
||||
echo $r->title;
|
||||
echo $title;
|
||||
echo "</span>";
|
||||
echo "<br />";
|
||||
$starttime=strtotime($r->hour.":".$r->minute);
|
||||
$endtime=$starttime+$r->duration*60;
|
||||
echo format_time($starttime);
|
||||
echo " to ";
|
||||
echo format_time($endtime);
|
||||
|
||||
if($r->eventtype=="scienceolympic") {
|
||||
if($eventType == "scienceolympic") {
|
||||
echo "<br />";
|
||||
echo i18n("Capacity").": ";
|
||||
$regteams=getNumRegistrations($r->id);
|
||||
$maxteams=$r->somaxteams;
|
||||
echo i18n("%1 of %2",array($regteams,$maxteams))."<br />";
|
||||
|
||||
$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='{$conference['id']}'
|
||||
AND so_teams.schools_id={$school->id}
|
||||
AND schedule_registrations.schedule_id='$r->id'");
|
||||
echo mysql_error();
|
||||
while($regr=mysql_fetch_object($regq)) {
|
||||
echo "<div style=\"padding: 2px; border: 1px solid black; background-color: yellow;\" onclick=\"handleTeamClick(event, {$regr->id}, {$r->events_id});\">";
|
||||
echo $regr->name;
|
||||
$regteams = getNumRegistrations($eid);
|
||||
$maxteams= $event['somaxteams'];
|
||||
echo i18n("%1 of %2", array($regteams, $maxteams)) . "<br />";
|
||||
foreach($event['registrations'] as $regr){
|
||||
echo "<div style=\"padding: 2px; border: 1px solid black; background-color: yellow;\" onclick=\"handleTeamClick(event, {$regr['id']}, $eid);\">";
|
||||
echo $regr['name'];
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
$js.="eventdivs[$r->id]={hour:$r->hour,minute:$r->minute,location:$r->locations_id,duration:$r->duration,title:'".rawurlencode($r->title)."',eventtype:'$r->eventtype'};\n";
|
||||
$x++;
|
||||
$js .= "eventdivs[$eid]={hour:$hour,minute:$minute,location:$location,duration:$duration,title:'".rawurlencode($title)."',eventtype:'$eventType'};\n";
|
||||
}
|
||||
}else{
|
||||
// it's actually an error message
|
||||
echo $eventList;
|
||||
}
|
||||
echo "<script type=\"text/javascript\">\n";
|
||||
echo $js;
|
||||
echo "</script>";
|
||||
}else if($_GET['action']=="loadevent") {
|
||||
}else if($_GET['action']=="loadevent") {
|
||||
|
||||
}else if($_GET['action']=="saveevent") {
|
||||
}else if($_GET['action']=="saveevent") {
|
||||
|
||||
}else if($_GET['action'] == "saveteamlist"){
|
||||
}else if($_GET['action'] == "saveteamlist"){
|
||||
// print_r($_POST);
|
||||
|
||||
// get a list of all students that could be put on this team
|
||||
|
||||
$results = mysql_query("SELECT * FROM users_student
|
||||
JOIN users ON users_student.users_id = users.uid
|
||||
JOIN users_conferences_link ucl ON ucl.users_uid = users_student.users_id
|
||||
WHERE schools_id = $schoolid
|
||||
AND ucl.conferences_id={$conference['id']}
|
||||
AND users.deleted = 'no'");
|
||||
|
||||
$query =
|
||||
"SELECT * FROM users"
|
||||
. " JOIN user_roles ON user_roles.users_id = users.id"
|
||||
. " JOIN roles ON roles.id = user_roles.roles_id"
|
||||
. " WHERE schools_id = $schoolid"
|
||||
. " AND conferences_id = {$conference['id']}"
|
||||
. " AND deleted = 'no'"
|
||||
. " AND roles.type = 'student'";
|
||||
$availList = array();
|
||||
while($record = mysql_fetch_array($results)){
|
||||
$availList[$record['uid']] = $record['firstname'] . ' ' . $record['lastname'];
|
||||
$availList[$record['accounts_id']] = $record['firstname'] . ' ' . $record['lastname'];
|
||||
}
|
||||
|
||||
// let's empty the current list of students for this team
|
||||
@ -173,7 +184,7 @@
|
||||
$query .= implode(',', $valueSet);
|
||||
$results = mysql_query($query);
|
||||
|
||||
}else if($_GET['action'] == "getteamlist"){
|
||||
}else if($_GET['action'] == "getteamlist"){
|
||||
// first we'll get the basic info, and do a quick check that the selected team is in this user's domain
|
||||
if(!array_key_exists('regId', $_POST)){
|
||||
echo "error\n";
|
||||
@ -193,16 +204,19 @@
|
||||
$teamName = $record['name'];
|
||||
|
||||
// get a list of all students that could be put on this team
|
||||
$query = 'SELECT * FROM users_student';
|
||||
$query .= ' JOIN users ON users_student.users_id = users.uid';
|
||||
$query .= ' JOIN users_conferences_link ucl ON ucl.users_uid = users_student.users_id';
|
||||
$query .= ' WHERE schools_id = ' . $schoolid;
|
||||
$query .= ' AND ucl.conferences_id=' . $conference['id'];
|
||||
$query .= ' AND users.deleted = "no"';
|
||||
|
||||
$query =
|
||||
"SELECT * FROM users"
|
||||
. " JOIN user_roles ON user_roles.users_id = users.id"
|
||||
. " JOIN roles ON roles.id = user_roles.roles_id"
|
||||
. " WHERE schools_id = $schoolid"
|
||||
. " AND conferences_id = {$conference['id']}"
|
||||
. " AND deleted = 'no'"
|
||||
. " AND roles.type = 'student'";
|
||||
$results = mysql_query($query);
|
||||
$availList = array();
|
||||
while($record = mysql_fetch_array($results)){
|
||||
$availList[$record['uid']] = $record['firstname'] . ' ' . $record['lastname'];
|
||||
$availList[$record['accounts_id']] = $record['firstname'] . ' ' . $record['lastname'];
|
||||
}
|
||||
|
||||
// now find out which of these students are already selected
|
||||
@ -210,6 +224,7 @@
|
||||
$query .= " WHERE users_uid IN (";
|
||||
$query .= implode(',', array_keys($availList)) . ')';
|
||||
$query .= " AND schedule_registrations_id = " . $_POST['regId'];
|
||||
echo "\n[[[ $query ]]]\n";
|
||||
$results = mysql_query($query);
|
||||
$selectedList = array();
|
||||
if($results){
|
||||
@ -265,7 +280,7 @@
|
||||
echo "max_size=" . $results['default_max_team_size'] . ';';
|
||||
*/
|
||||
echo '</script>';
|
||||
}else{
|
||||
}else{
|
||||
|
||||
send_header("Event Registration",
|
||||
array('School Home' => 'schoolaccess.php'),
|
||||
@ -487,6 +502,5 @@
|
||||
|
||||
send_footer();
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -57,6 +57,13 @@ Date List
|
||||
<input type="submit" value="Edit Team">
|
||||
</form>
|
||||
|
||||
<h1>Event Schedule</h1>
|
||||
<a href="api/schedule/list">Schedule Listing</a><br/>
|
||||
<a href="api/locations/list">Location Listing</a><br/>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<h1>Session Variables</h1>
|
||||
<?
|
||||
echo json_encode($_SESSION);
|
||||
|
Loading…
Reference in New Issue
Block a user