<?php print_string("configteacherassignteachers") ?>
</td>
</tr>
+<tr valign=top>
+ <td align=right><p>maxbytes:</td>
+ <td>
+ <?php
+ $options = get_max_upload_sizes();
+ choose_from_menu ($options, "maxbytes", $config->maxbytes, "");
+ ?>
+ </td>
+ <td>
+ <?php print_string("configmaxbytes") ?>
+ </td>
+</tr>
<tr>
<td colspan=3 align=center>
$strmanagemodules = get_string("managemodules");
$strmodulename = get_string("modulename", $module);
- print_header("$site->shortname: $strconfigvariables", $site->fullname,
+ print_header("$site->shortname: $strmodulename: $strconfiguration", $site->fullname,
"<a href=\"index.php\">$stradmin</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> ".
"<a href=\"modules.php\">$strmanagemodules</a> -> $strmodulename", $focus);
helpbutton("coursegrades", get_string("grades")); ?>
</td>
</tr>
+<tr valign=top>
+ <td><P><?php print_string("maximumupload") ?>:</td>
+ <td><?php
+ $choices = get_max_upload_sizes($CFG->maxbytes);
+ choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
+ helpbutton("courseuploadsize", get_string("maximumupload")); ?>
+ </td>
+</tr>
<tr valign=top>
<td><P><?php print_string("wordforteacher") ?>:</td>
<td><input type="text" name="teacher" maxlength="100" size=25 value="<?php p($form->teacher) ?>">
if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
print_heading($strcustomscales);
+
+ if (isteacheredit($course->id)) {
+ echo "<p align=\"center\">(";
+ print_string("scalestip");
+ echo ")</p>";
+ }
+
foreach ($scales as $scale) {
$scalemenu = make_menu_from_list($scale->scale);
print_simple_box_end();
echo "<hr />";
}
+
+ } else {
+ if (isteacheredit($course->id)) {
+ echo "<p align=\"center\">(";
+ print_string("scalestip");
+ echo ")</p>";
+ }
}
if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
}
+ if ($oldversion < 2003092900) {
+ table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
+ }
+
return $result;
}
`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',
table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
}
+ if ($oldversion < 2003092900) {
+ table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
+ }
return $result;
}
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'
}
}
-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) {
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;
}
--- /dev/null
+<form method="post" action="module.php" name="form">
+
+<table cellpadding=9 cellspacing=0 >
+<tr valign=top>
+ <td align=right><p>assignment_maxbytes:</td>
+ <td><?php
+ $choices = get_max_upload_sizes($CFG->maxbytes);
+ choose_from_menu ($choices, "assignment_maxbytes", $CFG->assignment_maxbytes, "");
+ ?>
+ </td>
+ <td>
+ <?php print_string("configmaxbytes", "assignment") ?>
+ </td>
+</tr>
+
+<tr>
+ <td colspan=3 align=center>
+ <input type="submit" value="<?php print_string("savechanges") ?>"></td>
+</tr>
+</table>
+
+</form>
$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,
$form->grade = 100;
}
if (empty($form->maxbytes)) {
- $form->maxbytes = "";
+ $form->maxbytes = $CFG->assignment_maxbytes;
}
if (empty($form->timedue)) {
$form->timedue = "";
</tr>
<tr valign=top>
<td align=right><p><b><?php print_string("maximumsize", "assignment") ?>:</b></p></td>
- <td>
- <?php
- $sizelist = array("10Kb", "50Kb", "100Kb", "500Kb", "1Mb", "2Mb", "5Mb", "10Mb", "20Mb", "50Mb");
- $maxsize = get_max_upload_file_size();
- $sizeinlist = false;
- foreach ($sizelist as $size) {
- $sizebytes = get_real_size($size);
- if ($sizebytes < $maxsize) {
- $filesize[$sizebytes] = $size;
- }
- if ($form->maxbytes == $sizebytes) {
- $sizeinlist = true;
- }
- }
- $filesize[$maxsize] = display_size($maxsize);
- if (!$sizeinlist) {
- $form->maxbytes = get_real_size("500K");
- }
- ksort($filesize, SORT_NUMERIC);
- choose_from_menu($filesize, "maxbytes", "$form->maxbytes", "");
- ?>
- </td>
+ <td><?php
+ $choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
+ choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
+ ?>
+ </td>
</tr>
<tr valign=top>
<td align=right><p><b><?php print_string("duedate", "assignment") ?>:</b></td>
<?php print_string("configmanydiscussions", "forum") ?>
</td>
</tr>
+<tr valign=top>
+ <td align=right><p>forum_maxbytes:</td>
+ <td><?php
+ $choices = get_max_upload_sizes($CFG->maxbytes);
+ choose_from_menu ($choices, "forum_maxbytes", $CFG->forum_maxbytes, "");
+ ?>
+ </td>
+ <td>
+ <?php print_string("configmaxbytes", "forum") ?>
+ </td>
+</tr>
+
<tr>
<td colspan=3 align=center>
<input type="submit" value="<?php print_string("savechanges") ?>"></td>
table_column("forum", "scale", "scale", "integer", "10", "", "0");
execute_sql("UPDATE {$CFG->prefix}forum SET scale = (- scale)");
}
+
+ if ($oldversion < 2003100600) {
+ table_column("forum", "", "maxbytes", "integer", "10", "unsigned", "0", "", "scale");
+ }
return true;
assesstimestart int(10) unsigned NOT NULL default '0',
assesstimefinish int(10) unsigned NOT NULL default '0',
scale int(10) NOT NULL default '0',
+ maxbytes int(10) unsigned NOT NULL default '0',
forcesubscribe tinyint(1) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
open number(2) default '2' not null,\r
assessed number(10) default '0' NOT NULL,\r
scale number(10) default '0' NOT NULL,\r
+ maxbytes number(10) default '0' NOT NULL,\r
forcesubscribe number(1) default '0' NOT NULL,\r
timemodified number(10) default '0' NOT NULL\r
);\r
execute_sql("UPDATE {$CFG->prefix}forum SET scale = (- scale)");
}
+ if ($oldversion < 2003100600) {
+ table_column("forum", "", "maxbytes", "integer", "10", "unsigned", "0", "", "scale");
+ }
+
return true;
}
assesstimestart integer NOT NULL default '0',
assesstimefinish integer NOT NULL default '0',
scale integer NOT NULL default '0',
+ maxbytes integer NOT NULL default '0',
forcesubscribe integer NOT NULL default '0',
timemodified integer NOT NULL default '0'
);
set_config("forum_manydiscussions", 100); // Number of discussions on a page
}
+if (!isset($CFG->forum_maxbytes)) {
+ set_config("forum_maxbytes", 512000); // Default maximum size for all forums
+}
+
+
/// STANDARD FUNCTIONS ///////////////////////////////////////////////////////////
return "";
}
+ if (!$forum = get_record("forum", "id", $post->forum)) {
+ return "";
+ }
+
+ if (!$course = get_record("course", "id", $forum->course)) {
+ return "";
+ }
+
+ $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $forum->maxbytes);
+
$newfile_name = clean_filename($newfile['name']);
if (valid_uploaded_file($newfile)) {
+ if ($maxbytes and $newfile['size'] > $maxbytes) {
+ return "";
+ }
if (! $newfile_name) {
notify("This file had a wierd filename and couldn't be uploaded");
if (!isset($form->forcesubscribe)) {
$form->forcesubscribe = "";
}
+ if (!isset($form->maxbytes)) {
+ $form->maxbytes = $CFG->forum_maxbytes;
+ }
?>
<form name="form" method="post" <?php echo $onsubmit ?> action="mod.php">
<table cellpadding=5>
?>
</td>
</tr>
+<tr valign=top>
+ <td align=right><p><b><?php print_string("maxattachmentsize", "forum") ?>:</b></p></td>
+ <td>
+ <?php
+ $choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
+ $choices[0] = get_string("courseuploadlimit") . " (".display_size($course->maxbytes).")";
+ choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
+ helpbutton("maxattachmentsize", get_string("maxattachmentsize", "forum"), "forum");
+ ?>
+ </td>
+</tr>
<tr>
<td align=right valign=top><p><b><?php print_string("allowratings", "forum") ?>:</b></p></td>
<tr valign=top>
<td align=right><p><b><?php print_string("attachment", "forum") ?>:<br \>(<?php print_string("optional") ?>) </b></p></td>
<td>
- <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_max_upload_file_size() ?>">
+ <?php $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $forum->maxbytes); ?>
+ <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>">
<input type="file" name="attachment" size=40>
<?php
helpbutton("attachment", get_string("attachment", "forum"), "forum");
- print_string("maxsize", "", display_size(get_max_upload_file_size()));
+ print_string("maxsize", "", display_size($maxbytes));
?>
</td>
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003082502;
+$module->version = 2003100600;
$module->cron = 60;
?>
</tr>
-<?php if (!empty($CFG->gdversion)) { ?>
+<?php
+ $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes);
+ if (!empty($CFG->gdversion) and $maxbytes) {
+?>
<tr valign=top>
<td><p><?php print_string("newpicture") ?>:</td>
<td>
- <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_max_upload_file_size() ?>">
+ <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>">
<input type="file" name="imagefile" size=40>
<?php helpbutton("picture", get_string("helppicture"));
- print_string("maxsize", "", display_size(get_max_upload_file_size()));
+ print_string("maxsize", "", display_size($maxbytes));
if (isset($err["imagefile"])) formerr($err["imagefile"]);
?>
</td>
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
-$version = 2003091800; // The current version is a date (YYYYMMDDXX)
+$version = 2003092900; // The current version is a date (YYYYMMDDXX)
$release = "1.2 development"; // User-friendly version number