Documents: Added Validation messages when have no course, have no file,

have no docInfo, have no path, have different group id, permissions
problem with alert and error
- refs BT#17861
pull/3591/head
Carlos Alvarado 5 years ago
parent 19a5c3d96d
commit acb95b3f5c
No known key found for this signature in database
GPG Key ID: B612DB1EE6658FBB
  1. 6
      main/document/document.php
  2. 76
      main/inc/lib/document.lib.php

@ -280,7 +280,7 @@ switch ($action) {
) )
); );
} else { } else {
Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning')); Display::addFlash(Display::return_message(get_lang('Impossible'), 'error'));
} }
} }
} else { } else {
@ -1808,7 +1808,7 @@ if ($isAllowedToEdit ||
); );
} else { } else {
$actionsLeft .= Display::url( $actionsLeft .= Display::url(
Display::return_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM), Display::return_icon('upload_file.png', get_lang('FileToUpload'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
); );
} }
@ -2284,7 +2284,7 @@ echo '<script>
}); });
data = $(this).data("id"); data = $(this).data("id");
$(".upload_element_"+data).removeClass("hidden"); $(".upload_element_"+data).removeClass("hidden");
$.each($(".currentFile"),function(a,b){ $.each($("[name=\'currentFile\']"),function(a,b){
$(b).val(data); $(b).val(data);
}); });
}); });

@ -5683,40 +5683,26 @@ class DocumentManager
'class' => 'removeHiddenFile', 'class' => 'removeHiddenFile',
] ]
); );
$html = " $form = new FormValidator(
<div class='replaceIndividualFile upload_element_".$randomUploadName." hidden'> 'upload',
<div class='form-group ' id='file_file'> 'POST',
<label class='col-sm-2 control-label' for='file_".$randomUploadName."'> api_get_self().'?'.api_get_cidreq(),
".get_lang('File')." '',
</label> ['enctype' => 'multipart/form-data']
<div class='col-sm-8'> );
<input class='' name='file_".$randomUploadName."' style='width: 250px' type='file'> $form->addElement('html', "<div class='replaceIndividualFile upload_element_".$randomUploadName." hidden'>");
</div> $form->addElement('hidden', 'id_'.$randomUploadName, $randomUploadName);
<div class='col-sm-2'></div> $form->addElement('hidden', 'currentFile', $randomUploadName);
</div> $form->addElement('hidden', 'currentUrl', api_get_self().'?'.api_get_cidreq().'&id='.$document_id);
<div class='form-group '> $form->addElement('hidden', 'id_'.$randomUploadName, $document_id);
<label class='col-sm-2 control-label' for='upload_".$randomUploadName."_submitDocument'> $label = '';
$form->addElement('file', 'file_'.$randomUploadName, [get_lang('File'), $label], 'style="width: 250px" id="user_upload"');
</label> $form->addButtonSend(get_lang('SendDocument'), 'submitDocument');
<div class='col-sm-8'> $form->addProgress('DocumentUpload', 'file');
$form->addElement('html', '</div>');
<button class=' btn btn-primary ' id='upload_".$randomUploadName."_submitDocument'
name='submitDocument' $html = $form->returnForm();
type='submit'>
<em class='fa fa-paper-plane'></em> ".get_lang('ReplaceFile')."
</button>
</div>
<div class='col-sm-2'></div>
</div>
<input class='currentFile' name='currentFile' type='hidden' >
<input id='upload_".$randomUploadName."__qf__upload_".$randomUploadName."' name='_qf__upload_".$randomUploadName."'
type='hidden'
value=''>
<input id='upload_".$randomUploadName."_id' name='id_$randomUploadName' type='hidden' value='$id'>
<input id='upload_".$randomUploadName."_MAX_FILE_SIZE' name='MAX_FILE_SIZE' type='hidden' value='".ini_get('upload_max_filesize')."'>
</div>
";
$modify_icons[] = $html; $modify_icons[] = $html;
} }
@ -6732,15 +6718,21 @@ class DocumentManager
$course_id = $_course['real_id']; $course_id = $_course['real_id'];
if (empty($course_id)) { if (empty($course_id)) {
Display::addFlash(Display::return_message(get_lang('NoCourse'), 'error'));
return false; return false;
} }
if (empty($base_work_dir)) { if (empty($base_work_dir)) {
Display::addFlash(get_lang('Path'));
return false; return false;
} }
if (isset($file) && $file['error'] == 4) { if (isset($file) && $file['error'] == 4) {
//no file //no file
Display::addFlash(Display::return_message(get_lang('NoArchive'), 'error'));
return false; return false;
} }
@ -6761,12 +6753,20 @@ class DocumentManager
$sessionId $sessionId
); );
if (empty($docInfo)) { if (empty($docInfo)) {
Display::addFlash(Display::return_message(get_lang('ArchiveName'), 'error'));
return false; return false;
} }
$path = $docInfo['path']; $path = $docInfo['path'];
} }
if (empty($path) || empty($docInfo) || empty($documentId)) { if (empty($path) || empty($docInfo) || empty($documentId)) {
$str = '';
$str .= "<br>".get_lang('Path');
$str .= "<br>".get_lang('ArchiveName');
$str .= "<br>".get_lang('NoFileSpecified');
Display::addFlash(Display::return_message($str, 'error'));
return false; return false;
} }
@ -6779,11 +6779,15 @@ class DocumentManager
); );
if (empty($itemInfo)) { if (empty($itemInfo)) {
Display::addFlash(Display::return_message(get_lang('NoFileSpecified'), 'error'));
return false; return false;
} }
// Filtering by group. // Filtering by group.
if ($itemInfo['to_group_id'] != $groupId) { if ($itemInfo['to_group_id'] != $groupId) {
Display::addFlash(Display::return_message(get_lang("NoGroupsAvailable"), 'error'));
return false; return false;
} }
$now = new DateTime(); $now = new DateTime();
@ -6798,7 +6802,7 @@ class DocumentManager
$originalMime = self::file_get_mime_type($base_work_dir.$path); $originalMime = self::file_get_mime_type($base_work_dir.$path);
$newMime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file['tmp_name']); $newMime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file['tmp_name']);
if ($originalMime != $newMime) { if ($originalMime != $newMime) {
Display::addFlash(Display::return_message(get_lang('FileError'), 'warning')); Display::addFlash(Display::return_message(get_lang('FileError'), 'error'));
return false; return false;
} }
@ -6810,6 +6814,7 @@ class DocumentManager
$file_renamed_from_disk = true; $file_renamed_from_disk = true;
} else { } else {
// Couldn't rename - file permissions problem? // Couldn't rename - file permissions problem?
Display::addFlash(Display::return_message(get_lang('ErrorImportingFile'), 'error'));
error_log( error_log(
__FILE__.' '.__LINE__.': Error renaming '.$base_work_dir.$path.' to ' __FILE__.' '.__LINE__.': Error renaming '.$base_work_dir.$path.' to '
.$base_work_dir.$new_path.'. This is probably due to file permissions', .$base_work_dir.$new_path.'. This is probably due to file permissions',
@ -6837,6 +6842,7 @@ class DocumentManager
) { ) {
return true; return true;
} else { } else {
Display::addFlash(Display::return_message(get_lang('ErrorImportingFile'), 'warning'));
//Something went wrong //Something went wrong
//The file or directory isn't there anymore (on the filesystem) //The file or directory isn't there anymore (on the filesystem)
// This means it has been removed externally. To prevent a // This means it has been removed externally. To prevent a

Loading…
Cancel
Save