Internal: Remove unused files

pull/3466/head
Julio Montoya 4 years ago
parent d8bf07cd3f
commit 1fcdba62b1
  1. 370
      public/main/inc/global-min.inc.php
  2. 307
      public/main/inc/global_error_message.inc.php
  3. 6
      public/main/inc/index.html
  4. 2
      public/main/install/index.php
  5. 238
      public/main/work/downloadfolder.inc.php

@ -1,370 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This is a minified version of global.inc.php meant *only* for download.php
* to check permissions and deliver the file.
*/
// Include the libraries that are necessary everywhere
require_once __DIR__.'/../../vendor/autoload.php';
require_once __DIR__.'/../../app/AppKernel.php';
$kernel = new AppKernel('', '');
// Determine the directory path where this current file lies.
// This path will be useful to include the other initialisation files.
$includePath = __DIR__;
// Include the main Chamilo platform configuration file.
$_configuration = [];
$alreadyInstalled = false;
if (file_exists($kernel->getConfigurationFile())) {
require_once $kernel->getConfigurationFile();
$alreadyInstalled = true;
// Recalculate a system absolute path symlinks insensible.
$includePath = $_configuration['root_sys'].'main/inc/';
} else {
//Redirects to the main/install/ page
if (!$alreadyInstalled) {
$global_error_code = 2;
// The system has not been installed yet.
require_once __DIR__.'/../inc/global_error_message.inc.php';
die();
}
}
$kernel->setApi($_configuration);
// Ensure that _configuration is in the global scope before loading
// main_api.lib.php. This is particularly helpful for unit tests
if (!isset($GLOBALS['_configuration'])) {
$GLOBALS['_configuration'] = $_configuration;
}
// Include the main Chamilo platform library file.
require_once $_configuration['root_sys'].'main/inc/lib/api.lib.php';
// Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI'].
api_request_uri();
// Do not over-use this variable. It is only for this script's local use.
$libraryPath = __DIR__.'/lib/';
// @todo convert this libs in classes
require_once $libraryPath.'database.constants.inc.php';
require_once $libraryPath.'text.lib.php';
require_once $libraryPath.'array.lib.php';
require_once $libraryPath.'online.inc.php';
require_once $libraryPath.'banner.lib.php';
// Doctrine ORM configuration
$dbParams = [
'driver' => 'pdo_mysql',
'host' => $_configuration['db_host'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'dbname' => $_configuration['main_database'],
// Only relevant for pdo_sqlite, specifies the path to the SQLite database.
'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
// Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : '',
];
try {
$database = new \Database();
$database->connect($dbParams);
} catch (Exception $e) {
$global_error_code = 3;
// The database server is not available or credentials are invalid.
require $includePath.'/global_error_message.inc.php';
die();
}
/* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
if (!empty($_configuration['multiple_access_urls'])) {
$_configuration['access_url'] = 1;
$access_urls = api_get_access_urls();
$root_rel = api_get_self();
$root_rel = substr($root_rel, 1);
$pos = strpos($root_rel, '/');
$root_rel = substr($root_rel, 0, $pos);
$protocol = 'http://';
if (!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') {
$protocol = 'https://';
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
//urls with subdomains (HTTP_HOST is preferred - see #6764)
$request_url_root = '';
if (empty($_SERVER['HTTP_HOST'])) {
if (empty($_SERVER['SERVER_NAME'])) {
$request_url_root = $protocol.'localhost/';
} else {
$request_url_root = $protocol.$_SERVER['SERVER_NAME'].'/';
}
} else {
$request_url_root = $protocol.$_SERVER['HTTP_HOST'].'/';
}
//urls with subdirs
$request_url_sub = $request_url_root.$root_rel.'/';
// You can use subdirs as multi-urls, but in this case none of them can be
// the root dir. The admin portal should be something like https://host/adm/
// At this time, subdirs will still hold a share cookie, so not ideal yet
// see #6510
foreach ($access_urls as $details) {
if ($request_url_sub == $details['url']) {
$_configuration['access_url'] = $details['id'];
break; //found one match with subdir, get out of foreach
}
// Didn't find any? Now try without subdirs
if ($request_url_root == $details['url']) {
$_configuration['access_url'] = $details['id'];
break; //found one match, get out of foreach
}
}
} else {
$_configuration['access_url'] = 1;
}
// Check if APCu is available. If so, store the value in $_configuration
if (extension_loaded('apcu')) {
$apcEnabled = ini_get('apc.enabled');
if (!empty($apcEnabled) && $apcEnabled != 'Off' && $apcEnabled != 'off') {
$_configuration['apc'] = true;
$_configuration['apc_prefix'] = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
}
}
$charset = 'UTF-8';
// Enables the portability layer and configures PHP for UTF-8
\Patchwork\Utf8\Bootup::initAll();
// Start session after the internationalization library has been initialized.
ChamiloSession::start($alreadyInstalled);
// access_url == 1 is the default chamilo location
if ($_configuration['access_url'] != 1) {
$url_info = api_get_access_url($_configuration['access_url']);
if ($url_info['active'] == 1) {
$settings_by_access = &api_get_settings(null, 'list', $_configuration['access_url'], 1);
foreach ($settings_by_access as &$row) {
if (empty($row['variable'])) {
$row['variable'] = 0;
}
if (empty($row['subkey'])) {
$row['subkey'] = 0;
}
if (empty($row['category'])) {
$row['category'] = 0;
}
$settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
}
}
}
$result = &api_get_settings(null, 'list', 1);
foreach ($result as &$row) {
if ($_configuration['access_url'] != 1) {
if ($url_info['active'] == 1) {
$var = empty($row['variable']) ? 0 : $row['variable'];
$subkey = empty($row['subkey']) ? 0 : $row['subkey'];
$category = empty($row['category']) ? 0 : $row['category'];
}
if ($row['access_url_changeable'] == 1 && $url_info['active'] == 1) {
if (isset($settings_by_access_list[$var]) &&
isset($settings_by_access_list[$var][$subkey]) &&
$settings_by_access_list[$var][$subkey][$category]['selected_value'] != '') {
if ($row['subkey'] == null) {
$_setting[$row['variable']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
} else {
$_setting[$row['variable']][$row['subkey']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
}
} else {
if ($row['subkey'] == null) {
$_setting[$row['variable']] = $row['selected_value'];
} else {
$_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
}
}
} else {
if ($row['subkey'] == null) {
$_setting[$row['variable']] = $row['selected_value'];
} else {
$_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
}
}
} else {
if ($row['subkey'] == null) {
$_setting[$row['variable']] = $row['selected_value'];
} else {
$_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
}
}
}
$result = &api_get_settings('Plugins', 'list', $_configuration['access_url']);
$_plugins = [];
foreach ($result as &$row) {
$key = &$row['variable'];
if (isset($_setting[$key]) && is_string($_setting[$key])) {
$_setting[$key] = [];
}
if ($row['subkey'] == null) {
$_setting[$key][] = $row['selected_value'];
$_plugins[$key][] = $row['selected_value'];
} else {
$_setting[$key][$row['subkey']] = $row['selected_value'];
$_plugins[$key][$row['subkey']] = $row['selected_value'];
}
}
ini_set('log_errors', '1');
/**
* Include the trad4all language file.
*/
// if we use the javascript version (without go button) we receive a get
// if we use the non-javascript version (with the go button) we receive a post
$user_language = '';
$browser_language = '';
// see #8149
if (!empty($_SESSION['user_language_choice'])) {
$user_language = $_SESSION['user_language_choice'];
}
if (!empty($_GET['language'])) {
$user_language = $_GET['language'];
}
if (!empty($_POST['language_list'])) {
$user_language = preg_replace('/index\.php\?language=/', '', $_POST['language_list']);
}
if (empty($user_language) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !isset($_SESSION['_user'])) {
$l = SubLanguageManager::getLanguageFromBrowserPreference($_SERVER['HTTP_ACCEPT_LANGUAGE']);
if (!empty($l)) {
$user_language = $browser_language = $l;
}
}
// Checking if we have a valid language. If not we set it to the platform language.
$valid_languages = api_get_languages();
if (!empty($valid_languages)) {
if (!in_array($user_language, $valid_languages['folder'])) {
$user_language = api_get_setting('platformLanguage');
}
$language_priority1 = api_get_setting('languagePriority1');
$language_priority2 = api_get_setting('languagePriority2');
$language_priority3 = api_get_setting('languagePriority3');
$language_priority4 = api_get_setting('languagePriority4');
if (isset($_GET['language']) ||
(isset($_POST['language_list']) && !empty($_POST['language_list'])) ||
!empty($browser_language)
) {
$user_selected_language = $user_language; // $_GET['language']; or HTTP_ACCEPT_LANGUAGE
$_SESSION['user_language_choice'] = $user_selected_language;
$platformLanguage = $user_selected_language;
}
if (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false) {
$language_interface = api_get_language_from_type($language_priority4);
} else {
$language_interface = api_get_setting('platformLanguage');
}
if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false) {
$language_interface = api_get_language_from_type($language_priority3);
} else {
if (isset($_SESSION['user_language_choice'])) {
$language_interface = $_SESSION['user_language_choice'];
}
}
if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false) {
$language_interface = api_get_language_from_type($language_priority2);
} else {
if (isset($_user['language'])) {
$language_interface = $_user['language'];
}
}
if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false) {
$language_interface = api_get_language_from_type($language_priority1);
} else {
if (isset($_course['language'])) {
$language_interface = $_course['language'];
}
}
// If language is set via browser ignore the priority
if (isset($_GET['language'])) {
$language_interface = $user_language;
}
}
$language_interface_initial_value = $language_interface;
$langPath = api_get_path(SYS_LANG_PATH);
$languageFilesToLoad = [
$langPath.'english/trad4all.inc.php',
$langPath.$language_interface.'/trad4all.inc.php',
];
foreach ($languageFilesToLoad as $languageFile) {
if (is_file($languageFile)) {
require $languageFile;
}
}
// include the local (contextual) parameters of this course or section
require $includePath.'/local.inc.php';
// Update of the logout_date field in the table track_e_login
// (needed for the calculation of the total connection time)
if (!isset($_SESSION['login_as']) && isset($_user)) {
// if $_SESSION['login_as'] is set, then the user is an admin logged as the user
$tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = "SELECT login_id, login_date
FROM $tbl_track_login
WHERE
login_user_id='".$_user["user_id"]."'
ORDER BY login_date DESC
LIMIT 0,1";
$q_last_connection = Database::query($sql);
if (Database::num_rows($q_last_connection) > 0) {
$now = api_get_utc_datetime();
$i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
// is the latest logout_date still relevant?
$sql = "SELECT logout_date FROM $tbl_track_login
WHERE login_id = $i_id_last_connection";
$q_logout_date = Database::query($sql);
$res_logout_date = convert_sql_date(Database::result($q_logout_date, 0, 'logout_date'));
$lifeTime = api_get_configuration_value('session_lifetime');
if ($res_logout_date < time() - $lifeTime) {
// it isn't, we should create a fresh entry
Event::eventLogin($_user['user_id']);
// now that it's created, we can get its ID and carry on
} else {
$sql = "UPDATE $tbl_track_login SET logout_date = '$now'
WHERE login_id = '$i_id_last_connection'";
Database::query($sql);
}
$tableUser = Database::get_main_table(TABLE_MAIN_USER);
$sql = "UPDATE $tableUser SET last_login = '$now'
WHERE user_id = ".$_user["user_id"];
Database::query($sql);
}
}

@ -1,307 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script displays error messages on fatal errors during initialization.
*
* @author Ivan Tcholakov, 2009-2010
*/
$Organisation = '<a href="http://www.chamilo.org" target="_blank">Chamilo Homepage</a>';
$PoweredBy = 'Powered by <a href="http://www.chamilo.org" target="_blank"> Chamilo </a> &copy; '.date('Y');
/**
* English language variables.
*/
// Sections.
$SectionSystemRequirementsProblem = 'System requirements problem';
$SectionInstallation = 'Installation';
$SectionDatabaseUnavailable = 'Database is unavailable';
$SectionTechnicalIssues = 'Technical issues';
$SectionProtection = 'Protection measure';
// Error code.
$ErrorCode = 'Error code';
// Error code 1.
$IncorrectPhpVersionTitle = 'Incorrect PHP version';
$IncorrectPhpVersionDescription = 'Warning: we have detected that your version of PHP is %s1. To install Chamilo, you need to have PHP %s2 or superior. If you don\'t know what we\'re talking about, please contact your hosting provider or your support team.
%s3 Read the installation guide.';
// Error code 2.
$InstallationTitle = 'Chamilo has not been installed';
$InstallationDescription = 'Click to INSTALL Chamilo %s or read the installation guide';
// Error code 3.
// Error code 4.
// Error code 5.
$DatabaseUnavailableTitle = 'Database is unavailable';
$DatabaseUnavailableDescription = 'This portal is currently experiencing database issues. Please report this to the portal administrator. Thank you for your help.';
// Error code 6.
$AlreadyInstalledTitle = 'Chamilo has already been installed';
$AlreadyInstalledDescription = 'The system has already been installed. In order to protect its contents, we have to prevent you from starting the installation script again. Please return to the main page.';
// Unspecified error.
$TechnicalIssuesTitle = 'Technical issues';
$TechnicalIssuesDescription = 'This portal is currently experiencing technical issues. Please report this to the portal administrator. Thank you for your help.';
if (is_int($global_error_code) && $global_error_code > 0) {
if (class_exists('Template') && function_exists('api_get_configuration_value')) {
$theme = Template::getThemeFallback().'/';
} else {
$theme = 'chamilo';
}
$root_rel = '';
$installation_guide_url = $root_rel.'documentation/installation_guide.html';
$css_list = [
'public/build/vendor.css',
'public/build/css/app.css',
'public/build/css/base.css',
'public/build/css/themes/'.$theme.'/default.css',
];
$web_img = 'main/img';
$root_sys = str_replace('\\', '/', realpath(__DIR__.'/../../')).'/';
$css_def = '';
foreach ($css_list as $cssFile) {
$cssFile = $root_sys.$cssFile;
if (file_exists($cssFile)) {
$css_def .= file_get_contents($cssFile);
}
}
$global_error_message = [];
switch ($global_error_code) {
case 1:
$global_error_message['section'] = $SectionSystemRequirementsProblem;
$global_error_message['title'] = $IncorrectPhpVersionTitle;
$php_version = function_exists('phpversion') ? phpversion() : (defined('PHP_VERSION') ? PHP_VERSION : '');
$php_version = empty($php_version) ? '' : '(PHP '.$php_version.')';
$IncorrectPhpVersionDescription = str_replace('%s1', $php_version, $IncorrectPhpVersionDescription);
$IncorrectPhpVersionDescription = str_replace('%s2', REQUIRED_PHP_VERSION, $IncorrectPhpVersionDescription);
$pos = strpos($IncorrectPhpVersionDescription, '%s3');
if (false !== $pos) {
$length = strlen($IncorrectPhpVersionDescription);
$read_installation_guide = substr($IncorrectPhpVersionDescription, $pos + 3, $length);
$IncorrectPhpVersionDescription = substr($IncorrectPhpVersionDescription, 0, $pos);
$IncorrectPhpVersionDescription .= '<br /><a class="btn btn-default" href="'.$installation_guide_url.'" target="_blank">'.$read_installation_guide.'</a>';
}
$global_error_message['description'] = $IncorrectPhpVersionDescription;
break;
case 2:
require __DIR__.'/../install/version.php';
$global_error_message['section'] = $SectionInstallation;
$global_error_message['title'] = $InstallationTitle;
if (false === ($pos = strpos($InstallationDescription, '%s'))) {
$InstallationDescription = 'Click to INSTALL Chamilo %s or read the installation guide';
}
$read_installation_guide = substr($InstallationDescription, $pos + 2);
$versionStatus = (!empty($new_version_status) && 'stable' != $new_version_status ? $new_version_status : '');
$InstallationDescription = '<form action="'.$root_rel.'main/install/index.php" method="get">
<div class="row">
<div class="col-md-12">
<div class="office">
<h2 class="title">Welcome to the Chamilo '.$new_version.' '.$new_version_status.' installation wizard</h2>
<p class="text">Let\'s start hunting skills down with Chamilo LMS! This wizard will guide you through the Chamilo installation and configuration process.</p>
<p class="download-info">
<button class="btn btn-primary btn-lg" type="submit" value="INSTALL Chamilo" ><i class="fa fa-download" aria-hidden="true"></i> Install Chamilo</button>
<a class="btn btn-success btn-lg" href="'.$installation_guide_url.'" target="_blank"> '.$read_installation_guide.'</a>
</p>
</div>
</div>
</div>
</form>';
$global_error_message['description'] = $InstallationDescription;
break;
case 3:
case 4:
case 5:
$global_error_message['section'] = $SectionDatabaseUnavailable;
$global_error_message['title'] = $DatabaseUnavailableTitle;
$global_error_message['description'] = $DatabaseUnavailableDescription;
break;
case 6:
$global_error_message['section'] = $SectionProtection;
$global_error_message['title'] = $AlreadyInstalledTitle;
$global_error_message['description'] = $AlreadyInstalledDescription;
break;
default:
$global_error_message['section'] = $SectionTechnicalIssues;
$global_error_message['title'] = $TechnicalIssuesTitle;
$global_error_message['description'] = $TechnicalIssuesDescription;
break;
}
$show_error_codes = defined('SHOW_ERROR_CODES') && SHOW_ERROR_CODES && 2 != $global_error_code;
$global_error_message['code'] = $show_error_codes ? $ErrorCode.': '.$global_error_code.'<br /><br />' : '';
$global_error_message['details'] = empty($global_error_message['details']) ? '' : ($show_error_codes ? ': '.$global_error_message['details'] : $global_error_message['details']);
$global_error_message['organisation'] = $Organisation;
$global_error_message['powered_by'] = $PoweredBy;
$global_error_message['encoding'] = 'UTF-8';
$global_error_message['chamilo_logo'] = "data:image/png;base64,".base64_encode(file_get_contents($root_sys.'public/build/css/themes/'.$theme.'/images/header-logo.png'));
$bgImage = base64_encode(file_get_contents("$root_sys/public/img/bg_space.png"));
$bgMoon = base64_encode(file_get_contents("$root_sys/public/img/bg_moon_two.png"));
$installChamiloImage = "data:image/png;base64,".base64_encode(file_get_contents("$root_sys/public/img/mr_chamilo_install.png"));
$global_error_message['mr_chamilo'] = $installChamiloImage;
if (2 == $global_error_code) {
$global_error_message_page =
<<<EOM
<!DOCTYPE html>
<html>
<head>
<title>{TITLE}</title>
<meta charset="{ENCODING}" />
<style>
$css_def
html, body {min-height:100%; padding:0; margin:0;}
#wrapper {padding:0; position:absolute; top:0; bottom:0; left:0; right:0;}
@keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
@-webkit-keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
@-ms-keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
@-moz-keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
.install-home{
background-image: url("data:image/png;base64,$bgImage");
background-position: 0px 0px;
background-repeat: repeat;
animation: animatedBackground 40s linear infinite;
-ms-animation: animatedBackground 40s linear infinite;
-moz-animation: animatedBackground 40s linear infinite;
-webkit-animation: animatedBackground 40s linear infinite;
}
.installer{
background: url("data:image/png;base64,$bgMoon") no-repeat center 390px;
}
.avatar{
text-align: center;
}
.avatar .img-fluid{
display: initial;
}
.office{
padding: 10px 20px;
//background-color: rgba(35, 40, 56, 0.7);
background-color: rgba(0, 22, 48, 0.8);
border-radius: 5px;
}
@media (max-width: 480px) {
.download-info .btn-success{
margin-top: 10px;
}
}
</style>
</head>
<body class="install-home">
<div id="wrapper" class="installer">
<header>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo">
<img src="{CHAMILO_LOGO}"/>
</div>
</div>
</div>
</div>
</header>
<div id="content">
<div class="container">
<div class="welcome-install">
<div class="avatar">
<img class="img-fluid" src="{MR_CHAMILO}"/>
</div>
<div class="row">
<div class="col-md-12">
<div class="office">
<p class="text">
{DESCRIPTION}
{CODE}
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
EOM;
} else {
$global_error_message_page =
<<<EOM
<!DOCTYPE html>
<html>
<head>
<title>{TITLE}</title>
<meta charset="{ENCODING}" />
<style>
$css_def
</style>
</head>
<body>
<div id="page-error">
<div class="page-wrap">
<header>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo">
<img src="{CHAMILO_LOGO}"/>
</div>
</div>
</div>
</div>
</header>
<section id="menu-bar">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only"></span></a>
</li>
</ul>
</div>
</div>
</nav>
</section>
<section id="content-error">
<div class="container">
<div class="well">
<div class="alert alert-danger" role="alert">
{DESCRIPTION}
{CODE}
</div>
</div>
</div>
</section>
</div>
</div>
</body>
</html>
EOM;
}
foreach ($global_error_message as $key => $value) {
$global_error_message_page = str_replace('{'.strtoupper($key).'}', $value, $global_error_message_page);
}
header('Content-Type: text/html; charset='.$global_error_message['encoding']);
die($global_error_message_page);
}

@ -1,6 +0,0 @@
<html>
<head>
</head>
<body>
</body>
</html>

@ -161,7 +161,7 @@ require_once __DIR__.'/version.php';
if (isAlreadyInstalledSystem()) {
// The system has already been installed, so block re-installation.
$global_error_code = 6;
require '../inc/global_error_message.inc.php';
echo 'Portal already installed';
exit;
}

@ -1,238 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Functions and main code for the download folder feature.
*
* @todo use ids instead of the path like the document tool
*/
require_once __DIR__.'/../inc/global.inc.php';
api_protect_course_script(true);
$workId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$current_course_tool = TOOL_STUDENTPUBLICATION;
$_course = api_get_course_info();
if (empty($_course)) {
api_not_allowed();
}
require_once 'work.lib.php';
$work_data = get_work_data_by_id($workId);
$groupId = api_get_group_id();
if (empty($work_data)) {
api_not_allowed();
}
// Prevent some stuff.
if (empty($path)) {
$path = '/';
}
if (empty($_course) || empty($_course['path'])) {
api_not_allowed();
}
$sys_course_path = api_get_path(SYS_COURSE_PATH);
// 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);
$tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tableUser = Database::get_main_table(TABLE_MAIN_USER);
// 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
$files = [];
$course_id = api_get_course_int_id();
$sessionId = api_get_session_id();
$sessionCondition = api_get_session_condition($sessionId, true, false, 'props.session_id');
$filenameCondition = null;
if (array_key_exists('filename', $work_data)) {
$filenameCondition = ', filename';
}
$groupIid = 0;
if ($groupId) {
$groupInfo = GroupManager::get_group_properties($groupId);
$groupIid = $groupInfo['iid'];
}
if (api_is_allowed_to_edit() || api_is_coach()) {
//Search for all files that are not deleted => visibility != 2
$sql = "SELECT DISTINCT
url,
title,
description,
insert_user_id,
sent_date,
contains_file
$filenameCondition
FROM $tbl_student_publication AS work
INNER JOIN $prop_table AS props
ON (work.id = props.ref AND props.c_id = work.c_id)
INNER JOIN $tableUser as u
ON (
work.user_id = u.user_id
)
WHERE
props.tool = 'work' AND
props.c_id = $course_id AND
work.c_id = $course_id AND
work.parent_id = $workId AND
work.filetype = 'file' AND
props.visibility <> '2' AND
work.active IN (0, 1) AND
work.post_group_id = $groupIid
$sessionCondition
";
} else {
$courseInfo = api_get_course_info();
protectWork($courseInfo, $workId);
$userCondition = '';
// All users
if (0 == $courseInfo['show_score']) {
// Do another filter
} else {
// Only teachers
$userCondition = ' AND props.insert_user_id = '.api_get_user_id();
}
//for other users, we need to create a zipfile with only visible files and folders
$sql = "SELECT DISTINCT
url,
title,
description,
insert_user_id,
sent_date,
contains_file
$filenameCondition
FROM $tbl_student_publication AS work
INNER JOIN $prop_table AS props
ON (
props.c_id = work.c_id AND
work.id = props.ref
)
WHERE
props.c_id = $course_id AND
work.c_id = $course_id AND
props.tool = 'work' AND
work.accepted = 1 AND
work.active = 1 AND
work.parent_id = $workId AND
work.filetype = 'file' AND
props.visibility = '1' AND
work.post_group_id = $groupIid
$userCondition
";
}
$query = Database::query($sql);
//add tem to the zip file
while ($not_deleted_file = Database::fetch_assoc($query)) {
$userInfo = api_get_user_info($not_deleted_file['insert_user_id']);
$insert_date = api_get_local_time($not_deleted_file['sent_date']);
$insert_date = str_replace([':', '-', ' '], '_', $insert_date);
$title = basename($not_deleted_file['title']);
if (!empty($filenameCondition)) {
if (isset($not_deleted_file['filename']) && !empty($not_deleted_file['filename'])) {
$title = $not_deleted_file['filename'];
}
}
$filename = $insert_date.'_'.$userInfo['username'].'_'.$title;
$filename = api_replace_dangerous_char($filename);
// File exists
if (file_exists($sys_course_path.$_course['path'].'/'.$not_deleted_file['url']) &&
!empty($not_deleted_file['url'])
) {
$files[basename($not_deleted_file['url'])] = $filename;
$addStatus = $zip_folder->add(
$sys_course_path.$_course['path'].'/'.$not_deleted_file['url'],
PCLZIP_OPT_REMOVE_PATH,
$sys_course_path.$_course['path'].'/work',
PCLZIP_CB_PRE_ADD,
'my_pre_add_callback'
);
} else {
// Convert texts in html files
$filename = trim($filename).'.html';
$work_temp = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().'_'.$filename;
file_put_contents($work_temp, $not_deleted_file['description']);
$files[basename($work_temp)] = $filename;
$addStatus = $zip_folder->add(
$work_temp,
PCLZIP_OPT_REMOVE_PATH,
api_get_path(SYS_ARCHIVE_PATH),
PCLZIP_CB_PRE_ADD,
'my_pre_add_callback'
);
@unlink($work_temp);
}
}
if (!empty($files)) {
$fileName = api_replace_dangerous_char($work_data['title']);
// Logging
Event::event_download($fileName.'.zip (folder)');
//start download of created file
$name = $fileName.'.zip';
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;
}
} else {
exit;
}
/* Extra function (only used here) */
function my_pre_add_callback($p_event, &$p_header)
{
global $files;
if (isset($files[basename($p_header['stored_filename'])])) {
$p_header['stored_filename'] = $files[basename($p_header['stored_filename'])];
return 1;
}
return 0;
}
/**
* Return the difference between two arrays, as an array of those key/values
* Use this as array_diff doesn't give the.
*
* @param array $arr1 first array
* @param array $arr2 second array
*
* @return array difference between the two arrays
*/
function diff($arr1, $arr2)
{
$res = [];
$r = 0;
foreach ($arr1 as $av) {
if (!in_array($av, $arr2)) {
$res[$r] = $av;
$r++;
}
}
return $res;
}
Loading…
Cancel
Save