move code up one directory
[atutor.git] / mods / _standard / reading_list / delete_resource.php
1 <?php\r
2 /****************************************************************/\r
3 /* ATutor                                                                                                               */\r
4 /****************************************************************/\r
5 /* Copyright (c) 2002-2008                                      */\r
6 /* Written by Greg Gay & Joel Kronenberg & Chris Ridpath        */\r
7 /* Inclusive Design Institute                                   */\r
8 /* http://atutor.ca                                                                                             */\r
9 /*                                                              */\r
10 /* This program is free software. You can redistribute it and/or*/\r
11 /* modify it under the terms of the GNU General Public License  */\r
12 /* as published by the Free Software Foundation.                                */\r
13 /****************************************************************/\r
14 // $Id$\r
15 define('AT_INCLUDE_PATH', '../../../include/');\r
16 require (AT_INCLUDE_PATH.'vitals.inc.php');\r
17 authenticate(AT_PRIV_READING_LIST);\r
18 \r
19 if (isset($_POST['submit_no'])) {\r
20         $msg->addFeedback('CANCELLED');\r
21         Header('Location: display_resources.php');\r
22         exit;\r
23 } else if (isset($_POST['submit_yes'])) {\r
24         $_POST['id'] = intval($_POST['id']);\r
25         $resource_id = $_POST['id'];\r
26 \r
27         // delete the resource from the list\r
28         $sql = "DELETE FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND resource_id=$resource_id";\r
29         $result = mysql_query($sql, $db);\r
30 \r
31         // find any readings that use this resource and delete them too\r
32         $sql = "DELETE FROM ".TABLE_PREFIX."reading_list WHERE course_id=$_SESSION[course_id] AND resource_id=$resource_id";\r
33         $result = mysql_query($sql, $db);\r
34 \r
35         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
36         header('Location: display_resources.php');\r
37         exit;\r
38 }\r
39 \r
40 require(AT_INCLUDE_PATH.'header.inc.php');\r
41 \r
42 $_GET['id'] = intval($_GET['id']); \r
43 $resource_id = $_GET['id'];\r
44 \r
45 // get the resource ID for this reading\r
46 $sql = "SELECT title FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND resource_id=$resource_id";\r
47 $result = mysql_query($sql, $db);\r
48 \r
49 if ($row = mysql_fetch_assoc($result)){\r
50         $hidden_vars['id'] = $resource_id;\r
51         $confirm = array('RL_DELETE_RESOURCE', AT_print($row['title'], 'reading_list.title'));\r
52         $msg->addConfirm($confirm, $hidden_vars);\r
53         $msg->printConfirm();\r
54 }\r
55 else {\r
56         $msg->addError('ITEM_NOT_FOUND');\r
57 }\r
58 \r
59 require(AT_INCLUDE_PATH.'footer.inc.php');\r
60 ?>