Fixing documents tool move functionality, replacing curdirpath in document list, adding more information and icons in the upload multiple files funcionality see BT#2784

skala
Julio Montoya 15 years ago
parent 52560c2e03
commit 9f8dbf8eeb
  1. 130
      main/document/document.inc.php
  2. 183
      main/document/document.php
  3. 89
      main/document/edit_document.php
  4. 34
      main/document/showinframes.php
  5. 27
      main/document/upload.php
  6. BIN
      main/img/icons/22/preview_view_na.png
  7. 16
      main/inc/ajax/document.ajax.php
  8. 69
      main/inc/lib/document.lib.php
  9. 20
      main/inc/lib/fileDisplay.lib.php
  10. 2
      main/inc/lib/javascript/jquery-ui/default.css
  11. 24
      main/inc/lib/main_api.lib.php

@ -98,14 +98,30 @@ function build_directory_selector($folders, $curdirpath, $group_dir = '', $chang
* @param int $show_as_icon - if it is true, only a clickable icon will be shown
* @return string url
*/
function create_document_link($www, $title, $path, $filetype, $size, $visibility, $show_as_icon = false) {
function create_document_link($document_data, $show_as_icon = false) {
global $dbl_click_id;
if (isset($_SESSION['_gid'])) {
$req_gid = '&gidReq='.$_SESSION['_gid'];
} else {
$req_gid = '';
}
$url_path = urlencode($path);
$course_info = api_get_course_info();
$www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document';
$use_document_title = api_get_setting('use_document_title');
// Get the title or the basename depending on what we're using
if ($use_document_title == 'true' && $id['title'] != '') {
$title = $document_data['title'];
} else {
$title = basename($document_data['title']);
}
$filetype = $document_data['filetype'];
$size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size'];
$visibility = $document_data['visibility'];
$path = $document_data['path'];
$url_path = urlencode($document_data['path']);
// Add class="invisible" on invisible files
$visibility_class = ($visibility == 0) ? ' class="invisible"' : '';
@ -127,10 +143,12 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility
// HTML-files an some other types are shown in a frameset by default.
$is_browser_viewable_file = is_browser_viewable($ext);
if ($is_browser_viewable_file) {
$url = 'showinframes.php?'.api_get_cidreq().'&file='.$url_path.$req_gid;
//$url = 'showinframes.php?'.api_get_cidreq().'&file='.$url_path.$req_gid;
$url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
} else {
// url-encode for problematic characters (we may not call them dangerous characters...)
$path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
//$new_path = '?id='.$document_data['id'];
$url = $www.$path;
}
// Disabled fragment of code, there is a special icon for opening in a new window.
@ -139,7 +157,8 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility
// $target = '_blank';
//}
} else {
$url = api_get_self().'?'.api_get_cidreq().'&curdirpath='.$url_path.$req_gid;
//$url = api_get_self().'?'.api_get_cidreq().'&curdirpath='.$url_path.$req_gid;
$url = api_get_self().'?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
}
// The little download icon
@ -150,45 +169,35 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility
$tooltip_title_alt = $tooltip_title;
if ($path == '/shared_folder') {
$tooltip_title_alt = get_lang('UserFolders');
}elseif(strstr($path, 'shared_folder_session_')) {
} elseif(strstr($path, 'shared_folder_session_')) {
$tooltip_title_alt = get_lang('UserFolders').' ('.api_get_session_name($current_session_id).')';
}elseif(strstr($tooltip_title, 'sf_user_')) {
} elseif(strstr($tooltip_title, 'sf_user_')) {
$userinfo = Database::get_user_info_from_id(substr($tooltip_title, 8));
$tooltip_title_alt = get_lang('UserFolder').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
}
elseif($path == '/chat_files') {
} elseif($path == '/chat_files') {
$tooltip_title_alt = get_lang('ChatFiles');
}
elseif($path == '/video') {
} elseif($path == '/video') {
$tooltip_title_alt = get_lang('Video');
}
elseif($path == '/audio') {
} elseif($path == '/audio') {
$tooltip_title_alt = get_lang('Audio');
}
elseif($path == '/flash') {
} elseif($path == '/flash') {
$tooltip_title_alt = get_lang('Flash');
}
elseif($path == '/images') {
} elseif($path == '/images') {
$tooltip_title_alt = get_lang('Images');
}
elseif($path == '/images/gallery') {
} elseif($path == '/images/gallery') {
$tooltip_title_alt = get_lang('DefaultCourseImages');
}
$current_session_id=api_get_session_id();
if (!$show_as_icon) {
if ($filetype == 'folder') {
if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') {
//filter when I am into shared folder, I can show for donwload only my shared folder
if(is_shared_folder($_GET['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())
{
if(is_shared_folder($_GET['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()) {
$force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),22).'</a>';
}
}
elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin())
{
} elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || 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(),22).'</a>';
}
}
@ -200,24 +209,20 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility
if(api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0){
$copy_myfiles_link = ($filetype == 'file') ? api_get_self().'?'.api_get_cidreq().'&curdirpath='.$_GET['curdirpath'].'&amp;action=copytomyfiles&amp;id='.$url_path.$req_gid :api_get_self().'?'.api_get_cidreq();
if($filetype == 'file')
{
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(),22).'&nbsp;&nbsp;</a>';
}
}
if ($is_browser_viewable_file) {
$open_in_new_window_link = '<a href="'.$www.str_replace('%2F', '/',$url_path).'?'.api_get_cidreq().'" style="float:right"'.$prevent_multiple_click.' target="_blank">'.Display::return_icon('open_in_new_window.png', get_lang('OpenInANewWindow'), array(),22).'&nbsp;&nbsp;</a>';
}
return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link;
//end copy files to users myfiles
}
else{
} else {
if(preg_match('/shared_folder/', urldecode($url)) && preg_match('/shared_folder$/', urldecode($url))==false && preg_match('/shared_folder_session_'.$current_session_id.'$/', urldecode($url))==false){
return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
}
else{
} else {
return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
}
}
@ -337,12 +342,23 @@ function build_document_icon_tag($type, $path) {
* @param int $id dbase id of the document
* @return string html img tags with hyperlinks
*/
function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_template, $is_read_only = 0, $session_id = 0) {
//function build_edit_icons($document_data, $curdirpath, $type, $path, $visibility, $id, $is_template, $is_read_only = 0, $session_id = 0) {
function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0, $session_id = 0) {
if (isset($_SESSION['_gid'])) {
$req_gid = '&amp;gidReq='.$_SESSION['_gid'];
} else {
$req_gid = '';
}
$document_id = $document_data['id'];
$type = $document_data['filetype'];
$path = $document_data['path'];
$parent_id = DocumentManager::get_document_id(api_get_course_info(), dirname($path));
$visibility= $document_data['visibility'];
$is_read_only= $document_data['readonly'];
$curdirpath = dirname($document_data['path']);
// Build URL-parameters for table-sorting
$sort_params = array();
if (isset($_GET['column'])) {
@ -372,20 +388,21 @@ function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_templ
$modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'),'',22);
$modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'),array(), 22);
$modify_icons .= '&nbsp;'.Display::return_icon('move.png', get_lang('Move'),array(), 22);
if(api_is_allowed_to_edit() || api_is_platform_admin()){
if (api_is_allowed_to_edit() || api_is_platform_admin()){
$modify_icons .= '&nbsp;'.Display::return_icon($visibility_icon.'_na.png', get_lang('VisibilityCannotBeChanged'),'',22);
}
} else {
if ($is_certificate_mode) {
$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'&selectcat='.$gradebook_category.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
//$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'&selectcat='.$gradebook_category.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'&selectcat='.$gradebook_category.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
} else {
if($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){
$modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
}
elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
} elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
$modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
}else{
$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
} else {
$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
}
}
@ -405,11 +422,11 @@ function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_templ
}
if ($is_certificate_mode) {
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;move='.urlencode($path).$req_gid.'&selectcat='.$gradebook_category.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'&amp;move='.$document_id.$req_gid.'&selectcat='.$gradebook_category.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;'.$visibility_command.'='.$id.$req_gid.'&amp;'.$sort_params.'&selectcat='.$gradebook_category.'">'.
Display::return_icon($visibility_icon.'.png', get_lang('Move'),array(), 22).'</a>';
} else {
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;move='.urlencode($path).$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'&amp;move='.$document_id.$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
if(api_is_allowed_to_edit() || api_is_platform_admin()){
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;'.$visibility_command.'='.$id.$req_gid.'&amp;'.$sort_params.'">'.Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),'',22).'</a>';
}
@ -441,10 +458,9 @@ function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_templ
}
}
}
}
else{
} else {
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;remove_as_template='.$id.$req_gid.'&amp;'.$sort_params.'">'.
Display::return_icon('preview_view_na.png', get_lang('RemoveAsTemplate'),'',22).'</a>';
Display::return_icon('wizard_na.png', get_lang('RemoveAsTemplate'),'',22).'</a>';
}
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$id.'">'.Display::return_icon('pdf.png', get_lang('Export2PDF'),array(), 22).'</a>';
}
@ -453,16 +469,17 @@ function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_templ
}
function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
$form = '<form name="move_to" action="'.api_get_self().'" method="post">'."\n";
$form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />'."\n";
$form = '<form name="move_to" action="'.api_get_self().'" method="post">';
$form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />';
$form .= '<div class="row">';
$form .= ' <div class="label">';
$form .= '<div class="label">';
$form .= get_lang('MoveTo');
$form .= ' </div>';
$form .= ' <div class="formw">';
$form .= '</div>';
$form .= '<div class="formw">';
$form .= ' <select name="move_to">'."\n";
$form .= '<select name="move_to">';
// Group documents cannot be uploaded in the root
if ($group_dir == '') {
@ -499,7 +516,7 @@ function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir =
if (api_get_setting('use_document_title')) {
$path_displayed = get_titles_of_path($folder);
}
$form .= '<option value="'.$folder.'">'.$path_displayed.'</option>'."\n";
$form .= '<option value="'.$folder.'">'.$path_displayed.'</option>';
}
}
}
@ -511,18 +528,19 @@ function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir =
}
$display_folder = substr($path_displayed,strlen($group_dir));
$display_folder = ($display_folder == '') ? get_lang('Documents') : $display_folder;
$form .= '<option value="'.$folder.'">'.$display_folder.'</option>'."\n";
$form .= '<option value="'.$folder.'">'.$display_folder.'</option>';
}
}
}
$form .= ' </select>'."\n";
$form .= ' </select>';
$form .= ' </div>';
$form .= ' </div>';
$form .= '<div class="row">';
$form .= ' <div class="label"></div>';
$form .= ' <div class="formw">';
$form .= ' <button type="submit" class="next" name="move_file_submit">'.get_lang('MoveElement').'</button>'."\n";
$form .= ' <button type="submit" class="next" name="move_file_submit">'.get_lang('MoveElement').'</button>';
$form .= ' </div>';
$form .= '</div>';

@ -67,6 +67,13 @@ if (isset($_GET['id_session'])) {
$course_id = api_get_course_id();
DocumentManager::create_directory_certificate_in_course($course_id);
//Hack in order to use document.php?id=X
if (isset($_GET['id'])) {
$document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id());
//@todo replace all
$_GET['curdirpath'] = $document_data['path'];
}
// Show preview
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(intval($_GET['set_preview']))) {
if (isset($_GET['set_preview'])) {
@ -109,8 +116,7 @@ if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $
$htmlHeadXtra[] =
"<script type=\"text/javascript\">
function confirmation (name)
{
function confirmation (name) {
if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
{return true;}
else
@ -157,7 +163,7 @@ if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
$group_member_with_upload_rights = false;
if ($group_properties['doc_state'] == 2) { // Documents are private
if ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members (members + tutors) allowed
if ($is_allowed_to_edit || GroupManager :: is_user_in_group(api_get_user_id(), $_SESSION['_gid'])) { // Only courseadmin or group members (members + tutors) allowed
$to_group_id = $_SESSION['_gid'];
$req_gid = '&amp;gidReq='.$_SESSION['_gid'];
$interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
@ -174,7 +180,7 @@ if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
$interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
//allowed to upload?
if ($is_allowed_to_edit || GroupManager::is_subscribed($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members can upload
if ($is_allowed_to_edit || GroupManager::is_subscribed(api_get_user_id(), $_SESSION['_gid'])) { // Only courseadmin or group members can upload
$group_member_with_upload_rights = true;
}
} else { // Documents not active for this group
@ -215,9 +221,11 @@ if ($to_group_id != 0 && $curdirpath == '/') {
// Check visibility of the current dir path. Don't show anything if not allowed
//@todo check this validation for coaches
//if (!$is_allowed_to_edit || api_is_coach()) { before
if (!$is_allowed_to_edit || api_is_coach()) {
if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $_course, api_get_session_id(),'folder'))) {
if (!$is_allowed_to_edit && api_is_coach()) {
if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $_course, api_get_session_id(),'folder'))) {
api_not_allowed();
}
}
@ -237,7 +245,7 @@ if($current_session_id==0){
$usf_dir_name = '/shared_folder';
$to_group_id = 0;
$visibility = 0;
create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
create_unexisting_directory($_course, api_get_user_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
// Create dynamic user shared folder
if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.api_get_user_id())) {
@ -245,17 +253,16 @@ if($current_session_id==0){
$usf_dir_name = '/shared_folder/sf_user_'.api_get_user_id();
$to_group_id = 0;
$visibility = 1;
create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
create_unexisting_directory($_course, api_get_user_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
}
else{
} else {
//Create shared folder session
if (!file_exists($base_work_dir.'/shared_folder_session_'.$current_session_id)) {
$usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($current_session_id).')';
$usf_dir_name = '/shared_folder_session_'.$current_session_id;
$to_group_id = 0;
$visibility = 0;
create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
create_unexisting_directory($_course, api_get_user_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
//Create dynamic user shared folder into a shared folder session
if (!file_exists($base_work_dir.'/shared_folder_session_'.$current_session_id.'/sf_user_'.api_get_user_id())) {
@ -263,7 +270,7 @@ else{
$usf_dir_name = '/shared_folder_session_'.$current_session_id.'/sf_user_'.api_get_user_id();
$to_group_id = 0;
$visibility = 1;
create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
create_unexisting_directory($_course, api_get_user_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
}
@ -293,7 +300,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'download') {
event_download($my_get_id);
// Check visibility of document and paths
if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible($my_get_id, $_course)) {
if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible($my_get_id, $_course, api_get_session_id())) {
api_not_allowed();
}
@ -312,14 +319,12 @@ if (isset($_GET['action']) && $_GET['action'] == 'downloadfolder' && (api_get_se
//filter when I am into shared folder, I can donwload only my shared folder
if(is_any_user_shared_folder($_GET['path'],$current_session_id)){
if(is_my_shared_folder($_user['user_id'], $_GET['path'], $current_session_id) || api_is_allowed_to_edit() || api_is_platform_admin()){
if(is_my_shared_folder(api_get_user_id(), $_GET['path'], $current_session_id) || api_is_allowed_to_edit() || api_is_platform_admin()){
require 'downloadfolder.inc.php';
}
}
else{
} else {
require 'downloadfolder.inc.php';
}
}
// Export to PDF
@ -358,43 +363,31 @@ if (!$is_certificate_mode) {
$dir_acum = '';
for ($i = 0; $i < $array_len; $i++) {
$url_dir = 'document.php?&amp;curdirpath='.$dir_acum.$dir_array[$i];
//Max char 80
$url_to_who = cut($dir_array[$i],80);
if ($is_certificate_mode) {
$interbreadcrumb[] = array('url' => $url_dir.'&amp;selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who);
}
else{
} else {
$interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
}
//does not repeat the name group in the url
if (!empty($_SESSION['_gid'])) {
unset($dir_array[1]);
}
$dir_acum .= $dir_array[$i].'/';
}
if (isset($_GET['createdir'])) {
$interbreadcrumb[] = array('url' => '', 'name' => get_lang('CreateDir'));
}
Display::display_header('','Doc');
// Lib for event log, stats & tracking & record of the access
event_access_tool(TOOL_DOCUMENT);
/* DISPLAY */
if ($to_group_id != 0) { // Add group name after for group documents
$add_group_to_title = ' ('.$group_properties['name'].')';
}
@ -429,16 +422,15 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
if (Security::remove_XSS($_GET['copy']) == 'yes'){
if (!copy($file, $copyfile)) {
Display::display_error_message(get_lang('CopyFailed'));
}else{
} else {
Display::display_confirmation_message(get_lang('OverwritenFile'));
}
}
}else{
} else {
if (!copy($file, $copyfile)) {
Display::display_error_message(get_lang('CopyFailed'));
}else{
Display::display_confirmation_message(get_lang('CopyMade'));
Display::display_error_message(get_lang('CopyFailed'));
} else {
Display::display_confirmation_message(get_lang('CopyMade'));
}
}
}
@ -447,27 +439,30 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
/* MOVE FILE OR DIRECTORY */
//Only teacher and all users into their group and each user into his/her shared folder
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) || is_my_shared_folder($_user['user_id'], Security::remove_XSS($_POST['move_to']), $current_session_id)){
$my_get_move = Security::remove_XSS($_GET['move']);
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id) || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($_POST['move_to']), $current_session_id)){
$my_get_move = intval($_REQUEST['move']);
if (isset($_GET['move']) && $_GET['move'] != '') {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($my_get_move, $_course,api_get_session_id())) {
if (!DocumentManager::is_visible_by_id($my_get_move, api_get_course_info(), api_get_session_id())) {
api_not_allowed();
}
}
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) {
if (DocumentManager::check_readonly($_course, api_get_user_id(), $my_get_move)) {
api_not_allowed();
}
}
if (DocumentManager::get_document_id($_course, $my_get_move)) {
$document_to_move = DocumentManager::get_document_data_by_id($my_get_move, api_get_course_id());
$move_path = $document_to_move['path'];
if (!empty($document_to_move)) {
$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights);
//filter if is my shared folder. TODO: move this code to build_move_to_selector function
if(is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) && !$is_allowed_to_edit){
if (is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id) && !$is_allowed_to_edit){
$main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id();//only main user shared folder
$main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//';//all subfolders
$user_shared_folders=array();
@ -477,38 +472,38 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
$user_shared_folders[]=$fold;
}
}
echo '<div class="row"><div class="form_header">'.get_lang('Move').'</div></div>';
echo build_move_to_selector($user_shared_folders, $move_path, $my_get_move, $group_properties['directory']);
} else {
echo '<div class="row"><div class="form_header">'.get_lang('Move').'</div></div>';
echo build_move_to_selector($user_shared_folders, Security::remove_XSS($_GET['curdirpath']), $my_get_move, $group_properties['directory']);
}
else{
echo '<div class="row"><div class="form_header">'.get_lang('Move').'</div></div>';
echo build_move_to_selector($folders, Security::remove_XSS($_GET['curdirpath']), $my_get_move, $group_properties['directory']);
echo build_move_to_selector($folders, $move_path, $my_get_move, $group_properties['directory']);
}
}
}
if (isset($_POST['move_to']) && isset($_POST['move_file'])) {
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) {
if (DocumentManager::check_readonly($_course, api_get_user_id(), $_POST['move_file'])) {
api_not_allowed();
}
}
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($my_get_move, $_course,api_get_session_id())) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($_POST['move_file'], $_course, api_get_session_id())) {
api_not_allowed();
}
}
$document_to_move = DocumentManager::get_document_data_by_id($_POST['move_file'], api_get_course_id());
require_once $lib_path.'fileManage.lib.php';
// This is needed for the update_db_info function
//$dbTable = $_course['dbNameGlu'].'document';
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
// Security fix: make sure they can't move files that are not in the document table
if (DocumentManager::get_document_id($_course, $_POST['move_file'])) {
if (move($base_work_dir.$_POST['move_file'], $base_work_dir.$_POST['move_to'])) {
update_db_info('update', $_POST['move_file'], $_POST['move_to'].'/'.basename($_POST['move_file']));
if (!empty($document_to_move)) {
if (move($base_work_dir.$document_to_move['path'], $base_work_dir.$_POST['move_to'])) {
update_db_info('update', $document_to_move['path'], $_POST['move_to'].'/'.basename($document_to_move['path']));
// Set the current path
$curdirpath = $_POST['move_to'];
$curdirpathurl = urlencode($_POST['move_to']);
@ -524,23 +519,20 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
/* DELETE FILE OR DIRECTORY */
//Only teacher and all users into their group
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)){
if (isset($_GET['delete'])) {
if (api_is_coach()) {
if (!DocumentManager::is_visible($_GET['delete'], $_course)) {
api_not_allowed();
}
}
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $_GET['delete'], '', true)) {
if (api_is_coach()) {
if (!DocumentManager::is_visible($_GET['delete'], $_course, api_get_session_id())) {
api_not_allowed();
}
}
if (DocumentManager::check_readonly($_course, api_get_user_id(), $_GET['delete'], '', true)) {
api_not_allowed();
}
}
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) {
if ( isset($_GET['delete_certificate_id']) && $_GET['delete_certificate_id'] == strval(intval($_GET['delete_certificate_id']))) {
$course_id = api_get_course_id();
@ -556,10 +548,9 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'delete':
foreach ($_POST['path'] as $index => & $path) {
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $path)) {
if (DocumentManager::check_readonly($_course, api_get_user_id(), $path)) {
Display::display_error_message(get_lang('CantDeleteReadonlyFiles'));
break 2;
}
@ -583,7 +574,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
/* CREATE DIRECTORY */
//Only teacher and all users into their group and any user into his/her shared folder
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)){
// Create directory with $_POST data
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
// Needed for directory creation
@ -601,7 +592,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
$dir_check = $base_work_dir.$dir_name;
if (!is_dir($dir_check)) {
$created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
$created_dir = create_unexisting_directory($_course, api_get_user_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
if ($created_dir) {
Display::display_confirmation_message('<span title="'.$created_dir.'">'.get_lang('DirCr').'</span>', false);
// Uncomment if you want to enter the created dir
@ -634,21 +625,20 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
$update_id = $_GET['set_invisible'];
$visibility_command = 'invisible';
}
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($update_id, $_course)) {
api_not_allowed();
}
}
if (!$is_allowed_to_edit) {
if(DocumentManager::check_readonly($_course, $_user['user_id'], '', $update_id)) {
if (!$is_allowed_to_edit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($update_id, $_course, api_get_session_id())) {
api_not_allowed();
}
}
if(DocumentManager::check_readonly($_course, api_get_user_id(), '', $update_id)) {
api_not_allowed();
}
}
// Update item_property to change visibility
if (api_item_property_update($_course, TOOL_DOCUMENT, $update_id, $visibility_command, $_user['user_id'], null, null, null, null, $current_session_id)) {
if (api_item_property_update($_course, TOOL_DOCUMENT, $update_id, $visibility_command, api_get_user_id(), null, null, null, null, $current_session_id)) {
Display::display_confirmation_message(get_lang('VisibilityChanged'));//don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all)
} else {
Display::display_error_message(get_lang('ViModProb'));
@ -658,7 +648,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_sett
/* TEMPLATE ACTION */
//Only teacher and all users into their group
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)){
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)){
if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
$document_id_for_template = intval($_GET['add_as_template']);
@ -822,12 +812,13 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
$invisibility_span_close = ($id['visibility'] == 0) ? '</span>' : '';
// Size (or total size of a directory)
$size = $id['filetype'] == 'folder' ? get_total_folder_size($id['path'], $is_allowed_to_edit) : $id['size'];
/*
// Get the title or the basename depending on what we're using
if ($use_document_title == 'true' && $id['title'] != '') {
$document_name = $id['title'];
} else {
$document_name = basename($id['path']);
}
}*/
// Data for checkbox
if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
$row[] = $id['path'];
@ -866,13 +857,13 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
// Icons (clickable)
//$row[]= build_document_icon_tag($id['filetype'],$id['path']);
$row[] = create_document_link($http_www, $document_name, $id['path'], $id['filetype'], $size, $id['visibility'], true);
$row[] = create_document_link($id, true);
// Validacion when belongs to a session
$session_img = api_get_session_image($id['session_id'], $_user['status']);
// Document title with hyperlink
$row[] = create_document_link($http_www, $document_name, $id['path'], $id['filetype'], $size, $id['visibility']).$session_img.'<br />'.$invisibility_span_open.nl2br(htmlspecialchars($id['comment'],ENT_QUOTES,$charset)).$invisibility_span_close.$user_link;
// Document title with hyperlink
$row[] = create_document_link($id).$session_img.'<br />'.$invisibility_span_open.nl2br(htmlspecialchars($id['comment'],ENT_QUOTES,$charset)).$invisibility_span_close.$user_link;
// Comments => display comment under the document name
//$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
@ -886,11 +877,11 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
$display_date = date_to_str_ago($last_edit_date);
$row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
// Admins get an edit column
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) {
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)) {
$is_template = isset($id['is_template']) ? $id['is_template'] : false;
// If readonly, check if it the owner of the file or if the user is an admin
if ($id['insert_user_id'] == $_user['user_id'] || api_is_platform_admin()) {
$edit_icons = build_edit_icons($curdirpath, $id['filetype'], $id['path'], $id['visibility'], $key, $is_template, 0);
if ($id['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
$edit_icons = build_edit_icons($id, $key, $is_template, 0);
} else {
$edit_icons = build_edit_icons($curdirpath, $id['filetype'], $id['path'], $id['visibility'], $key, $is_template, $id['readonly']);
}
@ -899,6 +890,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
$row[] = $last_edit_date;
$row[] = $size;
$total_size = $total_size + $size;
//@todo wtf is that?
if ((isset ($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
$sortable_data[] = $row;
}
@ -910,7 +902,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
$column_show = array();
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) {
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)) {
// TODO:check enable more options for shared folders
/* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
@ -981,7 +973,7 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
<?php
}
//Show disk quota
if (!$is_certificate_mode && !is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) {
if (!$is_certificate_mode && !is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)) {
?>
<a href="quota.php?<?php echo api_get_cidreq(); ?>">
<?php Display::display_icon('disk_quota.png', get_lang('ShowCourseQuotaUse'),'','32'); ?></a>
@ -996,7 +988,7 @@ if (!is_null($docs_and_folders)) {
if (!$is_certificate_mode && $total_size != 0 && (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin())) {
//for student does not show icon into other shared folder, and does not show into main path (root)
if (is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id) && $curdirpath!='/' || api_is_allowed_to_edit() || api_is_platform_admin()) {
if (is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id) && $curdirpath!='/' || api_is_allowed_to_edit() || api_is_platform_admin()) {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=downloadfolder&amp;path='.$curdirpathurl.'">'.Display::return_icon('save_pack.png', get_lang('Save').' (ZIP)','','32').'</a>';
}
@ -1023,7 +1015,7 @@ $column_show[] = 1;
$column_show[] = 1;
$column_show[] = 1;
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) {
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)) {
$column_show[] = 1;
}
$column_show[] = 0;
@ -1067,7 +1059,7 @@ $table->set_header($column++, get_lang('Name'));
$table->set_header($column++, get_lang('Size'),true,array ('style' => 'width:50px;'));
$table->set_header($column++, get_lang('Date'),true,array ('style' => 'width:150px;'));
// Admins get an edit column
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) {
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)) {
$table->set_header($column++, get_lang('Actions'), false,array ('style' => 'width:180px;'));
}
@ -1087,5 +1079,4 @@ if (!empty($table_footer)) {
}
// Footer
Display::display_footer()
?>
Display::display_footer();

@ -95,11 +95,25 @@ if (api_is_in_group()) {
$group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
}
$file = $_GET['file'];
//echo('file: '.$file.'<br />');
$doc = basename($file);
//echo('doc: '.$doc.'<br />');
$dir = Security::remove_XSS($_GET['curdirpath']);
if (isset($_GET['id'])) {
$document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id());
if (empty($document_data)) {
api_not_allowed();
}
$document_id = $document_data['id'];
$dir = dirname($document_data['path']);
$parent_id = DocumentManager::get_document_id(api_get_course_info(), $dir);
$dir_original = $dir;
$file = $document_data['path'];
$doc = basename($file);
$my_cur_dir_path = Security::remove_XSS($_GET['curdirpath']);
} else {
$dir = Security::remove_XSS($_GET['curdirpath']);
$dir_original = $dir;
$file = $_GET['file'];
$doc = basename($file);
}
//I'm in the certification module?
$is_certificate_mode = DocumentManager::is_certificate_mode($dir);
@ -183,7 +197,7 @@ if (!empty($_SESSION['_gid'])) {
$group_document = true;
$noPHP_SELF = true;
}
$my_cur_dir_path = Security::remove_XSS($_GET['curdirpath']);
if (!$is_certificate_mode)
$interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents'));
else
@ -327,8 +341,8 @@ if ($is_allowed_to_edit) {
if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) {
copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css', $filepath.'css/frames.css');
$doc_id = add_document($_course, $dir.'css/frames.css', 'file', filesize($filepath.'css/frames.css'), 'frames.css');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, $current_session_id);
}
}
@ -337,11 +351,15 @@ if ($is_allowed_to_edit) {
if ($document_id) {
$file_size = filesize($filepath.$filename.'.'.$extension);
update_existing_document($_course, $document_id, $file_size, $read_only_flag);
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'], null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', api_get_user_id(), null, null, null, null, $current_session_id);
// Update parent folders
item_property_update_on_folder($_course, $dir,$_user['user_id']);
$dir = substr($dir, 0, -1);
header('Location: document.php?curdirpath='.urlencode($dir));
item_property_update_on_folder($_course, $dir, api_get_user_id());
$dir_modified = substr($dir, 0, -1);
//header('Location: document.php?id='.urlencode($dir));
$my_id = DocumentManager::get_document_id($_course, $dir_modified);
header('Location: document.php?id='.$my_id);
exit ();
} else {
//$msgError = get_lang('Impossible');
@ -359,7 +377,6 @@ if ($is_allowed_to_edit) {
}
}
} else {
if (is_file($filepath.$filename.'.'.$extension)) {
$file_size = filesize($filepath.$filename.'.'.$extension);
$document_id = DocumentManager::get_document_id($_course, $file);
@ -433,10 +450,9 @@ $owner_id = $document_info['insert_user_id'];
$last_edit_date = $document_info['lastedit_date'];
if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'] )) {
$get_cur_path = Security::remove_XSS($_GET['curdirpath']);
$get_file = Security::remove_XSS($_GET['file']);
$action = api_get_self().'?sourceFile='.urlencode($file_name).'&curdirpath='.urlencode($get_cur_path).'&file='.urlencode($get_file).'&doc='.urlencode($doc);
if ($owner_id == api_get_user_id() || api_is_platform_admin() || $is_allowed_to_edit || GroupManager :: is_user_in_group(api_get_user_id(), api_get_group_id() )) {
$get_cur_path = $dir;
$action = api_get_self().'?sourceFile='.urlencode($file_name).'&id='.$document_data['id'];
$form = new FormValidator('formEdit', 'post', $action);
// Form title
@ -478,16 +494,13 @@ if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_
}
}
if (!$group_document && !is_my_shared_folder($_user['user_id'], $my_cur_dir_path, $current_session_id)) {
if (!$group_document && !is_my_shared_folder(api_get_user_id(), $my_cur_dir_path, $current_session_id)) {
$metadata_link = '<a href="../metadata/index.php?eid='.urlencode('Document.'.$docId).'">'.get_lang('AddMetadata').'</a>';
//Updated on field
$last_edit_date = api_get_local_time($last_edit_date, null, date_default_timezone_get());
$display_date = date_to_str_ago($last_edit_date).'<br /><span class="dropbox_date">'.api_format_date($last_edit_date).'</span>';
$display_date = date_to_str_ago($last_edit_date).'<br /><span class="dropbox_date">'.api_format_date($last_edit_date).'</span>';
$form->addElement('static', null, get_lang('Metadata'), $metadata_link);
$form->addElement('static', null, get_lang('UpdatedOn'), $display_date);
}
@ -495,7 +508,7 @@ if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_
/*
$renderer = $form->defaultRenderer();
*/
if ($owner_id == $_user['user_id'] || api_is_platform_admin()) {
if ($owner_id == api_get_user_id() || api_is_platform_admin()) {
$renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
$checked =& $form->addElement('checkbox', 'readonly', get_lang('ReadOnly'));
if ($readonly == 1) {
@ -508,8 +521,6 @@ if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_
else
$form->addElement('style_submit_button','submit',get_lang('SaveDocument'), 'class="save"');
$defaults['filename'] = $filename;
$defaults['extension'] = $extension;
$defaults['file_path'] = Security::remove_XSS($_GET['file']);
@ -524,7 +535,7 @@ if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_
/*
$form->addElement('html', '<div id="frmModel" style="display:block; height:525px; width:240px; position:absolute; top:115px; left:1px;"></div>');
*/
if (isset($_REQUEST['curdirpath']) && $_GET['curdirpath']=='/certificates') {
if (isset($_REQUEST['curdirpath']) && $dir =='/certificates') {
$all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate();
$str_info='';
foreach ($all_information_by_create_certificate[0] as $info_value) {
@ -532,10 +543,8 @@ if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_
}
$create_certificate=get_lang('CreateCertificateWithTags');
Display::display_normal_message($create_certificate.': <br /><br />'.$str_info,false);
}
show_return($call_from_tool, $slide_id, $is_certificate_mode);
///
}
show_return($parent_id, $dir_original, $call_from_tool, $slide_id, $is_certificate_mode);
if($extension=='svg' && !api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){
Display::display_warning_message(get_lang('BrowserDontSupportsSVG'));
}
@ -593,27 +602,21 @@ function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) {
}
//return button back to
function show_return($call_from_tool='', $slide_id=0, $is_certificate_mode=false) {
$path = Security::remove_XSS($_GET['curdirpath']);
function show_return($document_id, $path, $call_from_tool='', $slide_id=0, $is_certificate_mode=false) {
$pathurl = urlencode($path);
echo '<div class="actions">';
if ($is_certificate_mode)
{
if ($is_certificate_mode) {
echo '<a href="document.php?curdirpath='.Security::remove_XSS($_GET['curdirpath']).'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'','32').'</a>';
}
elseif($call_from_tool=='slideshow'){
} elseif($call_from_tool=='slideshow') {
echo '<a href="'.api_get_path(WEB_PATH).'main/document/slideshow.php?slide_id='.$slide_id.'&curdirpath='.Security::remove_XSS(urlencode($_GET['curdirpath'])).'">'.Display::return_icon('slideshow.png', get_lang('BackTo').' '.get_lang('ViewSlideshow'),'','32').'</a>';
}
elseif($call_from_tool=='editdraw'){
} elseif($call_from_tool=='editdraw') {
echo '<a href="document.php?action=exit_slideshow&curdirpath='.$pathurl.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'),'','32').'</a>';
echo '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png',get_lang('BackTo').' '.get_lang('Draw'),'','32').'</a>';
}
elseif($call_from_tool=='editpaint'){
} elseif($call_from_tool=='editpaint'){
echo '<a href="document.php?action=exit_slideshow&curdirpath='.$pathurl.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'),'','32').'</a>';
echo '<a href="javascript:history.back(1)">'.Display::return_icon('paint.png',get_lang('BackTo').' '.get_lang('Paint')).'</a>';
}
else{
echo '<a href="document.php?action=exit_slideshow&curdirpath='.$pathurl.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'),'','32').'</a>';
} else {
echo '<a href="document.php?action=exit_slideshow&id='.$document_id.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'),'','32').'</a>';
}
echo '</div>';
}

@ -27,27 +27,39 @@
$language_file[] = 'document';
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
require_once api_get_path(LIBRARY_PATH).'glossary.lib.php';
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
$noPHP_SELF = true;
$header_file = Security::remove_XSS($_GET['file']);
$path_array = explode('/', str_replace('\\', '/', $header_file));
$path_array = array_map('urldecode', $path_array);
$header_file = implode('/', $path_array);
$nameTools = $header_file;
$document_id = intval($_GET['id']);
//Generate path
if ($document_id) {
$course_code = api_get_course_id();
if (!empty($course_code)) {
$document_data = DocumentManager::get_document_data_by_id($document_id, $course_code);
$header_file = $document_data['path'];
$name_to_show = cut($document_data['title'],80);
}
} else {
$path_array = explode('/', str_replace('\\', '/', $header_file));
$path_array = array_map('urldecode', $path_array);
$header_file = implode('/', $path_array);
$nameTools = $header_file;
$name_to_show = cut($header_file, 80);
}
$name_to_show = cut($header_file, 80);
$current_group = GroupManager :: get_group_properties($_SESSION['_gid']);
$group_id = api_get_group_id();
$current_group = GroupManager :: get_group_properties($group_id);
$current_group_name=$current_group['name'];
if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
$req_gid = '&amp;gidReq='.$_SESSION['_gid'];
if (isset($group_id) && $group_id != '') {
$req_gid = '&amp;gidReq='.$group_id;
$interbreadcrumb[] = array ('url' => '../group/group.php?', 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' '.$current_group_name);
$interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace').' '.$current_group_name);
$name_to_show = explode('/', $name_to_show);
unset ($name_to_show[1]);
$name_to_show = implode('/', $name_to_show);

@ -82,8 +82,8 @@ $htmlHeadXtra[] = "
<script type=\"text/javascript\">
$(function () {
$('#file_upload').fileUploadUI({
uploadTable: $('#files'),
downloadTable: $('#files'),
uploadTable: $('.files'),
downloadTable: $('.files'),
buildUploadRow: function (files, index) {
return $('<tr><td>' + files[index].name + '<\/td>' +
'<td class=\"file_upload_progress\"><div><\/div><\/td>' +
@ -93,7 +93,7 @@ $(function () {
'<\/button><\/td><\/tr>');
},
buildDownloadRow: function (file) {
return $('<tr><td>' + file.name + '<\/td><\/tr>');
return $('<tr><td>' + file.name + '<\/td> <td>' + file.size + '<\/td> <td>' + file.result + '<\/td> <\/tr>');
}
});
$('#tabs').tabs();
@ -310,8 +310,7 @@ $form->addElement('radio', 'if_exists', '', get_lang('UplRenameLong'), 'rename')
// Close the java script and avoid the footer up
$form -> addElement('html', '</div>');
// Button send document
// Button upload document
$form->addElement('style_submit_button', 'submitDocument', get_lang('SendDocument'), 'class="upload"');
$form->add_real_progress_bar('DocumentUpload', 'user_upload');
@ -321,7 +320,20 @@ $form->setDefaults($defaults);
$simple_form = $form->return_form();
// Multiple uploads
echo '
<style>
.files {
border-collapse: collapse;
margin-top: 10px;
}
.files td {
padding: 3px 10px 3px 0;
}
</style>
';
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php';
$multiple_form = get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'<br />';
$multiple_form .= '<form id="file_upload" action="'.$url.'" method="POST" enctype="multipart/form-data">
@ -330,8 +342,9 @@ $multiple_form .= '<form id="file_upload" action="'.$url.'" method="POST" encty
<button>Upload</button>
<div>'.get_lang('UploadFiles').'</div>
</form>';
$multiple_form .='<table id="files"></table>';
$multiple_form .='<table class="files"></table>';
$headers = array(get_lang('Simple') , get_lang('Multiple'));
echo Display::tabs($headers, array($simple_form, $multiple_form ),'tabs');
// Footer
Display::display_footer();

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

@ -9,8 +9,18 @@ if (api_is_anonymous()){
}
if(!empty($_FILES)) {
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
DocumentManager::upload_document($_FILES, $_POST['curdirpath'], '', '', 0);
$file = $_FILES['file'];
echo '{"name":"'.$file['name'].'","type":"'.$file['type'].'","size":"'.$file['size'].'"}';
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
$result = DocumentManager::upload_document($_FILES, $_POST['curdirpath'], '', '', 0, 'overwrite');
$file = $_FILES['file'];
$json = array();
$json['name'] = Display::url(api_htmlentities($file['name']), $result['url'], array('target'=>'_blank'));
$json['type'] = api_htmlentities($file['type']);
$json['size'] = format_file_size($file['size']);
if (!empty($result) && is_array($result)) {
$json['result'] = Display::return_icon('accept.png', get_lang('Uploaded'));
} else {
$json['result'] = Display::return_icon('exclamation.png', get_lang('Error'));
}
echo json_encode($json);
}
exit;

@ -7,7 +7,6 @@
* and eliminate code duplication fro group documents, scorm documents, main documents.
* Include/require it in your code to use its functionality.
*
* @version 1.1, January 2005
* @package chamilo.library
*/
@ -999,10 +998,12 @@ class DocumentManager {
$course_info = api_get_course_info($course_code);
$TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
$id = intval($id);
$sql = "SELECT * FROM $TABLE_DOCUMENT WHERE id = $id";
$sql = "SELECT * FROM $TABLE_DOCUMENT WHERE id = $id ";
$result = Database::query($sql);
if ($result && Database::num_rows($result) == 1) {
$row = Database::fetch_array($result,'ASSOC');
$row = Database::fetch_array($result,'ASSOC');
//Public document URL
$row['url'] = api_get_path(WEB_CODE_PATH).'document/showinframes.php?cidReq'.$course_code.'&id='.$id;
return $row;
}
return false;
@ -1116,14 +1117,15 @@ class DocumentManager {
$propTable = Database::get_course_table(TABLE_ITEM_PROPERTY, $course['dbName']);
$id = intval($id);
$session_id = intval($session_id);
$condition = "AND id_session = $session_id";
//$condition = "AND id_session = $session_id";
$condition = "AND id_session IN ('$session_id', '0') ";
if (!in_array($file_type, array('file','folder'))) {
$file_type = 'file';
}
// The " d.filetype='file' " let the user see a file even if the folder is hidden see #2198
$sql = "SELECT path FROM $docTable d, $propTable ip " .
$sql = "SELECT visibility FROM $docTable d, $propTable ip " .
"WHERE d.id=ip.ref AND ip.tool='".TOOL_DOCUMENT."' $condition AND filetype='$file_type' AND d.id = $id";
$result = Database::query($sql);
$is_visible = false;
@ -1801,35 +1803,44 @@ class DocumentManager {
$pdf->html_to_pdf($file_path, $document_data['title'], $course_code);
}
/**
* Uploads a document
*
* @param $files
* @param $path
* @param $title
* @param $comment
* @param $unzip
* @param $if_exists overwrite, rename or warn if exists (default)
* @param $index_document
* @param $show_output
* @return unknown_type
*/
public function upload_document($files, $path, $title = '', $comment = '', $unzip = 0, $if_exists = '', $index_document = false, $show_output = false) {
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
//If we want to unzip a file, we need the library
if (isset($unzip) && $unzip == 1) {
if (isset($unzip) && intval($unzip) == 1) {
require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
}
}
$max_filled_space = self::get_course_quota();
$course_info = api_get_course_info();
$courseDir = $course_info['path'].'/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path.$courseDir;
$course_info = api_get_course_info();
$courseDir = $course_info['path'].'/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path.$courseDir;
if (isset($files['file'])) {
//echo('<pre>');
//echo('</pre>');
$upload_ok = process_uploaded_file($files['file']);
if ($upload_ok) {
// File got on the server without problems, now process it
$new_path = handle_uploaded_document($course_info, $files['file'], $base_work_dir, $path, api_get_user_id(), api_get_group_id(), null, $max_filled_space, $unzip, $if_exists, $show_output);
$new_comment = isset($title) ? trim($comment) : '';
$new_title = isset($title) ? trim($title) : '';
$new_title = isset($title) ? trim($title) : '';
$docid = DocumentManager::get_document_id($course_info, $new_path);
if ($new_path && ($new_comment || $new_title)) {
if (($docid = DocumentManager::get_document_id($course_info, $new_path))) {
if (!empty($docid)) {
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$ct = '';
if ($new_comment) $ct .= ", comment='$new_comment'";
@ -1837,12 +1848,14 @@ class DocumentManager {
Database::query("UPDATE $table_document SET ".substr($ct, 1)." WHERE id = $docid");
}
}
// Showing message when sending zip files
if ($new_path === true && $unzip == 1) {
//Display::display_confirmation_message(get_lang('UplUploadSucceeded').'<br />', false);
if ($new_path === true && $unzip == 1 && $show_output) {
Display::display_confirmation_message(get_lang('UplUploadSucceeded').'<br />', false);
}
if ((api_get_setting('search_enabled') == 'true') && ($docid = DocumentManager::get_document_id($course_info, $new_path))) {
//@todo move this code somewhere else a.k.a Rework search module
if ((api_get_setting('search_enabled') == 'true') && $index_document && !empty($docid)) {
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$result = Database::query("SELECT * FROM $table_document WHERE id = '$docid' LIMIT 1");
if (Database::num_rows($result) == 1) {
@ -1986,12 +1999,18 @@ class DocumentManager {
// Check for missing images in html files
$missing_files = check_for_missing_files($base_work_dir.$new_path);
if ($missing_files) {
if ($missing_files && $show_output) {
// Show a form to upload the missing files
//Display::display_normal_message(build_missing_files_form($missing_files, $path, $files['file']['name']), false);
Display::display_normal_message(build_missing_files_form($missing_files, $path, $files['file']['name']), false);
}
if (!empty($docid) && is_numeric($docid)) {
$document_data = self::get_document_data_by_id($docid, $course_info['code']);
return $document_data;
}
}
}
return false;
}
/**

@ -113,25 +113,17 @@ function choose_image($file_name)
* @param int Size of the file in bytes
* @return string A human readable representation of the file size
*/
function format_file_size($file_size)
{
if($file_size >= 1073741824)
{
function format_file_size($file_size) {
$file_size = intval($file_size);
if($file_size >= 1073741824) {
$file_size = round($file_size / 1073741824 * 100) / 100 . 'G';
}
elseif($file_size >= 1048576)
{
} elseif($file_size >= 1048576) {
$file_size = round($file_size / 1048576 * 100) / 100 . 'M';
}
elseif($file_size >= 1024)
{
} elseif($file_size >= 1024) {
$file_size = round($file_size / 1024 * 100) / 100 . 'k';
}
else
{
} else {
$file_size = $file_size . 'B';
}
return $file_size;
}

@ -1,5 +1,5 @@
/*
Custom changes for the jquery-ui
Custom changes for the jquery-ui see the readme file
*/
/* smoothness */

@ -1635,7 +1635,7 @@ function api_get_session_image($session_id, $status_id) {
$session_img = '';
if ((int)$status_id != 5) { //check whether is not a student
if ($session_id > 0) {
$session_img = "&nbsp;".Display::return_icon('star.png', get_lang('SessionSpecificResource'), array('align' => 'absmiddle'));
$session_img = "&nbsp;&nbsp;".Display::return_icon('star.png', get_lang('SessionSpecificResource'), array('align' => 'absmiddle'), 22);
}
}
return $session_img;
@ -4801,7 +4801,8 @@ function api_get_jquery_ui_js($include_jqgrid = false) {
}
/**
* Returns the jquery library js headers
* Returns the jquery library js and css headers
*
* @param array list of jquery libraries supported jquery-ui, jqgrid
* @param bool add the jquery library
* @return string html tags
@ -4816,15 +4817,16 @@ function api_get_jquery_libraries_js($libraries, $include_jquery = true) {
$js .= api_get_jquery_js();
}
if (in_array('jquery-ui',$libraries)) {
//jquery-ui js and css
if (in_array('jquery-ui', $libraries)) {
//Jquery ui
$theme = 'smoothness'; // Current themes: cupertino, smoothness, ui-lightness. Find the themes folder in main/inc/lib/javascript/jquery-ui
$js .= '<link rel="stylesheet" href="'.$js_path.'jquery-ui/'.$theme.'/jquery-ui-1.8.7.custom.css" type="text/css">';
$js .= '<script src="'.$js_path.'jquery-ui/'.$theme.'/jquery-ui-1.8.7.custom.min.js" type="text/javascript" language="javascript"></script>';
}
//Grid js
if (in_array('jqgrid',$libraries)) {
//jqgrid js and css
if (in_array('jqgrid', $libraries)) {
$languaje = 'en';
$platform_isocode = strtolower(api_get_language_isocode());
@ -4839,13 +4841,19 @@ function api_get_jquery_libraries_js($libraries, $include_jquery = true) {
$js .= '<script src="'.$js_path.'jqgrid/js/i18n/grid.locale-'.$languaje.'.js" type="text/javascript" language="javascript"></script>';
$js .= '<script src="'.$js_path.'jqgrid/js/jquery.jqGrid.min.js" type="text/javascript" language="javascript"></script>';
}
//Document multiple upload funcionality
if (in_array('jquery-upload',$libraries)) {
//Adding default CSS changes of the jquery-ui themes for Chamilo in order to preserve the original jquery-ui css
$js .= '<script src="'.$js_path.'jquery-upload/jquery.fileupload.js" type="text/javascript" language="javascript"></script>';
$js .= '<script src="'.$js_path.'jquery-upload/jquery.fileupload-ui.js" type="text/javascript" language="javascript"></script>';
$js .= '<link rel="stylesheet" href="'.$js_path.'jquery-upload/jquery.fileupload-ui.css" type="text/css">';
}
}
//jquery-ui css changes for Chamilo
if (in_array('jquery-ui',$libraries)) {
//Adding default CSS changes of the jquery-ui themes for Chamilo in order to preserve the original jquery-ui css
$js .= '<link rel="stylesheet" href="'.$js_path.'jquery-ui/default.css" type="text/css">';
}
return $js;
}

Loading…
Cancel
Save