Moving function from fileDisplay.lib.php to fileManage.lib.php

skala
Julio Montoya 12 years ago
parent 6a4477262c
commit efc4ecaadf
  1. 2
      main/admin/class_import.php
  2. 3
      main/admin/class_list.php
  3. 35
      main/admin/special_exports.php
  4. 3
      main/admin/user_export.php
  5. 1
      main/admin/usergroup_user_import.php
  6. 1
      main/auth/profile.php
  7. 8
      main/coursecopy/classes/CourseArchiver.class.php
  8. 6
      main/coursecopy/classes/CourseRestorer.class.php
  9. 4
      main/document/document.inc.php
  10. 19
      main/document/document.php
  11. 216
      main/document/document_lite.php
  12. 6
      main/document/edit_document.php
  13. 2
      main/dropbox/dropbox_init.inc.php
  14. 2
      main/exercice/GC.php
  15. 12
      main/exercice/exercice.php
  16. 2
      main/exercice/export/exercise_import.inc.php
  17. 2
      main/exercice/hotpotatoes.lib.php
  18. 4
      main/exercice/hotpotatoes.php
  19. 2
      main/exercice/savescores.php
  20. 2
      main/exercice/showinframes.php
  21. 8
      main/inc/ajax/social.ajax.php
  22. 27
      main/inc/course_document.inc.php
  23. 1
      main/inc/global.inc.php
  24. 8
      main/inc/lib/document.lib.php
  25. 6
      main/inc/lib/fckeditor/editor/plugins/MP3/fck_mp3.php
  26. 8
      main/inc/lib/fckeditor/editor/plugins/ajaxfilemanager/ajax_file_paste.php
  27. 244
      main/inc/lib/fileDisplay.lib.php
  28. 893
      main/inc/lib/fileManage.lib.php
  29. 14
      main/inc/lib/formvalidator/FormValidator.class.php
  30. 2
      main/inc/lib/groupmanager.lib.php
  31. 9
      main/inc/lib/main_api.lib.php
  32. 2
      main/inc/lib/search/tool_processors/document_processor.class.php
  33. 1
      main/install/update-db-scorm-1.6.x-1.8.0.inc.php
  34. 6
      main/metadata/importmanifest.php
  35. 4
      main/newscorm/aicc.class.php
  36. 2
      main/newscorm/learnpath_functions.inc.php
  37. 12
      main/newscorm/resourcelinker.inc.php
  38. 4
      main/newscorm/scorm.class.php
  39. 8
      main/resourcelinker/resourcelinker.inc.php
  40. 4
      main/work/work.lib.php
  41. 6
      main/work/work.php
  42. 61
      tests/main/inc/lib/fileDisplay.lib.test.php
  43. 28
      tests/main/inc/lib/fileManage.lib.test.php
  44. 28
      tests/main/inc/lib/fileManager.lib.test.php

@ -54,8 +54,6 @@ $cidReset = true;
// Including some necessary dokeos files.
include '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'import.lib.php';
// Setting the section (for the tabs).

@ -69,9 +69,6 @@ function modify_filter($class_id) {
return $result;
}
require api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require api_get_path(LIBRARY_PATH).'classmanager.lib.php';
$tool_name = get_lang('ClassList');
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));

@ -3,7 +3,7 @@
/**
* Special exports
*
* @author Jhon Hinojosa
* @author Jhon Hinojosa
* @author Julio Montoya Fixing pclzip folder + some clean <gugli100@gmail.com>
* @package chamilo.include.export
*/
@ -24,7 +24,6 @@ $nameTools = get_lang('SpecialExports');
// include additional libraries
require_once '../document/document.inc.php';
// include additional libraries
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once '../coursecopy/classes/CourseBuilder.class.php';
require_once '../coursecopy/classes/CourseArchiver.class.php';
require_once '../coursecopy/classes/CourseRestorer.class.php';
@ -50,30 +49,30 @@ $error =0;
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) {
if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) {
$export = false;
if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
$FileZip = create_zip();
$to_group_id = 0;
$to_group_id = 0;
$sql_session = "SELECT id, name FROM $tbl_session ";
$query_session = Database::query($sql_session);
$ListSession = array();
while ($rows_session = Database::fetch_assoc($query_session)) {
$ListSession[$rows_session['id']] = $rows_session['name'];
}
$zip_folder=new PclZip($FileZip['TEMP_FILE_ZIP']);
if(!isset($_POST['resource']) || count($_POST['resource']) == 0 ) {
Display::display_error_message(get_lang('ErrorMsgSpecialExport'));
} else {
$Resource = $_POST['resource'];
foreach ($Resource as $Code_course => $Sessions) {
$_course = Database::get_course_info($Code_course);
$_course = Database::get_course_info($Code_course);
$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course_id = $_course['real_id'];
//Add item to the zip file course
$sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props
WHERE props.tool='".TOOL_DOCUMENT."'
@ -82,7 +81,7 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
AND docs.filetype='file'
AND docs.session_id = '0'
AND props.visibility<>'2'
AND props.to_group_id= $to_group_id AND docs.c_id = $course_id AND props.c_id = $course_id";
AND props.to_group_id= $to_group_id AND docs.c_id = $course_id AND props.c_id = $course_id";
$query = Database::query($sql );
while ($rows_course_file = Database::fetch_assoc($query)) {
$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'],
@ -90,7 +89,7 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory']."/document".$FileZip['PATH_REMOVE']
);
}
foreach ($Sessions as $IdSession => $value){
$session_id = Security::remove_XSS($IdSession);
//Add tem to the zip file session course
@ -129,8 +128,8 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
}
if ($export && $name) {
Display::display_confirmation_message(get_lang('BackupCreated'));
echo '<br /><a class="btn" href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.urlencode($name).'&session=true">'.get_lang('Download').'</a>';
Display::display_confirmation_message(get_lang('BackupCreated'));
echo '<br /><a class="btn" href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.urlencode($name).'&session=true">'.get_lang('Download').'</a>';
} else {
// Display forms especial export
if (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
@ -168,7 +167,7 @@ function form_special_export() {
function create_zip(){
$path = '';
if(empty($path)) { $path='/'; }
$remove_dir = ($path!='/') ? substr($path,0,strlen($path) - strlen(basename($path))) : '/';
$remove_dir = ($path!='/') ? substr($path,0,strlen($path) - strlen(basename($path))) : '/';
$sys_archive_path = api_get_path(SYS_ARCHIVE_PATH);
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$temp_zip_dir = $sys_archive_path."temp";
@ -211,11 +210,11 @@ function fullexportspecial(){
$list_course = array();
$zip_folder = new PclZip($FileZip['TEMP_FILE_ZIP']);
$list_course = Database::get_course_list();
$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
if (count($list_course) >0 ) {
foreach($list_course as $_course) {
if($FileZip['PATH'] == '/') {
@ -223,8 +222,8 @@ function fullexportspecial(){
} else {
$querypath = $FileZip['PATH'];
}
$course_id = $_course['real_id'];
$course_id = $_course['real_id'];
//Add tem to the zip file course
$sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props
WHERE props.tool='".TOOL_DOCUMENT."'

@ -15,7 +15,6 @@ require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
// Database table definitions
@ -94,7 +93,7 @@ if ($form->validate()) {
$sql .= " FROM $user_table u ORDER BY lastname,firstname";
}
$filename = 'export_users_'.date('Y-m-d_H-i-s');
}
}
$data = array();
$extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC',false);
if ($export['addcsvheader']=='1' AND $export['file_type']=='csv') {

@ -129,7 +129,6 @@ require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'import.lib.php';
$tool_name = get_lang('AddUsersToAClass') . ' CSV';

@ -96,7 +96,6 @@ EOF;
require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
// Libraries
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile');

@ -91,7 +91,7 @@ class CourseArchiver {
foreach ($course->resources[RESOURCE_SCORM] as $id => $document) {
$doc_dir = dirname($backup_dir . $document->path);
@mkdir($doc_dir, $perm_dirs, true);
copyDirTo($course->path . $document->path, $doc_dir, false);
FileManager::copyDirTo($course->path . $document->path, $doc_dir, false);
}
}
@ -100,14 +100,14 @@ class CourseArchiver {
if (is_array($course->resources[RESOURCE_EVENT])) {
$doc_dir = dirname($backup_dir . '/upload/calendar/');
@mkdir($doc_dir, $perm_dirs, true);
copyDirTo($course->path . 'upload/calendar/', $doc_dir, false);
FileManager::copyDirTo($course->path . 'upload/calendar/', $doc_dir, false);
}
//Copy learningpath author image
if (is_array($course->resources[RESOURCE_LEARNPATH])) {
$doc_dir = dirname($backup_dir . '/upload/learning_path/');
@mkdir($doc_dir, $perm_dirs, true);
copyDirTo($course->path . 'upload/learning_path/', $doc_dir, false);
FileManager::copyDirTo($course->path . 'upload/learning_path/', $doc_dir, false);
}
//Copy announcements attachments
@ -115,7 +115,7 @@ class CourseArchiver {
if (is_array($course->resources[RESOURCE_ANNOUNCEMENT])) {
$doc_dir = dirname($backup_dir . '/upload/announcements/');
@mkdir($doc_dir, $perm_dirs, true);
copyDirTo($course->path . 'upload/announcements/', $doc_dir, false);
FileManager::copyDirTo($course->path . 'upload/announcements/', $doc_dir, false);
}
// Zip the course-contents

@ -663,7 +663,7 @@ class CourseRestorer
switch ($this->file_option) {
case FILE_OVERWRITE :
rmdirr($path.$document->path);
copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false);
FileManager::copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false);
break;
case FILE_SKIP :
@ -692,14 +692,14 @@ class CourseRestorer
}
rename($this->course->backup_path.'/'.$document->path, $this->course->backup_path.'/'.$new_file_name);
copyDirTo($this->course->backup_path.'/'.$new_file_name, $path.dirname($new_file_name), false);
FileManager::copyDirTo($this->course->backup_path.'/'.$new_file_name, $path.dirname($new_file_name), false);
rename($this->course->backup_path.'/'.$new_file_name, $this->course->backup_path.'/'.$document->path);
break;
} // end switch
} // end if file exists
else {
copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false);
FileManager::copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false);
}
} // end for each
}

@ -121,7 +121,7 @@ function create_document_link($document_data, $show_as_icon = false, $counter =
}
$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' ? FileManager::get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size'];
$path = $document_data['path'];
$url_path = urlencode($document_data['path']);
@ -363,7 +363,7 @@ function build_document_icon_tag($type, $path)
$current_session_id = api_get_session_id();
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
if ($type == 'file') {
$icon = choose_image($basename);
$icon = FileManager::choose_image($basename);
if (preg_match('/_chnano_.wav$/i', $basename)) {
$icon = "jplayer_play.png";

@ -45,18 +45,7 @@ require_once $lib_path . 'fileDisplay.lib.php';
require_once $lib_path . 'fileManage.lib.php';
api_protect_course_script(true);
/*
Testing time labels
$now = api_get_utc_datetime();
var_dump(api_convert_and_format_date($now, TIME_NO_SEC_FORMAT));
var_dump(api_convert_and_format_date($now, DATE_FORMAT_SHORT));
var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG));
var_dump(api_convert_and_format_date($now, DATE_FORMAT_NUMBER));
var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG_24H));
var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_SHORT));
var_dump(api_convert_and_format_date($now, DATE_TIME_FORMAT_SHORT_TIME_FIRST));
var_dump(api_convert_and_format_date($now, DATE_FORMAT_NUMBER_NO_YEAR));
*/
//erase temp nanogons' audio, image edit
if(isset($_SESSION['temp_audio_nanogong']) && !empty($_SESSION['temp_audio_nanogong'])) {
unlink($_SESSION['temp_audio_nanogong']);
@ -613,8 +602,8 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
if (file_exists($real_path_target)) {
$fileExist = true;
}
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']));
if (FileManager::move($base_work_dir . $document_to_move['path'], $base_work_dir . $_POST['move_to'])) {
FileManager::update_db_info('update', $document_to_move['path'], $_POST['move_to'] . '/' . basename($document_to_move['path']));
//update database item property
$doc_id = $_POST['move_file'];
@ -1035,7 +1024,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
$invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
// Size (or total size of a directory)
$size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
$size = $document_data['filetype'] == 'folder' ? FileManager::get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
// Get the title or the basename depending on what we're using
if ($document_data['title'] != '') {

@ -57,7 +57,7 @@ if (api_get_session_id() != 0) {
$document_id = intval($_REQUEST['id']);
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
switch ($action) {
case 'download':
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
@ -81,23 +81,23 @@ switch ($action) {
// Check visibility of document and paths
if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id())) {
api_not_allowed(true);
}
}
$full_file_name = $base_work_dir.$document_data['path'];
if (Security::check_abs_path($full_file_name, $base_work_dir.'/')) {
DocumentManager::file_send_for_download($full_file_name, true);
}
exit;
break;
case 'downloadfolder' :
break;
case 'downloadfolder' :
if (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin()) {
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
//filter when I am into shared folder, I can donwload only my shared folder
if (is_any_user_shared_folder($document_data['path'], $session_id)) {
if (is_any_user_shared_folder($document_data['path'], $session_id)) {
if (is_my_shared_folder(api_get_user_id(), $document_data['path'], $session_id) || api_is_allowed_to_edit() || api_is_platform_admin()){
require 'downloadfolder.inc.php';
}
} else {
} else {
require 'downloadfolder.inc.php';
}
exit;
@ -106,22 +106,22 @@ switch ($action) {
}
//If no actions we proceed to show the document (Hack in order to use document.php?id=X)
//If no actions we proceed to show the document (Hack in order to use document.php?id=X)
if (isset($document_id)) {
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
//If the document is not a folder we show the document
if ($document_data) {
$parent_id = $document_data['parent_id'];
//$visibility = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
$visibility = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') {
if ($visibility && api_is_allowed_to_session_edit()) {
$url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq();
if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') {
if ($visibility && api_is_allowed_to_session_edit()) {
$url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq();
header("Location: $url");
}
}
exit;
} else {
if (!$visibility && !api_is_allowed_to_edit()) {
@ -130,7 +130,7 @@ if (isset($document_id)) {
}
$_GET['curdirpath'] = $document_data['path'];
}
// What's the current path?
// We will verify this a bit further down
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
@ -139,9 +139,9 @@ if (isset($document_id)) {
$curdirpath = Security::remove_XSS($_POST['curdirpath']);
} else {
$curdirpath = '/';
}
}
$curdirpathurl = urlencode($curdirpath);
} else {
// What's the current path?
// We will verify this a bit further down
@ -152,19 +152,19 @@ if (isset($document_id)) {
} else {
$curdirpath = '/';
}
$curdirpathurl = urlencode($curdirpath);
// Check the path
// If the path is not found (no document id), set the path to /
$document_id = DocumentManager::get_document_id($course_info, $curdirpath);
if (!$document_id) {
$document_id = DocumentManager::get_document_id($course_info, $curdirpath);
}
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
$parent_id = $document_data['parent_id'];
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
$parent_id = $document_data['parent_id'];
}
$current_folder_id = $document_id;
@ -203,7 +203,7 @@ if ($to_group_id != 0 && $curdirpath == '/') {
//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 ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $_course, api_get_session_id(),'folder'))) {
api_not_allowed(true);
}
}
@ -231,12 +231,12 @@ if ($is_certificate_mode) {
// Interbreadcrumb for the current directory root path
if (empty($document_data['parents'])) {
if (isset($_GET['createdir'])) {
if (isset($_GET['createdir'])) {
$interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']);
} else {
$interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
}
} else {
}
} else {
foreach($document_data['parents'] as $document_sub_data) {
if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
$document_sub_data['document_url'] = '#';
@ -258,37 +258,37 @@ $file_list = $format_list = '';
$count = 1;
if (!empty($docs_and_folders))
foreach ($docs_and_folders as $file) {
foreach ($docs_and_folders as $file) {
if ($file['filetype'] == 'file') {
$path_info = pathinfo($file['path']);
$path_info = pathinfo($file['path']);
$extension = strtolower($path_info['extension']);
//@todo use a js loop to autogenerate this code
if (in_array($extension, array('ogg', 'mp3', 'wav'))) {
$document_data = DocumentManager::get_document_data_by_id($file['id'], api_get_course_id());
if ($extension == 'ogg') {
$extension = 'oga';
}
$jquery .= ' $("#jquery_jplayer_'.$count.'").jPlayer({
ready: function() {
$(this).jPlayer("setMedia", {
'.$extension.' : "'.$document_data['direct_url'].'"
}
$jquery .= ' $("#jquery_jplayer_'.$count.'").jPlayer({
ready: function() {
$(this).jPlayer("setMedia", {
'.$extension.' : "'.$document_data['direct_url'].'"
});
},
},
swfPath: "'.$js_path.'jquery-jplayer",
supplied: "mp3, m4a, oga, ogv, wav",
solution: "flash, html", // Do not change this setting otherwise
cssSelectorAncestor: "#jp_interface_'.$count.'",
supplied: "mp3, m4a, oga, ogv, wav",
solution: "flash, html", // Do not change this setting otherwise
cssSelectorAncestor: "#jp_interface_'.$count.'",
});'."\n\n";
$count++;
}
$count++;
}
}
}
$htmlHeadXtra[] = '<script type="text/javascript">
$(document).ready( function() {
//Experimental changes to preview mp3, ogg files
'.$jquery.'
//Experimental changes to preview mp3, ogg files
'.$jquery.'
//Keep this down otherwise the jquery player will not work
for (i=0;i<$(".actions").length;i++) {
if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
@ -356,24 +356,24 @@ 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(api_get_user_id(), $curdirpath, $session_id) || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($_POST['move_to']), $session_id)) {
if (isset($_GET['move']) && $_GET['move'] != '') {
$my_get_move = intval($_REQUEST['move']);
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($my_get_move, $course_info, api_get_session_id(), api_get_user_id())) {
if (!DocumentManager::is_visible_by_id($my_get_move, $course_info, api_get_session_id(), api_get_user_id())) {
api_not_allowed();
}
}
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, api_get_user_id(), $my_get_move)) {
if (DocumentManager::check_readonly($_course, api_get_user_id(), $my_get_move)) {
api_not_allowed();
}
}
$document_to_move = DocumentManager::get_document_data_by_id($my_get_move, api_get_course_id());
$move_path = $document_to_move['path'];
$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);
@ -388,10 +388,10 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
$user_shared_folders[]=$fold;
}
}
echo '<legend>'.get_lang('Move').'</legend>';
echo '<legend>'.get_lang('Move').'</legend>';
echo build_move_to_selector($user_shared_folders, $move_path, $my_get_move, $group_properties['directory']);
} else {
echo '<legend>'.get_lang('Move').'</legend>';
echo build_move_to_selector($folders, $move_path, $my_get_move, $group_properties['directory']);
}
@ -399,35 +399,35 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
}
if (isset($_POST['move_to']) && isset($_POST['move_file'])) {
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, api_get_user_id(), $_POST['move_file'])) {
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($_POST['move_file'], $_course, api_get_session_id(), api_get_user_id())) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($_POST['move_file'], $_course, api_get_session_id(), api_get_user_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';
$document_to_move = DocumentManager::get_document_data_by_id($_POST['move_file'], api_get_course_id());
require_once $lib_path.'fileManage.lib.php';
// Security fix: make sure they can't move files that are not in the document table
if (!empty($document_to_move)) {
$real_path_target = $base_work_dir.$_POST['move_to'].'/'.basename($document_to_move['path']);
$fileExist=false;
if(file_exists($real_path_target)){
$fileExist=true;
}
if (move($base_work_dir.$document_to_move['path'], $base_work_dir.$_POST['move_to'])) {
}
if (FileManager::move($base_work_dir.$document_to_move['path'], $base_work_dir.$_POST['move_to'])) {
//if (1) {
//$contents = DocumentManager::replace_urls_inside_content_html_when_moving_file(basename($document_to_move['path']), $base_work_dir.dirname($document_to_move['path']), $base_work_dir.$_POST['move_to']);
//exit;
update_db_info('update', $document_to_move['path'], $_POST['move_to'].'/'.basename($document_to_move['path']));
FileManager::update_db_info('update', $document_to_move['path'], $_POST['move_to'].'/'.basename($document_to_move['path']));
//update database item property
$doc_id=$_POST['move_file'];
@ -438,12 +438,12 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
elseif(is_file($real_path_target)){
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentMoved', api_get_user_id(),$to_group_id,null,null,null,$session_id);
Display::display_confirmation_message(get_lang('DocMv'));
}
}
// Set the current path
$curdirpath = $_POST['move_to'];
$curdirpathurl = urlencode($_POST['move_to']);
} else {
if($fileExist){
if(is_dir($real_path_target)){
@ -468,19 +468,19 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)){
if (isset($_GET['delete'])) {
if (!$is_allowed_to_edit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible($_GET['delete'], $_course, api_get_session_id())) {
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']))) {
if ( isset($_GET['delete_certificate_id']) && $_GET['delete_certificate_id'] == strval(intval($_GET['delete_certificate_id']))) {
$default_certificate_id = $_GET['delete_certificate_id'];
DocumentManager::remove_attach_certificate(api_get_course_id(), $default_certificate_id);
}
@ -528,16 +528,16 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
Display::display_error_message(get_lang('CannotCreateDir'));
} else {
} else {
if (!empty($_POST['dir_id'])) {
$document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id());
$curdirpath = $document_data['path'];
}
$added_slash = ($curdirpath == '/') ? '' : '/';
}
$added_slash = ($curdirpath == '/') ? '' : '/';
$dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
$dir_name = disable_dangerous_file($dir_name);
$dir_check = $base_work_dir.$dir_name;
if (!is_dir($dir_check)) {
$created_dir = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
if ($created_dir) {
@ -572,13 +572,13 @@ if ($is_allowed_to_edit) {
$update_id = intval($_GET['set_invisible']);
$visibility_command = 'invisible';
}
if (!$is_allowed_to_edit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($update_id, $_course, api_get_session_id(), api_get_user_id())) {
if (!$is_allowed_to_edit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($update_id, $_course, api_get_session_id(), api_get_user_id())) {
api_not_allowed();
}
}
}
if (DocumentManager::check_readonly($_course, api_get_user_id(), '', $update_id)) {
api_not_allowed();
}
@ -621,7 +621,7 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
$document_id_for_template = intval(Database::escape_string($_GET['add_as_template']));
$title = Security::remove_XSS($_POST['template_title']);
//$description = Security::remove_XSS($_POST['template_description']);
//$description = Security::remove_XSS($_POST['template_description']);
$user_id = api_get_user_id();
// Create the template_thumbnails folder in the upload folder (if needed)
@ -664,7 +664,7 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
}
if (isset($_GET['remove_as_template'])) {
$document_id_for_template = intval($_GET['remove_as_template']);
$document_id_for_template = intval($_GET['remove_as_template']);
$user_id = api_get_user_id();
DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id);
Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate'));
@ -684,8 +684,8 @@ if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isse
}
/* GET ALL DOCUMENT DATA FOR CURDIRPATH */
if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
$docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, true);
if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
$docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, true);
} else {
$docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, false);
}
@ -701,34 +701,34 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
// Create a sortable table with our data
$sortable_data = array();
$count = 1;
$count = 1;
foreach ($docs_and_folders as $key => $document_data) {
$row = array();
$row = array();
$row['id'] = $document_data['id'];
//$row['type'] = $document_data['filetype'];
$row['type'] = create_document_link($document_data, true, $count, $is_visible);
$row['type'] = create_document_link($document_data, true, $count, $is_visible);
// If the item is invisible, wrap it in a span with class invisible
$is_visible = DocumentManager::is_visible_by_id($document_data['id'], $course_info, api_get_session_id(), api_get_user_id(), false);
$invisibility_span_open = ($is_visible == 0) ? '<span class="muted">' : '';
$invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
// Size (or total size of a directory)
$size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
$size = $document_data['filetype'] == 'folder' ? FileManager::get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
$row['size'] = format_file_size($size);
// Get the title or the basename depending on what we're using
if ($document_data['title'] != '') {
$document_name = $document_data['title'];
} else {
$document_name = basename($document_data['path']);
}
$row['name'] = $document_name;
$row['name'] = $document_name;
$row['name'] = create_document_link($document_data, false, null, $is_visible).$session_img.'<br />'.$invisibility_span_open.'<i>'.nl2br(htmlspecialchars($document_data['comment'],ENT_QUOTES,$charset)).'</i>'.$invisibility_span_close.$user_link;
// Data for checkbox
if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
$row[] = $document_data['path'];
@ -767,19 +767,19 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
// Icons (clickable)
$row[] = create_document_link($document_data, true, $count, $is_visible);
$path_info = pathinfo($document_data['path']);
if (isset($path_info['extension']) && in_array($path_info['extension'], array('ogg', 'mp3','wav'))) {
$count ++;
}
// Validacion when belongs to a session
$session_img = api_get_session_image($document_data['session_id'], $_user['status']);
// Document title with link
// Document title with link
$row[] = create_document_link($document_data, false, null, $is_visible).$session_img.'<br />'.$invisibility_span_open.'<i>'.nl2br(htmlspecialchars($document_data['comment'],ENT_QUOTES,$charset)).'</i>'.$invisibility_span_close.$user_link;
// Comments => display comment under the document name
$display_size = format_file_size($size);
$row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
@ -791,13 +791,13 @@ 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(api_get_user_id(), $curdirpath, $session_id)) {
$is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
// If readonly, check if it the owner of the file or if the user is an admin
if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
$is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
// If readonly, check if it the owner of the file or if the user is an admin
if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
$edit_icons = build_edit_icons($document_data, $key, $is_template, 0, $is_visible);
} else {
} else {
$edit_icons = build_edit_icons($document_data, $key, $is_template, $document_data['readonly'], $is_visible);
}
$row[] = $edit_icons;
@ -807,7 +807,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
$row[] = $document_name;
$total_size = $total_size + $size;
if ((isset($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
if ((isset($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
$sortable_data[] = $row;
}
}
@ -839,13 +839,13 @@ $action_links = 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
'\';
'\';
}';
$js_content = Display::grid_js('documents', '' ,$columns,$column_model, $extra_params, $sortable_data, $action_links,true);
$htmlHeadXtra[] = '<script>
$(function() {
// grid definition see the $career->display() function
'.$js_content.'
'.$js_content.'
});
</script>';

@ -492,9 +492,9 @@ Display::display_footer();
function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) {
$file_name_for_change = $base_work_dir.$dir.$source_file;
//api_display_debug_info("call my_rename: params $file_name_for_change, $rename_to");
//api_display_debug_info("call FileManager::my_rename: params $file_name_for_change, $rename_to");
$rename_to = disable_dangerous_file($rename_to); // Avoid renaming to .htaccess file
$rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API
$rename_to = FileManager::my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API
if ($rename_to) {
if (isset($dir) && $dir != '') {
@ -505,7 +505,7 @@ function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) {
$new_full_file_name = '/'.$rename_to;
}
update_db_info('update', $source_file, $new_full_file_name); // fileManage API
FileManager::update_db_info('update', $source_file, $new_full_file_name); // fileManage API
$name_changed = get_lang('ElRen');
$info_message = get_lang('fileModified');

@ -64,7 +64,7 @@ require_once 'dropbox_class.inc.php';
// including some libraries that are also used in the documents tool
require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php'; // we use a function build_document_icon_tag
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; // the function choose_image is used
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; // the function FileManager::choose_image is used
require_once api_get_path(LIBRARY_PATH).'document.lib.php';

@ -52,7 +52,7 @@ function HotPotGCt($folder,$flag,$userID) { // Garbage Collector
if (stristr($val,$userID.".t.html"))
{ if ($flag == 1)
{
my_delete($folder."/".$val);
FileManager::my_delete($folder."/".$val);
}
else
{

@ -266,16 +266,16 @@ if ($is_allowedToEdit) {
GetImgParams($file, $documentPath, $imgparams, $imgcount);
$fld = GetFolderName($file);
for ($i = 0; $i < $imgcount; $i++) {
my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
FileManager::my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
FileManager::update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
}
if (my_delete($documentPath . $file)) {
update_db_info("delete", $file);
if (FileManager::my_delete($documentPath . $file)) {
FileManager::update_db_info("delete", $file);
}
// hotpotatoes folder may contains several tests so don't delete folder if not empty : http://support.chamilo.org/issues/2165
if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !folder_is_empty($documentPath . $uploadPath . "/" . $fld . "/"))) {
my_delete($documentPath . $uploadPath . "/" . $fld . "/");
if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !FileManager::folder_is_empty($documentPath . $uploadPath . "/" . $fld . "/"))) {
FileManager::my_delete($documentPath . $uploadPath . "/" . $fld . "/");
} break;
case 'enable' : // enables an exercise
$newVisibilityStatus = "1"; //"visible"

@ -168,7 +168,7 @@ function import_exercise($file) {
$answer->save();
}
// delete the temp dir where the exercise was unzipped
my_delete($baseWorkDir . $uploadPath);
FileManager::my_delete($baseWorkDir . $uploadPath);
$operation = true;
}
return $operation;

@ -417,7 +417,7 @@ function HotPotGCt($folder, $flag, $user_id) {
while (list($key, $val) = each($filelist)) {
if (stristr($val, $user_id.'.t.html')) {
if ($flag == 1) {
my_delete($folder.'/'.$val);
FileManager::my_delete($folder.'/'.$val);
} else {
echo $folder.'/'.$val.'<br />';
}

@ -134,8 +134,8 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
if ($checked) { $imgcount = $imgcount-1; }
else {
$dialogBox .= $filename.' '.get_lang('NameNotEqual');
my_delete($document_sys_path.$uploadPath.'/'.$fld.'/'.$filename);
update_db_info('delete', $uploadPath.'/'.$fld.'/'.$filename);
FileManager::my_delete($document_sys_path.$uploadPath.'/'.$fld.'/'.$filename);
FileManager::update_db_info('delete', $uploadPath.'/'.$fld.'/'.$filename);
}
if ($imgcount == 0) { // all image uploaded
$finish = 1;

@ -30,7 +30,7 @@ require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
$full_file_path = $documentPath.$test;
my_delete($full_file_path.$_user['user_id'].".t.html");
FileManager::my_delete($full_file_path.$_user['user_id'].".t.html");
$TABLETRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$tbl_learnpath_user = Database::get_course_table(TABLE_LEARNPATH_USER);

@ -24,7 +24,7 @@ $time = $_REQUEST['time'];
$user_id = api_get_user_id();
$full_file_path = $document_path.$doc_url;
my_delete($full_file_path.$user_id.'.t.html');
FileManager::my_delete($full_file_path.$user_id.'.t.html');
$content = ReadFileCont($full_file_path.$user_id.'.t.html');
if ($content == '') {

@ -18,7 +18,7 @@ switch ($action) {
$my_current_friend = Security::remove_XSS($_POST['friend_id']);
$my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']);
$my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
$FileManager::my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
$friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']);
$type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered?
$is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //filtered?
@ -43,7 +43,7 @@ switch ($action) {
}
$my_current_friend = Security::remove_XSS($_POST['friend_id']);
$my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']);
$my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
$FileManager::my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
$friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']);
$type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered?
$is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //filtered?
@ -62,9 +62,9 @@ switch ($action) {
echo '';
break;
}
$my_delete_friend = intval($_POST['delete_friend_id']);
$FileManager::my_delete_friend = intval($_POST['delete_friend_id']);
if (isset($_POST['delete_friend_id'])) {
SocialManager::remove_user_rel_user($my_delete_friend);
SocialManager::remove_user_rel_user($FileManager::my_delete_friend);
}
break;
case 'show_my_friends':

@ -189,20 +189,13 @@ if ($docs_and_folders) {
$invisibility_span_open = ($id['visibility'] == 0) ? '<span class="invisible">' : '';
$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];
$size = $id['filetype'] == 'folder' ? FileManager::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 ($id['title'] != '') {
$document_name = $id['title'];
} else {
$document_name = basename($id['path']);
}
//$row[] = $key; //testing
//data for checkbox
/*
if ($is_allowed_to_edit AND count($docs_and_folders) > 1) {
$row[] = $id['path'];
}
*/
// icons with hyperlinks
$row[]= '<a href="#" onclick="javascript: OpenFile(\''.$http_www.'/'.$id['title'].'\', \''.$sType.'\');return false;">'.build_document_icon_tag($id['filetype'],$id['path']).'</a>';
//document title with hyperlink
@ -212,7 +205,7 @@ if ($docs_and_folders) {
$display_size = format_file_size($size);
$row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
//last edit date
$display_date = format_date(strtotime($id['lastedit_date']));
$display_date = date('d.m.Y', (strtotime($id['lastedit_date'])));
$row[] = '<span style="display:none;">'.$id['lastedit_date'].'</span>'.$invisibility_span_open.$display_date.$invisibility_span_close;
$sortable_data[] = $row;
@ -242,24 +235,12 @@ $table->set_header($column++, api_htmlentities(get_lang('Title'), ENT_QUOTES));
$table->set_header($column++, api_htmlentities(get_lang('Size'), ENT_QUOTES));
$table->set_header($column++, api_htmlentities(get_lang('Date'), ENT_QUOTES));
//currently only delete action -> take only DELETE right into account
/*
if (count($docs_and_folders) > 1) {
if ($is_allowed_to_edit) {
$form_actions = array();
$form_action['delete'] = get_lang('Delete');
$table->set_form_actions($form_action, 'path');
}
}
*/
echo api_utf8_encode($table->get_table_html());
echo api_utf8_encode($table_footer);
// Functions
?>
<script type="text/javascript">
<script>
<!--
function OpenFile( fileUrl, type )
{
@ -279,4 +260,4 @@ function OpenFile( fileUrl, type )
//window.close() ;
}
//-->
</script>
</script>

@ -201,7 +201,6 @@ if (isset($_configuration['main_database'])) {
)
));
//Setting Doctrine ORM
$app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array(
"orm.proxies_dir" => $app['db.orm.proxies_dir'],

@ -913,9 +913,9 @@ class DocumentManager {
self::delete_document_from_db($row['id'], $_course, $current_session_id, true);
}
//delete documents, do it like this so metadata get's deleted too
//update_db_info('delete', $path);
//FileManager::update_db_info('delete', $path);
//throw it away
my_delete($base_work_dir.$path);
FileManager::my_delete($base_work_dir.$path);
$file_deleted_from_disk = true;
}
} else {
@ -1149,7 +1149,7 @@ class DocumentManager {
$template_id = Database::result($result,0,0);
include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg');
FileManager::my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg');
$sql = 'DELETE FROM '.$table_template.' WHERE course_code="'.$course_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"';
@ -2890,7 +2890,7 @@ class DocumentManager {
if (!is_array($resource)) {
$resource = base64_decode($resource);
// It's a file.
$icon = choose_image($resource);
$icon = FileManager::choose_image($resource);
$position = strrpos($icon, '.');
$icon = substr($icon, 0, $position) . '_small.gif';
$file_info = explode('|@j@|', $resource);

@ -47,10 +47,8 @@ include('../../../../../../inc/global.inc.php');
<td>
<?php
$sType = "MP3";
//if (api_is_in_course() || api_is_platform_admin())
//{
include(api_get_path(INCLUDE_PATH).'course_document.inc.php');
//}
include(api_get_path(INCLUDE_PATH).'course_document.inc.php');
?>
</td>
</tr>

@ -101,7 +101,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) {
}
$new_path = $chamiloFolder; //sample /images
$dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo
update_db_info('update', $old_path, $new_path); //Chamilo
FileManager::update_db_info('update', $old_path, $new_path); //Chamilo
$curdirpath = $new_path;
$doc_id = DocumentManager::get_document_id($_course, $curdirpath); //Chamilo
$current_session_id = api_get_session_id();
@ -152,7 +152,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) {
}
$new_path = $chamiloFolder; //sample /images
$dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo
update_db_info('update', $old_path, $new_path); //Chamilo
FileManager::update_db_info('update', $old_path, $new_path); //Chamilo
$curdirpath = $new_path;
$doc_id = DocumentManager::get_document_id($_course, $curdirpath); //Chamilo
$current_session_id = api_get_session_id();
@ -164,7 +164,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) {
}
$new_path = $chamiloFolder; //sample /images/book_highlight.jpg
$dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo
update_db_info('update', $old_path, $new_path); //Chamilo
FileManager::update_db_info('update', $old_path, $new_path); //Chamilo
//update items
$curdirpath = $new_path;
$doc_id = DocumentManager::get_document_id($_course, $curdirpath); //Chamilo
@ -181,7 +181,7 @@ if (CONFIG_SYS_VIEW_ONLY || (!CONFIG_OPTIONS_CUT && !CONFIG_OPTIONS_COPY)) {
$new_path = $chamiloFolder; //sample /images/book_highlight.jpg
//update documents
$dbTable = Database::get_course_table(TABLE_DOCUMENT); //Chamilo
update_db_info('update', $old_path, $new_path); //Chamilo
FileManager::update_db_info('update', $old_path, $new_path); //Chamilo
//update items
$curdirpath = $new_path;
$doc_id = DocumentManager::get_document_id($_course, $curdirpath);

@ -1,244 +0,0 @@
<?php
/* See license terms in /license.txt */
/**
* This is the file display library for Dokeos.
* Include/require it in your code to use its functionality.
*
* @package chamilo.library
*/
/**
* Code
*/
/* GENERIC FUNCTIONS : FOR OLDER PHP VERSIONS */
if ( ! function_exists('array_search') ) {
/**
* Searches haystack for needle and returns the key
* if it is found in the array, FALSE otherwise.
*
* Natively implemented in PHP since 4.0.5 version.
* This function is intended for previous version.
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - needle (mixed)
* @param - haystack (array)
* @return - array key or FALSE
*
* @see - http://www.php.net/array_search
*/
function array_search($needle, $haystack)
{
while (list($key, $val) = each($haystack))
if ($val == $needle)
return $key;
return false;
}
}
/* FILE DISPLAY FUNCTIONS */
/**
* Define the image to display for each file extension.
* This needs an existing image repository to work.
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $file_name (string) - Name of a file
* @return - The gif image to chose
*/
function choose_image($file_name)
{
static $type, $image;
/* TABLES INITIALISATION */
if (!$type || !$image)
{
$type['word' ] = array('doc', 'dot', 'rtf', 'mcw', 'wps', 'psw', 'docm', 'docx', 'dotm', 'dotx');
$type['web' ] = array('htm', 'html', 'htx', 'xml', 'xsl', 'php', 'xhtml');
$type['image' ] = array('gif', 'jpg', 'png', 'bmp', 'jpeg', 'tif', 'tiff');
$type['image_vect'] = array('svg','svgz');
$type['audio' ] = array('wav', 'mid', 'mp2', 'mp3', 'midi', 'sib', 'amr', 'kar', 'oga','au','wma');
$type['video' ] = array('mp4', 'mov', 'rm', 'pls', 'mpg', 'mpeg', 'm2v', 'm4v', 'flv', 'f4v', 'avi', 'wmv', 'asf', '3gp','ogv','ogg','ogx','webm');
$type['excel' ] = array('xls', 'xlt', 'xls', 'xlt', 'pxl', 'xlsx', 'xlsm', 'xlam', 'xlsb', 'xltm', 'xltx');
$type['compressed'] = array('zip', 'tar', 'rar', 'gz');
$type['code' ] = array('js', 'cpp', 'c', 'java', 'phps', 'jsp', 'asp', 'aspx', 'cfm');
$type['acrobat' ] = array('pdf');
$type['powerpoint'] = array('ppt', 'pps', 'pptm', 'pptx', 'potm', 'potx', 'ppam', 'ppsm', 'ppsx');
$type['flash' ] = array('fla', 'swf');
$type['text' ] = array('txt','log');
$type['oo_writer' ] = array('odt', 'ott', 'sxw', 'stw');
$type['oo_calc' ] = array('ods', 'ots', 'sxc', 'stc');
$type['oo_impress'] = array('odp', 'otp', 'sxi', 'sti');
$type['oo_draw' ] = array('odg', 'otg', 'sxd', 'std');
$type['epub' ] = array('epub');
$type['java' ] = array('class','jar');
$type['freemind' ] = array('mm');
$image['word' ] = 'word.gif';
$image['web' ] = 'file_html.gif';
$image['image' ] = 'file_image.gif';
$image['image_vect'] = 'file_svg.png';
$image['audio' ] = 'file_sound.gif';
$image['video' ] = 'film.gif';
$image['excel' ] = 'excel.gif';
$image['compressed'] = 'file_zip.gif';
$image['code' ] = 'icons/22/mime_code.png';
$image['acrobat' ] = 'file_pdf.gif';
$image['powerpoint'] = 'powerpoint.gif';
$image['flash' ] = 'file_flash.gif';
$image['text' ] = 'icons/22/mime_text.png';
$image['oo_writer' ] = 'file_oo_writer.gif';
$image['oo_calc' ] = 'file_oo_calc.gif';
$image['oo_impress'] = 'file_oo_impress.gif';
$image['oo_draw' ] = 'file_oo_draw.gif';
$image['epub' ] = 'file_epub.gif';
$image['java' ] = 'file_java.png';
$image['freemind' ] = 'file_freemind.png';
}
/* FUNCTION CORE */
$extension = array();
if (!is_array($file_name)) {
if (preg_match('/\.([[:alnum:]]+)(\?|$)/', $file_name, $extension)) {
$extension[1] = strtolower($extension[1]);
foreach ($type as $generic_type => $extension_list)
{
if (in_array($extension[1], $extension_list))
{
return $image[$generic_type];
}
}
}
}
return 'defaut.gif';
}
/**
* Transform a UNIX time stamp in human readable format date.
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $date - UNIX time stamp
* @return - A human readable representation of the UNIX date
*/
function format_date($date)
{
return date('d.m.Y', $date);
}
/**
* Transform the file path to a URL.
*
* @param - $file_path (string) - Relative local path of the file on the hard disk
* @return - Relative url
*/
function format_url($file_path)
{
$path_component = explode('/', $file_path);
$path_component = array_map('rawurlencode', $path_component);
return implode('/', $path_component);
}
/**
* Get the most recent time the content of a folder was changed.
*
* @param - $dir_name (string) - Path of the dir on the hard disk
* @param - $do_recursive (bool) - Traverse all folders in the folder?
* @return - Time the content of the folder was changed
*/
function recent_modified_file_time($dir_name, $do_recursive = true)
{
$dir = dir($dir_name);
$last_modified = 0;
$return = 0;
if (is_dir($dir)) {
while(($entry = $dir->read()) !== false)
{
if ($entry != '.' && $entry != '..')
continue;
if (!is_dir($dir_name.'/'.$entry))
$current_modified = filemtime($dir_name.'/'.$entry);
elseif ($do_recursive)
$current_modified = recent_modified_file_time($dir_name.'/'.$entry, true);
if ($current_modified > $last_modified)
$last_modified = $current_modified;
}
$dir->close();
//prevents returning 0 (for empty directories)
$return = ($last_modified == 0) ? filemtime($dir_name) : $last_modified;
}
return $return;
}
/**
* Get the total size of a directory.
*
* @param - $dir_name (string) - Path of the dir on the hard disk
* @return - Total size in bytes
*/
function folder_size($dir_name)
{
$size = 0;
if ($dir_handle = opendir($dir_name))
{
while (($entry = readdir($dir_handle)) !== false)
{
if($entry == '.' || $entry == '..')
continue;
if(is_dir($dir_name.'/'.$entry))
$size += folder_size($dir_name.'/'.$entry);
else
$size += filesize($dir_name.'/'.$entry);
}
closedir($dir_handle);
}
return $size;
}
/**
* Calculates the total size of a directory by adding the sizes (that
* are stored in the database) of all files & folders in this directory.
*
* @param string $path
* @param boolean $can_see_invisible
* @return Total size
*/
function get_total_folder_size($path, $can_see_invisible = false) {
$table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$tool_document = TOOL_DOCUMENT;
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
$session_condition = api_get_session_condition($session_id, true, true, 'props.id_session');
$visibility_rule = ' props.visibility ' . ($can_see_invisible ? '<> 2' : '= 1');
$sql = "SELECT SUM(table1.size) FROM (
SELECT size FROM $table_itemproperty AS props, $table_document AS docs
WHERE docs.c_id = $course_id AND
docs.id = props.ref AND
docs.path LIKE '$path/%' AND
props.c_id = $course_id AND
props.tool = '$tool_document' AND
$visibility_rule
$session_condition
GROUP BY ref
) as table1";
$result = Database::query($sql);
if ($result && Database::num_rows($result) != 0) {
$row = Database::fetch_row($result);
return $row[0] == null ? 0 : $row[0];
} else {
return 0;
}
}

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This is the file manage library for Chamilo.
* Include/require it in your code to use its functionality.
@ -7,449 +8,405 @@
*/
/**
* Update the file or directory path in the document db document table
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - action (string) - action type require : 'delete' or 'update'
* @param - old_path (string) - old path info stored to change
* @param - new_path (string) - new path info to substitute
* @desc Update the file or directory path in the document db document table
*
*/
function update_db_info($action, $old_path, $new_path = '') {
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
/* DELETE */
if ($action == 'delete') {
$old_path = Database::escape_string($old_path);
$to_delete = "WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'";
$query = "DELETE FROM $dbTable " . $to_delete;
$result = Database::query("SELECT id FROM $dbTable " . $to_delete);
if (Database::num_rows($result)) {
require_once api_get_path(INCLUDE_PATH).'../metadata/md_funcs.php';
$mdStore = new mdstore(TRUE); // create if needed
This class contains functions that you can access statically.
$md_type = (substr($dbTable, -13) == 'scormdocument') ? 'Scorm' : 'Document';
FileManager::list_all_directories($path)
FileManager::list_all_files($dir_array)
FileManager::compat_load_file($file_name)
FileManager::set_default_settings($upload_path, $filename, $filetype="file", $glued_table, $default_visibility='v')
while ($row = Database::fetch_array($result)) {
$eid = $md_type . '.' . $row['id'];
$mdStore->mds_delete($eid);
$mdStore->mds_delete_offspring($eid);
@author Roan Embrechts
@version 1.1, July 2004
* @package chamilo.library
*/
class FileManager
{
/**
* Update the file or directory path in the document db document table
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - action (string) - action type require : 'delete' or 'update'
* @param - old_path (string) - old path info stored to change
* @param - new_path (string) - new path info to substitute
* @desc Update the file or directory path in the document db document table
*
*/
static function update_db_info($action, $old_path, $new_path = '') {
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
/* DELETE */
if ($action == 'delete') {
$old_path = Database::escape_string($old_path);
$to_delete = "WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'";
$query = "DELETE FROM $dbTable " . $to_delete;
$result = Database::query("SELECT id FROM $dbTable " . $to_delete);
if (Database::num_rows($result)) {
require_once api_get_path(INCLUDE_PATH).'../metadata/md_funcs.php';
$mdStore = new mdstore(TRUE); // create if needed
$md_type = (substr($dbTable, -13) == 'scormdocument') ? 'Scorm' : 'Document';
while ($row = Database::fetch_array($result)) {
$eid = $md_type . '.' . $row['id'];
$mdStore->mds_delete($eid);
$mdStore->mds_delete_offspring($eid);
}
}
}
}
/* UPDATE */
if ($action == 'update') {
if ($new_path[0] == '.') $new_path = substr($new_path, 1);
$new_path = str_replace('//', '/', $new_path);
// Attempt to update - tested & working for root dir
$new_path = Database::escape_string($new_path);
$query = "UPDATE $dbTable
SET path = CONCAT('".$new_path."', SUBSTRING(path, LENGTH('".$old_path."')+1) )
WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'";
}
Database::query($query);
}
/**
* Cheks a file or a directory actually exist at this location
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - file_path (string) - path of the presume existing file or dir
* @return - boolean TRUE if the file or the directory exists
* boolean FALSE otherwise.
*/
function check_name_exist($file_path) {
clearstatcache();
$save_dir = getcwd();
if (!is_dir(dirname($file_path))) {
return false;
}
chdir(dirname($file_path));
$file_name = basename($file_path);
if (file_exists($file_name)) {
chdir($save_dir);
return true;
} else {
chdir($save_dir);
return false;
}
}
/**
* Deletes a file or a directory
*
* @author - Hugues Peeters
* @param - $file (String) - the path of file or directory to delete
* @return - bolean - true if the delete succeed
* bolean - false otherwise.
* @see - delete() uses check_name_exist() and removeDir() functions
*/
function my_delete($file) {
if (check_name_exist($file)) {
if (is_file($file)) { // FILE CASE
unlink($file);
return true;
} elseif (is_dir($file)) { // DIRECTORY CASE
removeDir($file);
return true;
}
} else {
return false; // no file or directory to delete
}
}
/**
* Removes a directory recursively
*
* @returns true if OK, otherwise false
*
* @author Amary <MasterNES@aol.com> (from Nexen.net)
* @author Olivier Brouckaert <oli.brouckaert@skynet.be>
*
* @param string $dir directory to remove
*/
function removeDir($dir) {
if (!@$opendir = opendir($dir)) {
return false;
}
while ($readdir = readdir($opendir)) {
if ($readdir != '..' && $readdir != '.') {
if (is_file($dir.'/'.$readdir)) {
if (!@unlink($dir.'/'.$readdir)) {
return false;
}
} elseif (is_dir($dir.'/'.$readdir)) {
if (!removeDir($dir.'/'.$readdir)) {
return false;
}
}
}
}
closedir($opendir);
if (!@rmdir($dir)) {
return false;
}
return true;
}
/* UPDATE */
if ($action == 'update') {
if ($new_path[0] == '.') $new_path = substr($new_path, 1);
$new_path = str_replace('//', '/', $new_path);
/**
* Return true if folder is empty
* @author : hubert.borderiou@grenet.fr
* @param string $in_folder : folder path on disk
* @return 1 if folder is empty, 0 otherwise
*/
function folder_is_empty($in_folder) {
$tab_folder_content = scandir($in_folder);
$folder_is_empty = 0;
if ((count($tab_folder_content) == 2 && in_array(".", $tab_folder_content) && in_array("..", $tab_folder_content)) || (count($tab_folder_content) < 2)) {
$folder_is_empty = 1;
// Attempt to update - tested & working for root dir
$new_path = Database::escape_string($new_path);
$query = "UPDATE $dbTable
SET path = CONCAT('".$new_path."', SUBSTRING(path, LENGTH('".$old_path."')+1) )
WHERE c_id = $course_id AND path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%'";
}
Database::query($query);
}
return $folder_is_empty;
}
/**
* Cheks a file or a directory actually exist at this location
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - file_path (string) - path of the presume existing file or dir
* @return - boolean TRUE if the file or the directory exists
* boolean FALSE otherwise.
*/
static function check_name_exist($file_path) {
clearstatcache();
$save_dir = getcwd();
if (!is_dir(dirname($file_path))) {
return false;
}
chdir(dirname($file_path));
$file_name = basename($file_path);
if (file_exists($file_name)) {
chdir($save_dir);
return true;
} else {
chdir($save_dir);
return false;
}
}
/**
* Renames a file or a directory
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $file_path (string) - complete path of the file or the directory
* @param - $new_file_name (string) - new name for the file or the directory
* @return - boolean - true if succeed
* - boolean - false otherwise
* @see - rename() uses the check_name_exist() and php2phps() functions
*/
function my_rename($file_path, $new_file_name) {
/**
* Deletes a file or a directory
*
* @author - Hugues Peeters
* @param - $file (String) - the path of file or directory to delete
* @return - bolean - true if the delete succeed
* bolean - false otherwise.
* @see - delete() uses check_name_exist() and removeDir() functions
*/
static function my_delete($file) {
if (self::check_name_exist($file)) {
if (is_file($file)) { // FILE CASE
unlink($file);
return true;
} elseif (is_dir($file)) { // DIRECTORY CASE
self::removeDir($file);
return true;
}
} else {
return false; // no file or directory to delete
}
}
$save_dir = getcwd();
$path = dirname($file_path);
$old_file_name = basename($file_path);
/**
* Removes a directory recursively
*
* @returns true if OK, otherwise false
*
* @author Amary <MasterNES@aol.com> (from Nexen.net)
* @author Olivier Brouckaert <oli.brouckaert@skynet.be>
*
* @param string $dir directory to remove
*/
static function removeDir($dir) {
if (!@$opendir = opendir($dir)) {
return false;
}
$new_file_name = replace_dangerous_char($new_file_name);
while ($readdir = readdir($opendir)) {
if ($readdir != '..' && $readdir != '.') {
if (is_file($dir.'/'.$readdir)) {
if (!@unlink($dir.'/'.$readdir)) {
return false;
}
} elseif (is_dir($dir.'/'.$readdir)) {
if (!self::removeDir($dir.'/'.$readdir)) {
return false;
}
}
}
}
// If no extension, take the old one
if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) {
$new_file_name .= substr($old_file_name, $dotpos);
}
closedir($opendir);
// Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz'
// This is useful for folder names, where otherwise '.' would be sticky
if (!@rmdir($dir)) {
return false;
}
// Extension PHP is not allowed, change to PHPS
$new_file_name = php2phps($new_file_name);
return true;
}
if ($new_file_name == $old_file_name) {
return $old_file_name;
}
if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) {
return false;
}
// On a Windows server, it would be better not to do the above check
// because it succeeds for some new names resembling the old name.
// But on Unix/Linux the check must be done because rename overwrites.
/**
* Return true if folder is empty
* @author : hubert.borderiou@grenet.fr
* @param string $in_folder : folder path on disk
* @return 1 if folder is empty, 0 otherwise
*/
chdir($path);
$res = rename($old_file_name, $new_file_name) ? $new_file_name : false;
chdir($save_dir);
return $res;
}
static function folder_is_empty($in_folder) {
$tab_folder_content = scandir($in_folder);
$folder_is_empty = 0;
if ((count($tab_folder_content) == 2 && in_array(".", $tab_folder_content) && in_array("..", $tab_folder_content)) || (count($tab_folder_content) < 2)) {
$folder_is_empty = 1;
}
return $folder_is_empty;
}
/**
* Moves a file or a directory to an other area
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $source (String) - the path of file or directory to move
* @param - $target (String) - the path of the new area
* @return - bolean - true if the move succeed
* bolean - false otherwise.
* @see - move() uses check_name_exist() and copyDirTo() functions
*/
function move($source, $target) {
if (check_name_exist($source)) {
$file_name = basename($source);
/**
* Renames a file or a directory
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $file_path (string) - complete path of the file or the directory
* @param - $new_file_name (string) - new name for the file or the directory
* @return - boolean - true if succeed
* - boolean - false otherwise
* @see - rename() uses the check_name_exist() and php2phps() functions
*/
static function my_rename($file_path, $new_file_name) {
if (check_name_exist($target.'/'.$file_name)) {
return false;
} else {
/* File case */
if (is_file($source)) {
copy($source , $target.'/'.$file_name);
unlink($source);
return true;
}
/* Directory case */
elseif (is_dir($source)) {
// Check to not copy the directory inside itself
if (ereg('^'.$source.'/', $target.'/')) { // TODO: ereg() function is deprecated in PHP 5.3
return false;
} else {
copyDirTo($source, $target);
return true;
}
}
}
} else {
return false;
}
}
$save_dir = getcwd();
$path = dirname($file_path);
$old_file_name = basename($file_path);
/**
* Moves a directory and its content to an other area
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $orig_dir_path (string) - the path of the directory to move
* @param - $destination (string) - the path of the new area
* @return - no return
*/
function copyDirTo($orig_dir_path, $destination, $move = true) {
$save_dir = getcwd();
// Extract directory name - create it at destination - update destination trail
$dir_name = basename($orig_dir_path);
if (is_dir($orig_dir_path)) {
mkdir($destination.'/'.$dir_name, api_get_permissions_for_new_directories());
$destination_trail = $destination.'/'.$dir_name;
if (is_dir($destination)) {
chdir ($orig_dir_path) ;
$handle = opendir($orig_dir_path);
$new_file_name = replace_dangerous_char($new_file_name);
while ($element = readdir($handle)) {
if ($element == '.' || $element == '..') {
continue; // Skip the current and parent directories
} elseif (is_file($element)) {
copy($element, $destination_trail.'/'.$element);
if ($move) {
unlink($element) ;
}
} elseif (is_dir($element)) {
$dir_to_copy[] = $orig_dir_path.'/'.$element;
}
}
// If no extension, take the old one
if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) {
$new_file_name .= substr($old_file_name, $dotpos);
}
closedir($handle) ;
// Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz'
// This is useful for folder names, where otherwise '.' would be sticky
if (sizeof($dir_to_copy) > 0) {
foreach ($dir_to_copy as $this_dir) {
copyDirTo($this_dir, $destination_trail, $move); // Recursivity
}
}
// Extension PHP is not allowed, change to PHPS
$new_file_name = php2phps($new_file_name);
if ($move) {
rmdir($orig_dir_path) ;
}
chdir($save_dir);
}
}
}
if ($new_file_name == $old_file_name) {
return $old_file_name;
}
/* NOTE: These functions batch is used to automatically build HTML forms
* with a list of the directories contained on the course Directory.
*
* From a thechnical point of view, form_dir_lists calls sort_dir wich calls index_dir
*/
if (strtolower($new_file_name) != strtolower($old_file_name) && self::check_name_exist($path.'/'.$new_file_name)) {
return false;
}
// On a Windows server, it would be better not to do the above check
// because it succeeds for some new names resembling the old name.
// But on Unix/Linux the check must be done because rename overwrites.
chdir($path);
$res = rename($old_file_name, $new_file_name) ? $new_file_name : false;
chdir($save_dir);
return $res;
}
/**
* Gets all the directories and subdirectories
* contented in a given directory
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - path (string) - directory path of the one to index
* @return - an array containing the path of all the subdirectories
*/
function index_dir($path) {
$dir_array = array();
$save_dir = getcwd();
if (is_dir($path)){
chdir($path);
$handle = opendir($path);
// Reads directory content end record subdirectoies names in $dir_array
if ($handle !== false) {
while ($element = readdir($handle)) {
if ($element == '.' || $element == '..') continue; // Skip the current and parent directories
if (is_dir($element)) $dir_array[] = $path.'/'.$element;
}
closedir($handle) ;
}
// Recursive operation if subdirectories exist
$dir_number = sizeof($dir_array);
if ($dir_number > 0) {
for ($i = 0 ; $i < $dir_number ; $i++) {
$sub_dir_array = index_dir($dir_array[$i]); // Function recursivity
$dir_array = array_merge((array)$dir_array, (array)$sub_dir_array); // Data merge
/**
* Moves a file or a directory to an other area
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $source (String) - the path of file or directory to move
* @param - $target (String) - the path of the new area
* @return - bolean - true if the move succeed
* bolean - false otherwise.
* @see - move() uses check_name_exist() and copyDirTo() functions
*/
static function move($source, $target) {
if (self::check_name_exist($source)) {
$file_name = basename($source);
if (self::check_name_exist($target.'/'.$file_name)) {
return false;
} else {
/* File case */
if (is_file($source)) {
copy($source , $target.'/'.$file_name);
unlink($source);
return true;
} elseif (is_dir($source)) {
/* Directory case */
// Check to not copy the directory inside itself
if (ereg('^'.$source.'/', $target.'/')) { // TODO: ereg() function is deprecated in PHP 5.3
return false;
} else {
self::copyDirTo($source, $target);
return true;
}
}
}
} else {
return false;
}
}
chdir($save_dir) ;
return $dir_array ;
}
/**
* Indexes all the directories and subdirectories
* contented in a given directory, and sort them alphabetically
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - path (string) - directory path of the one to index
* @return - an array containing the path of all the subdirectories sorted
* false, if there is no directory
* @see - index_and_sort_dir uses the index_dir() function
*/
function index_and_sort_dir($path) {
$dir_list = index_dir($path);
if ($dir_list) {
natsort($dir_list);
return $dir_list;
}
return false;
}
/**
* Builds a html form listing all directories of a given directory
*
*/
function form_dir_list($source_type, $source_component, $command, $base_work_dir) {
$dir_list = index_and_sort_dir($base_work_dir);
$dialog_box .= "<form action=\"".api_get_self()."\" method=\"post\">\n" ;
$dialog_box .= "<input type=\"hidden\" name=\"".$source_type."\" value=\"".$source_component."\">\n" ;
$dialog_box .= get_lang('Move').' '.$source_component.' '.get_lang('To');
$dialog_box .= "<select name=\"".$command."\">\n" ;
$dialog_box .= "<option value=\"\" style=\"color:#999999\">".get_lang('Root')."\n";
$bwdLen = strlen($base_work_dir) ; // base directories lenght, used under
/* build html form inputs */
if ($dir_list) {
while (list( , $path_value) = each($dir_list) ) {
$path_value = substr ( $path_value , $bwdLen ); // Truncates cunfidential informations confidentielles
$dirname = basename ($path_value); // Extracts $path_value directory name du nom
/* compute de the display tab */
$tab = ""; // $tab reinitialisation
$depth = substr_count($path_value, '/'); // The number of nombre '/' indicates the directory deepness
for ($h = 0; $h < $depth; $h++) {
$tab .= "&nbsp;&nbsp;";
}
$dialog_box .= "<option value=\"$path_value\">$tab>$dirname\n";
}
}
$dialog_box .= "</select>\n";
$dialog_box .= "<input type=\"submit\" value=\"".get_lang('Ok')."\">";
$dialog_box .= "</form>\n";
return $dialog_box;
}
}
/**
* Extracting extention of a filename
*
* @returns array
* @param string $filename filename
*/
function getextension($filename) {
$bouts = explode('.', $filename);
return array(array_pop($bouts), implode('.', $bouts));
}
/**
* Moves a directory and its content to an other area
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - $orig_dir_path (string) - the path of the directory to move
* @param - $destination (string) - the path of the new area
* @return - no return
*/
static function copyDirTo($orig_dir_path, $destination, $move = true) {
$save_dir = getcwd();
// Extract directory name - create it at destination - update destination trail
$dir_name = basename($orig_dir_path);
if (is_dir($orig_dir_path)) {
mkdir($destination.'/'.$dir_name, api_get_permissions_for_new_directories());
$destination_trail = $destination.'/'.$dir_name;
if (is_dir($destination)) {
chdir ($orig_dir_path) ;
$handle = opendir($orig_dir_path);
while ($element = readdir($handle)) {
if ($element == '.' || $element == '..') {
continue; // Skip the current and parent directories
} elseif (is_file($element)) {
copy($element, $destination_trail.'/'.$element);
if ($move) {
unlink($element) ;
}
} elseif (is_dir($element)) {
$dir_to_copy[] = $orig_dir_path.'/'.$element;
}
}
closedir($handle) ;
if (sizeof($dir_to_copy) > 0) {
foreach ($dir_to_copy as $this_dir) {
self::copyDirTo($this_dir, $destination_trail, $move); // Recursivity
}
}
if ($move) {
rmdir($orig_dir_path) ;
}
chdir($save_dir);
}
}
}
/**
* Calculation size of a directory
*
* @returns integer size
* @param string $path path to size
* @param boolean $recursive if true , include subdir in total
*/
function dirsize($root, $recursive = true) {
$dir = @opendir($root);
$size = 0;
while ($file = @readdir($dir)) {
if (!in_array($file, array('.', '..'))) {
if (is_dir($root.'/'.$file)) {
$size += $recursive ? dirsize($root.'/'.$file) : 0;
} else {
$size += @filesize($root.'/'.$file);
}
}
}
@closedir($dir);
return $size;
}
/* NOTE: These functions batch is used to automatically build HTML forms
* with a list of the directories contained on the course Directory.
*
* From a thechnical point of view, form_dir_lists calls sort_dir wich calls index_dir
*/
/**
* Gets all the directories and subdirectories
* contented in a given directory
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - path (string) - directory path of the one to index
* @return - an array containing the path of all the subdirectories
*/
static function index_dir($path) {
$dir_array = array();
$save_dir = getcwd();
if (is_dir($path)){
chdir($path);
$handle = opendir($path);
// Reads directory content end record subdirectoies names in $dir_array
if ($handle !== false) {
while ($element = readdir($handle)) {
if ($element == '.' || $element == '..') continue; // Skip the current and parent directories
if (is_dir($element)) $dir_array[] = $path.'/'.$element;
}
closedir($handle) ;
}
// Recursive operation if subdirectories exist
$dir_number = sizeof($dir_array);
if ($dir_number > 0) {
for ($i = 0 ; $i < $dir_number ; $i++) {
$sub_dir_array = self::index_dir($dir_array[$i]); // Function recursivity
$dir_array = array_merge((array)$dir_array, (array)$sub_dir_array); // Data merge
}
}
}
chdir($save_dir) ;
return $dir_array ;
}
/* CLASS FileManager */
/**
* Indexes all the directories and subdirectories
* contented in a given directory, and sort them alphabetically
*
* @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
* @param - path (string) - directory path of the one to index
* @return - an array containing the path of all the subdirectories sorted
* false, if there is no directory
* @see - index_and_sort_dir uses the index_dir() function
*/
static function index_and_sort_dir($path) {
$dir_list = self::index_dir($path);
if ($dir_list) {
natsort($dir_list);
return $dir_list;
}
return false;
}
/**
This class contains functions that you can access statically.
FileManager::list_all_directories($path)
FileManager::list_all_files($dir_array)
FileManager::compat_load_file($file_name)
FileManager::set_default_settings($upload_path, $filename, $filetype="file", $glued_table, $default_visibility='v')
/**
* Extracting extention of a filename
*
* @returns array
* @param string $filename filename
*/
static function getextension($filename) {
$bouts = explode('.', $filename);
return array(array_pop($bouts), implode('.', $bouts));
}
@author Roan Embrechts
@version 1.1, July 2004
* @package chamilo.library
*/
class FileManager
{
/**
* Calculation size of a directory
*
* @returns integer size
* @param string $path path to size
* @param boolean $recursive if true , include subdir in total
*/
static function dirsize($root, $recursive = true) {
$dir = @opendir($root);
$size = 0;
while ($file = @readdir($dir)) {
if (!in_array($file, array('.', '..'))) {
if (is_dir($root.'/'.$file)) {
$size += $recursive ? dirsize($root.'/'.$file) : 0;
} else {
$size += @filesize($root.'/'.$file);
}
}
}
@closedir($dir);
return $size;
}
/**
Returns a list of all directories, except the base dir,
@ -460,7 +417,7 @@ class FileManager
@author Roan Embrechts
@version 1.0.1
*/
function list_all_directories($path) {
static function list_all_directories($path) {
$result_array = array();
if (is_dir($path)) {
@ -581,6 +538,124 @@ class FileManager
Database::query($query);
}
function choose_image($file_name)
{
static $type, $image;
/* TABLES INITIALISATION */
if (!$type || !$image)
{
$type['word' ] = array('doc', 'dot', 'rtf', 'mcw', 'wps', 'psw', 'docm', 'docx', 'dotm', 'dotx');
$type['web' ] = array('htm', 'html', 'htx', 'xml', 'xsl', 'php', 'xhtml');
$type['image' ] = array('gif', 'jpg', 'png', 'bmp', 'jpeg', 'tif', 'tiff');
$type['image_vect'] = array('svg','svgz');
$type['audio' ] = array('wav', 'mid', 'mp2', 'mp3', 'midi', 'sib', 'amr', 'kar', 'oga','au','wma');
$type['video' ] = array('mp4', 'mov', 'rm', 'pls', 'mpg', 'mpeg', 'm2v', 'm4v', 'flv', 'f4v', 'avi', 'wmv', 'asf', '3gp','ogv','ogg','ogx','webm');
$type['excel' ] = array('xls', 'xlt', 'xls', 'xlt', 'pxl', 'xlsx', 'xlsm', 'xlam', 'xlsb', 'xltm', 'xltx');
$type['compressed'] = array('zip', 'tar', 'rar', 'gz');
$type['code' ] = array('js', 'cpp', 'c', 'java', 'phps', 'jsp', 'asp', 'aspx', 'cfm');
$type['acrobat' ] = array('pdf');
$type['powerpoint'] = array('ppt', 'pps', 'pptm', 'pptx', 'potm', 'potx', 'ppam', 'ppsm', 'ppsx');
$type['flash' ] = array('fla', 'swf');
$type['text' ] = array('txt','log');
$type['oo_writer' ] = array('odt', 'ott', 'sxw', 'stw');
$type['oo_calc' ] = array('ods', 'ots', 'sxc', 'stc');
$type['oo_impress'] = array('odp', 'otp', 'sxi', 'sti');
$type['oo_draw' ] = array('odg', 'otg', 'sxd', 'std');
$type['epub' ] = array('epub');
$type['java' ] = array('class','jar');
$type['freemind' ] = array('mm');
$image['word' ] = 'word.gif';
$image['web' ] = 'file_html.gif';
$image['image' ] = 'file_image.gif';
$image['image_vect'] = 'file_svg.png';
$image['audio' ] = 'file_sound.gif';
$image['video' ] = 'film.gif';
$image['excel' ] = 'excel.gif';
$image['compressed'] = 'file_zip.gif';
$image['code' ] = 'icons/22/mime_code.png';
$image['acrobat' ] = 'file_pdf.gif';
$image['powerpoint'] = 'powerpoint.gif';
$image['flash' ] = 'file_flash.gif';
$image['text' ] = 'icons/22/mime_text.png';
$image['oo_writer' ] = 'file_oo_writer.gif';
$image['oo_calc' ] = 'file_oo_calc.gif';
$image['oo_impress'] = 'file_oo_impress.gif';
$image['oo_draw' ] = 'file_oo_draw.gif';
$image['epub' ] = 'file_epub.gif';
$image['java' ] = 'file_java.png';
$image['freemind' ] = 'file_freemind.png';
}
/* FUNCTION CORE */
$extension = array();
if (!is_array($file_name)) {
if (preg_match('/\.([[:alnum:]]+)(\?|$)/', $file_name, $extension)) {
$extension[1] = strtolower($extension[1]);
foreach ($type as $generic_type => $extension_list)
{
if (in_array($extension[1], $extension_list))
{
return $image[$generic_type];
}
}
}
}
return 'defaut.gif';
}
} //end class FileManager
/**
* Transform the file path to a URL.
*
* @param - $file_path (string) - Relative local path of the file on the hard disk
* @return - Relative url
*/
function format_url($file_path)
{
$path_component = explode('/', $file_path);
$path_component = array_map('rawurlencode', $path_component);
return implode('/', $path_component);
}
/**
* Calculates the total size of a directory by adding the sizes (that
* are stored in the database) of all files & folders in this directory.
*
* @param string $path
* @param boolean $can_see_invisible
* @return Total size
*/
function get_total_folder_size($path, $can_see_invisible = false) {
$table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$tool_document = TOOL_DOCUMENT;
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
$session_condition = api_get_session_condition($session_id, true, true, 'props.id_session');
$visibility_rule = ' props.visibility ' . ($can_see_invisible ? '<> 2' : '= 1');
$sql = "SELECT SUM(table1.size) FROM (
SELECT size FROM $table_itemproperty AS props, $table_document AS docs
WHERE docs.c_id = $course_id AND
docs.id = props.ref AND
docs.path LIKE '$path/%' AND
props.c_id = $course_id AND
props.tool = '$tool_document' AND
$visibility_rule
$session_condition
GROUP BY ref
) as table1";
$result = Database::query($sql);
if ($result && Database::num_rows($result) != 0) {
$row = Database::fetch_row($result);
return $row[0] == null ? 0 : $row[0];
} else {
return 0;
}
}
}

@ -5,21 +5,11 @@
require_once api_get_path(LIBRARY_PATH) . 'pear/HTML/QuickForm.php';
require_once api_get_path(LIBRARY_PATH) . 'pear/HTML/QuickForm/advmultiselect.php';
/**
* Filter
*/
define('NO_HTML', 1);
define('STUDENT_HTML', 2);
define('TEACHER_HTML', 3);
define('STUDENT_HTML_FULLPAGE', 4);
define('TEACHER_HTML_FULLPAGE', 5);
/**
* Objects of this class can be used to create/manipulate/validate user input.
*/
class FormValidator extends HTML_QuickForm
{
/**
* Create a form validator based on an array of form data:
*
@ -143,9 +133,9 @@ class FormValidator extends HTML_QuickForm
$this->registerRule('filetype', null, 'HTML_QuickForm_Rule_Filetype', $dir . 'Rule/Filetype.php');
$this->registerRule('multiple_required', 'required', 'HTML_QuickForm_Rule_MultipleRequired', $dir . 'Rule/MultipleRequired.php');
$this->registerRule('url', null, 'HTML_QuickForm_Rule_Url', $dir . 'Rule/Url.php');
$this->registerRule('compare_fields', null, 'HTML_QuickForm_Compare_Fields', $dir . 'Rule/CompareFields.php');
$this->registerRule('compare_fields', null, 'HTML_QuickForm_Compare_Fields', $dir . 'Rule/CompareFields.php');
$this->registerRule('compare_datetime_text', null, 'HTML_QuickForm_Rule_CompareDateTimeText', $dir . 'Rule/CompareDateTimeText.php');
// Modify the default templates
$renderer = & $this->defaultRenderer();

@ -369,7 +369,7 @@ class GroupManager {
if (file_exists($source_directory)) {
if (api_get_setting('permanently_remove_deleted_files') == 'true') {
//Delete
my_delete($source_directory);
FileManager::my_delete($source_directory);
} else {
//Rename
rename($source_directory, $destination_dir);

@ -359,6 +359,15 @@ define('MESSAGE_STATUS_INVITATION_DENIED', '7');
define('SESSION_LINK_TARGET', '_self');
/**
* Form validator
*/
define('NO_HTML', 1);
define('STUDENT_HTML', 2);
define('TEACHER_HTML', 3);
define('STUDENT_HTML_FULLPAGE', 4);
define('TEACHER_HTML_FULLPAGE', 5);
/**
* Inclusion of internationalization libraries

@ -91,7 +91,7 @@ class document_processor extends search_processor {
$url = sprintf($url, $course_path, $row['path']);
// Get the image path
include_once api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php';
$icon = choose_image(basename($row['path']));
$icon = FileManager::choose_image(basename($row['path']));
$thumbnail = api_get_path(WEB_CODE_PATH) . 'img/' . $icon;
$image = $thumbnail;
//FIXME: use big images

@ -14,7 +14,6 @@
*/
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; //check_name_exists()
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
require_once api_get_path(SYS_CODE_PATH).'newscorm/scorm.class.php';

@ -1,5 +1,5 @@
<?php
/**
<?php
/**
* Chamilo metadata/importmanifest.php
* 2006/12/15
* Copyright (C) 2006 rene.haentjens@UGent.be - see metadata/md_funcs.php
@ -619,7 +619,7 @@ echo '<h3>', get_lang('OrElse'), '</h3>', "\n<table>\n";
$specifics = '<select name="workWith">' . "\n" .
'<option value="" style="color:#999999">' . get_lang('Root') . "</option>\n";
if (($dirList = index_and_sort_dir($baseWorkDir))) // fileManage.lib
if (($dirList = FileManager::index_and_sort_dir($baseWorkDir))) // fileManage.lib
{
$someDirs = array();

@ -684,8 +684,8 @@ class aicc extends learnpath {
DocumentManager :: file_send_for_download($zipfilename, true);
// Delete the temporary zip file and directory in fileManage.lib.php
my_delete($zipfilename);
my_delete($zipfoldername);
FileManager::my_delete($zipfilename);
FileManager::my_delete($zipfoldername);
return true;
}

@ -1885,7 +1885,7 @@ function exportSCORM($scormname, $course) {
// Clear.
include_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
my_delete($zipfilename);
FileManager::my_delete($zipfilename);
}
/**

@ -95,7 +95,7 @@ function show_documents($folder) {
if (file_or_folder($row['path'])) {
echo '<img src="../img/file.gif" align="middle" />';
} else {
$image = choose_image($row['path']);
$image = FileManager::choose_image($row['path']);
echo "<img src=\"../img/$image\" align=\"middle\" />";
}
@ -142,7 +142,7 @@ function show_documents($folder) {
if (file_or_folder($path)) {
echo '<img src="../img/file.gif" align="middle" />';
} else {
$image = choose_image($path);
$image = FileManager::choose_image($path);
echo "<img src=\"../img/$image\" align=\"middle\" />";
}
@ -284,7 +284,7 @@ function display_addedresource_link($type, $id, $style = '') {
$pathname = explode('/',$myrow['path']); // Making a correct name for the link.
$last = count($pathname) - 1; // Making a correct name for the link.
$filename = $pathname[$last]; // Making a correct name for the link.
$image = choose_image($filename);
$image = FileManager::choose_image($filename);
$ext = explode('.', $filename);
$ext = strtolower($ext[sizeof($ext)-1]);
$myrow['path'] = rawurlencode($myrow['path']);
@ -753,7 +753,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
}
}
if (($builder != 'builder') && ($icon != 'wrap')) { echo "</td><td>"; }
$image = choose_image($filename);
$image = FileManager::choose_image($filename);
$sql = "select * from $tbl_lp_item where id=$id_in_path";
//error_log('New LP - Querying lp_item table: '.$sql, 0);
@ -1578,7 +1578,7 @@ function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_win
$pathname = explode('/', $myrow['path']); // Making a correct name for the link.
$last = count($pathname) - 1; // Making a correct name for the link.
$filename = $pathname[$last]; // Making a correct name for the link.
$image = choose_image($filename);
$image = FileManager::choose_image($filename);
$ext = explode('.', $filename);
$ext = strtolower($ext[sizeof($ext) - 1]);
$myrow['path'] = rawurlencode($myrow['path']);
@ -1830,7 +1830,7 @@ function rl_get_resource_name($course_code, $learnpath_id, $id_in_path) {
$pathname = explode('/', $myrow['path']); // Making a correct name for the link.
$last = count($pathname) - 1; // Making a correct name for the link.
$filename = $pathname[$last]; // Making a correct name for the link.
$image = choose_image($filename);
$image = FileManager::choose_image($filename);
$ext = explode('.', $filename);
$ext = strtolower($ext[sizeof($ext) - 1]);
$myrow['path'] = rawurlencode($myrow['path']);

@ -795,8 +795,8 @@ class scorm extends learnpath {
DocumentManager :: file_send_for_download($zipfilename, true);
// Delete the temporary zip file and directory in fileManage.lib.php
my_delete($zipfilename);
my_delete($zipfoldername);
FileManager::my_delete($zipfilename);
FileManager::my_delete($zipfoldername);
return true;
}

@ -98,7 +98,7 @@ function show_documents($folder)
}
else
{
$image = choose_image($row['path']);
$image = FileManager::choose_image($row['path']);
echo "<img src=\"../img/$image\" align=\"middle\" />";
}
@ -158,7 +158,7 @@ function show_documents($folder)
}
else
{
$image = choose_image($path);
$image = FileManager::choose_image($path);
echo "<img src=\"../img/$image\" align=\"middle\" />";
}
@ -309,7 +309,7 @@ function display_addedresource_link($type, $id, $style='')
$pathname = explode('/',$myrow['path']); // making a correct name for the link
$last = count($pathname) - 1; // making a correct name for the link
$filename = $pathname[$last]; // making a correct name for the link
$image = choose_image($filename);
$image = FileManager::choose_image($filename);
$ext = explode('.',$filename);
$ext = strtolower($ext[sizeof($ext)-1]);
$myrow['path'] = rawurlencode($myrow['path']);
@ -821,7 +821,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
}
}
if (($builder != 'builder') and ($icon != 'wrap')) { echo "</td><td>"; }
$image=choose_image($filename);
$image=FileManager::choose_image($filename);
$sql="select * from $tbl_learnpath_item where id=$id_in_path";
$result=Database::query($sql); $row=Database::fetch_array($result);

@ -1118,7 +1118,7 @@ function del_dir($id) {
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
$new_dir = $work_data_url.'_DELETED_'.$id;
if (api_get_setting('permanently_remove_deleted_files') == 'true'){
my_delete($work_data_url);
FileManager::my_delete($work_data_url);
} else {
if (file_exists($work_data_url)) {
rename($work_data_url, $new_dir);
@ -1193,7 +1193,7 @@ function update_dir_name($work_data, $new_name, $title) {
$new_name = Security::remove_XSS($new_name);
$new_name = replace_dangerous_char($new_name);
$new_name = disable_dangerous_file($new_name);
my_rename($base_work_dir.'/'.$path, $new_name);
FileManager::my_rename($base_work_dir.'/'.$path, $new_name);
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
//update all the files in the other directories according with the next query

@ -428,7 +428,7 @@ switch ($action) {
$realUrl = str_replace($_configuration['root_sys'], api_get_path(WEB_PATH), str_replace("\\", '/', realpath($submitGroupWorkUrl)));
$form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl);
$text_document = $form->addElement('text', 'document', get_lang('Document'));
$defaults['document'] = '<a href="' . format_url($submitGroupWorkUrl) . '">' . $realUrl . '</a>';
$defaults['document'] = '<a href="' . FileManager::format_url($submitGroupWorkUrl) . '">' . $realUrl . '</a>';
$text_document->freeze();
} elseif ($item_id && ($is_allowed_to_edit or $is_author)) {
$workUrl = $currentCourseRepositoryWeb . $workUrl;
@ -934,7 +934,7 @@ switch ($action) {
//security fix: make sure they can't move files that are not in the document table
if ($path = get_work_path($item_id)) {
if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
if (FileManager::move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
//update db
update_work_url($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']);
@ -1075,7 +1075,7 @@ switch ($action) {
if ($row['contains_file'] == 1) {
if (!empty($work)) {
if (api_get_setting('permanently_remove_deleted_files') == 'true') {
my_delete($currentCourseRepositorySys.'/'.$work);
FileManager::my_delete($currentCourseRepositorySys.'/'.$work);
Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
$file_deleted = true;
} else {

@ -1,5 +1,4 @@
<?php
require_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
class TestFileDisplay extends UnitTestCase {
public function TestFileDisplay(){
@ -14,63 +13,5 @@ class TestFileDisplay extends UnitTestCase {
//todo public function testFolderSize()
//todo public function testGetTotalFolderSize()
public function testChooseImage(){
global $_course;
static $type, $image;
$file_name = '';
$res = choose_image($file_name);
$this->assertEqual($res,'defaut.gif');
$this->assertTrue(is_string($res));
//var_dump($file_name);
}
public function testFormatFileSize(){
$file_size = '100';
$res = format_file_size($file_size);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testFormatDate(){
$date = '11/02/2009';
$res = format_date($date);
$this->assertTrue($res);
//var_dump($res);
}
public function testFormatUrl(){
$file_path ='/var/www/path/';
$res = format_url($file_path);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testRecentModifiedFileTime(){
$dir_name = '';
$$do_recursive =true;
$res = recent_modified_file_time($dir_name, $do_recursive);
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
public function testFolderSize(){
$dir_name ='';
$res = folder_size($dir_name);
$this->assertFalse($res);
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
}
?>
}

@ -37,14 +37,14 @@ class TestFileManager extends UnitTestCase {
public function testUpdatedbInfo(){
$action ='';
$oldPath ='';
$res = update_db_info($action, $oldPath, $newPath="");
$res = FileManager::update_db_info($action, $oldPath, $newPath="");
$this->assertNull($res);
//var_dump($res);
}
public function testCheckNameExist(){
$filePath ='';
$res = check_name_exist($filePath);
$res = FileManager::check_name_exist($filePath);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -53,7 +53,7 @@ class TestFileManager extends UnitTestCase {
public function testMyDelete(){
$file='';
$res = my_delete($file);
$res = FileManager::my_delete($file);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res===false);
@ -62,7 +62,7 @@ class TestFileManager extends UnitTestCase {
public function testRemoveDir(){
$dir='';
$res = removeDir($dir);
$res = FileManager::removeDir($dir);
$this->assertTrue(is_bool($res));
$this->assertFalse($res === true);
//var_dump($res);
@ -71,7 +71,7 @@ class TestFileManager extends UnitTestCase {
public function testMyRename(){
$filePath ='document/';
$newFileName='';
$res = my_rename($filePath, $newFileName);
$res = FileManager::my_rename($filePath, $newFileName);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
//var_dump($res);
@ -80,7 +80,7 @@ class TestFileManager extends UnitTestCase {
public function testMove(){
$source ='';
$target ='';
$res = move($source, $target);
$res = FileManager::move($source, $target);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
$this->assertFalse($res);
@ -90,14 +90,14 @@ class TestFileManager extends UnitTestCase {
public function testCopyDirTo(){
$origDirPath=api_get_path(SYS_COURSE_PATH).'document/audio';
$destination=api_get_path(SYS_COURSE_PATH).'document/flash/audio';
$res = copyDirTo($origDirPath, $destination, $move = false);
$res = FileManager::copyDirTo($origDirPath, $destination, $move = false);
$this->assertTrue($res===null);
$this->assertNull($res);
}
public function testIndexDir(){
$path=api_get_path(SYS_COURSE_PATH).'document/';
$res = index_dir($path);
$res = FileManager::index_dir($path);
if(!is_null($res)) {
$this->assertTrue(is_array($res));
} else {
@ -108,7 +108,7 @@ class TestFileManager extends UnitTestCase {
public function testIndexAndSortDir(){
$path=api_get_path(SYS_COURSE_PATH).'document/';
$res = index_and_sort_dir($path);
$res = FileManager::index_and_sort_dir($path);
if(!is_bool($res)) {
$this->assertTrue($res);
$this->assertTrue(is_array($res));
@ -116,16 +116,6 @@ class TestFileManager extends UnitTestCase {
//var_dump($res);
}
public function testFormDirList(){
$sourceType = '';
$sourceComponent = '';
$command = '';
$baseWorkDir = api_get_path(SYS_COURSE_PATH).'document/';
$res = form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testMkpath(){
$path=api_get_path(SYS_COURSE_PATH).'document/';

@ -44,14 +44,14 @@ class TestFileManager extends UnitTestCase {
public function testUpdatedbInfo(){
$action ='';
$oldPath ='';
$res = update_db_info($action, $oldPath, $newPath="");
$res = FileManager::update_db_info($action, $oldPath, $newPath="");
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testCheckNameExist(){
$filePath ='';
$res = check_name_exist($filePath);
$res = FileManager::check_name_exist($filePath);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -60,7 +60,7 @@ class TestFileManager extends UnitTestCase {
public function testMyDelete(){
$file='';
$res = my_delete($file);
$res = FileManager::my_delete($file);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res===false);
@ -69,7 +69,7 @@ class TestFileManager extends UnitTestCase {
public function testRemoveDir(){
$dir='';
$res = removeDir($dir);
$res = FileManager::removeDir($dir);
$this->assertTrue(is_bool($res));
$this->assertFalse($res === true);
//var_dump($res);
@ -78,7 +78,7 @@ class TestFileManager extends UnitTestCase {
public function testMyRename(){
$filePath ='documents';
$newFileName='';
$res = my_rename($filePath, $newFileName);
$res = FileManager::my_rename($filePath, $newFileName);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
//var_dump($res);
@ -87,7 +87,7 @@ class TestFileManager extends UnitTestCase {
public function testMove(){
$source ='';
$target ='';
$res = move($source, $target);
$res = FileManager::move($source, $target);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
$this->assertFalse($res);
@ -97,14 +97,14 @@ class TestFileManager extends UnitTestCase {
public function testCopyDirTo(){
$origDirPath='';
$destination='';
$res = copyDirTo($origDirPath, $destination, $move=true);
$res = FileManager::copyDirTo($origDirPath, $destination, $move=true);
$this->assertTrue($res===null);
$this->assertNull($res);
}
public function testIndexDir(){
$path='/var/www/path/';
$res = index_dir($path);
$res = FileManager::index_dir($path);
$this->assertFalse(is_array($res));
$this->assertNull($res);
//var_dump($res);
@ -112,7 +112,7 @@ class TestFileManager extends UnitTestCase {
public function testIndexAndSortDir(){
$path='/var/www/path/';
$res = index_and_sort_dir($path);
$res = FileManager::index_and_sort_dir($path);
$this->assertFalse($res);
$this->assertFalse(is_array($res));
$this->assertTrue(is_bool($res));
@ -120,16 +120,6 @@ class TestFileManager extends UnitTestCase {
//var_dump($res);
}
public function testFormDirList(){
$sourceType='';
$sourceComponent='';
$command='';
$baseWorkDir='';
$res =form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testMkpath(){
$path='/var/www/path/';

Loading…
Cancel
Save