AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / tests / create_question_multichoice.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']) || isset($_POST['submit_no'])) {
25         $msg->addFeedback('CANCELLED');
26         header('Location: question_db.php?_course_id='.$_course_id);
27         exit;
28 } else if (isset($_POST['submit'])) {
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']);
33         $_POST['answer']      = intval($_POST['answer']);
34
35         if ($_POST['question'] == ''){
36                 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
37         }
38                 
39         if (!$msg->containsErrors()) {
40                 for ($i=0; $i<10; $i++) {
41                         $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
42                 }
43
44                 $answers = array_fill(0, 10, 0);
45                 $answers[$_POST['answer']] = 1;
46
47                 $_POST['feedback']   = $addslashes($_POST['feedback']);
48                 $_POST['question']   = $addslashes($_POST['question']);
49
50                 $sql_params = array(    $_POST['category_id'], 
51                                                                 $_course_id,
52                                                                 $_POST['feedback'], 
53                                                                 $_POST['question'], 
54                                                                 $_POST['choice'][0], 
55                                                                 $_POST['choice'][1], 
56                                                                 $_POST['choice'][2], 
57                                                                 $_POST['choice'][3], 
58                                                                 $_POST['choice'][4], 
59                                                                 $_POST['choice'][5], 
60                                                                 $_POST['choice'][6], 
61                                                                 $_POST['choice'][7], 
62                                                                 $_POST['choice'][8], 
63                                                                 $_POST['choice'][9], 
64                                                                 $answers[0], 
65                                                                 $answers[1], 
66                                                                 $answers[2], 
67                                                                 $answers[3], 
68                                                                 $answers[4], 
69                                                                 $answers[5], 
70                                                                 $answers[6], 
71                                                                 $answers[7], 
72                                                                 $answers[8], 
73                                                                 $answers[9]);
74                 $sql = vsprintf(TR_SQL_QUESTION_MULTI, $sql_params);
75                 
76                 if ($testsQuestionsDAO->execute($sql)) {
77                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
78                         header('Location: question_db.php?_course_id='.$_course_id);
79                         exit;
80                 }
81         }
82 } else {
83         $_POST['answer'] = 0;
84 }
85
86 $onload = 'document.form.category_id.focus();';
87
88 require_once(TR_INCLUDE_PATH.'header.inc.php');
89
90 $msg->printConfirm();
91
92 $savant->assign('course_id', $_course_id);
93 $savant->display('tests/create_edit_question_multichoice.tmpl.php');
94
95 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>