]>
src.bluestatic.org Git - bugdar.git/blob - admin/field.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 [#]gpl[#] 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/functions_datastore.php' );
25 if (! can_perform ( 'canadminfields' ))
31 'input_text' => $lang- > string ( 'Single-Line Text Box' ),
32 'input_checkbox' => $lang- > string ( 'Checkbox Flag' ),
33 'select_single' => $lang- > string ( 'Drop-Down Menu' ),
36 // ###################################################################
38 if ( empty ( $_REQUEST [ 'do' ]))
40 $_REQUEST [ 'do' ] = 'modify' ;
43 // ###################################################################
45 if ( $_REQUEST [ 'do' ] == 'kill' )
47 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
50 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
53 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = $field [fieldid]" );
54 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = $field [fieldid]" );
55 $db- > query ( "ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill DROP field $field [fieldid]" );
56 $db- > query ( "OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill" );
60 $admin- > redirect ( 'field.php?do=modify' );
63 // ###################################################################
65 if ( $_REQUEST [ 'do' ] == 'delete' )
67 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
70 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
73 $admin- > page_confirm ( $lang- > string ( 'Are you sure you want to delete this bug field? Doing so will remove everything for this field and it cannot be undone!' ), "field.php?do=kill&fieldid= $field [fieldid]" );
76 // ###################################################################
78 if ( $_REQUEST [ 'do' ] == 'update' )
83 $type = $bugsys- > in
[ 'type' ];
85 if ( $bugsys- > in
[ 'fieldid' ])
87 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
90 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
95 $type = $field [ 'type' ];
98 if ( empty ( $bugsys- > in
[ 'name' ]))
100 $admin- > error ( $lang- > string ( 'You must specify a display name.' ));
102 if (! isset ( $TYPES [ " $type" ]) AND $add )
104 $admin- >error( $lang- >string('Invalid field type specified.'));
110 $extrafields = 'defaultvalue, regexmatch, maxlength';
111 $extradata = " '" . $bugsys- >in[' defaultvalue
'] . "' , '" . $bugsys- >in[' regexmatch
'] . "' , " . intval( $bugsys- >in['maxlength']);
112 $extraupdate = " defaultvalue
= '" . $bugsys- >in[' defaultvalue
'] . "' , regexmatch
= '" . $bugsys- >in[' regexmatch
'] . "' , maxlength
= " . intval( $bugsys- >in['maxlength']);
115 case 'input_checkbox':
116 $extrafields = 'defaultvalue';
117 $extradata = intval( $bugsys- >in['defaultvalue']);
118 $extraupdate = " defaultvalue
= " . intval( $bugsys- >in['defaultvalue']);
121 case 'select_single':
122 $extrafields = 'selects, usedefault';
124 // can't use explode() here because explode() returns !empty() when splitting an empty string
125 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
126 $selects = preg_split(" #\n#", trim($bugsys->in['selects']), 0, PREG_SPLIT_NO_EMPTY);
127 array_walk ( $selects , 'trim' );
128 if ( count ( $selects ) < 1 )
130 $admin- > error ( $lang- > string ( 'You need to specify some select values.' ));
133 $extradata = "'" . $bugsys- > escape ( serialize ( $selects )) . "', " . intval ( $bugsys- > in
[ 'usedefault' ]);
134 $extraupdate = "selects = '" . $bugsys- > escape ( serialize ( $selects )) . "', usedefault = " . intval ( $bugsys- > in
[ 'usedefault' ]);
141 INSERT INTO " . TABLE_PREFIX
. "bugfield
142 (name, description, type, required, cansearch, $extrafields )
144 ('" . $bugsys- > in
[ 'name' ] . "',
145 '" . $bugsys- > in
[ 'description' ] . "', ' $type' , " . intval ( $bugsys- > in
[ 'required' ]) . ",
146 " . intval ( $bugsys- > in
[ 'cansearch' ]) . ", $extradata
150 $fieldid = $db- > insert_id ();
152 $db- > query ( "ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill ADD field $fieldid MEDIUMTEXT NULL" );
153 $db- > query ( "OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill" );
158 UPDATE " . TABLE_PREFIX
. "bugfield
159 SET name = '" . $bugsys- > in
[ 'name' ] . "',
160 description = '" . $bugsys- > in
[ 'description' ] . "',
161 required = " . intval ( $bugsys- > in
[ 'required' ]) . ",
162 cansearch = " . intval ( $bugsys- > in
[ 'cansearch' ]) . ",
164 WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ])
167 $fieldid = intval ( $bugsys- > in
[ 'fieldid' ]);
170 foreach ( $bugsys- > in
[ 'custom' ] AS $usergroupid => $mask )
172 $values [] = intval ( $usergroupid ) . ", $fieldid , " . intval ( $mask );
176 REPLACE INTO " . TABLE_PREFIX
. "bugfieldpermission
177 (usergroupid, fieldid, mask)
179 (" . implode ( "), \n\t\t\t (" , $values ) . ")"
184 $admin- > redirect ( 'field.php?do=modify' , ( $add ? $lang- > string ( 'The custom field has been added' ) : $lang- > string ( 'The custom field has been updated' )));
187 // ###################################################################
189 if ( $_REQUEST [ 'do' ] == 'add' OR $_REQUEST [ 'do' ] == 'edit' )
191 $add = (( $_REQUEST [ 'do' ] == 'add' ) ? true : false );
192 $typeselect = (( $add AND empty ( $bugsys- > in
[ 'step' ])) ? true : false );
193 $edit = (( $add ) ? false : true );
195 $admin- > page_start (( $add ? $lang- > string ( 'Add New Custom Field' ) : $lang- > string ( 'Edit Custom Field' )));
196 $admin- > form_start ( 'field.php' , ( $typeselect ? 'add' : 'update' ));
197 if ( $add AND ! $typeselect )
199 $admin- > form_hidden_field ( 'type' , $bugsys- > in
[ 'type' ]);
203 $admin- > form_hidden_field ( 'step' , 1 );
204 $admin- > table_start ( true , '40%' );
205 $admin- > table_head ( $lang- > string ( 'Select Type' ), 2 , 'custom_bug_fields' );
209 $admin- > table_start ();
210 $admin- > table_head (( $add ? $lang- > string ( 'Add New Bug Field' ) . ' - ' . $TYPES [ $bugsys- > in
[ 'type' ] ] : $lang- > string ( 'Edit Field' )), 2 , 'custom_bug_fields_options' );
215 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
218 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
221 $admin- > form_hidden_field ( 'fieldid' , $field [ 'fieldid' ]);
226 $type = (( $add ) ? $bugsys- > in
[ 'type' ] : $field [ 'type' ]);
229 // show type selector
230 if ( empty ( $bugsys- > in
[ 'step' ]) AND $add )
232 foreach ( $TYPES AS $name => $description )
234 $admin- > list_item ( $description , $name );
236 $admin- > row_list ( $lang- > string ( 'Field Type' ), 'type' , false );
238 $admin- > row_submit ();
241 // have type, do that funkay thing!
244 if (! isset ( $TYPES [ " $type" ]))
246 $admin- >error( $lang- >getlex('error_invalid_id'));
250 $admin- >row_span( $lang- >string('Global Fields'), 'thead', 'center');
251 $admin- >row_text( $lang- >string('Field Type'), $TYPES [" $type" ]);
252 $admin- > row_input ( $lang- > string ( 'Display Name' ), 'name' , $field [ 'name' ]);
253 $admin- > row_textarea ( $lang- > string ( 'Description' ), 'description' , $field [ 'description' ]);
254 $admin- > row_yesno ( $lang- > string ( 'Required' ), 'required' , $field [ 'required' ]);
255 $admin- > row_yesno ( $lang- > string ( 'Can Be Searched' ), 'cansearch' , (( isset ( $field [ 'cansearch' ])) ? $field [ 'cansearch' ] : true ));
257 // type-specific fields
258 $admin- > row_span ( $lang- > string ( 'Type-Specific Fields' ), 'thead' , 'center' );
263 $admin- > row_input ( $lang- > string ( 'Default Value' ), 'defaultvalue' , $field [ 'defaultvalue' ]);
264 $admin- > row_input ( $lang- > string ( 'Regular Expression Match' ), 'regexmatch' , $field [ 'regexmatch' ]);
265 $admin- > row_input ( $lang- > string ( 'Maximum Length' ), 'maxlength' , $field [ 'maxlength' ], 2 , 10 );
268 case 'input_checkbox' :
269 $admin- > row_yesno ( $lang- > string ( 'Checked By Default' ), 'defaultvalue' , $field [ 'defaultvalue' ]);
272 case 'select_single' :
273 $admin- > row_textarea ( $lang- > string ( 'Selection Values' ), 'selects' , stripslashes ( implode ( " \n " , unserialize ( $field [ 'selects' ]))));
274 $admin- > row_yesno ( $lang- > string ( 'Make the First Option Default' ), 'usedefault' , $field [ 'usedefault' ]);
280 // custom field permissions
281 $admin- > table_start ();
282 $admin- > table_head ( $lang- > string ( 'Custom Field Permissions' ));
286 $perms = $db- > query ( "SELECT usergroupid, mask FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = $field [fieldid]" );
287 while ( $perm = $db- > fetch_array ( $perms ))
289 $permissions [ " $perm [usergroupid]" ] = $perm [ 'mask' ];
293 $usergroups = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "usergroup ORDER BY usergroupid" );
294 while ( $usergroup = $db- > fetch_array ( $usergroups ))
297 $admin- > list_item ( $lang- > string ( 'No Permission' ), 0 , $permissions [ " $usergroup [usergroupid]" ] == 0 );
298 $admin- > list_item ( $lang- > string ( 'Can View Field' ), 1 , $permissions [ " $usergroup [usergroupid]" ] == 1 );
299 $admin- > list_item ( $lang- > string ( 'Can View, Edit Field' ), 2 , $permissions [ " $usergroup [usergroupid]" ] == 2 );
300 $admin- > row_list ( $usergroup [ 'title' ], "custom[ $usergroup [usergroupid]]" );
306 $admin- > table_start ();
307 $admin- > row_submit ((( $edit ) ? '<a href="field.php?do=delete&fieldid=' . $field [ 'fieldid' ] . '">[' . $lang- > string ( 'Delete Field' ) . ']</a>' : '' ));
315 // ###################################################################
317 if ( $_REQUEST [ 'do' ] == 'modify' )
319 $admin- > page_start ( $lang- > string ( 'Additional Bug Fields' ));
321 $admin- > table_start ();
322 $admin- > table_head ( $lang- > string ( 'Additional Bug Fields' ), 3 , 'custom_bug_fields' );
323 $admin- > table_column_head ( array ( $lang- > string ( 'Display Name/Description' ), $lang- > string ( 'Field ID' ), $lang- > string ( 'Actions' )));
325 $fields = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid ASC" );
326 while ( $field = $db- > fetch_array ( $fields ))
328 $admin- > row_multi_item (
330 " $field [name]<div class= \" smallfont \" ><em> $field [description]</em></div>" => 'l' ,
331 " $field [fieldid]" => 'c' ,
332 "<a href= \" field.php?do=edit&fieldid= $field [fieldid] \" >[" . $lang- > string ( 'Edit' ) . "]</a> <a href= \" field.php?do=delete&fieldid= $field [fieldid] \" >[" . $lang- > string ( 'Delete' ) . "]</a>" => 'c'
337 $admin- > row_span ( '<a href="field.php?do=add">[' . $lang- > string ( 'Add New Bug Field' ) . ']</a>' , 'tfoot' , 'center' , 3 );
343 /*=====================================================================*\
344 || ###################################################################
347 || ###################################################################
348 \*=====================================================================*/