Adding "template" setting that allows change the template files '*.tpl' see BT#6214

skala
Julio Montoya 13 years ago
parent bd2cfce1bb
commit fc7fb86309
  1. 45
      main/admin/settings.lib.php
  2. 17
      main/admin/settings.php
  3. 104
      main/inc/global.inc.php
  4. 30
      main/inc/lib/template.lib.php
  5. 3
      main/install/1.10.0/db_main.sql
  6. 4
      main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql

@ -184,11 +184,12 @@ function handle_plugins() {
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Julio Montoya <gugli100@gmail.com>, Chamilo
*/
function handle_stylesheets() {
function handle_stylesheets()
{
global $_configuration;
// Current style.
$currentstyle = api_get_setting('stylesheets');
$currentStyle = api_get_setting('stylesheets');
$is_style_changeable = false;
@ -203,7 +204,6 @@ function handle_stylesheets() {
}
$form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets#tabs-2');
//$form->addElement('header', get_lang('UploadNewStylesheet'));
$form->addElement('text', 'name_stylesheet', get_lang('NameStylesheet'), array('size' => '40', 'maxlength' => '40'));
$form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet'));
@ -211,6 +211,7 @@ function handle_stylesheets() {
$form->addRule('new_stylesheet', get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', 'filetype', $allowed_file_types);
$form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('style_submit_button', 'stylesheet_upload', get_lang('Upload'), array('class'=>'save'));
$show_upload_form = false;
@ -238,6 +239,7 @@ function handle_stylesheets() {
// Add event to the system log.
$user_id = api_get_user_id();
$category = $_GET['category'];
event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
if ($result) {
@ -268,21 +270,14 @@ function handle_stylesheets() {
$selected = $style_dir;
$safe_style_dir = $style_dir;
} else {
if (!isset($_POST['style']) && ($currentstyle == $style_dir || ($style_dir == 'chamilo' && !$currentstyle))) {
if (!isset($_POST['style']) && ($currentStyle == $style_dir || ($style_dir == 'chamilo' && !$currentStyle))) {
$selected = $style_dir;
} else {
$selected = '';
}
}
$show_name = ucwords(str_replace('_', ' ', $style_dir));
if ($is_style_changeable) {
$list_of_styles[$style_dir] = "<option value=\"".$style_dir."\" ".$selected." /> $show_name </option>";
$list_of_styles[$style_dir] = '<option value="'.$style_dir.'" /> '.$show_name.'</option>';
$list_of_names[$style_dir] = $show_name;
//echo "<input type=\"radio\" name=\"style\" value=\"".$style_dir."\" ".$selected." onClick=\"parent.preview.location='style_preview.php?style=".$style_dir."';\"/>";
//echo '<a href="style_preview.php?style='.$style_dir.'" target="preview">'.$show_name.'</a>';
} else {
//echo '<a href="style_preview.php?style='.$style_dir.'" target="preview">'.$show_name.'</a>';
}
$counter++;
}
@ -291,15 +286,16 @@ function handle_stylesheets() {
@closedir($handle);
}
//Sort styles in alphabetical order
// Sort styles in alphabetical order
asort($list_of_names);
$select_list = array();
foreach ($list_of_names as $style_dir=>$item) {
foreach ($list_of_names as $style_dir => $item) {
$select_list[$style_dir] = strip_tags($list_of_styles[$style_dir]);
}
$form_change->addElement('select', 'style', get_lang('NameStylesheet'), $select_list);
$form_change->setDefaults('style', $selected);
$form_change->setDefaults(array('style' => $selected));
if ($form_change->validate()) {
// Submit stylesheets.
@ -315,8 +311,12 @@ function handle_stylesheets() {
// Remove path prefix except the style name and put file on disk
$zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir,0,-strlen($safe_style_dir)));
}
$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>';
Display::display_normal_message($str,false);
$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>';
Display::display_normal_message($str, false);
}
if (isset($_POST['preview'])) {
global $app;
$app['template']->preview_theme = 'academica';
}
}
@ -886,7 +886,7 @@ function add_edit_template() {
// Setting the information of the template that we are editing.
$form->setDefaults($defaults);
}
// Settting the form elements: the submit button.
// Setting the form elements: the submit button.
$form->addElement('style_submit_button' , 'submit', get_lang('Ok') ,'class="save"');
// Setting the rules: the required fields.
@ -1055,7 +1055,7 @@ function update_gradebook_score_display_custom_values($values) {
function generate_settings_form($settings, $settings_by_access_list) {
global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list;
$table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$form = new FormValidator('settings', 'post', 'settings.php?category='.Security::remove_XSS($_GET['category']));
@ -1071,12 +1071,12 @@ function generate_settings_form($settings, $settings_by_access_list) {
}
$default_values = array();
$url_info = api_get_access_url($url_id);
$i = 0;
foreach ($settings as $row) {
if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; }
if (in_array($row['variable'], array_keys($settings_to_avoid))) {
continue;
}
if (!empty($_configuration['multiple_access_urls'])) {
if (api_is_global_platform_admin()) {
@ -1129,6 +1129,7 @@ function generate_settings_form($settings, $settings_by_access_list) {
}
switch ($row['type']) {
case 'text':
case 'textfield':
if (in_array($row['variable'], $convert_byte_to_mega_list)) {
$form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('class' => 'span1', 'maxlength' => '8'));

@ -40,9 +40,10 @@ api_protect_admin_script();
// Settings to avoid
$settings_to_avoid = array(
'stylesheets' => '', // handled by the handle_stylesheet() function
'use_session_mode' => 'true',
'gradebook_enable' => 'false',
'example_material_course_creation' => 'true' // ON by default - now we have this option when we create a course
'example_material_course_creation' => 'true' // ON by default - now we have this option when we create a course
);
$convert_byte_to_mega_list = array(
@ -52,10 +53,6 @@ $convert_byte_to_mega_list = array(
'default_group_quotum'
);
if (isset($_POST['style'])) {
Display::$preview_style = $_POST['style'];
}
// Database table definitions.
$table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
@ -252,16 +249,11 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
continue;
}
$key = Database::escape_string($key);
$sql = "UPDATE $table_settings_current SET selected_value = 'false' WHERE variable = '".$key."' AND access_url = ".intval(
$url_id
)." AND type IN ('checkbox', 'radio') ";
$sql = "UPDATE $table_settings_current SET selected_value = 'false'
WHERE variable = '".$key."' AND access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') ";
$res = Database::query($sql);
}
/*foreach($settings_to_avoid as $key => $value) {
api_set_setting($key, $value, null, null, $_configuration['access_url']);
}*/
// Save the settings.
$keys = array();
@ -552,6 +544,7 @@ if (!empty($_GET['category'])) {
case 'Stylesheets':
// Displaying the extensions: Stylesheets.
handle_stylesheets();
$form->display();
break;
case 'Search':
handle_search();

@ -181,19 +181,6 @@ $app['breadcrumb'] = array();
// The script is allowed? This setting is modified when calling api_is_not_allowed()
$app['allowed'] = true;
// Template settings loaded in template.lib.php
$app['template.show_header'] = true;
$app['template.show_footer'] = true;
$app['template.show_learnpath'] = false;
$app['template.hide_global_chat'] = true;
$app['template.load_plugins'] = true;
// Default template style
$app['template_style'] = 'default';
// Default layout
$app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
// Start session after the internationalization library has been initialized
// @todo use silex session provider instead of a custom class
@ -218,6 +205,22 @@ if (!$app['configuration']['db_host']) {
//$app->abort(500, "Database is unavailable"); //error 3
}*/
$checkConnection = false;
if (isset($_configuration['main_database'])) {
// The system has not been designed to use special SQL modes that were introduced since MySQL 5.
Database::query("set session sql_mode='';");
$checkConnection = @Database::select_db($_configuration['main_database'], $conn_return);
if ($checkConnection) {
// Initialization of the database encoding to be used.
Database::query("SET SESSION character_set_server = 'utf8';");
Database::query("SET SESSION collation_server = 'utf8_general_ci';");
Database::query("SET NAMES 'utf8';");
}
}
/* Retrieving all the chamilo config settings for multiple URLs feature*/
if (isset($_configuration['multiple_access_urls']) && !empty($_configuration['multiple_access_urls'])) {
$_configuration['access_url'] = 1;
@ -236,27 +239,51 @@ if (isset($_configuration['multiple_access_urls']) && !empty($_configuration['mu
$_configuration['access_url'] = 1;
}
// Loading chamilo settings
/* @todo create a service provider to load plugins.
Check how bolt add extensions (including twig templates, config with yml)*/
$_plugins = array();
if ($alreadyInstalled && $checkConnection) {
$settings_refresh_info = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
$settings_latest_update = $settings_refresh_info ? $settings_refresh_info['selected_value'] : null;
$_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
$_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
if (empty($_setting)) {
api_set_settings_and_plugins();
} else {
if (isset($_setting['settings_latest_update']) && $_setting['settings_latest_update'] != $settings_latest_update) {
api_set_settings_and_plugins();
$_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
$_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
}
}
}
$app['plugins'] = $_plugins;
// Template settings loaded in template.lib.php
$app['template.show_header'] = true;
$app['template.show_footer'] = true;
$app['template.show_learnpath'] = false;
$app['template.hide_global_chat'] = true;
$app['template.load_plugins'] = true;
// Default template style
$templateStyle = api_get_setting('template');
$templateStyle = isset($templateStyle) && !empty($templateStyle) ? $templateStyle : 'default';
$app['template_style'] = $templateStyle;
// Default layout
$app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
$app['configuration'] = $_configuration;
/** Including service providers */
require_once 'services.php';
$charset = 'UTF-8';
$checkConnection = false;
if (isset($app['configuration']['main_database'])) {
// The system has not been designed to use special SQL modes that were introduced since MySQL 5.
Database::query("set session sql_mode='';");
$checkConnection = @Database::select_db($app['configuration']['main_database'], $conn_return);
if ($checkConnection) {
// Initialization of the database encoding to be used.
Database::query("SET SESSION character_set_server = 'utf8';");
Database::query("SET SESSION collation_server = 'utf8_general_ci';");
Database::query("SET NAMES 'utf8';");
}
}
// Manage Chamilo error messages
$app->error(
@ -294,29 +321,6 @@ $app->error(
// Preserving the value of the global variable $charset.
$charset_initial_value = $charset;
// Loading chamilo settings
/* @todo create a service provider to load plugins.
Check how bolt add extensions (including twig templates, config with yml)*/
$_plugins = array();
if ($alreadyInstalled && $checkConnection) {
$settings_refresh_info = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
$settings_latest_update = $settings_refresh_info ? $settings_refresh_info['selected_value'] : null;
$_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
$_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
if (empty($_setting)) {
api_set_settings_and_plugins();
} else {
if (isset($_setting['settings_latest_update']) && $_setting['settings_latest_update'] != $settings_latest_update) {
api_set_settings_and_plugins();
$_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
$_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
}
}
}
$app['plugins'] = $_plugins;
// Section (tabs in the main chamilo menu)
$app['this_section'] = SECTION_GLOBAL;

@ -307,7 +307,9 @@ class Template
$this->assign('_u', $user_info);
}
/** Set system parameters */
/**
* Set system parameters
*/
private function setSystemParameters()
{
global $_configuration;
@ -338,14 +340,17 @@ class Template
}
/**
* Set theme, include CSS files */
* Set theme, include CSS files
*/
private function setCssFiles()
{
global $disable_js_and_css_files;
$css = array();
$this->theme = api_get_visual_theme();
if (isset($_POST['style']) && api_is_platform_admin()) {
$this->preview_theme = $_POST['style'];
}
if (!empty($this->preview_theme)) {
$this->theme = $this->preview_theme;
}
@ -354,18 +359,19 @@ class Template
$cssPath = api_get_path(WEB_CSS_PATH);
//Base CSS
// Base CSS.
$css[] = api_get_cdn_path($cssPath.'base.css');
//Compressed version of default + all CSS files
//$css[] = api_get_cdn_path(api_get_path(WEB_PATH).'web/css/'.$this->theme.'/style.css');
// Compressed version of default + all CSS files
// @todo use assetic to compress files
// $css[] = api_get_cdn_path(api_get_path(WEB_PATH).'web/css/'.$this->theme.'/style.css');
//Default theme CSS
// Default theme CSS.
$css[] = api_get_cdn_path($cssPath.$this->theme.'/default.css');
$css[] = api_get_cdn_path($cssPath.'bootstrap-responsive.css');
$css[] = api_get_cdn_path($cssPath.'responsive.css');
$css[] = api_get_cdn_path($cssPath.'font_awesome/font-awesome.css');
//Extra CSS files
// Extra CSS files.
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css';
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
@ -414,14 +420,10 @@ class Template
$style_print = api_get_css(api_get_cdn_path($cssPath.$this->theme.'/print.css'), 'print');
$this->assign('css_style_print', $style_print);
}
// Logo
/*$logo = $this->returnLogo($this->theme);
$this->assign('logo', $logo);*/
}
/**
*
* Sets JS files
*/
private function setJsFiles()
{
@ -536,7 +538,7 @@ class Template
$this->assign('title_string', $title_string);
//Setting the theme and CSS files
$this->setCSSFiles();
$this->setCssFiles();
$this->setJsFiles();
// Implementation of prefetch.

@ -927,6 +927,7 @@ VALUES
('allow_teachers_to_create_sessions', NULL,'radio','Session','false','AllowTeachersToCreateSessionsTitle','AllowTeachersToCreateSessionsComment', NULL, NULL, 0),
('login_as_allowed',NULL,'radio','Security','true','AdminLoginAsAllowedTitle','AdminLoginAsAllowedComment', 1, 0, 1),
('admins_can_set_users_pass','radio','security','true','AdminsCanChangeUsersPassTitle','AdminsCanChangeUsersPassComment', 1, 0, 1),
('template', NULL, 'text', 'stylesheets', 'default', 'DefaultTemplateTitle', 'DefaultTemplateComment', NULL, NULL, 1),
('chamilo_database_version', NULL, 'textfield', NULL, '1.10.0.001','DatabaseVersion','', NULL, NULL, 0); -- base value, updated at end of file. Don't change here
UNLOCK TABLES;
@ -3526,4 +3527,4 @@ CREATE TABLE ext_log_entries (
) DEFAULT CHARSET=utf8;
-- Do not move this
UPDATE settings_current SET selected_value = '1.10.0.015' WHERE variable = 'chamilo_database_version';
UPDATE settings_current SET selected_value = '1.10.0.016' WHERE variable = 'chamilo_database_version';

@ -287,5 +287,7 @@ ALTER TABLE course_field_values ADD COLUMN comment VARCHAR(100) default '';
ALTER TABLE question_field_values ADD COLUMN comment VARCHAR(100) default '';
ALTER TABLE c_quiz ADD COLUMN end_button int NOT NULL default 0;
INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('template', NULL, 'text', 'stylesheets', 'default', 'DefaultTemplateTitle', 'DefaultTemplateComment', NULL, NULL, 1);
-- Do not move this
UPDATE settings_current SET selected_value = '1.10.0.015' WHERE variable = 'chamilo_database_version';
UPDATE settings_current SET selected_value = '1.10.0.016' WHERE variable = 'chamilo_database_version';

Loading…
Cancel
Save