f4a992321256d52083ec50c8231027b7d6dadc79
[acontent.git] / docs / tests / create_question_truefalse.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['required']     = 1; //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('statement')));
37         }
38
39         if (!$msg->containsErrors()) {
40                 $_POST['feedback'] = $addslashes($_POST['feedback']);
41                 $_POST['question'] = $addslashes($_POST['question']);
42
43                 /*
44                 $sql = 'SELECT content_id FROM '.TABLE_PREFIX."tests WHERE test_id=$_POST[tid]";
45                 $result = mysql_query($sql, $db);                       
46                 $row = mysql_fetch_assoc($result);
47                 */
48
49                 $sql_params = array(    $_POST['category_id'], 
50                                                                 $_course_id,
51                                                                 $_POST['feedback'], 
52                                                                 $_POST['question'], 
53                                                                 $_POST['answer']);
54
55                 $sql = vsprintf(TR_SQL_QUESTION_TRUEFALSE, $sql_params);
56                 if ($testsQuestionsDAO->execute($sql)) {
57                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
58                         header('Location: question_db.php?_course_id='.$_course_id);
59                 }
60                 else
61                         $msg->addError('DB_NOT_UPDATED');
62         }
63 }
64
65 $onload = 'document.form.category_id.focus();';
66 require_once(TR_INCLUDE_PATH.'header.inc.php');
67
68 $savant->assign('course_id', $_course_id);
69 $savant->display('tests/create_edit_question_truefalse.tmpl.php');
70
71 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>