diff --git a/admin/config.html b/admin/config.html index b8a79c71f8b..2848bbd2990 100644 --- a/admin/config.html +++ b/admin/config.html @@ -300,6 +300,18 @@ +
maxbytes:
:
:
("; + print_string("scalestip"); + echo ")
"; + } + foreach ($scales as $scale) { $scalemenu = make_menu_from_list($scale->scale); @@ -64,6 +71,13 @@ print_simple_box_end(); echo "("; + print_string("scalestip"); + echo ")
"; + } } if ($scales = get_records("scale", "courseid", "0", "name ASC")) { diff --git a/lib/db/mysql.php b/lib/db/mysql.php index d5b6ef09180..3152c56f189 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -505,6 +505,10 @@ function main_upgrade($oldversion=0) { table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score"); } + if ($oldversion < 2003092900) { + table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker"); + } + return $result; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 9b8b2a9b3b4..d9da0b3d580 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -48,6 +48,7 @@ CREATE TABLE `prefix_course` ( `numsections` smallint(5) unsigned NOT NULL default '1', `showrecent` smallint(5) unsigned NOT NULL default '1', `marker` int(10) unsigned NOT NULL default '0', + `maxbytes` int(10) unsigned NOT NULL default '0', `visible` int(10) unsigned NOT NULL default '1', `timecreated` int(10) unsigned NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 89e6a89a030..e7e09b7ce19 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -254,6 +254,9 @@ function main_upgrade($oldversion=0) { table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score"); } + if ($oldversion < 2003092900) { + table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker"); + } return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index 5e4fe2d3217..30a5f4141e9 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -26,6 +26,7 @@ CREATE TABLE prefix_course ( numsections integer NOT NULL default '1', showrecent integer NOT NULL default '1', marker integer NOT NULL default '0', + maxbytes integer NOT NULL default '0', visible integer NOT NULL default '1', timecreated integer NOT NULL default '0', timemodified integer NOT NULL default '0' diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 8a57b0350e6..ec9d6bfcccb 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1059,12 +1059,64 @@ function valid_uploaded_file($newfile) { } } -function get_max_upload_file_size() { +function get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0) { /// Returns the maximum size for uploading files +/// There are six possible upload limits: +/// +/// 1) in Apache using LimitRequestBody (no way of checking or changing this) +/// 2) in php.ini for 'upload_max_filesize' (can not be changed inside PHP) +/// 3) in .htaccess for 'upload_max_filesize' (can not be changed inside PHP) +/// 4) by the Moodle admin in $CFG->maxbytes +/// 5) by the teacher in the current course $course->maxbytes +/// 6) by the teacher for the current module, eg $assignment->maxbytes +/// +/// These last two are passed to this function as arguments (in bytes). +/// Anything defined as 0 is ignored. +/// The smallest of all the non-zero numbers is returned. + if (! $filesize = ini_get("upload_max_filesize")) { $filesize = "5M"; } - return get_real_size($filesize); + $minimumsize = get_real_size($filesize); + + if ($sitebytes and $sitebytes < $minimumsize) { + $minimumsize = $sitebytes; + } + + if ($coursebytes and $coursebytes < $minimumsize) { + $minimumsize = $coursebytes; + } + + if ($modulebytes and $modulebytes < $minimumsize) { + $minimumsize = $modulebytes; + } + + return $minimumsize; +} + +function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) { +/// Related to the above function - this function returns an +/// array of possible sizes in an array, translated to the +/// local language. + + if (!$maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes)) { + return array(); + } + + $filesize[$maxsize] = display_size($maxsize); + + $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152, + 5242880, 10485760, 20971520, 52428800, 104857600); + + foreach ($sizelist as $sizebytes) { + if ($sizebytes < $maxsize) { + $filesize[$sizebytes] = display_size($sizebytes); + } + } + + krsort($filesize, SORT_NUMERIC); + + return $filesize; } function get_directory_list($rootdir, $excludefile="", $descend=true) { @@ -1127,14 +1179,24 @@ function get_real_size($size=0) { function display_size($size) { /// Converts bytes into display form + + static $gb,$mb,$kb,$b; + + if (empty($gb)) { + $gb = get_string('sizegb'); + $mb = get_string('sizemb'); + $kb = get_string('sizekb'); + $b = get_string('sizeb'); + } + if ($size >= 1073741824) { - $size = round($size / 1073741824 * 10) / 10 . "Gb"; + $size = round($size / 1073741824 * 10) / 10 . $gb; } else if ($size >= 1048576) { - $size = round($size / 1048576 * 10) / 10 . "Mb"; + $size = round($size / 1048576 * 10) / 10 . $mb; } else if ($size >= 1024) { - $size = round($size / 1024 * 10) / 10 . "Kb"; + $size = round($size / 1024 * 10) / 10 . $kb; } else { - $size = $size . "b"; + $size = $size ." $b"; } return $size; } diff --git a/mod/assignment/config.html b/mod/assignment/config.html new file mode 100644 index 00000000000..26248960d46 --- /dev/null +++ b/mod/assignment/config.html @@ -0,0 +1,22 @@ + diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 8dfacf800cd..37dab00ec6d 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -8,6 +8,10 @@ define("UPLOADSINGLE", "1"); $ASSIGNMENT_TYPE = array (OFFLINE => get_string("typeoffline", "assignment"), UPLOADSINGLE => get_string("typeuploadsingle", "assignment") ); +if (!isset($CFG->assignment_maxbytes)) { + set_config("assignment_maxbytes", 1024000); // Default maximum size for all assignments +} + function assignment_add_instance($assignment) { // Given an object containing all the necessary data, diff --git a/mod/assignment/mod.html b/mod/assignment/mod.html index 224c612f2de..031bcf2b37b 100644 --- a/mod/assignment/mod.html +++ b/mod/assignment/mod.html @@ -25,7 +25,7 @@ $form->grade = 100; } if (empty($form->maxbytes)) { - $form->maxbytes = ""; + $form->maxbytes = $CFG->assignment_maxbytes; } if (empty($form->timedue)) { $form->timedue = ""; @@ -104,28 +104,11 @@:
:
forum_maxbytes: