2fcfb9032c70e29ba3219be878f8340f63e5ff67
[atutor.git] / docs / mods / _standard / links / tools / categories.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 if ((isset($_POST['delete']) || isset($_POST['edit'])) && !isset($_POST['cat_id'])) {\r
26                 $msg->addError('NO_ITEM_SELECTED');\r
27 } else if (isset($_POST['delete'])) {\r
28         //check if links are in the cat\r
29         $sql    = "SELECT link_id FROM ".TABLE_PREFIX."links WHERE cat_id=$_POST[cat_id]";\r
30         $result = mysql_query($sql, $db);\r
31     if ($row = mysql_fetch_assoc($result)) {\r
32                 $msg->addError('LINK_CAT_NOT_EMPTY');\r
33         } else {\r
34                 header('Location: categories_delete.php?cat_id='.$_POST['cat_id']);\r
35                 exit;\r
36         }\r
37 } else if (isset($_POST['edit'])) {\r
38         header('Location: categories_edit.php?cat_id='.$_POST['cat_id']);\r
39         exit;\r
40 }\r
41 \r
42 require(AT_INCLUDE_PATH.'header.inc.php'); \r
43 \r
44 \r
45 ?>\r
46 <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">\r
47 <table summary="" class="data" rules="cols" align="center" style="width: 95%;">\r
48 <thead>\r
49 <tr>\r
50         <th scope="col">&nbsp;</th>\r
51         <th scope="col"><?php echo _AT('name'); ?></th>\r
52         <th scope="col"><?php echo _AT('parent'); ?></th>\r
53 </tr>\r
54 </thead>\r
55 \r
56 <?php\r
57 $categories = get_link_categories(true, true);\r
58 \r
59 if (!empty($categories)) { ?>\r
60         <tfoot>\r
61         <tr>\r
62                 <td colspan="4">\r
63                         <div class="row buttons">\r
64                         <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /> \r
65                         </div>\r
66                 </td>\r
67         </tr>\r
68         </tfoot>\r
69         <tbody>\r
70 \r
71 <?php foreach ($categories as $id=>$row) {\r
72 \r
73                 if (!empty($row['cat_name'])) {\r
74 \r
75                 $parent_cat_name = '';\r
76                 if ($row['cat_parent']) {\r
77                         $sql_cat        = "SELECT name, owner_id, owner_type FROM ".TABLE_PREFIX."links_categories WHERE cat_id=".$row['cat_parent'];\r
78                         $result_cat = mysql_query($sql_cat, $db);\r
79                         $row_cat = mysql_fetch_assoc($result_cat);\r
80                         $parent_cat_name = AT_print($row_cat['name'], 'links_categories.name');\r
81 \r
82                         if (empty($parent_cat_name)) {\r
83                                 $parent_cat_name = get_group_name($row_cat['owner_id']);\r
84                         }\r
85                 } else {\r
86                         $parent_cat_name = '<strong>'._AT('none').'</strong>';\r
87                 }\r
88         ?>\r
89                 <tr onmousedown="document.form['m<?php echo $id; ?>'].checked = true;rowselect(this);" id="r_<?php echo $id; ?>">\r
90                         <td width="10"><input type="radio" name="cat_id" value="<?php echo $id; ?>" id="m<?php echo $id; ?>" /></td>\r
91                         <td><label for="m<?php echo $id; ?>"><?php echo AT_print($row['cat_name'], 'members.first_name'); ?></label></td>\r
92                         <td><?php echo $parent_cat_name; ?></td>\r
93                 </tr>\r
94                 </tbody>\r
95 \r
96 <?php\r
97                 } \r
98         }?>\r
99 <?php\r
100 } else { ?>\r
101         <tr>\r
102                 <td colspan="3"><?php echo _AT('none_found'); ?></td>\r
103         </tr>\r
104 <?php } ?>\r
105 \r
106 \r
107 </table>\r
108 </form>\r
109 \r
110 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>