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 if (isset($_POST['submit'])) {
\r
23 /* insert or update a category */
\r
24 $cat_id = intval($_POST['cat_id']);
\r
25 $cat_parent_id = intval($_POST['cat_parent_id']);
\r
26 $cat_name = trim($_POST['cat_name']);
\r
28 $cat_name = $addslashes($cat_name);
\r
29 $cat_theme = $addslashes($_POST['cat_theme']);
\r
31 if ($cat_name == '') {
\r
32 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
\r
34 $cat_name = validate_length($cat_name, 100);
\r
36 if ($_POST['theme_parent']) {
\r
37 $sql = "SELECT theme FROM ".TABLE_PREFIX."course_cats WHERE cat_id=$cat_parent_id";
\r
38 $result = mysql_query($sql, $db);
\r
39 if ($row = mysql_fetch_assoc($result)) {
\r
40 $cat_theme = $row['theme'];
\r
44 if (!$msg->containsErrors()) {
\r
46 $sql = "INSERT INTO ".TABLE_PREFIX."course_cats VALUES (NULL, '$cat_name', $cat_parent_id, '$cat_theme')";
\r
47 $result = mysql_query($sql, $db);
\r
48 $cat_id = mysql_insert_id($db);
\r
49 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
51 write_to_log(AT_ADMIN_LOG_INSERT, 'course_cats', mysql_affected_rows($db), $sql);
\r
53 header('Location: course_categories.php');
\r
56 } else if (isset($_POST['cancel'])) {
\r
57 $msg->addFeedback('CANCELLED');
\r
58 header('Location: course_categories.php');
\r
62 /* $categories[category_id] = array(cat_name, cat_parent, num_courses, [array(children)]) */
\r
63 $categories = get_categories();
\r
65 require(AT_INCLUDE_PATH.'header.inc.php');
\r
70 <form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
71 <input type="hidden" name="cat_id" value="<?php echo $cat_id; ?>" />
\r
72 <input type="hidden" name="form_submit" value="1" />
\r
74 <div class="input-form">
\r
76 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="category_name"><?php echo _AT('title'); ?></label><br />
\r
77 <input type="text" id="category_name" name="cat_name" size="30" value="<?php echo htmlspecialchars($categories[$cat_id]['cat_name']); ?>" />
\r
81 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="category_parent"><?php echo _AT('cats_parent_category'); ?></label><br />
\r
82 <select name="cat_parent_id" id="category_parent"><?php
\r
85 $current_cat_id = $pcat_id;
\r
86 $exclude = false; /* don't exclude the children */
\r
88 $current_cat_id = $cat_id;
\r
89 $exclude = true; /* exclude the children */
\r
92 echo '<option value="0"> [ '._AT('cats_none').' ] </option>';
\r
93 echo '<option value="0"></option>';
\r
95 /* @See: include/lib/admin_categories */
\r
96 select_categories($categories, 0, $current_cat_id, $exclude);
\r
100 <?php if (defined('AT_ENABLE_CATEGORY_THEMES') && AT_ENABLE_CATEGORY_THEMES) : ?>
\r
102 <label for="category_theme"><?php echo _AT('cat_theme'); ?></label><br />
\r
103 <select name="cat_theme" id="category_theme"><?php
\r
105 echo '<option value="0"> [ '._AT('cats_none').' ] </option>';
\r
107 $_themes = get_enabled_themes();
\r
108 foreach ($_themes as $theme) {
\r
109 $theme = trim($theme);
\r
110 $theme_dir = get_folder($theme);
\r
111 if ($theme_dir == $categories[$cat_id]['theme']) {
\r
112 echo '<option value="'.$theme_dir.'" selected="selected">'.$theme.'</option>';
\r
114 echo '<option value="'.$theme_dir.'">'.$theme.'</option>';
\r
119 <?php if ($cat_id && is_array($categories[$cat_id]['children']) && count($categories[$cat_id]['children'])): ?>
\r
121 <input type="checkbox" name="theme_children" id="theme_children" value="1" /><label for="theme_children"><?php echo _AT('apply_theme_subcategories'); ?></label>
\r
123 <?php if ($categories[$cat_id]['cat_parent'] || $pcat_id): ?>
\r
125 <input type="checkbox" name="theme_parent" id="theme_parent" value="1" /><label for="theme_parent"><?php echo _AT('use_parent_theme'); ?></label>
\r
131 <div class="row buttons">
\r
132 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
\r
133 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
138 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>