Should fix bug when exporting a LP to a zip see #4706, requires some changes in courses/.htaccess

skala
Julio Montoya 13 years ago
parent 3448d50a84
commit 587634649c
  1. 64
      main/document/download_scorm.php
  2. 54
      main/exercice/export/scorm/scorm_export.php
  3. 22
      main/install/htaccess.dist
  4. 103
      main/newscorm/learnpath.class.php
  5. 5
      main/newscorm/lp_view.php

@ -0,0 +1,64 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file is responsible for passing requested documents to the browser.
*
* @package chamilo.document
*/
/**
* Code
*/
session_cache_limiter('none');
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
// Protection
api_protect_course_script();
if (!isset($_course)) {
api_not_allowed(true);
}
// If LP obj exists
if (isset($_SESSION['oLP'])) {
$obj = $_SESSION['oLP'];
} else {
api_not_allowed();
}
//If is visible for the current user
if (!$obj->is_lp_visible_for_student($obj->get_id(), api_get_user_id())) {
api_not_allowed();
}
$doc_url = isset($_GET['url']) ? $_GET['url'] : null;
// Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
$doc_url = str_replace('///', '&', $doc_url);
// Still a space present? it must be a '+' (that got replaced by mod_rewrite)
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url;
if (strpos($doc_url,'../') OR strpos($doc_url,'/..')) {
$doc_url = '';
}
$sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm';
//var_dump($sys_course_path);
if (is_dir($sys_course_path.$doc_url)) {
api_not_allowed();
}
if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
$full_file_name = $sys_course_path.$doc_url;
// Launch event
event_download($doc_url);
DocumentManager::file_send_for_download($full_file_name);
}
exit;

@ -73,37 +73,40 @@ class ScormAssessmentItem
* End the XML flow, closing the </item> tag.
*
*/
function end_page()
{
function end_page() {
if($this->standalone){return '</html>';}
return '';
}
/**
* Start document header
*/
function start_header()
{
function start_header() {
if($this->standalone){return '<head>'. "\n";}
return '';
}
/**
* Print CSS inclusion
*/
function css() {
if($this->standalone) {
$css = '';
if ($this->standalone) {
$css = '<style type="text/css" media="screen, projection">'."\n";
$css .= '/*<![CDATA[*/'."\n";
$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/default.css";'."\n";
//$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/default.css";'."\n";
$css .= '/*]]>*/'."\n";
$css .= '</style>'."\n";
$css .= '<style type="text/css" media="print">'."\n";
$css .= '/*<![CDATA[*/'."\n";
$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/print.css";'."\n";
//$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/print.css";'."\n";
$css .= '/*]]>*/'."\n";
$css .= '</style>'."\n";
return $css;
$css .= '</style>'."\n";
}
return '';
return $css;
}
/**
@ -262,27 +265,26 @@ class ScormSection
var $exercise;
/**
* Constructor.
* @param $exe The Exercise instance to export
* @author Amand Tihon <amand@alrj.org>
*/
* Constructor.
* @param $exe The Exercise instance to export
* @author Amand Tihon <amand@alrj.org>
*/
function ScormSection($exe) {
$this->exercise = $exe;
}
/**
* Start the XML flow.
*
* This opens the <item> block, with correct attributes.
*
*/
function start_page() {
/**
* Start the XML flow.
*
* This opens the <item> block, with correct attributes.
*
*/
function start_page() {
global $charset;
$head = $foot = "";
$head = '<?xml version="1.0" encoding="'.$charset.'" standalone="no"?>' . "\n".'<html>'."\n";
$head = '<?xml version="1.0" encoding="'.$charset.'" standalone="no"?>' . "\n".'<html>'."\n";
return $head;
}
}
/**
* End the XML flow, closing the </item> tag.
@ -305,12 +307,12 @@ class ScormSection
function css() {
$css = '<style type="text/css" media="screen, projection">'."\n";
$css .= '/*<![CDATA[*/'."\n";
$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/default.css";'."\n";
//$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/default.css";'."\n";
$css .= '/*]]>*/'."\n";
$css .= '</style>'."\n";
$css .= '<style type="text/css" media="print">'."\n";
$css .= '/*<![CDATA[*/'."\n";
$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/print.css";'."\n";
//$css .= '@import "'.api_get_path(WEB_PATH).'main/css/public_admin/print.css";'."\n";
$css .= '/*]]>*/'."\n";
$css .= '</style>'."\n";
return $css;

@ -1,22 +1,26 @@
###########################################################################################
#change this file to fit your configuration and save it as .htaccess in the courses folder#
###########################################################################################
#chamilo mod rewrite
#comment lines start with # and are not processed
# Change this file to fit your configuration and save it as .htaccess in the courses folder #
# Chamilo mod rewrite
# Comment lines start with # and are not processed
<IfModule mod_rewrite.c>
RewriteEngine On
#rewrite base is the dir chamilo is installed in with trailing slash
# Rewrite base is the dir chamilo is installed in with trailing slash
RewriteBase {CHAMILO_URL_APPEND_PATH}/courses/
#do not rewrite on the main dir
#change this path to the path of your main folder
# Do not rewrite on the main dir
# Change this path to the path of your main folder
RewriteCond %{REQUEST_URI} !^{CHAMILO_URL_APPEND_PATH}/main/
#replace nasty ampersands by 3 slashes, we change these back in download.php
RewriteRule ([^/]+)/document/(.*)&(.*)$ $1/document/$2///$3 [N]
#rewrite everything in the document folder of a course to the download script
# Rewrite everything in the scorm folder of a course to the download script
RewriteRule ([^/]+)/scorm/(.*)$ {CHAMILO_URL_APPEND_PATH}/main/document/download_scorm.php?doc_url=/$2&cDir=$1 [QSA,L]
# Rewrite everything in the document folder of a course to the download script
RewriteRule ([^/]+)/document/(.*)$ {CHAMILO_URL_APPEND_PATH}/main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L]
# Rewrite everything in the work folder
RewriteRule ([^/]+)/work/(.*)$ {CHAMILO_URL_APPEND_PATH}/main/work/download.php?file=work/$2&cDir=$1 [QSA,L]
</IfModule>

@ -1991,7 +1991,6 @@ class learnpath {
return $output;
}
/**
* This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
* @param int Learnpath id
@ -8225,6 +8224,7 @@ class learnpath {
// Check type of URL.
//error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
if ($doc_info[1] == 'remote') {
// Remote file. Save url as is.
$my_dep_file->setAttribute('href', $doc_info[0]);
@ -8286,23 +8286,24 @@ class learnpath {
//error_log(__LINE__.'Abs path: '.$file_path, 0);
// Prepare the current directory path (until just under 'document') with a trailing slash.
$cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
// Check if the current document is in that path.
// Check if the current document is in that path.
if (strstr($file_path, $cur_path) !== false) {
// The document is in that path, now get the relative path
// to the containing document.
$orig_file_path = dirname($cur_path.$my_file_path).'/';
$orig_file_path = str_replace('\\', '/', $orig_file_path);
$relative_path = '';
if (strstr($file_path, $cur_path) !== false) {
if (strpos($orig_file_path, $file_path) == false) {
$relative_path = '';
if (strstr($file_path, $cur_path) !== false) {
if (strpos($orig_file_path, $file_path) == false) {
//no need to do something
$file_path = $relative_path = substr($file_path, strlen($cur_path));
$file_path = $relative_path = substr($file_path, strlen($cur_path));
//$file_path = substr($file_path, strlen($cur_path));
//$relative_path = str_replace('document/', '', $file_path);
} else {
$relative_path = substr($file_path, strlen($orig_file_path));
$file_path = substr($file_path, strlen($cur_path));
}
}
} else {
// This case is still a problem as it's difficult to calculate a relative path easily
// might still generate wrong links.
@ -8365,13 +8366,12 @@ class learnpath {
case 'rel': // Path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
if (substr($doc_info[0], 0, 2) == '..') {
// Relative path going up.
$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
$current_dir = str_replace('\\', '/', $current_dir);
$file_path = realpath($current_dir.$doc_info[0]);
$file_path = str_replace('\\', '/', $file_path);
//error_log($file_path.' <-> '.$main_path,0);
if (strstr($file_path, $main_path) !== false) {
// The calculated real path is really inside Chamilo's root path.
@ -8549,7 +8549,7 @@ class learnpath {
// Get included docs.
$inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
// Dependency to other files - not yet supported.
$i = 1;
$i = 1;
foreach ($inc_docs as $doc_info) {
if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
$my_dep = $xmldoc->createElement('resource');
@ -8572,7 +8572,7 @@ class learnpath {
$current_dir = dirname($abs_path);
$current_dir = str_replace('\\', '/', $current_dir);
$file_path = realpath($abs_path);
$file_path = str_replace('\\', '/', $file_path);
$file_path = str_replace('\\', '/', $file_path);
$my_dep_file->setAttribute('href', 'document/'.$file_path);
$my_dep->setAttribute('xml:base', '');
if (strstr($file_path, $main_path) !== false) {
@ -8654,21 +8654,20 @@ class learnpath {
$info_file_path = explode('/', $file_path);
if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
$file_path_dest = 'document/'.$file_path;
}
}
//error_log('Reduced path: '.$file_path, 0);
$zip_files_abs[] = $file_path;
$link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
$my_dep_file->setAttribute('href', 'document/'.$file_path);
$my_dep->setAttribute('xml:base', '');
$my_dep->setAttribute('xml:base', '');
}
} else {
$zip_files[] = $my_sub_dir.'/'.$doc_info[0];
$my_dep_file->setAttribute('href', $doc_info[0]);
$my_dep->setAttribute('xml:base', $my_xml_sub_dir);
}
break;
default:
$my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
@ -8743,11 +8742,17 @@ class learnpath {
//echo $main_path.$file_path.'<br />';
@copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
// Check if the file needs a link update
if (in_array($file_path, array_keys($link_updates))) {
$count_parents = explode('/', $file_path);
$count_parents = count($count_parents) - 1;
$mult = str_repeat('../', $count_parents);
$string = file_get_contents($dest_file);
unlink($dest_file);
foreach ($link_updates[$file_path] as $old_new) {
//error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
// This is an ugly hack that allows .flv files to be found by the flv player that
@ -8759,14 +8764,19 @@ class learnpath {
} elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
$old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
}
$string = str_replace($old_new['orig'], $old_new['dest'], $string);
$new_dest = str_replace('document/', $mult.'document/', $old_new['dest']);
//$string = str_replace($old_new['orig'], $old_new['dest'], $string);
$string = str_replace($old_new['orig'], $new_dest, $string);
//var_dump($old_new['orig'], $old_new['dest']); echo '--> ';
//var_dump($new_path);
//Add files inside the HTMLs
$new_path = str_replace('/courses/', '', $old_new['orig']);
/*var_dump($sys_course_path.$new_path);
var_dump($archive_path.$temp_dir_short.'/document/'.$old_new['dest']);
echo '---';*/
copy($sys_course_path.$new_path, $archive_path.$temp_dir_short.'/document/'.$old_new['dest']);
//var_dump($sys_course_path.$new_path); var_dump($archive_path.$temp_dir_short.'/'.$old_new['dest']); echo '---';
copy($sys_course_path.$new_path, $archive_path.$temp_dir_short.'/'.$old_new['dest']);
}
file_put_contents($dest_file, $string);
@ -8785,6 +8795,7 @@ class learnpath {
//echo $main_path.$file_path.' - '.$dest_file.'<br />';
copy($main_path.$file_path, $dest_file);
// Check if the file needs a link update.
if (in_array($file_path, array_keys($link_updates))) {
$string = file_get_contents($dest_file);
@ -8806,33 +8817,29 @@ class learnpath {
if (is_array($links_to_create)) {
foreach ($links_to_create as $file => $link) {
$file_content = '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
<head>
<title>'.$link['title'].'</title>
<meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
</head>
<body dir="'.api_get_text_direction().'">
<div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
</body>
</html>';
file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
$file_content = '<!DOCTYPE html>
<head>
<meta charset="'.api_get_language_isocode().'" />
<title>'.$link['title'].'</title>
</head>
<body dir="'.api_get_text_direction().'">
<div style="text-align:center">
<a href="'.$link['url'].'">'.$link['title'].'</a></div>
</body>
</html>';
file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
}
}
// Add non exportable message explanation.
$lang_not_exportable = get_lang('ThisItemIsNotExportable');
$file_content = '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
<head>
<title>'.$lang_not_exportable.'</title>
<meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
</head>
<body dir="'.api_get_text_direction().'">';
$file_content = '<!DOCTYPE html>
<head>
<meta charset="'.api_get_language_isocode().'" />
<title>'.$lang_not_exportable.'</title>
<meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
</head>
<body dir="'.api_get_text_direction().'">';
$file_content .=
<<<EOD
<style>
@ -8881,13 +8888,15 @@ EOD;
$manifest = @$xmldoc->saveXML();
$manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
$zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
$zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
// Clean possible temporary files.
foreach ($files_cleanup as $file) {
$res = unlink($file);
if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
}
// Send file to client.
//$name = 'scorm_export_'.$this->lp_id.'.zip';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';

@ -396,10 +396,11 @@ if (Database::num_rows($res_media) > 0) {
<div id="learning_path_right_zone" style="margin-left:<?php echo $margin_left;?>;height:100%">
<?php
// hub 26-05-2010 Fullscreen or not fullscreen
$height = '100%';
if ($_SESSION['oLP']->mode == 'fullscreen') {
echo '<iframe id="content_id_blank" name="content_name_blank" src="blank.php" border="0" frameborder="0" style="width:100%;height:600px" ></iframe>';
echo '<iframe id="content_id_blank" name="content_name_blank" src="blank.php" border="0" frameborder="0" style="width:100%;height:'.$height.'" ></iframe>';
} else {
echo '<iframe id="content_id" name="content_name" src="'.$src.'" border="0" frameborder="0" style="display: block; width:100%;height:600px"></iframe>';
echo '<iframe id="content_id" name="content_name" src="'.$src.'" border="0" frameborder="0" style="display: block; width:100%;height:'.$height.'"></iframe>';
}
?>
</div>

Loading…
Cancel
Save