Add safetyquestions as part of the project/view and project/edit API

This commit is contained in:
james 2011-03-03 02:57:40 +00:00
parent 4fe1b04db3
commit 95bbdab5f6
3 changed files with 51 additions and 2 deletions

View File

@ -1055,7 +1055,8 @@ switch($request[0]) {
/* APIDOC: project/view
description(Displays the current project information)
return(project array)
object(project: {project_id integer, projectdivisions_id integer, title varchar(255), language char(2), req_electricity enum('no', 'yes'), req_table enum('no', 'yes'), req_special varchar(128), summary text})
object(project: {project_id integer, projectdivisions_id integer, title varchar(255), language char(2), req_electricity enum('no', 'yes'), req_table enum('no', 'yes'), req_special varchar(128), summary text,safetyquestions array of question})
object(question: {id,question,type,required,ord,answer})
*/
case 'view':
if($u=user_load($_SESSION['users_id'])) {
@ -1077,6 +1078,8 @@ switch($request[0]) {
/* APIDOC: project/edit
post(project array)
description(Edit an existing project. "language" notes the language a participant wishes to be judged in. "req_electricity" notes whethor or not the project requires an electrical outlet. "req_table" states whether or not the project needs a table. "req_special" is a field for special requirements.)
object(project: as per project/view)
object(question: for sake of not re-transmitting all the safetyquestion text, the only fields required to save are {id,answer})
return(project array)
*/
case 'edit':
@ -1090,7 +1093,6 @@ switch($request[0]) {
$message = saveProjectData($project);
if($message == 'success'){
$ret['status'] = 'ok';
//FIXME: this should getProject or something to reload whats actually in the database instead of just returning what they gave us
$ret['project'] = getProject($_SESSION['users_id']);
}else{
$ret['status'] = 'error';

View File

@ -273,8 +273,10 @@ function saveProjectData($data){
$message = i18n("Cannot make changes to forms once they have been received by the fair");
}else if(registrationDeadlinePassed()){
$message = i18n("Cannot make changes to forms after registration deadline");
/* if fields are missing, thtas okay, save what we do have, no point makign them re-enter the whole thing
}else if(count($missingFields)){
$message = i18n("Required fields missing: %1", array(implode(', ', $missingFields)));
*/
}else{
//first, lets make sure this project really does belong to them
$q = mysql_query("SELECT * FROM projects WHERE id='" . $data['project_id'] . "' AND registrations_id='" . $_SESSION['registration_id'] . "' AND conferences_id='" . $conference['id'] . "'");
@ -318,6 +320,20 @@ function saveProjectData($data){
"WHERE id='" . $data['project_id'] . "'");
$message = mysql_error();
//update the safetyquestion answers (safety table)
if(is_array($data['safetyquestions'])) {
//wipe them all out first
mysql_query("DELETE FROM safety WHERE registrations_id='{$_SESSION['registration_id']}' AND conferences_id='{$conference['id']}'");
//and add them back
foreach($data['safetyquestions'] AS $q) {
mysql_query("INSERT INTO safety (registrations_id,safetyquestions_id,answer,conferences_id) VALUES (
'{$_SESSION['registration_id']}',
'{$q['id']}',
'".mysql_real_escape_string($q['answer'])."',
'{$conference['id']}')");
}
}
if($message == ''){
$message = 'success';
}
@ -480,6 +496,9 @@ function getProject($userId){
}else{
$returnval = mysql_fetch_assoc($q);
}
$safetyquestions=getSafetyQuestions($regId);
$returnval['safetyquestions']=$safetyquestions;
return $returnval;
}
@ -737,4 +756,30 @@ function getMentors($registrations_id){
}
return $returnval;
}
function getSafetyQuestions($reg_id="") {
global $conference;
if($reg_id) $regId=$reg_id;
else $regId=$_SESSION['registration_id'];
//get their answers
$safetyanswers=array();
$q=mysql_query("SELECT * FROM safety WHERE registrations_id='$regId'");
while($r=mysql_fetch_object($q)) {
$safetyanswers[$r->safetyquestions_id]=$r->answer;
}
$ret=array();
//now get all the possible questiosn
$q=mysql_query("SELECT `id`,`question`,`type`,`required`,`ord` FROM safetyquestions WHERE conferences_id='".$conference['id']."' ORDER BY ord");
while($r=mysql_fetch_assoc($q)) {
if(array_key_exists($r['id'],$safetyanswers))
$r['answer']=$safetyanswers[$r['id']];
else
$r['answer']=null;
$ret[]=$r;
}
return $ret;
}
?>

View File

@ -135,5 +135,7 @@ else if($newstatus=="complete") {
else
echo notice(i18n("There are no safety questions to be answered"));
send_footer();
?>