These patches are maintained in an publicly accessible Arch repository, see: http://lists.eduforge.org/cgi-bin/archzoom.cgi/arch-eduforge@catalyst.net.nz--2004-MIRROR/moodle--eduforge--1.3.3
Index of arch patches in this commit:
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-66
2004-09-16 00:03:41 GMT
Penny Leach <penny@catalyst.net.nz>
changes to upload class to be silent if we want it to be, integration with editing user profile and group profile (which meant changes in lib/gdlib.php as well as course/group-edit and group.php and user/edit.html and edit.php
Full logs:
Revision: moodle--eduforge--1.3.3--patch-66
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Thu Sep 16 12:03:41 NZST 2004
Standard-date: 2004-09-16 00:03:41 GMT
Modified-files: course/group-edit.html course/group.php
lib/gdlib.php lib/uploadlib.php user/edit.html
user/edit.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-66
Summary: changes to upload class to be silent if we want it to be, integration with editing user profile and group profile (which meant changes in lib/gdlib.php as well as course/group-edit and group.php and user/edit.html and edit.php
Keywords:
<tr valign="top">
<td align="right"><p><?php print_string("newpicture") ?>:</td>
<td>
- <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>" />
- <input type="file" name="imagefile" size="40" />
<?php helpbutton("picture", get_string("helppicture"));
+ require_once($CFG->dirroot.'/lib/uploadlib.php');
+ upload_print_form_fragment(1,array('imagefile'),null,false,null,0,0,false);
print_string("maxsize", "", display_size($maxbytes));
if (isset($err["imagefile"])) formerr($err["imagefile"]);
?>
$err['name'] = get_string("missingname");
} else {
- if (!empty($_FILES['imagefile'])) {
+ require_once($CFG->dirroot.'/lib/uploadlib.php');
+ $um = new upload_manager('imagefile',false,false,null,false,0,false);
+ if ($um->preprocess_files()) {
require_once("$CFG->libdir/gdlib.php");
- if ($filename = valid_uploaded_file($_FILES['imagefile'])) {
- $group->picture = save_profile_image($group->id, $filename, 'groups');
- }
+ $group->picture = save_profile_image($group->id, $um, 'groups');
}
$group->name = $form->name;
$group->description = $form->description;
if (!update_record("groups", $group)) {
notify("A strange error occurred while trying to save ");
} else {
- redirect("group.php?id=$course->id&group=$group->id", get_string("changessaved"));
+ notify(get_string('changessaved'));
+ print_continue("group.php?id=$course->id&group=$group->id");
}
}
}
}
}
-function save_profile_image($id, $filename, $dir="users") {
-// Given a filename to a known image, this function scales and crops
+function save_profile_image($id, $uploadmanager, $dir="users") {
+// Given an upload manager with the right settings, this function performs a virus scan, and then scales and crops
// it and saves it in the right place to be a "user" or "group" image.
global $CFG;
return false;
}
+ if (!$uploadmanager) {
+ return false;
+ }
+
umask(0000);
if (!file_exists("$CFG->dataroot/$dir")) {
return false;
}
}
-
- $originalfile = "$CFG->dataroot/$dir/$id/original";
- if (!move_uploaded_file($filename, $originalfile)) {
+ $destination = "$CFG->dataroot/$dir/$id";
+ if (!$uploadmanager->save_files($destination)) {
return false;
}
- @chmod($originalfile, 0666);
+ $originalfile = $uploadmanager->get_new_filepath();
$imageinfo = GetImageSize($originalfile);
var $status; // keep track of if we're ok (errors for each file are kept in $files['whatever']['uploadlog']
var $course; // the course this file has been uploaded for (for logging and virus notifications)
var $inputname; // if we're only getting one file.
+ var $notify; // if we're given silent=true in the constructor, this gets built up to hold info about the process.
/**
* Constructor, sets up configuration stuff so we know how to act.
* @param $handlecollisions - whether to use handle_filename_collision() or not. (optional, defaults to false)
* @param $course - the course the files are being uploaded for (for logging and virus notifications)
* @param $recoverifmultiple - if we come across a virus, or if a file doesn't validate or whatever, do we continue? optional, defaults to true.
- * @param $modbytes - max bytes for this module - this and $course->maxbytes are used to get the maxbytes to use (lowest) from get_max_upload_file_size().
+ * @param $modbytes - max bytes for this module - this and $course->maxbytes are used to get the maxbytes from get_max_upload_file_size().
+ * @param $silent - whether to notify errors or not.
*/
- function upload_manager($inputname='',$deleteothers=false,$handlecollisions=false,$course=null,$recoverifmultiple=false,$modbytes=0) {
+ function upload_manager($inputname='',$deleteothers=false,$handlecollisions=false,$course=null,$recoverifmultiple=false,$modbytes=0,$silent=false) {
global $CFG;
$this->config->handlecollisions = $handlecollisions;
$this->config->recoverifmultiple = $recoverifmultiple;
$this->config->maxbytes = get_max_upload_file_size($CFG->maxbytes,$course->maxbytes,$modbytes);
+ $this->config->silent = $silent;
$this->files = array();
$this->status = false;
$this->course = $course;
if (!$this->config->recoverifmultiple && count($this->files) > 1) {
$a->name = $this->files[$name]['originalname'];
$a->problem = $this->files[$name]['uploadlog'];
- notify(get_string('uploadfailednotrecovering','moodle',$a));
+ if (!$this->config->silent) {
+ notify(get_string('uploadfailednotrecovering','moodle',$a));
+ }
+ else {
+ $this->notify .= "<br />".get_string('uploadfailednotrecovering','moodle',$a);
+ }
$this->status = false;
return false;
}
else if (count($this->files) == 1) {
- notify($this->files[$name]['uploadlog']);
+ if (!$this->config->silent) {
+ notify($this->files[$name]['uploadlog']);
+ }
+ else {
+ $this->notify .= "<br />".$this->files[$name]['uploadlog'];
+ }
$this->status = false;
return false;
}
}
}
if ($deletedsomething) {
- notify(get_string('uploadoldfilesdeleted'));
+ if (!$this->config->silent) {
+ notify(get_string('uploadoldfilesdeleted'));
+ }
+ else {
+ $this->notify .= "<br />".get_string('uploadoldfilesdeleted');
+ }
}
}
return false;
}
+ /**
+ * If we're only handling one file (if input name was given in the constructor) this will return the full path to the saved file.
+ */
+ function get_new_filepath() {
+ if (!empty($this->inputname) && count($this->files) == 1) {
+ return $this->files[$this->inputname]['fullpath'];
+ }
+ return false;
+ }
+
/**
* If we're only handling one file (if inputname was given in the constructor) this will return the ORIGINAL filename of the file.
*/
<tr valign="top">
<td align="right"> <?php print_string("newpicture") ?>: </td>
<td>
- <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>" />
- <input type="file" name="imagefile" size="40" />
- <?php helpbutton("picture", get_string("helppicture"));
+ <?php
+ require_once($CFG->dirroot.'/lib/uploadlib.php');
+ upload_print_form_fragment(1,array('imagefile'),null,false,null,0,0,false);
+ helpbutton("picture", get_string("helppicture"));
print_string("maxsize", "", display_size($maxbytes));
if (isset($err["imagefile"])) formerr($err["imagefile"]);
?>
$usernew->username = trim(moodle_strtolower($usernew->username));
}
- if (empty($_FILES['imagefile'])) {
- $_FILES['imagefile'] = NULL; // To avoid using uninitialised variable later
- }
- if (find_form_errors($user, $usernew, $err)) {
- if ($filename = valid_uploaded_file($_FILES['imagefile'])) {
- $usernew->picture = save_profile_image($user->id, $filename);
+ require_once($CFG->dirroot.'/lib/uploadlib.php');
+ $um = new upload_manager('imagefile',false,false,null,false,0,true);
+
+ if (find_form_errors($user, $usernew, $err,$um)) {
+ if (empty($err['imagefile']) && $usernew->picture = save_profile_image($user->id, $um,'users')) {
set_field('user', 'picture', $usernew->picture, 'id', $user->id); /// Note picture in DB
} else {
if (!empty($usernew->deletepicture)) {
} else {
$timenow = time();
-
- if ($filename = valid_uploaded_file($_FILES['imagefile'])) {
- $usernew->picture = save_profile_image($user->id, $filename);
- } else {
+
+ if (!$usernew->picture = save_profile_image($user->id,$um,'users')) {
if (!empty($usernew->deletepicture)) {
set_field('user', 'picture', 0, 'id', $user->id); /// Delete picture
$usernew->picture = 0;
$usernew->picture = $user->picture;
}
}
-
+
$usernew->timemodified = time();
-
+
if (isadmin()) {
if (!empty($usernew->newpassword)) {
$usernew->password = md5($usernew->newpassword);
/// FUNCTIONS ////////////////////
-function find_form_errors(&$user, &$usernew, &$err) {
+function find_form_errors(&$user, &$usernew, &$err, &$um) {
global $CFG;
if (isadmin()) {
$err["email"] = $error;
}
}
+ if (!$um->preprocess_files()) {
+ $err['imagefile'] = $um->notify;
+ }
$user->email = $usernew->email;