move code up one directory
[atutor.git] / mods / _standard / photos / sublinks.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010                                             */
6 /* Inclusive Design Institute                                          */
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$
14
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 require(AT_PA_INCLUDE.'classes/PhotoAlbum.class.php');
17 require(AT_PA_INCLUDE.'lib.inc.php');
18
19 //Comparison Function, return reverse results 
20 function cmp($a, $b){
21         $a = strtotime($a['created_date']);
22         $b = strtotime($b['created_date']);
23         if ($a==$b){
24                 return 0;
25         }
26          return ($a < $b) ? 1 : -1;
27 }
28
29 global $db, $_base_href;
30
31 $record_limit = 3;              //Numero massimo dei possibili sottocontenuti visualizzabili nella home-page
32 $cnt = 0;               // count number of returned forums
33
34 //grab comments and if new course album/photo
35 $pa = new PhotoAlbum();
36 $visible_albums = array_merge($pa->getAlbums($_SESSION['member_id'], AT_PA_TYPE_COURSE_ALBUM),
37                                         $pa->getAlbums($_SESSION['member_id'], AT_PA_TYPE_MY_ALBUM));
38 //check if there are any albums
39 if (empty($visible_albums)){
40         return 0;
41 }
42
43 foreach($visible_albums as $album){
44         $album_ids .= $album['id'] . ', ';
45 }
46 $album_ids = substr($album_ids, 0, strlen($albums_ids) - 2);
47
48 //album comments
49 $sql = 'SELECT * FROM '.TABLE_PREFIX.'pa_album_comments WHERE album_id IN ('.$album_ids.') ORDER BY created_date DESC';
50 $result = mysql_query($sql, $db);
51 while($row = mysql_fetch_assoc($result)){
52         $all_comments[] = $row;
53 }
54
55 //photo comments
56 $sql = 'SELECT c.*, p.album_id FROM '.TABLE_PREFIX.'pa_photo_comments c LEFT JOIN '.TABLE_PREFIX.'pa_photos p ON p.id=c.photo_id WHERE p.album_id IN ('.$album_ids.') ORDER BY created_date DESC';
57 $result = mysql_query($sql, $db);
58 while($row = mysql_fetch_assoc($result)){
59         $all_comments[] = $row;
60 }
61
62 if (empty($all_comments)){
63         return 0;
64 }
65
66 //sort the comments by date in decrement order
67 uasort($all_comments, 'cmp');
68
69 //assign proper link to the comment list.
70 foreach($all_comments as $comment){
71         if (isset($comment['photo_id'])){
72                 $list[] = _AT('comment').': <a href="'.$_base_href.AT_PA_BASENAME.'photo.php?aid='.$comment['album_id'].SEP.'pid='.$comment['photo_id'].'">'.AT_print($comment['comment'], 'photos.comment').'</a>';
73         } elseif (isset($comment['album_id'])){
74                 $list[] = _AT('comment').': <a href="'.$_base_href.AT_PA_BASENAME.'albums.php?id='.$comment['album_id'].'">'.AT_print($comment['comment'], 'photos.comment').'</a>';
75         }
76         if (++$cnt >= $record_limit) break;
77 }
78
79 if (count($list) > 0) {
80         return $list;
81 } else {
82         return 0;
83 }
84 ?>