remove old readme
[atutor.git] / docs / mods / _standard / tests / delete_question.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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 authenticate(AT_PRIV_TESTS);
17
18 $tid = intval($_REQUEST['tid']);
19
20 if (isset($_POST['submit_no'])) {
21         $msg->addFeedback('CANCELLED');
22         header('Location: question_db.php');
23         exit;
24 } else if (isset($_POST['submit_yes'])) {
25         $_POST['qid'] = explode(',', $_POST['qid']);
26
27         foreach ($_POST['qid'] as $id) {
28                 $id = intval($id);
29
30                 $sql    = "DELETE FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$id AND course_id=$_SESSION[course_id]";
31                 $result = mysql_query($sql, $db) or die(mysql_error());
32
33                 if (mysql_affected_rows($db) == 1) {
34                         $sql    = "DELETE FROM ".TABLE_PREFIX."tests_questions_assoc WHERE question_id=$id";
35                         $result = mysql_query($sql, $db) or die(mysql_error());
36                 }
37         }
38
39         $msg->addFeedback('QUESTION_DELETED');
40         header('Location: question_db.php');
41         exit;
42 } /* else: */
43
44 require(AT_INCLUDE_PATH.'header.inc.php');
45
46 $these_questions= explode(",", $_REQUEST['qid']);
47
48 foreach($these_questions as $this_question){
49         $this_question = intval($this_question);
50         $sql = "SELECT question FROM ".TABLE_PREFIX."tests_questions WHERE question_id = '$this_question' ";
51         $result = mysql_query($sql, $db);
52         $row = mysql_fetch_assoc($result);
53         $confirm .= "<li>".$row['question']."</li>";
54 }
55
56 $confirm = array('DELETE', $confirm);
57 $hidden_vars['qid'] = $_REQUEST['qid'];
58
59 $msg->addConfirm($confirm, $hidden_vars);
60 $msg->printConfirm();
61
62 require(AT_INCLUDE_PATH.'footer.inc.php');
63 ?>