Fixing document quota when using dropbox see #3918

skala
Julio Montoya 13 years ago
parent 8d1a475bab
commit 4532e24aac
  1. 5
      main/course_info/infocours.php
  2. 10
      main/document/upload.php
  3. 15
      main/dropbox/dropbox_functions.inc.php
  4. 3
      main/dropbox/dropbox_init.inc.php
  5. 6
      main/dropbox/index.php
  6. 8
      main/exercice/export/exercise_import.inc.php
  7. 4
      main/exercice/hotpotatoes.php
  8. 3
      main/inc/lib/document.lib.php
  9. 34
      main/inc/lib/fileUpload.lib.php
  10. 4
      main/newscorm/learnpath.class.php
  11. 2
      main/newscorm/lp_admin_view.php
  12. 2
      main/upload/upload.document.php
  13. 5
      tests/main/inc/lib/fileUpload.lib.test.php

@ -17,7 +17,7 @@
/* INIT SECTION */
// Language files that need to be included
$language_file = array('create_course', 'course_info', 'admin', 'gradebook');
$language_file = array('create_course', 'course_info', 'admin', 'gradebook', 'document');
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_SETTING;
$this_section = SECTION_COURSES;
@ -27,6 +27,7 @@ $nameTools = get_lang('ModifInfo');
/* Libraries */
require_once api_get_path(INCLUDE_PATH).'conf/course_info.conf.php';
require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
api_protect_course_script(true);
api_block_anonymous_users();
@ -179,6 +180,8 @@ $group = array();
$group[]=$form->createElement('select_theme', 'course_theme', null, array('class'=>' ', 'id'=>'course_theme_id'));
$form->addGroup($group, '', array(get_lang("Stylesheets")), '');
$form->addElement('label', get_lang('DocumentQuota'), format_file_size(DocumentManager::get_course_quota()));
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');

@ -47,7 +47,7 @@ require_once 'document.inc.php';
// Adding extra javascript to the form
$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-upload'));
$htmlHeadXtra[] = '<script type="text/javascript">
$htmlHeadXtra[] = '<script>
function check_unzip() {
if(document.upload.unzip.checked){
@ -74,16 +74,12 @@ function advanced_parameters() {
function setFocus(){
$("#title_file").focus();
}
$(document).ready(function () {
setFocus();
});
</script>';
$htmlHeadXtra[] = "
<script type=\"text/javascript\">
<script>
$(function () {
setFocus();
$('#file_upload').fileUploadUI({
uploadTable: $('.files'),
downloadTable: $('.files'),

@ -755,13 +755,6 @@ function store_add_dropbox() {
// Validating the form data
// the author is
/*
if (!isset($_POST['authors'])) {
return get_lang('AuthorFieldCannotBeEmpty');
}
*/
// there are no recipients selected
if (!isset($_POST['recipients']) || count( $_POST['recipients']) <= 0) {
return get_lang('YouMustSelectAtLeastOneDestinee');
@ -807,7 +800,6 @@ function store_add_dropbox() {
$dropbox_overwrite = true;
}
// doing the upload
$dropbox_filename = $_FILES['file']['name'];
@ -824,6 +816,12 @@ function store_add_dropbox() {
if (!is_uploaded_file($dropbox_filetmpname)) { // check user fraud : no clean error msg.
return get_lang('TheFileIsNotUploaded');
}
$upload_ok = process_uploaded_file($_FILES['file'], true);
if (!$upload_ok) {
return null;
}
// Try to add an extension to the file if it hasn't got one
$dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype);
@ -831,6 +829,7 @@ function store_add_dropbox() {
$dropbox_filename = replace_dangerous_char($dropbox_filename);
// Transform any .php file in .phps fo security
$dropbox_filename = php2phps($dropbox_filename);
//filter extension
if (!filter_extension($dropbox_filename)) {
return get_lang('UplUnableToSaveFileFilteredExtension');

@ -30,8 +30,7 @@
use \ChamiloSession as Session;
$language_file = 'dropbox';
$language_file = array('dropbox', 'document');
// This var disables the link in the breadcrumbs on top of the page
//$noPHP_SELF = true;

@ -144,8 +144,10 @@ if ($action == 'add') {
if (isset($_POST['submitWork'])) {
$check = Security::check_token();
if ($check) {
Display :: display_confirmation_message(store_add_dropbox());
//require_once 'dropbox_submit.php';
$message = store_add_dropbox();
if (!empty($message)) {
Display :: display_confirmation_message($message);
}
}
}

@ -35,17 +35,13 @@ function tempdir($dir, $prefix = 'tmp', $mode = 0777) {
*/
function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) {
global $_course, $_user;
//Check if the file is valid (not to big and exists)
if (!isset ($_FILES['userFile']) || !is_uploaded_file($_FILES['userFile']['tmp_name'])) {
// upload failed
return false;
}
$max_filled_space = DocumentManager::get_course_quota();
if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, $max_filled_space , 1)) {
}
if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 1)) {
if (!function_exists('gzopen')) {
//claro_delete_file($uploadPath);
return false;

@ -96,8 +96,6 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
// Moved this down here as the upload handling functions give output.
if ($form->validate()) {
$max_filled_space = DocumentManager::get_course_quota();
//initialise $finish
if (!isset($finish)) { $finish = 0; }
@ -128,7 +126,7 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
/*if (treat_uploaded_file($_FILES['userFile'], $document_sys_path, $uploadPath."/".$fld, $max_filled_space, $unzip))*/
$allow_output_on_success = false;
if (handle_uploaded_document($_course, $_FILES['userFile'], $document_sys_path, $uploadPath.'/'.$fld, api_get_user_id(), null, null, $max_filled_space, $unzip, '', $allow_output_on_success)) {
if (handle_uploaded_document($_course, $_FILES['userFile'], $document_sys_path, $uploadPath.'/'.$fld, api_get_user_id(), null, null, $unzip, '', $allow_output_on_success)) {
if ($finish == 2) {
$imgparams = $_POST['imgparams'];

@ -2192,7 +2192,6 @@ class DocumentManager {
public static function upload_document($files, $path, $title ='', $comment = '', $unzip = 0, $if_exists = '', $index_document = false, $show_output = false) {
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$max_filled_space = self::get_course_quota();
$course_info = api_get_course_info();
$course_dir = $course_info['path'].'/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
@ -2203,7 +2202,7 @@ class DocumentManager {
if ($upload_ok) {
// File got on the server without problems, now process it
$new_path = handle_uploaded_document($course_info, $files['file'], $base_work_dir, $path, api_get_user_id(), api_get_group_id(), null, $max_filled_space, $unzip, $if_exists, $show_output);
$new_path = handle_uploaded_document($course_info, $files['file'], $base_work_dir, $path, api_get_user_id(), api_get_group_id(), null, $unzip, $if_exists, $show_output);
if ($new_path) {
$docid = DocumentManager::get_document_id($course_info, $new_path);

@ -117,7 +117,7 @@ function process_uploaded_file($uploaded_file, $show_output = true) {
}
return false;
}
if (!file_exists($uploaded_file['tmp_name'])) {
// No file was uploaded.
if ($show_output) {
@ -135,7 +135,21 @@ function process_uploaded_file($uploaded_file, $show_output = true) {
}
return false;
}
}
}
$course_id = api_get_course_id();
//Checking course quota if we are in a course
if (!empty($course_id)) {
$max_filled_space = DocumentManager::get_course_quota();
// Check if there is enough space to save the file
if (!DocumentManager::enough_space($uploaded_file['size'], $max_filled_space)) {
if ($show_output) {
Display::display_error_message(get_lang('UplNotEnoughSpace'));
}
return false;
}
}
// case 0: default: We assume there is no error, the file uploaded with success.
return true;
@ -154,14 +168,13 @@ function process_uploaded_file($uploaded_file, $show_output = true) {
* @param string $upload_path
* @param int $user_id
* @param int $to_group_id, 0 for everybody
* @param int $to_user_id, NULL for everybody
* @param int $maxFilledSpace
* @param int $to_user_id, NULL for everybody
* @param int $unzip 1/0
* @param string $what_if_file_exists overwrite, rename or warn if exists (default)
* @param boolean Optional output parameter. So far only use for unzip_uploaded_document function. If no output wanted on success, set to false.
* @return path of the saved file
*/
function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upload_path, $user_id, $to_group_id = 0, $to_user_id = null, $maxFilledSpace = '', $unzip = 0, $what_if_file_exists = '', $output = true) {
function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upload_path, $user_id, $to_group_id = 0, $to_user_id = null, $unzip = 0, $what_if_file_exists = '', $output = true) {
if (!$user_id) die('Not a valid user.');
// Strip slashes
$uploaded_file['name'] = stripslashes($uploaded_file['name']);
@ -169,17 +182,16 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
$uploaded_file['name'] = add_ext_on_mime($uploaded_file['name'], $uploaded_file['type']);
$current_session_id = api_get_session_id();
if (empty($maxFilledSpace)) {
$maxFilledSpace = DocumentManager::get_course_quota();
}
//Just in case process_uploaded_file is not called
$max_filled_space = DocumentManager::get_course_quota();
// Check if there is enough space to save the file
if (!DocumentManager::enough_space($uploaded_file['size'], $maxFilledSpace)) {
if (!DocumentManager::enough_space($uploaded_file['size'], $max_filled_space)) {
if ($output) {
Display::display_error_message(get_lang('UplNotEnoughSpace'));
}
return false;
}
}
// If the want to unzip, check if the file has a .zip (or ZIP,Zip,ZiP,...) extension
if ($unzip == 1 && preg_match('/.zip$/', strtolower($uploaded_file['name']))) {

@ -591,7 +591,7 @@ class learnpath {
// Upload the file in the documents tool.
include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
$file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', false);
// Getting the filename only.
$file_components = explode('/', $file_path);
@ -1091,7 +1091,7 @@ class learnpath {
if ($pi['extension'] == 'mp3') {
$c_det = api_get_course_info($this->cc);
$bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
$path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
$path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, 0, 'rename', false, 0);
$path = substr($path, 7);
// Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
$audio_update_sql = ", audio = '" . Database::escape_string($path) . "' ";

@ -285,7 +285,7 @@ if (isset($_POST['save_audio'])) {
// Upload the file in the documents tool.
include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$file_path = handle_uploaded_document($_course, $_FILES[$key], api_get_path(SYS_COURSE_PATH).$_course['path'].'/document','/audio', api_get_user_id(), '', '', '', '', '', false);
$file_path = handle_uploaded_document($_course, $_FILES[$key], api_get_path(SYS_COURSE_PATH).$_course['path'].'/document','/audio', api_get_user_id(), '', '', '', '', false);
// Getting the filename only.
$file_components = explode('/', $file_path);

@ -58,7 +58,7 @@ if(isset($_FILES['user_upload'])) {
$upload_ok = process_uploaded_file($_FILES['user_upload']);
if($upload_ok) {
//file got on the server without problems, now process it
$new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space,$_POST['unzip'],$_POST['if_exists']);
$new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$_POST['unzip'],$_POST['if_exists']);
$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
$new_title = isset($_POST['title']) ? trim($_POST['title']) : '';

@ -224,8 +224,7 @@ class TestFileUpload extends UnitTestCase {
$upload_path='';
$user_id=1;
$to_group_id=0;
$to_user_id=NULL;
$maxFilledSpace='';
$to_user_id=NULL;
$unzip=0;
$what_if_file_exists='';
$output=true;
@ -236,7 +235,7 @@ class TestFileUpload extends UnitTestCase {
$clean_name = disable_dangerous_file($clean_name);
$file_path = $upload_path.$clean_name;
ob_start();
$res= handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload_path,$user_id,$to_group_id=0,$to_user_id=NULL,$maxFilledSpace='',$unzip=0,$what_if_file_exists='',$output=true);
$res= handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload_path,$user_id,$to_group_id=0,$to_user_id=NULL, $unzip=0,$what_if_file_exists='',$output=true);
$this->assertTrue(is_null($res));
ob_end_clean();
//var_dump($res);

Loading…
Cancel
Save