From d5a5e9800fbf519753e47f510dde2ac8a89921ab Mon Sep 17 00:00:00 2001 From: james Date: Fri, 10 Dec 2004 21:23:59 +0000 Subject: [PATCH] save the safety responses in the safety table --- register_participants_safety.php | 40 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/register_participants_safety.php b/register_participants_safety.php index 13ecae8..8595e87 100644 --- a/register_participants_safety.php +++ b/register_participants_safety.php @@ -39,29 +39,19 @@ echo mysql_error(); if($_POST['action']=="save") { - /* - do nothing yet - //first, lets make sure this project really does belong to them - $q=mysql_query("SELECT * FROM projects WHERE id='".$_POST['id']."' AND registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); - if(mysql_num_rows($q)==1) + //first we will delete all their old answer, its easier to delete and re-insert in this case then it would be to find the corresponding answers and update them + mysql_query("DELETE FROM safety WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); + $safetyids=array_keys($_POST['safety']); + foreach($safetyids AS $key=>$val) { - mysql_query("UPDATE projects SET ". - "title='".mysql_escape_string(stripslashes($_POST['title']))."', ". - "projectdivisions_id='".$_POST['projectdivisions_id']."', ". - "language='".mysql_escape_string(stripslashes($_POST['language']))."', ". - "req_table='".mysql_escape_string(stripslashes($_POST['req_table']))."', ". - "req_electricity='".mysql_escape_string(stripslashes($_POST['req_electricity']))."', ". - "req_special='".mysql_escape_string(stripslashes($_POST['req_special']))."', ". - "summary='".mysql_escape_string(stripslashes($_POST['summary']))."' ". - "WHERE id='".$_POST['id']."'"); + mysql_query("INSERT INTO safety (registrations_id,safetyquestions_id,year,answer) VALUES (". + "'".$_SESSION['registration_id']."', ". + "'$val', ". + "'".$config['FAIRYEAR']."', ". + "'".mysql_escape_string(stripslashes($_POST['safety'][$val]))."')"); echo mysql_error(); - echo notice(i18n("Safety information successfully updated")); + } - else - { - echo error(i18n("Invalid project to update")); - } -*/ } @@ -81,16 +71,22 @@ else if($newstatus=="complete") echo "\n"; echo "\n"; + $q=mysql_query("SELECT * FROM safety WHERE registrations_id='".$_SESSION['registration_id']."'"); + while($r=mysql_fetch_object($q)) + { + $safetyanswers[$r->safetyquestions_id]=$r->answer; + } + $q=mysql_query("SELECT * FROM safetyquestions ORDER BY ord"); $num=1; while($r=mysql_fetch_object($q)) { - echo ""; echo ""; echo "";
$num. ".i18n($r->question).""; if($r->type=="check") { - echo "id]\" value=\"checked\" />"; + if($safetyanswers[$r->id]=="checked") $ch="checked=\"checked\""; else $ch=""; + echo "id]\" value=\"checked\" />"; } echo "