Add API registration/view

Add API registration/edit
This commit is contained in:
james 2011-03-02 23:52:44 +00:00
parent b955b01965
commit 87940b54de
3 changed files with 115 additions and 21 deletions

57
api.php
View File

@ -900,6 +900,63 @@ switch($request[0]) {
} }
break; 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': case 'project':
$chk=api_user_auth_required('participant'); $chk=api_user_auth_required('participant');
if($chk['status']!="ok") { if($chk['status']!="ok") {

View File

@ -47,8 +47,7 @@ function registrationDeadlinePassed()
} }
function studentStatus($reg_id="") function studentIndividualStatus($userid) {
{
global $config, $conference; global $config, $conference;
if($config['participant_student_personal']=="yes") if($config['participant_student_personal']=="yes")
$required_fields=array("firstname","lastname","address","city","postalcode","phonehome","grade","dateofbirth","schools_id","sex"); $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") if($config['participant_student_tshirt']=="yes")
$required_fields[]="tshirt"; $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; if($reg_id) $rid=$reg_id;
else $rid=$_SESSION['registration_id']; else $rid=$_SESSION['registration_id'];
@ -67,23 +85,11 @@ function studentStatus($reg_id="")
if(mysql_num_rows($q)<$config['minstudentsperproject']) if(mysql_num_rows($q)<$config['minstudentsperproject'])
return "incomplete"; return "incomplete";
while($r=mysql_fetch_object($q)) while($r=mysql_fetch_object($q)) {
{ //if any one of them is incomplete, then the overall status is incomplete
foreach ($required_fields AS $req) if(studentIndividualStatus($r->id)=='incomplete')
{ return 'incomplete';
if($req=="dateofbirth")
{
if($r->$req=="0000-00-00" || !$r->$req)
return "incomplete";
}
else
{
if(!$r->$req)
return "incomplete";
}
}
} }
//if it made it through without returning incomplete, then we must be complete //if it made it through without returning incomplete, then we must be complete
return "complete"; return "complete";
} }
@ -315,9 +321,14 @@ function namecheckStatus($reg_id="")
return 'complete'; return 'complete';
} }
function participant_status_completion_details($u){ function participant_status_completion_details($u,$regId=null){
$p = getProject($u['id']); if($regId) {
$regId = $p['registrations_id']; //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){ if(!$regId){
return array( return array(
'namecheck' => 'incomplete', 'namecheck' => 'incomplete',

View File

@ -317,6 +317,7 @@ function saveProjectData($data){
"summarycountok='$summarycountok'" . "summarycountok='$summarycountok'" .
"WHERE id='" . $data['project_id'] . "'"); "WHERE id='" . $data['project_id'] . "'");
$message = mysql_error(); $message = mysql_error();
if($message == ''){ if($message == ''){
$message = 'success'; $message = 'success';
} }
@ -414,6 +415,31 @@ function getRegistrationsId($user){
return $result['registrations_id']; 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){ function getProject($userId){
global $conference; global $conference;