-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.php
239 lines (223 loc) · 8.75 KB
/
profile.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
<?php
use MagicObject\Request\PicoFilterConstant;
use MagicObject\Request\InputGet;
use MagicObject\Request\InputPost;
use MusicProductionManager\Constants\ParamConstant;
use MusicProductionManager\Data\Entity\User;
use MusicProductionManager\Data\Entity\UserProfile;
use MusicProductionManager\Utility\ServerUtil;
use MusicProductionManager\Utility\PicoStringUtil;
use MusicProductionManager\Utility\UserUtil;
require_once "inc/auth-with-login-form.php";
$inputGet = new InputGet();
$inputPost = new InputPost();
if($inputGet->equalsAction(ParamConstant::ACTION_EDIT) && $inputPost->getSave() == 'save')
{
$inputPost->filterName(PicoFilterConstant::FILTER_SANITIZE_SPECIAL_CHARS);
$inputPost->filterUsername(PicoFilterConstant::FILTER_SANITIZE_ALPHANUMERICPUNC);
$inputPost->filterEmail(PicoFilterConstant::FILTER_SANITIZE_EMAIL);
$userId = $currentLoggedInUser->getUserId();
$user = new User(null, $database);
$user->setUserId($userId);
$password = $inputPost->getPassword();
if(!empty($password))
{
$hashPassword = hash('sha256', $inputPost->getPassword());
$user->setPassword($hashPassword);
$_SESSION['spass'] = $hashPassword;
}
$user->setName($inputPost->getName());
$user->setBirthDay($inputPost->getBirthDay());
$user->setGender($inputPost->getGender());
$user->setTimeZone($inputPost->getTimeZone());
$username = $inputPost->getUsername();
if(!empty($username) && !UserUtil::isDuplicatedUsername($database, $userId, $username))
{
$user->setUsername($username);
$_SESSION['suser'] = $username;
}
$email = $inputPost->getEmail();
if(!empty($email) && !UserUtil::isDuplicatedEmail($database, $userId, $email))
{
$user->setEmail($email);
}
$user->setTimeEdit(date('Y-m-d H:i:s'));
$user->setAdminEdit($userId);
$user->setIpEdit(ServerUtil::getRemoteAddress($cfg));
$user->update();
if($inputPost->getVocalGuideInstrument() != "")
{
$userProfile = new UserProfile(null, $database);
try
{
$userProfile->findOneByUserIdAndProfileName($user->getUserId(), "vocal-guide-intrument");
}
catch(Exception $e)
{
$userProfile = new UserProfile(null, $database);
$userProfile->setUserId($user->getUserId());
$userProfile->setProfileName("vocal-guide-intrument");
}
$userProfile->setProfileValue($inputPost->getVocalGuideInstrument());
$userProfile->setTimeEdit(date('Y-m-d H:i:s'));
$userProfile->save();
}
header('Location: '.basename(($_SERVER['PHP_SELF'])));
}
if($inputGet->equalsAction(ParamConstant::ACTION_EDIT))
{
require_once "inc/header.php";
$user = new User(null, $database);
try
{
$user->findOneByUserId($currentLoggedInUser->getUserId());
$userProfile = new UserProfile(null, $database);
try
{
$userProfile->findOneByUserIdAndProfileName($user->getUserId(), "vocal-guide-intrument");
}
catch(Exception $e)
{
// do nothing
}
$vocalGuideInstrument = $userProfile->issetProfileValue() ? $userProfile->getProfileValue() : $cfg->getDefaultVocalGuideInstrument();
?>
<form action="" method="post">
<table class="table table-responsive table-responsive-two-side">
<tbody>
<tr>
<td>Name</td>
<td><input type="text" class="form-control" name="name" id="name" value="<?php echo $user->getName();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Gender</td>
<td><select class="form-control" name="gender" id="gender">
<option value="M"<?php echo $user->createSelectedGender('M');?>>Man</option>
<option value="W"<?php echo $user->createSelectedGender('W');?>>Woman</option>
</select></td>
</tr>
<tr>
<td>Birth Day</td>
<td><input type="date" class="form-control" name="birth_day" id="birth_day" value="<?php echo $user->getBirthDay();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" class="form-control" name="email" id="email" value="<?php echo $user->getEmail();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" class="form-control" name="username" id="username" value="<?php echo $user->getUsername();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="form-control" name="password" id="password" value="" autocomplete="off"></td>
</tr>
<tr>
<td>Vocal Guide Instrument</td>
<td><select class="form-control" name="vocal_guide_instrument" id="vocal_guide_instrument">
<option value="piano"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='piano');?>>Piano</option>
<option value="acoustic_grand_piano"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='acoustic_grand_piano');?>>Acoustic Grand Piano</option>
<option value="electric_piano_1"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='electric_piano_1');?>>Electric Piano 1</option>
<option value="electric_piano_2"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='electric_piano_2');?>>Electric Piano 2</option>
<option value="clavinet"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='guitar');?>>Clavinet</option>
<option value="guitar"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='guitar');?>>Guitar</option>
<option value="acoustic_guitar_nylon"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='acoustic_guitar_nylon');?>>Acoustic Guitar Nylon</option>
<option value="acoustic_guitar_steel"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='acoustic_guitar_steel');?>>Acoustic Guitar Steel</option>
<option value="acoustic_bass"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='acoustic_bass');?>>Acoustic Bass</option>
<option value="celesta"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='celesta');?>>Celesta</option>
<option value="voice_oohs"<?php echo PicoStringUtil::formSelected($vocalGuideInstrument=='voice_oohs');?>>Voice Oohs</option>
</select></td>
</tr>
<tr>
<td>Time Zone</td>
<td><select class="form-control" name="time_zone" id="time_zone" data-value="<?php echo $user->getTimeZone();?>"></select></td>
</tr>
</tbody>
</table>
<input type="hidden" name="save" value="save">
<button type="submit" class="btn btn-success">Update</button>
<button type="button" class="btn btn-primary" onclick="window.location='profile.php'">Cancel</button>
</form>
<script type="text/javascript">
$(document).ready(function(e1){
$('#time_zone').load('lib.ajax/time-zone.php', function(responseTxt, statusTxt, xhr){
if(statusTxt == "success")
{
$('#time_zone').val($('#time_zone').attr('data-value') );
}
if(statusTxt == "error")
{
}
});
});
</script>
<?php
}
catch(Exception $e)
{
// do something here
}
require_once "inc/footer.php";
}
else
{
require_once "inc/header.php";
$user = new User(null, $database);
try
{
$user->findOneByUserId($currentLoggedInUser->getUserId());
$userProfile = new UserProfile(null, $database);
try
{
$userProfile->findOneByUserIdAndProfileName($user->getUserId(), "vocal-guide-intrument");
}
catch(Exception $e)
{
// do nothing
}
$vocalGuideInstrument = $userProfile->issetProfileValue() ? $userProfile->getProfileValue() : $cfg->getDefaultVocalGuideInstrument();
?>
<table class="table table-responsive table-responsive-two-side">
<tbody>
<tr>
<td>User ID</td>
<td><?php echo $user->getUserId();?></td>
</tr>
<tr>
<td>Username</td>
<td><?php echo $user->getUsername();?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo $user->getName();?></td>
</tr>
<tr>
<td>Gender</td>
<td><?php echo $user->getGender() == 'M' ? 'Man' : 'Woman';?></td>
</tr>
<tr>
<td>Birth Day</td>
<td><?php echo $user->getBirthDay();?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo $user->getEmail();?></td>
</tr>
<tr>
<td>Vocal Guide Instrument</td>
<td><?php echo $vocalGuideInstrument;?></td>
<tr>
<td>Time Zone</td>
<td><?php echo $user->getTimeZone();?></td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-primary" onclick="window.location='profile.php?action=edit'">Edit</button>
<?php
}
catch(Exception $e)
{
// do something here
}
require_once "inc/footer.php";
}