Download file directly see BT#7680

1.10.x
Julio Montoya 9 years ago
parent fff980f981
commit 6956617f5d
  1. 66
      main/dropbox/dropbox_download.php
  2. 43
      main/inc/lib/display.lib.php

@ -17,9 +17,9 @@ require_once 'dropbox_functions.inc.php';
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$user_id = api_get_user_id(); $user_id = api_get_user_id();
if (isset($_GET['cat_id']) AND if (isset($_GET['cat_id']) &&
is_numeric($_GET['cat_id']) AND is_numeric($_GET['cat_id']) &&
$_GET['action'] == 'downloadcategory' AND $_GET['action'] == 'downloadcategory' &&
isset($_GET['sent_received']) isset($_GET['sent_received'])
) { ) {
/** step 1: constructing the sql statement. /** step 1: constructing the sql statement.
@ -69,9 +69,7 @@ if (isset($_GET['cat_id']) AND
// Check if the id makes sense // Check if the id makes sense
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
Display::display_header($nameTools, 'Dropbox'); api_not_allowed(true);
Display :: display_error_message(get_lang('Error'));
Display::display_footer();
exit; exit;
} }
@ -84,9 +82,13 @@ if (user_can_download_file($_GET['id'], api_get_user_id())) {
/* ERROR IF NOT ALLOWED TO DOWNLOAD */ /* ERROR IF NOT ALLOWED TO DOWNLOAD */
if (!$allowed_to_download) { if (!$allowed_to_download) {
Display::display_header($nameTools, 'Dropbox'); api_not_allowed(
Display::display_error_message(get_lang('YouAreNotAllowedToDownloadThisFile')); true,
Display::display_footer(); Display::return_message(
get_lang('YouAreNotAllowedToDownloadThisFile'),
'error'
)
);
exit; exit;
} else { } else {
/* DOWNLOAD THE FILE */ /* DOWNLOAD THE FILE */
@ -100,50 +102,8 @@ if (!$allowed_to_download) {
exit; exit;
} }
$file = $work->title; $file = $work->title;
$mimetype = DocumentManager::file_get_mime_type(true); DocumentManager::file_send_for_download($path, true, $file);
$fileinfo = pathinfo($file); exit;
$extension = $fileinfo['extension'];
if (!empty($extension) && isset($mimetype[$extension]) && $_GET['action'] != 'download') {
// give hint to browser about filetype
header( 'Content-type: ' . $mimetype[$extension] . "\n");
} else {
//no information about filetype: force a download dialog window in browser
header( "Content-type: application/octet-stream\n");
}
header('Content-Disposition: attachment; filename='.$file);
/**
* Note that if you use these two headers from a previous example:
* header('Cache-Control: no-cache, must-revalidate');
* header('Pragma: no-cache');
* before sending a file to the browser, the "Open" option on Internet Explorer's file download dialog will not work properly. If the user clicks "Open" instead of "Save," the target application will open an empty file, because the downloaded file was not cached. The user will have to save the file to their hard drive in order to use it.
* Make sure to leave these headers out if you'd like your visitors to be able to use IE's "Open" option.
*/
header("Pragma: \n");
header("Cache-Control: \n");
header("Cache-Control: public\n"); // IE cannot download from sessions without a cache
/*if (isset($_SERVER['HTTPS'])) {
/**
* We need to set the following headers to make downloads work using IE in HTTPS mode.
*
//header('Pragma: ');
//header('Cache-Control: ');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
header("Last-Modified: " . gmdate( "D, d M Y H:i:s") . " GMT\n");
header("Cache-Control: no-store, no-cache, must-revalidate\n"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0\n", false);
}*/
header('Content-Description: '.trim(htmlentities($file)));
header('Content-transfer-encoding: binary');
header("Content-Length: " . filesize($path)."\n" );
$fp = fopen( $path, 'rb');
fpassthru($fp);
exit();
} }
//@todo clean this file the code below is useless there are 2 exits in previous conditions ... maybe a bad copy/paste/merge? //@todo clean this file the code below is useless there are 2 exits in previous conditions ... maybe a bad copy/paste/merge?
exit; exit;

@ -1268,8 +1268,7 @@ class Display
foreach($rows as $content) { foreach($rows as $content) {
$table->setCellContents($row, $column, $content); $table->setCellContents($row, $column, $content);
$row++; $row++;
//$column++; }
}
} }
return $table->toHtml(); return $table->toHtml();
} }
@ -1341,8 +1340,9 @@ class Display
tet.to_group_id group_id, tet.to_group_id group_id,
ctt.image image, ctt.image image,
ctt.link link ctt.link link
FROM $tool_edit_table tet INNER JOIN $course_tool_table ctt FROM $tool_edit_table tet
ON tet.c_id = ctt.c_id INNER JOIN $course_tool_table ctt
ON tet.c_id = ctt.c_id
WHERE WHERE
tet.c_id = $course_id AND tet.c_id = $course_id AND
tet.lastedit_date > '$oldestTrackDate' ". tet.lastedit_date > '$oldestTrackDate' ".
@ -1358,7 +1358,7 @@ class Display
$group_ids[] = 0; //add group 'everyone' $group_ids[] = 0; //add group 'everyone'
$notifications = array(); $notifications = array();
// Filter all last edits of all tools of the course // Filter all last edits of all tools of the course
while ($res && ($item_property = Database::fetch_array($res))) { while ($res && ($item_property = Database::fetch_array($res, 'ASSOC'))) {
// First thing to check is if the user never entered the tool // First thing to check is if the user never entered the tool
// or if his last visit was earlier than the last modification. // or if his last visit was earlier than the last modification.
@ -1390,6 +1390,7 @@ class Display
) { ) {
continue; continue;
} }
// If it's a survey, make sure the user's invited. Otherwise drop it. // If it's a survey, make sure the user's invited. Otherwise drop it.
if ($item_property['tool'] == TOOL_SURVEY) { if ($item_property['tool'] == TOOL_SURVEY) {
$survey_info = SurveyManager::get_survey($item_property['ref'], 0, $course_code); $survey_info = SurveyManager::get_survey($item_property['ref'], 0, $course_code);
@ -1403,13 +1404,21 @@ class Display
} }
} }
} }
// If it's a learning path, ensure it is currently visible to the user // If it's a learning path, ensure it is currently visible to the user
if ($item_property['tool'] == TOOL_LEARNPATH) { if ($item_property['tool'] == TOOL_LEARNPATH) {
if (!learnpath::is_lp_visible_for_student($item_property['ref'], $user_id, $course_code)) { if (!learnpath::is_lp_visible_for_student($item_property['ref'], $user_id, $course_code)) {
continue; continue;
} }
} }
if ($item_property['tool'] == 'work' && $item_property['type'] == 'DirectoryCreated') {
if ($item_property['tool'] == TOOL_DROPBOX) {
$item_property['link'] = 'dropbox/dropbox_download.php?id='.$item_property['ref'];
}
if ($item_property['tool'] == 'work' &&
$item_property['type'] == 'DirectoryCreated'
) {
$item_property['lastedit_type'] = 'WorkAdded'; $item_property['lastedit_type'] = 'WorkAdded';
} }
$notifications[$item_property['tool']] = $item_property; $notifications[$item_property['tool']] = $item_property;
@ -1417,16 +1426,28 @@ class Display
} }
// Show all tool icons where there is something new. // Show all tool icons where there is something new.
$retvalue = ' '; $return = ' ';
while (list($key, $notification) = each($notifications)) { foreach($notifications as $notification) {
$lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date'])); $lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date']));
$type = $notification['lastedit_type']; $type = $notification['lastedit_type'];
$label = get_lang('TitleNotification').": ".get_lang($type)." ($lastDate)"; $label = get_lang('TitleNotification').": ".get_lang($type)." ($lastDate)";
$retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$course_code.'&ref='.$notification['ref'].'&gidReq='.$notification['to_group_id'].'&id_session='.$sessionId.'">'.
Display::return_icon($notification['image'], $label).'</a>&nbsp;'; if (strpos($notification['link'], '?') === false) {
$notification['link'] = $notification['link'].'?notification=1';
} else {
$notification['link'] = $notification['link'].'&notification=1';
}
$return .= Display::url(
Display::return_icon($notification['image'], $label),
api_get_path(WEB_CODE_PATH).
$notification['link'].'&cidReq='.$course_code.
'&ref='.$notification['ref'].
'&gidReq='.$notification['to_group_id'].
'&id_session='.$sessionId
).'&nbsp;';
} }
return $retvalue; return $return;
} }
/** /**

Loading…
Cancel
Save