remove old readme
[atutor.git] / docs / mods / _core / cats_categories / admin / edit_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 require(AT_INCLUDE_PATH.'../mods/_core/themes/lib/themes.inc.php');\r
18 admin_authenticate(AT_ADMIN_PRIV_CATEGORIES);\r
19 \r
20 require(AT_INCLUDE_PATH.'../mods/_core/cats_categories/lib/admin_categories.inc.php');\r
21 \r
22 $cat_id = intval($_REQUEST['cat_id']);\r
23 \r
24 if (isset($_POST['submit'])) {\r
25         $cat_name = $addslashes($_POST['cat_name']);\r
26         $cat_theme = $addslashes($_POST['cat_theme']);\r
27         $cat_parent_id = intval($_POST['cat_parent_id']);\r
28 \r
29         if ($_POST['theme_parent']) {\r
30                 // get the theme of the parent category.\r
31 \r
32                 $sql    = "SELECT theme FROM ".TABLE_PREFIX."course_cats WHERE cat_id=$cat_parent_id";\r
33                 $result = mysql_query($sql, $db);\r
34                 if ($row = mysql_fetch_assoc($result)) {\r
35                         $cat_theme = $row['theme'];\r
36                 }\r
37         }\r
38         if ($cat_name == '') {\r
39                 $msg->addError(array('EMPTY_FIELDS', _AT('title')));\r
40         }\r
41 \r
42         if (!$msg->containsErrors()) {\r
43 \r
44                 if ($_POST['theme_children']) {\r
45                         // apply this theme to all the sub-categories recursively.\r
46                         $children = recursive_get_subcategories($cat_id);\r
47                         $children = implode(',', $children);\r
48 \r
49                         if ($children) {\r
50                                 $sql = "UPDATE ".TABLE_PREFIX."course_cats SET theme='$cat_theme' WHERE cat_id IN ($children)";\r
51                                 $result = mysql_query($sql, $db);\r
52 \r
53                                 write_to_log(AT_ADMIN_LOG_UPDATE, 'course_cats', mysql_affected_rows($db), $sql);\r
54                         }\r
55                 }\r
56 \r
57                 $sql = "UPDATE ".TABLE_PREFIX."course_cats SET cat_parent=$cat_parent_id, cat_name='$cat_name', theme='$cat_theme' WHERE cat_id=$cat_id";\r
58                 $result = mysql_query($sql, $db);\r
59 \r
60                 write_to_log(AT_ADMIN_LOG_UPDATE, 'course_cats', mysql_affected_rows($db), $sql);\r
61 \r
62                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
63 \r
64                 header('Location: course_categories.php');\r
65                 exit;\r
66         }\r
67 } else if (isset($_POST['cancel'])) {\r
68         $msg->addFeedback('CANCELLED');\r
69         header('Location: course_categories.php');\r
70         exit;\r
71 }\r
72 \r
73 /* get all the categories: */\r
74 /* $categories[category_id] = array(cat_name, cat_parent, num_courses, [array(children)]) */\r
75 $categories = get_categories();\r
76 \r
77 require(AT_INCLUDE_PATH.'header.inc.php'); \r
78 $msg->printAll();\r
79 \r
80 ?>\r
81 \r
82 <form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">\r
83 <input type="hidden" name="cat_id" value="<?php echo $cat_id; ?>" />\r
84 <input type="hidden" name="form_submit" value="1" />\r
85 \r
86 <div class="input-form">\r
87         <div class="row">\r
88                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="category_name"><?php echo _AT('title'); ?></label><br />\r
89                 <input type="text" id="category_name" name="cat_name" size="30" value="<?php echo htmlspecialchars($categories[$cat_id]['cat_name']); ?>" />\r
90         </div>\r
91 \r
92         <div class="row">\r
93                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="category_parent"><?php echo _AT('cats_parent_category'); ?></label><br />\r
94                 <select name="cat_parent_id" id="category_parent"><?php\r
95 \r
96                                 $current_cat_id = $cat_id;\r
97                                 $exclude = true; /* exclude the children */\r
98                                 echo '<option value="0">&nbsp;&nbsp;&nbsp;[ '._AT('cats_none').' ]&nbsp;&nbsp;&nbsp;</option>';\r
99                                 echo '<option value="0"></option>';\r
100 \r
101                                 /* @See: include/lib/admin_categories */\r
102                                 select_categories($categories, 0, $current_cat_id, $exclude);\r
103                         ?></select>\r
104         </div>\r
105 \r
106 \r
107 <?php if (defined('AT_ENABLE_CATEGORY_THEMES') && AT_ENABLE_CATEGORY_THEMES) : ?>\r
108         <div class="row">\r
109                 <label for="category_theme"><?php echo _AT('cat_theme'); ?></label><br />\r
110                 <select name="cat_theme" id="category_theme"><?php\r
111 \r
112                                 echo '<option value="0">&nbsp;&nbsp;&nbsp;[ '._AT('cats_none').' ]&nbsp;&nbsp;&nbsp;</option>';\r
113 \r
114                                 $_themes = get_enabled_themes();\r
115                                 foreach ($_themes as $theme) {\r
116                                         $theme = trim($theme);\r
117                                         $theme_dir = get_folder($theme);\r
118                                         $theme_info = get_themes_info($theme_dir);\r
119                                         if ($theme_info['dir_name'] == $categories[$cat_id]['theme']) {\r
120                                                 echo '<option value="'.$theme_info['dir_name'].'" selected="selected">'.$theme.'</option>';\r
121                                         } else {\r
122                                                 echo '<option value="'.$theme_info['dir_name'].'">'.$theme.'</option>';\r
123                                         }\r
124                                 }\r
125 \r
126                         ?></select>\r
127                         <?php if ($cat_id && is_array($categories[$cat_id]['children']) && count($categories[$cat_id]['children'])): ?>\r
128                                 <br />\r
129                                 <input type="checkbox" name="theme_children" id="theme_children" value="1" /><label for="theme_children"><?php echo _AT('apply_theme_subcategories'); ?></label>\r
130                         <?php endif; ?>\r
131                         <?php if ($categories[$cat_id]['cat_parent']): ?>\r
132                                 <br />\r
133                                 <input type="checkbox" name="theme_parent" id="theme_parent" value="1" /><label for="theme_parent"><?php echo _AT('use_parent_theme'); ?></label>\r
134                         <?php endif; ?>\r
135                         <br /><br />\r
136         </div>\r
137 <?php endif; ?>\r
138 \r
139         <div class="row buttons">\r
140                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />\r
141                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"  />\r
142         </div>\r
143 </div>\r
144 </form>\r
145 \r
146 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>