fix the broken judge 'other questions' section and re-implement the missing checkbox functionality

This commit is contained in:
james 2009-10-08 23:28:40 +00:00
parent 383581ef7f
commit c2db9aa106
2 changed files with 18 additions and 19 deletions

View File

@ -59,6 +59,7 @@ case 'save':
$u['highest_psd'] = stripslashes($_POST['highest_psd']);
user_save($u);
questions_save_answers("judgereg",$u['id'],$_POST['questions']);
happy_("Preferences successfully saved");
exit;
}

View File

@ -63,28 +63,22 @@ function questions_load_questions($section, $year)
function questions_save_answers($section, $id, $answers)
{
$qs = questions_load_questions($section);
global $config;
$qs = questions_load_questions($section,$config['FAIRYEAR']);
$keys = array_keys($answers);
$query = "DELETE FROM question_answers ".
"WHERE users_id='$id' ".
" AND (";
$n = 0;
foreach($keys as $qid) {
if($n == 1) $query .= " OR ";
$n = 1;
$query .= " questions_id='$qid'";
}
$query .= ')';
mysql_query($query);
$q=mysql_query("SELECT * FROM questions WHERE year='{$config['FAIRYEAR']}'");
while($r=mysql_fetch_object($q)) {
mysql_query("DELETE FROM question_answers WHERE users_id='$id' AND questions_id='$r->id'");
echo mysql_error();
}
$keys = array_keys($answers);
foreach($keys as $qid) {
/* Poll key */
mysql_query("INSERT INTO question_answers ".
"(users_id,questions_id,answer) VALUES(".
"'$id','$qid',".
"'".mysql_escape_string($answers[$qid])."'".
")" );
mysql_query("INSERT INTO question_answers
(users_id,questions_id,answer) VALUES(
'$id','$qid',
'".mysql_escape_string($answers[$qid])."')" );
}
}
@ -105,7 +99,6 @@ function questions_print_answer_editor($section, &$u, $array_name)
{
$ans = questions_load_answers($section, $u['id']);
$qs = questions_load_questions($section, $u['year']);
$keys = array_keys($qs);
foreach($keys as $qid) {
print("<tr>\n");
@ -125,6 +118,10 @@ function questions_print_answer_editor($section, &$u, $array_name)
"name=\"$iname\" size=10 maxlen=11 ".
"value=\"{$ans[$qid]}\" >\n");
break;
case 'check':
if($ans[$qid]=="yes") $ch="checked=\"checked\""; else $ch="";
print("<input $ch type=\"checkbox\" name=\"$iname\" value=\"yes\">\n");
break;
}
print("</td>\n");
print("</tr>\n");
@ -133,8 +130,9 @@ function questions_print_answer_editor($section, &$u, $array_name)
function questions_print_answers($section, $id)
{
global $config;
$ans = questions_load_answers($section, $id);
$qs = questions_load_questions($section);
$qs = questions_load_questions($section,$config['FAIRYEAR']);
$keys = array_keys($qs);
foreach($keys as $qid) {
echo "<tr>\n";