move code up one directory
[atutor.git] / mods / _standard / links / tools / categories_delete.php
1 <?php\r
2 /****************************************************************************/\r
3 /* ATutor                                                                                                                                       */\r
4 /****************************************************************************/\r
5 /* Copyright (c) 2002-2010                                                  */\r
6 /* Inclusive Design Institute                                               */\r
7 /* http://atutor.ca                                                                                                                     */\r
8 /*                                                                                                                                                      */\r
9 /* This program is free software. You can redistribute it and/or                        */\r
10 /* modify it under the terms of the GNU General Public License                          */\r
11 /* as published by the Free Software Foundation.                                                        */\r
12 /****************************************************************************/\r
13 // $Id$\r
14 \r
15 define('AT_INCLUDE_PATH', '../../../../include/');\r
16 require(AT_INCLUDE_PATH.'vitals.inc.php');\r
17 require (AT_INCLUDE_PATH.'../mods/_standard/links/lib/links.inc.php');\r
18 \r
19 if (!manage_links()) {\r
20         $msg->addError('ACCESS_DENIED');\r
21         header('Location: '.AT_BASE_HREF.'mods/_standard/links/index.php');\r
22         exit;\r
23 }\r
24 \r
25 $cat_id = intval($_REQUEST['cat_id']);\r
26 \r
27 if (isset($_POST['submit_no'])) {\r
28         $msg->addFeedback('CANCELLED');\r
29         header('Location: categories.php');\r
30         exit;\r
31 } else if (isset($_POST['submit_yes'])) {\r
32         /* delete has been confirmed, delete this category */\r
33         $owner_type     = intval($_POST['owner_type']);\r
34         $owner_id       = intval($_POST['owner_id']);\r
35         //OR get_cat_info() again incase data has ben tampered?\r
36 \r
37         if (!links_authenticate($owner_type, $owner_id)) {\r
38                 $msg->addError('ACCESS_DENIED');\r
39                 header('Location: '.AT_BASE_HREF.'mods/_standard/links/tools/categories.php');\r
40                 exit;\r
41         }\r
42 \r
43         //check if there are sub cats within this cat, or links\r
44         $sql = "SELECT C.cat_id, L.link_id FROM ".TABLE_PREFIX."links_categories C, ".TABLE_PREFIX."links L WHERE C.parent_id=$cat_id OR L.cat_id=$cat_id";\r
45         $result = mysql_query($sql, $db);\r
46         if (mysql_num_rows($result) == 0) {\r
47                 $sql = "DELETE FROM ".TABLE_PREFIX."links_categories WHERE owner_id=$owner_id AND owner_type=$owner_type AND cat_id=$cat_id";\r
48                 $result = mysql_query($sql, $db);\r
49                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
50         } else {\r
51                 $msg->addError('LINK_CAT_NOT_EMPTY');\r
52         }\r
53 \r
54         header('Location: categories.php');\r
55         exit;\r
56 }\r
57 \r
58 require(AT_INCLUDE_PATH.'header.inc.php');\r
59 \r
60         $row = get_cat_info($cat_id);\r
61 \r
62         if (empty($row)) {\r
63                 $msg->printErrors('ITEM_NOT_FOUND');\r
64         } else {\r
65                 $hidden_vars['cat_name']= $row['name'];\r
66                 $hidden_vars['cat_id']  = $row['cat_id'];\r
67                 $hidden_vars['owner_type']      = $row['owner_type'];\r
68                 $hidden_vars['owner_id']        = $row['owner_id'];\r
69 \r
70                 $confirm = array('DELETE_CATEGORY', AT_print($row['name'], 'links_categories.name'));\r
71                 $msg->addConfirm($confirm, $hidden_vars);\r
72                 \r
73                 $msg->printConfirm();\r
74         }\r
75 \r
76 require(AT_INCLUDE_PATH.'footer.inc.php');\r
77 \r
78 ?>