Add upload in document/lp form see BT#10887

ofaj
jmontoya 10 years ago
parent a43ff833f8
commit e1eaab826c
  1. 2
      app/Resources/public/css/base.css
  2. 2
      main/document/upload.php
  3. 30
      main/inc/ajax/document.ajax.php
  4. 38
      main/inc/lib/document.lib.php
  5. 66
      main/newscorm/learnpath.class.php
  6. 131
      main/newscorm/lp_add_item.php

@ -5399,7 +5399,7 @@ div#chat-remote-video video {
width: 420px;
}
.tab-wrapper .tab-content{
padding: 25px;
padding: 25px 0px 25px 0px;
}
.description-upload{
margin-bottom: 10px;

@ -315,7 +315,7 @@ if ($is_certificate_mode) {
// Link to create a folder
echo $toolbar = Display::toolbarAction('toolbar-upload', array( 0 => $actions), 1);
echo $toolbar = Display::toolbarAction('toolbar-upload', array(0 => $actions), 1);
// Form to select directory
$folders = DocumentManager::get_all_document_folders($_course, $groupId, $is_allowed_to_edit);
if (!$is_certificate_mode) {

@ -26,13 +26,29 @@ switch ($action) {
exit;
}
$fileExistsOption = api_get_setting('document_if_file_exists_option');
$defaultFileExistsOption = 'rename';
if (!empty($fileExistsOption)) {
$defaultFileExistsOption = $fileExistsOption;
$directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0;
$currentDirectory = '';
if (empty($directoryParentId)) {
$currentDirectory = isset($_REQUEST['curdirpath']) ? $_REQUEST['curdirpath'] : '';
} else {
$documentData = DocumentManager::get_document_data_by_id($directoryParentId, api_get_course_id());
if ($documentData) {
$currentDirectory = $documentData['path'];
}
}
//$ifExists = isset($_POST['if_exists']) ? $_POST['if_exists'] : $defaultFileExistsOption;
$ifExists = isset($_POST['if_exists']) ? $_POST['if_exists'] : '';
$unzip = isset($_POST['unzip']) ? 1 : 0;
if (empty($ifExists)) {
$fileExistsOption = api_get_setting('document_if_file_exists_option');
$defaultFileExistsOption = 'rename';
if (!empty($fileExistsOption)) {
$defaultFileExistsOption = $fileExistsOption;
}
} else {
$defaultFileExistsOption = $ifExists;
}
if (!empty($_FILES)) {
$files = $_FILES['files'];
@ -51,10 +67,10 @@ switch ($action) {
$globalFile['files'] = $file;
$result = DocumentManager::upload_document(
$globalFile,
$_REQUEST['curdirpath'],
$currentDirectory,
$file['name'],
'', // comment
0,
$unzip,
$defaultFileExistsOption,
false,
false,

@ -2789,6 +2789,8 @@ class DocumentManager
* @param string $if_exists overwrite, rename or warn (default)
* @param bool $index_document index document (search xapian module)
* @param bool $show_output print html messages
* @param string $fileKey
*
* @return array|bool
*/
public static function upload_document(
@ -2829,6 +2831,21 @@ class DocumentManager
$sessionId
);
// Showing message when sending zip files
if ($new_path === true && $unzip == 1) {
if ($show_output) {
Display::display_confirmation_message(
get_lang('UplUploadSucceeded').'<br />',
false
);
}
return [
'title' => $path,
'url' => $path,
];
}
if ($new_path) {
$documentId = DocumentManager::get_document_id(
$course_info,
@ -2875,13 +2892,6 @@ class DocumentManager
);
}
// Showing message when sending zip files
if ($new_path === true && $unzip == 1 && $show_output) {
Display::display_confirmation_message(
get_lang('UplUploadSucceeded') . '<br />',
false
);
}
if ($index_document) {
self::index_document(
@ -3403,13 +3413,13 @@ class DocumentManager
$return = '';
if ($lp_id) {
if ($folderId === false) {
$return .= '<div class="lp_resource_element">';
/*$return .= '<div class="lp_resource_element">';
$return .= Display::return_icon('new_doc.gif', '', array(), ICON_SIZE_SMALL);
$return .= Display::url(
get_lang('NewDocument'),
api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id
);
$return .= '</div>';
$return .= '</div>';*/
}
} else {
$return .= Display::div(
@ -5034,8 +5044,14 @@ class DocumentManager
* @return string html form
*/
public static function build_directory_selector($folders, $document_id, $group_dir = '', $change_renderer = false, & $form = null, $selectName = 'id')
{
public static function build_directory_selector(
$folders,
$document_id,
$group_dir = '',
$change_renderer = false,
& $form = null,
$selectName = 'id'
) {
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
$folder_titles = array();

@ -8672,7 +8672,7 @@ class learnpath
$course_info = api_get_course_info();
$sessionId = api_get_session_id();
$document_tree = DocumentManager::get_document_preview(
$documentTree = DocumentManager::get_document_preview(
$course_info,
$this->lp_id,
null,
@ -8684,7 +8684,69 @@ class learnpath
true
);
return $document_tree;
$headers = array(
get_lang('Files'),
get_lang('NewDocument'),
get_lang('Upload'),
);
$multipleForm = '';
$form = new FormValidator('form_upload', 'POST', api_get_self() . '?' .$_SERVER['QUERY_STRING'], '', array('enctype'=> "multipart/form-data"));
$folders = DocumentManager::get_all_document_folders(
api_get_course_info(),
0,
true
);
DocumentManager::build_directory_selector(
$folders,
'',
array(),
true,
$form,
'directory_parent_id'
);
$form->addElement('radio', 'if_exists', get_lang('UplWhatIfFileExists'), get_lang('UplDoNothing'), 'nothing');
$form->addElement('radio', 'if_exists', '', get_lang('UplOverwriteLong'), 'overwrite');
$form->addElement('radio', 'if_exists', '', get_lang('UplRenameLong'), 'rename');
$form->setDefaults(['if_exists' => 'rename']);
// Check box options
$form->addElement(
'checkbox',
'unzip',
get_lang('Options'),
get_lang('Uncompress')
);
$form->addHtml('
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>'.get_lang('AddFiles').'</span>
<!-- The file input field used as target for the file upload widget -->
<input id="file_upload" type="file" name="files[]" multiple>
</span>
<br />
<br />
<!-- The global progress bar -->
<div id="progress" class="progress">
<div class="progress-bar progress-bar-success"></div>
</div>
<div id="files" class="files"></div>
'
);
$new = $this->display_document_form('add', 0);
$tabs = Display::tabs($headers, array($documentTree, $new, $form->returnForm()), 'subtab');
return $tabs;
}
/**

@ -93,20 +93,136 @@ if (!empty($gradebook) && $gradebook == 'view') {
);
}
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
$interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $learnPath->get_name());
$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-upload'));
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?'.api_get_cidreq().'&a=upload_file&curdirpath=';
$htmlHeadXtra[] = "
<script>
$(function () {
'use strict';
$('#form_upload').submit(function() {
return false;
});
var url = '".$url."';
var uploadButton = $('<button/>')
.addClass('btn btn-primary')
.prop('disabled', true)
.text('".get_lang('Loading')."')
.on('click', function () {
var \$this = $(this),
data = \$this.data();
\$this
.off('click')
.text('".get_lang('Cancel')."')
.on('click', function () {
\$this.remove();
data.abort();
});
data.submit().always(function () {
\$this.remove();
});
});
$('#file_upload').fileupload({
url: url,
dataType: 'json',
autoUpload: false,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
data.context = $('<div/>').appendTo('#files');
$.each(data.files, function (index, file) {
var node = $('<p/>').append($('<span/>').text(file.name));
if (!index) {
node
.append('<br>')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
if (file.preview) {
node
.prepend('<br>')
.prepend(file.preview);
}
if (file.error) {
node
.append('<br>')
.append($('<span class=\"text-danger\"/>').text(file.error));
}
if (index + 1 === data.files.length) {
data.context.find('button')
.text('Upload')
.prop('disabled', !!data.files.error);
}
}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
}).on('fileuploaddone', function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.url) {
var link = $('<a>')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index]).wrap(link);
} else if (file.error) {
var error = $('<span class=\"text-danger\"/>').text(file.error);
$(data.context.children()[index])
.append('<br>')
.append(error);
}
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('<span class=\"text-danger\"/>').text('File upload failed.');
$(data.context.children()[index])
.append('<br>')
.append(error);
});
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>";
$interbreadcrumb[] = array(
'url' => 'lp_controller.php?action=list?'.api_get_cidreq(),
'name' => get_lang('LearningPaths'),
);
$interbreadcrumb[] = array(
'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
'name' => $learnPath->get_name(),
);
switch ($type) {
case 'chapter':
$interbreadcrumb[] = array(
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(),
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
'name' => get_lang('NewStep'),
);
$interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewChapter'));
break;
case 'document':
$interbreadcrumb[] = array(
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(),
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
'name' => get_lang('NewStep'),
);
break;
@ -115,7 +231,7 @@ switch ($type) {
break;
}
if ($action == 'add_item' && $type == 'document' ) {
if ($action == 'add_item' && $type == 'document') {
$interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
}
@ -164,10 +280,9 @@ jQuery(document).ready(function(){
$(document).ready(function() {
$("#doc_form").removeClass( "col-md-8" ).addClass( "col-md-7" );
$("#hide_bar_template").click(function() {
$("#lp_sidebar").toggleClass("hide");
if ($('#doc_form').is('.col-md-7')) {
$('#doc_form').removeClass('col-md-7');
$('#doc_form').addClass('col-md-11');
@ -175,7 +290,7 @@ $(document).ready(function() {
$('#doc_form').removeClass('col-md-11');
$('#doc_form').addClass('col-md-7');
}
$("#hide_bar_template").toggleClass("hide_bar_template_not_hide");
});

Loading…
Cancel
Save