made a copy
[atutor.git] / mods / _standard / blogs / sublinks.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
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
15
16 global $db;
17
18 $record_limit = 3;      // Number of sublinks to display for this module on course home page -> detail view
19
20 $sql = "SELECT G.group_id, G.title, G.modules FROM ".TABLE_PREFIX."groups G INNER JOIN ".TABLE_PREFIX."groups_types T USING (type_id) WHERE T.course_id=$_SESSION[course_id] ORDER BY G.title LIMIT $record_limit";
21 $result = mysql_query($sql, $db);
22
23 if (mysql_num_rows($result) > 0) {
24         while ($row = mysql_fetch_assoc($result)) {
25                 if (strpos($row['modules'], '_standard/blogs') !== FALSE) {
26                         // retrieve the last posted date/time from this blog
27                         $sql = "SELECT MAX(date) AS date FROM ".TABLE_PREFIX."blog_posts WHERE owner_type=".BLOGS_GROUP." AND owner_id={$row['group_id']}";
28                         $date_result = mysql_query($sql, $db);
29                         if (($date_row = mysql_fetch_assoc($date_result)) && $date_row['date']) {
30                                 $last_updated = ' - ' . _AT('last_updated', AT_date(_AT('forum_date_format'), $date_row['date'], AT_DATE_MYSQL_DATETIME));
31                         } else {
32                                 $last_updated = '';
33                         }
34         
35                         $link_title = $row['title'].$last_updated;
36                         $list[] = '<a href="'.url_rewrite('blogs/view.php?ot='.BLOGS_GROUP.htmlentities(SEP).'oid='.$row['group_id'], AT_PRETTY_URL_IS_HEADER).'"'.
37                                   (strlen($link_title) > SUBLINK_TEXT_LEN ? ' title="'.$link_title.'"' : '') .'>'. 
38                                   validate_length($link_title, SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY) .'</a>'; 
39                 }
40         }
41         return $list;
42         
43 } else {
44         return 0;
45 }
46 ?>