support to store default profile for new users

This commit is contained in:
Roland Gruber 2017-10-20 20:26:35 +02:00
parent 54bf006d5c
commit 2c14a5ae61
4 changed files with 69 additions and 1 deletions

View File

@ -971,6 +971,11 @@ class accountContainer {
}
}
}
if ($profileLoaded) {
$profileName = $_POST['accountContainerSelectLoadProfile'];
$result[] = array('INFO', _('Profile "%s" loaded.'), '<div class="hidden lam-dialog-msg" id="lam-make-default-profile-dlg">' . _('Setting saved') . '</div>' .
'<a href="#" id="lam-make-default-profile" data-name="%s" data-typeid="%s" data-ok="%s">' . _('Click here to make this your default profile.') . '</a>', array($profileName, $profileName, $this->get_type()->getId(), _('Ok')));
}
// update titles
$this->titleBarTitle = $typeObject->getTitleBarTitle($this);
$this->titleBarSubtitle = $typeObject->getTitleBarSubtitle($this);
@ -1714,7 +1719,16 @@ class accountContainer {
$this->initModules();
// sort module buttons
$this->sortModules();
$profile = \LAM\PROFILES\loadAccountProfile('default', $this->type->getId());
$profileName = 'default';
$profileCookieKey = 'defaultProfile_' . $this->get_type()->getId();
if (!empty($_COOKIE[$profileCookieKey])) {
$cookieProfileName = $_COOKIE[$profileCookieKey];
if (\LAM\PROFILES\profileExists($profileName, $this->get_type()->getId())) {
$profileName = $cookieProfileName;
$this->lastLoadedProfile = $cookieProfileName;
}
}
$profile = \LAM\PROFILES\loadAccountProfile($profileName, $this->type->getId());
// pass profile to each module
$modules = array_keys($this->module);
foreach ($modules as $module) $this->module[$module]->load_profile($profile);

View File

@ -64,6 +64,20 @@ function getAccountProfiles($typeId, $profile = null) {
return $ret;
}
/**
* Returns if the given profile exists.
*
* @param string name profile name
* @param string $typeId type id
* @return bool exists
*/
function profileExists($name, $typeId) {
if (!isValidProfileName($name) || !preg_match("/^[a-z0-9_]+$/i", $typeId) || ($typeId == null)) {
return false;
}
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $name . "." . $typeId;
return is_file($file);
}
/**
* Loads an profile of the given account type

View File

@ -763,6 +763,10 @@ div.dialog-page {
float: left;
}
div.lam-dialog-msg {
margin: 10px;
}
/* mobile */
@media only screen and (max-width: 40.0625em) {

View File

@ -791,7 +791,43 @@ window.lam.form.autoTrim = function() {
});
};
window.lam.dialog = window.lam.dialog || {};
window.lam.dialog.showMessage = function(title, okText, divId) {
var buttonList = {};
buttonList[okText] = function() { jQuery(this).dialog("close"); };
jQuery('#' + divId).dialog({
modal: true,
title: title,
dialogClass: 'defaultBackground',
buttons: buttonList,
width: 'auto'
});
};
window.lam.account = window.lam.account || {};
/**
* Adds a listener on the link to set default profile.
*/
window.lam.account.addDefaultProfileListener = function() {
var defaultProfileLink = jQuery('#lam-make-default-profile');
if (defaultProfileLink) {
defaultProfileLink.click(function() {
var link = $(this);
var typeId = link.data('typeid');
var name = link.data('name');
var okText = link.data('ok');
var date = new Date();
date.setTime(date.getTime() + (365*24*60*60*1000));
document.cookie = 'defaultProfile_' + typeId + '=' + name + '; expires=' + date.toUTCString();
window.lam.dialog.showMessage(null, okText, 'lam-make-default-profile-dlg');
});
}
};
jQuery(document).ready(function() {
window.lam.gui.equalHeight();
window.lam.form.autoTrim();
window.lam.account.addDefaultProfileListener();
});