When uploading a file now the default visibility depends of the portal and course settings.

1.9.x
Julio Montoya 12 years ago
parent 22d078b7a4
commit 30ca07b15c
  1. 105
      main/inc/lib/document.lib.php
  2. 42
      main/inc/lib/fileUpload.lib.php

@ -1057,14 +1057,10 @@ class DocumentManager {
$row['url'] = api_get_path(WEB_CODE_PATH) . 'document/showinframes.php?cidReq=' . $course_code . '&id=' . $id;
$row['document_url'] = api_get_path(WEB_CODE_PATH) . 'document/document.php?cidReq=' . $course_code . '&id=' . $id;
$row['absolute_path'] = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document' . $row['path'];
$row['absolute_path_from_document'] = '/document' . $row['path'];
$pathinfo = pathinfo($row['path']);
$row['absolute_parent_path'] = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document' . $pathinfo['dirname'] . '/';
$row['direct_url'] = $www . $path;
if (dirname($row['path']) == '.') {
@ -1092,12 +1088,6 @@ class DocumentManager {
if (!empty($parent_id)) {
$sub_document_data = self::get_document_data_by_id($parent_id, $course_code, false);
//@todo add visibility here
/* $sub_visibility = self::is_visible_by_id($parent_id, $course_info, api_get_session_id(), api_get_user_id());
if ($visibility && $sub_visibility == false) {
$visibility = false;
}
*/
$parents[] = $sub_document_data;
}
}
@ -2219,6 +2209,10 @@ class DocumentManager {
return $return;
}
/**
* @param int $document_id
* @param string $course_code
*/
public static function export_to_pdf($document_id, $course_code) {
require_once api_get_path(LIBRARY_PATH) . 'pdf.lib.php';
$course_data = api_get_course_info($course_code);
@ -2231,17 +2225,26 @@ class DocumentManager {
/**
* Uploads a document
*
* @param array the $_FILES variable
* @param string $path
* @param string title
* @param string comment
* @param int unzip or not the file
* @param int if_exists overwrite, rename or warn if exists (default)
* @param bool index document (search xapian module)
* @param bool print html messages
* @return unknown_type
* @param array $files the $_FILES variable
* @param string $path
* @param string $title
* @param string $comment
* @param int $unzip unzip or not the file
* @param int $if_exists if_exists overwrite, rename or warn if exists (default)
* @param bool $index_document index document (search xapian module)
* @param bool $show_output print html messages
* @return array|bool
*/
public static function upload_document($files, $path, $title = null, $comment = null, $unzip = 0, $if_exists = null, $index_document = false, $show_output = false) {
public static function upload_document(
$files,
$path,
$title = null,
$comment = null,
$unzip = 0,
$if_exists = null,
$index_document = false,
$show_output = false
) {
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
$course_info = api_get_course_info();
@ -2254,7 +2257,18 @@ class DocumentManager {
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, $unzip, $if_exists, $show_output);
$new_path = handle_uploaded_document(
$course_info,
$files['file'],
$base_work_dir,
$path,
api_get_user_id(),
api_get_group_id(),
null,
$unzip,
$if_exists,
$show_output
);
if ($new_path) {
$docid = DocumentManager::get_document_id($course_info, $new_path);
@ -2285,12 +2299,6 @@ class DocumentManager {
Display::display_confirmation_message(get_lang('UplUploadSucceeded') . '<br />', false);
}
/* // Check for missing images in html files
$missing_files = check_for_missing_files($base_work_dir.$new_path);
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);
} */
if ($index_document) {
self::index_document($docid, $course_info['code'], null, $_POST['language'], $_REQUEST, $if_exists);
}
@ -2956,6 +2964,13 @@ class DocumentManager {
return $return;
}
/**
* @param int $doc_id
* @param string $course_code
* @param int $session_id
* @param int $user_id
* @return bool
*/
public static function check_visibility_tree($doc_id, $course_code, $session_id, $user_id) {
$document_data = self::get_document_data_by_id($doc_id, $course_code);
@ -3180,10 +3195,18 @@ class DocumentManager {
return true;
}
/**
* @return array
*/
public static function get_web_odf_extension_list() {
return array('ods', 'odt');
}
/**
* @param $path
* @param bool $is_certificate_mode
* @return bool
*/
public static function is_folder_to_avoid($path, $is_certificate_mode = false) {
$folders_to_avoid = array(
'/HotPotatoes_files',
@ -3230,6 +3253,9 @@ class DocumentManager {
return in_array($path, $folders_to_avoid);
}
/**
* @return array
*/
static function get_system_folders() {
$system_folders = array(
'/certificates',
@ -3244,6 +3270,31 @@ class DocumentManager {
return $system_folders;
}
/**
* @param $courseCode
* @return string
*/
public static function getDocumentDefaultVisibility($courseCode)
{
$setting = api_get_setting('tool_visible_by_default_at_creation');
$courseVisibility = 'visible';
if (isset($setting[TOOL_DOCUMENT])) {
$portalDefaultVisibility = 'invisible';
if ($setting[TOOL_DOCUMENT] == 'true') {
$portalDefaultVisibility = 'visible';
}
$courseVisibility = $portalDefaultVisibility;
}
if (api_get_setting('documents_default_visibility_defined_in_course') == 'true') {
$courseVisibility = api_get_course_setting('documents_default_visibility', $courseCode);
}
return $courseVisibility;
}
}
//end class DocumentManager

@ -176,15 +176,28 @@ function process_uploaded_file($uploaded_file, $show_output = true) {
* @param boolean Optional output parameter. So far only use for unzip_uploaded_document function. If no output wanted on success, set to false.
* @return path of the saved file
*/
function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upload_path, $user_id, $to_group_id = 0, $to_user_id = null, $unzip = 0, $what_if_file_exists = '', $output = true) {
if (!$user_id) die('Not a valid user.');
function handle_uploaded_document(
$_course,
$uploaded_file,
$base_work_dir,
$upload_path,
$user_id,
$to_group_id = 0,
$to_user_id = null,
$unzip = 0,
$what_if_file_exists = '',
$output = true
) {
if (!$user_id) {
die('Not a valid user.');
}
// Strip slashes
$uploaded_file['name'] = stripslashes($uploaded_file['name']);
// Add extension to files without one (if possible)
$uploaded_file['name'] = add_ext_on_mime($uploaded_file['name'], $uploaded_file['type']);
$current_session_id = api_get_session_id();
//Just in case process_uploaded_file is not called
// Just in case process_uploaded_file is not called
$max_filled_space = DocumentManager::get_course_quota();
// Check if there is enough space to save the file
@ -211,22 +224,18 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
// No "dangerous" files
$clean_name = disable_dangerous_file($clean_name);
// Checking file extension
if (!filter_extension($clean_name)) {
if ($output) {
Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
}
return false;
} else {
// Extension is good
//echo '<br />clean name = '.$clean_name;
//echo '<br />upload_path = '.$upload_path;
// If the upload path differs from / (= root) it will need a slash at the end
if ($upload_path != '/') {
$upload_path = $upload_path.'/';
}
//echo '<br />upload_path = '.$upload_path;
$file_path = $upload_path.$clean_name;
//echo '<br />file path = '.$file_path;
// Full path to where we want to store the file with trailing slash
$where_to_save = $base_work_dir.$upload_path;
// At least if the directory doesn't exist, tell so
@ -236,10 +245,9 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
}
return false;
}
//echo '<br />where to save = '.$where_to_save;
// Full path of the destination
$store_path = $where_to_save.$clean_name;
//echo '<br />store path = '.$store_path;
// Name of the document without the extension (for the title)
$document_name = get_document_title($uploaded_file['name']);
// Size of the uploaded file (in bytes)
@ -260,13 +268,13 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
$document_id = DocumentManager::get_document_id($_course, $file_path);
if (is_numeric($document_id)) {
// Update filesize
// Update file size
update_existing_document($_course, $document_id, $uploaded_file['size']);
// Update document item_property
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $user_id, $to_group_id, $to_user_id, null, null, $current_session_id);
//Redo visibility
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $document_id);
}
// If the file is in a folder, we need to update all parent folders
@ -274,7 +282,7 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
// Display success message with extra info to user
if ($output) {
Display::display_confirmation_message(get_lang('UplUploadSucceeded').'<br />'.$file_path .' '. get_lang('UplFileOverwritten'), false);
}
}
return $file_path;
} else {
// Put the document data in the database
@ -282,6 +290,9 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
if ($document_id) {
// Put the document in item_property update
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $user_id, $to_group_id, $to_user_id, null, null, $current_session_id);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $document_id);
}
// If the file is in a folder, we need to update all parent folders
item_property_update_on_folder($_course, $upload_path, $user_id);
@ -314,6 +325,9 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
if ($document_id) {
// Update document item_property
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $user_id, $to_group_id, $to_user_id, null, null, $current_session_id);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $document_id);
}
// If the file is in a folder, we need to update all parent folders
item_property_update_on_folder($_course, $upload_path, $user_id);
@ -347,6 +361,8 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
if ($document_id) {
// Update document item_property
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $user_id, $to_group_id, $to_user_id, null, null, $current_session_id);
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $document_id);
}
// If the file is in a folder, we need to update all parent folders
item_property_update_on_folder($_course,$upload_path,$user_id);

Loading…
Cancel
Save