Allow same name in publications see BT#11678

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 064c993458
commit 98aeb95b53
  1. 3
      main/inc/ajax/work.ajax.php
  2. 51
      main/inc/lib/formvalidator/FormValidator.class.php
  3. 40
      main/work/work.lib.php

@ -51,7 +51,8 @@ switch ($action) {
$groupId, $groupId,
$userId, $userId,
$file, $file,
true false,
false
); );
$json = array(); $json = array();

@ -1316,12 +1316,12 @@ EOT;
*/ */
private function addMultipleUploadJavascript($url, $inputName) private function addMultipleUploadJavascript($url, $inputName)
{ {
$icon = Display::return_icon('file_txt.gif');
$this->addHtml(" $this->addHtml("
<script> <script>
$(function () { $(function () {
'use strict'; 'use strict';
$('#".$this->getAttribute('id')."').submit(function() {
$('#".$this->getAttribute('id')."').submit(function(){
return false; return false;
}); });
@ -1363,33 +1363,25 @@ EOT;
previewCrop: true, previewCrop: true,
dropzone: $('#dropzone') dropzone: $('#dropzone')
}).on('fileuploadadd', function (e, data) { }).on('fileuploadadd', function (e, data) {
data.context = $('<div/>').appendTo('#files'); data.context = $('<div class=\"row\" style=\"margin-bottom:35px\" />').appendTo('#files');
$.each(data.files, function (index, file) { $.each(data.files, function (index, file) {
var node = $('<p/>').append($('<span/>').text(file.name)); var node = $('<div class=\"col-sm-5\">').text(file.name);
/*if (!index) {
node
.append('<br>')
.append(uploadButton.clone(true).data(data));
}*/
node.appendTo(data.context); node.appendTo(data.context);
} }
); );
}).on('fileuploadprocessalways', function (e, data) { }).on('fileuploadprocessalways', function (e, data) {
var index = data.index, var index = data.index,
file = data.files[index], file = data.files[index],
node = $(data.context.children()[index]); node = $(data.context.children()[index]);
if (file.preview) { if (file.preview) {
node data.context
.prepend('<br>') .prepend($('<div class=\"col-sm-2\">').html(file.preview))
.prepend(file.preview); ;
node } else {
.append('<br>') data.context
.append($('<span class=\"text-success\"/>').text('" . addslashes(get_lang('UplUploadSucceeded')) . "')); .prepend($('<div class=\"col-sm-2\">').html('".$icon."'))
} ;
if (file.error) {
node
.append('<br>')
.append($('<span class=\"text-danger\"/>').text(file.error));
} }
if (index + 1 === data.files.length) { if (index + 1 === data.files.length) {
data.context.find('button') data.context.find('button')
@ -1408,22 +1400,20 @@ EOT;
var link = $('<a>') var link = $('<a>')
.attr('target', '_blank') .attr('target', '_blank')
.prop('href', file.url); .prop('href', file.url);
$(data.context.children()[index]).parent().wrap(link);
$(data.context.children()[index]).wrap(link); var successMessage = $('<div class=\"col-sm-3\">').html($('<span class=\"alert alert-success\"/>').text('" . addslashes(get_lang('UplUploadSucceeded')) . "'));
$(data.context.children()[index]).parent().append(successMessage);
} else if (file.error) { } else if (file.error) {
var error = $('<span class=\"text-danger\"/>').text(file.error); var error = $('<div class=\"col-sm-3\">').html($('<span class=\"alert alert-danger\"/>').text(file.error));
$(data.context.children()[index]) $(data.context.children()[index]).parent().append(error);
.append('<br>')
.append(error);
} }
}); });
}).on('fileuploadfail', function (e, data) { }).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) { $.each(data.files, function (index) {
var failedMessage = '" . addslashes(get_lang('UplUploadFailed')) . "'; var failedMessage = '" . addslashes(get_lang('UplUploadFailed')) . "';
var error = $('<span class=\"text-danger\"/>').text(failedMessage); var error = $('<div class=\"col-sm-3\">').html($('<span class=\"alert alert-danger\"/>').text(failedMessage));
$(data.context.children()[index]) $(data.context.children()[index]).parent().append(error);
.append('<br>')
.append(error);
}); });
}).prop('disabled', !$.support.fileInput) }).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled'); .parent().addClass($.support.fileInput ? undefined : 'disabled');
@ -1431,8 +1421,7 @@ EOT;
$('.fileinput-button').hide(); $('.fileinput-button').hide();
}); });
</script>" </script>");
);
} }
} }

@ -3333,7 +3333,12 @@ function uploadWork($my_folder_data, $_course, $isCorrection = false, $workInfo
} }
if (empty($file['size'])) { if (empty($file['size'])) {
return array('error' => Display :: return_message(get_lang('UplUploadFailedSizeIsZero'), 'error')); return array(
'error' => Display:: return_message(
get_lang('UplUploadFailedSizeIsZero'),
'error'
),
);
} }
$updir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work/'; //directory path to upload $updir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/work/'; //directory path to upload
@ -3535,11 +3540,21 @@ function checkExistingWorkFileName($filename, $workId)
* @param int $userId * @param int $userId
* @param array $file * @param array $file
* @param bool $checkDuplicated * @param bool $checkDuplicated
* @param bool $showFlashMessage
* *
* @return null|string * @return null|string
*/ */
function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId, $userId, $file = [], $checkDuplicated = false) function processWorkForm(
{ $workInfo,
$values,
$courseInfo,
$sessionId,
$groupId,
$userId,
$file = [],
$checkDuplicated = false,
$showFlashMessage = true
) {
$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$courseId = $courseInfo['real_id']; $courseId = $courseInfo['real_id'];
@ -3570,8 +3585,10 @@ function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId,
} }
if (isset($result['error'])) { if (isset($result['error'])) {
$message = $result['error']; if ($showFlashMessage) {
Display::addFlash($message); $message = $result['error'];
Display::addFlash($message);
}
$saveWork = false; $saveWork = false;
} }
@ -3654,10 +3671,19 @@ function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId,
sendAlertToUsers($workId, $courseInfo, $sessionId); sendAlertToUsers($workId, $courseInfo, $sessionId);
Event::event_upload($workId); Event::event_upload($workId);
$workData = get_work_data_by_id($workId); $workData = get_work_data_by_id($workId);
Display::addFlash(Display::return_message(get_lang('DocAdd'))); if ($showFlashMessage) {
Display::addFlash(Display::return_message(get_lang('DocAdd')));
}
} }
} else { } else {
Display::addFlash(Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error')); if ($showFlashMessage) {
Display::addFlash(
Display::return_message(
get_lang('IsNotPosibleSaveTheDocument'),
'error'
)
);
}
} }
return $workData; return $workData;

Loading…
Cancel
Save