diff --git a/lang/en/repository.php b/lang/en/repository.php index 3ce42b4b8e1..62e8e616842 100644 --- a/lang/en/repository.php +++ b/lang/en/repository.php @@ -91,6 +91,7 @@ $string['errornotyourfile'] = 'You cannot pick file which is not added by your'; $string['erroruniquename'] = 'Repository instance name should be unique'; $string['existingrepository'] = 'This repository already exists'; $string['federatedsearch'] = 'Federated search'; +$string['fileexists'] = 'File name already being used, please use another name'; $string['filename'] = 'Filename'; $string['filenotnull'] = 'You must select a file to upload.'; $string['filesaved'] = 'The file has been saved'; diff --git a/repository/filepicker.js b/repository/filepicker.js index 6bf3796a314..6b004d2810a 100644 --- a/repository/filepicker.js +++ b/repository/filepicker.js @@ -1006,6 +1006,8 @@ M.core_filepicker.init = function(Y, options) { str += ''; str += ''; str += ''; + str += ''; + str += ''; str += ''; for (var i in types) { str += ''; diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index a239b59555f..b51d121ec2f 100755 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -251,7 +251,7 @@ switch ($action) { // see MDL-23407 try { // TODO: add file scanning MDL-19380 into each plugin - $result = $repo->upload(); + $result = $repo->upload($saveas_filename); echo json_encode($result); } catch (Exception $e) { $err->error = $e->getMessage(); diff --git a/repository/upload/lib.php b/repository/upload/lib.php index 430f51c323b..85e21370631 100755 --- a/repository/upload/lib.php +++ b/repository/upload/lib.php @@ -41,7 +41,7 @@ class repository_upload extends repository { * Process uploaded file * @return array|bool */ - public function upload() { + public function upload($saveas_filename) { global $USER, $CFG; $types = optional_param('accepted_types', '*', PARAM_RAW); @@ -79,8 +79,10 @@ class repository_upload extends repository { throw new moodle_exception('maxbytes'); } - if (empty($record->filename)) { + if (empty($saveas_filename)) { $record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); + } else { + $record->filename = $saveas_filename; } if ($this->mimetypes != '*') { @@ -99,11 +101,13 @@ class repository_upload extends repository { } if ($file = $fs->get_file($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename)) { - return array( - 'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(), - 'id'=>$file->get_itemid(), - 'file'=>$file->get_filename() - ); + throw new moodle_exception('fileexists', 'repository'); + //$record->filename = ; + //return array( + //'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(), + //'id'=>$file->get_itemid(), + //'file'=>$file->get_filename() + //); } $record->contextid = $context->id;