2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 define('TR_INCLUDE_PATH', '../include/');
14 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
15 require_once(TR_INCLUDE_PATH.'lib/test_question_queries.inc.php');
16 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsDAO.class.php');
17 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
21 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
22 $testsQuestionsDAO = new TestsQuestionsDAO();
24 if (isset($_POST['cancel']) || isset($_POST['submit_no'])) {
25 $msg->addFeedback('CANCELLED');
26 header('Location: question_db.php?_course_id='.$_course_id);
28 } else if ($_POST['submit'] || $_POST['submit_yes']) {
29 $_POST['required'] = intval($_POST['required']);
30 $_POST['feedback'] = trim($_POST['feedback']);
31 $_POST['question'] = trim($_POST['question']);
32 $_POST['category_id'] = intval($_POST['category_id']);
34 if ($_POST['question'] == ''){
35 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
38 if (!$msg->containsErrors()) {
39 $choice_new = array(); // stores the non-blank choices
40 $answer_new = array(); // stores the associated "answer" for the choices
41 for ($i=0; $i<10; $i++) {
43 * Db defined it to be 255 length, chop strings off it it's less than that
46 $_POST['choice'][$i] = Utility::validateLength($_POST['choice'][$i], 255);
47 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
48 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
50 if ($_POST['choice'][$i] == '') {
51 /* an empty option can't be correct */
52 $_POST['answer'][$i] = 0;
54 /* filter out empty choices/ remove gaps */
55 $choice_new[] = $_POST['choice'][$i];
56 $answer_new[] = $_POST['answer'][$i];
58 if ($_POST['answer'][$i] != 0)
63 if ($has_answer != TRUE && !$_POST['submit_yes']) {
65 $hidden_vars['required'] = htmlspecialchars($_POST['required']);
66 $hidden_vars['feedback'] = htmlspecialchars($_POST['feedback']);
67 $hidden_vars['question'] = htmlspecialchars($_POST['question']);
68 $hidden_vars['category_id'] = htmlspecialchars($_POST['category_id']);
70 for ($i = 0; $i < count($choice_new); $i++) {
71 $hidden_vars['answer['.$i.']'] = htmlspecialchars($answer_new[$i]);
72 $hidden_vars['choice['.$i.']'] = htmlspecialchars($choice_new[$i]);
75 $msg->addConfirm('NO_ANSWER', $hidden_vars);
78 //add slahes throughout - does that fix it?
79 $_POST['answer'] = $answer_new;
80 $_POST['choice'] = $choice_new;
81 $_POST['answer'] = array_pad($_POST['answer'], 10, 0);
82 $_POST['choice'] = array_pad($_POST['choice'], 10, '');
84 $_POST['feedback'] = $addslashes($_POST['feedback']);
85 $_POST['question'] = $addslashes($_POST['question']);
87 $sql_params = array( $_POST['category_id'],
110 $_POST['answer'][9]);
111 $sql = vsprintf(TR_SQL_QUESTION_MULTIANSWER, $sql_params);
113 if ($testsQuestionsDAO->execute($sql)) {
114 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
115 header('Location: question_db.php?_course_id='.$_course_id);
122 $onload = 'document.form.category_id.focus();';
124 require_once(TR_INCLUDE_PATH.'header.inc.php');
126 $msg->printConfirm();
128 $savant->assign('qid', $qid);
129 $savant->assign('tid', $_REQUEST['tid']);
130 $savant->assign('course_id', $_course_id);
131 $savant->display('tests/create_edit_question_multianswer.tmpl.php');
133 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>