AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / tests / questions.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 $page = 'tests';
14 define('TR_INCLUDE_PATH', '../include/');
15 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
16 require_once(TR_INCLUDE_PATH.'classes/testQuestions.class.php');
17 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
18 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsDAO.class.php');
19 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsCategoriesDAO.class.php');
20 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsAssocDAO.class.php');
21
22 global $_course_id;
23
24 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
25 $testsDAO = new TestsDAO();
26 $testsQuestionsCategoriesDAO = new TestsQuestionsCategoriesDAO();
27 $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
28
29 $_pages['tests/questions.php']['title_var']    = 'questions';
30 $_pages['tests/questions.php']['parent']   = 'tests/index.php';
31 $_pages['tests/questions.php']['children'] = array('tests/add_test_questions.php?tid='.$_GET['tid'].'&_course_id='.$_course_id);
32
33 $_pages['tests/add_test_questions.php?tid='.$_GET['tid'].'&_course_id='.$_course_id]['title_var']    = 'add_questions';
34 $_pages['tests/add_test_questions.php?tid='.$_GET['tid'].'&_course_id='.$_course_id]['parent']   = 'tests/questions.php?tid='.$_GET['tid'].'&_course_id='.$_course_id;
35
36 $_pages['tests/questions.php']['guide']    = 'instructor/?p=add_questions.php';
37
38 $tid = intval($_REQUEST['tid']);
39
40 if (isset($_POST['submit'])) {
41         $count = 1;
42         foreach ($_POST['weight'] as $qid => $weight) {
43                 $qid    = intval($qid);
44                 $weight = intval($weight);
45
46                 $orders = $_POST['ordering'];
47                 asort($orders);
48                 $orders = array_keys($orders);
49
50                 foreach ($orders as $k => $id)
51                         $orders[$k] = intval($id);
52                         
53                 $orders = array_flip($orders);
54                 
55                 $testsQuestionsAssocDAO->Update($tid, $qid, $weight, $orders[$qid]+1);
56                 $count++;
57         }
58
59         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
60         header('Location: '.$_SERVER['PHP_SELF'] .'?tid='.$tid.'&_course_id='.$_course_id);
61         exit;
62 }
63
64 $cats    = array();
65 $cats[0] = _AT('cats_uncategorized');
66 $cat_rows = $testsQuestionsCategoriesDAO->getByCourseID($_course_id);
67 if (is_array($cat_rows)) {
68         foreach ($cat_rows as $cat_row) {
69                 $cats[$cat_row['category_id']] = $cat_row['title'];
70         }
71 }
72
73 require_once(TR_INCLUDE_PATH.'header.inc.php');
74
75 $row = $testsDAO->get($tid);
76 echo '<div class="input-form">';
77 echo '<h3>'._AT('questions_for').' '.AT_print($row['title'], 'tests.title').'</h3>';
78
79 $rows = $testsQuestionsAssocDAO->getZeroWeightRowsByTestID($tid);
80 if (is_array($rows)) {
81         $msg->printWarnings('QUESTION_WEIGHT');
82 }
83
84 $msg->printAll();
85
86 $rows = $testsQuestionsAssocDAO->getByTestID($tid);
87
88 $savant->assign('cats', $cats);
89 $savant->assign('rows', $rows);
90 $savant->assign('tid', $tid);
91 $savant->assign('course_id', $_course_id);
92 $savant->display('tests/questions.tmpl.php');
93 echo '</div>';
94 require_once(TR_INCLUDE_PATH.'footer.inc.php');?>