Adding handfull function api_get_plugin_setting(), adding new "main_top" and "main_bottom" plugins zones, adding new plugin "before_login" see BT#6939
parent
9cc50c5124
commit
e84ef79420
@ -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…
Reference in new issue