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

skala
Julio Montoya 14 years ago
parent 15ac06c527
commit 71e4a057a0
  1. 28
      main/admin/special_exports.php
  2. 8
      main/course_info/download.php
  3. 26
      main/coursecopy/classes/CourseArchiver.class.php
  4. 4
      main/coursecopy/classes/CourseBuilder.class.php
  5. 9
      main/coursecopy/create_backup.php
  6. 2
      main/document/document.inc.php
  7. 18
      main/document/document.php
  8. 89
      main/document/downloadfolder.inc.php
  9. 174
      main/dropbox/dropbox_functions.inc.php
  10. 101
      main/dropbox/dropbox_submit.php
  11. 12
      main/dropbox/index.php
  12. 8
      main/exercice/admin.php
  13. 6
      main/exercice/exercice.php
  14. 3
      main/exercice/export/exercise_import.inc.php
  15. 5
      main/exercice/export/qti2/qti2_export.php
  16. 1
      main/inc/lib/add_course.lib.inc.php
  17. 5
      main/inc/lib/document.lib.php
  18. 5
      main/inc/lib/fileUpload.lib.php
  19. 10
      main/inc/lib/main_api.lib.php
  20. 4
      main/newscorm/learnpath_functions.inc.php
  21. 18
      main/newscorm/lp_list.php
  22. 1
      main/newscorm/scorm.class.php
  23. 3
      main/newscorm/scorm_admin.php
  24. 49
      main/upload/upload.document.php
  25. 59
      main/work/downloadfolder.inc.php
  26. 13
      main/work/work.lib.php
  27. 24
      tests/main/dropbox/dropbox_functions.inc.test.php

@ -1,17 +1,18 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
/* For licensing terms, see /license.txt */
/**
* Special exports
*
* @author Jhon Hinojosa <jhon.hinojosa@dokeos.com>
* @author Jhon Hinojosa
* @author Julio Montoya Fixing pclzip folder + some clean <gugli100@gmail.com>
* @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').'<br /><br /><a class="bottom-link" href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.urlencode($name).'&session=true">'.$name.'</a>', false);
echo '<p><a class="bottom-link" href="'.api_get_path(WEB_CODE_PATH).'admin/index.php">&nbsp;'.get_lang('MainMenu').'</a></p>';
} else{
Display::display_confirmation_message(get_lang('BackupCreated'));
echo '<br /><a class="a_button orange medium" href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.urlencode($name).'&session=true">'.get_lang('Download').'</a>';
} else {
// Display forms especial export
if (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
$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,

@ -1,7 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
//session_cache_limiter('public');
require '../inc/global.inc.php';
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
@ -20,7 +20,7 @@ $archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
list($extension) = getextension($archive_file);
if (empty($extension) || !file_exists($archive_path.$archive_file)) {
exit();
exit;
}
$extension = strtolower($extension);
@ -47,5 +47,5 @@ if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
header('Content-Disposition: attachment; filename='.$archive_file);
readfile($archive_path.$archive_file);
} else {
exit;
}
api_not_allowed(true);
}

@ -36,19 +36,19 @@ class CourseArchiver
* Write a course and all its resources to a zip-file.
* @return string A pointer to the zip-file
*/
function write_course($course)
{
function write_course($course) {
$perm_dirs = api_get_permissions_for_new_directories();
CourseArchiver::clean_backup_dir();
// Create a temp directory
$tmp_dir_name = 'CourseArchiver_'.uniqid('');
$backup_dir = api_get_path(SYS_ARCHIVE_PATH).''.$tmp_dir_name.'/';
$tmp_dir_name = 'CourseArchiver_'.api_get_unique_id();
$backup_dir = api_get_path(SYS_ARCHIVE_PATH).$tmp_dir_name.'/';
// All course-information will be stored in course_info.dat
$course_info_file = $backup_dir.'course_info.dat';
$zip_dir = api_get_path(SYS_ARCHIVE_PATH).'';
$zip_dir = api_get_path(SYS_ARCHIVE_PATH);
$user = api_get_user_info();
$zip_file = $user['user_id'].'_'.$course->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;
}
}
?>
}

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

@ -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('<br />', 3).'<a class="bottom-link" href="../course_info/download.php?archive='.$zip_file.'">'.$zip_file.'</a>', false);
echo '<div style="width:200px"><a class="bottom-link" href="'.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php" >'.get_lang('CourseHomepage').'</a></div>';
$zip_file = CourseArchiver :: write_course($course);
Display::display_confirmation_message(get_lang('BackupCreated'));
echo '<br /><a class="a_button orange medium" href="../course_info/download.php?archive='.$zip_file.'">'.get_lang('Download').'</a>';
?>
<!-- Manual download <script language="JavaScript">
setTimeout('download_backup()',2000);
@ -101,4 +102,4 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
}
/* FOOTER */
Display::display_footer();
Display::display_footer();

@ -129,7 +129,7 @@ function create_document_link($document_data, $show_as_icon = false, $counter =
if (!$show_as_icon) {
// Build download link (icon)
$forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&path='.$url_path.$req_gid : api_get_self().'?'.api_get_cidreq().'&amp;action=download&amp;id='.$url_path.$req_gid;
$forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&id='.$document_data['id'] : api_get_self().'?'.api_get_cidreq().'&amp;action=download&amp;id='.$document_data['id'];
// Folder download or file download?
$forcedownload_icon = ($filetype == 'folder') ? 'save_pack.png' : 'save.png';
// Prevent multiple clicks on zipped folder download

@ -257,10 +257,10 @@ if ($current_session_id == 0) {
/* MAIN SECTION */
if (isset($_GET['action']) && $_GET['action'] == 'download') {
$my_get_id = Security::remove_XSS($_GET['id']);
$my_get_id = intval($_GET['id']);
$document_data = DocumentManager::get_document_data_by_id($my_get_id, api_get_course_id());
// Check whether the document is in the database
if (!DocumentManager::get_document_id($_course, $my_get_id)) {
if (empty($document_data)) {
// File not found!
header('HTTP/1.0 404 Not Found');
$error404 = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
@ -274,17 +274,13 @@ if (isset($_GET['action']) && $_GET['action'] == 'download') {
echo $error404;
exit;
}
// Launch event
event_download($my_get_id);
event_download($document_data['url']);
// Check visibility of document and paths
if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible($my_get_id, $_course, api_get_session_id())) {
if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible_by_id($my_get_id, $_course, api_get_session_id(), 'file' )) {
api_not_allowed(true);
}
$doc_url = $my_get_id;
$full_file_name = $base_work_dir.$doc_url;
$full_file_name = $base_work_dir.$document_data['path'];
if (Security::check_abs_path($full_file_name, $base_work_dir.'/')) {
DocumentManager::file_send_for_download($full_file_name, true);
}
@ -1076,7 +1072,7 @@ if (!is_null($docs_and_folders)) {
//for student does not show icon into other shared folder, and does not show into main path (root)
if (is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id) && $curdirpath!='/' || api_is_allowed_to_edit() || api_is_platform_admin()) {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=downloadfolder&amp;path='.$curdirpathurl.'">'.Display::return_icon('save_pack.png', get_lang('Save').' (ZIP)','','32').'</a>';
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=downloadfolder&amp;id='.$document_id.'">'.Display::return_icon('save_pack.png', get_lang('Save').' (ZIP)','','32').'</a>';
}
}
}

@ -9,17 +9,15 @@
set_time_limit(0);
$path = $_GET['path'];
$document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id());
$path = $document_data['path'];
// Prevent some stuff
if (empty($path)) {
$path = '/';
}
// Check to see if they want to download an existing folder
if (($path != '/') && (!DocumentManager::get_document_id($_course, $path))) {
$path = '/';
if (empty($document_data)) {
api_not_allowed();
}
if (empty($path)) {
$path = '/';
}
//a student should not be able to download a root shared directory
if (($path == '/shared_folder' || $path=='/shared_folder_session_'.api_get_session_id()) && (!api_is_allowed_to_edit() || !api_is_platform_admin())){
@ -30,63 +28,44 @@ if (($path == '/shared_folder' || $path=='/shared_folder_session_'.api_get_sessi
}
//zip library for creation of the zipfile
include api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
require api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
//Creating a ZIP file
$temp_zip_file = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip";
$zip_folder = new PclZip($temp_zip_file);
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
$prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
// 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
if (!is_dir($temp_zip_dir)) {
mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
}
// Cleanup: check the temp dir for old files and delete them
else {
$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);
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
$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 (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 );
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('</pre>');
// 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.'<br>');
//echo('<b>FILES FOR ZIP</b><br />');
//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].'<br />';
}
} // 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

@ -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 <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, 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.

@ -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
<?php
}
}
*/
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', '').'>';
}
}
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>";
}
}
/**

@ -285,9 +285,9 @@ if ($_GET['action'] != 'add') {
if (api_get_session_id() == 0) {
echo '<div class="actions">';
if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32')."</a>";
echo get_lang('Category').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
$movelist[0] = 'Root'; // move_received selectbox content
} else {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32').'</a>';
@ -296,9 +296,9 @@ if ($_GET['action'] != 'add') {
} else {
if (api_is_allowed_to_session_edit(false, true)) {
echo '<div class="actions">';
if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32')."</a>";
echo get_lang('Category').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
$movelist[0] = 'Root'; // move_received selectbox content
} else {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32').'</a>';
@ -322,9 +322,9 @@ if ($_GET['action'] != 'add') {
if (api_get_session_id() == 0) {
echo '<div class="actions">';
if ($view_dropbox_category_sent != 0) {
echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].'</strong> ';
if ($view_dropbox_category_sent != 0) {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category=0&amp;view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32')."</a>";
echo get_lang('Category').': <strong>'.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].'</strong> ';
} else {
echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&amp;action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32')."</a>\n";
}

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

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

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

@ -475,7 +475,4 @@ function export_question($questionId, $standalone=true)
$ims = new ImsAssessmentItem($question);
return $ims->export($standalone);
}
?>
}

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

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

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

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

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

@ -417,22 +417,12 @@ if (is_array($flat_list)) {
/* Export */
if ($details['lp_type'] == 1) {
$dsp_disk =
"<a href='".api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id'>" .
"<img src=\"../img/icons/22/export_scorm.png\" border=\"0\" title=\"".get_lang('Export')."\">" .
"</a>" .
"";
$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 =
"<a href='".api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id&export_name=".replace_dangerous_char($name, 'strict').".zip'>" .
"<img src=\"../img/icons/22/export_scorm.png\" border=\"0\" title=\"".get_lang('Export')."\">" .
"</a>" .
"";
$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 =
//"<a href='".api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id'>" .
"<img src=\"../img/cd_gray.gif\" border=\"0\" title=\"".get_lang('Export')."\">" . //"</a>" .
"";
$dsp_disk = Display::return_icon('cd_gray.gif', get_lang('Export'), array(), 22);
}
/* Auto Lunch LP code*/

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

@ -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 <ywarnier@beeznest.org>
*/
exit;
// Flag to allow for anonymous user - needs to be set before global.inc.php.
$use_anonymous = true;

@ -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 <ywarnier@beeznest.org>
*/
@ -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("<pre>");
//print_r($_FILES['user_upload']);
//echo("</pre>");
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);
/*============================================================================*/
?>
<?php
//=======================================//
//they want to create a new directory//
//=======================================//
if(isset($_GET['createdir']))
{
//create the form that asks for the directory name
@ -220,10 +193,6 @@ if(api_get_setting('use_document_title')=='true')
<!-- so they can get back to the documents -->
<p><?php echo (get_lang('Back'));?> <?php echo (get_lang('To'));?> <a href="document.php?curdirpath=<?php echo $path; ?>"><?php echo (get_lang('DocumentsOverview'));?></a></p>
<?php
/*
FOOTER
*/
Display::display_footer();
?>
Display::display_footer();

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

@ -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='<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&gradebook='.$gradebook.'&action=downloadfolder&path=/'.$mydir.'">
'.Display::return_icon('save_pack.png', get_lang('Save'),array('style' => 'float:right;'), 22).'</a>';
if (api_is_allowed_to_edit()) {
$zip = '<a href="'.api_get_self().'?cidReq='.api_get_course_id().'&gradebook='.$gradebook.'&action=downloadfolder&path=/'.$mydir.'">
'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), 22).'</a>';
}
$row[] = $zip.'<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&curdirpath='.$mydir.'"'.$class.'>'.$dir.'</a>'.$add_to_name.'<br />'.$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()."'";

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

Loading…
Cancel
Save