forked from science-ation/science-ation
Add API registration/view
Add API registration/edit
This commit is contained in:
parent
b955b01965
commit
87940b54de
57
api.php
57
api.php
@ -900,6 +900,63 @@ 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)
|
||||
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") {
|
||||
|
@ -47,8 +47,7 @@ function registrationDeadlinePassed()
|
||||
|
||||
}
|
||||
|
||||
function studentStatus($reg_id="")
|
||||
{
|
||||
function studentIndividualStatus($userid) {
|
||||
global $config, $conference;
|
||||
if($config['participant_student_personal']=="yes")
|
||||
$required_fields=array("firstname","lastname","address","city","postalcode","phonehome","grade","dateofbirth","schools_id","sex");
|
||||
@ -58,6 +57,25 @@ function studentStatus($reg_id="")
|
||||
if($config['participant_student_tshirt']=="yes")
|
||||
$required_fields[]="tshirt";
|
||||
|
||||
$q=mysql_query("SELECT * FROM users WHERE id='{$userid}' AND conferences_id='{$conference['id']}'");
|
||||
$r=mysql_fetch_object($q);
|
||||
|
||||
foreach ($required_fields AS $req) {
|
||||
if($req=="dateofbirth") {
|
||||
if($r->$req=="0000-00-00" || !$r->$req)
|
||||
return "incomplete";
|
||||
}
|
||||
else {
|
||||
if(!$r->$req)
|
||||
return "incomplete";
|
||||
}
|
||||
}
|
||||
return 'complete';
|
||||
}
|
||||
|
||||
function studentStatus($reg_id="") {
|
||||
global $config, $conference;
|
||||
|
||||
if($reg_id) $rid=$reg_id;
|
||||
else $rid=$_SESSION['registration_id'];
|
||||
|
||||
@ -67,23 +85,11 @@ function studentStatus($reg_id="")
|
||||
if(mysql_num_rows($q)<$config['minstudentsperproject'])
|
||||
return "incomplete";
|
||||
|
||||
while($r=mysql_fetch_object($q))
|
||||
{
|
||||
foreach ($required_fields AS $req)
|
||||
{
|
||||
if($req=="dateofbirth")
|
||||
{
|
||||
if($r->$req=="0000-00-00" || !$r->$req)
|
||||
return "incomplete";
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
//if any one of them is incomplete, then the overall status is incomplete
|
||||
if(studentIndividualStatus($r->id)=='incomplete')
|
||||
return 'incomplete';
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$r->$req)
|
||||
return "incomplete";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if it made it through without returning incomplete, then we must be complete
|
||||
return "complete";
|
||||
}
|
||||
@ -315,9 +321,14 @@ function namecheckStatus($reg_id="")
|
||||
return 'complete';
|
||||
}
|
||||
|
||||
function participant_status_completion_details($u){
|
||||
function participant_status_completion_details($u,$regId=null){
|
||||
if($regId) {
|
||||
//just use it
|
||||
}else {
|
||||
//we onlty have the user object, so get the regId from that
|
||||
$p = getProject($u['id']);
|
||||
$regId = $p['registrations_id'];
|
||||
}
|
||||
if(!$regId){
|
||||
return array(
|
||||
'namecheck' => 'incomplete',
|
||||
|
@ -317,6 +317,7 @@ function saveProjectData($data){
|
||||
"summarycountok='$summarycountok'" .
|
||||
"WHERE id='" . $data['project_id'] . "'");
|
||||
$message = mysql_error();
|
||||
|
||||
if($message == ''){
|
||||
$message = 'success';
|
||||
}
|
||||
@ -414,6 +415,31 @@ function getRegistrationsId($user){
|
||||
|
||||
return $result['registrations_id'];
|
||||
}
|
||||
function getRegistration($id) {
|
||||
global $conference;
|
||||
$q=mysql_query("SELECT id,num,start,status,end,nummentors FROM registrations WHERE id='$id' AND conferences_id='{$conference['id']}'");
|
||||
$reg=mysql_fetch_assoc($q);
|
||||
if(!$reg) return null;
|
||||
|
||||
$s=mysql_query("SELECT users.id,users.firstname,users.lastname, accounts.id AS accounts_id, accounts.username FROM users JOIN accounts ON users.accounts_id=accounts.id WHERE users.registrations_id='$id' AND users.conferences_id='{$conference['id']}'");
|
||||
while($r=mysql_fetch_assoc($s)) {
|
||||
$r['complete']=studentIndividualStatus($r['id']);
|
||||
$reg['students'][]=$r;
|
||||
}
|
||||
|
||||
$reg['status']=participant_status_completion_details(null,$id);
|
||||
return $reg;
|
||||
}
|
||||
|
||||
function saveRegistrationData($d) {
|
||||
global $conference;
|
||||
if($d['id']) {
|
||||
mysql_query("UPDATE registrations SET nummentors='{$d['nummentors']}' WHERE id='{$d['id']}' AND conferences_id='{$conference['id']}'");
|
||||
return getRegistration($d['id']);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
function getProject($userId){
|
||||
global $conference;
|
||||
|
Loading…
Reference in New Issue
Block a user