tagging as ATutor 1.5.4-release
[atutor.git] / tools / news / index.php
1 <?php\r
2 /****************************************************************/\r
3 /* ATutor                                                                                                               */\r
4 /****************************************************************/\r
5 /* Copyright (c) 2002-2007 by Greg Gay & Joel Kronenberg        */\r
6 /* Adaptive Technology Resource Centre / University of Toronto  */\r
7 /* http://atutor.ca                                                                                             */\r
8 /*                                                              */\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
13 // $Id$\r
14 \r
15 $page = 'tools';\r
16 define('AT_INCLUDE_PATH', '../../include/');\r
17 require(AT_INCLUDE_PATH.'vitals.inc.php');\r
18 authenticate(AT_PRIV_ANNOUNCEMENTS);\r
19 \r
20 if (isset($_GET['edit'], $_GET['id'])) {\r
21         header('Location: '.AT_BASE_HREF.'editor/edit_news.php?aid='.intval($_GET['id']));\r
22         exit;\r
23 } else if (isset($_GET['delete'], $_GET['id'])) {\r
24         header('Location: '.AT_BASE_HREF.'editor/delete_news.php?aid='.intval($_GET['id']));\r
25         exit;\r
26 } else if ((isset($_GET['edit']) || isset($_GET['delete']))) {\r
27         $msg->addError('NO_ITEM_SELECTED');\r
28 }\r
29 \r
30 require(AT_INCLUDE_PATH.'header.inc.php');\r
31 \r
32 $orders = array('asc' => 'desc', 'desc' => 'asc');\r
33 $cols   = array('title' => 1, 'date' => 1);\r
34 \r
35 if (isset($_GET['asc'])) {\r
36         $order = 'asc';\r
37         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'date';\r
38 } else if (isset($_GET['desc'])) {\r
39         $order = 'desc';\r
40         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'date';\r
41 } else {\r
42         // no order set\r
43         $order = 'desc';\r
44         $col   = 'date';\r
45 }\r
46 \r
47 $sql    = "SELECT news_id, title, date FROM ".TABLE_PREFIX."news WHERE course_id=$_SESSION[course_id] $and ORDER BY $col $order";\r
48 $result = mysql_query($sql, $db);\r
49 \r
50 ?>\r
51 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">\r
52 <table class="data" summary="" rules="cols">\r
53 <colgroup>\r
54         <?php if ($col == 'title'): ?>\r
55                 <col />\r
56                 <col class="sort" />\r
57                 <col />\r
58         <?php elseif($col == 'date'): ?>\r
59                 <col span="2" />\r
60                 <col class="sort" />\r
61         <?php endif; ?>\r
62 </colgroup>\r
63 <thead>\r
64 <tr>\r
65         <th scope="col">&nbsp;</th>\r
66         <th scope="col"><a href="tools/news/index.php?<?php echo $orders[$order]; ?>=title"><?php echo _AT('title'); ?></a></th>\r
67         <th scope="col"><a href="tools/news/index.php?<?php echo $orders[$order]; ?>=date"><?php echo _AT('date'); ?></a></th>\r
68 </tr>\r
69 </thead>\r
70 <tfoot>\r
71 <tr>\r
72         <td colspan="3"><input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /></td>\r
73 </tr>\r
74 </tfoot>\r
75 <tbody>\r
76         <?php if ($row = mysql_fetch_assoc($result)): ?>\r
77                 <?php do { ?>\r
78                         <tr onmousedown="document.form['n<?php echo $row['news_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['news_id']; ?>">\r
79                                 <td><input type="radio" name="id" value="<?php echo $row['news_id']; ?>" id="n<?php echo $row['news_id']; ?>" /></td>\r
80                                 <td><label for="n<?php echo $row['news_id']; ?>"><?php echo AT_print($row['title'], 'news.title'); ?></label></td>\r
81                                 <td><?php echo AT_date(_AT('announcement_date_format'), $row['date'], AT_DATE_MYSQL_DATETIME); ?></td>\r
82                         </tr>\r
83                 <?php } while ($row = mysql_fetch_assoc($result)); ?>\r
84         <?php else: ?>\r
85                 <tr>\r
86                         <td colspan="3"><?php echo _AT('none_found'); ?></td>\r
87                 </tr>\r
88         <?php endif; ?>\r
89 </tbody>\r
90 </table>\r
91 </form>\r
92 \r
93 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>