Commit a0564ca5 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Check that files uploaded during block configuration are the right type for the block

parent 6a6e4caf
......@@ -486,6 +486,22 @@ function pieform_element_filebrowser_upload(Pieform $form, $element, $data) {
}
// Upload succeeded
if (isset($element['filters'])) {
$artefacttypes = $element['filters']['artefacttype'];
$filetypes = $element['filters']['filetype'];
if (!empty($artefacttypes) || !empty($filetypes)) {
// Need to check the artefacttype or filetype (mimetype) of the uploaded file.
$file = artefact_instance_from_id($newid);
if (is_array($artefacttypes) && !in_array($file->get('artefacttype'), $artefacttypes)
|| is_array($filetypes) && !in_array($file->get('filetype'), $filetypes)) {
$result['error'] = true;
$result['message'] = get_string('wrongfiletypeforblock', 'artefact.file');
return $result;
}
}
}
if ($parentfoldername) {
if ($data->title == $originalname) {
$result['message'] = get_string('uploadoffiletofoldercomplete', 'artefact.file',
......
......@@ -378,6 +378,9 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
this.add_to_selected_list = function (id, highlight) {
if (!self.filedata[id]) {
return;
}
var tbody = getFirstElementByTagAndClassName('tbody', null, self.id + '_selectlist');
var rows = getElementsByTagAndClassName('tr', null, tbody);
if (rows.length == 0) {
......
......@@ -200,6 +200,6 @@ $string['Title'] = 'Title';
$string['imagetitle'] = 'Image Title';
$string['usenodefault'] = 'Use no default';
$string['usingnodefaultprofileicon'] = 'Now using no default profile icon';
$string['wrongfiletypeforblock'] = 'The file you uploaded was not the correct type for this block.';
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment