remove old readme
[atutor.git] / mods / _standard / file_storage / module_news.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  * Get the latest updates of this module
16  * @return list of news, [timestamp]=>
17  */
18 function file_storage_news() {
19         global $db, $enrolled_courses, $system_courses;
20         $news = array();
21
22         if ($enrolled_courses == '') {
23                 return $news;
24         }
25         
26         // As personal files are listed in any enrolled courses of the student,
27         // randomly pick one course for bouce.php
28         $end_of_first_course = strpos($enrolled_courses, ",") - 1;
29         $any_one_enrolled_course = substr($enrolled_courses, 1, $end_of_first_course ? $end_of_first_course : -1);
30         
31         $sql = "(SELECT date, file_id, file_name, owner_id course_id, description 
32                    FROM ".TABLE_PREFIX."files 
33                   WHERE owner_type = ".WORKSPACE_COURSE." AND owner_id IN ".$enrolled_courses.")
34                 UNION
35                 (SELECT date, file_id, file_name, ".$any_one_enrolled_course." course_id, description 
36                    FROM ".TABLE_PREFIX."files
37                   WHERE owner_type = ".WORKSPACE_PERSONAL." AND owner_id = ".$_SESSION['member_id'].")
38                 UNION
39                 (SELECT f.date, f.file_id, f.file_name, gt.course_id, f.description 
40                    FROM ".TABLE_PREFIX."files f, ".TABLE_PREFIX."groups g, ".TABLE_PREFIX."groups_types gt
41                   WHERE owner_type = ".WORKSPACE_GROUP." 
42                     AND f.owner_id = g.group_id 
43                     AND g.type_id = gt.type_id 
44                     AND gt.course_id IN ".$enrolled_courses.")
45                  ORDER BY date DESC";
46         $result = mysql_query($sql, $db);
47         
48         if($result){
49                 while($row = mysql_fetch_assoc($result)){
50                         if($row['description'] !=""){
51                                 $filetext = $row['description'];
52                         } else {
53                                 $filetext = $row['file_name'];
54                         }
55                         $news[] = array('time'=>$row['date'], 
56                               'object'=>$row, 
57                               'course'=>$system_courses[$row['course_id']]['title'],
58                               'alt'=>_AT('download'),
59                               'thumb'=>'images/application_get.png', 
60                               'link'=>'<a href="bounce.php?course='.$row['course_id'].SEP.'p='.urlencode('mods/_standard/file_storage/index.php?download=1'.SEP.'files[]='. $row['file_id']).'"'.
61                           (strlen($filetext) > SUBLINK_TEXT_LEN ? ' title="'.AT_print($filetext, 'input.text').'"' : '') .'>'. 
62                           AT_print(validate_length($filetext, SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY), 'input.text') .'</a>');
63                 }
64         }
65         return $news;
66 }
67
68 ?>