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.'../tests/lib/likert_presets.inc.php');
16 require_once(TR_INCLUDE_PATH.'lib/test_question_queries.inc.php');
17 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsDAO.class.php');
18 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
21 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
23 $testsQuestionsDAO = new TestsQuestionsDAO();
25 if (isset($_POST['cancel'])) {
26 $msg->addFeedback('CANCELLED');
27 header('Location: question_db.php?_course_id='.$_course_id);
29 } else if (isset($_POST['submit'])) {
30 $_POST['question'] = trim($_POST['question']);
31 $_POST['category_id'] = intval($_POST['category_id']);
33 $empty_fields = array();
34 if ($_POST['question'] == ''){
35 $empty_fields[] = _AT('question');
37 if ($_POST['choice'][0] == '') {
38 $empty_fields[] = _AT('choice').' 1';
41 if ($_POST['choice'][1] == '') {
42 $empty_fields[] = _AT('choice').' 2';
45 if (!empty($empty_fields)) {
46 $msg->addError(array('EMPTY_FIELDS', implode(', ', $empty_fields)));
49 if (!$msg->containsErrors()) {
50 $_POST['feedback'] = '';
51 $_POST['question'] = $addslashes($_POST['question']);
53 for ($i=0; $i<10; $i++) {
54 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
55 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
57 if ($_POST['choice'][$i] == '') {
58 /* an empty option can't be correct */
59 $_POST['answer'][$i] = 0;
63 $sql_params = array( $_POST['category_id'],
88 $sql = vsprintf(TR_SQL_QUESTION_LIKERT, $sql_params);
89 if ($testsQuestionsDAO->execute($sql)) {
90 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
91 header('Location: question_db.php?_course_id='.$_course_id);
95 $msg->addError('DB_NOT_UPDATED');
98 } else if (isset($_POST['preset'])) {
100 $_POST['preset_num'] = intval($_POST['preset_num']);
102 if (isset($_likert_preset[$_POST['preset_num']])) {
103 $_POST['choice'] = $_likert_preset[$_POST['preset_num']];
104 } else if ($_POST['preset_num']) {
105 $row = $testsQuestionsDAO->get($_POST[preset_num]);
107 for ($i=0; $i<10; $i++) {
108 $_POST['choice'][$i] = $row['choice_' . $i];
115 $onload = 'document.form.category_id.focus();';
117 require_once(TR_INCLUDE_PATH.'header.inc.php');
119 $savant->assign('likert_preset', $_likert_preset);
120 $savant->assign('testsQuestionsDAO', $testsQuestionsDAO);
121 $savant->assign('course_id', $_course_id);
122 $savant->display('tests/create_edit_question_likert.tmpl.php');
124 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>