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'])) {
25 $msg->addFeedback('CANCELLED');
26 header('Location: question_db.php?_course_id='.$_course_id);
28 } else if ($_POST['submit']) {
29 $missing_fields = array();
31 $_POST['feedback'] = trim($_POST['feedback']);
32 $_POST['question'] = trim($_POST['question']);
33 $_POST['category_id'] = intval($_POST['category_id']);
35 if ($_POST['question'] == ''){
36 $missing_fields[] = _AT('question');
39 if (trim($_POST['choice'][0]) == '') {
40 $missing_fields[] = _AT('item').' 1';
42 if (trim($_POST['choice'][1]) == '') {
43 $missing_fields[] = _AT('item').' 2';
46 if ($missing_fields) {
47 $missing_fields = implode(', ', $missing_fields);
48 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
51 if (!$msg->containsErrors()) {
52 $choice_new = array(); // stores the non-blank choices
53 $answer_new = array(); // stores the non-blank answers
54 $order = 0; // order count
55 for ($i=0; $i<10; $i++) {
57 * Db defined it to be 255 length, chop strings off it it's less than that
60 $_POST['choice'][$i] = Utility::validateLength($_POST['choice'][$i], 255);
61 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
63 if ($_POST['choice'][$i] != '') {
64 /* filter out empty choices/ remove gaps */
65 $choice_new[] = $_POST['choice'][$i];
66 $answer_new[] = $order++;
70 $_POST['choice'] = array_pad($choice_new, 10, '');
71 $answer_new = array_pad($answer_new, 10, 0);
72 $_POST['feedback'] = $addslashes($_POST['feedback']);
73 $_POST['question'] = $addslashes($_POST['question']);
75 $sql_params = array( $_POST['category_id'],
99 $sql = vsprintf(TR_SQL_QUESTION_ORDERING, $sql_params);
101 if ($testsQuestionsDAO->execute($sql)) {
102 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
103 header('Location: question_db.php?_course_id='.$_course_id);
107 $msg->addError('DB_NOT_UPDATED');
111 $onload = 'document.form.category_id.focus();';
113 require_once(TR_INCLUDE_PATH.'header.inc.php');
115 $savant->assign('course_id', $_course_id);
116 $savant->display('tests/create_edit_question_ordering.tmpl.php');
118 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>