Fix use of course_info/download.php

Load course backup path by default otherwise
it uses the root of archive path.
pull/2487/head
jmontoyaa 9 years ago
parent 7856e918f8
commit 0daef52f15
  1. 6
      main/admin/course_export.php
  2. 4
      main/admin/settings.lib.php
  3. 46
      main/admin/special_exports.php
  4. 8
      main/course_info/download.php
  5. 2
      main/inc/lib/myspace.lib.php
  6. 1
      main/inc/lib/pdf.lib.php
  7. 11
      main/session/session_export.php
  8. 16
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php
  9. 11
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php
  10. 1
      tests/test_suite.php

@ -18,9 +18,6 @@ $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAd
set_time_limit(0);
$archivePath = api_get_path(SYS_ARCHIVE_PATH);
$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
$course_list = CourseManager::get_courses_list();
$formSent = null;
$courses = $selected_courses = array();
@ -47,9 +44,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
}
if (!empty($courses)) {
$archiveFile = 'export_courses_list_'.api_get_local_time();
$listToExport[] = [
'Code',
'Title',
@ -117,7 +112,6 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
}
}
Display:: display_header($tool_name);
$form = new FormValidator('export', 'post', api_get_self());

@ -1711,8 +1711,10 @@ function generateCSSDownloadLink($style)
$zip = new PclZip($arch);
// Remove path prefix except the style name and put file on disk
$zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir,0,-strlen($style)));
$url = api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive_path=&archive=' . str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch);
//@TODO: use more generic script to download.
$str = '<a class="btn btn-primary btn-large" href="' . api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=' . str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch) . '">'.get_lang('ClickHereToDownloadTheFile').'</a>';
$str = '<a class="btn btn-primary btn-large" href="' .$url. '">'.get_lang('ClickHereToDownloadTheFile').'</a>';
Display::display_normal_message($str, false);
} else {
Display::addFlash(Display::return_message(get_lang('FileNotFound'), 'warning'));

@ -22,6 +22,7 @@ $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAd
api_protect_admin_script(true);
$nameTools = get_lang('SpecialExports');
$export = '';
$querypath = '';
// include additional libraries
if (function_exists('ini_set')) {
@ -43,10 +44,10 @@ $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') ||
(isset ($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')
(isset($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')
) {
$export = false;
if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
$FileZip = create_zip();
$to_group_id = 0;
$sql_session = "SELECT id, name FROM $tbl_session ";
@ -61,7 +62,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') ||
$groupCondition = " (props.to_group_id = 0 OR props.to_group_id IS NULL)";
}
$zip_folder=new PclZip($FileZip['TEMP_FILE_ZIP']);
$zip_folder = new PclZip($FileZip['TEMP_FILE_ZIP']);
if (!isset($_POST['resource']) || count($_POST['resource']) == 0) {
Display::display_error_message(get_lang('ErrorMsgSpecialExport'));
} else {
@ -130,7 +131,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') ||
if ($export && $name) {
Display::display_confirmation_message(get_lang('BackupCreated'));
echo '<br /><a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.urlencode($name).'&session=true">'.get_lang('Download').'</a>';
echo '<br /><a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive='.urlencode($name).'">'.get_lang('Download').'</a>';
} else {
// Display forms especial export
if (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
@ -153,7 +154,7 @@ Display::display_footer();
function form_special_export()
{
$form = new FormValidator('special_exports','post');
$form = new FormValidator('special_exports', 'post');
$renderer = $form->defaultRenderer();
$renderer->setCustomElementTemplate('<div>{element}</div> ');
$form->addElement('radio', 'backup_option', '', get_lang('SpecialCreateFullBackup'), 'full_backup');
@ -173,9 +174,9 @@ function create_zip()
$path = '/';
}
$remove_dir = ($path != '/') ? substr($path, 0, strlen($path) - strlen(basename($path))) : '/';
$sys_archive_path = api_get_path(SYS_ARCHIVE_PATH);
$sys_archive_path = api_get_path(SYS_ARCHIVE_PATH).'special_export/';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$temp_zip_dir = $sys_archive_path."temp";
$temp_zip_dir = $sys_archive_path;
if (!is_dir($temp_zip_dir)) {
mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
} else {
@ -237,8 +238,8 @@ function fullexportspecial()
}
if (count($list_course) > 0) {
foreach($list_course as $_course) {
if($FileZip['PATH'] == '/') {
foreach ($list_course as $_course) {
if ($FileZip['PATH'] == '/') {
$querypath=''; // to prevent ...path LIKE '//%'... in query
} else {
$querypath = $FileZip['PATH'];
@ -256,23 +257,23 @@ function fullexportspecial()
AND $groupCondition
AND docs.c_id = $course_id
AND props.c_id = $course_id";
$query = Database::query($sql );
$query = Database::query($sql);
while ($rows_course_file = Database::fetch_assoc($query)) {
$rows_course_file['path'];
$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'],
PCLZIP_OPT_ADD_PATH, $_course['directory'],
$zip_folder->add(
$FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'],
PCLZIP_OPT_ADD_PATH,
$_course['directory'],
PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory']."/document".$FileZip['PATH_REMOVE']
);
}
//Add tem to the zip file session course
$code_course = $_course['code'];
$sql_session = "SELECT s.id, name, c_id
$sql = "SELECT s.id, name, c_id
FROM $tbl_session_course sc
INNER JOIN $tbl_session s
ON sc.session_id = s.id
WHERE c_id = '$course_id' ";
$query_session = Database::query($sql_session);
$query_session = Database::query($sql);
while ($rows_session = Database::fetch_assoc($query_session)) {
$session_id = $rows_session['id'];
$sql_session_doc = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props
@ -287,10 +288,13 @@ function fullexportspecial()
AND props.c_id = $course_id ";
$query_session_doc = Database::query($sql_session_doc);
while ($rows_course_session_file = Database::fetch_assoc($query_session_doc)) {
$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory'].'/document'.$rows_course_session_file['path'],
PCLZIP_OPT_ADD_PATH, $_course['directory']."/".$rows_session['name'],
PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory'].'/document'.$FileZip['PATH_REMOVE']
);
$zip_folder->add(
$FileZip['PATH_COURSE'].$_course['directory'].'/document'.$rows_course_session_file['path'],
PCLZIP_OPT_ADD_PATH,
$_course['directory']."/".$rows_session['name'],
PCLZIP_OPT_REMOVE_PATH,
$FileZip['PATH_COURSE'].$_course['directory'].'/document'.$FileZip['PATH_REMOVE']
);
}
}
}

@ -11,14 +11,11 @@ use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
if (isset($_GET['session']) && $_GET['session']) {
$archive_path = api_get_path(SYS_ARCHIVE_PATH).'temp/';
$_cid = true;
$is_courseAdmin = true;
if (isset($_GET['archive_path'])) {
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
} else {
$archive_path = CourseArchiver::getBackupDir();
}
$archive_file = isset($_GET['archive']) ? $_GET['archive'] : null;
$archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
@ -40,7 +37,6 @@ if (in_array($extension, array('xml', 'csv')) && (api_is_platform_admin(true) ||
if (empty($content_type)) {
api_not_allowed(true);
}
if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
DocumentManager::file_send_for_download($archive_path.$archive_file, true, $archive_file);
exit;

@ -87,7 +87,7 @@ class MySpace
public function export_csv($header, $data, $file_name = 'export.csv')
{
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
$archive_url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
$archive_url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive=';
if (!$open = fopen($archive_path.$file_name, 'w+')) {
$message = get_lang('noOpen');

@ -561,7 +561,6 @@ class PDF
$course_info = api_get_course_info($course_code);
// course path
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.api_get_current_access_url_id().'_pdf_watermark.png';
} else {
// course path
$store_path = api_get_path(SYS_CODE_PATH).'default_course_document/images/'.api_get_current_access_url_id().'_pdf_watermark.png';

@ -28,7 +28,7 @@ $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$archivePath = api_get_path(SYS_ARCHIVE_PATH);
$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive=';
$tool_name = get_lang('ExportSessionListXMLCSV');
@ -80,15 +80,9 @@ if (isset($_POST['formSent'])) {
}
if (Database::num_rows($result)) {
$sessionListToExport = [];
if (in_array($file_type, ['csv', 'xls'])) {
$archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time();
$cvs = true;
$sessionListToExport[] = [
'SessionName',
@ -121,7 +115,6 @@ if (isset($_POST['formSent'])) {
fputs($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Sessions>\n");
}
while ($row = Database::fetch_array($result)) {
$row['name'] = str_replace(';',',',$row['name']);
$row['username'] = str_replace(';',',',$row['username']);
@ -129,8 +122,6 @@ if (isset($_POST['formSent'])) {
$row['access_end_date'] = str_replace(';',',',$row['access_end_date']);
$row['visibility'] = str_replace(';',',',$row['visibility']);
$row['session_category'] = str_replace(';',',',$row['session_category_id']);
// users
$sql = "SELECT DISTINCT $tbl_user.username
FROM $tbl_user

@ -1334,9 +1334,7 @@ class CourseBuilder
public function build_session_course()
{
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course = Database::get_main_table(
TABLE_MAIN_SESSION_COURSE
);
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$list_course = CourseManager::get_course_list();
$list = array();
foreach ($list_course as $_course) {
@ -1347,12 +1345,12 @@ class CourseBuilder
$this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['directory'];
$this->course->encoding = api_get_system_encoding(); //current platform encoding
$courseId = $_course['real_id'];
$sql_session = "SELECT s.id, name, c_id
FROM $tbl_session_course sc
INNER JOIN $tbl_session s
ON sc.session_id = s.id
WHERE sc.c_id = '$courseId' ";
$query_session = Database::query($sql_session);
$sql = "SELECT s.id, name, c_id
FROM $tbl_session_course sc
INNER JOIN $tbl_session s
ON sc.session_id = s.id
WHERE sc.c_id = '$courseId' ";
$query_session = Database::query($sql);
while ($rows_session = Database::fetch_assoc($query_session)) {
$session = new CourseSession(
$rows_session['id'],

@ -52,9 +52,11 @@ class CourseSelectForm
el = document.getElementById('div_'+item);
if (el.style.display == 'none') {
el.style.display = '';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className = 'fa fa-minus-square-o fa-lg';
} else {
el.style.display='none';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className ='fa fa-plus-square-o fa-lg';
}
}
@ -148,10 +150,8 @@ class CourseSelectForm
echo '</h3>';
}
echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
$icon = Display::returnIconPath('myprogress_bar.gif');
echo '<div class="tool-backups-options">';
echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
echo '<form method="post" id="upload_form" name="course_select_form">';
echo '<input type="hidden" name="action" value="course_select_form"/>';
if (!empty($hidden_fields['destination_course']) &&
@ -596,10 +596,12 @@ class CourseSelectForm
el = document.getElementById('div_'+item);
if (el.style.display == 'none') {
el.style.display = '';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className('fa fa-minus-square-o fa-lg');
}
else{
el.style.display = 'none';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className('fa fa-plus-square-o fa-lg');
}
}
@ -646,10 +648,9 @@ class CourseSelectForm
}
echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
$icon = Display::returnIconPath('progress_bar.gif');
echo '<div class="tool-backups-options">';
echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
echo '<form method="post" id="upload_form" name="course_select_form">';
echo '<input type="hidden" name="action" value="course_select_form"/>';
foreach ($list_course as $course) {
foreach ($course->resources as $type => $resources) {

@ -170,7 +170,6 @@ class TestsSuite extends TestSuite
$this->addFile(api_get_path(SYS_TEST_PATH).'main/gradebook/lib/be/evaluation.class.test.php');
$this->addFile(api_get_path(SYS_TEST_PATH).'main/gradebook/lib/be/exerciselink.class.test.php');
$this->addFile(api_get_path(SYS_TEST_PATH).'main/gradebook/lib/be/forumthreadlink.class.test.php');
$this->addFile(api_get_path(SYS_TEST_PATH).'main/course_info/download.lib.test.php');
*/
// NEW SCORM
//$this->addFile(api_get_path(SYS_TEST_PATH).'main/lp/learnpath.class.test.php');

Loading…
Cancel
Save