http://atutor.ca/atutor/mantis/view.php?id=4785
[atutor.git] / docs / mods / _standard / file_storage / module_news.php
index 400914a..c83145f 100644 (file)
@@ -19,15 +19,34 @@ function file_storage_news() {
        global $db, $enrolled_courses, $system_courses;
        $news = array();
 
-       if ($enrolled_courses == ''){
+       if ($enrolled_courses == '') {
                return $news;
-       } 
-
-       $sql = "SELECT date, file_id, file_name, owner_id, description FROM ".TABLE_PREFIX."files WHERE owner_id IN $enrolled_courses ORDER BY date DESC";
+       }
+       
+       // As personal files are listed in any enrolled courses of the student,
+       // randomly pick one course for bouce.php
+       $end_of_first_course = strpos($enrolled_courses, ",") - 1;
+       $any_one_enrolled_course = substr($enrolled_courses, 1, $end_of_first_course ? $end_of_first_course : -1);
+       
+       $sql = "(SELECT date, file_id, file_name, owner_id course_id, description 
+                  FROM ".TABLE_PREFIX."files 
+                 WHERE owner_type = ".WORKSPACE_COURSE." AND owner_id IN ".$enrolled_courses.")
+               UNION
+               (SELECT date, file_id, file_name, ".$any_one_enrolled_course." course_id, description 
+                  FROM ".TABLE_PREFIX."files
+                 WHERE owner_type = ".WORKSPACE_PERSONAL." AND owner_id = ".$_SESSION['member_id'].")
+               UNION
+               (SELECT f.date, f.file_id, f.file_name, gt.course_id, f.description 
+                  FROM ".TABLE_PREFIX."files f, ".TABLE_PREFIX."groups g, ".TABLE_PREFIX."groups_types gt
+                 WHERE owner_type = ".WORKSPACE_GROUP." 
+                   AND f.owner_id = g.group_id 
+                   AND g.type_id = gt.type_id 
+                   AND gt.course_id IN ".$enrolled_courses.")
+                ORDER BY date DESC";
        $result = mysql_query($sql, $db);
+       
        if($result){
                while($row = mysql_fetch_assoc($result)){
-                       $row['course_id'] = $row['owner_id'];
                        if($row['description'] !=""){
                                $filetext = $row['description'];
                        } else {
@@ -35,10 +54,10 @@ function file_storage_news() {
                        }
                        $news[] = array('time'=>$row['date'], 
                              'object'=>$row, 
-                             'course'=>$system_courses[$row['owner_id']]['title'],
+                             'course'=>$system_courses[$row['course_id']]['title'],
                              'alt'=>_AT('download'),
                              'thumb'=>'images/application_get.png', 
-                             'link'=>'<a href="bounce.php?course='.$row['owner_id'].SEP.'p='.urlencode('mods/_standard/file_storage/index.php?download=1'.SEP.'files[]='. $row['file_id']).'"'.
+                             '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']).'"'.
                          (strlen($filetext) > SUBLINK_TEXT_LEN ? ' title="'.AT_print($filetext, 'input.text').'"' : '') .'>'. 
                          AT_print(validate_length($filetext, SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY), 'input.text') .'</a>');
                }