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',
27 // ###################################################################
29 if (empty($_REQUEST['do']))
31 $_REQUEST['do'] = 'modify';
34 // ###################################################################
36 if ($_REQUEST['do'] == 'kill')
38 // run code to remove item in database
41 // ###################################################################
43 if ($_REQUEST['do'] == 'delete')
48 // ###################################################################
50 if ($_REQUEST['do'] == 'update')
55 $type = $bugsys->in
['type'];
57 if ($bugsys->in
['fieldid'])
59 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfields WHERE fieldid = " . intval($bugsys->in
['fieldid']));
62 $admin->error(phrase('error_invalid_id'));
67 $type = $field['type'];
70 if (empty($bugsys->in
['shortname']) AND $add)
72 $admin->error('You must specify a short name/call name.');
74 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)
76 $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.');
79 if (empty($bugsys->in
['name']))
81 $admin->error('You must specify a display name.');
83 if (!isset($TYPES["$type"]) AND $add)
85 $admin->error('Invalid field type specified.');
92 $extrafields = 'defaultvalue, regexmatch, maxlength';
93 $extradata = "'" . $bugsys->in
['defaultvalue'] . "', '" . $bugsys->in
['regexmatch'] . "', " . intval($bugsys->in
['maxlength']);
94 $extraupdate = "defaultvalue = '" . $bugsys->in
['defaultvalue'] . "', regexmatch = '" . $bugsys->in
['regexmatch'] . "', maxlength = " . intval($bugsys->in
['maxlength']);
97 case 'input_checkbox':
98 $extrafields = 'default';
99 $extradata = intval($bugsys->in
['default']);
100 $extraupdate = "default = " . intval($bugsys->in
['default']);
103 case 'select_single':
104 $extrafields = 'selects, usedefault';
106 // can't use explode() here because explode() returns !empty() when splitting an empty string
107 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
108 $selects = preg_split("#\n#", trim($bugsys->in
['selects']), 0, PREG_SPLIT_NO_EMPTY
);
109 array_walk($selects, 'trim');
110 if (count($selects) < 1)
112 $admin->error('You need to specify some select values.');
115 $extradata = "'" . $bugsys->escape(serialize($selects)) . "', " . intval($bugsys->in
['usedefault']);
116 $extraupdate = "selects = '" . $bugsys->escape(serialize($selects)) . "', usedefault = " . intval($bugsys->in
['usedefault']);
122 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfields WHERE shortname = '" . $bugsys->in
['shortname'] . "'") OR $bugsys->in
['shortname'] == 'bugid')
124 $admin->error('That short name is already in use, please change it so it is unique.');
128 INSERT INTO bugfields
129 (shortname, name, description, type, required, private, $extrafields)
131 ('" . $bugsys->in
['shortname'] . "', '" . $bugsys->in
['name'] . "',
132 '" . $bugsys->in
['description'] . "', '$type', " . intval($bugsys->in
['required']) . ",
133 " . intval($bugsys->in
['private']) . ", $extradata
137 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bugvalues ADD " . $bugsys->in
['shortname'] . " MEDIUMTEXT NOT NULL");
138 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvalues");
143 UPDATE " . TABLE_PREFIX
. "bugfields
144 SET name = '" . $bugsys->in
['name'] . "',
145 description = '" . $bugsys->in
['description'] . "',
146 required = " . intval($bugsys->in
['required']) . ",
147 private = " . intval($bugsys->in
['private']) . ",
149 WHERE fieldid = " . intval($bugsys->in
['fieldid'])
153 $admin->redirect('fields.php?do=modify', (($add) ?
'The custom bug field has been added.' : 'The bug field has been updated.'));
156 // ###################################################################
158 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
160 $add = (($_REQUEST['do'] == 'add') ? true
: false
);
161 $typeselect = (($add AND empty($bugsys->in
['step'])) ? true
: false
);
162 $edit = (($add) ? false
: true
);
164 $admin->page_start(phrase((($add) ?
'add_new_field' : 'edit_field')));
165 $admin->form_start('fields.php', (($typeselect) ?
'add' : 'update'));
166 if ($add AND !$typeselect)
168 $admin->form_hidden_field('type', $bugsys->in
['type']);
172 $admin->form_hidden_field('step', 1);
173 $admin->table_start(true
, '40%');
174 $admin->table_head('Select Type');
178 $admin->table_start();
179 $admin->table_head((($add) ?
phrase('add_new_field') . ' - ' . $TYPES[ $bugsys->in
['type'] ] : phrase('edit_field')));
184 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfields WHERE fieldid = " . intval($bugsys->in
['fieldid']));
187 $admin->error(phrase('error_invalid_id'));
190 $admin->form_hidden_field('fieldid', $field['fieldid']);
195 $type = (($add) ?
$bugsys->in
['type'] : $field['type']);
198 // show type selector
199 if (empty($bugsys->in
['step']) AND $add)
201 foreach ($TYPES AS $name => $description)
203 $admin->list_item($description, $name);
205 $admin->row_list('Select field type', 'type', false
);
207 $admin->row_submit();
210 // have type, do that funkay thing!
213 if (!isset($TYPES["$type"]))
215 $admin->error(phrase('error_invalid_id'));
219 $admin->row_span('Global Fields', 'thead', 'center');
220 $admin->row_text('Field Type', $TYPES["$type"]);
221 $admin->row_input('Short Name/Call Name', 'shortname', $field['shortname']);
222 $admin->row_input('Display Name', 'name', $field['name']);
223 $admin->row_textarea('Description', 'description', $field['description']);
224 $admin->row_yesno('Required', 'required', $field['required']);
225 $admin->row_yesno('Private Field', 'private', $field['private']);
227 // type-specific fields
228 $admin->row_span('Type-Specific Fields', 'thead', 'center');
233 $admin->row_input('Default Value', 'defaultvalue', $field['defaultvalue']);
234 $admin->row_input('Regular Expression Match', 'regexmatch', $field['regexmatch']);
235 $admin->row_input('Maximum Length', 'maxlength', $field['maxlength'], 2, 10);
239 $admin->row_textarea('Default Value', 'defaultvalue', $field['defaultvalue']);
240 $admin->row_input('Regular Expression Match', 'regexmatch', $field['regexmatch']);
241 $admin->row_input('Maximum Length', 'maxlength', $field['maxlength'], 2, 10);
244 case 'input_checkbox':
245 $admin->row_yesno('Checked By Default', 'default', $field['default']);
248 case 'select_single':
249 $admin->row_textarea('Selection Values', 'selects', implode("\n", unserialize($field['selects'])));
250 $admin->row_yesno('Make the First Option Default', 'usedefault', $field['usedefault']);
255 $admin->row_submit((($edit) ?
'<a href="fields.php?do=delete&fieldid=' . $field['fieldid'] . '">[Delete Field]</a>' : ''));
263 // ###################################################################
265 if ($_REQUEST['do'] == 'modify')
267 $admin->page_start(phrase('additional_bug_fields'));
269 $admin->table_start();
270 $admin->table_head(phrase('additional_bug_fields'), 3);
271 $admin->table_column_head(array('Display Name/Description', 'Short Name/Field ID', 'Actions'));
273 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX
. "bugfields ORDER BY fieldid ASC");
274 while ($field = $db->fetch_array($fields))
276 $admin->row_multi_item(
278 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
279 "$field[shortname] (fieldid: $field[fieldid])" => 'c',
280 "<a href=\"fields.php?do=edit&fieldid=$field[fieldid]\">[Edit]</a> <a href=\"fields.php?do=delete&fieldid=$field[fieldid]\">[Delete]</a>" => 'c'
285 $admin->row_span('<input type="button" name="addug" value=" ' . phrase('add_new_field') . ' " onclick="window.location = \'fields.php?do=add\';" />', 'tfoot', 'center', 3);
291 /*=====================================================================*\
292 || ###################################################################
295 || ###################################################################
296 \*=====================================================================*/