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/_standard/links/lib/links.inc.php');
\r
19 if (!manage_links()) {
\r
20 $msg->addError('ACCESS_DENIED');
\r
21 header('Location: '.AT_BASE_HREF.'mods/_standard/links/index.php');
\r
25 $cat_id = intval($_REQUEST['cat_id']);
\r
27 if (isset($_POST['submit'])) {
\r
29 //check if cat name is empty
\r
30 if ($_POST['cat_name'] == '') {
\r
31 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
\r
34 if (!$msg->containsErrors()) {
\r
35 //authorized cat parent?
\r
36 $lid = explode('-', $_POST['cat_parent_id']);
\r
37 $parent_id = intval($lid[0]);
\r
38 $owner_type = intval($lid[1]);
\r
39 $owner_id = intval($lid[2]);
\r
41 if (!links_authenticate($owner_type, $owner_id)) {
\r
42 $msg->addError('ACCESS_DENIED');
\r
43 header('Location: '.AT_BASE_HREF.'mods/_standard/links/tools/categories.php');
\r
47 $cat_name = $addslashes($_POST['cat_name']);
\r
49 //Check length of the post, if it's exceeded 100 as defined in the db.
\r
50 $cat_name = validate_length($cat_name, 100);
\r
52 $sql = "UPDATE ".TABLE_PREFIX."links_categories SET parent_id=$parent_id, name='$cat_name', owner_type=$owner_type, owner_id=$owner_id WHERE cat_id=".$cat_id;
\r
54 $result = mysql_query($sql, $db);
\r
55 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
56 header('Location: categories.php');
\r
59 } else if (isset($_POST['cancel'])) {
\r
60 $msg->addFeedback('CANCELLED');
\r
61 header('Location: categories.php');
\r
64 $row = get_cat_info($cat_id);
\r
66 //authorized to edit this cat?
\r
67 if (!links_authenticate($row['owner_type'], $row['owner_id'])) {
\r
68 $msg->addError('ACCESS_DENIED');
\r
69 header('Location: '.AT_BASE_HREF.'mods/_standard/links/tools/categories.php');
\r
74 /* get all the categories: */
\r
75 /* $categories[category_id] = array(cat_name, cat_parent, num_courses, [array(children)]) */
\r
76 $categories = get_link_categories(true);
\r
78 $onload = 'document.form.category_name.focus();';
\r
80 require(AT_INCLUDE_PATH.'header.inc.php');
\r
82 $current_cat_id = $categories[$cat_id]['cat_parent'];
\r
85 <form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
86 <input type="hidden" name="cat_id" value="<?php echo $cat_id; ?>" />
\r
87 <input type="hidden" name="form_submit" value="1" />
\r
89 <div class="input-form">
\r
91 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="category_name"><?php echo _AT('title'); ?></label><br />
\r
92 <input type="text" id="category_name" name="cat_name" value="<?php echo stripslashes(htmlspecialchars($categories[$cat_id]['cat_name'])); ?>" />
\r
96 <label for="category_parent"><?php echo _AT('cats_parent_category'); ?></label><br />
\r
97 <select name="cat_parent_id" id="category_parent"><?php
\r
98 $exclude = true; /* exclude the children */
\r
100 //remove the current cat_id and it's sub cats from list, don't want to print them out.
\r
101 if (is_array($categories[$current_cat_id]['children'])) {
\r
102 foreach ($categories[$current_cat_id]['children'] as $id=>$child) {
\r
103 if ($child == $cat_id) {
\r
104 unset($categories[$current_cat_id]['children'][$id]);
\r
108 unset($categories[$cat_id]);
\r
110 $auth = manage_links();
\r
111 if ($auth == LINK_CAT_AUTH_ALL) {
\r
112 echo '<option value="0-'.LINK_CAT_COURSE.'-'.$_SESSION['course_id'].'"> [ '._AT('cats_none').' ] </option>';
\r
113 echo '<option value="0-'.LINK_CAT_COURSE.'-'.$_SESSION['course_id'].'"></option>';
\r
115 select_link_categories($categories, 0, $current_cat_id, $exclude, 0, TRUE);
\r
118 <div class="row buttons">
\r
119 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
\r
120 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
125 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>