Esempio n. 1
0
/**
 * download_selected
 * @return void
 **/
function download_selected($dir)
{
    $dir = get_abs_dir($dir);
    global $site_name;
    require_once "_include/archive.php";
    $items = qxpage_selected_items();
    if (count($items) == 1 && is_file($items[0])) {
        download_item($dir, $items[0]);
    } else {
        zip_download($dir, $items);
    }
}
Esempio n. 2
0
function _download_items($dir, $items)
{
    // check if user selected any items to download
    _debug("count items: '{$items['0']}'");
    if (count($items) == 0) {
        show_error($GLOBALS["error_msg"]["miscselitems"]);
    }
    // check if user has permissions to download
    // this file
    if (!_is_download_allowed($dir, $items)) {
        show_error($GLOBALS["error_msg"]["accessitem"]);
    }
    // if we have exactly one file and this is a real
    // file we directly download it
    if (count($items) == 1 && get_is_file($dir, $items[0])) {
        $abs_item = get_abs_item($dir, $items[0]);
        _download($abs_item, $items[0]);
    }
    // otherwise we do the zip download
    zip_download(get_abs_dir($dir), $items);
}
Esempio n. 3
0
        // here we also incorporate the person table to make sure that deleted sent documents are not included.
        $sql = "SELECT DISTINCT file.id, file.filename, file.title\n                FROM " . $dropbox_cnf['tbl_file'] . " file\n                INNER JOIN " . $dropbox_cnf['tbl_person'] . " person\n                ON (person.file_id=file.id AND file.c_id = {$course_id} AND person.c_id = {$course_id})\n                WHERE\n                    file.uploader_id = {$user_id} AND\n                    file.cat_id='" . intval($_GET['cat_id']) . "'  AND\n                    person.user_id = {$user_id}";
    }
    if ($_GET['sent_received'] == 'received') {
        $sql = "SELECT DISTINCT file.id, file.filename, file.title\n                FROM " . $dropbox_cnf['tbl_file'] . " file\n                INNER JOIN " . $dropbox_cnf['tbl_person'] . " person\n                ON (person.file_id=file.id AND file.c_id = {$course_id} AND person.c_id = {$course_id})\n                INNER JOIN " . $dropbox_cnf['tbl_post'] . " post\n                ON (post.file_id = file.id AND post.c_id = {$course_id} AND file.c_id = {$course_id})\n                WHERE\n                    post.cat_id = " . intval($_GET['cat_id']) . " AND\n                    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;
}
/*	DOWNLOAD A FILE */
/* AUTHORIZATION */
// Check if the id makes sense
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    Display::display_header($nameTools, 'Dropbox');
    Display::display_error_message(get_lang('Error'));
    Display::display_footer();
    exit;
}
// Check if the user is allowed to download the file
$allowed_to_download = false;
if (user_can_download_file($_GET['id'], api_get_user_id())) {
    $allowed_to_download = true;
/**
* This function is a wrapper function for the multiple actions feature.
* @return   Mixed   If there is a problem, return a string message, otherwise nothing
* @author   Patrick Cool <*****@*****.**>, Ghent University
* @version  march 2006
*/
function handle_multiple_actions()
{
    $_user = api_get_user_info();
    $is_courseAdmin = api_is_course_admin();
    $is_courseTutor = api_is_course_tutor();
    // STEP 1: are we performing the actions on the received or on the sent files?
    if ($_POST['action'] == 'delete_received' || $_POST['action'] == 'download_received') {
        $part = 'received';
    } elseif ($_POST['action'] == 'delete_sent' || $_POST['action'] == 'download_sent') {
        $part = 'sent';
    }
    // STEP 2: at least one file has to be selected. If not we return an error message
    $ids = isset($_GET['id']) ? $_GET['id'] : array();
    if (count($ids) > 0) {
        $checked_file_ids = $_POST['id'];
    } else {
        foreach ($_POST as $key => $value) {
            if (strstr($value, $part . '_') and $key != 'view_received_category' and $key != 'view_sent_category') {
                $checked_files = true;
                $checked_file_ids[] = intval(substr($value, strrpos($value, '_')));
            }
        }
    }
    $checked_file_ids = $_POST['id'];
    if (!is_array($checked_file_ids) || count($checked_file_ids) == 0) {
        return get_lang('CheckAtLeastOneFile');
    }
    // STEP 3A: deleting
    if ($_POST['action'] == 'delete_received' || $_POST['action'] == 'delete_sent') {
        $dropboxfile = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
        foreach ($checked_file_ids as $key => $value) {
            if ($_GET['view'] == 'received') {
                $dropboxfile->deleteReceivedWork($value);
                $message = get_lang('ReceivedFileDeleted');
            }
            if ($_GET['view'] == 'sent' or empty($_GET['view'])) {
                $dropboxfile->deleteSentWork($value);
                $message = get_lang('SentFileDeleted');
            }
        }
        return $message;
    }
    // STEP 3B: giving comment
    if ($_POST['actions'] == 'comment') {
        // This has not been implemented.
        // The idea was that it would be possible to write the same feedback for the selected documents.
    }
    // STEP 3C: moving
    if (strstr($_POST['action'], 'move_')) {
        // check move_received_n or move_sent_n command
        if (strstr($_POST['action'], 'received')) {
            $part = 'received';
            $to_cat_id = str_replace('move_received_', '', $_POST['action']);
        } else {
            $part = 'sent';
            $to_cat_id = str_replace('move_sent_', '', $_POST['action']);
        }
        foreach ($checked_file_ids as $value) {
            store_move($value, $to_cat_id, $part);
        }
        return get_lang('FilesMoved');
    }
    // STEP 3D: downloading
    if ($_POST['action'] == 'download_sent' || $_POST['action'] == 'download_received') {
        zip_download($checked_file_ids);
    }
}