]>
src.bluestatic.org Git - bugdar.git/blob - admin/field.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]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/api_field.php' );
25 require_once ( './includes/class_api_error.php' );
26 APIError ( array ( new API_Error_Handler ( $admin ), 'admin_error' ));
28 NavLinks
:: fieldsPages ();
29 $navigator- > set_focus ( 'tab' , 'fields' , null );
31 if (! can_perform ( 'canadminfields' ))
36 // ###################################################################
38 if ( empty ( $_REQUEST [ 'do' ]))
40 $_REQUEST [ 'do' ] = 'modify' ;
43 // ###################################################################
45 if ( $_REQUEST [ 'do' ] == 'kill' )
47 $field = new FieldAPI ( $bugsys );
48 $field- > set ( 'fieldid' , $bugsys- > in
[ 'fieldid' ]);
49 $field- > set_condition ();
52 $admin- > redirect ( 'field.php?do=modify' );
55 // ###################################################################
57 if ( $_REQUEST [ 'do' ] == 'delete' )
59 $admin- > page_confirm ( _ ( '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' , 'kill' , array ( 'fieldid' => $bugsys- > in
[ 'fieldid' ]));
62 // ###################################################################
64 if ( $_REQUEST [ 'do' ] == 'update' )
69 $type = $bugsys- > in
[ 'type' ];
71 $field = new FieldAPI ( $bugsys );
73 if ( $bugsys- > in
[ 'fieldid' ])
75 $field- > set ( 'fieldid' , $bugsys- > in
[ 'fieldid' ]);
76 $field- > set_condition ();
81 $type = $field- > objdata
[ 'type' ];
85 $field- > set ( 'type' , $type );
91 $field- > set ( 'defaultvalue' , $bugsys- > in
[ 'defaultvalue' ]);
92 $field- > set ( 'regexmatch' , $bugsys- > in
[ 'regexmatch' ]);
93 $field- > set ( 'maxlength' , $bugsys- > in
[ 'maxlength' ]);
96 case 'input_checkbox' :
97 $field- > set ( 'defaultvalue' , $bugsys- > in
[ 'defaultvalue' ]);
100 case 'select_single' :
101 $field- > set ( 'selects' , $bugsys- > in
[ 'selects' ]);
102 $field- > set ( 'usedefault' , $bugsys- > in
[ 'usedefault' ]);
106 $field- > set ( 'name' , $bugsys- > in
[ 'name' ]);
107 $field- > set ( 'description' , $bugsys- > in
[ 'description' ]);
108 $field- > set ( 'required' , $bugsys- > in
[ 'required' ]);
109 $field- > set ( 'cansearch' , $bugsys- > in
[ 'cansearch' ]);
114 $fieldid = $field- > insertid
;
116 $db- > query ( "ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill ADD field $fieldid MEDIUMTEXT NULL" );
117 $db- > query ( "OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill" );
122 $fieldid = $field- > values
[ 'fieldid' ];
125 $bugsys- > input_clean ( 'custom' , TYPE_UINT
);
126 foreach ( $bugsys- > in
[ 'custom' ] AS $usergroupid => $mask )
128 $values [] = $bugsys- > clean ( $usergroupid , TYPE_UINT
) . ", $fieldid , " . $mask ;
132 REPLACE INTO " . TABLE_PREFIX
. "bugfieldpermission
133 (usergroupid, fieldid, mask)
135 (" . implode ( "), \n\t\t\t (" , $values ) . ")"
138 $admin- > redirect ( 'field.php?do=modify' , ( $add ? _ ( 'The custom field has been added' ) : _ ( 'The custom field has been updated' )));
141 // ###################################################################
143 if ( $_REQUEST [ 'do' ] == 'add' OR $_REQUEST [ 'do' ] == 'edit' )
145 $field = new FieldAPI ( $bugsys );
147 $add = (( $_REQUEST [ 'do' ] == 'add' ) ? true : false );
148 $typeselect = (( $add AND empty ( $bugsys- > in
[ 'step' ])) ? true : false );
149 $edit = (( $add ) ? false : true );
153 NavLinks
:: fieldsAdd ();
154 $navigator- > set_focus ( 'link' , 'fields-add' , 'fields' );
158 NavLinks
:: fieldsEdit ( $bugsys- > in
[ 'fieldid' ]);
159 $navigator- > set_focus ( 'link' , 'fields-pages-fields' , 'fields-pages' );
162 $admin- > page_start (( $add ? _ ( 'Add New Custom Field' ) : _ ( 'Edit Custom Field' )));
163 $admin- > form_start ( 'field.php' , ( $typeselect ? 'add' : 'update' ));
164 if ( $add AND ! $typeselect )
166 $admin- > form_hidden_field ( 'type' , $bugsys- > in
[ 'type' ]);
170 $admin- > form_hidden_field ( 'step' , 1 );
171 $admin- > table_start ( true , '40%' );
172 $admin- > table_head ( _ ( 'Select Type' ));
176 $admin- > table_start ();
177 $admin- > table_head (( $add ? _ ( 'Add New Bug Field' ) . ' - ' . FieldAPI
:: field_types ( $bugsys- > in
[ 'type' ]) : _ ( 'Edit Field' )));
182 $field- > set ( 'fieldid' , $bugsys- > in
[ 'fieldid' ]);
183 $field- > set_condition ();
186 $admin- > form_hidden_field ( 'fieldid' , $field- > objdata
[ 'fieldid' ]);
191 $type = (( $add ) ? $bugsys- > in
[ 'type' ] : $field- > objdata
[ 'type' ]);
194 // show type selector
195 if ( empty ( $bugsys- > in
[ 'step' ]) AND $add )
197 foreach ( FieldAPI
:: field_types () AS $name => $description )
199 $admin- > list_item ( $description , $name );
201 $admin- > row_list ( _ ( 'Field Type' ), 'type' , false );
203 $admin- > row_submit ();
206 // have type, do that funkay thing!
209 $field- > set ( 'type' , $type );
212 $admin- > row_span ( _ ( 'Global Fields' ), 'thead' , 'center' );
213 $admin- > row_text ( _ ( 'Field Type' ), FieldAPI
:: field_types ( $type ));
214 $admin- > row_input ( _ ( 'Display Name' ), 'name' , $field- > objdata
[ 'name' ]);
215 $admin- > row_textarea ( _ ( 'Description' ), 'description' , $field- > objdata
[ 'description' ]);
216 $admin- > row_yesno ( _ ( 'Required' ), 'required' , $field- > objdata
[ 'required' ]);
217 $admin- > row_yesno ( _ ( 'Can Be Searched' ), 'cansearch' , (( isset ( $field- > objdata
[ 'cansearch' ])) ? $field- > objdata
[ 'cansearch' ] : true ));
219 // type-specific fields
220 $admin- > row_span ( _ ( 'Type-Specific Fields' ), 'thead' , 'center' );
225 $admin- > row_input ( _ ( 'Default Value' ), 'defaultvalue' , $field- > objdata
[ 'defaultvalue' ]);
226 $admin- > row_input ( _ ( 'Regular Expression Match' ), 'regexmatch' , $field- > objdata
[ 'regexmatch' ]);
227 $admin- > row_input ( _ ( 'Maximum Length' ), 'maxlength' , $field- > objdata
[ 'maxlength' ], 2 , 10 );
230 case 'input_checkbox' :
231 $admin- > row_yesno ( _ ( 'Checked By Default' ), 'defaultvalue' , $field- > objdata
[ 'defaultvalue' ]);
234 case 'select_single' :
235 $admin- > row_textarea ( _ ( 'Selection Values' ), 'selects' , stripslashes ( implode ( " \n " , ( array ) unserialize ( $field- > objdata
[ 'selects' ]))));
236 $admin- > row_yesno ( _ ( 'Make the First Option Default' ), 'usedefault' , $field- > objdata
[ 'usedefault' ]);
242 // custom field permissions
243 $admin- > table_start ();
244 $admin- > table_head ( _ ( 'Custom Field Permissions' ));
248 $perms = $db- > query ( "SELECT usergroupid, mask FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = " . $field- > objdata
[ 'fieldid' ]);
249 while ( $perm = $db- > fetch_array ( $perms ))
251 $permissions [ " $perm [usergroupid]" ] = $perm [ 'mask' ];
255 $usergroups = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "usergroup ORDER BY usergroupid" );
256 while ( $usergroup = $db- > fetch_array ( $usergroups ))
259 $admin- > list_item ( _ ( 'No Permission' ), 0 , $permissions [ " $usergroup [usergroupid]" ] == 0 );
260 $admin- > list_item ( _ ( 'Can View Field' ), 1 , $permissions [ " $usergroup [usergroupid]" ] == 1 );
261 $admin- > list_item ( _ ( 'Can View, Edit Field' ), 2 , $permissions [ " $usergroup [usergroupid]" ] == 2 );
262 $admin- > row_list ( $usergroup [ 'title' ], "custom[ $usergroup [usergroupid]]" );
268 $admin- > table_start ();
269 $admin- > row_submit ();
277 // ###################################################################
279 if ( $_REQUEST [ 'do' ] == 'modify' )
281 NavLinks
:: fieldsAdd ();
282 $navigator- > set_focus ( 'link' , 'fields-pages-fields' , 'fields-pages' );
284 $admin- > page_start ( _ ( 'Additional Bug Fields' ));
286 $admin- > table_start ();
287 $admin- > table_head ( _ ( 'Additional Bug Fields' ), 3 , 'custom_bug_fields' );
288 $admin- > table_column_head ( array ( _ ( 'Display Name/Description' ), _ ( 'Field ID' ), _ ( 'Actions' )));
290 $fields = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid ASC" );
291 while ( $field = $db- > fetch_array ( $fields ))
293 $admin- > row_multi_item (
295 " $field [name]<div class= \" smallfont \" ><em> $field [description]</em></div>" => 'l' ,
296 " $field [fieldid]" => 'c' ,
297 "<a href= \" field.php?do=edit&fieldid= $field [fieldid] \" >[" . _ ( 'Edit' ) . "]</a> <a href= \" field.php?do=delete&fieldid= $field [fieldid] \" >[" . _ ( 'Delete' ) . "]</a>" => 'c'
307 /*=====================================================================*\
308 || ###################################################################
311 || ###################################################################
312 \*=====================================================================*/