-
Notifications
You must be signed in to change notification settings - Fork 3
/
preferences.php
235 lines (198 loc) · 7.27 KB
/
preferences.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
<?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
* - sLightsparkRelease, user's Lightspark 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
* - move and rename functions in their respective modules
*/
// application environment
require("path.php");
require(BASE."include/incl.php");
require(BASE."include/form_edit.php");
// returns an array of TableRow instances
function build_prefs_list($oUser)
{
$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 == "query:mode")
continue;
if($r->name == "sidebar")
continue;
if($r->name == "window:query")
continue;
if($r->name == "query:hide_header")
continue;
if($r->name == "query:hide_sidebar")
continue;
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;
}
return $aTableRows;
}
// returns an array of TableRow instances
function show_user_fields($oUser)
{
$aTableRows = array();
$sLightsparkRelease = $oUser->sLightsparkRelease;
if($oUser->hasPriv("admin"))
$sAdminChecked = 'checked="true"';
else
$sAdminChecked = "";
// Edit admin privilege
if($_SESSION['current']->hasPriv("admin"))
{
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Administrator");
$oTableRow->AddTextCell("<input type=\"checkbox\"".
" name=\"bIsAdmin\" value=\"true\" ".
"$sAdminChecked>");
$aTableRows[] = $oTableRow;
}
$oTableRow = new TableRow();
$oTableRow->AddTextCell(" Lightspark version");
$sBugzillaVersionList = make_bugzilla_version_list("sLightsparkRelease",
$sLightsparkRelease);
$oTableRow->AddCell(new TableCell($sBugzillaVersionList));
$aTableRows[] = $oTableRow;
// return the table rows
return $aTableRows;
}
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->sLightsparkRelease = $aClean['sLightsparkRelease'];
/* if the password was empty in both cases then skip updating the users password */
if($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("User Preferences");
echo "<div class='default_container'>\n";
echo "<form method=\"post\" action=\"preferences.php\">\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 html_frame_start("Preferences for ".$oUser->sRealname, "80%");
// build a table
$oTable = new Table();
$oTable->SetWidth("100%");
$oTable->SetAlign("left");
$oTable->SetCellSpacing(0);
$oTable->SetClass("box-body");
// retrieve the form editing rows
$aTableRows = GetEditAccountFormRows($oUser->sEmail, $oUser->sRealname);
foreach($aTableRows as $oTableRow)
$oTable->AddRow($oTableRow);
// retrieve the user fields
$aTableRows = show_user_fields($oUser);
foreach($aTableRows as $oTableRow)
$oTable->AddRow($oTableRow);
// if we don't manage another user
if( !isset($aClean['iUserId']) || $oUser->iUserId != $aClean['iUserId'])
{
$aTableRows = build_prefs_list($oUser);
foreach($aTableRows as $oTableRow)
{
$oTable->AddRow($oTableRow);
}
}
echo $oTable->GetString();
echo html_frame_end();
echo "<br> <div align=center> <input type=\"submit\" name='sSubmit' value=\"Update\"> </div> <br>\n";
echo "</form>\n";
echo "</div>\n";
apidb_footer();
?>