From e77fc688f020d82c36e3e77350f87d780657a161 Mon Sep 17 00:00:00 2001 From: arman Date: Mon, 3 Feb 2025 01:04:45 +0000 Subject: [PATCH] Made the "Judge Registration Questions" page functional --- config/signaturepage.php | 5 +++ questions.inc.php | 85 +++++++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/config/signaturepage.php b/config/signaturepage.php index 1afa723f..dff4b2b8 100644 --- a/config/signaturepage.php +++ b/config/signaturepage.php @@ -68,6 +68,11 @@ if (get_value_from_array($_POST, 'action') == 'save') { $stmt = $pdo->prepare("UPDATE signaturepage SET `use`='$usepa', `text`='" . get_value_from_array($_POST, 'postamble') . "' WHERE name='postamble'"); $stmt->execute(); + + echo $_POST['useteacherdeclaration']; + $stmt = $pdo->prepare("UPDATE signaturepage SET `use`='$usete', `text`='" . get_value_from_array($_POST, 'useteacherdeclaration') . "' WHERE name='useteacherdeclaration'"); + $stmt->execute(); + $stmt = $pdo->prepare("UPDATE signaturepage SET `use`='$userf', `text`='' WHERE name='regfee'"); $stmt->execute(); echo happy(i18n("$sentence_begin_participationform text successfully saved")); diff --git a/questions.inc.php b/questions.inc.php index 994f00bb..9be4a663 100644 --- a/questions.inc.php +++ b/questions.inc.php @@ -33,7 +33,7 @@ function questions_load_answers($section, $users_id) $ans = array(); $qs = questions_load_questions($section, $yearr->year); - foreach ($qs AS $id => $question) { + foreach ($qs as $id => $question) { $q = $pdo->prepare("SELECT * FROM question_answers WHERE users_id='$users_id' AND questions_id='$id'"); $q->execute(); $r = $q->fetch(PDO::FETCH_OBJ); @@ -111,9 +111,9 @@ function questions_print_answer_editor($section, &$u, $array_name) $keys = array_keys($qs); foreach ($keys as $qid) { $required = $qs[$qid]['required'] == 'yes' ? ' *' : ''; - print ("\n"); - print (" $required" . i18n($qs[$qid]['question']) . "\n"); - print (' '); + print("\n"); + print(" $required" . i18n($qs[$qid]['question']) . "\n"); + print(' '); $iname = "{$array_name}[{$qid}]"; switch ($qs[$qid]['type']) { case 'yesno': @@ -121,16 +121,16 @@ function questions_print_answer_editor($section, &$u, $array_name) $ch = 'checked="checked"'; else $ch = ''; - print ("" . i18n('Yes')); - print ('    '); + print("" . i18n('Yes')); + print('    '); if ($ans[$qid] == 'no') $ch = 'checked="checked"'; else $ch = ''; - print ("" . i18n('No')); + print("" . i18n('No')); break; case 'int': - print ('\n"); break; @@ -139,14 +139,14 @@ function questions_print_answer_editor($section, &$u, $array_name) $ch = 'checked="checked"'; else $ch = ''; - print ("\n"); + print("\n"); break; case 'text': - print ("\n"); + print("\n"); break; } - print ("\n"); - print ("\n"); + print("\n"); + print("\n"); } } @@ -182,12 +182,20 @@ function questions_update_question($qs) global $pdo; $qs['ord'] = $qs['ord'] ?? ''; $stmt = $pdo->prepare("UPDATE questions SET - `question`='" . $qs['question'] . "', - `type`='" . $qs['type'] . "', - `db_heading`='" . $qs['db_heading'] . "', - `required`='" . $qs['required'] . "', - `ord`=" . intval($qs['ord'] . " - WHERE id='{$qs['id']}' ")); + `question` = :question, + `type` = :type, + `db_heading` = :db_heading, + `required` = :required, + `ord` = :ord + WHERE id = :id"); + + $stmt->bindValue(':question', $qs['question']); + $stmt->bindValue(':type', $qs['type']); + $stmt->bindValue(':db_heading', $qs['db_heading']); + $stmt->bindValue(':required', $qs['required']); + $stmt->bindValue(':ord', intval($qs['ord'])); + $stmt->bindValue(':id', $qs['id']); + $stmt->execute(); show_pdo_errors_if_any($pdo); } @@ -274,20 +282,25 @@ function questions_editor($section, $year, $array_name, $self) $q->execute(); while ($r = $q->fetch(PDO::FETCH_OBJ)) { $x++; - $stmt = $pdo->prepare("INSERT INTO questions (id,year,section,db_heading,question,type,required,ord) - VALUES ( - '', '$year', - '" . $r->section . "', - '" . $r->db_heading . "', - '" . $r->question . "', - '" . $r->type . "', - '" . $r->required . "', - '" . $r->ord) . "')"; + $stmt = $pdo->prepare("INSERT INTO questions (id, year, section, db_heading, question, type, required, ord) + VALUES (NULL, :year, :section, :db_heading, :question, :type, :required, :ord)"); + + + $stmt->bindParam(':year', $year); + $stmt->bindParam(':section', $r->section); + $stmt->bindParam(':db_heading', $r->db_heading); + $stmt->bindParam(':question', $r->question); + $stmt->bindParam(':type', $r->type); + $stmt->bindParam(':required', $r->required); + $stmt->bindParam(':ord', $r->ord); + $stmt->execute(); } - echo happy(i18n('%1 question(s) successfully imported', - array($x))); + echo happy(i18n( + '%1 question(s) successfully imported', + array($x) + )); } /* @@ -455,10 +468,12 @@ function questions_editor($section, $year, $array_name, $self) . '' . i18n('Actions') . ''; $keys = array_keys($qs); - $types = array('check' => i18n('Check box'), + $types = array( + 'check' => i18n('Check box'), 'yesno' => i18n('Yes/No'), 'text' => i18n('Text'), - 'int' => i18n('Number')); + 'int' => i18n('Number') + ); foreach ($keys as $qid) { echo "{$qs[$qid]['ord']}"; @@ -483,10 +498,10 @@ function questions_editor($section, $year, $array_name, $self) if (count($keys) == 0) { $default_qs = questions_load_questions($section, -1); if (count($default_qs) != 0) { - print ('
'); - print (i18n('There are no questions for year %1, but there are %2 default questions. To import the default questions to year %1 click on the link below.', array($year, count($default_qs)))); - print ('
'); - print ("" . i18n('Import default questions') . '
'); + print('
'); + print(i18n('There are no questions for year %1, but there are %2 default questions. To import the default questions to year %1 click on the link below.', array($year, count($default_qs)))); + print('
'); + print("" . i18n('Import default questions') . '
'); } } }