2 /****************************************************************************/
\r
4 /****************************************************************************/
\r
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton */
\r
6 /* Adaptive Technology Resource Centre / University of Toronto */
\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.'lib/themes.inc.php');
\r
18 admin_authenticate(AT_ADMIN_PRIV_CATEGORIES);
\r
20 require(AT_INCLUDE_PATH.'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
35 if ($_POST['theme_parent']) {
\r
36 $sql = "SELECT theme FROM ".TABLE_PREFIX."course_cats WHERE cat_id=$cat_parent_id";
\r
37 $result = mysql_query($sql, $db);
\r
38 if ($row = mysql_fetch_assoc($result)) {
\r
39 $cat_theme = $row['theme'];
\r
43 if (!$msg->containsErrors()) {
\r
45 $sql = "INSERT INTO ".TABLE_PREFIX."course_cats VALUES (NULL, '$cat_name', $cat_parent_id, '$cat_theme')";
\r
46 $result = mysql_query($sql, $db);
\r
47 $cat_id = mysql_insert_id($db);
\r
48 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
50 write_to_log(AT_ADMIN_LOG_INSERT, 'course_cats', mysql_affected_rows($db), $sql);
\r
52 header('Location: course_categories.php');
\r
55 } else if (isset($_POST['cancel'])) {
\r
56 $msg->addFeedback('CANCELLED');
\r
57 header('Location: course_categories.php');
\r
61 /* $categories[category_id] = array(cat_name, cat_parent, num_courses, [array(children)]) */
\r
62 $categories = get_categories();
\r
64 require(AT_INCLUDE_PATH.'header.inc.php');
\r
69 <form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
70 <input type="hidden" name="cat_id" value="<?php echo $cat_id; ?>" />
\r
71 <input type="hidden" name="form_submit" value="1" />
\r
73 <div class="input-form">
\r
75 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="category_name"><?php echo _AT('title'); ?></label><br />
\r
76 <input type="text" id="category_name" name="cat_name" size="30" value="<?php echo htmlspecialchars($categories[$cat_id]['cat_name']); ?>" />
\r
80 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="category_parent"><?php echo _AT('cats_parent_category'); ?></label><br />
\r
81 <select name="cat_parent_id" id="category_parent"><?php
\r
84 $current_cat_id = $pcat_id;
\r
85 $exclude = false; /* don't exclude the children */
\r
87 $current_cat_id = $cat_id;
\r
88 $exclude = true; /* exclude the children */
\r
91 echo '<option value="0"> [ '._AT('cats_none').' ] </option>';
\r
92 echo '<option value="0"></option>';
\r
94 /* @See: include/lib/admin_categories */
\r
95 select_categories($categories, 0, $current_cat_id, $exclude);
\r
99 <?php if (defined('AT_ENABLE_CATEGORY_THEMES') && AT_ENABLE_CATEGORY_THEMES) : ?>
\r
101 <label for="category_theme"><?php echo _AT('cat_theme'); ?></label><br />
\r
102 <select name="cat_theme" id="category_theme"><?php
\r
104 echo '<option value="0"> [ '._AT('cats_none').' ] </option>';
\r
106 $_themes = get_enabled_themes();
\r
107 foreach ($_themes as $theme) {
\r
108 $theme = trim($theme);
\r
109 $theme_dir = get_folder($theme);
\r
110 if ($theme_dir == $categories[$cat_id]['theme']) {
\r
111 echo '<option value="'.$theme_dir.'" selected="selected">'.$theme.'</option>';
\r
113 echo '<option value="'.$theme_dir.'">'.$theme.'</option>';
\r
118 <?php if ($cat_id && is_array($categories[$cat_id]['children']) && count($categories[$cat_id]['children'])): ?>
\r
120 <input type="checkbox" name="theme_children" id="theme_children" value="1" /><label for="theme_children"><?php echo _AT('apply_theme_subcategories'); ?></label>
\r
122 <?php if ($categories[$cat_id]['cat_parent'] || $pcat_id): ?>
\r
124 <input type="checkbox" name="theme_parent" id="theme_parent" value="1" /><label for="theme_parent"><?php echo _AT('use_parent_theme'); ?></label>
\r
130 <div class="row buttons">
\r
131 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
\r
132 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
137 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>