forked from science-ation/science-ation
Add safetyquestions as part of the project/view and project/edit API
This commit is contained in:
parent
4fe1b04db3
commit
95bbdab5f6
6
api.php
6
api.php
@ -1055,7 +1055,8 @@ switch($request[0]) {
|
|||||||
/* APIDOC: project/view
|
/* APIDOC: project/view
|
||||||
description(Displays the current project information)
|
description(Displays the current project information)
|
||||||
return(project array)
|
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':
|
case 'view':
|
||||||
if($u=user_load($_SESSION['users_id'])) {
|
if($u=user_load($_SESSION['users_id'])) {
|
||||||
@ -1077,6 +1078,8 @@ switch($request[0]) {
|
|||||||
/* APIDOC: project/edit
|
/* APIDOC: project/edit
|
||||||
post(project array)
|
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.)
|
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)
|
return(project array)
|
||||||
*/
|
*/
|
||||||
case 'edit':
|
case 'edit':
|
||||||
@ -1090,7 +1093,6 @@ switch($request[0]) {
|
|||||||
$message = saveProjectData($project);
|
$message = saveProjectData($project);
|
||||||
if($message == 'success'){
|
if($message == 'success'){
|
||||||
$ret['status'] = 'ok';
|
$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']);
|
$ret['project'] = getProject($_SESSION['users_id']);
|
||||||
}else{
|
}else{
|
||||||
$ret['status'] = 'error';
|
$ret['status'] = 'error';
|
||||||
|
@ -273,8 +273,10 @@ function saveProjectData($data){
|
|||||||
$message = i18n("Cannot make changes to forms once they have been received by the fair");
|
$message = i18n("Cannot make changes to forms once they have been received by the fair");
|
||||||
}else if(registrationDeadlinePassed()){
|
}else if(registrationDeadlinePassed()){
|
||||||
$message = i18n("Cannot make changes to forms after registration deadline");
|
$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)){
|
}else if(count($missingFields)){
|
||||||
$message = i18n("Required fields missing: %1", array(implode(', ', $missingFields)));
|
$message = i18n("Required fields missing: %1", array(implode(', ', $missingFields)));
|
||||||
|
*/
|
||||||
}else{
|
}else{
|
||||||
//first, lets make sure this project really does belong to them
|
//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'] . "'");
|
$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'] . "'");
|
"WHERE id='" . $data['project_id'] . "'");
|
||||||
$message = mysql_error();
|
$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 == ''){
|
if($message == ''){
|
||||||
$message = 'success';
|
$message = 'success';
|
||||||
}
|
}
|
||||||
@ -480,6 +496,9 @@ function getProject($userId){
|
|||||||
}else{
|
}else{
|
||||||
$returnval = mysql_fetch_assoc($q);
|
$returnval = mysql_fetch_assoc($q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$safetyquestions=getSafetyQuestions($regId);
|
||||||
|
$returnval['safetyquestions']=$safetyquestions;
|
||||||
return $returnval;
|
return $returnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,4 +756,30 @@ function getMentors($registrations_id){
|
|||||||
}
|
}
|
||||||
return $returnval;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -135,5 +135,7 @@ else if($newstatus=="complete") {
|
|||||||
else
|
else
|
||||||
echo notice(i18n("There are no safety questions to be answered"));
|
echo notice(i18n("There are no safety questions to be answered"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
send_footer();
|
send_footer();
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user