Improve document render, load total size by ajax see BT#12052

pull/2487/head
jmontoyaa 8 years ago
parent b7b6a73ee4
commit 2ecb9f0bb0
  1. 49
      main/document/document.php
  2. 16
      main/inc/ajax/document.ajax.php
  3. 104
      main/inc/lib/document.lib.php

@ -1415,9 +1415,7 @@ if ($is_allowed_to_edit ||
DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
) {
if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
$document_id_for_template = intval($_GET['add_as_template']);
// Create the form that asks for the directory name
$templateForm .= '
<form name="set_document_as_new_template" class="form-horizontal" enctype="multipart/form-data" action="' . api_get_self() . '?add_as_template=' . $document_id_for_template . '" method="post">
@ -1446,7 +1444,6 @@ if ($is_allowed_to_edit ||
<hr>
';
} elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) {
$document_id_for_template = intval($_GET['add_as_template']);
$title = Security::remove_XSS($_POST['template_title']);
$user_id = api_get_user_id();
@ -1737,6 +1734,12 @@ $table_footer = '';
$total_size = 0;
$sortable_data = array();
$row = array();
$userIsSubscribed = CourseManager::is_user_subscribed_in_course(
api_get_user_id(),
$courseInfo['code']
);
if (isset($documentAndFolders) && is_array($documentAndFolders)) {
if ($groupId == 0 ||
GroupManager::user_has_access(
@ -1760,7 +1763,8 @@ if (isset($documentAndFolders) && is_array($documentAndFolders)) {
$courseInfo,
$sessionId,
api_get_user_id(),
false
false,
$userIsSubscribed
);
$invisibility_span_open = ($is_visible == 0) ? '<span class="muted">' : '';
@ -1799,6 +1803,7 @@ if (isset($documentAndFolders) && is_array($documentAndFolders)) {
// Icons (clickable)
$row[] = DocumentManager::create_document_link(
$document_data,
$courseInfo,
true,
$count,
$is_visible
@ -1815,9 +1820,16 @@ if (isset($documentAndFolders) && is_array($documentAndFolders)) {
// Validation when belongs to a session
$session_img = api_get_session_image($document_data['session_id'], $_user['status']);
$link = DocumentManager::create_document_link(
$document_data,
$courseInfo,
false,
null,
$is_visible
);
// Document title with link
$row[] = DocumentManager::create_document_link($document_data, false, null, $is_visible).
$session_img.'<br />'.$invisibility_span_open.
$row[] = $link.$session_img.'<br />'.$invisibility_span_open.
'<i>'.nl2br(htmlspecialchars($document_data['comment'], ENT_QUOTES, $charset)).'</i>'.
$invisibility_span_close.
$user_link;
@ -2060,22 +2072,21 @@ echo $dirForm;
echo $selector;
$table->display();
$ajaxURL = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=get_document_quota&'.api_get_cidreq();
if (count($documentAndFolders) > 1) {
if ($is_allowed_to_edit || $group_member_with_upload_rights) {
// Getting the course quota
$course_quota = DocumentManager::get_course_quota();
// Calculating the total space
$already_consumed_space_course = DocumentManager::documents_total_space(
api_get_course_int_id()
);
// Displaying the quota
DocumentManager::display_simple_quota(
$course_quota,
$already_consumed_space_course
);
echo '<script>
$(document).ready(function() {
$.ajax({
url:"'.$ajaxURL.'",
success:function(data){
$("#course_quota").html(data);
}
});
});
</script>';
echo '<span id="course_quota"></span>';
}
}
if (!empty($table_footer)) {

@ -8,6 +8,22 @@ require_once __DIR__.'/../global.inc.php';
$action = $_REQUEST['a'];
switch ($action) {
case 'get_document_quota':
// Getting the course quota
$course_quota = DocumentManager::get_course_quota();
// Calculating the total space
$already_consumed_space_course = DocumentManager::documents_total_space(
api_get_course_int_id()
);
// Displaying the quota
echo DocumentManager::display_simple_quota(
$course_quota,
$already_consumed_space_course
);
break;
case 'upload_file':
api_protect_course_script(true);
// User access same as upload.php

@ -1654,7 +1654,8 @@ class DocumentManager
$course_info,
$session_id,
$user_id,
$admins_can_see_everything = true
$admins_can_see_everything = true,
$userIsSubscribed = null
) {
$user_in_course = false;
@ -1671,12 +1672,18 @@ class DocumentManager
//2. Course and Session visibility are handle in local.inc.php/global.inc.php
//3. Checking if user exist in course/session
if ($session_id == 0) {
if (CourseManager::is_user_subscribed_in_course($user_id, $course_info['code']) || api_is_platform_admin()
) {
if (is_null($userIsSubscribed)) {
$userIsSubscribed = CourseManager::is_user_subscribed_in_course(
$user_id,
$course_info['code']
);
}
if ($userIsSubscribed === true || api_is_platform_admin()) {
$user_in_course = true;
}
// Check if course is open then we can consider that the student is registered to the course
if (isset($course_info) &&
in_array(
@ -1704,12 +1711,15 @@ class DocumentManager
}
// 4. Checking document visibility (i'm repeating the code in order to be more clear when reading ) - jm
if ($user_in_course) {
// 4.1 Checking document visibility for a Course
if ($session_id == 0) {
$item_info = api_get_item_property_info($course_info['real_id'], 'document', $doc_id, 0);
$item_info = api_get_item_property_info(
$course_info['real_id'],
'document',
$doc_id,
0
);
if (isset($item_info['visibility'])) {
// True for admins if document exists
@ -3163,7 +3173,8 @@ class DocumentManager
$percentage = round($percentage, 1);
$message = get_lang('YouAreCurrentlyUsingXOfYourX');
$message = sprintf($message, $already_consumed_space_m, $percentage . '%', $course_quota_m . ' ');
echo Display::div($message, array('id' => 'document_quota'));
return Display::div($message, array('id' => 'document_quota'));
}
/**
@ -5193,6 +5204,7 @@ class DocumentManager
* Create a html hyperlink depending on if it's a folder or a file
*
* @param array $document_data
* @param array $course_info
* @param int $show_as_icon - if it is true, only a clickable icon will be shown
* @param int $visibility (1/0)
* @param int $counter
@ -5201,14 +5213,17 @@ class DocumentManager
*/
public static function create_document_link(
$document_data,
$course_info,
$show_as_icon = false,
$counter = null,
$visibility
) {
global $dbl_click_id;
$course_info = api_get_course_info();
$current_session_id = api_get_session_id();
$www = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/document';
$webOdflist = DocumentManager::get_web_odf_extension_list();
$webODFList = DocumentManager::get_web_odf_extension_list();
$isAllowedToEdit = api_is_allowed_to_edit(null, true);
// Get the title or the basename depending on what we're using
if ($document_data['title'] != '') {
@ -5218,7 +5233,7 @@ class DocumentManager
}
$filetype = $document_data['filetype'];
$size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size'];
$size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], $isAllowedToEdit) : $document_data['size'];
$path = $document_data['path'];
$url_path = urlencode($document_data['path']);
@ -5250,7 +5265,7 @@ class DocumentManager
$is_browser_viewable_file = self::is_browser_viewable($ext);
if ($is_browser_viewable_file) {
if ($ext == 'pdf' || in_array($ext, $webOdflist)) {
if ($ext == 'pdf' || in_array($ext, $webODFList)) {
$url = api_get_self() . '?' . api_get_cidreq() . '&amp;action=download&amp;id=' . $document_data['id'];
} else {
$url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
@ -5291,16 +5306,14 @@ class DocumentManager
$tooltip_title_alt = get_lang('DefaultCourseImages');
}
$current_session_id = api_get_session_id();
$copy_to_myfiles = $open_in_new_window_link = null;
$curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
$send_to = null;
$checkExtension = $path;
if (!$show_as_icon) {
if ($filetype == 'folder') {
if (api_is_allowed_to_edit() ||
if ($isAllowedToEdit ||
api_is_platform_admin() ||
api_get_setting('students_download_folders') == 'true'
) {
@ -5308,13 +5321,13 @@ class DocumentManager
if (DocumentManager::is_shared_folder($curdirpath, $current_session_id)) {
if (preg_match('/shared_folder\/sf_user_' . api_get_user_id() . '$/', urldecode($forcedownload_link)) ||
preg_match('/shared_folder_session_' . $current_session_id . '\/sf_user_' . api_get_user_id() . '$/', urldecode($forcedownload_link)) ||
api_is_allowed_to_edit() || api_is_platform_admin()
$isAllowedToEdit || api_is_platform_admin()
) {
$force_download_html = ($size == 0) ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' .
Display::return_icon($forcedownload_icon, get_lang('Download'), array(), ICON_SIZE_SMALL) . '</a>';
}
} elseif (!preg_match('/shared_folder/', urldecode($forcedownload_link)) ||
api_is_allowed_to_edit() ||
$isAllowedToEdit ||
api_is_platform_admin()
) {
$force_download_html = ($size == 0) ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' .
@ -5332,7 +5345,6 @@ class DocumentManager
) {
$copy_myfiles_link = ($filetype == 'file') ? api_get_self() . '?' . api_get_cidreq() . '&action=copytomyfiles&id=' . $document_data['id'] : api_get_self() . '?' . api_get_cidreq();
if ($filetype == 'file') {
$copy_to_myfiles = '<a href="' . $copy_myfiles_link . '" style="float:right"' . $prevent_multiple_click . '>' .
Display::return_icon('briefcase.png', get_lang('CopyToMyFiles'), array(), ICON_SIZE_SMALL) . '&nbsp;&nbsp;</a>';
@ -5348,7 +5360,7 @@ class DocumentManager
$pdf_icon = '';
$extension = pathinfo($path, PATHINFO_EXTENSION);
if (!api_is_allowed_to_edit() &&
if (!$isAllowedToEdit &&
api_get_setting('students_export2pdf') == 'true' &&
$filetype == 'file' &&
in_array($extension, array('html', 'htm'))
@ -5403,7 +5415,7 @@ class DocumentManager
} else {
// For a "PDF Download" of the file.
$pdfPreview = null;
if ($ext != 'pdf' && !in_array($ext, $webOdflist)) {
if ($ext != 'pdf' && !in_array($ext, $webODFList)) {
$url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
} else {
$pdfPreview = Display::url(
@ -5447,16 +5459,16 @@ class DocumentManager
) {
$url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' .
DocumentManager::build_document_icon_tag($filetype, $path) .
DocumentManager::build_document_icon_tag($filetype, $path, $isAllowedToEdit) .
Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>';
} else {
return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' .
DocumentManager::build_document_icon_tag($filetype, $path) .
DocumentManager::build_document_icon_tag($filetype, $path, $isAllowedToEdit) .
Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>';
}
} else {
return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" target="' . $target . '"' . $visibility_class . ' style="float:left">' .
DocumentManager::build_document_icon_tag($filetype, $path) .
DocumentManager::build_document_icon_tag($filetype, $path, $isAllowedToEdit) .
Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>';
}
} else {
@ -5482,14 +5494,14 @@ class DocumentManager
) {
$url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id']; //without preview
return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' .
DocumentManager::build_document_icon_tag($filetype, $path) . '</a>';
DocumentManager::build_document_icon_tag($filetype, $path, $isAllowedToEdit) . '</a>';
} else {
return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' .
DocumentManager::build_document_icon_tag($filetype, $path) . '</a>';
DocumentManager::build_document_icon_tag($filetype, $path, $isAllowedToEdit) . '</a>';
}
} else {
return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" target="' . $target . '"' . $visibility_class . ' style="float:left">' .
DocumentManager::build_document_icon_tag($filetype, $path) . '</a>';
DocumentManager::build_document_icon_tag($filetype, $path, $isAllowedToEdit) . '</a>';
}
}
}
@ -5500,37 +5512,39 @@ class DocumentManager
*
* @param string $type (file/folder)
* @param string $path
* @param bool $isAllowedToEdit
* @return string img html tag
*/
public static function build_document_icon_tag($type, $path)
public static function build_document_icon_tag($type, $path, $isAllowedToEdit = null)
{
$basename = basename($path);
$current_session_id = api_get_session_id();
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
if (is_null($isAllowedToEdit)) {
$isAllowedToEdit = api_is_allowed_to_edit(null, true);
}
$user_image = false;
if ($type == 'file') {
$icon = choose_image($basename);
$basename = substr(strrchr($basename, '.'), 1);
} else {
if ($path == '/shared_folder') {
$icon = 'folder_users.png';
if ($is_allowed_to_edit) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpUsersFolder');
} else {
$basename = get_lang('UserFolders');
}
} elseif (strstr($basename, 'sf_user_')) {
$userinfo = api_get_user_info(substr($basename, 8));
$icon = $userinfo['avatar_small'];
$basename = get_lang('UserFolder') . ' ' . $userinfo['complete_name'];
$userInfo = api_get_user_info(substr($basename, 8));
$icon = $userInfo['avatar_small'];
$basename = get_lang('UserFolder') . ' ' . $userInfo['complete_name'];
$user_image = true;
} elseif (strstr($path, 'shared_folder_session_')) {
if ($is_allowed_to_edit) {
$basename = '***(' . api_get_session_name($current_session_id) . ')*** ' . get_lang('HelpUsersFolder');
$sessionName = api_get_session_name($current_session_id);
if ($isAllowedToEdit) {
$basename = '***(' . $sessionName . ')*** ' . get_lang('HelpUsersFolder');
} else {
$basename = get_lang('UserFolders') . ' (' . api_get_session_name($current_session_id) . ')';
$basename = get_lang('UserFolders') . ' (' . $sessionName . ')';
}
$icon = 'folder_users.png';
} else {
@ -5538,49 +5552,49 @@ class DocumentManager
if ($path == '/audio') {
$icon = 'folder_audio.gif';
if (api_is_allowed_to_edit()) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpDefaultDirDocuments');
} else {
$basename = get_lang('Audio');
}
} elseif ($path == '/flash') {
$icon = 'folder_flash.gif';
if (api_is_allowed_to_edit()) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpDefaultDirDocuments');
} else {
$basename = get_lang('Flash');
}
} elseif ($path == '/images') {
$icon = 'folder_images.gif';
if (api_is_allowed_to_edit()) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpDefaultDirDocuments');
} else {
$basename = get_lang('Images');
}
} elseif ($path == '/video') {
$icon = 'folder_video.gif';
if (api_is_allowed_to_edit()) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpDefaultDirDocuments');
} else {
$basename = get_lang('Video');
}
} elseif ($path == '/images/gallery') {
$icon = 'folder_gallery.gif';
if (api_is_allowed_to_edit()) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpDefaultDirDocuments');
} else {
$basename = get_lang('Gallery');
}
} elseif ($path == '/chat_files') {
$icon = 'folder_chat.png';
if (api_is_allowed_to_edit()) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpFolderChat');
} else {
$basename = get_lang('ChatFiles');
}
} elseif ($path == '/learning_path') {
$icon = 'folder_learningpath.gif';
if (api_is_allowed_to_edit()) {
if ($isAllowedToEdit) {
$basename = get_lang('HelpFolderLearningPaths');
} else {
$basename = get_lang('LearningPaths');
@ -5588,9 +5602,11 @@ class DocumentManager
}
}
}
if ($user_image) {
return Display::img($icon, $basename, array(), false);
}
return Display::return_icon($icon, $basename, array(), ICON_SIZE_MEDIUM);
}

Loading…
Cancel
Save