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' => 'Single-Line Text Box',
22 'textarea' => 'Multi-Line Text Area',
23 'input_checkbox' => 'Checkbox Flag',
24 'select_single' => 'Drop-Down Menu',
25 //'select_multi' => 'Multiple-Selection Menu'
28 // ###################################################################
30 if (empty($_REQUEST['do']))
32 $_REQUEST['do'] = 'modify';
35 // ###################################################################
37 if ($_REQUEST['do'] == 'kill')
39 // run code to remove item in database
42 // ###################################################################
44 if ($_REQUEST['do'] == 'delete')
49 // ###################################################################
51 if ($_REQUEST['do'] == 'update')
56 $type = $bugsys->in
['type'];
58 if ($bugsys->in
['fieldid'])
60 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfields WHERE fieldid = " . intval($bugsys->in
['fieldid']));
63 $admin->error(phrase('error_invalid_id'));
68 $type = $field['type'];
71 if (empty($bugsys->in
['shortname']) AND $add)
73 $admin->error('You must specify a short name/call name.');
75 if ((preg_match('#[^a-z0-9_]#', $bugsys->in
['shortname']) OR !preg_match('#^[a-z]#', $bugsys->in
['shortname']) OR preg_match('#[^a-z0-9]$#', $bugsys->in
['shortname'])) AND $add)
77 $admin->error('The short name can only contain lowercase letters, numbers, and underscores; it must also begin with a letter and cannot end in anything but a letter or a number.');
80 if (empty($bugsys->in
['name']))
82 $admin->error('You must specify a display name.');
84 if (!isset($TYPES["$type"]) AND $add)
86 $admin->error('Invalid field type specified.');
89 switch ($bugsys->in
['type'])
93 $extrafields = 'defaultvalue, regexmatch, maxlength';
94 $extradata = "'" . $bugsys->in
['defaultvalue'] . "', '" . $bugsys->in
['regexmatch'] . "', " . intval($bugsys->in
['maxlength']);
95 $extraupdate = "defaultvalue = '" . $bugsys->in
['defaultvalue'] . "', regexmatch = '" . $bugsys->in
['regexmatch'] . "', maxlength = " . intval($bugsys->in
['maxlength']);
98 case 'input_checkbox':
99 $extrafields = 'default';
100 $extradata = intval($bugsys->in
['default']);
101 $extraupdate = "default = " . intval($bugsys->in
['default']);
104 case 'select_single':
105 $extrafields = 'selects, usedefault';
107 // can't use explode() here because explode() returns !empty() when splitting an empty string
108 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
109 $selects = preg_split("#\n#", trim($bugsys->in
['selects']), 0, PREG_SPLIT_NO_EMPTY
);
110 array_walk($selects, 'trim');
112 if (count($selects) < 1)
114 $admin->error('You need to specify some select values.');
117 $extradata = "'" . $bugsys->escape(serialize($selects)) . "', " . intval($bugsys->in
['usedefault']);
118 $extraupdate = "selects = '" . $bugsys->escape(serialize($selects)) . "', usedefault = " . intval($bugsys->in
['usedefault']);
122 /*var_dump($extrafields);
123 var_dump($extradata);
124 var_dump($extraupdate);
129 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfields WHERE shortname = '" . $bugsys->in
['shortname'] . "'") OR $bugsys->in
['shortname'] == 'bugid')
131 $admin->error('That short name is already in use, please change it so it is unique.');
135 INSERT INTO bugfields
136 (shortname, name, description, type, required, private, $extrafields)
138 ('" . $bugsys->in
['shortname'] . "', '" . $bugsys->in
['name'] . "',
139 '" . $bugsys->in
['description'] . "', '$type', " . intval($bugsys->in
['required']) . ",
140 " . intval($bugsys->in
['private']) . ", $extradata
144 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bugvalues ADD " . $bugsys->in
['shortname'] . " MEDIUMTEXT NOT NULL");
145 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvalues");
150 UPDATE " . TABLE_PREFIX
. "bugfields
151 SET name = '" . $bugsys->in
['name'] . "',
152 description = '" . $bugsys->in
['description'] . "',
153 required = " . intval($bugsys->in
['required']) . ",
154 private = " . intval($bugsys->in
['private']) . ",
156 WHERE fieldid = " . intval($bugsys->in
['fieldid'])
160 $admin->redirect('fields.php?do=modify', (($add) ?
'The custom bug field has been added.' : 'The bug field has been updated.'));
163 // ###################################################################
165 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
167 $add = (($_REQUEST['do'] == 'add') ? true
: false
);
168 $typeselect = (($add AND empty($bugsys->in
['step'])) ? true
: false
);
169 $edit = (($add) ? false
: true
);
171 $admin->page_start(phrase((($add) ?
'add_new_field' : 'edit_field')));
172 $admin->form_start('fields.php', (($typeselect) ?
'add' : 'update'));
173 if ($add AND !$typeselect)
175 $admin->form_hidden_field('type', $bugsys->in
['type']);
179 $admin->form_hidden_field('step', 1);
180 $admin->table_start(true
, '40%');
181 $admin->table_head('Select Type');
185 $admin->table_start();
186 $admin->table_head((($add) ?
phrase('add_new_field') . ' - ' . $TYPES[ $bugsys->in
['type'] ] : phrase('edit_field')));
191 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfields WHERE fieldid = " . intval($bugsys->in
['fieldid']));
194 $admin->error(phrase('error_invalid_id'));
197 $admin->form_hidden_field('fieldid', $field['fieldid']);
202 $type = (($add) ?
$bugsys->in
['type'] : $field['type']);
205 // show type selector
206 if (empty($bugsys->in
['step']) AND $add)
208 foreach ($TYPES AS $name => $description)
210 $admin->list_item($description, $name);
212 $admin->row_list('Select field type', 'type', false
);
214 $admin->row_submit();
217 // have type, do that funkay thing!
220 if (!isset($TYPES["$type"]))
222 $admin->error(phrase('error_invalid_id'));
226 $admin->row_span('Global Fields', 'thead', 'center');
227 $admin->row_text('Field Type', $TYPES["$type"]);
228 $admin->row_input('Short Name/Call Name', 'shortname', $field['shortname']);
229 $admin->row_input('Display Name', 'name', $field['name']);
230 $admin->row_textarea('Description', 'description', $field['description']);
231 $admin->row_yesno('Required', 'required', $field['required']);
232 $admin->row_yesno('Private Field', 'private', $field['private']);
234 // type-specific fields
235 $admin->row_span('Type-Specific Fields', 'thead', 'center');
240 $admin->row_input('Default Value', 'defaultvalue', $field['defaultvalue']);
241 $admin->row_input('Regular Expression Match', 'regexmatch', $field['regexmatch']);
242 $admin->row_input('Maximum Length', 'maxlength', $field['maxlength'], 2, 10);
246 $admin->row_textarea('Default Value', 'defaultvalue', $field['defaultvalue']);
247 $admin->row_input('Regular Expression Match', 'regexmatch', $field['regexmatch']);
248 $admin->row_input('Maximum Length', 'maxlength', $field['maxlength'], 2, 10);
251 case 'input_checkbox':
252 $admin->row_yesno('Checked By Default', 'default', $field['default']);
255 case 'select_single':
256 $admin->row_textarea('Selection Values', 'selects', implode("\n", unserialize($field['selects'])));
257 $admin->row_yesno('Make the First Option Default', 'usedefault', $field['usedefault']);
262 $admin->row_submit((($edit) ?
'<a href="fields.php?do=delete&fieldid=' . $field['fieldid'] . '">[Delete Field]</a>' : ''));
270 // ###################################################################
272 if ($_REQUEST['do'] == 'modify')
274 $admin->page_start(phrase('additional_bug_fields'));
276 $admin->table_start();
277 $admin->table_head(phrase('additional_bug_fields'), 3);
278 $admin->table_column_head(array('Display Name/Description', 'Short Name/Field ID', 'Actions'));
280 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX
. "bugfields ORDER BY fieldid ASC");
281 while ($field = $db->fetch_array($fields))
283 $admin->row_multi_item(
285 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
286 "$field[shortname] (fieldid: $field[fieldid])" => 'c',
287 "<a href=\"fields.php?do=edit&fieldid=$field[fieldid]\">[Edit]</a> <a href=\"fields.php?do=delete&fieldid=$field[fieldid]\">[Delete]</a>" => 'c'
292 $admin->row_span('<input type="button" name="addug" value=" ' . phrase('add_new_field') . ' " onclick="window.location = \'fields.php?do=add\';" />', 'tfoot', 'center', 3);
298 /*=====================================================================*\
299 || ###################################################################
302 || ###################################################################
303 \*=====================================================================*/