diff --git a/api.php b/api.php index afedad8..ab53aea 100644 --- a/api.php +++ b/api.php @@ -877,6 +877,71 @@ switch($request[0]) { } break; + /* APIDOC: registration/view + description(registration information about the currently logged in users registration) + object(registration: {id,num,status,end,nummentors,students array of student,status array) + object(student: {id,accounts_id,username,firstname,lastname,complete) + return(registration array) + */ + case 'view': + $chk=api_user_auth_required('participant'); + if($chk['status']!="ok") { + $ret['status']="error"; + $ret['error']=$chk['error']; + break; + } + + if(!$_SESSION['registrations_id']) { + $ret['status']="error"; + $ret['error']="No registration has been created or joined yet"; + break; + } + + // be logged in as a student in order to create a project + $r=getRegistration($_SESSION['registrations_id']); + if($r) { + $ret['status']="ok"; + $ret['registration']=$r; + } + else { + $ret['status'] = 'error'; + $ret['error']="Invalid registration id"; + } + break; + default: + + /* APIDOC: registration/edit + description(update registration information. Updatable data: nummentors) + post(registration array) + return(registration array) + */ + case 'edit': + $chk=api_user_auth_required('participant'); + if($chk['status']!="ok") { + $ret['status']="error"; + $ret['error']=$chk['error']; + break; + } + + if(!$_SESSION['registrations_id']) { + $ret['status']="error"; + $ret['error']="No registration has been created or joined yet"; + break; + } + // be logged in as a student in order to create a project + $r=json_decode($_POST['registration'],true); + if(is_array($r)) { + $ret['status']='ok'; + $newreg=saveRegistrationData($r); + $ret['registration']=$newreg; + } else { + $ret['status']='error'; + $ret['error']="registration array required"; + } + + break; + + default: $ret['status']="error"; $ret['error']="invalid registration API command ({$request[1]})"; @@ -900,63 +965,6 @@ switch($request[0]) { } break; - case 'registration': - $chk=api_user_auth_required('participant'); - if($chk['status']!="ok") { - $ret['status']="error"; - $ret['error']=$chk['error']; - break; - } - - if(!$_SESSION['registrations_id']) { - $ret['status']="error"; - $ret['error']="No registration has been created or joined yet"; - break; - } - - switch($request[1]){ - /* APIDOC: registration/view - description(registration information about the currently logged in users registration) - object(registration: {id,num,status,end,nummentors,students array of student,status array) - object(student: {id,accounts_id,username,firstname,lastname,complete) - return(registration array) - */ - case 'view': - // be logged in as a student in order to create a project - $r=getRegistration($_SESSION['registrations_id']); - if($r) { - $ret['status']="ok"; - $ret['registration']=$r; - } - else { - $ret['status'] = 'error'; - $ret['error']="Invalid registration id"; - } - break; - default: - - /* APIDOC: registration/edit - description(update registration information. Updatable data: nummentors) - post(registration array) - return(registration array) - */ - case 'edit': - // be logged in as a student in order to create a project - $r=json_decode($_POST['registration'],true); - if(is_array($r)) { - $ret['status']='ok'; - $newreg=saveRegistrationData($r); - $ret['registration']=$newreg; - } else { - $ret['status']='error'; - $ret['error']="registration array required"; - } - - break; - } - break; - - case 'project': $chk=api_user_auth_required('participant'); if($chk['status']!="ok") {