From 529491456ceedbc592ed5797617df6c67dd91916 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 5 Mar 2013 22:10:50 +0000 Subject: [PATCH] Added checking for required custom questions being answered on the Judge "other information" forms. Also added asterisks to mark the required custom questions as such. --- judge.inc.php | 22 ++++++++++++++++++++-- questions.inc.php | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/judge.inc.php b/judge.inc.php index 6809b6b..e47a3f4 100644 --- a/judge.inc.php +++ b/judge.inc.php @@ -64,11 +64,29 @@ function judge_status_other(&$u) /* They must select a language to judge in */ if(count($u['languages']) < 1) return 'incomplete'; - - return 'complete'; + return judge_status_questions($u); } +function judge_status_questions($u){ + /* Logic: + - count the number of required questions and get their id's. + - count the questions answered by the user which match those id's + - if those counts are not the same, then the user has not answered all required questions + */ + global $config; + // get the questions we're looking for + $q = mysql_query("SELECT id FROM questions WHERE year=" . $config['FAIRYEAR'] . " AND required='yes'"); + $idList = array(); + while($row = mysql_fetch_assoc($q)) $idList[] = $row['id']; + $rval = 'complete'; + if(count($idList)){ + $q = mysql_query("SELECT COUNT(*) AS tally FROM question_answers WHERE questions_id IN(" . implode(',', $idList) . ") AND users_id=" . $u['id'] . " AND answer IS NOT NULL"); + $row = mysql_fetch_assoc($q); + if(intval($row['tally']) != count($idList)) $rval = 'incomplete'; + } + return $rval; +} function judge_status_special_awards(&$u) { diff --git a/questions.inc.php b/questions.inc.php index cb91328..09d7103 100644 --- a/questions.inc.php +++ b/questions.inc.php @@ -100,8 +100,9 @@ function questions_print_answer_editor($section, &$u, $array_name) $qs = questions_load_questions($section, $u['year']); $keys = array_keys($qs); foreach($keys as $qid) { + $required = $qs[$qid]['required'] == 'yes' ? ' *' : ''; print("\n"); - print(" ".i18n($qs[$qid]['question'])."\n"); + print(" $required".i18n($qs[$qid]['question'])."\n"); print(" "); $iname = "{$array_name}[{$qid}]"; switch($qs[$qid]['type']) {