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 if (isset($_POST['submit'])) {
\r
26 $cat_parent_id = intval($_POST['cat_parent_id']);
\r
27 $cat_name = trim($_POST['cat_name']);
\r
28 $cat_name = $addslashes($cat_name);
\r
30 if ($cat_name == '') {
\r
31 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
\r
34 if (!$msg->containsErrors()) {
\r
36 if (!empty($cat_parent_id)) {
\r
37 $cat_parent_id = explode('-', $_POST['cat_parent_id']);
\r
38 $parent_id = intval($cat_parent_id[0]);
\r
39 $owner_type = intval($cat_parent_id[1]);
\r
40 $owner_id = intval($cat_parent_id[2]);
\r
42 if (!links_authenticate($owner_type, $owner_id)) {
\r
43 $msg->addError('ACCESS_DENIED');
\r
44 header('Location: '.AT_BASE_HREF.'index.php');
\r
48 $owner_type = LINK_CAT_COURSE;
\r
49 $owner_id = $_SESSION['course_id'];
\r
53 //Check length of the post, if it's exceeded 100 as defined in the db.
\r
54 if ($strlen($cat_name) > 100){
\r
55 $cat_name = $substr($cat_name, 0, 100);
\r
58 $sql = "INSERT INTO ".TABLE_PREFIX."links_categories VALUES (NULL, $owner_type, $owner_id, '$cat_name', $parent_id)";
\r
59 $result = mysql_query($sql, $db);
\r
61 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
63 header('Location: categories.php');
\r
66 } else if (isset($_POST['cancel'])) {
\r
67 $msg->addFeedback('CANCELLED');
\r
68 header('Location: categories.php');
\r
73 /* $categories[category_id] = array(cat_name, cat_parent, num_courses, [array(children)]) */
\r
74 $categories = get_link_categories(true);
\r
76 $onload = 'document.form.category_name.focus();';
\r
78 require(AT_INCLUDE_PATH.'header.inc.php');
\r
83 <form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
85 <div class="input-form">
\r
87 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="category_name"><?php echo _AT('title'); ?></label><br />
\r
88 <input type="text" id="category_name" name="cat_name" value="<?php echo stripslashes(htmlspecialchars($categories[$cat_id]['cat_name'])); ?>" />
\r
92 <label for="category_parent"><?php echo _AT('cats_parent_category'); ?></label><br />
\r
93 <?php if ($categories): ?>
\r
94 <select name="cat_parent_id" id="category_parent">
\r
97 $current_cat_id = $pcat_id;
\r
98 $exclude = false; /* don't exclude the children */
\r
100 $current_cat_id = $cat_id;
\r
101 $exclude = true; /* exclude the children */
\r
104 $auth = manage_links();
\r
105 if ($auth == LINK_CAT_AUTH_ALL) {
\r
106 echo '<option value="0"></option>';
\r
109 select_link_categories($categories, 0, $current_cat_id, $exclude, 0, TRUE);
\r
113 echo _AT('cats_no_categories');
\r
117 <div class="row buttons">
\r
118 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
\r
119 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
124 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>