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