]>
src.bluestatic.org Git - bugdar.git/blob - admin/user.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 require_once ( './global.php' );
23 require_once ( './includes/api_user.php' );
24 require_once ( './includes/class_sort.php' );
26 APIError ( array ( new API_Error_Handler ( $admin ), 'admin_error' ));
28 NavLinks
:: usersPages ();
29 $navigator- > set_focus ( 'tab' , 'users' , null );
31 if (! can_perform ( 'canadminusers' ))
36 // ###################################################################
38 * Generate an inline checkbox
43 * @param bool Checked?
45 * @return string HTML checkbxo
47 function draw_checkbox ( $name , $checked )
49 return "<input type= \" checkbox \" class= \" button \" name= \"{ $name} \" value= \" 1 \" " . ( $checked == true ? ' checked="checked"' : '' ) . " />" ;
52 // ###################################################################
54 if ( empty ( $_REQUEST [ 'do' ]))
56 $_REQUEST [ 'do' ] = 'modify' ;
59 // ###################################################################
61 if ( $_REQUEST [ 'do' ] == 'kill' )
63 $user = new UserAPI ();
64 $user- > set ( 'userid' , $input- > in
[ 'userid' ]);
65 $user- > set_condition ();
68 $admin- > redirect ( 'user.php' );
71 // ###################################################################
73 if ( $_REQUEST [ 'do' ] == 'delete' )
75 $admin- > page_confirm ( T ( 'Are you sure you want to delete this user?' ), 'user.php' , 'kill' , array ( 'userid' => $input- > inputClean ( 'userid' , TYPE_UINT
)));
78 // ###################################################################
80 if ( $_POST [ 'do' ] == 'insert' )
82 $user = new UserAPI ();
83 $user- > set ( 'displayname' , $input- > in
[ 'displayname' ]);
84 $user- > set ( 'email' , $input- > in
[ 'email' ]);
85 $user- > set ( 'showemail' , $input- > in
[ 'showemail' ]);
86 $user- > set ( 'showcolors' , $input- > in
[ 'showcolors' ]);
87 $user- > set ( 'usergroupid' , $input- > in
[ 'usergroupid' ]);
88 $user- > set ( 'groupids' , $input- > in
[ 'groupids' ]);
89 $user- > set ( 'languageid' , $input- > in
[ 'languageid' ]);
90 $user- > set ( 'timezone' , $input- > in
[ 'timezone' ]);
91 $user- > set ( 'usedst' , $input- > in
[ 'usedst' ]);
92 $user- > set ( 'password' , $input- > in
[ 'password' ]);
93 $user- > set ( 'hidestatuses' , $input- > in
[ 'hidestatuses' ]);
94 $user- > set ( 'defaultsortkey' , $input- > in
[ 'defaultsortkey' ]);
95 $user- > set ( 'defaultsortas' , $input- > in
[ 'defaultsortas' ]);
98 // post_insert will set the email options... so we now have to dump them
99 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user- > insertid
);
101 $input- > inputClean ( 'emailopts' , TYPE_INT
);
102 if ( is_array ( $input- > in
[ 'emailopts' ]))
104 foreach ( $input- > in
[ 'emailopts' ] AS $relation => $bitarr )
107 foreach ( $bitarr AS $option => $yes )
109 $bitmask +
= $option * $yes ;
111 $db- > query ( "INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . $user- > insertid
. ", $relation , $bitmask )" );
115 $admin- > redirect ( 'user.php?do=edit&userid=' . $user- > insertid
);
118 // ###################################################################
120 if ( $_POST [ 'do' ] == 'update' )
122 $user = new UserAPI ();
123 $user- > set ( 'userid' , $input- > in
[ 'userid' ]);
124 $user- > set_condition ();
125 $user- > set ( 'displayname' , $input- > in
[ 'displayname' ]);
126 $user- > set ( 'email' , $input- > in
[ 'email' ]);
127 $user- > set ( 'showemail' , $input- > in
[ 'showemail' ]);
128 $user- > set ( 'showcolors' , $input- > in
[ 'showcolors' ]);
129 $user- > set ( 'usergroupid' , $input- > in
[ 'usergroupid' ]);
130 $user- > set ( 'groupids' , $input- > in
[ 'groupids' ]);
131 $user- > set ( 'languageid' , $input- > in
[ 'languageid' ]);
132 $user- > set ( 'timezone' , $input- > in
[ 'timezone' ]);
133 $user- > set ( 'usedst' , $input- > in
[ 'usedst' ]);
134 $user- > set ( 'password' , $input- > in
[ 'password' ]);
135 $user- > set ( 'hidestatuses' , $input- > in
[ 'hidestatuses' ]);
136 $user- > set ( 'defaultsortkey' , $input- > in
[ 'defaultsortkey' ]);
137 $user- > set ( 'defaultsortas' , $input- > in
[ 'defaultsortas' ]);
140 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user- > values
[ 'userid' ]);
141 $input- > inputClean ( 'emailopts' , TYPE_INT
);
142 if ( is_array ( $input- > in
[ 'emailopts' ]))
144 foreach ( $input- > in
[ 'emailopts' ] AS $relation => $bitarr )
147 foreach ( $bitarr AS $option => $yes )
149 $bitmask +
= $option * $yes ;
151 $db- > query ( "INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . $user- > values
[ 'userid' ] . ", $relation , $bitmask )" );
155 $admin- > redirect ( 'user.php?do=edit&userid=' . $user- > record
[ 'userid' ]);
158 // ###################################################################
160 if ( $_REQUEST [ 'do' ] == 'edit' OR $_REQUEST [ 'do' ] == 'add' )
162 $add = ( $_REQUEST [ 'do' ] == 'add' );
167 NavLinks
:: usersEdit ( $input- > in
[ 'userid' ]);
168 $navigator- > set_focus ( 'link' , 'users-pages-users' , 'users-pages' );
170 $user = new UserAPI ();
171 $user- > set ( 'userid' , $input- > in
[ 'userid' ]);
172 $user- > set_condition ();
177 NavLinks
:: usersAdd ();
178 $navigator- > set_focus ( 'link' , 'users-add' , 'users' );
181 $admin- > page_start (( $add ? T ( 'Add User' ) : T ( 'Edit User' )));
183 $admin- > form_start ( 'user.php' , ( $add ? 'insert' : 'update' ));
187 $admin- > form_hidden_field ( 'userid' , $user- > record
[ 'userid' ]);
190 $admin- > table_start ();
192 $admin- > table_head (( $add ? T ( 'Add User' ) : sprintf ( T ( 'Edit User (userid: %1 $s )' ), $user- > record
[ 'userid' ])));
194 $admin- > row_input ( T ( 'Display Name' ), 'displayname' , $user- > record
[ 'displayname' ]);
195 $admin- > row_input ( T ( 'Email' ), 'email' , $user- > record
[ 'email' ]);
196 $admin- > row_input (( $add ? T ( 'Password' ) : T ( 'Password (Leave blank for no change)' )), 'password' );
198 foreach ( bugdar
:: $datastore [ 'usergroup' ] AS $group )
200 $admin- > list_item ( $group [ 'title' ], $group [ 'usergroupid' ], ( $user- > record
[ 'usergroupid' ] == $group [ 'usergroupid' ]));
202 $admin- > row_list ( T ( 'Primary Usergroup' ), 'usergroupid' );
204 $ids = explode ( ',' , $user- > record
[ 'groupids' ]);
205 foreach ( bugdar
:: $datastore [ 'usergroup' ] AS $id => $group )
207 if ( $id == $user- > record
[ 'usergroupid' ])
211 $admin- > list_item ( $group [ 'title' ], $group [ 'usergroupid' ], in_array ( $id , $ids ));
213 $admin- > row_checkbox ( T ( 'Secondary Usergroups' ), 'groupids' );
215 $admin- > row_yesno ( T ( 'Show Email Publicly' ), 'showemail' , $user- > record
[ 'showemail' ]);
216 $admin- > row_yesno ( T ( 'Show Status Colors on Bug Listings' ), 'showcolors' , $user- > record
[ 'showcolors' ]);
218 foreach ( bugdar
:: $datastore [ 'language' ] AS $language )
220 $admin- > list_item ( $language [ 'title' ], $language [ 'languageid' ], ( $user- > record
[ 'languageid' ] == $language [ 'languageid' ]));
222 $admin- > row_list ( T ( 'Language' ), 'languageid' );
224 foreach ( $datef- > fetch_timezone_list () AS $value => $string )
226 $admin- > list_item ( $string , $value , ( $user- > record
[ 'timezone' ] == $value ));
228 $admin- > row_list ( T ( 'Timezone' ), 'timezone' );
230 $admin- > row_yesno ( T ( 'Observe Daylight Savings Time (DST)' ), 'usedst' , $user- > record
[ 'usedst' ]);
231 $admin- > row_text ( T ( 'Hidden Statuses on Bug Listing' ), construct_option_select ( 'hidestatuses' , bugdar
:: $datastore [ 'status' ], $user- > record
[ 'hidestatuses' ], 'statusid' , 'status' , 0 , true ));
232 $admin- > row_text ( T ( 'Default Sort Order Column' ), construct_option_select ( 'defaultsortkey' , ListSorter
:: fetch_by_text ( false ), $user- > record
[ 'defaultsortkey' ]));
233 $admin- > row_text ( T ( 'Default Sort Order Direction' ), construct_option_select ( 'defaultsortas' , ListSorter
:: fetch_as_text ( false ), $user- > record
[ 'defaultsortas' ]));
237 // -------------------------------------------------------------------
238 $admin- > table_start ( false );
239 $admin- > table_head ( T ( 'Email Options' ), 6 );
241 if ( $user- > record
[ 'userid' ])
243 $options = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user- > record
[ 'userid' ]);
244 foreach ( $options as $opt )
246 foreach ( $bugsys- > emailoptions
[ 'notifications' ] AS $name => $notif )
248 foreach ( $bugsys- > emailoptions
[ 'relations' ] AS $name => $relation )
250 if ( $opt [ 'mask' ] & $notif AND $opt [ 'relation' ] == $relation )
252 $checked [ " $relation" ][" $notif" ] = HTML_CHECKED
;
259 $admin- > table_column_head ( array ( '' , T ( 'Reporter' ), T ( 'Assignee' ), T ( 'Favorite' ), T ( 'Voter' ), T ( 'Commenter' )));
261 // -------------------------------------------------------------------
263 $admin- > row_text ( T ( 'New bug is added' ), '<div style="text-align: center">' . draw_checkbox ( 'emailopts[0][2048]' , $checked [ 0 ][ 2048 ]) . '</div>' , 'top' , 6 );
265 $admin- > row_text ( T ( 'I am made the assignee' ), '<div style="text-align: center">' . draw_checkbox ( 'emailopts[0][32]' , $checked [ 0 ][ 32 ]) . '</div>' , 'top' , 6 );
267 $admin- > row_multi_item ( array (
268 T ( 'Status or resolution changes' ) => 'l' ,
269 draw_checkbox ( 'emailopts[1][64]' , $checked [ 1 ][ 64 ]) => 'c' ,
270 draw_checkbox ( 'emailopts[2][64]' , $checked [ 2 ][ 64 ]) => 'c' ,
271 draw_checkbox ( 'emailopts[4][64]' , $checked [ 4 ][ 64 ]) => 'c' ,
272 draw_checkbox ( 'emailopts[8][64]' , $checked [ 8 ][ 64 ]) => 'c' ,
273 draw_checkbox ( 'emailopts[16][64]' , $checked [ 16 ][ 64 ]) => 'c' ,
276 $admin- > row_multi_item ( array (
277 T ( "'Duplicates' field is changed" ) => 'l' ,
278 draw_checkbox ( 'emailopts[1][128]' , $checked [ 1 ][ 128 ]) => 'c' ,
279 draw_checkbox ( 'emailopts[2][128]' , $checked [ 2 ][ 128 ]) => 'c' ,
280 draw_checkbox ( 'emailopts[4][128]' , $checked [ 4 ][ 128 ]) => 'c' ,
281 draw_checkbox ( 'emailopts[8][128]' , $checked [ 8 ][ 128 ]) => 'c' ,
282 draw_checkbox ( 'emailopts[16][128]' , $checked [ 16 ][ 128 ]) => 'c' ,
285 $admin- > row_multi_item ( array (
286 T ( 'A new comment is added' ) => 'l' ,
287 draw_checkbox ( 'emailopts[1][256]' , $checked [ 1 ][ 256 ]) => 'c' ,
288 draw_checkbox ( 'emailopts[2][256]' , $checked [ 2 ][ 256 ]) => 'c' ,
289 draw_checkbox ( 'emailopts[4][256]' , $checked [ 4 ][ 256 ]) => 'c' ,
290 draw_checkbox ( 'emailopts[8][256]' , $checked [ 8 ][ 256 ]) => 'c' ,
291 draw_checkbox ( 'emailopts[16][256]' , $checked [ 16 ][ 256 ]) => 'c' ,
294 $admin- > row_multi_item ( array (
295 T ( 'A new attachment is added' ) => 'l' ,
296 draw_checkbox ( 'emailopts[1][512]' , $checked [ 1 ][ 512 ]) => 'c' ,
297 draw_checkbox ( 'emailopts[2][512]' , $checked [ 2 ][ 512 ]) => 'c' ,
298 draw_checkbox ( 'emailopts[4][512]' , $checked [ 4 ][ 512 ]) => 'c' ,
299 draw_checkbox ( 'emailopts[8][512]' , $checked [ 8 ][ 512 ]) => 'c' ,
300 draw_checkbox ( 'emailopts[16][512]' , $checked [ 16 ][ 512 ]) => 'c' ,
303 $admin- > row_multi_item ( array (
304 T ( 'Any other field changes' ) => 'l' ,
305 draw_checkbox ( 'emailopts[1][1024]' , $checked [ 1 ][ 1024 ]) => 'c' ,
306 draw_checkbox ( 'emailopts[2][1024]' , $checked [ 2 ][ 1024 ]) => 'c' ,
307 draw_checkbox ( 'emailopts[4][1024]' , $checked [ 4 ][ 1024 ]) => 'c' ,
308 draw_checkbox ( 'emailopts[8][1024]' , $checked [ 8 ][ 1024 ]) => 'c' ,
309 draw_checkbox ( 'emailopts[16][1024]' , $checked [ 16 ][ 1024 ]) => 'c' ,
312 // -------------------------------------------------------------------
313 $admin- > row_submit ( null , ':save:' , ':reset:' , 6 );
321 // ###################################################################
323 if ( $_REQUEST [ 'do' ] == 'search' )
327 NavLinks
:: usersAdd ();
328 $navigator- > set_focus ( 'link' , 'users-pages-users' , 'users-pages' );
330 if ( is_numeric ( $input- > in
[ 'userdata' ]))
332 $input- > inputClean ( 'userdata' , TYPE_UINT
);
333 if ( $db- > queryFirst ( "SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . $input- > in
[ 'userdata' ]))
335 header ( 'Location: user.php?do=edit&userid=' . $input- > in
[ 'userdata' ]);
344 $input- > in
[ 'userdata' ] = str_replace ( '%' , '\%' , $input- > in
[ 'userdata' ]);
345 $results = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "user WHERE email LIKE '%" . $bugsys- > input_escape ( 'userdata' ) . "%' OR displayname LIKE '%" . $bugsys- > input_escape ( 'userdata' ) . "%'" );
347 if ( $db- > num_rows ( $results ) < 1 )
353 $admin- > page_start ( T ( 'Search Results' ));
355 $admin- > table_start ();
356 $admin- > table_head ( T ( 'Search Results' ), 4 );
357 $admin- > table_column_head ( array ( T ( 'Display Name' ), T ( 'Email' ), T ( 'User ID' ), T ( 'Actions' )));
359 foreach ( $results as $row )
361 $admin- > row_multi_item ( array (
362 $row [ 'displayname' ] => 'l' ,
363 $row [ 'email' ] => 'c' ,
364 $row [ 'userid' ] => 'c' ,
365 '<a href="user.php?do=edit&userid=' . $row [ 'userid' ] . '">[' . T ( 'Edit' ) . ']</a>' => 'c'
377 $admin- > error ( T ( 'Sorry, we could not find any users that matched your criteria.' ));
381 // ###################################################################
383 if ( $_REQUEST [ 'do' ] == 'showall' )
385 NavLinks
:: usersAdd ();
386 $navigator- > set_focus ( 'link' , 'users-showall' , 'users' );
388 LoadPaginationFramework ();
389 $pagination- > setBitProcessor ( 'AdminPageNavigatorBitCallback' );
390 $pagination- > setNavigatorProcessor ( 'AdminPageNavigatorCallback' );
392 $admin- > page_start ( T ( 'Show All Users' ));
393 $admin- > table_start ();
394 $admin- > table_head ( T ( 'Show All Users' ), 4 );
395 $admin- > table_column_head ( array ( T ( 'Display Name' ), T ( 'Email' ), T ( 'User ID' ), T ( 'Actions' )));
397 $count = $db- > queryFirst ( "SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user" );
398 $pagination- > setTotal ( $count [ 'count' ]);
399 $pagination- > splitPages ();
401 $users = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "user ORDER BY userid ASC LIMIT " . $pagination- > fetchLimit ( $pagination- > getPage () - 1 ) . ", " . $pagination- > getPerPage ());
402 foreach ( $users as $user )
404 $admin- > row_multi_item ( array (
405 $user [ 'displayname' ] => 'l' ,
406 $user [ 'email' ] => 'c' ,
407 $user [ 'userid' ] => 'c' ,
408 '<a href="user.php?do=edit&userid=' . $user [ 'userid' ] . '">[' . T ( 'Edit' ) . ']</a>' => 'c'
414 $admin- > page_code ( $pagination- > constructPageNav ( 'user.php?do=showall' ));
419 // ###################################################################
421 if ( $_REQUEST [ 'do' ] == 'modify' )
423 NavLinks
:: usersAdd ();
424 $navigator- > set_focus ( 'link' , 'users-pages-users' , 'users-pages' );
426 $admin- > page_start ( T ( 'User Search' ));
428 $admin- > form_start ( 'user.php' , 'search' );
429 $admin- > table_start ( true , '45%' );
431 $admin- > table_head ( T ( 'User Search' ));
432 $admin- > row_input ( T ( 'Name/Email/ID' ), 'userdata' );
434 $admin- > row_submit ( '' , ':save:' , '' );
442 /*=====================================================================*\
443 || ###################################################################
446 || ###################################################################
447 \*=====================================================================*/