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. 1
      main/admin/special_exports.php
  4. 1
      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. 6
      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. 25
      main/inc/course_document.inc.php
  23. 1
      main/inc/global.inc.php
  24. 8
      main/inc/lib/document.lib.php
  25. 4
      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. 241
      main/inc/lib/fileManage.lib.php
  29. 10
      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. 2
      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. 59
      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'));

@ -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';

@ -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

@ -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'] != '') {

@ -422,11 +422,11 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
$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'];
@ -717,7 +717,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
// 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

@ -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 )
{

@ -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');
//}
?>
</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,11 +1,26 @@
<?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.
* @package chamilo.library
*/
/**
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')
@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
*
@ -16,7 +31,7 @@
* @desc Update the file or directory path in the document db document table
*
*/
function update_db_info($action, $old_path, $new_path = '') {
static function update_db_info($action, $old_path, $new_path = '') {
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
@ -66,7 +81,7 @@ function update_db_info($action, $old_path, $new_path = '') {
* @return - boolean TRUE if the file or the directory exists
* boolean FALSE otherwise.
*/
function check_name_exist($file_path) {
static function check_name_exist($file_path) {
clearstatcache();
$save_dir = getcwd();
if (!is_dir(dirname($file_path))) {
@ -93,13 +108,13 @@ function check_name_exist($file_path) {
* bolean - false otherwise.
* @see - delete() uses check_name_exist() and removeDir() functions
*/
function my_delete($file) {
if (check_name_exist($file)) {
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
removeDir($file);
self::removeDir($file);
return true;
}
} else {
@ -117,7 +132,7 @@ function my_delete($file) {
*
* @param string $dir directory to remove
*/
function removeDir($dir) {
static function removeDir($dir) {
if (!@$opendir = opendir($dir)) {
return false;
}
@ -129,7 +144,7 @@ function removeDir($dir) {
return false;
}
} elseif (is_dir($dir.'/'.$readdir)) {
if (!removeDir($dir.'/'.$readdir)) {
if (!self::removeDir($dir.'/'.$readdir)) {
return false;
}
}
@ -153,7 +168,7 @@ function removeDir($dir) {
* @return 1 if folder is empty, 0 otherwise
*/
function folder_is_empty($in_folder) {
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)) {
@ -173,7 +188,7 @@ function folder_is_empty($in_folder) {
* - boolean - false otherwise
* @see - rename() uses the check_name_exist() and php2phps() functions
*/
function my_rename($file_path, $new_file_name) {
static function my_rename($file_path, $new_file_name) {
$save_dir = getcwd();
$path = dirname($file_path);
@ -196,7 +211,7 @@ function my_rename($file_path, $new_file_name) {
return $old_file_name;
}
if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) {
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
@ -219,12 +234,12 @@ function my_rename($file_path, $new_file_name) {
* bolean - false otherwise.
* @see - move() uses check_name_exist() and copyDirTo() functions
*/
function move($source, $target) {
static function move($source, $target) {
if (check_name_exist($source)) {
if (self::check_name_exist($source)) {
$file_name = basename($source);
if (check_name_exist($target.'/'.$file_name)) {
if (self::check_name_exist($target.'/'.$file_name)) {
return false;
} else {
/* File case */
@ -232,14 +247,13 @@ function move($source, $target) {
copy($source , $target.'/'.$file_name);
unlink($source);
return true;
}
} elseif (is_dir($source)) {
/* 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);
self::copyDirTo($source, $target);
return true;
}
}
@ -257,7 +271,7 @@ function move($source, $target) {
* @param - $destination (string) - the path of the new area
* @return - no return
*/
function copyDirTo($orig_dir_path, $destination, $move = true) {
static function copyDirTo($orig_dir_path, $destination, $move = true) {
$save_dir = getcwd();
// Extract directory name - create it at destination - update destination trail
@ -287,7 +301,7 @@ function copyDirTo($orig_dir_path, $destination, $move = true) {
if (sizeof($dir_to_copy) > 0) {
foreach ($dir_to_copy as $this_dir) {
copyDirTo($this_dir, $destination_trail, $move); // Recursivity
self::copyDirTo($this_dir, $destination_trail, $move); // Recursivity
}
}
@ -313,7 +327,7 @@ function copyDirTo($orig_dir_path, $destination, $move = true) {
* @param - path (string) - directory path of the one to index
* @return - an array containing the path of all the subdirectories
*/
function index_dir($path) {
static function index_dir($path) {
$dir_array = array();
$save_dir = getcwd();
if (is_dir($path)){
@ -331,7 +345,7 @@ function index_dir($path) {
$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
$sub_dir_array = self::index_dir($dir_array[$i]); // Function recursivity
$dir_array = array_merge((array)$dir_array, (array)$sub_dir_array); // Data merge
}
}
@ -350,8 +364,8 @@ function index_dir($path) {
* 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);
static function index_and_sort_dir($path) {
$dir_list = self::index_dir($path);
if ($dir_list) {
natsort($dir_list);
return $dir_list;
@ -360,53 +374,13 @@ function index_and_sort_dir($path) {
}
/**
* 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) {
static function getextension($filename) {
$bouts = explode('.', $filename);
return array(array_pop($bouts), implode('.', $bouts));
}
@ -418,7 +392,7 @@ function getextension($filename) {
* @param string $path path to size
* @param boolean $recursive if true , include subdir in total
*/
function dirsize($root, $recursive = true) {
static function dirsize($root, $recursive = true) {
$dir = @opendir($root);
$size = 0;
while ($file = @readdir($dir)) {
@ -434,23 +408,6 @@ function dirsize($root, $recursive = true) {
return $size;
}
/* CLASS FileManager */
/**
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')
@author Roan Embrechts
@version 1.1, July 2004
* @package chamilo.library
*/
class FileManager
{
/**
Returns a list of all directories, except the base dir,
of the current course. This function uses recursion.
@ -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';
}
/**
* 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;
} //end class FileManager
$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:
*

@ -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';

@ -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