forked from Sleepcap/vDiplomacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usercp.php
executable file
·248 lines (194 loc) · 7.53 KB
/
usercp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @package Base
* @subpackage Forms
*/
require_once('header.php');
require_once(l_r('objects/mailer.php'));
global $Mailer;
$Mailer = new Mailer();
if(!$User->type['User'])
{
libHTML::error(l_t("You can't use the user control panel, you're using a guest account."));
}
libHTML::starthtml();
if ( isset($_REQUEST['optout']) )
{
if ( $_REQUEST['optout'] == 'on' && !$User->type['Donator'] )
{
libHTML::notice(l_t("Opt-out"), l_t("Are you sure you want to opt-out of Plura? It helps keep this place running and on ".
"most modern computers is barely noticable.")."<br />
<form><input type='submit' class='form-submit' name='optout' value='".l_t("Opt-out")."' /></form>");
}
elseif( $_REQUEST['optout'] == l_t('Opt-out') && !$User->type['Donator'] )
{
$DB->sql_put("UPDATE wD_Users SET type = CONCAT_WS(',',type,'Donator') WHERE id = ".$User->id);
$User->type['Donator'] = true;
libHTML::notice(l_t("Opt-out"), l_t("You've opted-out of running the Plura applet. If you decide to re-enable it ".
"later the <a href='faq.php' class='light'>FAQ</a> has a link to do so."));
}
elseif( $_REQUEST['optout'] == 'off' && $User->type['Donator'] )
{
libHTML::notice(l_t("Opt-out"), l_t("Would you like to opt back into running the Plura Java applet?")."<br />
<form><input type='submit' class='form-submit' name='optout' value='".l_t('Opt-in')."' /></form>");
}
elseif( $_REQUEST['optout'] == l_t('Opt-in') && $User->type['Donator'] )
{
$types = array();
foreach($User->type as $type=>$isMember)
{
if ( $isMember && $type != 'Donator' ) $types[] = $type;
}
$types = implode(',',$types);
$DB->sql_put("UPDATE wD_Users SET type = '".$types."' WHERE id = ".$User->id);
$User->type['Donator'] = false;
libHTML::notice(l_t("Opt-out"), l_t("You've decided to re-add the Plura applet, thanks! By running the Plura applet you ".
"help keep this server running."));
}
}
if ( isset($_REQUEST['emailToken']))
{
if( !($email = libAuth::emailToken_email($_REQUEST['emailToken'])) )
libHTML::notice(l_t("E-mail change validation"),
l_t("A bad e-mail token was given, please check the validation link try again"));
$email = $DB->escape($email);
if( User::findEmail($email) )
libHTML::notice(l_t("E-mail change validation"),
l_t("The given e-mail address is already in use, please use a unique e-mail address"));
$DB->sql_put("UPDATE wD_Users SET email='".$email."' WHERE id = ".$User->id);
$User->email = $email;
print '<div class="content"><p class="notice">'.l_t('Your e-mail address has been succesfully changed').'</p></div>';
}
if ( isset($_REQUEST['userForm']) )
{
$formOutput = '';
try
{
$errors = array();
$SQLVars = User::processForm($_REQUEST['userForm'], $errors);
if( count($errors) )
throw new Exception(implode('. ',$errors));
unset($errors);
$allowed = array('E-mail'=>'email','E-mail hiding'=>'hideEmail',
'showCountryNames'=>'showCountryNames',
'showCountryNamesMap'=>'showCountryNamesMap',
'color Correct'=>'colorCorrect',
'SortOrder'=>'sortOrder',
'UnitOrder'=>'unitOrder',
'pointNClick opt in'=>'pointNClick',
'Add greyout overlay'=>'terrGrey',
'greyout intensity' => 'greyOut',
'Remove scrollbars from smallmap'=>'scrollbars',
'Homepage'=>'homepage','Comment'=>'comment');
$set = '';
foreach( $allowed as $name=>$SQLName )
{
if ( ! isset($SQLVars[$SQLName]) or $User->{$SQLName} == $SQLVars[$SQLName] )
continue;
if ( $SQLName == 'email' )
{
if( User::findEmail($SQLVars['email']) )
throw new Exception(l_t("The e-mail address '%s', is already in use. Please choose another.",$SQLVars['email']));
$Mailer->Send(array($SQLVars['email']=>$User->username), l_t('Changing your e-mail address'),
l_t("Hello %s",$User->username).",<br><br>
".l_t("You can use this link to change your account's e-mail address to this one:")."<br>
".libAuth::email_validateURL($SQLVars['email'])."<br><br>
".l_t("If you have any further problems contact the server's admin at %s.",Config::$adminEMail)."<br>
".l_t("Regards,<br>The webDiplomacy Gamemaster")."<br>
");
$formOutput .= l_t('A validation e-mail was sent to the new address, containing a link which will confirm '.
'the e-mail change. If you don\'t see it after a few minutes check your spam folder.');
unset($SQLVars['email']);
continue;
}
elseif( $SQLName == 'comment' )
{
if ( $User->{$SQLName} == $DB->msg_escape($SQLVars[$SQLName]) )
continue;
}
if ( $set != '' ) $set .= ', ';
$set .= $SQLName." = '".$SQLVars[$SQLName]."'";
$formOutput .= l_t('%s updated successfully.',$name).' ';
}
if ( $set != '' )
{
$DB->sql_put("UPDATE wD_Users SET ".$set." WHERE id = ".$User->id);
}
if ( isset($SQLVars['password']) )
{
$DB->sql_put("UPDATE wD_Users SET password = ".$SQLVars['password']." WHERE id = ".$User->id);
libAuth::keyWipe();
header('refresh: 3; url=logon.php');
$formOutput .= l_t('Password updated successfully; you have been logged out and '.
'will need to logon with the new password.').' ';
}
}
catch(Exception $e)
{
$formOutput .= $e->getMessage();
}
// We may have received no new data
if ( $formOutput )
{
$User->load(); // Reload in case of a change
print '<div class="content"><p class="notice">'.$formOutput.'</p></div>';
}
}
function printAndFindTab()
{
global $User, $Misc;
$tabs = array();
$tabs['General']=l_t("General settings");
$tabs['Features']=l_t("Special features");
$tabs['IAmap']=l_t("Interactive map");
$tabs['CountrySwitch']=l_t("Send your games to other players");
$tab = 'General';
$tabNames = array_keys($tabs);
if( isset($_REQUEST['tab']) && in_array($_REQUEST['tab'], $tabNames) )
$tab = $_REQUEST['tab'];
print '<div class="gamelistings-tabs">';
foreach($tabs as $tabChoice=>$tabTitle)
{
print '<a title="'.$tabTitle.'" href="usercp.php?tab='.$tabChoice;
print ( ( $tab == $tabChoice ) ? '" class="current"' : '"');
print '>'.l_t($tabChoice).'</a>';
}
print '</div>';
return $tab;
}
print libHTML::pageTitle(l_t('User account settings'),l_t('Alter the settings for your webDiplomacy user account; e.g. change your password/e-mail.'));
print '<form method="post">
<ul class="formlist">';
$tab = printAndFindTab();
print '<br>';
switch($tab)
{
case 'Features':
require_once(l_r('locales/English/accessability.php'));
break;
case 'CountrySwitch':
require_once(l_r('locales/English/countryswitch.php'));
break;
case 'IAmap':
require_once(l_r('locales/English/IAmap.php'));
break;
default:
require_once(l_r('locales/English/user.php'));
}
print '</div>';
libHTML::footer();
?>