made a copy
[atutor.git] / include / html / dropdowns / posts.inc.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
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 /************************************************************************/
13 // $Id: posts.inc.php 4812 2005-06-07 19:52:15Z joel $
14
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 global $db;
17 global $_base_path;
18 global $savant;
19
20 //Number of posts to display
21 $post_limit = 5;
22         
23 ob_start();
24
25 // global $course_id is set when a guest accessing a public course. 
26 // This is to solve the issue that the google indexing fails as the session vars are lost.
27 global $course_id;
28 if (isset($_SESSION['course_id'])) $course_id = $_SESSION['course_id'];
29
30 $forum_list = get_group_concat('forums_courses', 'forum_id', "course_id={$course_id}");
31 if ($forum_list != 0) {
32         $sql = "SELECT subject, post_id, forum_id, member_id FROM ".TABLE_PREFIX."forums_threads WHERE parent_id=0 AND forum_id IN ($forum_list) ORDER BY last_comment DESC LIMIT $post_limit";
33         $result = mysql_query($sql, $db);
34
35         if (mysql_num_rows($result) > 0) {
36                 while ($row = mysql_fetch_assoc($result)) {
37                         echo '&#176; <a href="' . $_base_path.url_rewrite('forum/view.php?fid=' . $row['forum_id'] . htmlentities(SEP) . 'pid=' . $row['post_id']) . '" title="' . $row['subject'] . ': ' . htmlspecialchars(get_display_name($row['member_id'])) . '">' . AT_print(validate_length($row['subject'], 20, VALIDATE_LENGTH_FOR_DISPLAY), 'forums_threads.subject') . '</a><br />';
38                 }
39         } else {
40                 echo '<em>'._AT('none_found').'</em>';
41         }
42 } else {
43         echo '<em>'._AT('none_found').'</em>';
44 }
45
46 $savant->assign('dropdown_contents', ob_get_contents());
47 ob_end_clean();
48
49 $savant->assign('title', _AT('forum_posts'));
50 $savant->display('include/box.tmpl.php');
51 ?>