move code up one directory
[atutor.git] / mods / _standard / tests / question_db.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
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 // $Id$
13 define('AT_INCLUDE_PATH', '../../../include/');
14 require(AT_INCLUDE_PATH.'vitals.inc.php');
15 require(AT_INCLUDE_PATH.'../mods/_standard/tests/classes/testQuestions.class.php');
16 authenticate(AT_PRIV_TESTS);
17
18 // converts array entries to ints
19 function intval_array ( & $value, $key) { $value = (int) $value; }
20
21 if ( (isset($_GET['edit']) || isset($_GET['delete']) || isset($_GET['export']) || isset($_GET['preview']) || isset($_GET['add'])) && !isset($_GET['questions'])){
22         $msg->addError('NO_ITEM_SELECTED');
23 } else if (isset($_GET['submit_create'], $_GET['question_type'])) {
24         header('Location: '.AT_BASE_HREF.'mods/_standard/tests/create_question_'.$addslashes($_GET['question_type']).'.php');
25         exit;
26 } else if (isset($_GET['edit'])) {
27         $id  = current($_GET['questions']);
28         $num_selected = count($id);
29
30         if ($num_selected == 1) {
31                 $ids = explode('|', $id[0], 2);
32                 $o = TestQuestions::getQuestion($ids[1]);
33                 if ($name = $o->getPrefix()) {
34                         header('Location: '.AT_BASE_HREF.'mods/_standard/tests/edit_question_'.$name.'.php?qid='.intval($ids[0]));
35                         exit;
36                 } else {
37                         header('Location: '.AT_BASE_HREF.'mods/_standard/tests/index.php');
38                         exit;
39                 }
40         } else {
41                 $msg->addError('SELECT_ONE_ITEM');
42         }
43
44 } else if (isset($_GET['delete'])) {
45         $id  = current($_GET['questions']);
46         $ids = array();
47         foreach ($_GET['questions'] as $category_questions) {
48                 $ids = array_merge($ids, $category_questions);
49         }
50
51         array_walk($ids, 'intval_array');
52         $ids = implode(',',$ids);
53
54         header('Location: '.AT_BASE_HREF.'mods/_standard/tests/delete_question.php?qid='.$ids);
55         exit;
56 } else if (isset($_GET['preview'])) {
57         $ids = array();
58         foreach ($_GET['questions'] as $category_questions) {
59                 $ids = array_merge($ids, $category_questions);
60         }
61
62         array_walk($ids, 'intval_array');
63         $ids = implode(',',$ids);
64
65         header('Location: '.AT_BASE_HREF.'mods/_standard/tests/preview_question.php?qid='.$ids);
66         exit;
67 } else if (isset($_GET['add'])) {
68         $id  = current($_GET['questions']);
69         $ids = explode('|', $id[0], 2);
70 } else if (isset($_GET['export'])) {
71         $ids = array();
72         foreach ($_GET['questions'] as $category_questions) {
73                 $ids = array_merge($ids, $category_questions);
74         }
75
76         array_walk($ids, 'intval_array');
77
78         if ($_GET['qti_export_version']=='2.1'){
79                 test_question_qti_export_v2p1($ids);
80         } else {
81                 test_question_qti_export($ids);
82         }
83
84         exit;
85 }
86
87 require(AT_INCLUDE_PATH.'header.inc.php');
88
89 ?>
90
91 <div class="input-form">
92         <fieldset class="group_form" style="width:45%;float:left;height:18em;min-width:15em;"><legend class="group_form"><?php echo _AT('create_new_question'); ?></legend>
93                 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
94                         <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
95                         <label for="question"><?php echo _AT('create_new_question'); ?></label><br />
96                         <?php $questions = TestQuestions::getQuestionPrefixNames(); ?>
97                         <select name="question_type" class="dropdown" id="question" size="8">
98                         <?php foreach ($questions as $type => $name): ?>
99                                 <option value="<?php echo $type; ?>"><?php echo $name; ?></option>
100                         <?php endforeach; ?>
101                         </select>
102                         <div class="row buttons">
103                         <input type="submit" name="submit_create" value="<?php echo _AT('create'); ?>" />
104                         </div>
105                 </form>
106         </fieldset>
107
108         <fieldset class="group_form" style="width:45%;float:left;clear:right;height:18em;min-width:18em;"><legend class="group_form"><?php echo _AT('import_question'); ?></legend>
109                 <form method="post" action="<?php echo 'mods/_standard/tests/question_import.php'; ?>" enctype="multipart/form-data" >  <label for="to_file"><?php echo _AT('upload_question'); ?></label><br />
110                         <input type="file" name="file" id="to_file" />
111                         <div class="row buttons">
112                         <input type="submit" name="submit_import" value="<?php echo _AT('import'); ?>" />
113                         </div>
114                 </form>
115         </fieldset>
116
117
118 <?php $tid = 0; ?>
119
120 <?php require(AT_INCLUDE_PATH.'../mods/_standard/tests/html/tests_questions.inc.php'); ?>
121 <br style="clear:both;" />
122 </div>
123 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>