2 /****************************************************************************/
\r
4 /****************************************************************************/
\r
5 /* Copyright (c) 2002-2010 */
\r
6 /* Inclusive Design Institute */
\r
7 /* http://atutor.ca */
\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
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
20 require(AT_INCLUDE_PATH.'../mods/_core/cats_categories/lib/admin_categories.inc.php');
\r
22 $cat_id = intval($_REQUEST['cat_id']);
\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
29 if ($_POST['theme_parent']) {
\r
30 // get the theme of the parent category.
\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
38 if ($cat_name == '') {
\r
39 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
\r
42 if (!$msg->containsErrors()) {
\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
50 $sql = "UPDATE ".TABLE_PREFIX."course_cats SET theme='$cat_theme' WHERE cat_id IN ($children)";
\r
51 $result = mysql_query($sql, $db);
\r
53 write_to_log(AT_ADMIN_LOG_UPDATE, 'course_cats', mysql_affected_rows($db), $sql);
\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
60 write_to_log(AT_ADMIN_LOG_UPDATE, 'course_cats', mysql_affected_rows($db), $sql);
\r
62 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
64 header('Location: course_categories.php');
\r
67 } else if (isset($_POST['cancel'])) {
\r
68 $msg->addFeedback('CANCELLED');
\r
69 header('Location: course_categories.php');
\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
77 require(AT_INCLUDE_PATH.'header.inc.php');
\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
86 <div class="input-form">
\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
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
96 $current_cat_id = $cat_id;
\r
97 $exclude = true; /* exclude the children */
\r
98 echo '<option value="0"> [ '._AT('cats_none').' ] </option>';
\r
99 echo '<option value="0"></option>';
\r
101 /* @See: include/lib/admin_categories */
\r
102 select_categories($categories, 0, $current_cat_id, $exclude);
\r
107 <?php if (defined('AT_ENABLE_CATEGORY_THEMES') && AT_ENABLE_CATEGORY_THEMES) : ?>
\r
109 <label for="category_theme"><?php echo _AT('cat_theme'); ?></label><br />
\r
110 <select name="cat_theme" id="category_theme"><?php
\r
112 echo '<option value="0"> [ '._AT('cats_none').' ] </option>';
\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
122 echo '<option value="'.$theme_info['dir_name'].'">'.$theme.'</option>';
\r
127 <?php if ($cat_id && is_array($categories[$cat_id]['children']) && count($categories[$cat_id]['children'])): ?>
\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
131 <?php if ($categories[$cat_id]['cat_parent']): ?>
\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
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
146 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>