2 /****************************************************************************/
4 /****************************************************************************/
5 /* Copyright (c) 2002-2006 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/');
17 require (AT_INCLUDE_PATH.'vitals.inc.php');
18 require (AT_INCLUDE_PATH.'lib/links.inc.php');
20 if (!manage_links()) {
21 $_pages['links/index.php']['children'] = array('links/add.php');
24 if (isset($_GET['view'])) {
25 $_GET['view'] = intval($_GET['view']);
27 $sql = "SELECT Url, hits FROM ".TABLE_PREFIX."links WHERE link_id=$_GET[view]";
28 $results = mysql_query($sql,$db);
30 if ($row = mysql_fetch_assoc($results)) {
31 if (!authenticate(AT_PRIV_LINKS, AT_PRIV_RETURN)) {
34 $sql = "UPDATE ".TABLE_PREFIX."links SET hits=$row[hits] WHERE link_id=$_GET[view]";
35 mysql_query($sql,$db);
39 header('Location: ' . $row['Url']);
44 require (AT_INCLUDE_PATH.'header.inc.php');
46 if ($_GET['reset_filter']) {
50 $_GET['cat_parent_id'] = intval($_GET['cat_parent_id']);
52 //get appropriate categories
53 $categories = get_link_categories();
55 //ascending decscending columns...
57 $orders = array('asc' => 'desc', 'desc' => 'asc');
58 $cols = array('LinkName' => 1, 'name' => 1, 'description' => 1);
60 if (isset($_GET['asc'])) {
62 $col = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'LinkName';
63 } else if (isset($_GET['desc'])) {
65 $col = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'LinkName';
73 if ($_GET['search']) {
74 $_GET['search'] = trim($_GET['search']);
75 $page_string .= SEP.'search='.urlencode($_GET['search']);
76 $search = $addslashes($_GET['search']);
77 $search = str_replace(array('%','_'), array('\%', '\_'), $search);
78 $search = '%'.$search.'%';
79 $search = "((LinkName LIKE '$search') OR (description LIKE '$search'))";
84 //view links of a child category
85 if ($_GET['cat_parent_id']) {
86 $children = get_child_categories ($_GET['cat_parent_id'], $categories);
87 $cat_sql = "C.cat_id IN ($children $_GET[cat_parent_id])";
88 $parent_id = intval($_GET['cat_parent_id']);
95 $tmp_groups = implode(',', $_SESSION['groups']);
97 if (!empty($tmp_groups)) {
98 $sql = "SELECT * FROM ".TABLE_PREFIX."links L INNER JOIN ".TABLE_PREFIX."links_categories C USING (cat_id) WHERE ((owner_id=$_SESSION[course_id] AND owner_type=".LINK_CAT_COURSE.") OR (owner_id IN ($tmp_groups) AND owner_type=".LINK_CAT_GROUP.")) AND L.Approved=1 AND $search AND $cat_sql ORDER BY $col $order";
100 $sql = "SELECT * FROM ".TABLE_PREFIX."links L INNER JOIN ".TABLE_PREFIX."links_categories C USING (cat_id) WHERE (owner_id=$_SESSION[course_id] AND owner_type=".LINK_CAT_COURSE.") AND L.Approved=1 AND $search AND $cat_sql ORDER BY $col $order";
102 $result = mysql_query($sql, $db);
103 $num_results = mysql_num_rows($result);
106 <?php if ($num_results > 0 || isset($_GET['filter'])): ?>
107 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
109 <div class="input-form">
111 <h3><?php echo _AT('results_found', $num_results); ?></h3>
115 <label for="category_parent"><?php echo _AT('select_cat'); ?></label>
117 <?php if (!empty($categories)): ?>
118 <select name="cat_parent_id" id="category_parent"><?php
120 $current_cat_id = $parent_id;
121 $exclude = false; /* don't exclude the children */
123 $current_cat_id = $cat_id;
124 $exclude = true; /* exclude the children */
127 echo '<option value="0"> '._AT('cats_all').' </option>';
128 select_link_categories($categories, 0, $current_cat_id, FALSE);
135 <label for="search"><?php echo _AT('search'); ?> (<?php echo _AT('title').', '._AT('description'); ?>)</label><br />
136 <input type="text" name="search" id="search" size="20" value="<?php echo htmlspecialchars($_GET['search']); ?>" />
140 <div class="row buttons">
141 <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
142 <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
148 <table class="data static" summary="" rules="cols">
150 <?php if ($col == 'LinkName'): ?>
153 <?php elseif($col == 'name'): ?>
157 <?php elseif($col == 'description'): ?>
164 <th scope="col"><a href="links/index.php?<?php echo $orders[$order]; ?>=LinkName<?php echo $page_string; ?>"><?php echo _AT('title'); ?></a></th>
165 <th scope="col"><a href="links/index.php?<?php echo $orders[$order]; ?>=name<?php echo $page_string; ?>"><?php echo _AT('category'); ?></a></th>
166 <th scope="col"><a href="links/index.php?<?php echo $orders[$order]; ?>=description<?php echo $page_string; ?>"><?php echo _AT('description'); ?></a></th>
170 <?php if ($row = mysql_fetch_assoc($result)) : ?>
174 <tr onmousedown="document.form['m<?php echo $row['link_id']; ?>'].checked = true;">
175 <td><a href="links/index.php?view=<?php echo $row['link_id']; ?>" target="_new" title="<?php echo AT_print($row['LinkName'], 'links.LinkName'); ?>"><?php echo AT_print($row['LinkName'], 'links.LinkName'); ?></a></td>
177 if (empty($row['name'])) {
178 $row['name'] = get_group_name($row['owner_id']);
180 echo AT_print($row['name'], 'links.name');
182 <td><?php echo AT_print($row['Description'], 'links.Description'); ?></td>
185 } while ($row = mysql_fetch_assoc($result)); ?>
188 <td colspan="3"><?php echo _AT('none_found'); ?></td>
194 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>