AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / docs / tests / create_question_matchingdd.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
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');
18
19 global $_course_id;
20
21 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
22 $testsQuestionsDAO = new TestsQuestionsDAO();
23
24 if (isset($_POST['cancel'])) {
25         $msg->addFeedback('CANCELLED');
26         header('Location: question_db.php?_course_id='.$_course_id);
27         exit;
28 } else if ($_POST['submit']) {
29         $_POST['feedback']    = trim($_POST['feedback']);
30         $_POST['instructions'] = trim($_POST['instructions']);
31         $_POST['category_id'] = intval($_POST['category_id']);
32
33         for ($i = 0 ; $i < 10; $i++) {
34                 $_POST['question'][$i]        = $addslashes(trim($_POST['question'][$i]));
35                 $_POST['question_answer'][$i] = (int) $_POST['question_answer'][$i];
36                 $_POST['answer'][$i]          = $addslashes(trim($_POST['answer'][$i]));
37         }
38
39         if (!$_POST['question'][0] 
40                 || !$_POST['question'][1] 
41                 || !$_POST['answer'][0] 
42                 || !$_POST['answer'][1]) {
43
44                 $msg->addError('QUESTION_EMPTY');
45         }
46         
47
48         if (!$msg->containsErrors()) {
49                 $_POST['feedback']     = $addslashes($_POST['feedback']);
50                 $_POST['instructions'] = $addslashes($_POST['instructions']);
51         
52                 $sql_params = array(    $_POST['category_id'], 
53                                                                 $_course_id,
54                                                                 $_POST['feedback'], 
55                                                                 $_POST['instructions'], 
56                                                                 $_POST['question'][0], 
57                                                                 $_POST['question'][1], 
58                                                                 $_POST['question'][2], 
59                                                                 $_POST['question'][3], 
60                                                                 $_POST['question'][4], 
61                                                                 $_POST['question'][5], 
62                                                                 $_POST['question'][6], 
63                                                                 $_POST['question'][7], 
64                                                                 $_POST['question'][8], 
65                                                                 $_POST['question'][9], 
66                                                                 $_POST['question_answer'][0], 
67                                                                 $_POST['question_answer'][1], 
68                                                                 $_POST['question_answer'][2], 
69                                                                 $_POST['question_answer'][3], 
70                                                                 $_POST['question_answer'][4], 
71                                                                 $_POST['question_answer'][5], 
72                                                                 $_POST['question_answer'][6], 
73                                                                 $_POST['question_answer'][7], 
74                                                                 $_POST['question_answer'][8], 
75                                                                 $_POST['question_answer'][9],
76                                                                 $_POST['answer'][0], 
77                                                                 $_POST['answer'][1], 
78                                                                 $_POST['answer'][2], 
79                                                                 $_POST['answer'][3], 
80                                                                 $_POST['answer'][4], 
81                                                                 $_POST['answer'][5], 
82                                                                 $_POST['answer'][6], 
83                                                                 $_POST['answer'][7], 
84                                                                 $_POST['answer'][8], 
85                                                                 $_POST['answer'][9]);
86
87                 $sql = vsprintf(TR_SQL_QUESTION_MATCHINGDD, $sql_params);
88
89                 if ($testsQuestionsDAO->execute($sql)) {
90                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
91                         header('Location: question_db.php?_course_id='.$_course_id);
92                         exit;
93                 }
94         }
95 }
96
97 // for matching test questions
98 $_letters = array(_AT('a'), _AT('b'), _AT('c'), _AT('d'), _AT('e'), _AT('f'), _AT('g'), _AT('h'), _AT('i'), _AT('j'));
99
100 $onload = 'document.form.category_id.focus();';
101
102 require_once(TR_INCLUDE_PATH.'header.inc.php');
103
104 $savant->assign('letters', $_letters);
105 $savant->assign('course_id', $_course_id);
106 $savant->display('tests/create_edit_question_matchingdd.tmpl.php');
107
108 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>