diff --git a/api.php b/api.php index 01a6415..2bf0601 100644 --- a/api.php +++ b/api.php @@ -98,6 +98,8 @@ switch($request[0]) { unset($_SESSION['accounts_id']); unset($_SESSION['superuser']); unset($_SESSION['roles']); + unset($_SESSION['users_id']); + unset($_SESSION['name']); $ret['status']="ok"; } break; @@ -119,13 +121,26 @@ switch($request[0]) { } break; - case "so": - api_user_auth_required('teacher'); + case "scienceolympics": + $chk=api_user_auth_required('teacher'); + if($chk['status']!="ok") { + $ret['status']="error"; + $ret['error']=$chk['error']; + break; + } + $u=user_load($_SESSION['users_id']); + if(!$u['schools_id']) { + $ret['status']="error"; + $ret['error']='Your teacher account is not attached to any school'; + break; + } + $school_id=$u['schools_id']; + + require_once("so_teams.inc.php"); switch($request[1]) { case "teams": switch($request[2]) { case "list": - $u=user_load($_SESSION['users_id']); $q=mysql_query("SELECT id,name FROM so_teams WHERE schools_id='{$u['schools_id']}' AND conferences_id='{$conference['id']}'"); $ret['status']='ok'; $teams=array(); @@ -135,27 +150,59 @@ switch($request[0]) { $ret['teams']=$teams; break; case "add": - $ret['status']='error'; - $ret['error']='not implemented yet'; + if($_POST['teamname']) { + if(so_team_add($school_id,$conference['id'],$_POST['teamname'])) { + $ret['status']="ok"; + } + else { + $ret['status']='error'; + $ret['error']='could not add team'; + } + } else { + $ret['status']='error'; + $ret['error']='teamname (varchar 64) is required'; + } break; case "edit": - $ret['status']='error'; - $ret['error']='not implemented yet'; + if($_POST['id'] && $_POST['teamname']) { + if(so_team_edit($school_id,$_POST['id'],$_POST['teamname'])) { + $ret['status']="ok"; + } + else { + $ret['status']='error'; + $ret['error']='could not edit team'; + } + } + else { + $ret['status']='error'; + $ret['error']='id (integer), teamname (varchar 64) are required'; + } break; - case "remove"; - $ret['status']='error'; - $ret['error']='not implemented yet'; + case "delete"; + if($_POST['id']) { + if(so_team_delete($school_id,$_POST['id'])) { + $ret['status']="ok"; + } + else { + $ret['status']='error'; + $ret['error']='could not delete team'; + } + } else { + $ret['status']='error'; + $ret['error']='id (integer) is required'; + } + break; default: $ret['status']="error"; - $ret['error']="invalid so/teams command ({$request[2]})"; + $ret['error']="invalid scienceolympics/teams command ({$request[2]})"; break; } break; default: $ret['status']="error"; - $ret['error']="invalid so command ({$request[1]})"; + $ret['error']="invalid scienceolympics command ({$request[1]})"; break; } break; diff --git a/schoolteams.php b/schoolteams.php index 9498456..e3ac690 100644 --- a/schoolteams.php +++ b/schoolteams.php @@ -1,17 +1,18 @@