From eb9ba087a9c97c08669a90ceeb05a36cd83c98c8 Mon Sep 17 00:00:00 2001 From: cindy li Date: Mon, 29 Aug 2011 14:20:36 +0000 Subject: [PATCH] http://atutor.ca/atutor/mantis/view.php?id=4785 --- docs/mods/_standard/file_storage/index.php | 13 +++++++- .../_standard/file_storage/module_news.php | 33 +++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/docs/mods/_standard/file_storage/index.php b/docs/mods/_standard/file_storage/index.php index 429818ad6..ae4fbd858 100644 --- a/docs/mods/_standard/file_storage/index.php +++ b/docs/mods/_standard/file_storage/index.php @@ -12,6 +12,17 @@ /****************************************************************/ // $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() @@ -164,7 +175,7 @@ else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_GET['move']) 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']); diff --git a/docs/mods/_standard/file_storage/module_news.php b/docs/mods/_standard/file_storage/module_news.php index 400914a98..c83145f46 100644 --- a/docs/mods/_standard/file_storage/module_news.php +++ b/docs/mods/_standard/file_storage/module_news.php @@ -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'=>'' SUBLINK_TEXT_LEN ? ' title="'.AT_print($filetext, 'input.text').'"' : '') .'>'. AT_print(validate_length($filetext, SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY), 'input.text') .''); } -- 2.17.1