-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreferences.php
More file actions
215 lines (188 loc) · 7.01 KB
/
preferences.php
File metadata and controls
215 lines (188 loc) · 7.01 KB
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
<?php
/**
* User's role and preferences editor.
*
* Optional parameters:
* - iUserId, user identifier (when an administrator edits another user)
* - iLimit
* - sOrderBy
* - sUserPassword, new password
* - sUserPassword2, new password confirmation
* - sUserEmail, e-mail address
* - sUserRealname, user's real name
* - sWineRelease, user's Wine release
* - bIsAdmin, true if user is an administrator
*
* TODO:
* - document iLimit and sOrderBy
* - replace sOrderBy with iOrderBy and use constants for each accepted value
* - add a field to prefs_list to flag the user level for the pref
*/
// application environment
require("path.php");
require(BASE."include/incl.php");
if(!$_SESSION['current']->isLoggedIn())
util_show_error_page_and_exit("You must be logged in to edit preferences");
// we come from the administration to edit an user
if($_SESSION['current']->hasPriv("admin") &&
isset($aClean['iUserId']) &&
isset($aClean['iLimit']) &&
isset($aClean['sOrderBy']) &&
in_array($aClean['sOrderBy'],array("email","realname","created"))
)
{
$oUser = new User($aClean['iUserId']);
} else
{
$oUser = &$_SESSION['current'];
}
if(isset($aClean['sSubmit']) && $aClean['sSubmit'] == "Update")
{
while(list($sKey, $sValue) = each($aClean))
{
/* if a parameter lacks 'pref_' at its head it isn't a */
/* preference so skip over processing it */
if(!ereg("^pref_(.+)$", $sKey, $arr))
continue;
$oUser->setPref($arr[1], $sValue);
}
/* make sure the user enters the same password twice */
if ($aClean['sUserPassword'] == $aClean['sUserPassword2'])
{
$str_passwd = $aClean['sUserPassword'];
}
else if ($aClean['sUserPassword'])
{
addmsg("The Passwords you entered did not match.", "red");
}
/* update user data fields */
$oUser->sEmail = $aClean['sUserEmail'];
$oUser->sRealname = $aClean['sUserRealname'];
$oUser->sWineRelease = $aClean['sWineRelease'];
/* if the password was empty in both cases then skip updating the users password */
if(!empty($str_passwd))
{
if(!$oUser->update_password($str_passwd))
addmsg("Failed to update password", "red");
}
if ($oUser->update() == SUCCESS)
{
addmsg("Preferences Updated", "green");
// we were managing an user, let's go back to the admin after
// updating tha admin status
if($oUser->iUserId == $aClean['iUserId'] &&
$_SESSION['current']->hasPriv("admin"))
{
if($aClean['bIsAdmin'] == "true")
$oUser->addPriv("admin");
else
$oUser->delPriv("admin");
util_redirect_and_exit(BASE."admin/adminUsers.php?iUserId=".$oUser->iUserId.
"&sSearch=".$aClean['sSearch']."&iLimit=".$aClean['iLimit'].
"&sOrderBy=".$aClean['sOrderBy']."&sSubmit=true");
}
}
else
{
addmsg("There was a problem updating your user info", "red");
}
}
apidb_header('Preferences');
echo "<h1 class=\"whq-app-title\">Preferences for {$oUser->sRealname}</h1>\n";
echo "<form method=\"post\" action=\"preferences.php\">\n";
// build a table
$oTable = new Table();
$oTable->SetWidth("100%");
$oTable->SetClass("whq-table");
// user account form
$aTableRows = array();
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Email Address");
$oTableRow->AddTextCell('<input type="text" name="sUserEmail" value="'.$oUser->sEmail.'" class="form-control">');
$aTableRows[] = $oTableRow;
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Password");
$oTableRow->AddTextCell('<input type="password" name="sUserPassword" class="form-control">');
$aTableRows[] = $oTableRow;
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Password (again)");
$oTableRow->AddTextCell('<input type="password" name="sUserPassword2" class="form-control">');
$aTableRows[] = $oTableRow;
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Real Name");
$oTableRow->AddTextCell('<input type="text" name="sUserRealname" value="'.$oUser->sRealname.'" class="form-control">');
$aTableRows[] = $oTableRow;
foreach($aTableRows as $oTableRow)
{
$oTable->AddRow($oTableRow);
}
$aTableRows = array();
// Edit admin privilege
$sAdminChecked = "";
if($oUser->hasPriv("admin"))
$sAdminChecked = 'checked="true"';
if($_SESSION['current']->hasPriv("admin"))
{
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Administrator");
$oTableRow->AddTextCell("<input type=\"checkbox\"".
" name=\"bIsAdmin\" value=\"true\" ".
"$sAdminChecked>");
$aTableRows[] = $oTableRow;
}
// wine version
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Wine version");
$sBugzillaVersionList = make_bugzilla_version_list("sWineRelease",
$oUser->sWineRelease);
if (!empty($sBugzillaVersionList))
{
$oTableRow->AddCell(new TableCell($sBugzillaVersionList));
$aTableRows[] = $oTableRow;
}
foreach($aTableRows as $oTableRow)
{
$oTable->AddRow($oTableRow);
}
// user preferences - only editable by user, not admin
if( !isset($aClean['iUserId']) || $oUser->iUserId != $aClean['iUserId'])
{
$aTableRows = array();
$hResult = query_parameters("SELECT * FROM prefs_list ORDER BY id");
while($hResult && $r = query_fetch_object($hResult))
{
// skip admin options
if(!$_SESSION['current']->hasPriv("admin"))
{
if($r->name == "debug")
continue;
}
/* Check if the permission only applies to a specific group */
if($r->show_for_group && !$_SESSION['current']->hasPriv($r->show_for_group))
continue;
$input = html_select("pref_$r->name", explode('|', $r->value_list),
$oUser->getpref($r->name, $r->def_value));
$oTableRow = new TableRow();
$oTableCell = new TableCell(" $r->description");
$oTableRow->AddCell($oTableCell);
$oTableCell = new TableCell($input);
$oTableRow->AddCell($oTableCell);
$aTableRows[] = $oTableRow;
}
foreach($aTableRows as $oTableRow)
{
$oTable->AddRow($oTableRow);
}
}
echo $oTable->GetString();
echo "<p><button type=\"submit\" name='sSubmit' value=\"Update\" class=\"btn btn-default\"><i class=\"fa fa-save\"></i> Save Preferences</button></p>\n";
// if we manage another user we give the parameters to go back to the admin
if( isset($aClean['iUserId']) && $oUser->iUserId == $aClean['iUserId'])
{
echo "<input type=\"hidden\" name=\"iLimit\" value=\"".$aClean['iLimit']."\">\n";
echo "<input type=\"hidden\" name=\"sOrderBy\" value=\"".$aClean['sOrderBy']."\">\n";
echo "<input type=\"hidden\" name=\"sSearch\" value=\"".$aClean['sSearch']."\">\n";
echo "<input type=\"hidden\" name=\"iUserId\" value=\"".$aClean['iUserId']."\">\n";
}
echo "</form>\n";
apidb_footer();