]>
src.bluestatic.org Git - bugdar.git/blob - admin/field.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 require_once ( './global.php' );
15 if (! can_perform ( 'canadminfields' ))
21 'input_text' => $lang- > string ( 'Single-Line Text Box' ),
22 'input_checkbox' => $lang- > string ( 'Checkbox Flag' ),
23 'select_single' => $lang- > string ( 'Drop-Down Menu' ),
26 // ###################################################################
28 if ( empty ( $_REQUEST [ 'do' ]))
30 $_REQUEST [ 'do' ] = 'modify' ;
33 // ###################################################################
35 if ( $_REQUEST [ 'do' ] == 'kill' )
37 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
40 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
43 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = $field [fieldid]" );
44 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = $field [fieldid]" );
45 $db- > query ( "ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill DROP field $field [fieldid]" );
46 $db- > query ( "OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill" );
48 $admin- > redirect ( 'field.php?do=modify' );
51 // ###################################################################
53 if ( $_REQUEST [ 'do' ] == 'delete' )
55 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
58 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
61 $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]" );
64 // ###################################################################
66 if ( $_REQUEST [ 'do' ] == 'update' )
71 $type = $bugsys- > in
[ 'type' ];
73 if ( $bugsys- > in
[ 'fieldid' ])
75 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
78 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
83 $type = $field [ 'type' ];
86 if ( empty ( $bugsys- > in
[ 'name' ]))
88 $admin- > error ( $lang- > string ( 'You must specify a display name.' ));
90 if (! isset ( $TYPES [ " $type" ]) AND $add )
92 $admin- >error( $lang- >string('Invalid field type specified.'));
98 $extrafields = 'defaultvalue, regexmatch, maxlength';
99 $extradata = " '" . $bugsys- >in[' defaultvalue
'] . "' , '" . $bugsys- >in[' regexmatch
'] . "' , " . intval( $bugsys- >in['maxlength']);
100 $extraupdate = " defaultvalue
= '" . $bugsys- >in[' defaultvalue
'] . "' , regexmatch
= '" . $bugsys- >in[' regexmatch
'] . "' , maxlength
= " . intval( $bugsys- >in['maxlength']);
103 case 'input_checkbox':
104 $extrafields = 'defaultvalue';
105 $extradata = intval( $bugsys- >in['defaultvalue']);
106 $extraupdate = " defaultvalue
= " . intval( $bugsys- >in['defaultvalue']);
109 case 'select_single':
110 $extrafields = 'selects, usedefault';
112 // can't use explode() here because explode() returns !empty() when splitting an empty string
113 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
114 $selects = preg_split(" #\n#", trim($bugsys->in['selects']), 0, PREG_SPLIT_NO_EMPTY);
115 array_walk ( $selects , 'trim' );
116 if ( count ( $selects ) < 1 )
118 $admin- > error ( $lang- > string ( 'You need to specify some select values.' ));
121 $extradata = "'" . $bugsys- > escape ( serialize ( $selects )) . "', " . intval ( $bugsys- > in
[ 'usedefault' ]);
122 $extraupdate = "selects = '" . $bugsys- > escape ( serialize ( $selects )) . "', usedefault = " . intval ( $bugsys- > in
[ 'usedefault' ]);
130 (name, description, type, required, cansearch, $extrafields )
132 ('" . $bugsys- > in
[ 'name' ] . "',
133 '" . $bugsys- > in
[ 'description' ] . "', ' $type' , " . intval ( $bugsys- > in
[ 'required' ]) . ",
134 " . intval ( $bugsys- > in
[ 'cansearch' ]) . ", $extradata
138 $fieldid = $db- > insert_id ();
140 $db- > query ( "ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill ADD field $fieldid MEDIUMTEXT NULL" );
141 $db- > query ( "OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill" );
146 UPDATE " . TABLE_PREFIX
. "bugfield
147 SET name = '" . $bugsys- > in
[ 'name' ] . "',
148 description = '" . $bugsys- > in
[ 'description' ] . "',
149 required = " . intval ( $bugsys- > in
[ 'required' ]) . ",
150 cansearch = " . intval ( $bugsys- > in
[ 'cansearch' ]) . ",
152 WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ])
156 $admin- > redirect ( 'field.php?do=modify' , ( $add ? $lang- > string ( 'The custom field has been added' ) : $lang- > string ( 'The custom field has been updated' )));
159 // ###################################################################
161 if ( $_REQUEST [ 'do' ] == 'add' OR $_REQUEST [ 'do' ] == 'edit' )
163 $add = (( $_REQUEST [ 'do' ] == 'add' ) ? true : false );
164 $typeselect = (( $add AND empty ( $bugsys- > in
[ 'step' ])) ? true : false );
165 $edit = (( $add ) ? false : true );
167 $admin- > page_start (( $add ? $lang- > string ( 'Add New Custom Field' ) : $lang- > string ( 'Edit Custom Field' )));
168 $admin- > form_start ( 'field.php' , ( $typeselect ? 'add' : 'update' ));
169 if ( $add AND ! $typeselect )
171 $admin- > form_hidden_field ( 'type' , $bugsys- > in
[ 'type' ]);
175 $admin- > form_hidden_field ( 'step' , 1 );
176 $admin- > table_start ( true , '40%' );
177 $admin- > table_head ( $lang- > string ( 'Select Type' ));
181 $admin- > table_start ();
182 $admin- > table_head (( $add ? $lang- > string ( 'Add New Bug Field' ) . ' - ' . $TYPES [ $bugsys- > in
[ 'type' ] ] : $lang- > string ( 'Edit Field' )));
187 $field = $db- > query_first ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval ( $bugsys- > in
[ 'fieldid' ]));
190 $admin- > error ( $lang- > getlex ( 'error_invalid_id' ));
193 $admin- > form_hidden_field ( 'fieldid' , $field [ 'fieldid' ]);
198 $type = (( $add ) ? $bugsys- > in
[ 'type' ] : $field [ 'type' ]);
201 // show type selector
202 if ( empty ( $bugsys- > in
[ 'step' ]) AND $add )
204 foreach ( $TYPES AS $name => $description )
206 $admin- > list_item ( $description , $name );
208 $admin- > row_list ( $lang- > string ( 'Field Type' ), 'type' , false );
210 $admin- > row_submit ();
213 // have type, do that funkay thing!
216 if (! isset ( $TYPES [ " $type" ]))
218 $admin- >error( $lang- >getlex('error_invalid_id'));
222 $admin- >row_span( $lang- >string('Global Fields'), 'thead', 'center');
223 $admin- >row_text( $lang- >string('Field Type'), $TYPES [" $type" ]);
224 $admin- > row_input ( $lang- > string ( 'Display Name' ), 'name' , $field [ 'name' ]);
225 $admin- > row_textarea ( $lang- > string ( 'Description' ), 'description' , $field [ 'description' ]);
226 $admin- > row_yesno ( $lang- > string ( 'Required' ), 'required' , $field [ 'required' ]);
227 $admin- > row_yesno ( $lang- > string ( 'Can Be Searched' ), 'cansearch' , (( isset ( $field [ 'cansearch' ])) ? $field [ 'cansearch' ] : true ));
229 // type-specific fields
230 $admin- > row_span ( $lang- > string ( 'Type-Specific Fields' ), 'thead' , 'center' );
235 $admin- > row_input ( $lang- > string ( 'Default Value' ), 'defaultvalue' , $field [ 'defaultvalue' ]);
236 $admin- > row_input ( $lang- > string ( 'Regular Expression Match' ), 'regexmatch' , $field [ 'regexmatch' ]);
237 $admin- > row_input ( $lang- > string ( 'Maximum Length' ), 'maxlength' , $field [ 'maxlength' ], 2 , 10 );
240 case 'input_checkbox' :
241 $admin- > row_yesno ( $lang- > string ( 'Checked By Default' ), 'defaultvalue' , $field [ 'defaultvalue' ]);
244 case 'select_single' :
245 $admin- > row_textarea ( $lang- > string ( 'Selection Values' ), 'selects' , stripslashes ( implode ( " \n " , unserialize ( $field [ 'selects' ]))));
246 $admin- > row_yesno ( $lang- > string ( 'Make the First Option Default' ), 'usedefault' , $field [ 'usedefault' ]);
251 $admin- > row_submit ((( $edit ) ? '<a href="field.php?do=delete&fieldid=' . $field [ 'fieldid' ] . '">[' . $lang- > string ( 'Delete Field' ) . ']</a>' : '' ));
259 // ###################################################################
261 if ( $_REQUEST [ 'do' ] == 'modify' )
263 $admin- > page_start ( $lang- > string ( 'Additional Bug Fields' ));
265 $admin- > table_start ();
266 $admin- > table_head ( $lang- > string ( 'Additional Bug Fields' ), 3 );
267 $admin- > table_column_head ( array ( $lang- > string ( 'Display Name/Description' ), $lang- > string ( 'Field ID' ), $lang- > string ( 'Actions' )));
269 $fields = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid ASC" );
270 while ( $field = $db- > fetch_array ( $fields ))
272 $admin- > row_multi_item (
274 " $field [name]<div class= \" smallfont \" ><em> $field [description]</em></div>" => 'l' ,
275 "(fieldid: $field [fieldid])" => 'c' ,
276 "<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'
281 $admin- > row_span ( '<a href="field.php?do=add">[' . $lang- > string ( 'Add New Bug Field' ) . ']</a>' , 'tfoot' , 'center' , 3 );
287 /*=====================================================================*\
288 || ###################################################################
291 || ###################################################################
292 \*=====================================================================*/