Fix judging registration

This commit is contained in:
arman 2025-02-05 22:47:16 +00:00
parent f978216b43
commit c6eaf1089f
2 changed files with 17 additions and 7 deletions

View File

@ -81,7 +81,10 @@ switch (get_value_from_array($_GET, 'action')) {
} }
user_save($u); user_save($u);
questions_save_answers('judgereg', $u['id'], $_POST['questions']);
if($POST['questions'])
questions_save_answers('judgereg', $u['id'], $_POST['questions']);
happy_('Preferences successfully saved'); happy_('Preferences successfully saved');
$u = user_load($eid); $u = user_load($eid);

View File

@ -63,16 +63,20 @@ function questions_load_questions($section, $year)
$qs[$r->id]['required'] = $r->required; $qs[$r->id]['required'] = $r->required;
$qs[$r->id]['question'] = $r->question; $qs[$r->id]['question'] = $r->question;
} }
return $qs; return $qs;
} }
function questions_save_answers($section, $id, $answers) function questions_save_answers($section, $id, $answers)
{ {
global $config, $pdo; global $config, $pdo;
$qs = questions_load_questions($section, $config['FAIRYEAR']); $qs = questions_load_questions($section, $config['FAIRYEAR']);
$keys = array_keys($answers); $keys = array_keys($answers);
$q = $pdo->prepare("SELECT * FROM questions WHERE year='{$config['FAIRYEAR']}'"); $q = $pdo->prepare("SELECT * FROM questions WHERE year='{$config['FAIRYEAR']}'");
$q->execute(); $q->execute();
while ($r = $q->fetch(PDO::FETCH_OBJ)) { while ($r = $q->fetch(PDO::FETCH_OBJ)) {
$stmt = $pdo->prepare("DELETE FROM question_answers WHERE users_id='$id' AND questions_id='$r->id'"); $stmt = $pdo->prepare("DELETE FROM question_answers WHERE users_id='$id' AND questions_id='$r->id'");
$stmt->execute(); $stmt->execute();
@ -109,21 +113,24 @@ function questions_print_answer_editor($section, &$u, $array_name)
$ans = questions_load_answers($section, $u['id']); $ans = questions_load_answers($section, $u['id']);
$qs = questions_load_questions($section, $u['year']); $qs = questions_load_questions($section, $u['year']);
$keys = array_keys($qs); $keys = array_keys($qs);
foreach ($keys as $qid) { foreach ($keys as $qid) {
$required = $qs[$qid]['required'] == 'yes' ? '<span class="requiredfield" style="float:right">&nbsp;*</span>' : ''; $required = $qs[$qid]['required'] == 'yes' ? '<span class="requiredfield" style="float:right">&nbsp;*</span>' : '';
print("<tr>\n"); print("<tr>\n");
print(" <td colspan=\"2\">$required" . i18n($qs[$qid]['question']) . "</td>\n"); print(" <td colspan=\"2\">$required" . i18n($qs[$qid]['question']) . "</td>\n");
print(' <td colspan="2">'); print(' <td colspan="2">');
$iname = "{$array_name}[{$qid}]"; $iname = "{$array_name}[{$qid}]";
switch ($qs[$qid]['type']) { switch ($qs[$qid]['type']) {
case 'yesno': case 'yesno':
if ($ans[$qid] == 'yes') if ($ans[$qid]->answer == 'yes')
$ch = 'checked="checked"'; $ch = 'checked="checked"';
else else
$ch = ''; $ch = '';
print("<input onclick=\"fieldChanged()\" $ch type=\"radio\" name=\"$iname\" value=\"yes\" />" . i18n('Yes')); print("<input onclick=\"fieldChanged()\" $ch type=\"radio\" name=\"$iname\" value=\"yes\" />" . i18n('Yes'));
print('&nbsp; &nbsp; '); print('&nbsp; &nbsp; ');
if ($ans[$qid] == 'no') if ($ans[$qid]->answer == 'no')
$ch = 'checked="checked"'; $ch = 'checked="checked"';
else else
$ch = ''; $ch = '';
@ -135,14 +142,14 @@ function questions_print_answer_editor($section, &$u, $array_name)
. "value=\"{$ans[$qid]}\" >\n"); . "value=\"{$ans[$qid]}\" >\n");
break; break;
case 'check': case 'check':
if ($ans[$qid] == 'yes') if ($ans[$qid]->answer == 'yes')
$ch = 'checked="checked"'; $ch = 'checked="checked"';
else else
$ch = ''; $ch = '';
print("<input $ch type=\"checkbox\" name=\"$iname\" value=\"yes\">\n"); print("<input $ch type=\"checkbox\" name=\"$iname\" value=\"yes\">\n");
break; break;
case 'text': case 'text':
print("<input type=\"text\" name=\"$iname\" value=\"{$ans[$qid]}\">\n"); print("<input type=\"text\" name=\"$iname\" value=\"{$ans[$qid]->answer}\">\n");
break; break;
} }
print("</td>\n"); print("</td>\n");