Commit 17487f3e authored by Fabio Montefuscolo's avatar Fabio Montefuscolo

[NEW] Makes possible to select a preferred perspective and stick with it

[FIX] Perspective was not loaded after login
parent 08394975
......@@ -23,19 +23,49 @@ class PerspectiveLib
$this->perspectivePreferences = TikiDb::get()->table('tiki_perspective_preferences');
}
/**
* @param $user
* @return int
*/
function get_preferred_perspective($user)
{
$perspectiveId = null;
if(empty($user)) {
return $perspectiveId;
}
$sql = "SELECT value FROM tiki_user_preferences WHERE prefName='perspective_preferred' AND user=?";
$perspectiveId = TikiDb::get()->getOne($sql, [$user]);
if(is_numeric($perspectiveId)) {
return (int) $perspectiveId;
}
return $perspectiveId;
}
/**
* @param $prefs
* @return int
*/
function get_current_perspective($prefs)
{
global $user;
$tikilib = TikiLib::lib('tiki');
$perspectiveId = $this->get_preferred_perspective($user);
if (isset($_REQUEST['perspectiveId'])) {
return (int) $_REQUEST['perspectiveId'];
$perspectiveId = (int) $_REQUEST['perspectiveId'];
} elseif (isset($_SESSION['current_perspective'])) {
return (int) $_SESSION['current_perspective'];
$perspectiveId = (int) $_SESSION['current_perspective'];
}
if($perspectiveId) {
return $perspectiveId;
}
$tikilib = TikiLib::lib("tiki");
if (method_exists($tikilib, "get_ip_address")) {
$ip = $tikilib->get_ip_address();
}
......@@ -137,6 +167,20 @@ class PerspectiveLib
return $out;
}
function load_perspective_preferences()
{
global $prefs, $section;
if (! isset($section) || $section != 'admin') {
if ($persp = $this->get_current_perspective($prefs)) {
$perspectivePreferences = $this->get_preferences($persp);
$prefs = $perspectivePreferences + $prefs;
}
}
return $prefs;
}
/**
* @param $perspectiveId
* @return mixed
......@@ -165,7 +209,9 @@ class PerspectiveLib
*/
function set_perspective($perspective, $by_area = false)
{
global $prefs, $url_scheme, $tikiroot;
global $prefs, $url_scheme, $user, $tikiroot;
$preferred_perspective = $this->get_preferred_perspective($user);
if ($this->get_perspective($perspective) || empty($perspective)) {
if ($prefs['multidomain_switchdomain'] == 'y') {
......@@ -186,7 +232,7 @@ class PerspectiveLib
}
}
}
if (empty($perspective)) {
if (empty($perspective) && !$preferred_perspective) {
unset($_SESSION['current_perspective']);
unset($_SESSION['current_perspective_name']);
} else {
......
......@@ -290,16 +290,6 @@ function initialize_prefs($force = false)
$cachelib->cacheItem('global_preferences', serialize($prefs));
}
if ($prefs['feature_perspective'] == 'y') {
if (! isset($section) || $section != 'admin') {
$perspectivelib = TikiLib::lib('perspective');
if ($persp = $perspectivelib->get_current_perspective($prefs)) {
$perspectivePreferences = $perspectivelib->get_preferences($persp);
$prefs = $perspectivePreferences + $prefs;
}
}
}
// Override preferences with system-configured preferences.
$system = $systemConfiguration->preference->toArray();
// Also include the site_ versions
......
......@@ -203,6 +203,21 @@
{/if}
</div>
</div>
{if $prefs.feature_perspective eq 'y' and $perspectives|@count gt 0}
<div class="form-group row">
<label class="col-form-label col-md-4" for="perspective_preferred">
{tr}Preferred perspective{/tr}
</label>
<div class="col-md-8">
<select id="perspective_preferred" name="perspective_preferred" class="form-control">
<option value="">----</option>
{foreach from=$perspectives item=persp}
<option value="{$persp.perspectiveId|escape}"{if $persp.perspectiveId eq $user_prefs.perspective_preferred} selected="selected"{/if}>{$persp.name|escape}</option>
{/foreach}
</select>
</div>
</div>
{/if}
<div class="form-group row">
<label class="col-form-label col-md-4" for="mailCharset">
{tr}Email character set{/tr}
......
......@@ -454,6 +454,7 @@ if (($prefs['rememberme'] != 'disabled') and (isset($_COOKIE["$user_cookie_site"
}
}
}
// if the auth method is 'web site', look for the username in $_SERVER
if (($prefs['auth_method'] == 'ws') and (isset($_SERVER['REMOTE_USER']))) {
if ($userlib->user_exists($_SERVER['REMOTE_USER'])) {
......@@ -538,6 +539,13 @@ if (isset($_SESSION["$user_cookie_site"])) {
}
}
if ($prefs['feature_perspective'] === 'y') {
$perspectivelib = TikiLib::lib('perspective');
$perspectivelib->load_perspective_preferences();
}
require_once('lib/setup/perms.php');
// --------------------------------------------------------------
// deal with register_globals
......
......@@ -12,6 +12,8 @@ $section = 'mytiki';
require_once('tiki-setup.php');
$modlib = TikiLib::lib('mod');
$userprefslib = TikiLib::lib('userprefs');
$perspectivelib = TikiLib::lib('perspective');
// User preferences screen
if ($prefs['feature_userPreferences'] != 'y' && $prefs['change_password'] != 'y' && $tiki_p_admin_users != 'y') {
$smarty->assign('msg', tra("This feature is disabled") . ": feature_userPreferences");
......@@ -60,6 +62,11 @@ $foo2 = str_replace("tiki-user_preferences", "tiki-index", $foo["path"]);
$smarty->assign('url_edit', $tikilib->httpPrefix() . $foo1);
$smarty->assign('url_visit', $tikilib->httpPrefix() . $foo2);
$smarty->assign('show_mouseover_user_info', isset($prefs['show_mouseover_user_info']) ? $prefs['show_mouseover_user_info'] : $prefs['feature_community_mouseover']);
if ($prefs['feature_perspective'] === 'y') {
$smarty->assign('perspectives', $perspectivelib->list_perspectives());
}
if ($prefs['feature_userPreferences'] == 'y' && isset($_REQUEST["new_prefs"]) && $access->checkOrigin()) {
check_ticket('user-prefs');
// setting preferences
......@@ -265,6 +272,12 @@ if ($prefs['feature_userPreferences'] == 'y' && isset($_REQUEST["new_prefs"]) &&
$tikilib->set_user_preference($userwatch, 'xmpp_custom_server_http_bind', $_REQUEST['xmpp_custom_server_http_bind']);
}
if (isset($_REQUEST['perspective_preferred']) && $perspectivelib->perspective_exists($_REQUEST['perspective_preferred'])) {
$tikilib->set_user_preference($userwatch, 'perspective_preferred', $_REQUEST['perspective_preferred']);
} else {
$tikilib->set_user_preference($userwatch, 'perspective_preferred', null);
}
TikiLib::events()->trigger(
'tiki.user.update',
[
......@@ -349,6 +362,17 @@ if (isset($_REQUEST['deleteaccount']) && $tiki_p_delete_account == 'y' && $acces
die();
}
if(!empty($_POST)) {
// This avoids accident form ressubmission
header('Location:' . basename(__FILE__));
}
/**
* Don't do any write operation from here
*/
$location = [
'lat' => (float) $tikilib->get_user_preference($userwatch, 'lat', ''),
'lon' => (float) $tikilib->get_user_preference($userwatch, 'lon', ''),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment