|
|
|
@ -17,108 +17,130 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
//many useful functions in main_api.lib.php, by default included |
|
|
|
//many useful functions in main_api.lib.php, by default included |
|
|
|
if(!function_exists('api_get_path')){header('location: upload.php');die;} |
|
|
|
if (!function_exists('api_get_path')) { |
|
|
|
|
|
|
|
header('location: upload.php'); |
|
|
|
|
|
|
|
die; |
|
|
|
|
|
|
|
} |
|
|
|
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; |
|
|
|
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; |
|
|
|
require_once api_get_path(LIBRARY_PATH) . 'document.lib.php'; |
|
|
|
require_once api_get_path(LIBRARY_PATH) . 'document.lib.php'; |
|
|
|
require_once '../document/document.inc.php'; |
|
|
|
require_once '../document/document.inc.php'; |
|
|
|
|
|
|
|
|
|
|
|
$courseDir = $_course['path']."/document"; |
|
|
|
$courseDir = $_course['path'] . "/document"; |
|
|
|
$sys_course_path = api_get_path(SYS_COURSE_PATH); |
|
|
|
$sys_course_path = api_get_path(SYS_COURSE_PATH); |
|
|
|
$base_work_dir = $sys_course_path.$courseDir; |
|
|
|
$base_work_dir = $sys_course_path . $courseDir; |
|
|
|
$noPHP_SELF=true; |
|
|
|
$noPHP_SELF = true; |
|
|
|
$max_filled_space = DocumentManager::get_course_quota(); |
|
|
|
$max_filled_space = DocumentManager::get_course_quota(); |
|
|
|
|
|
|
|
|
|
|
|
//what's the current path? |
|
|
|
//what's the current path? |
|
|
|
if(isset($_POST['curdirpath'])) { |
|
|
|
if (isset($_POST['curdirpath'])) { |
|
|
|
$path = $_POST['curdirpath']; |
|
|
|
$path = $_POST['curdirpath']; |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
$path = '/'; |
|
|
|
$path = '/'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check the path |
|
|
|
// Check the path |
|
|
|
// If the path is not found (no document id), set the path to / |
|
|
|
// If the path is not found (no document id), set the path to / |
|
|
|
if(!DocumentManager::get_document_id($_course,$path)) { $path = '/'; } |
|
|
|
if (!DocumentManager::get_document_id($_course, $path)) { |
|
|
|
|
|
|
|
$path = '/'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Header |
|
|
|
* Header |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
$nameTools = get_lang('UplUploadDocument'); |
|
|
|
$nameTools = get_lang('UplUploadDocument'); |
|
|
|
$interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($path).$req_gid, "name"=> $langDocuments); |
|
|
|
$interbreadcrumb[] = array( |
|
|
|
Display::display_header($nameTools,"Doc"); |
|
|
|
"url" => "./document.php?curdirpath=" . urlencode( |
|
|
|
|
|
|
|
$path |
|
|
|
|
|
|
|
) . $req_gid, |
|
|
|
|
|
|
|
"name" => $langDocuments |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
Display::display_header($nameTools, "Doc"); |
|
|
|
//show the title |
|
|
|
//show the title |
|
|
|
api_display_tool_title($nameTools.$add_group_to_title); |
|
|
|
api_display_tool_title($nameTools . $add_group_to_title); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Process |
|
|
|
* Process |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
//user has submitted a file |
|
|
|
//user has submitted a file |
|
|
|
if(isset($_FILES['user_upload'])) { |
|
|
|
if (isset($_FILES['user_upload'])) { |
|
|
|
$upload_ok = process_uploaded_file($_FILES['user_upload']); |
|
|
|
$upload_ok = process_uploaded_file($_FILES['user_upload']); |
|
|
|
if($upload_ok) { |
|
|
|
if ($upload_ok) { |
|
|
|
//file got on the server without problems, now process it |
|
|
|
//file got on the server without problems, now process it |
|
|
|
$new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$_POST['unzip'],$_POST['if_exists']); |
|
|
|
$new_path = handle_uploaded_document( |
|
|
|
|
|
|
|
$_course, |
|
|
|
|
|
|
|
$_FILES['user_upload'], |
|
|
|
|
|
|
|
$base_work_dir, |
|
|
|
|
|
|
|
$_POST['curdirpath'], |
|
|
|
|
|
|
|
$_user['user_id'], |
|
|
|
|
|
|
|
$to_group_id, |
|
|
|
|
|
|
|
$to_user_id, |
|
|
|
|
|
|
|
$_POST['unzip'], |
|
|
|
|
|
|
|
$_POST['if_exists'] |
|
|
|
|
|
|
|
); |
|
|
|
$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; |
|
|
|
$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; |
|
|
|
$new_title = isset($_POST['title']) ? trim($_POST['title']) : ''; |
|
|
|
$new_title = isset($_POST['title']) ? trim($_POST['title']) : ''; |
|
|
|
|
|
|
|
|
|
|
|
if ($new_path && ($new_comment || $new_title)) |
|
|
|
if ($new_path && ($new_comment || $new_title)) |
|
|
|
if (($docid = DocumentManager::get_document_id($_course, $new_path))) |
|
|
|
if (($docid = DocumentManager::get_document_id($_course, $new_path))) { |
|
|
|
{ |
|
|
|
|
|
|
|
$table_document = Database::get_course_table(TABLE_DOCUMENT); |
|
|
|
$table_document = Database::get_course_table(TABLE_DOCUMENT); |
|
|
|
$ct = ''; |
|
|
|
$ct = ''; |
|
|
|
if ($new_comment) $ct .= ", comment='$new_comment'"; |
|
|
|
if ($new_comment) $ct .= ", comment='$new_comment'"; |
|
|
|
if ($new_title) $ct .= ", title='$new_title'"; |
|
|
|
if ($new_title) $ct .= ", title='$new_title'"; |
|
|
|
Database::query("UPDATE $table_document SET" . substr($ct, 1) . |
|
|
|
Database::query("UPDATE $table_document SET" . substr($ct, 1) ." WHERE id = '$docid'"); |
|
|
|
" WHERE id = '$docid'"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//check for missing images in html files |
|
|
|
//check for missing images in html files |
|
|
|
$missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path); |
|
|
|
$missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path); |
|
|
|
if($missing_files) |
|
|
|
if ($missing_files) { |
|
|
|
{ |
|
|
|
|
|
|
|
//show a form to upload the missing files |
|
|
|
//show a form to upload the missing files |
|
|
|
Display::display_normal_message(build_missing_files_form($missing_files,$_POST['curdirpath'],$_FILES['user_upload']['name'])); |
|
|
|
Display::display_normal_message(build_missing_files_form($missing_files,$_POST['curdirpath'],$_FILES['user_upload']['name'])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//missing images are submitted |
|
|
|
//missing images are submitted |
|
|
|
if(isset($_POST['submit_image'])) { |
|
|
|
if (isset($_POST['submit_image'])) { |
|
|
|
$number_of_uploaded_images = count($_FILES['img_file']['name']); |
|
|
|
$number_of_uploaded_images = count($_FILES['img_file']['name']); |
|
|
|
//if images are uploaded |
|
|
|
//if images are uploaded |
|
|
|
if ($number_of_uploaded_images > 0) |
|
|
|
if ($number_of_uploaded_images > 0) { |
|
|
|
{ |
|
|
|
|
|
|
|
//we could also create a function for this, I'm not sure... |
|
|
|
//we could also create a function for this, I'm not sure... |
|
|
|
//create a directory for the missing files |
|
|
|
//create a directory for the missing files |
|
|
|
$img_directory = str_replace('.','_',$_POST['related_file']."_files"); |
|
|
|
$img_directory = str_replace('.','_',$_POST['related_file']."_files"); |
|
|
|
$missing_files_dir = create_unexisting_directory($_course,$_user['user_id'],api_get_session_id(), $to_group_id,$to_user_id,$base_work_dir,$img_directory); |
|
|
|
$missing_files_dir = create_unexisting_directory( |
|
|
|
|
|
|
|
$_course, |
|
|
|
|
|
|
|
$_user['user_id'], |
|
|
|
|
|
|
|
api_get_session_id(), |
|
|
|
|
|
|
|
$to_group_id, |
|
|
|
|
|
|
|
$to_user_id, |
|
|
|
|
|
|
|
$base_work_dir, |
|
|
|
|
|
|
|
$img_directory |
|
|
|
|
|
|
|
); |
|
|
|
//put the uploaded files in the new directory and get the paths |
|
|
|
//put the uploaded files in the new directory and get the paths |
|
|
|
$paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'],$base_work_dir,$missing_files_dir,$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space); |
|
|
|
$paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'],$base_work_dir,$missing_files_dir,$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space); |
|
|
|
//open the html file and replace the paths |
|
|
|
//open the html file and replace the paths |
|
|
|
replace_img_path_in_html_file($_POST['img_file_path'],$paths_to_replace_in_file,$base_work_dir.$_POST['related_file']); |
|
|
|
replace_img_path_in_html_file( |
|
|
|
|
|
|
|
$_POST['img_file_path'], |
|
|
|
|
|
|
|
$paths_to_replace_in_file, |
|
|
|
|
|
|
|
$base_work_dir . $_POST['related_file'] |
|
|
|
|
|
|
|
); |
|
|
|
//update parent folders |
|
|
|
//update parent folders |
|
|
|
item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']); |
|
|
|
item_property_update_on_folder($_course,$_POST['curdirpath'],$_user['user_id']); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//they want to create a directory |
|
|
|
//they want to create a directory |
|
|
|
if(isset($_POST['create_dir']) && $_POST['dirname']!='') |
|
|
|
if (isset($_POST['create_dir']) && $_POST['dirname']!='') { |
|
|
|
{ |
|
|
|
|
|
|
|
$added_slash = ($path=='/')?'':'/'; |
|
|
|
$added_slash = ($path=='/')?'':'/'; |
|
|
|
$dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']); |
|
|
|
$dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']); |
|
|
|
$created_dir = create_unexisting_directory($_course,$_user['user_id'],api_get_session_id(), $to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']); |
|
|
|
$created_dir = create_unexisting_directory($_course,$_user['user_id'],api_get_session_id(), $to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']); |
|
|
|
if($created_dir) |
|
|
|
if ($created_dir) { |
|
|
|
{ |
|
|
|
Display::display_normal_message(get_lang('DirCr')); |
|
|
|
//Display::display_normal_message("<strong>".$created_dir."</strong> was created!"); |
|
|
|
$path = $created_dir; |
|
|
|
Display::display_normal_message(get_lang('DirCr')); |
|
|
|
} else { |
|
|
|
$path = $created_dir; |
|
|
|
display_error(get_lang('CannotCreateDir')); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
display_error(get_lang('CannotCreateDir')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(isset($_GET['createdir'])) |
|
|
|
if (isset($_GET['createdir'])) { |
|
|
|
{ |
|
|
|
|
|
|
|
//create the form that asks for the directory name |
|
|
|
//create the form that asks for the directory name |
|
|
|
$new_folder_text = '<form action="'.api_get_self().'" method="POST">'; |
|
|
|
$new_folder_text = '<form action="'.api_get_self().'" method="POST">'; |
|
|
|
$new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>'; |
|
|
|
$new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>'; |
|
|
|
@ -128,11 +150,13 @@ if(isset($_GET['createdir'])) |
|
|
|
$new_folder_text .= '</form>'; |
|
|
|
$new_folder_text .= '</form>'; |
|
|
|
//show the form |
|
|
|
//show the form |
|
|
|
Display::display_normal_message($new_folder_text); |
|
|
|
Display::display_normal_message($new_folder_text); |
|
|
|
} |
|
|
|
} else { //give them a link to create a directory |
|
|
|
else { //give them a link to create a directory |
|
|
|
?> |
|
|
|
?> |
|
|
|
<p><a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&createdir=1"><img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" />
|
|
|
|
<p><a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&createdir=1"><img src="../img/new_folder.gif" border="0" align="absmiddle" alt ="" /> <?php echo(get_lang('CreateDir'));?></a></p>
|
|
|
|
<?php echo(get_lang('CreateDir'));?> |
|
|
|
<?php |
|
|
|
</a> |
|
|
|
|
|
|
|
</p> |
|
|
|
|
|
|
|
<?php |
|
|
|
} |
|
|
|
} |
|
|
|
?> |
|
|
|
?> |
|
|
|
|
|
|
|
|
|
|
|
|