AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / docs / tests / question_db.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.'classes/testQuestions.class.php');
16 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
17
18 global $_course_id;
19
20 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
21
22 // converts array entries to ints
23 function intval_array ( & $value, $key) { $value = (int) $value; }
24
25 if ( (isset($_GET['edit']) || isset($_GET['delete']) || isset($_GET['export']) || isset($_GET['preview']) || isset($_GET['add'])) && !isset($_GET['questions'])){
26         $msg->addError('NO_ITEM_SELECTED');
27 } else if (isset($_GET['submit_create'], $_GET['question_type'])) {
28         header('Location: '.TR_BASE_HREF.'tests/create_question_'.$addslashes($_GET['question_type']).'.php?_course_id='.$_course_id);
29         exit;
30 } else if (isset($_GET['edit'])) {
31         $id  = current($_GET['questions']);
32         $num_selected = count($id);
33
34         if ($num_selected == 1) {
35                 $ids = explode('|', $id[0], 2);
36                 $o = TestQuestions::getQuestion($ids[1]);
37                 if ($name = $o->getPrefix()) {
38                         header('Location: '.TR_BASE_HREF.'tests/edit_question_'.$name.'.php?qid='.intval($ids[0]).'&_course_id='.$_course_id);
39                         exit;
40                 } else {
41                         header('Location: '.TR_BASE_HREF.'tests/index.php?_course_id='.$_course_id);
42                         exit;
43                 }
44         } else {
45                 $msg->addError('SELECT_ONE_ITEM');
46         }
47
48 } else if (isset($_GET['delete'])) {
49         $id  = current($_GET['questions']);
50         $ids = array();
51         foreach ($_GET['questions'] as $category_questions) {
52                 $ids = array_merge($ids, $category_questions);
53         }
54
55         array_walk($ids, 'intval_array');
56         $ids = implode(',',$ids);
57
58         header('Location: '.TR_BASE_HREF.'tests/delete_question.php?qid='.$ids.'&_course_id='.$_course_id);
59         exit;
60 } else if (isset($_GET['preview'])) {
61         $ids = array();
62         foreach ($_GET['questions'] as $category_questions) {
63                 $ids = array_merge($ids, $category_questions);
64         }
65
66         array_walk($ids, 'intval_array');
67         $ids = implode(',',$ids);
68
69         header('Location: '.TR_BASE_HREF.'tests/preview_question.php?qid='.$ids.'&_course_id='.$_course_id);
70         exit;
71 } else if (isset($_GET['add'])) {
72         $id  = current($_GET['questions']);
73         $ids = explode('|', $id[0], 2);
74 } else if (isset($_GET['export'])) {
75         $ids = array();
76         foreach ($_GET['questions'] as $category_questions) {
77                 $ids = array_merge($ids, $category_questions);
78         }
79
80         array_walk($ids, 'intval_array');
81
82         if ($_GET['qti_export_version']=='2.1'){
83                 test_question_qti_export_v2p1($ids);
84         } else {
85                 test_question_qti_export($ids);
86         }
87
88         exit;
89 }
90
91 require_once(TR_INCLUDE_PATH.'header.inc.php');
92
93 $savant->assign('course_id', $_course_id);
94 $savant->assign('tid', $tid);
95 $savant->assign('questions', TestQuestions::getQuestionPrefixNames());
96
97 $savant->display('tests/question_db_top.tmpl.php');
98
99 $tid = 0; 
100
101 require_once(TR_INCLUDE_PATH.'../tests/html/tests_questions.inc.php'); 
102 ?>
103 <br style="clear:both;" />
104
105
106 <?php require_once(TR_INCLUDE_PATH.'footer.inc.php');?>