From c6eaf1089f3f411cae47b695fdbf4e5e638e6528 Mon Sep 17 00:00:00 2001 From: arman Date: Wed, 5 Feb 2025 22:47:16 +0000 Subject: [PATCH] Fix judging registration --- judge_other.php | 7 +++++-- questions.inc.php | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/judge_other.php b/judge_other.php index 1b43773f..bf55b783 100644 --- a/judge_other.php +++ b/judge_other.php @@ -80,8 +80,11 @@ switch (get_value_from_array($_GET, 'action')) { $u['flagged_judge'] = '1'; } - user_save($u); - questions_save_answers('judgereg', $u['id'], $_POST['questions']); + user_save($u); + + if($POST['questions']) + questions_save_answers('judgereg', $u['id'], $_POST['questions']); + happy_('Preferences successfully saved'); $u = user_load($eid); diff --git a/questions.inc.php b/questions.inc.php index 9be4a663..3cf6b7f6 100644 --- a/questions.inc.php +++ b/questions.inc.php @@ -43,7 +43,7 @@ function questions_load_answers($section, $users_id) } function questions_load_questions($section, $year) -{ +{ global $pdo; $q = $pdo->prepare('SELECT * FROM questions ' . "WHERE year='$year' " @@ -63,16 +63,20 @@ function questions_load_questions($section, $year) $qs[$r->id]['required'] = $r->required; $qs[$r->id]['question'] = $r->question; } + return $qs; } function questions_save_answers($section, $id, $answers) { global $config, $pdo; + $qs = questions_load_questions($section, $config['FAIRYEAR']); $keys = array_keys($answers); $q = $pdo->prepare("SELECT * FROM questions WHERE year='{$config['FAIRYEAR']}'"); $q->execute(); + + while ($r = $q->fetch(PDO::FETCH_OBJ)) { $stmt = $pdo->prepare("DELETE FROM question_answers WHERE users_id='$id' AND questions_id='$r->id'"); $stmt->execute(); @@ -109,21 +113,24 @@ 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) { + $required = $qs[$qid]['required'] == 'yes' ? ' *' : ''; print("\n"); print(" $required" . i18n($qs[$qid]['question']) . "\n"); print(' '); $iname = "{$array_name}[{$qid}]"; + switch ($qs[$qid]['type']) { case 'yesno': - if ($ans[$qid] == 'yes') + if ($ans[$qid]->answer == 'yes') $ch = 'checked="checked"'; else $ch = ''; print("" . i18n('Yes')); print('    '); - if ($ans[$qid] == 'no') + if ($ans[$qid]->answer == 'no') $ch = 'checked="checked"'; else $ch = ''; @@ -135,14 +142,14 @@ function questions_print_answer_editor($section, &$u, $array_name) . "value=\"{$ans[$qid]}\" >\n"); break; case 'check': - if ($ans[$qid] == 'yes') + if ($ans[$qid]->answer == 'yes') $ch = 'checked="checked"'; else $ch = ''; print("\n"); break; case 'text': - print("\n"); + print("answer}\">\n"); break; } print("\n");