From 71e4a057a0ca8beb2c118a3189d0a7c115b9303e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 16 Jun 2011 14:29:01 +0200 Subject: [PATCH] Fixing pclzip calls using /archive instead of courses/XXX/temp folder, also removing some useless code in dropbox and fixing/improving code that generates the zip, fixing the layout of the course copy, adding documentation, setting some functions to deprecated, changing icon of LP export to a CD common icon in all platorm --- main/admin/special_exports.php | 28 ++- main/course_info/download.php | 8 +- .../classes/CourseArchiver.class.php | 26 +-- .../classes/CourseBuilder.class.php | 4 +- main/coursecopy/create_backup.php | 9 +- main/document/document.inc.php | 2 +- main/document/document.php | 18 +- main/document/downloadfolder.inc.php | 89 ++++----- main/dropbox/dropbox_functions.inc.php | 174 +++--------------- main/dropbox/dropbox_submit.php | 101 +++++----- main/dropbox/index.php | 12 +- main/exercice/admin.php | 8 +- main/exercice/exercice.php | 6 +- main/exercice/export/exercise_import.inc.php | 3 - main/exercice/export/qti2/qti2_export.php | 5 +- main/inc/lib/add_course.lib.inc.php | 1 + main/inc/lib/document.lib.php | 5 +- main/inc/lib/fileUpload.lib.php | 5 +- main/inc/lib/main_api.lib.php | 10 + main/newscorm/learnpath_functions.inc.php | 4 + main/newscorm/lp_list.php | 18 +- main/newscorm/scorm.class.php | 1 - main/newscorm/scorm_admin.php | 3 + main/upload/upload.document.php | 49 +---- main/work/downloadfolder.inc.php | 59 ++---- main/work/work.lib.php | 13 +- .../dropbox/dropbox_functions.inc.test.php | 24 --- 27 files changed, 227 insertions(+), 458 deletions(-) mode change 100644 => 100755 tests/main/dropbox/dropbox_functions.inc.test.php diff --git a/main/admin/special_exports.php b/main/admin/special_exports.php index fd94da962c..b530028a66 100755 --- a/main/admin/special_exports.php +++ b/main/admin/special_exports.php @@ -1,17 +1,18 @@ + * @author Jhon Hinojosa + * @author Julio Montoya Fixing pclzip folder + some clean * @package special.export */ // name of the language file that needs to be included -$language_file = array ('admin'); +$language_file = array('admin'); // including the global file $cidReset = true; -include ('../inc/global.inc.php'); +require_once '../inc/global.inc.php'; // setting the section (for the tabs) $this_section = SECTION_PLATFORM_ADMIN; // setting breadcrumbs @@ -23,11 +24,11 @@ $nameTools = get_lang('SpecialExports'); // include additional libraries require_once '../document/document.inc.php'; // include additional libraries -include_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'); -require_once ('../coursecopy/classes/CourseSelectForm.class.php'); +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'; +require_once '../coursecopy/classes/CourseSelectForm.class.php'; if(function_exists('ini_set')) { ini_set('memory_limit','256M'); @@ -124,9 +125,9 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i } if ($export && $name) { - Display::display_confirmation_message(get_lang('BackupCreated').'

'.$name.'', false); - echo '

 '.get_lang('MainMenu').'

'; -} else{ + Display::display_confirmation_message(get_lang('BackupCreated')); + echo '
'.get_lang('Download').''; +} else { // Display forms especial export if (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') { $cb = new CourseBuilder(); @@ -183,9 +184,6 @@ function create_zip(){ closedir($handle); } $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip"; //create zipfile of given directory - - - return array('PATH' => $path, 'PATH_TEMP_ARCHIVE' => $temp_zip_dir, 'PATH_COURSE' => $sys_course_path, diff --git a/main/course_info/download.php b/main/course_info/download.php index dfda5faac8..a88d0bd1fe 100755 --- a/main/course_info/download.php +++ b/main/course_info/download.php @@ -1,7 +1,7 @@ code.'_'.date("YmdHis").'.zip'; + $zip_file = $user['user_id'].'_'.$course->code.'_'.date("Ymd-His").'.zip'; $php_errormsg = ''; $res = @mkdir($backup_dir, $perm_dirs); if ($res === false) @@ -92,13 +92,7 @@ class CourseArchiver if (is_array($course->resources[RESOURCE_SCORM])) { foreach ($course->resources[RESOURCE_SCORM] as $id => $document) { $doc_dir = dirname($backup_dir.$document->path); -// error_log($doc_dir); - - @mkdir($doc_dir, $perm_dirs, true); - //error_log($course->path.$document->path); - //error_log('----------'); - copyDirTo($course->path.$document->path, $doc_dir, false); } } @@ -111,11 +105,10 @@ class CourseArchiver copyDirTo($course->path.'upload/calendar/', $doc_dir, false); } - //Copy learningpath author image - + //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); + @mkdir($doc_dir, $perm_dirs, true); copyDirTo($course->path.'upload/learning_path/', $doc_dir, false); } @@ -220,5 +213,4 @@ class CourseArchiver $course->backup_path = $unzip_dir; return $course; } -} -?> +} \ No newline at end of file diff --git a/main/coursecopy/classes/CourseBuilder.class.php b/main/coursecopy/classes/CourseBuilder.class.php index 532e3a0d8b..949b965f6d 100755 --- a/main/coursecopy/classes/CourseBuilder.class.php +++ b/main/coursecopy/classes/CourseBuilder.class.php @@ -577,10 +577,8 @@ class CourseBuilder { $table_main = Database::get_course_table(TABLE_LP_MAIN); $table_item = Database::get_course_table(TABLE_LP_ITEM); $table_tool = Database::get_course_table(TABLE_TOOL_LIST); - $sql = 'SELECT * FROM '.$table_main.' WHERE session_id = 0'; - } - error_log($sql); + } $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { diff --git a/main/coursecopy/create_backup.php b/main/coursecopy/create_backup.php index 82301d91cd..282d8be52b 100755 --- a/main/coursecopy/create_backup.php +++ b/main/coursecopy/create_backup.php @@ -54,9 +54,10 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is $cb = new CourseBuilder(); $course = $cb->build(); } - $zip_file = CourseArchiver :: write_course($course); - Display::display_confirmation_message(get_lang('BackupCreated').str_repeat('
', 3).''.$zip_file.'', false); - echo '
'.get_lang('CourseHomepage').'
'; + $zip_file = CourseArchiver :: write_course($course); + Display::display_confirmation_message(get_lang('BackupCreated')); + echo '
'.get_lang('Download').''; + ?> no longer used, deleted files are included too like this - //$what_to_zip = $sys_course_path.$_course['path'].'/document'.$path; - // Creation of the zipped folder - //$zip_folder->create($what_to_zip ,PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/document'.$remove_dir ); +if (api_is_allowed_to_edit()) { // Set the path that will be used in the query if ($path == '/') { $querypath = ''; // To prevent ...path LIKE '//%'... in query } else { $querypath = $path; } + $querypath = Database::escape_string($querypath); // Search for all files that are not deleted => visibility != 2 - $query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE props.tool='".TOOL_DOCUMENT."' AND docs.id=props.ref AND docs.path LIKE '".$querypath."/%' AND docs.filetype='file' AND props.visibility<>'2' AND props.to_group_id=".$to_group_id.""); + $query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props + WHERE props.tool='".TOOL_DOCUMENT."' AND docs.id=props.ref AND docs.path LIKE '".$querypath."/%' AND docs.filetype='file' AND props.visibility<>'2' AND props.to_group_id=".$to_group_id.""); // Add tem to the zip file while ($not_deleted_file = Database::fetch_assoc($query)) { $zip_folder->add($sys_course_path.$_course['path'].'/document'.$not_deleted_file['path'], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/document'.$remove_dir); } -} -// For other users, we need to create a zipfile with only visible files and folders -else { +} else { + // For other users, we need to create a zipfile with only visible files and folders + if ($path == '/') { $querypath = ''; // To prevent ...path LIKE '//%'... in query } else { @@ -95,7 +74,9 @@ else { // A big problem: Visible files that are in a hidden folder are included when we do a query for visiblity='v' // So... I do it in a couple of steps: // 1st: Get all files that are visible in the given path - $query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE props.tool='".TOOL_DOCUMENT."' AND docs.id=props.ref AND docs.path LIKE '".$querypath."/%' AND props.visibility='1' AND docs.filetype='file' AND props.to_group_id=".$to_group_id); + $querypath = Database::escape_string($querypath); + $query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props + WHERE props.tool='".TOOL_DOCUMENT."' AND docs.id=props.ref AND docs.path LIKE '".$querypath."/%' AND props.visibility='1' AND docs.filetype='file' AND props.to_group_id=".$to_group_id); // Add them to an array while ($all_visible_files = Database::fetch_assoc($query)) { $all_visible_files_path[] = $all_visible_files['path']; @@ -105,7 +86,8 @@ else { //print_r($all_visible_files_path); //echo(''); // 2nd: Get all folders that are invisible in the given path - $query2 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE props.tool='".TOOL_DOCUMENT."' AND docs.id=props.ref AND docs.path LIKE '".$querypath."/%' AND props.visibility<>'1' AND docs.filetype='folder'"); + $query2 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props + WHERE props.tool='".TOOL_DOCUMENT."' AND docs.id=props.ref AND docs.path LIKE '".$querypath."/%' AND props.visibility<>'1' AND docs.filetype='folder'"); // If we get invisible folders, we have to filter out these results from all visible files we found if (Database::num_rows($query2) > 0) { // Add tem to an array @@ -128,26 +110,25 @@ else { $files_for_zipfile = $all_visible_files_path; } // Add all files in our final array to the zipfile - //echo("path to remove from file ".$sys_course_path.$_course['path']."/document".$remove_dir.'
'); - //echo('FILES FOR ZIP
'); - //print_r($files_for_zipfile); + for ($i = 0; $i < count($files_for_zipfile); $i++) { $zip_folder->add($sys_course_path.$_course['path'].'/document'.$files_for_zipfile[$i], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/document'.$remove_dir); //echo $sys_course_path.$_course['path'].'/document'.$files_for_zipfile[$i].'
'; } } // end for other users -//exit; // Launch event event_download(($path == '/') ? 'documents.zip (folder)' : basename($path).'.zip (folder)'); // Start download of created file //send_file_to_client($temp_zip_file, basename(empty($_GET['id']) ? 'documents' : $_GET['id']).'.zip'); -$name = ($path == '/') ? 'documents.zip' : basename($path).'.zip'; +$name = ($path == '/') ? 'documents.zip' : $document_data['title'].'.zip'; -DocumentManager::file_send_for_download($temp_zip_file, true, $name); -@unlink($temp_zip_file); -exit; +if (Security::check_abs_path($temp_zip_file, api_get_path(SYS_ARCHIVE_PATH))) { + DocumentManager::file_send_for_download($temp_zip_file, true, $name); + @unlink($temp_zip_file); + exit; +} /** * Returns the difference between two arrays, as an array of those key/values diff --git a/main/dropbox/dropbox_functions.inc.php b/main/dropbox/dropbox_functions.inc.php index 3d851b8c91..b1b7c1f474 100755 --- a/main/dropbox/dropbox_functions.inc.php +++ b/main/dropbox/dropbox_functions.inc.php @@ -83,9 +83,6 @@ function handle_multiple_actions() { } foreach ($checked_file_ids as $key => $value) { - //var_dump($value); - //var_dump($to_cat_id); - //var_dump($part); store_move($value, $to_cat_id, $part); } return get_lang('FilesMoved'); @@ -1030,66 +1027,57 @@ function store_feedback() { function zip_download($array) { global $_course; global $dropbox_cnf; - global $_user; global $files; - + $sys_course_path = api_get_path(SYS_COURSE_PATH); // zip library for creation of the zipfile require api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; // place to temporarily stash the zipfiles - $temp_zip_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'; - - // create the directory if it does not exist yet. - if (!is_dir($temp_zip_dir)) { - mkdir($temp_zip_dir, api_get_permissions_for_new_directories()); - } - - cleanup_temp_dropbox(); - - $files = ''; + $temp_zip_dir = api_get_path(SYS_COURSE_PATH); + + array_map('intval', $array); // note: we also have to add the check if the user has received or sent this file. $sql = "SELECT distinct file.filename, file.title, file.author, file.description FROM ".$dropbox_cnf['tbl_file']." file, ".$dropbox_cnf['tbl_person']." person WHERE file.id IN (".implode(', ',$array).") AND file.id=person.file_id - AND person.user_id='".$_user['user_id']."'"; + AND person.user_id='".api_get_user_id()."'"; $result = Database::query($sql); + $files = array(); while ($row = Database::fetch_array($result)) { $files[$row['filename']] = array('filename' => $row['filename'],'title' => $row['title'], 'author' => $row['author'], 'description' => $row['description']); } - //$alternative is a variable that uses an alternative method to create the zip - // because the renaming of the files inside the zip causes error on php5 (unexpected end of archive) - $alternative = true; - if ($alternative) { - zip_download_alternative($files); - exit; - } - - // create the zip file - $name = 'dropboxdownload-'.api_get_user_id().'-'.mktime().'.zip'; - $temp_zip_file = $temp_zip_dir.'/'.$name; - $zip_folder = new PclZip($temp_zip_file); - - foreach ($files as $key => $value) { - // met hernoemen van de files in de zip - $zip_folder->add(api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$value['filename'], PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox', PCLZIP_CB_PRE_ADD, 'my_pre_add_callback'); - // zonder hernoemen van de files in de zip - //$zip_folder->add(api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$value['filename'],PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox'); + // Step 3: create the zip file and add all the files to it + $temp_zip_file = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip"; + $zip_folder = new PclZip($temp_zip_file); + foreach ($files as $key => $value) { + $zip_folder->add(api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$value['filename'], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_CB_PRE_ADD, 'my_pre_add_callback'); } - - // create the overview file + + /* + * @todo if you want the overview code fix it by yourself + * + // Step 1: create the overview file and add it to the zip $overview_file_content = generate_html_overview($files, array('filename'), array('title')); - $overview_file = $temp_zip_dir.'/overview.html'; + $overview_file = $temp_zip_dir.'overview'.replace_dangerous_char(api_is_western_name_order() ? $_user['firstname'].' '.$_user['lastname'] : $_user['lastname'].' '.$_user['firstname'], 'strict').'.html'; $handle = fopen($overview_file, 'w'); fwrite($handle, $overview_file_content); + // todo: find a different solution for this because even 2 seconds is no guarantee. + sleep(2);*/ + + // Step 4: we add the overview file + //$zip_folder->add($overview_file, PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp'); - // send the zip file + // Step 5: send the file for download; + + $name = 'dropbox-'.api_get_utc_datetime().'.zip'; DocumentManager::file_send_for_download($temp_zip_file, true, $name); - exit; + @unlink($temp_zip_file); + exit; } /** @@ -1106,114 +1094,6 @@ function my_pre_add_callback($p_event, &$p_header) { return 1; } -/** -* This function is an alternative zip download. It was added because PCLZip causes problems on PHP5 when using PCLZIP_CB_PRE_ADD and a callback function to rename -* the files inside the zip file (dropbox scrambles the files to prevent -* @todo consider using a htaccess that denies direct access to the file but only allows the php file to access it. This would remove the scrambling requirement -* but it would require additional checks to see if the filename of the uploaded file is not used yet. -* @param $files is an associative array that contains the files that the user wants to download (check to see if the user is allowed to download these files already -* happened so the array is clean!!. The key is the filename on the filesystem. The value is an array that contains both the filename on the filesystem and -* the original filename (that will be used in the zip file) -* @todo when we copy the files there might be two files with the same name. We need a function that (recursively) checks this and changes the name -* -* @author Patrick Cool , Ghent University -* @version march 2006 -*/ -function zip_download_alternative($files) -{ - global $_course; - global $_user; - - $temp_zip_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'; - - // Step 2: we copy all the original dropbox files to the temp folder and change their name into the original name - foreach ($files as $key => $value) { - $value['title'] = check_file_name(api_strtolower($value['title'])); - $files[$value['filename']]['title'] = $value['title']; - copy(api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$value['filename'], api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'.$value['title']); - } - - // Step 3: create the zip file and add all the files to it - $temp_zip_file = $temp_zip_dir.'/dropboxdownload-'.api_get_user_id().'-'.mktime().'.zip'; - $zip_folder = new PclZip($temp_zip_file); - foreach ($files as $key => $value) { - $zip_folder->add(api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'.$value['title'], PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp'); - } - - // Step 1: create the overview file and add it to the zip - $overview_file_content = generate_html_overview($files, array('filename'), array('title')); - $overview_file = $temp_zip_dir.'overview'.replace_dangerous_char(api_is_western_name_order() ? $_user['firstname'].' '.$_user['lastname'] : $_user['lastname'].' '.$_user['firstname'], 'strict').'.html'; - $handle = fopen($overview_file, 'w'); - fwrite($handle, $overview_file_content); - // todo: find a different solution for this because even 2 seconds is no guarantee. - sleep(2); - - // Step 4: we add the overview file - $zip_folder->add($overview_file, PCLZIP_OPT_REMOVE_PATH, api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp'); - - // Step 5: send the file for download; - DocumentManager::file_send_for_download($temp_zip_file, true); - - // Step 6: remove the files in the temp dir - foreach ($files as $key => $value) { - unlink(api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'.$value['title']); - } - //unlink($overview_file); - - exit; -} - -/** -* @desc This function checks if the real filename of the dropbox files doesn't already exist in the temp folder. If this is the case then -* it will generate a different filename; -* -* @author Patrick Cool , Ghent University -* @version march 2006 -*/ -function check_file_name($file_name_2_check, $counter = 0) { - global $_course; - - $new_file_name = $file_name_2_check; - if ($counter != 0) { - $new_file_name = $counter.$new_file_name; - } - - if (!file_exists(api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'.$new_file_name)) { - return $new_file_name; - } else { - $counter++; - $new_file_name = check_file_name($file_name_2_check, $counter); - return $new_file_name; - } -} - - -/** -* @desc Cleans the temp zip files that were created when users download several files or a whole folder at once. -* T -* @return true -* @todo -* @author Patrick Cool , Ghent University -* @version march 2006 -*/ - -function cleanup_temp_dropbox() { - global $_course; - $handle = opendir(api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp'); - while (false !== ($file = readdir($handle))) { - if ($file != '.' OR $file != '..') { - $name = str_replace('.zip', '', $file); - $name_part = explode('-', $name); - $timestamp_of_file = $name_part[count($name_part) - 1]; - // if it is a dropboxdownloadfile and the file is older than one day then we delete it - if (strstr($file, 'dropboxdownload') AND $timestamp_of_file < (mktime() - 86400)) { - unlink(api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'.$file); - } - } - } - closedir($handle); - return true; -} /** * @desc Generates the contents of a html file that gives an overview of all the files in the zip file. diff --git a/main/dropbox/dropbox_submit.php b/main/dropbox/dropbox_submit.php index 91a0bf100f..714799856e 100755 --- a/main/dropbox/dropbox_submit.php +++ b/main/dropbox/dropbox_submit.php @@ -227,9 +227,12 @@ if (isset($_POST['submitWork'])) { /** * EXAMINE OR SEND MAILING (NEW) + * @deprecated The $_GET[mailingIndex] is never called */ -if (isset($_GET['mailingIndex'])) { // examine or send +/* +if (isset($_GET['mailingIndex'])) { + // examine or send $dropbox_person = new Dropbox_Person( $_user['user_id'], $is_courseAdmin, $is_courseTutor); if (isset($_SESSION['sentOrder'])) { $dropbox_person->orderSentWork($_SESSION['sentOrder']); @@ -251,55 +254,9 @@ if (isset($_GET['mailingIndex'])) { // examine or send ON cu.user_id = u.user_id AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND cu.course_code = '".$_course['sysCode']."'"; $sel .= " WHERE u.".dropbox_cnf("mailingWhere".$var)." = '"; - function getUser($thisRecip) { - // string result = error message, array result = [user_id, lastname, firstname] - - global $var, $sel; - if (isset($students)) { - unset($students); - } - - $result = Database::query($sel . $thisRecip . "'"); - while ( ($res = Database::fetch_array($result))) {$students[] = $res;} - Database::free_result($result); - - if (count($students) == 1) { - return($students[0]); - } elseif (count($students) > 1) { - return ' <'.get_lang('MailingFileRecipDup', '').$var."= $thisRecip>"; - } else { - return ' <'.get_lang('MailingFileRecipNotFound', '').$var."= $thisRecip>"; - } - } - $preFix = $nameParts[1]; $postFix = $nameParts[3]; $preLen = api_strlen($preFix); $postLen = api_strlen($postFix); - function findRecipient($thisFile) { - // string result = error message, array result = [user_id, lastname, firstname, status] - - global $nameParts, $preFix, $preLen, $postFix, $postLen; - - if (preg_match(dropbox_cnf('mailingFileRegexp'), $thisFile, $matches)) { - $thisName = $matches[1]; - if (api_substr($thisName, 0, $preLen) == $preFix) { - if ($postLen == 0 || api_substr($thisName, -$postLen) == $postFix) { - $thisRecip = api_substr($thisName, $preLen, api_strlen($thisName) - $preLen - $postLen); - if ($thisRecip) { - return getUser($thisRecip); - } - return ' <'.get_lang('MailingFileNoRecip', '').'>'; - } else { - return ' <'.get_lang('MailingFileNoPostfix', '').$postFix.'>'; - } - } else { - return ' <'.get_lang('MailingFileNoPrefix', '').$preFix.'>'; - } - } else { - return ' <'.get_lang('MailingFileFunny', '').'>'; - } - } - require api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php'; $zipFile = new pclZip($mailing_file); @@ -407,9 +364,8 @@ if (isset($_GET['mailingIndex'])) { // examine or send } - /** - * EXAMINE OR SEND MAILING RESULTMESSAGE - */ + //EXAMINE OR SEND MAILING RESULTMESSAGE + if ($error) { ?> @@ -423,6 +379,51 @@ if (isset($_GET['mailingIndex'])) { // examine or send '; + } else { + return ' <'.get_lang('MailingFileNoPostfix', '').$postFix.'>'; + } + } else { + return ' <'.get_lang('MailingFileNoPrefix', '').$preFix.'>'; + } + } else { + return ' <'.get_lang('MailingFileFunny', '').'>'; + } +} + +function getUser($thisRecip) { + // string result = error message, array result = [user_id, lastname, firstname] + + global $var, $sel; + if (isset($students)) { + unset($students); + } + + $result = Database::query($sel . $thisRecip . "'"); + while ( ($res = Database::fetch_array($result))) {$students[] = $res;} + Database::free_result($result); + + if (count($students) == 1) { + return($students[0]); + } elseif (count($students) > 1) { + return ' <'.get_lang('MailingFileRecipDup', '').$var."= $thisRecip>"; + } else { + return ' <'.get_lang('MailingFileRecipNotFound', '').$var."= $thisRecip>"; + } +} /** diff --git a/main/dropbox/index.php b/main/dropbox/index.php index 09b3ce231d..4a518f02d5 100755 --- a/main/dropbox/index.php +++ b/main/dropbox/index.php @@ -285,9 +285,9 @@ if ($_GET['action'] != 'add') { if (api_get_session_id() == 0) { echo '
'; - if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { - echo get_lang('CurrentlySeeing').': '.$dropbox_categories[$view_dropbox_category_received]['cat_name'].' '; + if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { echo ''.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32').""; + echo get_lang('Category').': '.$dropbox_categories[$view_dropbox_category_received]['cat_name'].' '; $movelist[0] = 'Root'; // move_received selectbox content } else { echo ''.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32').''; @@ -296,9 +296,9 @@ if ($_GET['action'] != 'add') { } else { if (api_is_allowed_to_session_edit(false, true)) { echo '
'; - if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { - echo get_lang('CurrentlySeeing').': '.$dropbox_categories[$view_dropbox_category_received]['cat_name'].' '; + if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { echo ''.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32').""; + echo get_lang('Category').': '.$dropbox_categories[$view_dropbox_category_received]['cat_name'].' '; $movelist[0] = 'Root'; // move_received selectbox content } else { echo ''.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32').''; @@ -322,9 +322,9 @@ if ($_GET['action'] != 'add') { if (api_get_session_id() == 0) { echo '
'; - if ($view_dropbox_category_sent != 0) { - echo get_lang('CurrentlySeeing').': '.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].' '; + if ($view_dropbox_category_sent != 0) { echo ''.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32').""; + echo get_lang('Category').': '.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].' '; } else { echo "".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32')."\n"; } diff --git a/main/exercice/admin.php b/main/exercice/admin.php index 6a294d93da..c6076e5386 100755 --- a/main/exercice/admin.php +++ b/main/exercice/admin.php @@ -137,15 +137,15 @@ $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); if ($_GET['action'] == 'exportqti2' && !empty($_GET['questionId'])) { - require_once('export/qti2/qti2_export.php'); - $export = export_question((int)$_GET['questionId'],true); + require_once 'export/qti2/qti2_export.php'; + $export = export_question($_GET['questionId'],true); $qid = (int)$_GET['questionId']; require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'); $archive_path = api_get_path(SYS_ARCHIVE_PATH); $temp_dir_short = uniqid(); $temp_zip_dir = $archive_path."/".$temp_dir_short; if(!is_dir($temp_zip_dir)) mkdir($temp_zip_dir, api_get_permissions_for_new_directories()); - $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip"; + $temp_zip_file = $temp_zip_dir."/".api_get_unique_id().".zip"; $temp_xml_file = $temp_zip_dir."/qti2export_".$qid.'.xml'; file_put_contents($temp_xml_file,$export); $zip_folder=new PclZip($temp_zip_file); @@ -157,7 +157,7 @@ if ($_GET['action'] == 'exportqti2' && !empty($_GET['questionId'])) { unlink($temp_xml_file); rmdir($temp_zip_dir); //DocumentManager::string_send_for_download($export,true,'qti2export_q'.$_GET['questionId'].'.xml'); - exit(); //otherwise following clicks may become buggy + exit; //otherwise following clicks may become buggy } // intializes the Exercise object diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index 31fdb1b656..492aa579e3 100755 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -314,11 +314,11 @@ if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') { require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php'; $archive_path = api_get_path(SYS_ARCHIVE_PATH); - $temp_dir_short = uniqid(); + $temp_dir_short = api_get_unique_id(); $temp_zip_dir = $archive_path . "/" . $temp_dir_short; if (!is_dir($temp_zip_dir)) mkdir($temp_zip_dir, api_get_permissions_for_new_directories()); - $temp_zip_file = $temp_zip_dir . "/" . md5(time()) . ".zip"; + $temp_zip_file = $temp_zip_dir . "/" . api_get_unique_id() . ".zip"; $temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml'; file_put_contents($temp_xml_file, $export); $zip_folder = new PclZip($temp_zip_file); @@ -330,7 +330,7 @@ if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') { unlink($temp_zip_file); unlink($temp_xml_file); rmdir($temp_zip_dir); - exit (); //otherwise following clicks may become buggy + exit; //otherwise following clicks may become buggy } if (!empty ($_POST['export_user_fields'])) { switch ($_POST['export_user_fields']) { diff --git a/main/exercice/export/exercise_import.inc.php b/main/exercice/export/exercise_import.inc.php index 701c9a4360..034dcadb56 100755 --- a/main/exercice/export/exercise_import.inc.php +++ b/main/exercice/export/exercise_import.inc.php @@ -41,9 +41,6 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) { // upload failed return false; } - - //1- Unzip folder in a new repository - require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php'; $max_filled_space = DocumentManager::get_course_quota(); if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, $max_filled_space , 1)) { diff --git a/main/exercice/export/qti2/qti2_export.php b/main/exercice/export/qti2/qti2_export.php index b53345a16f..1804980875 100755 --- a/main/exercice/export/qti2/qti2_export.php +++ b/main/exercice/export/qti2/qti2_export.php @@ -475,7 +475,4 @@ function export_question($questionId, $standalone=true) $ims = new ImsAssessmentItem($question); return $ims->export($standalone); - -} - -?> +} \ No newline at end of file diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 4afd334f75..ad624a0512 100755 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -2624,6 +2624,7 @@ function checkArchive($path_to_archive) { /** * Extract properties of the files from a ZIP package, write them to disk and * return them as an array. + * @todo this function seems not to be used * @param string Absolute path to the ZIP file * @param bool Whether the ZIP file is compressed (not implemented). Defaults to TRUE. * @return array List of files properties from the ZIP package diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 8acc367a7a..8a0cf96342 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -1997,10 +1997,7 @@ return 'application/octet-stream'; */ public function upload_document($files, $path, $title = '', $comment = '', $unzip = 0, $if_exists = '', $index_document = false, $show_output = false) { require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; - //If we want to unzip a file, we need the library - if (isset($unzip) && intval($unzip) == 1) { - require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; - } + $max_filled_space = self::get_course_quota(); $course_info = api_get_course_info(); $course_dir = $course_info['path'].'/document'; diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 468457a2e8..e6d4f0d8a1 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -561,7 +561,7 @@ function treat_uploaded_file($uploaded_file, $base_work_dir, $upload_path, $max_ * @return boolean true if it succeeds false otherwise */ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_filled_space) { - + require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; $zip_file = new pclZip($uploaded_file['tmp_name']); // Check the zip content (real size and file extension) @@ -675,7 +675,8 @@ function unzip_uploaded_document($uploaded_file, $upload_path, $base_work_dir, $ global $_user; global $to_user_id; global $to_group_id; - + + require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; $zip_file = new pclZip($uploaded_file['tmp_name']); // Check the zip content (real size and file extension) diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 151123121a..5cd683f198 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -5068,4 +5068,14 @@ function api_get_multiple_access_url() { return true; } return false; +} + +/* + * Returns a md5 unique id + * @todo add more parameters + */ + +function api_get_unique_id() { + $id = md5(time().uniqid().api_get_user_id().api_get_course_id().api_get_session_id()); + return $id; } \ No newline at end of file diff --git a/main/newscorm/learnpath_functions.inc.php b/main/newscorm/learnpath_functions.inc.php index 5f7ca073f7..204b79bc0b 100755 --- a/main/newscorm/learnpath_functions.inc.php +++ b/main/newscorm/learnpath_functions.inc.php @@ -1888,6 +1888,7 @@ function deldir($dir) { /** * This functions exports the given path. This is the opener function, which is called first + * @deprecated this function is only called in the newscorm/scorm_admin.php which is deprecated * @param integer The path id * @return resource A zip file, containing a hopefully Scorm compliant course made from the LP. This might happen when we don't actually exit the function first :-) */ @@ -1985,6 +1986,7 @@ function exportpath($learnpath_id) { // 8. Put the files in the exportdir into a zip and force download. include_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; + // Create zipfile of given directory. $zip_folder = new PclZip(api_get_path(SYS_COURSE_PATH).$_course['path']."/temp/".$LPnamesafe.".zip"); @@ -2018,6 +2020,8 @@ function exportpath($learnpath_id) { * * Basically, all this function does is put the scorm directory back into a zip file (like the one * that was most probably used to import the course at first) + * @deprecated this function is only called in the newscorm/scorm_admin.php which is deprecated + * * @param string Name of the SCORM path (or the directory under which it resides) * @param array Not used right now. Should replace the use of global $_course * @return void diff --git a/main/newscorm/lp_list.php b/main/newscorm/lp_list.php index 7890b74f75..61fc8d0ac3 100755 --- a/main/newscorm/lp_list.php +++ b/main/newscorm/lp_list.php @@ -417,22 +417,12 @@ if (is_array($flat_list)) { /* Export */ if ($details['lp_type'] == 1) { - $dsp_disk = - "" . - "" . - "" . - ""; + $dsp_disk = Display::url(Display::return_icon('cd.gif', get_lang('Export'), array(), 22), api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id"); + } elseif ($details['lp_type'] == 2) { - $dsp_disk = - "" . - "" . - "" . - ""; + $dsp_disk = Display::url(Display::return_icon('cd.gif', get_lang('Export'), array(), 22), api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id&export_name=".replace_dangerous_char($name, 'strict').".zip"); } else { - $dsp_disk = - //"" . - "" . //"" . - ""; + $dsp_disk = Display::return_icon('cd_gray.gif', get_lang('Export'), array(), 22); } /* Auto Lunch LP code*/ diff --git a/main/newscorm/scorm.class.php b/main/newscorm/scorm.class.php index 55dd0e2095..c008b0da51 100755 --- a/main/newscorm/scorm.class.php +++ b/main/newscorm/scorm.class.php @@ -468,7 +468,6 @@ class scorm extends learnpath { if ($this->debug > 0) { error_log('In scorm::import_package('.print_r($zip_file_info,true).',"'.$current_dir.'") method', 0); } require_once api_get_path(LIBRARY_PATH).'document.lib.php'; $maxFilledSpace = DocumentManager :: get_course_quota(); - //$maxFilledSpace = 1000000000; $zip_file_path = $zip_file_info['tmp_name']; $zip_file_name = $zip_file_info['name']; diff --git a/main/newscorm/scorm_admin.php b/main/newscorm/scorm_admin.php index 719958091a..98aee3c4fb 100755 --- a/main/newscorm/scorm_admin.php +++ b/main/newscorm/scorm_admin.php @@ -2,6 +2,7 @@ /* For licensing terms, see /license.txt */ // This file is probably deprecated - 2009-05-14 - ywarnier +// No calls found in Chamilo file is deprecated. Adding an exit - 2011-06 jmontoya /** * This script handles SCO administration features * @package chamilo.learnpath.scorm @@ -11,6 +12,8 @@ * @author Yannick Warnier, complete refactoring */ +exit; + // Flag to allow for anonymous user - needs to be set before global.inc.php. $use_anonymous = true; diff --git a/main/upload/upload.document.php b/main/upload/upload.document.php index 20280cf7e3..fcf45aa14d 100755 --- a/main/upload/upload.document.php +++ b/main/upload/upload.document.php @@ -3,6 +3,8 @@ /** * Process part of the document sub-process for upload. This script MUST BE included by upload/index.php * as it prepares most of the variables needed here. + * + * @todo check if this file is deprecated ... jmontoya * @package chamilo.upload * @author Yannick Warnier */ @@ -16,22 +18,10 @@ //many useful functions in main_api.lib.php, by default included if(!function_exists('api_get_path')){header('location: upload.php');die;} -require_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'); -require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php'); -require_once('../document/document.inc.php'); +require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; +require_once api_get_path(LIBRARY_PATH) . 'document.lib.php'; +require_once '../document/document.inc.php'; -//REMOVE -// If we want to unzip a file, we need the library -if (isset($_POST['unzip']) && $_POST['unzip'] == 1) -{ - require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'); -} -/* ------------------------------------------------------------ - Variables - - some need defining before inclusion of libraries ------------------------------------------------------------ -*/ $courseDir = $_course['path']."/document"; $sys_course_path = api_get_path(SYS_COURSE_PATH); $base_work_dir = $sys_course_path.$courseDir; @@ -64,15 +54,9 @@ api_display_tool_title($nameTools.$add_group_to_title); */ //user has submitted a file -if(isset($_FILES['user_upload'])) -{ - //echo("
");
-	//print_r($_FILES['user_upload']);
-	//echo("
"); - +if(isset($_FILES['user_upload'])) { $upload_ok = process_uploaded_file($_FILES['user_upload']); - if($upload_ok) - { + if($upload_ok) { //file got on the server without problems, now process it $new_path = handle_uploaded_document($_course, $_FILES['user_upload'],$base_work_dir,$_POST['curdirpath'],$_user['user_id'],$to_group_id,$to_user_id,$max_filled_space,$_POST['unzip'],$_POST['if_exists']); $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; @@ -133,17 +117,6 @@ if(isset($_POST['create_dir']) && $_POST['dirname']!='') } } -//tracking not needed here? -//event_access_tool(TOOL_DOCUMENT); - -/*============================================================================*/ -?> - -

- + +Display::display_footer(); \ No newline at end of file diff --git a/main/work/downloadfolder.inc.php b/main/work/downloadfolder.inc.php index e470947ce3..0ee8ad869d 100755 --- a/main/work/downloadfolder.inc.php +++ b/main/work/downloadfolder.inc.php @@ -3,7 +3,7 @@ /** * Functions and main code for the download folder feature - * + * @todo use ids instead of the path like the document tool * @package chamilo.work */ @@ -13,51 +13,28 @@ if (empty($path)) { $path = '/'; } +if (empty($_course) || empty($_course['path'])) { + api_not_allowed(); +} +$sys_course_path = api_get_path(SYS_COURSE_PATH); + //zip library for creation of the zipfile require api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'; -//we need this path to clean it out of the zip file -//I'm not using dirname as it gives too much problems (cfr. \) -$remove_dir = ($path != '/') ? substr($path, 0, strlen($path) - strlen(basename($path))) : '/'; - -//place to temporarily stash the zipfiles -$temp_zip_dir = $sys_course_path.$_course['path'].'/temp'; -//create the temp dir if it doesn't exist -//or do a cleanup befor creating the zipfile +//Creating a ZIP file +$temp_zip_file = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip"; -if (!is_dir($temp_zip_dir)) { - mkdir($temp_zip_dir, api_get_permissions_for_new_directories()); -} else { - //cleanup: check the temp dir for old files and delete them - $handle = opendir($temp_zip_dir); - while (false !== ($file = readdir($handle))) { - if ($file != '.' && $file != '..') { - //the "age" of the file in hours - $Diff = (time() - filemtime("$temp_zip_dir/$file"))/60/60; - //delete files older than 4 hours - if ($Diff > 4) { - unlink("$temp_zip_dir/$file"); - } - } - } - closedir($handle); -} - -//create zipfile of given directory -$temp_zip_file = $temp_zip_dir."/".md5(time()).".zip"; $zip_folder = new PclZip($temp_zip_file); + $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION); -$prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); +$prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); + //Put the files in the zip //2 possibilities: admins get all files and folders in the selected folder (except for the deleted ones) //normal users get only visible files that are in visible folders //admins are allowed to download invisible files if (api_is_allowed_to_edit()) { - //folder we want to zip --> no longer used, deleted files are included too like this - //$what_to_zip = $sys_course_path.$_course['path']."/document".$path; - //creation of the zipped folder - //$zip_folder->create($what_to_zip ,PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path']."/document".$remove_dir ); //set the path that will be used in the query if ($path == '/') { $querypath = ''; // to prevent ...path LIKE '//%'... in query @@ -69,9 +46,9 @@ if (api_is_allowed_to_edit()) { $query = Database::query("SELECT url FROM $tbl_student_publication AS work, $prop_table AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'2'"); //add tem to the zip file - while ($not_deleted_file = Database::fetch_assoc($query)) { //var_dump($sys_course_path.$_course['path'].'/'.$not_deleted_file['url']);exit(); - $zip_folder->add($sys_course_path.$_course['path'].'/'.$not_deleted_file['url'], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work'.$remove_dir); - } + while ($not_deleted_file = Database::fetch_assoc($query)) { + $zip_folder->add($sys_course_path.$_course['path'].'/'.$not_deleted_file['url'], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work'); + } } else { //for other users, we need to create a zipfile with only visible files and folders @@ -94,7 +71,7 @@ if (api_is_allowed_to_edit()) { } //2nd: get all folders that are invisible in the given path $query2 = Database::query("SELECT url FROM $tbl_student_publication AS work, $prop_table AS props - WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'1' AND props.lastedit_user_id='".api_get_user_id()."'"); + WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'1' AND props.lastedit_user_id='".api_get_user_id()."'"); //if we get invisible folders, we have to filter out these results from all visible files we found @@ -128,9 +105,9 @@ event_download(basename($path).'.zip (folder)'); //start download of created file $name = basename($path).'.zip'; -if (Security::check_abs_path($temp_zip_file, $temp_zip_dir.'/')) { - DocumentManager::file_send_for_download($temp_zip_file, true, $name); - @unlink($temp_zip_file); +if (Security::check_abs_path($temp_zip_file, api_get_path(SYS_ARCHIVE_PATH))) { + DocumentManager::file_send_for_download($temp_zip_file, true, $name); + @unlink($temp_zip_file); exit; } diff --git a/main/work/work.lib.php b/main/work/work.lib.php index d83460078e..bbc6e60bde 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -693,8 +693,8 @@ function display_student_publications_list($work_dir, $sub_course_dir, $currentC $count_document = Database::fetch_row($res_document); $cant_files = $count_document[0]; //count directories - $sql_directory = "SELECT count(*) FROM $work_table s WHERE url NOT LIKE '/".$mydir."/%/%' AND url LIKE '/".$mydir."/%'"; - $res_directory = Database::query($sql_directory); + $sql_directory = "SELECT count(*) FROM $work_table s WHERE url NOT LIKE '/".$mydir."/%/%' AND url LIKE '/".$mydir."/%'"; + $res_directory = Database::query($sql_directory); $count_directory = Database::fetch_row($res_directory); $cant_dir = $count_directory[0]; @@ -737,10 +737,11 @@ function display_student_publications_list($work_dir, $sub_course_dir, $currentC $add_to_name = ''; } $show_as_icon = get_work_id($mydir); //true or false + if ($show_as_icon) { - if (is_allowed_to_edit()) { - $zip=' - '.Display::return_icon('save_pack.png', get_lang('Save'),array('style' => 'float:right;'), 22).''; + if (api_is_allowed_to_edit()) { + $zip = ' + '.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), 22).''; } $row[] = $zip.''.$dir.''.$add_to_name.'
'.$cant_files.' '.$text_file.$dirtext; } else { @@ -1465,7 +1466,7 @@ function to_javascript_work() { function get_work_id($path) { $TBL_STUDENT_PUBLICATION = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); $TBL_PROP_TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY); - if (is_allowed_to_edit()) { + if (api_is_allowed_to_edit()) { $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2'"; } else { $sql = "SELECT work.id FROM $TBL_STUDENT_PUBLICATION AS work,$TBL_PROP_TABLE AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work/".$path."%' AND work.filetype='file' AND props.visibility<>'2' AND props.lastedit_user_id='".api_get_user_id()."'"; diff --git a/tests/main/dropbox/dropbox_functions.inc.test.php b/tests/main/dropbox/dropbox_functions.inc.test.php old mode 100644 new mode 100755 index 4bb9316f1a..f367dab382 --- a/tests/main/dropbox/dropbox_functions.inc.test.php +++ b/tests/main/dropbox/dropbox_functions.inc.test.php @@ -415,30 +415,6 @@ class TestDropboxFunctions extends UnitTestCase { } */ - /** - * This function is an alternative zip download. It was added because PCLZip causes problems on PHP5 when using PCLZIP_CB_PRE_ADD and a callback function to rename - * the files inside the zip file (dropbox scrambles the files to prevent - * @todo consider using a htaccess that denies direct access to the file but only allows the php file to access it. This would remove the scrambling requirement - * but it would require additional checks to see if the filename of the uploaded file is not used yet. - * @param $files is an associative array that contains the files that the user wants to download (check to see if the user is allowed to download these files already - * happened so the array is clean!!. The key is the filename on the filesystem. The value is an array that contains both the filename on the filesystem and - * the original filename (that will be used in the zip file) - * @todo when we copy the files there might be two files with the same name. We need a function that (recursively) checks this and changes the name - */ -/* - function testzip_download_alternative() { - global $_course; - global $_user; - $files = 'test'; - $res= zip_download_alternative($files); - if(!is_null($res)){ - $this->assertTrue(is_string($res)); - } - //var_dump($res); - } -*/ - - /** * Function that finds a given config setting */