move code up one directory
[atutor.git] / mods / _core / cats_categories / admin / delete_category.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 admin_authenticate(AT_ADMIN_PRIV_CATEGORIES);\r
18 \r
19 if (isset($_POST['submit_no'])) {\r
20         $msg->addFeedback('CANCELLED');\r
21         header('Location: course_categories.php');\r
22         exit;\r
23 } else if (isset($_POST['submit_yes'])) {\r
24         /* delete has been confirmed, delete this category */\r
25         $cat_id = intval($_POST['cat_id']);\r
26 \r
27         if (!is_array($categories[$cat_id]['children'])) {\r
28                 $sql = "DELETE FROM ".TABLE_PREFIX."course_cats WHERE cat_id=$cat_id";\r
29                 $result = mysql_query($sql, $db);\r
30 \r
31                 write_to_log(AT_ADMIN_LOG_DELETE, 'course_cats', mysql_affected_rows($db), $sql);\r
32 \r
33                 $sql = "UPDATE ".TABLE_PREFIX."courses SET cat_id=0 WHERE cat_id=$cat_id";\r
34                 $result = mysql_query($sql, $db);\r
35 \r
36                 write_to_log(AT_ADMIN_LOG_DELETE, 'courses', mysql_affected_rows($db), $sql);\r
37 \r
38                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
39                 header('Location: course_categories.php');\r
40                 exit;\r
41         }\r
42 }\r
43 \r
44 require(AT_INCLUDE_PATH.'header.inc.php');\r
45 \r
46         $_GET['cat_id'] = intval($_GET['cat_id']); \r
47 \r
48         $sql = "SELECT * FROM ".TABLE_PREFIX."course_cats WHERE cat_id=$_GET[cat_id]";\r
49         $result = mysql_query($sql,$db);\r
50 \r
51         if (mysql_num_rows($result) == 0) {\r
52                 $msg->printErrors('ITEM_NOT_FOUND');\r
53         } else {\r
54                 $row = mysql_fetch_assoc($result);\r
55                 \r
56                 $hidden_vars['cat_name']= $row['cat_name'];\r
57                 $hidden_vars['cat_id']  = $row['cat_id'];\r
58 \r
59                 $confirm = array('DELETE_CATEGORY', AT_print($row['cat_name'], 'course_cats.cat_name'));\r
60                 $msg->addConfirm($confirm, $hidden_vars);\r
61                 \r
62                 $msg->printConfirm();\r
63         }\r
64 \r
65 require(AT_INCLUDE_PATH.'footer.inc.php');\r
66 \r
67 ?>