123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- $language_file = 'dropbox';
- require_once 'dropbox_config.inc.php';
- require_once 'dropbox_functions.inc.php';
- require_once 'dropbox_class.inc.php';
- require_once api_get_path(LIBRARY_PATH).'document.lib.php';
- $course_id = api_get_course_int_id();
- $user_id = api_get_user_id();
- if (isset($_GET['cat_id']) AND
- is_numeric($_GET['cat_id']) AND
- $_GET['action'] == 'downloadcategory' AND
- isset($_GET['sent_received'])
- ) {
-
- if ($_GET['sent_received'] == 'sent') {
-
- $sql = "SELECT DISTINCT file.id, file.filename, file.title
- FROM ".$dropbox_cnf['tbl_file']." file
- INNER JOIN ".$dropbox_cnf['tbl_person']." person
- ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
- WHERE
- file.uploader_id = $user_id AND
- file.cat_id='".intval($_GET['cat_id'])."' AND
- person.user_id = $user_id";
- }
- if ($_GET['sent_received'] == 'received') {
- $sql = "SELECT DISTINCT file.id, file.filename, file.title
- FROM ".$dropbox_cnf['tbl_file']." file
- INNER JOIN ".$dropbox_cnf['tbl_person']." person
- ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
- INNER JOIN ".$dropbox_cnf['tbl_post']." post
- ON (post.file_id = file.id AND post.c_id = $course_id AND file.c_id = $course_id)
- WHERE
- post.cat_id = ".intval($_GET['cat_id'])." AND
- post.dest_user_id = $user_id" ;
- }
- $files_to_download = array();
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $files_to_download[] = $row['id'];
- }
- if (!is_array($files_to_download) OR empty($files_to_download)) {
- header('location: index.php?view='.Security::remove_XSS($_GET['sent_received']).'&error=ErrorNoFilesInFolder');
- exit;
- }
- zip_download($files_to_download);
- exit;
- }
- if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
- Display::display_header($nameTools, 'Dropbox');
- Display :: display_error_message(get_lang('Error'));
- Display::display_footer();
- exit;
- }
- $allowed_to_download = false;
- if (user_can_download_file($_GET['id'], api_get_user_id())) {
- $allowed_to_download = true;
- }
- if (!$allowed_to_download) {
- Display::display_header($nameTools, 'Dropbox');
- Display::display_error_message(get_lang('YouAreNotAllowedToDownloadThisFile'));
- Display::display_footer();
- exit;
- } else {
-
-
- $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX][] = intval($_GET['id']);
- $work = new Dropbox_work($_GET['id']);
- $path = dropbox_cnf('sysPath') . '/' . $work -> filename;
- if (!Security::check_abs_path($path, dropbox_cnf('sysPath').'/')) {
- exit;
- }
- $file = $work->title;
- $mimetype = DocumentManager::file_get_mime_type(true);
- $fileinfo = pathinfo($file);
- $extension = $fileinfo['extension'];
- if (!empty($extension) && isset($mimetype[$extension]) && $_GET['action'] != 'download') {
-
- header( 'Content-type: ' . $mimetype[$extension] . "\n");
- } else {
-
- header( "Content-type: application/octet-stream\n");
- }
- header('Content-Disposition: attachment; filename='.$file);
-
- header("Pragma: \n");
- header("Cache-Control: \n");
- header("Cache-Control: public\n");
-
- header('Content-Description: '.trim(htmlentities($file)));
- header('Content-transfer-encoding: binary');
- header("Content-Length: " . filesize($path)."\n" );
- $fp = fopen( $path, 'rb');
- fpassthru($fp);
- exit();
- }
- exit;
|