/****************************************************************/
// $Id$
+/**
+ * This script creates the main index page for "file storage" that
+ * handles file upload, edit, view, delete, assignment hand-in etc.
+ * The table below is the mapping between owner type and owner id:
+ ******************************************************
+ * owner_type owner_id
+ ******************************************************
+ * WORKSPACE_COURSE course_id
+ * WORKSPACE_PERSONAL member_id
+ * WORKSPACE_GROUP group_id
+ */
define('AT_INCLUDE_PATH', '../../../include/');
require(AT_INCLUDE_PATH.'vitals.inc.php');
require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php'); // for get_human_size()
else if (isset($_GET['download']) && (isset($_GET['folders']) || isset($_GET['files']))) {
if (is_array($_GET['files']) && (count($_GET['files']) == 1) && empty($_GET['folders'])) {
$file_id = current($_GET['files']);
- $sql = "SELECT file_name, file_size FROM ".TABLE_PREFIX."files WHERE file_id=$file_id AND owner_type=$owner_type AND owner_id=$owner_id";
+ $sql = "SELECT file_name, file_size FROM ".TABLE_PREFIX."files WHERE file_id=$file_id";
$result = mysql_query($sql, $db);
if ($row = mysql_fetch_assoc($result)) {
$ext = fs_get_file_extension($row['file_name']);
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 {
}
$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>');
}