This commit is contained in:
Xes
2025-08-14 22:36:35 +02:00
parent f00a2c32bb
commit 1c9e806972
15 changed files with 482 additions and 0 deletions

24
custompages/README.md Normal file
View File

@@ -0,0 +1,24 @@
Custom pages
=============
CustomPages looks for alternatives in this directory, and displays them if present.
The user-provided custom pages must exactly be named as such :
- index-logged.php for the general landing page before login
- index-unlogged.php for the general landing page when already logged-in
- registration.php for the registration form
- registration-feedback.php for the registration success feedback
- lostpassword.php for the password recovery form
### Installation
- Enable the use_custom_pages setting
- Create your own modifications based in the files with the suffix "-dist.php"
### Important notes
- Do not replace the images in the images/ directory.
Instead, create new images, as the current ones will be overwritten
by each Chamilo upgrade.

View File

@@ -0,0 +1,118 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Quick page to react to first login cases.
*
* @package chamilo.custompages
*/
require_once api_get_path(SYS_PATH).'main/inc/global.inc.php';
require_once __DIR__.'/language.php';
/**
* Security checks.
*/
if (!isset($_SESSION['conditional_login']['uid'])) {
exit("Not Authorised");
}
if (isset($_POST['password'])) {
$u = api_get_user_info($_SESSION['conditional_login']['uid']);
if ($_POST['password'] != $_POST['password2']) {
header('Location: '.api_get_self().'?invalid=2');
exit();
}
if (empty($_POST['password'])) { //|| !api_check_password($password)) { //Pass must be at least 5 char long with 2 digits and 3 letters
header('Location: '.api_get_self().'?invalid=1');
exit();
}
$password = $_POST['password'];
$updated = UserManager::update_user(
$u['user_id'],
$u['firstname'],
$u['lastname'],
$u['username'],
$password,
$u['auth_source'],
$u['email'],
$u['status'],
$u['official_code'],
$u['phone'],
$u['picture_uri'],
$u['expiration_date'],
$u['active'],
$u['creator_id'],
$u['hr_dept_id'],
null,
$u['language'],
''
);
if ($updated !== false) {
UserManager::update_extra_field_value($u['user_id'], 'already_logged_in', 'true');
ConditionalLogin::login();
}
}
if ($_GET['invalid'] == 1) {
$error_message = get_lang('CurrentPasswordEmptyOrIncorrect');
}
if ($_GET['invalid'] == 2) {
$error_message = get_lang('PassTwo');
}
$www = api_get_path('WEB_PATH');
/**
* HTML output.
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Custompage - login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="<?php echo $www; ?>web/assets/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
if (top.location != location)
top.location.href = document.location.href ;
// Handler pour la touche retour
$('input').keyup(function(e) {
if (e.keyCode == 13) {
$('#changepassword-form').submit();
}
});
});
</script>
</head>
<body>
<div id="backgroundimage">
<img src="/custompages/images/page-background.png" class="backgroundimage" />
</div>
<div id="wrapper">
<div id="header">
<img src="/custompages/images/header.png" alt="Logo" />
</div> <!-- #header -->
<h2> <?php echo custompages_get_lang('FirstLogin'); ?> </h2>
<div id="changepassword-form-box" class="form-box">
<div class="info"> <?php echo custompages_get_lang('FirstLoginChangePassword'); ?> </div>
<?php if (isset($error_message)) {
echo '<div id="changepassword-form-error" class="form-error">'.$error_message.'</div>';
}?>
<form id="changepassword-form" class="form" method="post">
<div>
<label for="password">*<?php echo custompages_get_lang('Password'); ?></label>
<input name="password" type="password" /><br />
<label for="password2">*<?php echo custompages_get_lang('Password'); ?></label>
<input name="password2" type="password" /><br />
</div>
</form>
<div id="changepassword-form-submit" class="form-submit" onclick="document.forms['changepassword-form'].submit();">
<span><?php echo custompages_get_lang('LoginEnter'); ?></span>
</div> <!-- #form-submit -->
</div> <!-- #form -->
<div id="footer">
<img src="/custompages/images/footer.png" />
</div> <!-- #footer -->
</div> <!-- #wrapper -->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -0,0 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Redirect to normal Chamilo.
*
* @package chamilo.custompages
*/
require_once api_get_path(SYS_PATH).'main/inc/global.inc.php';
$www = api_get_path('WEB_PATH');
/**
* Redirect.
*/
header("Location: $www/user_portal.php");
exit;

View File

@@ -0,0 +1,56 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Redirect script.
*/
require_once api_get_path(SYS_PATH).'main/inc/global.inc.php';
require_once __DIR__.'/language.php';
$template = new Template(get_lang('SignIn'), false, false, false, false, true, true);
/**
* Homemade micro-controller.
*/
if (isset($_GET['loginFailed'])) {
if (isset($_GET['error'])) {
switch ($_GET['error']) {
case 'account_expired':
$error_message = get_lang('AccountExpired');
break;
case 'account_inactive':
$error_message = get_lang('AccountInactive');
break;
case 'user_password_incorrect':
$error_message = get_lang('InvalidId');
break;
case 'access_url_inactive':
$error_message = get_lang('AccountURLInactive');
break;
default:
$error_message = get_lang('InvalidId');
}
} else {
$error_message = get_lang('InvalidId');
}
}
if (isset($error_message)) {
$template->assign('error', $error_message);
}
$flash = Display::getFlashToString();
Display::cleanFlashMessages();
if (api_get_setting('allow_registration') === 'true') {
$urlRegister = api_get_path(WEB_CODE_PATH).'auth/inscription.php?language='.api_get_interface_language();
$template->assign('url_register', $urlRegister);
}
$urlLostPassword = api_get_path(WEB_CODE_PATH).'auth/lostPassword.php?language='.api_get_interface_language();
$template->assign('url_lost_password', $urlLostPassword);
$template->assign('mgs_flash', $flash);
$layout = $template->get_template('custompage/login.tpl');
$content = $template->fetch($layout);
$template->assign('content', $content);
$template->display_blank_template();

View File

@@ -0,0 +1,53 @@
<?php
/* For licensing terms, see /license.txt */
/**
* CustomPages : Browser language detection
* Include this file in your custom page if you want to set the language variable of the Chamilo session
* to the best pick according to the visitor's browser's options.
* 2011, Jean-Karim Bockstael, CBlue <jeankarim@cblue.be>
* This requires the Chamilo system to be initialized
* (note that it's easier to do the following include in the parent page).
*
* @package chamilo.custompages
*/
/**
* Returns the best match between available languages and visitor preferences.
*
* @return string the best match as 2-chars code, null when none match
*/
function get_preferred_language($available_langs)
{
// Parsing the Accept-languages HTTP header
$langs = [];
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $httplang) {
$rawlang = explode(';q=', $httplang);
if (strpos($rawlang[0], '-') !== false) {
// We ignore the locale part, as in en-GB vs en-US
$rawlang[0] = substr($rawlang[0], 0, strpos($rawlang[0], '-'));
}
if (count($rawlang) == 1) {
$rawlang[1] = 1.0; // The absence of weighting means a weight of 1 (max)
}
$langs[$rawlang[1]][] = $rawlang[0];
}
krsort($langs, SORT_NUMERIC);
// Choosing the best match
foreach ($langs as $weight => $codes) {
foreach ($codes as $code) {
if (in_array($code, $available_langs)) {
return $code;
}
}
}
// No match
return null;
}
/**
* Get a language variable in a specific language.
*/
function custompages_get_lang($variable)
{
return get_lang($variable, null, $_SESSION['user_language_choice']);
}

50
custompages/language.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Definition of language-related functions for cases where th user isn't
* logged in yet.
*
* @package chamilo.custompages
*/
// Get helper functions
require_once __DIR__.'/language.inc.php';
// Define the languages you want to make available for auto-detection here
$available_langs = ['en', 'fr', 'es', 'gl', 'eu'];
// Define the translation of these language codes to Chamilo languages
$chamilo_langs = [
null => 'english',
'en' => 'english',
'fr' => 'french',
'nl' => 'dutch',
'de' => 'german',
'es' => 'spanish',
'gl' => 'galician',
'eu' => 'basque',
];
$lang_match = $chamilo_langs[get_preferred_language($available_langs)];
// recover previous value ...
if (isset($_SESSION['user_language_choice'])) {
$lang_match = $_SESSION['user_language_choice'];
}
// Chamilo parameter, on logout
if (isset($_REQUEST['language']) && !empty($_REQUEST['language']) && in_array($_REQUEST['language'], $chamilo_langs)) {
$lang_match = $_REQUEST['language'];
}
// Incoming link parameter
if (isset($_REQUEST['lang']) && !empty($_REQUEST['lang']) && in_array($_REQUEST['lang'], $available_langs)) {
$lang_match = $chamilo_langs[$_REQUEST['lang']];
}
$detect = api_get_setting('auto_detect_language_custom_pages');
if ($detect === 'true') {
// Auto detect
$_user['language'] = $lang_match;
$_SESSION['user_language_choice'] = $lang_match;
} else {
// Chamilo default platform.
$defaultLanguage = api_get_interface_language();
$_user['language'] = $defaultLanguage;
$_SESSION['user_language_choice'] = $defaultLanguage;
}

View File

@@ -0,0 +1,54 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Displayed after the user has been logged out.
*
* @package chamilo.custompages
*/
$called_direcly = !function_exists('api_get_path');
if ($called_direcly) {
return '';
}
require_once __DIR__.'/language.php';
$www = api_get_path('WEB_PATH');
/**
* HTML output.
*/
?>
<!DOCTYPE html>
<html>
<head>
<title>Custompage - logged out</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="<?php echo $www; ?>web/assets/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
if (top.location != location)
top.location.href = document.location.href ;
});
</script>
</head>
<body>
<div id="backgroundimage">
<img src="<?php echo $www; ?>/custompages/images/page-background.png" class="backgroundimage" alt="background"/>
</div>
<div id="wrapper">
<div id="header">
<img src="<?php echo $www; ?>/custompages/images/header.png" alt="Logo" />
</div>
<div id="login-form-box" class="form-box">
<div id="login-form-info" class="form-info">
You have been logged out.
</div>
</div>
<a href="<?php echo $www.'user_portal.php'; ?>">Go to your portal</a>
<div id="footer">
<img src="<?php echo $www; ?>/custompages/images/footer.png" alt="footer"/>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,23 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Quick form to ask for password reminder.
*
* @package chamilo.custompages
*/
require_once api_get_path(SYS_PATH).'main/inc/global.inc.php';
require_once __DIR__.'/language.php';
$template = new Template(get_lang('LostPassword'), false, false, false, false, true, true);
$error = null;
if (isset($content['info']) && !empty($content['info'])) {
$error = $content['info'];
}
$template->assign('error');
$template->assign('form', $content['form']);
$layout = $template->get_template('custompage/lostpassword.tpl');
$content = $template->fetch($layout);
$template->assign('content', $content);
$template->display_blank_template();

View File

@@ -0,0 +1,36 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script allows for specific registration rules (see CustomPages feature of Chamilo)
* Please contact CBlue regarding any licences issues.
* Author: noel@cblue.be
* Copyright: CBlue SPRL, 20XX (GNU/GPLv3).
*
* @package chamilo.custompages
*/
require_once api_get_path(SYS_PATH).'main/inc/global.inc.php';
require_once __DIR__.'/language.php';
$template = new Template(get_lang('Registration'), false, false, false, false, true, true);
/**
* Removes some unwanted elementend of the form object.
* 03-26-2020 Added check if element exist.
*/
if (isset($content['form']->_elementIndex['extra_mail_notify_invitation'])) {
$content['form']->removeElement('extra_mail_notify_invitation');
}
if (isset($content['form']->_elementIndex['extra_mail_notify_message'])) {
$content['form']->removeElement('extra_mail_notify_message');
}
if (isset($content['form']->_elementIndex['extra_mail_notify_group_message'])) {
$content['form']->removeElement('extra_mail_notify_group_message');
}
$content['form']->removeElement('official_code');
$content['form']->removeElement('phone');
$template->assign('form', $content['form']->returnForm());
$layout = $template->get_template('custompage/registration.tpl');
$content = $template->fetch($layout);
$template->assign('content', $content);
$template->display_blank_template();

View File

@@ -0,0 +1,48 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Quick display for user registration.
*
* @package chamilo.custompages
*/
/**
* HTML output.
*/
require_once api_get_path(SYS_PATH).'main/inc/global.inc.php';
require_once __DIR__.'/language.php';
$rootWeb = api_get_path('WEB_PATH');
?>
<html>
<head>
<title><?php echo custompages_get_lang('Registration'); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="<?php echo $rootWeb; ?>web/assets/jquery/dist/jquery.min.js"></script>
</head>
<body>
<img src="/custompages/images/page-background.png" class="backgroundimage" />
<section id="registration">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="form-wrap">
<div class="logo">
<img src="/custompages/images/header.png">
</div>
<div id="registration-form-box" class="form-box">
<div class="block-form-login">
<?php echo $content['info']; ?>
</div>
</div>
<div id="footer">
<img src="../../custompages/images/footer.png" />
</div> <!-- #footer -->
</div>
</div>
</div>
</div>
</section>
</body>
</html>

View File

@@ -0,0 +1,5 @@
Custom Pages : URL Images
This features allows each access URL to have a number of images (currently three) specific to this URL. This allows easier customization of landing pages by access URL.
You can access a URL's images by calling the static function CustomPages::getURLImages() in your custom page.