]> src.bluestatic.org Git - bugdar.git/blob - admin/field.php
r1522: Adding a PHP4 constructor to the Authentication class
[bugdar.git] / admin / field.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 require_once('./global.php');
23 require_once('./includes/api_field.php');
24
25 require_once('./includes/class_api_error.php');
26 APIError(array(new API_Error_Handler($admin), 'admin_error'));
27
28 NavLinks::fieldsPages();
29 $navigator->set_focus('tab', 'fields', null);
30
31 if (!can_perform('canadminfields'))
32 {
33 admin_login();
34 }
35
36 // ###################################################################
37
38 if (empty($_REQUEST['do']))
39 {
40 $_REQUEST['do'] = 'modify';
41 }
42
43 // ###################################################################
44
45 if ($_REQUEST['do'] == 'kill')
46 {
47 $field = new FieldAPI($bugsys);
48 $field->set('fieldid', $bugsys->in['fieldid']);
49 $field->set_condition();
50 $field->delete();
51
52 $admin->redirect('field.php?do=modify');
53 }
54
55 // ###################################################################
56
57 if ($_REQUEST['do'] == 'delete')
58 {
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']));
60 }
61
62 // ###################################################################
63
64 if ($_REQUEST['do'] == 'update')
65 {
66 $edit = false;
67 $add = true;
68
69 $type = $bugsys->in['type'];
70
71 $field = new FieldAPI($bugsys);
72
73 if ($bugsys->in['fieldid'])
74 {
75 $field->set('fieldid', $bugsys->in['fieldid']);
76 $field->set_condition();
77 $field->fetch();
78
79 $edit = true;
80 $add = false;
81 $type = $field->objdata['type'];
82 }
83 else
84 {
85 $field->set('type', $type);
86 }
87
88 switch ($type)
89 {
90 case 'input_text':
91 $field->set('defaultvalue', $bugsys->in['defaultvalue']);
92 $field->set('regexmatch', $bugsys->in['regexmatch']);
93 $field->set('maxlength', $bugsys->in['maxlength']);
94 break;
95
96 case 'input_checkbox':
97 $field->set('defaultvalue', $bugsys->in['defaultvalue']);
98 break;
99
100 case 'select_single':
101 $field->set('selects', $bugsys->in['selects']);
102 $field->set('usedefault', $bugsys->in['usedefault']);
103 break;
104 }
105
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']);
110
111 if ($add)
112 {
113 $field->insert();
114 $fieldid = $field->insertid;
115
116 $db->query("ALTER TABLE " . TABLE_PREFIX . "bug ADD custom$fieldid MEDIUMTEXT NULL");
117 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bug");
118 }
119 else
120 {
121 $field->update();
122 $fieldid = $field->values['fieldid'];
123 }
124
125 $bugsys->input_clean('custom', TYPE_UINT);
126 foreach ($bugsys->in['custom'] AS $usergroupid => $mask)
127 {
128 $values[] = $bugsys->clean($usergroupid, TYPE_UINT) . ", $fieldid, " . $mask;
129 }
130
131 $db->query("
132 REPLACE INTO " . TABLE_PREFIX . "bugfieldpermission
133 (usergroupid, fieldid, mask)
134 VALUES
135 (" . implode("),\n\t\t\t(", $values) . ")"
136 );
137
138 $admin->redirect('field.php?do=modify', ($add ? _('The custom field has been added') : _('The custom field has been updated')));
139 }
140
141 // ###################################################################
142
143 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
144 {
145 $field = new FieldAPI($bugsys);
146
147 $add = (($_REQUEST['do'] == 'add') ? true : false);
148 $typeselect = (($add AND empty($bugsys->in['step'])) ? true : false);
149 $edit = (($add) ? false : true);
150
151 if ($add)
152 {
153 NavLinks::fieldsAdd();
154 $navigator->set_focus('link', 'fields-add', 'fields');
155 }
156 else
157 {
158 NavLinks::fieldsEdit($bugsys->in['fieldid']);
159 $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages');
160 }
161
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)
165 {
166 $admin->form_hidden_field('type', $bugsys->in['type']);
167 }
168 if ($typeselect)
169 {
170 $admin->form_hidden_field('step', 1);
171 $admin->table_start(true, '40%');
172 $admin->table_head(_('Select Type'));
173 }
174 else
175 {
176 $admin->table_start();
177 $admin->table_head(($add ? _('Add New Bug Field') . ' - ' . FieldAPI::field_types($bugsys->in['type']) : _('Edit Field')));
178 }
179
180 if ($edit)
181 {
182 $field->set('fieldid', $bugsys->in['fieldid']);
183 $field->set_condition();
184 $field->fetch();
185
186 $admin->form_hidden_field('fieldid', $field->objdata['fieldid']);
187 }
188
189 if (!$typeselect)
190 {
191 $type = (($add) ? $bugsys->in['type'] : $field->objdata['type']);
192 }
193
194 // show type selector
195 if (empty($bugsys->in['step']) AND $add)
196 {
197 foreach (FieldAPI::field_types() AS $name => $description)
198 {
199 $admin->list_item($description, $name);
200 }
201 $admin->row_list(_('Field Type'), 'type', false);
202
203 $admin->row_submit();
204 $admin->table_end();
205 }
206 // have type, do that funkay thing!
207 else
208 {
209 $field->set('type', $type);
210
211 // global fields
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));
218
219 // type-specific fields
220 $admin->row_span(_('Type-Specific Fields'), 'thead', 'center');
221
222 switch ($type)
223 {
224 case 'input_text':
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);
228 break;
229
230 case 'input_checkbox':
231 $admin->row_yesno(_('Checked By Default'), 'defaultvalue', $field->objdata['defaultvalue']);
232 break;
233
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']);
237 break;
238 }
239
240 $admin->table_end();
241
242 // custom field permissions
243 $admin->table_start();
244 $admin->table_head(_('Custom Field Permissions'));
245
246 if ($edit)
247 {
248 $perms = $db->query("SELECT usergroupid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = " . $field->objdata['fieldid']);
249 while ($perm = $db->fetch_array($perms))
250 {
251 $permissions["$perm[usergroupid]"] = $perm['mask'];
252 }
253 }
254
255 $usergroups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid");
256 while ($usergroup = $db->fetch_array($usergroups))
257 {
258 unset($listitem);
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]]");
263 }
264
265 $admin->table_end();
266
267 // end table
268 $admin->table_start();
269 $admin->row_submit();
270 $admin->table_end();
271 $admin->form_end();
272 }
273
274 $admin->page_end();
275 }
276
277 // ###################################################################
278
279 if ($_REQUEST['do'] == 'modify')
280 {
281 NavLinks::fieldsAdd();
282 $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages');
283
284 $admin->page_start(_('Additional Bug Fields'));
285
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')));
289
290 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid ASC");
291 while ($field = $db->fetch_array($fields))
292 {
293 $admin->row_multi_item(
294 array(
295 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
296 "$field[fieldid]" => 'c',
297 "<a href=\"field.php?do=edit&amp;fieldid=$field[fieldid]\">[" . _('Edit') . "]</a> <a href=\"field.php?do=delete&amp;fieldid=$field[fieldid]\">[" . _('Delete') . "]</a>" => 'c'
298 )
299 );
300 }
301
302 $admin->table_end();
303
304 $admin->page_end();
305 }
306
307 /*=====================================================================*\
308 || ###################################################################
309 || # $HeadURL$
310 || # $Id$
311 || ###################################################################
312 \*=====================================================================*/
313 ?>