2 /****************************************************************************/
4 /****************************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay, Joel Kronenberg & Heidi Hazelton */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************************/
15 define('AT_INCLUDE_PATH', '../../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 require (AT_INCLUDE_PATH.'lib/links.inc.php');
19 if (!manage_links()) {
20 $msg->addError('ACCESS_DENIED');
21 header('Location: '.AT_BASE_HREF.'links/index.php');
25 if (!isset($_POST['approved'])) {
26 $_POST['approved'] = 1;
29 if (isset($_POST['cancel'])) {
30 $msg->addFeedback('CANCELLED');
31 header('Location: '.AT_BASE_HREF.'tools/links/index.php');
35 if (isset($_POST['add_link']) && isset($_POST['submit'])) {
37 //check category_id and see if user is allowed..
38 $cat = explode('-', $_POST['cat']);
39 $cat_id = intval($cat[0]);
40 $owner_type = intval($cat[1]);
41 $owner_id = intval($cat[2]);
43 if (!links_authenticate($owner_type, $owner_id)) {
44 $msg->addError('ACCESS_DENIED');
45 header('Location: '.AT_BASE_HREF.'links/index.php');
49 $missing_fields = array();
50 if ($_POST['cat'] == 0 || $_POST['cat'] == '') {
51 $missing_fields[] = _AT('category');
53 if (trim($_POST['title']) == '') {
54 $missing_fields[] = _AT('title');
56 if (trim($_POST['url']) == '' || $_POST['url'] == 'http://') {
57 $missing_fields[] = _AT('url');
59 if (trim($_POST['description']) == '') {
60 $missing_fields[] = _AT('description');
63 if ($missing_fields) {
64 $missing_fields = implode(', ', $missing_fields);
65 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
68 if (!$msg->containsErrors() && isset($_POST['submit'])) {
69 $_POST['title'] = $addslashes($_POST['title']);
70 $_POST['url'] == $addslashes($_POST['url']);
71 $_POST['description'] = $addslashes($_POST['description']);
73 $name = get_display_name($_SESSION['member_id']);
76 $approved = intval($_POST['approved']);
78 $sql = "INSERT INTO ".TABLE_PREFIX."links VALUES (NULL, $cat_id, '$_POST[url]', '$_POST[title]', '$_POST[description]', $approved, '$name', '$email', NOW(), 0)";
79 mysql_query($sql, $db);
81 $msg->addFeedback('LINK_ADDED');
83 header('Location: '.AT_BASE_HREF.'tools/links/index.php');
86 $_POST['title'] = stripslashes($_POST['title']);
87 $_POST['url'] == stripslashes($_POST['url']);
88 $_POST['description'] = stripslashes($_POST['description']);
92 if (!isset($_POST['url'])) {
93 $_POST['url'] = 'http://';
96 $categories = get_link_categories(true);
98 if (empty($categories)) {
99 $msg->addError('LINK_CAT_EMPTY');
100 header('Location: '.AT_BASE_HREF.'tools/links/index.php');
104 $onload = 'document.form.title.focus();';
106 require(AT_INCLUDE_PATH.'header.inc.php');
111 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
112 <input type="hidden" name="add_link" value="true" />
114 <div class="input-form">
116 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="title"><?php echo _AT('title'); ?></label><br />
117 <input type="text" name="title" size="40" id="title" value="<?php echo $_POST['title']; ?>"/>
121 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="cat"><?php echo _AT('category'); ?></label><br />
122 <select name="cat" id="cat"><?php
124 $current_cat_id = $pcat_id;
125 $exclude = false; /* don't exclude the children */
127 $current_cat_id = $cat_id;
128 $exclude = true; /* exclude the children */
130 select_link_categories($categories, 0, $_POST['cat'], FALSE, '', TRUE);
136 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="url"><?php echo _AT('url'); ?></label><br />
137 <input type="text" name="url" size="40" id="url" value="<?php echo $_POST['url']; ?>" />
141 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="description"><?php echo _AT('description'); ?></label><br />
142 <textarea name="description" cols="55" rows="5" id="description" style="width:90%;"><?php echo $_POST['description']; ?></textarea>
146 <?php echo _AT('approve'); ?><br />
148 if ($_POST['approved']) {
149 $y = 'checked="checked"';
151 } else if (isset ($_POST['approved'])) {
152 $n = 'checked="checked"';
155 $y = 'checked="checked"';
159 <input type="radio" id="yes" name="approved" value="1" <?php echo $y; ?>><label for="yes"><?php echo _AT('yes'); ?></label> <input type="radio" id="no" name="approved" value="0" <?php echo $n; ?>><label for="no"><?php echo _AT('no'); ?></label>
162 <div class="row buttons">
163 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
164 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
169 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>