f778d631b50f00f582a58110c9ed77db5fe29548
[atutor.git] / docs / mods / _standard / tests / delete_result.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
17 authenticate(AT_PRIV_TESTS);
18
19 $tid = intval($_REQUEST['tid']);
20 $rids = explode(',', $_REQUEST['rid']);
21 foreach ($rids as $k => $id) {
22         $rids[$k] = intval($id);
23 }
24 $rid = implode(',', $rids);
25
26 // Check that the user deletes submissions in his own test; if not, exit like authenticate()
27 $sql    = "SELECT count(*) AS cnt FROM ".TABLE_PREFIX."tests_results R LEFT JOIN ".TABLE_PREFIX."tests USING (test_id) WHERE result_id IN ($rid) AND course_id = $_SESSION[course_id] AND R.test_id = $tid";
28
29 $result = mysql_query($sql, $db);
30 $row = mysql_fetch_array($result);
31 if ($row['cnt'] < count($rids)) {
32         exit;
33 }
34
35 if (isset($_POST['submit_no'])) {
36         $msg->addFeedback('CANCELLED');
37         header('Location: '.AT_BASE_HREF.'mods/_standard/tests/results.php?tid='.$tid);
38         exit;
39
40 } else if (isset($_POST['submit_yes'])) {
41         $sql    = "DELETE FROM ".TABLE_PREFIX."tests_answers WHERE result_id IN ($rid)";
42         $result = mysql_query($sql, $db);
43
44         $sql    = "DELETE FROM ".TABLE_PREFIX."tests_results WHERE result_id IN ($rid)";
45         $result = mysql_query($sql, $db);
46                 
47         $msg->addFeedback('RESULT_DELETED');
48         header('Location: '.AT_BASE_HREF.'mods/_standard/tests/results.php?tid='.$tid);
49         exit;
50
51
52 $_pages['mods/_standard/tests/delete_result.php']['title_var']  = 'delete_results';
53 $_pages['mods/_standard/tests/delete_result.php']['parent'] = 'mods/_standard/tests/results.php?tid='.$tid;
54
55 $_pages['mods/_standard/tests/results.php?tid='.$tid]['title_var'] = 'submissions';
56 $_pages['mods/_standard/tests/results.php?tid='.$tid]['parent'] = 'mods/_standard/tests/index.php';
57
58 require(AT_INCLUDE_PATH.'header.inc.php');
59
60 unset($hidden_vars);
61 $hidden_vars['tid'] = $tid;
62 $hidden_vars['rid'] = $rid;
63 $msg->addConfirm(array('DELETE', _AT('submissions') .': <strong>'. count($rids) .'</strong>'), $hidden_vars);
64
65 $msg->printConfirm();
66
67 require(AT_INCLUDE_PATH.'footer.inc.php');
68 ?>