diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc
index eb2a03a4..2efd4d82 100644
--- a/lam/lib/modules.inc
+++ b/lam/lib/modules.inc
@@ -971,6 +971,11 @@ class accountContainer {
}
}
}
+ if ($profileLoaded) {
+ $profileName = $_POST['accountContainerSelectLoadProfile'];
+ $result[] = array('INFO', _('Profile "%s" loaded.'), '
' . _('Setting saved') . '
' .
+ '' . _('Click here to make this your default profile.') . '', 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);
diff --git a/lam/lib/profiles.inc b/lam/lib/profiles.inc
index 45f4d521..16681471 100644
--- a/lam/lib/profiles.inc
+++ b/lam/lib/profiles.inc
@@ -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
diff --git a/lam/style/500_layout.css b/lam/style/500_layout.css
index 91df2dee..1930854b 100644
--- a/lam/style/500_layout.css
+++ b/lam/style/500_layout.css
@@ -763,6 +763,10 @@ div.dialog-page {
float: left;
}
+div.lam-dialog-msg {
+ margin: 10px;
+}
+
/* mobile */
@media only screen and (max-width: 40.0625em) {
diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js
index 2cef5f9e..e724b241 100644
--- a/lam/templates/lib/500_lam.js
+++ b/lam/templates/lib/500_lam.js
@@ -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();
});