moved code up one level to eliminate the docs subdirectory
[acontent.git] / tests / delete_test.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/Utility.class.php');
17 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsDAO.class.php');
18 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsAssocDAO.class.php');
19 require_once(TR_INCLUDE_PATH.'classes/DAO/ContentTestsAssocDAO.class.php');
20
21 global $_course_id;
22
23 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
24         
25 $testsDAO = new TestsDAO();
26
27 if (isset($_POST['submit_no'])) {
28         $msg->addFeedback('CANCELLED');
29         header('Location: index.php?_course_id='.$_course_id);
30         exit;
31 } else if (isset($_POST['submit_yes'])) {
32         
33         $tid = intval($_POST['tid']);
34
35         if ($testsDAO->Delete($tid)) {
36                 $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
37                 $testsQuestionsAssocDAO->DeleteByTestID($tid);
38
39                 //delete test content association as well
40                 $contentTestsAssocDAO = new ContentTestsAssocDAO();
41                 $contentTestsAssocDAO->DeleteByTestID($tid);
42         }
43
44         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
45         header('Location: '.TR_BASE_HREF.'tests/index.php?_course_id='.$_course_id);
46         exit;
47
48 } /* else: */
49
50 require_once(TR_INCLUDE_PATH.'header.inc.php');
51
52 $_GET['tid'] = intval($_GET['tid']);
53
54 $row = $testsDAO->get($_GET['tid']);
55
56 unset($hidden_vars);
57 $hidden_vars['tid'] = $_GET['tid'];
58 $hidden_vars['_course_id'] = $_course_id;
59
60 $msg->addConfirm(array('DELETE_TEST', $row['title']), $hidden_vars);
61 $msg->printConfirm();
62
63 require_once(TR_INCLUDE_PATH.'footer.inc.php');
64 ?>