1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category frontend
|
5
|
* @package account
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: preferences_form.php 1987 2013-10-19 00:49:58Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/preferences_form.php $
|
14
|
* @lastmodified $Date: 2013-10-19 02:49:58 +0200 (Sat, 19 Oct 2013) $
|
15
|
*
|
16
|
*/
|
17
|
|
18
|
/* -------------------------------------------------------- */
|
19
|
// Must include code to stop this file being accessed directly
|
20
|
if(!defined('WB_PATH')) {
|
21
|
require_once(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php');
|
22
|
throw new IllegalFileException();
|
23
|
}
|
24
|
/* -------------------------------------------------------- */
|
25
|
|
26
|
$oReg = WbAdaptor::getInstance();
|
27
|
$mLang = Translate::getinstance();
|
28
|
|
29
|
if($wb->is_authenticated() === false) {
|
30
|
// User needs to login first
|
31
|
header("Location: ".WB_URL."/account/login.php?redirect=".$wb->link);
|
32
|
exit(0);
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
*
|
37
|
*/
|
38
|
$sUserLanguage = LANGUAGE;
|
39
|
// Check existing language
|
40
|
$sql = 'SELECT `language` ';
|
41
|
$sql .= 'FROM `'.TABLE_PREFIX.'users` ';
|
42
|
$sql .= 'WHERE `user_id` = '.$wb->get_user_id();
|
43
|
if ($sUserLanguage = $database->get_one($sql)) {
|
44
|
$_SESSION['LANGUAGE'] = $sUserLanguage;
|
45
|
}
|
46
|
|
47
|
$sDefaultLanguage = DEFAULT_LANGUAGE;
|
48
|
//$sLang = $wb->get_session('LANGUAGE');
|
49
|
$sLanguage = LANGUAGE.'.php';
|
50
|
|
51
|
$LanguageDir = WB_PATH .'/account/languages/';
|
52
|
$sLanguageFile = ( file_exists($LanguageDir.$sUserLanguage.'.php') ? $LanguageDir.$sUserLanguage.'.php' : $LanguageDir.$sLanguage);
|
53
|
$sLanguageFile = ( is_readable($sLanguageFile) ? $sLanguageFile : $LanguageDir.$sDefaultLanguage.'.php' );
|
54
|
// load module default language file (EN)
|
55
|
require($sLanguageFile);
|
56
|
|
57
|
if(!function_exists('utf8_check')) { require(WB_PATH.'/framework/functions-utf8.php'); }
|
58
|
|
59
|
$sIncludeHeadLinkCss = '';
|
60
|
if( is_readable(WB_PATH .'/account/frontend.css')) {
|
61
|
$sIncludeHeadLinkCss .= '<link href="'.WB_URL.'/account/frontend.css"';
|
62
|
$sIncludeHeadLinkCss .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
|
63
|
}
|
64
|
|
65
|
$error = array();
|
66
|
$success = array();
|
67
|
|
68
|
$template = new Template(WB_PATH .'/account/htt','keep');
|
69
|
|
70
|
// show template
|
71
|
$template->set_file('page', 'preferences.htt');
|
72
|
$template->set_block('page', 'main_block', 'main');
|
73
|
|
74
|
/**
|
75
|
*
|
76
|
*/
|
77
|
switch($wb->get_post('action')):
|
78
|
case 'details':
|
79
|
require_once(WB_PATH .'/account/details.php');
|
80
|
break;
|
81
|
case 'email':
|
82
|
require_once(WB_PATH .'/account/email.php');
|
83
|
break;
|
84
|
case 'password':
|
85
|
require_once(WB_PATH .'/account/password.php');
|
86
|
break;
|
87
|
default:
|
88
|
// do nothing
|
89
|
endswitch; // switch
|
90
|
|
91
|
// get existing values from database
|
92
|
$sql = "SELECT `display_name`,`email`,`language`,`timezone`,`date_format`,`time_format` ";
|
93
|
$sql .= "FROM `".TABLE_PREFIX."users` ";
|
94
|
$sql .= "WHERE `user_id` = '".$wb->get_user_id()."'";
|
95
|
|
96
|
if($rowset = $database->query($sql)) {
|
97
|
$row = $rowset->fetchRow();
|
98
|
$_SESSION['LANGUAGE'] = $row['language'];
|
99
|
$_SESSION['EMAIL'] = $row['email'];
|
100
|
$_SESSION['DISPLAY_NAME'] = $row['display_name'];
|
101
|
$_SESSION['TIMEZONE'] = $row['timezone'];
|
102
|
$_SESSION['DATE_FORMAT'] = $row['date_format'];
|
103
|
$_SESSION['TIME_FORMAT'] = $row['time_format'];
|
104
|
}
|
105
|
if($database->is_error()) $error[] = $database->get_error();
|
106
|
// insert values into form
|
107
|
$template->set_var('DISPLAY_NAME', $row['display_name']);
|
108
|
$template->set_var('EMAIL', $row['email']);
|
109
|
$template->set_var('ACTION_URL', WB_URL.'/account/preferences.php');
|
110
|
|
111
|
$_SESSION['HTTP_REFERER'] =( ($_SESSION['LANGUAGE'] != LANGUAGE ) ? WB_URL.'?lang='.$_SESSION['LANGUAGE'] : $_SESSION['HTTP_REFERER']);
|
112
|
$template->set_block('main_block', 'show_detail_send_block', 'show_detail_send');
|
113
|
$template->set_block('main_block', 'show_email_send_block', 'show_email_send');
|
114
|
$template->set_block('main_block', 'show_password_send_block', 'show_password_send');
|
115
|
|
116
|
$aLangAddons = array();
|
117
|
$aLangBrowser = array();
|
118
|
// default, if no information from client available
|
119
|
$sAutoLanguage = DEFAULT_LANGUAGE;
|
120
|
|
121
|
// read available languages from table addons
|
122
|
$aLangAddons = $admin->getAvailableLanguages();
|
123
|
|
124
|
$aLangUsed = array_flip(explode(',',$wb->getLanguagesInUsed()));
|
125
|
$aLangUsed = array_intersect_key($aLangAddons, $aLangUsed);
|
126
|
if( (sizeof($aLangUsed)<2) || !($oReg->PageLanguages) ){
|
127
|
$aLangUsed = $aLangAddons;
|
128
|
}
|
129
|
|
130
|
if( !(array_key_exists($sUserLanguage, $aLangUsed)) ) {
|
131
|
$template->parse('show_detail_send', '');
|
132
|
$template->parse('show_email_send', '');
|
133
|
$template->parse('show_password_send', '');
|
134
|
} else {
|
135
|
$template->parse('show_detail_send', 'show_detail_send_block');
|
136
|
$template->parse('show_email_send', 'show_email_send_block');
|
137
|
$template->parse('show_password_send', 'show_password_send_block');
|
138
|
}
|
139
|
|
140
|
// Insert language text and messages visibilty="hidden"
|
141
|
// WB_URL.'/account/preferences.php'
|
142
|
$template->set_var(array(
|
143
|
'REFERER_ID' => ( $wb->get_session('HTTP_REFERER')!='' ? $_SESSION['HTTP_REFERER'] : WB_URL),
|
144
|
'HTTP_REFERER' => (!(array_key_exists($sUserLanguage, $aLangUsed)) ?WB_URL.'/account/preferences.php':( $wb->get_session('HTTP_REFERER')!='' ? $_SESSION['HTTP_REFERER'] : WB_URL)),
|
145
|
'CSS_BLOCK' => $sIncludeHeadLinkCss,
|
146
|
'TEXT_SAVE' => $TEXT['SAVE'],
|
147
|
'TEXT_RESET' => $TEXT['RESET'],
|
148
|
'SUBMIT_BUTTON' => (!(array_key_exists($sUserLanguage, $aLangUsed)) ?'submit':'button'),
|
149
|
'VALUE_BUTTON' => (!(array_key_exists($sUserLanguage, $aLangUsed)) ?'details':'cancel'),
|
150
|
'TEXT_CANCEL' => (!(array_key_exists($sUserLanguage, $aLangUsed)) ? $MOD_PREFERENCE['SAVE_LANGUAGE']:$TEXT['CANCEL']),
|
151
|
'MOD_PREFERENCE_SET_PREFERENCES_LANGUAGE' => !(array_key_exists($sUserLanguage, $aLangUsed)) ? $MOD_PREFERENCE['SET_PREFERENCES_LANGUAGE']:'',
|
152
|
'DISPLAY_PREFERENCES_LANGUAGE' => !(array_key_exists($sUserLanguage, $aLangUsed)) ? '':'display:none',
|
153
|
'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
|
154
|
'TEXT_EMAIL' => $TEXT['EMAIL'],
|
155
|
'TEXT_LANGUAGE' => $TEXT['LANGUAGE'],
|
156
|
'TEXT_TIMEZONE' => $TEXT['TIMEZONE'],
|
157
|
'TEXT_DATE_FORMAT' => $TEXT['DATE_FORMAT'],
|
158
|
'TEXT_TIME_FORMAT' => $TEXT['TIME_FORMAT'],
|
159
|
'TEXT_CURRENT_PASSWORD' => $TEXT['CURRENT_PASSWORD'],
|
160
|
'TEXT_NEW_PASSWORD' => $TEXT['NEW_PASSWORD'],
|
161
|
'TEXT_RETYPE_NEW_PASSWORD' => $TEXT['RETYPE_NEW_PASSWORD']
|
162
|
)
|
163
|
);
|
164
|
|
165
|
// read available languages from table addons and assign it to the template
|
166
|
$template->set_block('main_block', 'language_list_block', 'language_list');
|
167
|
foreach( $aLangUsed as $sDirectory => $sName )
|
168
|
{
|
169
|
$langIcons = ( empty($sDirectory) ? 'none' : strtolower($sDirectory));
|
170
|
|
171
|
$template->set_var('CODE', $sDirectory);
|
172
|
$template->set_var('NAME', $sName);
|
173
|
$template->set_var('FLAG', THEME_URL.'/images/flags/'.$langIcons);
|
174
|
$template->set_var('SELECTED', ( $_SESSION['LANGUAGE'] == $sDirectory ? ' selected="selected"' : '') );
|
175
|
|
176
|
$template->parse('language_list', 'language_list_block', true);
|
177
|
}
|
178
|
|
179
|
// Insert default timezone values
|
180
|
$user_time = true;
|
181
|
require(ADMIN_PATH.'/interface/timezones.php');
|
182
|
$template->set_block('main_block', 'timezone_list_block', 'timezone_list');
|
183
|
foreach($TIMEZONES AS $hour_offset => $title) {
|
184
|
$template->set_var('VALUE', $hour_offset);
|
185
|
$template->set_var('NAME', $title);
|
186
|
$template->set_var('SELECTED', ($wb->get_timezone() == ($hour_offset * 3600) ? ' selected="selected"' : '') );
|
187
|
$template->parse('timezone_list', 'timezone_list_block', true);
|
188
|
}
|
189
|
// Insert date format list
|
190
|
$user_time = true;
|
191
|
require(ADMIN_PATH.'/interface/date_formats.php');
|
192
|
$template->set_block('main_block', 'date_format_list_block', 'date_format_list');
|
193
|
foreach($DATE_FORMATS AS $format => $title)
|
194
|
{
|
195
|
$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
|
196
|
if($format != 'system_default') {
|
197
|
$template->set_var('VALUE', $format);
|
198
|
} else {
|
199
|
$template->set_var('VALUE', '');
|
200
|
}
|
201
|
$template->set_var('NAME', $title);
|
202
|
if($wb->get_session('DATE_FORMAT') == $format AND !isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) {
|
203
|
$template->set_var('SELECTED', 'selected="selected"');
|
204
|
} elseif($format == 'system_default' AND isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) {
|
205
|
$template->set_var('SELECTED', 'selected="selected"');
|
206
|
} else {
|
207
|
$template->set_var('SELECTED', '');
|
208
|
}
|
209
|
$template->parse('date_format_list', 'date_format_list_block', true);
|
210
|
}
|
211
|
|
212
|
// Insert time format list
|
213
|
$user_time = true;
|
214
|
require(ADMIN_PATH.'/interface/time_formats.php');
|
215
|
$template->set_block('main_block', 'time_format_list_block', 'time_format_list');
|
216
|
foreach($TIME_FORMATS AS $format => $title)
|
217
|
{
|
218
|
$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
|
219
|
if($format != 'system_default') {
|
220
|
$template->set_var('VALUE', $format);
|
221
|
} else {
|
222
|
$template->set_var('VALUE', '');
|
223
|
}
|
224
|
$template->set_var('NAME', $title);
|
225
|
if($wb->get_session('TIME_FORMAT') == $format AND !isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) {
|
226
|
$template->set_var('SELECTED', 'selected="selected"');
|
227
|
} elseif($format == 'system_default' AND isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) {
|
228
|
$template->set_var('SELECTED', 'selected="selected"');
|
229
|
} else {
|
230
|
$template->set_var('SELECTED', '');
|
231
|
}
|
232
|
$template->parse('time_format_list', 'time_format_list_block', true);
|
233
|
}
|
234
|
// Insert language headings
|
235
|
$template->set_var(array(
|
236
|
'HEADING_MY_SETTINGS' => $HEADING['MY_SETTINGS'],
|
237
|
'HEADING_MY_EMAIL' => $HEADING['MY_EMAIL'],
|
238
|
'HEADING_MY_PASSWORD' => $HEADING['MY_PASSWORD']
|
239
|
)
|
240
|
);
|
241
|
|
242
|
// Insert module releated language text and messages
|
243
|
$template->set_var(array(
|
244
|
'MOD_PREFERENCE_PLEASE_SELECT' => $MOD_PREFERENCE['PLEASE_SELECT'],
|
245
|
'MOD_PREFERENCE_SAVE_SETTINGS' => $MOD_PREFERENCE['SAVE_SETTINGS'],
|
246
|
'MOD_PREFERENCE_SAVE_EMAIL' => $MOD_PREFERENCE['SAVE_EMAIL'],
|
247
|
'MOD_PREFERENCE_SAVE_PASSWORD' => $MOD_PREFERENCE['SAVE_PASSWORD'],
|
248
|
)
|
249
|
);
|
250
|
// Insert error and/or success messages
|
251
|
$template->set_block('main_block', 'error_block', 'error_list');
|
252
|
$template->set_var('ERROR_VALUE', '');
|
253
|
if(sizeof($error)>0){
|
254
|
$template->set_var('ERROR_VALUE', $wb->format_message(implode('<br />',$error),'error'));
|
255
|
$template->parse('error_list', 'error_block', true);
|
256
|
} else {
|
257
|
$template->parse('error_list', '');
|
258
|
}
|
259
|
|
260
|
$template->set_block('main_block', 'success_block', 'success_list');
|
261
|
$template->set_var('SUCCESS_VALUE', '');
|
262
|
if(sizeof($success)!=0){
|
263
|
$template->set_var('SUCCESS_VALUE', $wb->format_message(implode('<br />',$success),'ok'));
|
264
|
$template->parse('success_list', 'success_block', true);
|
265
|
} else {
|
266
|
$template->parse('success_list', '');
|
267
|
}
|
268
|
// Parse template for preferences form
|
269
|
$template->parse('main', 'main_block', false);
|
270
|
$template->pparse('output', 'page');
|