diff --git a/admin/settings/courses.php b/admin/settings/courses.php index 0c5b26bdda3..3816113345d 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -35,10 +35,11 @@ if ($hassiteconfig $temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes')))); $temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes')))); + $currentmaxbytes = get_config('moodlecourse', 'maxbytes'); if (isset($CFG->maxbytes)) { - $choices = get_max_upload_sizes($CFG->maxbytes); + $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $currentmaxbytes); } else { - $choices = get_max_upload_sizes(); + $choices = get_max_upload_sizes(0, 0, 0, $currentmaxbytes); } $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices)); diff --git a/course/edit_form.php b/course/edit_form.php index 4d00ea9dc0c..3cf493e91a7 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -150,7 +150,7 @@ class course_edit_form extends moodleform { $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); - $choices = get_max_upload_sizes($CFG->maxbytes); + $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $course->maxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index f7b74ea6a62..34b42d146dd 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5778,9 +5778,11 @@ function get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0) * @param int $sizebytes Set maximum size * @param int $coursebytes Current course $course->maxbytes (in bytes) * @param int $modulebytes Current module ->maxbytes (in bytes) + * @param int|array $custombytes custom upload size/s which will be added to list, + * Only value/s smaller then maxsize will be added to list. * @return array */ -function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) { +function get_max_upload_sizes($sitebytes = 0, $coursebytes = 0, $modulebytes = 0, $custombytes = null) { global $CFG; if (!$maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes)) { @@ -5792,6 +5794,14 @@ function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) { $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 20971520, 52428800, 104857600); + // If custombytes is given then add it to the list. + if (!is_null($custombytes)) { + if (is_number($custombytes)) { + $custombytes = array((int)$custombytes); + } + $sizelist = array_unique(array_merge($sizelist, $custombytes)); + } + // Allow maxbytes to be selected if it falls outside the above boundaries if (isset($CFG->maxbytes) && !in_array(get_real_size($CFG->maxbytes), $sizelist)) { // note: get_real_size() is used in order to prevent problems with invalid values