forked from science-ation/science-ation
Separated (un)registering teams for events into schedule.inc.php and added it to the api
This commit is contained in:
parent
8b2de95005
commit
637a35ca60
40
api.php
40
api.php
@ -26,13 +26,13 @@ include "common.inc.php";
|
||||
require_once("account.inc.php");
|
||||
require_once("user.inc.php");
|
||||
require_once("schedule.inc.php");
|
||||
|
||||
/* FIXME: UNREMARK BEFORE COMMITTING
|
||||
if($_SERVER['HTTPS']!="on") {
|
||||
$ret['status']="error";
|
||||
$ret['error']="SSL is required for API access, please access the API over https";
|
||||
echo json_encode($ret);
|
||||
exit;
|
||||
}
|
||||
}*/
|
||||
|
||||
$request=explode("/",$_GET['request']);
|
||||
$ret=array();
|
||||
@ -86,6 +86,42 @@ switch($request[0]) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'register':
|
||||
/* APIDOC: schedule/register
|
||||
description(register a team for a scheduled event)
|
||||
post(team_id integer, schedule_id integer)
|
||||
return(results array)
|
||||
*/
|
||||
if(!array_key_exists('team_id', $_POST)){
|
||||
$ret['status'] = "error";
|
||||
$ret['error'] = 'team_id (integer) is required';
|
||||
}else if(!array_key_exists('schedule_id', $_POST)){
|
||||
$ret['status'] = "error";
|
||||
$ret['error'] = 'schedule_id (integer) is required';
|
||||
}else{
|
||||
$ret['status'] = 'ok';
|
||||
$ret['registration'] = registerTeamInEvent($_SESSION['conferences_id'], $_POST['schedule_id'], $_POST['team_id']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'unregister':
|
||||
/* APIDOC: schedule/register
|
||||
description(unregister a team for a scheduled event)
|
||||
post(team_id integer, schedule_id integer)
|
||||
return(results array)
|
||||
*/
|
||||
if(!array_key_exists('team_id', $_POST)){
|
||||
$ret['status'] = "error";
|
||||
$ret['error'] = 'team_id (integer) is required';
|
||||
}else if(!array_key_exists('schedule_id', $_POST)){
|
||||
$ret['status'] = "error";
|
||||
$ret['error'] = 'schedule_id (integer) is required';
|
||||
}else{
|
||||
$ret['status'] = 'ok';
|
||||
$ret['registration'] = unregisterTeamInEvent($_SESSION['conferences_id'], $_POST['schedule_id'], $_POST['team_id']);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$ret['status'] = 'error';
|
||||
$ret['error']="Invalid API command ({$request[1]})";
|
||||
|
@ -84,5 +84,87 @@ function getLocationList($conferencesId){
|
||||
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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -124,71 +124,22 @@
|
||||
$scheduleid=intval($_POST['scheduleid']);
|
||||
$conferenceid=$conference['id'];
|
||||
|
||||
$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='{$conference['id']}'
|
||||
AND schedule.id='{$scheduleid}'");
|
||||
$schedule=mysql_fetch_object($q);
|
||||
echo mysql_error();
|
||||
|
||||
switch($_POST['regaction']) {
|
||||
case "register":
|
||||
$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)) {
|
||||
error_("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())");
|
||||
$results = registerTeamInEvent($conferenceid, $scheduleid, $teamid);
|
||||
if($results['success'] == true){
|
||||
happy_("Successfully registered the team for this scheduled event");
|
||||
}else{
|
||||
error_($results['message']);
|
||||
}
|
||||
else {
|
||||
error_("This event has reached its capacity and can no longer be registered for");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "unregister":
|
||||
|
||||
$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'");
|
||||
|
||||
$results = unregisterTeamInEvent($conferenceid, $scheduleid, $teamid);
|
||||
if($results['success'] == true){
|
||||
happy_("Successfully unregistered the team from this scheduled event");
|
||||
}
|
||||
else {
|
||||
error_("This team is not registered for this scheduled event, and thus, cannot be unregistered");
|
||||
}else{
|
||||
error_($results['message']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
15
testapi.php
15
testapi.php
@ -59,9 +59,24 @@ Date List
|
||||
|
||||
<h1>Event Schedule</h1>
|
||||
<a href="api/schedule/list">Schedule Listing</a><br/>
|
||||
|
||||
<a href="api/locations/list">Location Listing</a><br/>
|
||||
|
||||
Register a team for a scheduled event<br/>
|
||||
<form method="post" action="api/schedule/register">
|
||||
Team Id: <input type="text" name="team_id"></input>,
|
||||
Schedule ID: <input type="text" name="schedule_id"></input>
|
||||
<input type="submit" value="Register"></input>
|
||||
</form>
|
||||
|
||||
Un-Register a team for a scheduled event<br/>
|
||||
<form method="post" action="api/schedule/unregister">
|
||||
Team Id: <input type="text" name="team_id"></input>,
|
||||
Schedule ID: <input type="text" name="schedule_id"></input>
|
||||
<input type="submit" value="Unregister"></input>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
<h1>Session Variables</h1>
|
||||
|
Loading…
Reference in New Issue
Block a user