allow templates packed as apps to replace login screen template by setting it as default template (without setting it in header.inc.php)

This commit is contained in:
Ralf Becker 2013-11-14 13:52:50 +00:00
parent fb2c103cef
commit 74dd9f0e02
3 changed files with 188 additions and 185 deletions

View File

@ -100,7 +100,24 @@ if($GLOBALS['egw_info']['server']['auth_type'] == 'cas')
}
else
{
$GLOBALS['egw_info']['server']['template_dir'] = EGW_SERVER_ROOT . '/phpgwapi/templates/' . $GLOBALS['egw_info']['login_template_set'];
// allow template to overide login-template (without modifying header.inc.php) by setting default or forced pref
$prefs = new preferences();
$prefs->account_id = preferences::DEFAULT_ID;
$prefs->read_repository();
$class = $prefs->data['common']['template_set'].'_framework';
if (class_exists($class) && constant($class.'::LOGIN_TEMPLATE_SET'))
{
$GLOBALS['egw_info']['server']['template_set'] =
$GLOBALS['egw_info']['login_template_set'] = $prefs->data['common']['template_set'];
$GLOBALS['egw_info']['server']['template_dir'] =
EGW_SERVER_ROOT . '/' . $GLOBALS['egw_info']['login_template_set'].'/templates/'.$GLOBALS['egw_info']['login_template_set'];
}
else
{
$GLOBALS['egw_info']['server']['template_dir'] = EGW_SERVER_ROOT . '/phpgwapi/templates/' . $GLOBALS['egw_info']['login_template_set'];
}
unset($prefs);
// read the images from the login-template-set, not the (maybe not even set) users template-set
$GLOBALS['egw_info']['user']['preferences']['common']['template_set'] = $GLOBALS['egw_info']['login_template_set'];

View File

@ -349,19 +349,178 @@ abstract class egw_framework
abstract function footer();
/**
* displays a login screen
*
* @string $extra_vars for login url
* @return string
*/
abstract function login_screen($extra_vars);
* displays a login screen
*
* @param string $extra_vars for login url
*/
function login_screen($extra_vars)
{
//error_log(__METHOD__."() server[template_dir]=".array2string($GLOBALS['egw_info']['server']['template_dir']).", this->template=$this->template, this->template_dir=$this->template_dir, get_class(this)=".get_class($this));
$tmpl = new Template($GLOBALS['egw_info']['server']['template_dir']);
$tmpl->set_file(array('login_form' => 'login.tpl'));
$tmpl->set_var('lang_message',$GLOBALS['loginscreenmessage']);
$last_loginid = $_COOKIE['last_loginid'];
if($GLOBALS['egw_info']['server']['show_domain_selectbox'])
{
foreach($GLOBALS['egw_domain'] as $domain => $data)
{
$domains[$domain] = $domain;
}
$tmpl->set_var(array(
'lang_domain' => lang('domain'),
'select_domain' => html::select('logindomain',$_COOKIE['last_domain'],$domains,true,'tabindex="2"'),
));
}
else
{
/* trick to make domain section disapear */
$tmpl->set_block('login_form','domain_selection');
$tmpl->set_var('domain_selection',$GLOBALS['egw_info']['user']['domain'] ?
html::input_hidden('logindomain',$GLOBALS['egw_info']['user']['domain']) : '');
if($last_loginid !== '')
{
reset($GLOBALS['egw_domain']);
list($default_domain) = each($GLOBALS['egw_domain']);
if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
{
$last_loginid .= '@' . $_COOKIE['last_domain'];
}
}
}
$config_reg = config::read('registration');
if($config_reg['enable_registration'])
{
if ($config_reg['register_link'])
{
$reg_link='&nbsp;<a href="'. $GLOBALS['egw']->link('/registration/index.php','lang_code='.$_GET['lang']). '">'.lang('Not a user yet? Register now').'</a><br/>';
}
if ($config_reg['lostpassword_link'])
{
$lostpw_link='&nbsp;<a href="'. $GLOBALS['egw']->link('/registration/index.php','menuaction=registration.registration_ui.lost_password&lang_code='.$_GET['lang']). '">'.lang('Lost password').'</a><br/>';
}
if ($config_reg['lostid_link'])
{
$lostid_link='&nbsp;<a href="'. $GLOBALS['egw']->link('/registration/index.php','menuaction=registration.registration_ui.lost_username&lang_code='.$_GET['lang']). '">'.lang('Lost Login Id').'</a><br/>';
}
/* if at least one option of "registration" is activated display the registration section */
if($config_reg['register_link'] || $config_reg['lostpassword_link'] || $config_reg['lostid_link'] )
{
$tmpl->set_var(array(
'register_link' => $reg_link,
'lostpassword_link' => $lostpw_link,
'lostid_link' => $lostid_link,
));
}
else
{
/* trick to make registration section disapear */
$tmpl->set_block('login_form','registration');
$tmpl->set_var('registration','');
}
}
$tmpl->set_var('login_url', $GLOBALS['egw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
$tmpl->set_var('version',$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
$tmpl->set_var('cd',check_logoutcode($_GET['cd']));
$tmpl->set_var('cookie',$last_loginid);
$tmpl->set_var('lang_username',lang('username'));
$tmpl->set_var('lang_password',lang('password'));
$tmpl->set_var('lang_login',lang('login'));
$tmpl->set_var('website_title', $GLOBALS['egw_info']['server']['site_title']);
$tmpl->set_var('template_set',$this->template);
if (substr($GLOBALS['egw_info']['server']['login_logo_file'], 0, 4) == 'http' ||
strpos($GLOBALS['egw_info']['server']['login_logo_file'], '//') !== false)
{
$var['logo_file'] = $GLOBALS['egw_info']['server']['login_logo_file'];
}
else
{
$var['logo_file'] = common::image('phpgwapi',$GLOBALS['egw_info']['server']['login_logo_file']?$GLOBALS['egw_info']['server']['login_logo_file']:'logo');
}
$var['logo_url'] = $GLOBALS['egw_info']['server']['login_logo_url']?$GLOBALS['egw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
if (substr($var['logo_url'],0,4) != 'http')
{
$var['logo_url'] = 'http://'.$var['logo_url'];
}
$var['logo_title'] = $GLOBALS['egw_info']['server']['login_logo_title']?$GLOBALS['egw_info']['server']['login_logo_title']:'www.eGroupWare.org';
$tmpl->set_var($var);
/* language section if activated in site config */
if (@$GLOBALS['egw_info']['server']['login_show_language_selection'])
{
$tmpl->set_var(array(
'lang_language' => lang('Language'),
'select_language' => html::select('lang',$GLOBALS['egw_info']['user']['preferences']['common']['lang'],
translation::get_installed_langs(),true,'tabindex="1"'),
));
}
else
{
$tmpl->set_block('login_form','language_select');
$tmpl->set_var('language_select','');
}
/********************************************************\
* Check if authentification via cookies is allowed *
* and place a time selectbox, how long cookie is valid *
\********************************************************/
if($GLOBALS['egw_info']['server']['allow_cookie_auth'])
{
$tmpl->set_block('login_form','remember_me_selection');
$tmpl->set_var('lang_remember_me',lang('Remember me'));
$tmpl->set_var('select_remember_me',html::select('remember_me', '', array(
'' => lang('not'),
'1hour' => lang('1 Hour'),
'1day' => lang('1 Day'),
'1week'=> lang('1 Week'),
'1month' => lang('1 Month'),
'forever' => lang('Forever'),
),true,'tabindex="3"'));
}
else
{
/* trick to make remember_me section disapear */
$tmpl->set_block('login_form','remember_me_selection');
$tmpl->set_var('remember_me_selection','');
}
$tmpl->set_var('autocomplete', ($GLOBALS['egw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
$GLOBALS['egw']->js->set_onload('document.login_form.login.focus();');
$this->render($tmpl->fp('loginout','login_form'),false,false);
}
/**
* displays a login denied message
*
* @return string
*/
abstract function denylogin_screen();
* displays a login denied message
*/
function denylogin_screen()
{
$tmpl = new Template($GLOBALS['egw_info']['server']['template_dir']);
$tmpl->set_file(array(
'login_form' => 'login_denylogin.tpl'
));
$tmpl->set_var(array(
'template_set' => 'default',
'deny_msg' => lang('Oops! You caught us in the middle of system maintainance.').
'<br />'.lang('Please, check back with us shortly.'),
));
$this->render($tmpl->fp('loginout','login_form'),false,false);
}
/**
* Get footer as array to eg. set as vars for a template (from idots' head.inc.php)

View File

@ -357,179 +357,6 @@ egw.set_user('.$GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['acc
isset($GLOBALS['egw_info']['flags']['nonavbar']) && !$GLOBALS['egw_info']['flags']['nonavbar'];
}
/**
* displays a login screen
*
* @param string $extra_vars for login url
*/
function login_screen($extra_vars)
{
$tmpl = new Template($GLOBALS['egw_info']['server']['template_dir']);
$tmpl->set_file(array('login_form' => 'login.tpl'));
$tmpl->set_var('lang_message',$GLOBALS['loginscreenmessage']);
$last_loginid = $_COOKIE['last_loginid'];
if($GLOBALS['egw_info']['server']['show_domain_selectbox'])
{
foreach($GLOBALS['egw_domain'] as $domain => $data)
{
$domains[$domain] = $domain;
}
$tmpl->set_var(array(
'lang_domain' => lang('domain'),
'select_domain' => html::select('logindomain',$_COOKIE['last_domain'],$domains,true,'tabindex="2"'),
));
}
else
{
/* trick to make domain section disapear */
$tmpl->set_block('login_form','domain_selection');
$tmpl->set_var('domain_selection',$GLOBALS['egw_info']['user']['domain'] ?
html::input_hidden('logindomain',$GLOBALS['egw_info']['user']['domain']) : '');
if($last_loginid !== '')
{
reset($GLOBALS['egw_domain']);
list($default_domain) = each($GLOBALS['egw_domain']);
if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
{
$last_loginid .= '@' . $_COOKIE['last_domain'];
}
}
}
$config_reg = config::read('registration');
if($config_reg['enable_registration'])
{
if ($config_reg['register_link'])
{
$reg_link='&nbsp;<a href="'. $GLOBALS['egw']->link('/registration/index.php','lang_code='.$_GET['lang']). '">'.lang('Not a user yet? Register now').'</a><br/>';
}
if ($config_reg['lostpassword_link'])
{
$lostpw_link='&nbsp;<a href="'. $GLOBALS['egw']->link('/registration/index.php','menuaction=registration.registration_ui.lost_password&lang_code='.$_GET['lang']). '">'.lang('Lost password').'</a><br/>';
}
if ($config_reg['lostid_link'])
{
$lostid_link='&nbsp;<a href="'. $GLOBALS['egw']->link('/registration/index.php','menuaction=registration.registration_ui.lost_username&lang_code='.$_GET['lang']). '">'.lang('Lost Login Id').'</a><br/>';
}
/* if at least one option of "registration" is activated display the registration section */
if($config_reg['register_link'] || $config_reg['lostpassword_link'] || $config_reg['lostid_link'] )
{
$tmpl->set_var(array(
'register_link' => $reg_link,
'lostpassword_link' => $lostpw_link,
'lostid_link' => $lostid_link,
));
}
else
{
/* trick to make registration section disapear */
$tmpl->set_block('login_form','registration');
$tmpl->set_var('registration','');
}
}
$tmpl->set_var('login_url', $GLOBALS['egw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
$tmpl->set_var('version',$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
$tmpl->set_var('cd',check_logoutcode($_GET['cd']));
$tmpl->set_var('cookie',$last_loginid);
$tmpl->set_var('lang_username',lang('username'));
$tmpl->set_var('lang_password',lang('password'));
$tmpl->set_var('lang_login',lang('login'));
$tmpl->set_var('website_title', $GLOBALS['egw_info']['server']['site_title']);
$tmpl->set_var('template_set',$this->template);
if (substr($GLOBALS['egw_info']['server']['login_logo_file'], 0, 4) == 'http' ||
strpos($GLOBALS['egw_info']['server']['login_logo_file'], '//') !== false)
{
$var['logo_file'] = $GLOBALS['egw_info']['server']['login_logo_file'];
}
else
{
$var['logo_file'] = common::image('phpgwapi',$GLOBALS['egw_info']['server']['login_logo_file']?$GLOBALS['egw_info']['server']['login_logo_file']:'logo');
}
$var['logo_url'] = $GLOBALS['egw_info']['server']['login_logo_url']?$GLOBALS['egw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
if (substr($var['logo_url'],0,4) != 'http')
{
$var['logo_url'] = 'http://'.$var['logo_url'];
}
$var['logo_title'] = $GLOBALS['egw_info']['server']['login_logo_title']?$GLOBALS['egw_info']['server']['login_logo_title']:'www.eGroupWare.org';
$tmpl->set_var($var);
/* language section if activated in site config */
if (@$GLOBALS['egw_info']['server']['login_show_language_selection'])
{
$tmpl->set_var(array(
'lang_language' => lang('Language'),
'select_language' => html::select('lang',$GLOBALS['egw_info']['user']['preferences']['common']['lang'],
translation::get_installed_langs(),true,'tabindex="1"'),
));
}
else
{
$tmpl->set_block('login_form','language_select');
$tmpl->set_var('language_select','');
}
/********************************************************\
* Check if authentification via cookies is allowed *
* and place a time selectbox, how long cookie is valid *
\********************************************************/
if($GLOBALS['egw_info']['server']['allow_cookie_auth'])
{
$tmpl->set_block('login_form','remember_me_selection');
$tmpl->set_var('lang_remember_me',lang('Remember me'));
$tmpl->set_var('select_remember_me',html::select('remember_me', '', array(
'' => lang('not'),
'1hour' => lang('1 Hour'),
'1day' => lang('1 Day'),
'1week'=> lang('1 Week'),
'1month' => lang('1 Month'),
'forever' => lang('Forever'),
),true,'tabindex="3"'));
}
else
{
/* trick to make remember_me section disapear */
$tmpl->set_block('login_form','remember_me_selection');
$tmpl->set_var('remember_me_selection','');
}
$tmpl->set_var('autocomplete', ($GLOBALS['egw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
$GLOBALS['egw']->js->set_onload('document.login_form.login.focus();');
$this->render($tmpl->fp('loginout','login_form'),false,false);
}
/**
* displays a login denied message
*/
function denylogin_screen()
{
$tmpl = new Template($GLOBALS['egw_info']['server']['template_dir']);
$tmpl->set_file(array(
'login_form' => 'login_denylogin.tpl'
));
$tmpl->set_var(array(
'template_set' => 'default',
'deny_msg' => lang('Oops! You caught us in the middle of system maintainance.').
'<br />'.lang('Please, check back with us shortly.'),
));
$this->render($tmpl->fp('loginout','login_form'),false,false);
}
/**
* Get navbar as array to eg. set as vars for a template (from idots' navbar.inc.php)
*