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 'input_checkbox' => 'Checkbox Flag',
23 'select_single' => '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(phrase('error_invalid_id'));
43 $db->query("DELETE FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = $field[fieldid]");
44 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill DROP $field[shortname]");
45 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill");
47 $admin->redirect('fields.php?do=modify', 'The field has been successfully removed from the system.');
50 // ###################################################################
52 if ($_REQUEST['do'] == 'delete')
54 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval($bugsys->in
['fieldid']));
57 $admin->error(phrase('error_invalid_id'));
60 $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!', "fields.php?do=kill&fieldid=$field[fieldid]");
63 // ###################################################################
65 if ($_REQUEST['do'] == 'update')
70 $type = $bugsys->in
['type'];
72 if ($bugsys->in
['fieldid'])
74 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval($bugsys->in
['fieldid']));
77 $admin->error(phrase('error_invalid_id'));
82 $type = $field['type'];
85 if (empty($bugsys->in
['shortname']) AND $add)
87 $admin->error('You must specify a short name/call name.');
89 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)
91 $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.');
94 if (empty($bugsys->in
['name']))
96 $admin->error('You must specify a display name.');
98 if (!isset($TYPES["$type"]) AND $add)
100 $admin->error('Invalid field type specified.');
106 $extrafields = 'defaultvalue, regexmatch, maxlength';
107 $extradata = "'" . $bugsys->in
['defaultvalue'] . "', '" . $bugsys->in
['regexmatch'] . "', " . intval($bugsys->in
['maxlength']);
108 $extraupdate = "defaultvalue = '" . $bugsys->in
['defaultvalue'] . "', regexmatch = '" . $bugsys->in
['regexmatch'] . "', maxlength = " . intval($bugsys->in
['maxlength']);
111 case 'input_checkbox':
112 $extrafields = 'defaultvalue';
113 $extradata = intval($bugsys->in
['defaultvalue']);
114 $extraupdate = "defaultvalue = " . intval($bugsys->in
['defaultvalue']);
117 case 'select_single':
118 $extrafields = 'selects, usedefault';
120 // can't use explode() here because explode() returns !empty() when splitting an empty string
121 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
122 $selects = preg_split("#\n#", trim($bugsys->in
['selects']), 0, PREG_SPLIT_NO_EMPTY
);
123 array_walk($selects, 'trim');
124 if (count($selects) < 1)
126 $admin->error('You need to specify some select values.');
129 $extradata = "'" . $bugsys->escape(serialize($selects)) . "', " . intval($bugsys->in
['usedefault']);
130 $extraupdate = "selects = '" . $bugsys->escape(serialize($selects)) . "', usedefault = " . intval($bugsys->in
['usedefault']);
136 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE shortname = '" . $bugsys->in
['shortname'] . "'") OR $bugsys->in
['shortname'] == 'bugid')
138 $admin->error('That short name is already in use, please change it so it is unique.');
143 (shortname, name, description, type, required, private, $extrafields)
145 ('" . $bugsys->in
['shortname'] . "', '" . $bugsys->in
['name'] . "',
146 '" . $bugsys->in
['description'] . "', '$type', " . intval($bugsys->in
['required']) . ",
147 " . intval($bugsys->in
['private']) . ", $extradata
151 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill ADD " . $bugsys->in
['shortname'] . " MEDIUMTEXT NULL");
152 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill");
157 UPDATE " . TABLE_PREFIX
. "bugfield
158 SET name = '" . $bugsys->in
['name'] . "',
159 description = '" . $bugsys->in
['description'] . "',
160 required = " . intval($bugsys->in
['required']) . ",
161 private = " . intval($bugsys->in
['private']) . ",
163 WHERE fieldid = " . intval($bugsys->in
['fieldid'])
167 $admin->redirect('fields.php?do=modify', (($add) ?
'The custom bug field has been added.' : 'The bug field has been updated.'));
170 // ###################################################################
172 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
174 $add = (($_REQUEST['do'] == 'add') ? true
: false
);
175 $typeselect = (($add AND empty($bugsys->in
['step'])) ? true
: false
);
176 $edit = (($add) ? false
: true
);
178 $admin->page_start(phrase((($add) ?
'add_new_field' : 'edit_field')));
179 $admin->form_start('fields.php', (($typeselect) ?
'add' : 'update'));
180 if ($add AND !$typeselect)
182 $admin->form_hidden_field('type', $bugsys->in
['type']);
186 $admin->form_hidden_field('step', 1);
187 $admin->table_start(true
, '40%');
188 $admin->table_head('Select Type');
192 $admin->table_start();
193 $admin->table_head((($add) ?
phrase('add_new_field') . ' - ' . $TYPES[ $bugsys->in
['type'] ] : phrase('edit_field')));
198 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . intval($bugsys->in
['fieldid']));
201 $admin->error(phrase('error_invalid_id'));
204 $admin->form_hidden_field('fieldid', $field['fieldid']);
209 $type = (($add) ?
$bugsys->in
['type'] : $field['type']);
212 // show type selector
213 if (empty($bugsys->in
['step']) AND $add)
215 foreach ($TYPES AS $name => $description)
217 $admin->list_item($description, $name);
219 $admin->row_list('Select field type', 'type', false
);
221 $admin->row_submit();
224 // have type, do that funkay thing!
227 if (!isset($TYPES["$type"]))
229 $admin->error(phrase('error_invalid_id'));
233 $admin->row_span('Global Fields', 'thead', 'center');
234 $admin->row_text('Field Type', $TYPES["$type"]);
235 $admin->row_input('Short Name/Call Name', 'shortname', $field['shortname']);
236 $admin->row_input('Display Name', 'name', $field['name']);
237 $admin->row_textarea('Description', 'description', $field['description']);
238 $admin->row_yesno('Required', 'required', $field['required']);
239 $admin->row_yesno('Private Field', 'private', $field['private']);
241 // type-specific fields
242 $admin->row_span('Type-Specific Fields', 'thead', 'center');
247 $admin->row_input('Default Value', 'defaultvalue', $field['defaultvalue']);
248 $admin->row_input('Regular Expression Match', 'regexmatch', $field['regexmatch']);
249 $admin->row_input('Maximum Length', 'maxlength', $field['maxlength'], 2, 10);
252 case 'input_checkbox':
253 $admin->row_yesno('Checked By Default', 'defaultvalue', $field['defaultvalue']);
256 case 'select_single':
257 $admin->row_textarea('Selection Values', 'selects', implode("\n", unserialize($field['selects'])));
258 $admin->row_yesno('Make the First Option Default', 'usedefault', $field['usedefault']);
263 $admin->row_submit((($edit) ?
'<a href="fields.php?do=delete&fieldid=' . $field['fieldid'] . '">[Delete Field]</a>' : ''));
271 // ###################################################################
273 if ($_REQUEST['do'] == 'modify')
275 $admin->page_start(phrase('additional_bug_fields'));
277 $admin->table_start();
278 $admin->table_head(phrase('additional_bug_fields'), 3);
279 $admin->table_column_head(array('Display Name/Description', 'Short Name/Field ID', 'Actions'));
281 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid ASC");
282 while ($field = $db->fetch_array($fields))
284 $admin->row_multi_item(
286 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
287 "$field[shortname] (fieldid: $field[fieldid])" => 'c',
288 "<a href=\"fields.php?do=edit&fieldid=$field[fieldid]\">[Edit]</a> <a href=\"fields.php?do=delete&fieldid=$field[fieldid]\">[Delete]</a>" => 'c'
293 $admin->row_span('<input type="button" name="addug" value=" ' . phrase('add_new_field') . ' " onclick="window.location = \'fields.php?do=add\';" />', 'tfoot', 'center', 3);
299 /*=====================================================================*\
300 || ###################################################################
303 || ###################################################################
304 \*=====================================================================*/