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