1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8if (basename($_SERVER['SCRIPT_NAME']) === basename(__FILE__)) {
9	die('This script may only be included.');
10}
11
12// Handle the current user prefs in session
13if (! isset($_SESSION['u_info']) || $_SESSION['u_info']['login'] != $user) {
14	$_SESSION['u_info'] = [];
15	$_SESSION['u_info']['login'] = $user;
16	$_SESSION['u_info']['group'] = ( $user ) ? $userlib->get_user_default_group($user) : '';
17	if (empty($user)) {
18		$_SESSION['preferences'] = []; // For anonymous, store some preferences like the theme in the session.
19	}
20}
21
22// Define the globals $u_info array for use in php / smarty
23$u_info =& $_SESSION['u_info'];
24$smarty->assign_by_ref('u_info', $u_info);
25
26$smarty->assign_by_ref('user', $user);
27$user_preferences = []; // Used for cache
28
29if ($user) {
30	$default_group = $group = $_SESSION['u_info']['group'];
31	$smarty->assign('group', $group); // do not use by_ref as $group can be changed in the .php
32	$smarty->assign('default_group', $group);
33
34	// Initialize user preferences
35
36	// Defaults that are not in global prefs
37	$prefs['user_article_watch_editor'] = 'n';
38	$prefs['user_blog_watch_editor'] = 'n';
39	$prefs['user_calendar_watch_editor'] = 'n';
40	$prefs['user_wiki_watch_editor'] = 'n';
41	$prefs['user_tracker_watch_editor'] = 'n';
42	$prefs['user_comment_watch_editor'] = 'n';
43	$prefs['user_category_watch_editor'] = 'n';
44	$prefs['user_plugin_approval_watch_editor'] = 'n';
45
46	// Get all user prefs in one query
47	$tikilib->get_user_preferences($user);
48
49	// Check pref for user theme
50	if ($prefs['change_theme'] !== 'y') {
51		unset($user_preferences[$user]['theme']);
52		unset($user_preferences[$user]['theme_option']);
53	} else {
54		if (! empty($user_preferences[$user]['theme']) && empty($user_preferences[$user]['theme_option'])) {
55			$prefs['theme_option'] = '';
56		}
57	}
58
59	// Prefs overriding
60	$prefs = array_merge($prefs, $user_preferences[$user]);
61
62	// Set the userPage name for this user since other scripts use this value.
63	$userPage = $prefs['feature_wiki_userpage_prefix'] . $user;
64	$exist = $tikilib->page_exists($userPage);
65	$smarty->assign('userPage', $userPage);
66	$smarty->assign('userPage_exists', $exist);
67} else {
68	if (isset($_SESSION['preferences'])) {
69		$prefs = array_merge($prefs, $_SESSION['preferences']);
70	}
71	$allowMsgs = 'n';
72}
73
74$smarty->assign('IP', $tikilib->get_ip_address());
75
76$tikilib->set_display_timezone($user);
77
78if (! empty($section) && $section == 'admin' && ! empty($prefs['language_admin'])) {
79	$prefs['language'] = $prefs['language_admin'];
80}
81
82$smarty->refreshLanguage();
83
84if ($prefs['language'] != $prefs['site_language']) {
85	$prefslib = TikiLib::lib('prefs');
86	$translatablePreferences = $prefslib->getTranslatablePreferences();
87
88	foreach ($translatablePreferences as $preference) {
89		if (! empty($prefs[$preference . '_' . $prefs['language']])) {
90			$prefs[$preference . '_translated'] = $prefs[$preference . '_' . $prefs['language']];
91		}
92	}
93}
94