Assignments/Works: Should fix bug when downloading folder see #3964

skala
Julio Montoya 14 years ago
parent ac08e7004b
commit 83e42a74bd
  1. 36
      main/work/downloadfolder.inc.php
  2. 17
      main/work/work.lib.php

@ -8,6 +8,7 @@
*/
$path = $_GET['path'];
//prevent some stuff
if (empty($path)) {
$path = '/';
@ -19,7 +20,7 @@ if (empty($_course) || empty($_course['path'])) {
$sys_course_path = api_get_path(SYS_COURSE_PATH);
//zip library for creation of the zipfile
require api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
//Creating a ZIP file
$temp_zip_file = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip";
@ -34,6 +35,9 @@ $prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
//normal users get only visible files that are in visible folders
//admins are allowed to download invisible files
$files = array();
$course_id = api_get_course_int_id();
if (api_is_allowed_to_edit()) {
//set the path that will be used in the query
if ($path == '/') {
@ -43,15 +47,18 @@ if (api_is_allowed_to_edit()) {
}
//search for all files that are not deleted => visibility != 2
$querypath = Database::escape_string($querypath);
$query = Database::query("SELECT url FROM $tbl_student_publication AS work, $prop_table AS props
WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'2'");
$sql = "SELECT url, title FROM $tbl_student_publication AS work, $prop_table AS props
WHERE props.c_id = $course_id AND work.c_id = $course_id AND props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'2'";
$query = Database::query($sql);
//add tem to the zip file
while ($not_deleted_file = Database::fetch_assoc($query)) {
$zip_folder->add($sys_course_path.$_course['path'].'/'.$not_deleted_file['url'], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work');
}
if (file_exists($sys_course_path.$_course['path'].'/'.$not_deleted_file['url'])) {
$files[basename($not_deleted_file['url'])] = $not_deleted_file['title'];
$zip_folder->add($sys_course_path.$_course['path'].'/'.$not_deleted_file['url'], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work', PCLZIP_CB_PRE_ADD, 'my_pre_add_callback');
}
}
} else {
//for other users, we need to create a zipfile with only visible files and folders
//for other users, we need to create a zipfile with only visible files and folders
if ($path == '/') {
$querypath = ''; // to prevent ...path LIKE '//%'... in query
} else {
@ -95,7 +102,8 @@ if (api_is_allowed_to_edit()) {
}
//add all files in our final array to the zipfile
for ($i=0;$i<count($files_for_zipfile);$i++) {
$zip_folder->add($sys_course_path.$_course['path'].'/'.$files_for_zipfile[$i], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work'.$remove_dir);
$files[$files_for_zipfile[$i]] = 'julio';
//$zip_folder->add($sys_course_path.$_course['path'].'/'.$files_for_zipfile[$i], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work'.$remove_dir, PCLZIP_CB_PRE_ADD, 'my_pre_add_callback');
}
}//end for other users
@ -111,9 +119,19 @@ if (Security::check_abs_path($temp_zip_file, api_get_path(SYS_ARCHIVE_PATH))) {
exit;
}
/* Extra function (only used here) */
function my_pre_add_callback($p_event, &$p_header) {
global $files;
if (isset($files[basename($p_header['stored_filename'])])) {
$p_header['stored_filename'] = $files[basename($p_header['stored_filename'])];
return 1;
}
return 0;
}
/**
* Return the difference between two arrays, as an array of those key/values
* Use this as array_diff doesn't give the

@ -822,16 +822,16 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
} else {
$add_to_name = '';
}
$show_as_icon = get_work_id($mydir); //true or false
$work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']);
if ($show_as_icon) {
if (!empty($show_as_icon)) {
if (api_is_allowed_to_edit()) {
$zip = '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&gradebook='.$gradebook.'&action=downloadfolder&path=/'.$mydir.'">
'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), 22).'</a>';
}
$row[] = $zip.
'<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&id='.$work_data['id'].'"'.$class.'>'.
$row[] = $zip.'<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&id='.$work_data['id'].'"'.$class.'>'.
$work_title.'</a>'.
$add_to_name.'<br />'.$cant_files.' '.$text_file.$dirtext;
} else {
@ -1613,11 +1613,14 @@ function to_javascript_work() {
function get_work_id($path) {
$TBL_STUDENT_PUBLICATION = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$TBL_PROP_TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course_id = api_get_course_int_id();
if (api_is_allowed_to_edit()) {
$sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2'";
$sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work, $TBL_PROP_TABLE AS props
WHERE props.c_id = $course_id AND work.c_id = $course_id AND props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2'";
} else {
$sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2' AND props.lastedit_user_id='".api_get_user_id()."'";
}
$sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props
WHERE props.c_id = $course_id AND work.c_id = $course_id AND props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2' AND props.lastedit_user_id='".api_get_user_id()."'";
}
$result = Database::query($sql);
$num_rows = Database::num_rows($result);

Loading…
Cancel
Save