Adding handfull function api_get_plugin_setting(), adding new "main_top" and "main_bottom" plugins zones, adding new plugin "before_login" see BT#6939

1.9.x
Julio Montoya 12 years ago
parent 9cc50c5124
commit e84ef79420
  1. 12
      index.php
  2. 18
      main/inc/lib/main_api.lib.php
  3. 2
      main/inc/lib/plugin.lib.php
  4. 16
      main/template/default/layout/layout_1_col.tpl
  5. 120
      main/template/default/layout/layout_2_col.tpl
  6. 35
      main/template/default/layout/login_form.tpl
  7. 6
      main/template/default/layout/main.tpl
  8. 69
      plugin/before_login/index.php
  9. 47
      plugin/before_login/plugin.php
  10. 12
      plugin/before_login/template.tpl

@ -137,8 +137,18 @@ if (api_get_setting('display_categories_on_homepage') == 'true') {
if (api_is_facebook_auth_activated() && !api_get_user_id()) {
facebook_connect();
}
$showLoginForm = true;
if (api_is_anonymous()) {
if (!isset($_SESSION['before_login_accepted'])) {
if (in_array('before_login', $controller->tpl->plugin->get_installed_plugins())) {
$showLoginForm = false;
}
}
}
$controller->set_login_form();
if ($showLoginForm) {
$controller->set_login_form();
}
//@todo move this inside the IndexManager
if (!api_is_anonymous()) {

@ -2097,7 +2097,8 @@ function api_get_coachs_from_course($session_id=0,$course_code='') {
* @author René Haentjens
* @author Bart Mollet
*/
function api_get_setting($variable, $key = null) {
function api_get_setting($variable, $key = null)
{
global $_setting;
if ($variable == 'header_extra_content') {
$filename = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';
@ -2128,6 +2129,21 @@ function api_get_setting($variable, $key = null) {
return $value;
}
/**
* @param string $plugin
* @param string $variable
* @return string
*/
function api_get_plugin_setting($plugin, $variable)
{
$variableName = $plugin.'_'.$variable;
$result = api_get_setting($variableName);
if (isset($result[$plugin])) {
return $result[$plugin];
}
return null;
}
/**
* Returns the value of a setting from the web-adjustable admin config settings.
**/

@ -4,6 +4,8 @@
class AppPlugin
{
public $plugin_regions = array(
'main_top',
'main_bottom',
'login_top',
'login_bottom',
'menu_top',

@ -3,10 +3,17 @@
{# 1 column #}
{% block body %}
{# Plugin main top #}
{% if plugin_main_top %}
<div id="plugin_main_top" class="span12">
{{ plugin_main_top }}
</div>
{% endif %}
{# Plugin top #}
{% if plugin_content_top %}
<div id="plugin_content_top" class="span12">
{{ plugin_content_top}}
{{ plugin_content_top }}
</div>
{% endif %}
@ -29,4 +36,11 @@
{{ plugin_content_bottom }}
</div>
{% endif %}
{# Plugin main bottom #}
{% if plugin_main_bottom %}
<div id="plugin_main_bottom" class="span12">
{{ plugin_main_bottom }}
</div>
{% endif %}
{% endblock %}

@ -1,73 +1,80 @@
{% extends "default/layout/main.tpl" %}
{% block body %}
{% block body %}
{# Main content #}
{# Right column #}
<div class="span3 menu-column">
{# Plugin main top #}
{% if plugin_main_top %}
<div id="plugin_main_top" class="span12">
{{ plugin_main_top }}
</div>
{% endif %}
{# Right column #}
<div class="span3 menu-column">
{% if plugin_menu_top %}
<div id="plugin_menu_top">
{{plugin_menu_top}}
</div>
{% endif %}
{% endif %}
{# if user is not login show the login form #}
{% if _u.logged == 0 %}
{% include "default/layout/login_form.tpl" %}
{% endif %}
{# User picture #}
{# User picture #}
{{ user_image_block }}
{# User Profile links #}
{# User Profile links #}
{{ profile_block }}
{# Course block - admin #}
{# Course block - admin #}
{{ course_block }}
{# Course block - teacher #}
{# Course block - teacher #}
{{ teacher_block }}
{# Notice #}
{# Notice #}
{{ notice_block }}
{# Help #}
{# Help #}
{{ help_block }}
{# Links that are not added in the tabs #}
{# Links that are not added in the tabs #}
{{ navigation_course_links }}
{# Reservation block #}
{# Reservation block #}
{{ reservation_block }}
{# Search (xapian) #}
{# Search (xapian) #}
{{ search_block }}
{# Classes #}
{# Classes #}
{{ classes_block }}
{# Skills #}
{# Skills #}
{{ skills_block }}
{# Plugin courses sidebar #}
{# Plugins for footer section #}
{# Plugin courses sidebar #}
{# Plugins for footer section #}
{% if plugin_menu_bottom %}
<div id="plugin_menu_bottom">
{{ plugin_menu_bottom }}
</div>
{% endif %}
{% endif %}
</div>
<div class="span9 content-column">
{# Plugin bottom #}
{# Plugin bottom #}
{% if plugin_content_top %}
<div id="plugin_content_top">
{{ plugin_content_top }}
</div>
{% endif %}
{# Portal homepage #}
{# Portal homepage #}
{% if home_page_block %}
<section id="homepage">
<div class="row">
@ -77,32 +84,32 @@
</div>
</section>
{% endif %}
{# ?? #}
{{ sniff_notification }}
{% include "default/layout/page_body.tpl" %}
{# Welcome to course block #}
{% if welcome_to_course_block %}
{# Welcome to course block #}
{% if welcome_to_course_block %}
<section id="welcome_to_course">
{{ welcome_to_course_block }}
</section>
{% endif %}
{% if content is not null %}
<section id="main_content">
{{ content }}
</section>
{% endif %}
{# Announcements #}
{% if announcements_block %}
{# Announcements #}
{% if announcements_block %}
<section id="announcements">
{{ announcements_block }}
</section>
{% endif %}
{# Course categories (must be turned on in the admin settings) #}
{% if course_category_block %}
<section id="course_category">
@ -113,17 +120,24 @@
</div>
</section>
{% endif %}
{# Hot courses template #}
{% include "default/layout/hot_courses.tpl" %}
{# Content bottom #}
{% if plugin_content_bottom %}
{# Hot courses template #}
{% include "default/layout/hot_courses.tpl" %}
{# Content bottom #}
{% if plugin_content_bottom %}
<div id="plugin_content_bottom">
{{plugin_content_bottom}}
</div>
{% endif %}
&nbsp;
</div>
{# Plugin main bottom #}
{% if plugin_main_bottom %}
<div id="plugin_main_bottom" class="span12">
{{ plugin_main_bottom }}
</div>
{% endif %}
{% endblock %}

@ -1,22 +1,25 @@
<div id="login_block" class="well sidebar-nav">
{% if login_language_form %}
{{ login_language_form }}
<div id="login_block" class="well sidebar-nav">
{% if plugin_login_top is not null %}
<div id="plugin_login_top">
{{ plugin_login_top }}
</div>
{% endif %}
{{ login_language_form }}
{{login_failed}}
{% if plugin_login_top is not null %}
<div id="plugin_login_top">
{{ plugin_login_top }}
</div>
{% endif %}
{{login_form}}
{{ login_failed }}
{{login_options}}
{{ login_form }}
{% if plugin_login_bottom is not null %}
<div id="plugin_login_bottom">
{{ plugin_login_bottom }}
</div>
{% endif %}
</div>
{{ login_options }}
{% if plugin_login_bottom is not null %}
<div id="plugin_login_bottom">
{{ plugin_login_bottom }}
</div>
{% endif %}
</div>
{% endif %}

@ -1,8 +1,8 @@
{% block header %}
{% include "default/layout/main_header.tpl" %}
{% include "default/layout/main_header.tpl" %}
{% endblock %}
{% block body %}
{% block body %}
{% if show_sniff == 1 %}
{% include "default/layout/sniff.tpl" %}
{% endif %}
@ -16,5 +16,5 @@
<div class="push"></div>
</div> <!-- end of #wrapper section -->
{% endif %}
{% include "default/layout/main_footer.tpl" %}
{% include "default/layout/main_footer.tpl" %}
{% endblock %}

@ -0,0 +1,69 @@
<?php
/**
* @package chamilo.plugin.before_login
*/
if (api_is_anonymous()) {
// Only available in the index.php page
$loginAccepted = isset($_SESSION['before_login_accepted']) ? $_SESSION['before_login_accepted'] : null;
$currentPage = str_replace('index.php', '', $_SERVER['REQUEST_URI']);
//var_dump(api_get_path(REL_PATH), $currentPage);
if (api_get_path(REL_PATH) !== $currentPage) {
return null;
}
if ($loginAccepted) {
return null;
}
$option1 = api_get_plugin_setting('before_login', 'option1');
$urlOption1 = api_get_plugin_setting('before_login', 'option1_url');
$option2 = api_get_plugin_setting('before_login', 'option2');
$urlOption2 = api_get_plugin_setting('before_login', 'option2_url');
$form = new FormValidator('form');
$renderer =& $form->defaultRenderer();
$renderer->setHeaderTemplate('');
$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
$renderer->setElementTemplate('<tr><td>{element}</td></tr>');
$form->addElement('header', $option1);
$form->addElement('checkbox', 'left', null, get_lang('Yes'));
$form->addElement('button', 'submit', get_lang('Send'));
if ($form->validate()) {
$result = $form->getSubmitValues();
if (isset($result['left']) && $result['left']) {
$_SESSION['before_login_accepted'] = 1;
header('Location: '.$urlOption1);
exit;
}
}
$form2 = new FormValidator('form');
$renderer =& $form2->defaultRenderer();
$renderer->setHeaderTemplate('');
$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
$renderer->setElementTemplate('<tr><td>{element}</td></tr>');
$form->addElement('header', $option2);
$form2->addElement('checkbox', 'right', null, get_lang('Yes'));
$form2->addElement('button', 'submit', get_lang('Send'));
if ($form2->validate()) {
$result = $form2->getSubmitValues();
if (isset($result['right']) && $result['right']) {
header('Location: '.$urlOption2);
exit;
}
}
$_template['option1'] = api_get_plugin_setting('before_login', 'option1');
$_template['option2'] = api_get_plugin_setting('before_login', 'option2');
$_template['form_option1'] = $form->return_form();
$_template['form_option2'] = $form2->return_form();
}

@ -0,0 +1,47 @@
<?php
/**
* This script is a configuration file for the add_this plugin.
* These settings will be used in the administration interface for plugins
* (Chamilo configuration settings->Plugins)
* @package chamilo.plugin
* @author Julio Montoya <gugli100@gmail.com>
*/
/* Plugin config */
// The plugin title.
$plugin_info['title'] = 'Show HTML before login';
// The comments that go with the plugin.
$plugin_info['comment'] = "Show a content before loading the login page.";
// The plugin version.
$plugin_info['version'] = '1.0';
// The plugin author.
$plugin_info['author'] = 'Julio Montoya';
// The plugin configuration.
$form = new FormValidator('form');
$form->addElement('header', 'Option 1');
$form->addElement('textarea', 'option1', 'Description');
$form->addElement('text', 'option1_url', 'Redirect to');
$form->addElement('header', 'Option 2');
$form->addElement('textarea', 'option2', 'Description');
$form->addElement('text', 'option2_url', 'Redirect to');
$form->addElement('button', 'submit_button', get_lang('Save'));
// Get default value for form
$defaults = array();
$defaults['option1'] = api_get_plugin_setting('before_login', 'option1');
$defaults['option2'] = api_get_plugin_setting('before_login', 'option2');
$defaults['option1_url'] = api_get_plugin_setting('before_login', 'option1_url');
$defaults['option2_url'] = api_get_plugin_setting('before_login', 'option2_url');
$plugin_info['templates'] = array('template.tpl');
$form->setDefaults($defaults);
// Display form
$plugin_info['settings_form'] = $form;

@ -0,0 +1,12 @@
<div class="span12">
<div class="row">
<div class="span6">
{{ before_login.option1 }}
{{ before_login.form_option1 }}
</div>
<div class="span6">
{{ before_login.option2 }}
{{ before_login.form_option2 }}
</div>
</div>
</div>
Loading…
Cancel
Save