r908: Implementing new navigation system for the entire "Fields" tab
[bugdar.git] / admin / autoaction.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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/functions_datastore.php');
24
25 NavLinks::fieldsPages();
26 $navigator->set_focus('tab', 'fields', null);
27
28 if (!can_perform('canadminbugs'))
29 {
30 admin_login();
31 }
32
33 // ###################################################################
34
35 if (empty($_REQUEST['do']))
36 {
37 $_REQUEST['do'] = 'modify';
38 }
39
40 // ###################################################################
41
42 if ($_REQUEST['do'] == 'kill')
43 {
44 $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . $bugsys->input_clean('actionid', TYPE_UINT));
45 if (!$action)
46 {
47 $admin->error($lang->getlex('error_invalid_id'));
48 }
49
50 $db->query("DELETE FROM " . TABLE_PREFIX . "autoaction WHERE actionid = $action[actionid]");
51
52 build_auto_actions();
53
54 $admin->redirect('autoaction.php?do=modify');
55 }
56
57 // ###################################################################
58
59 if ($_REQUEST['do'] == 'delete')
60 {
61 $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . $bugsys->input_clean('actionid', TYPE_UINT));
62 if (!$action)
63 {
64 $admin->error($lang->getlex('error_invalid_id'));
65 }
66
67 $admin->page_confirm($lang->string('Are you sure you want to delete this action?'), "autoaction.php?do=kill&amp;actionid=$action[actionid]");
68 }
69
70 // ###################################################################
71
72 if ($_POST['do'] == 'insert' OR $_POST['do'] == 'update')
73 {
74 if (empty($bugsys->in['name']))
75 {
76 $admin->error($lang->string('You need to specify a name for this action.'));
77 }
78
79 foreach ($bugsys->in['fields'] AS $key => $value)
80 {
81 if (!empty($value) AND $value != -1 AND !is_array($value))
82 {
83 $deltas['builtin']["$key"] = $value;
84 }
85 }
86
87 foreach ($bugsys->in['fields']['custom'] AS $key => $value)
88 {
89 if (!empty($value) AND $value != -1)
90 {
91 $deltas['custom']["$key"] = $value;
92 }
93 }
94
95 if (sizeof($deltas['custom']) < 1 AND sizeof($deltas['builtin']) < 1)
96 {
97 $admin->error($lang->string('You need to specify some fields to change.'));
98 }
99
100 if ($_POST['do'] == 'insert')
101 {
102 $db->query("
103 INSERT INTO " . TABLE_PREFIX . "autoaction
104 (name, description, fieldchanges, comment)
105 VALUES
106 ('" . $bugsys->in['name'] . "', '" . $bugsys->in['description'] . "',
107 '" . $bugsys->escape(serialize($deltas)) . "', '" . $bugsys->in['comment'] . "'
108 )"
109 );
110
111 build_auto_actions();
112
113 $admin->redirect('autoaction.php');
114 }
115 else
116 {
117 if (!$bugsys->in['actionid'])
118 {
119 $admin->error($lang->getlex('error_invalid_id'));
120 }
121
122 $db->query("
123 UPDATE " . TABLE_PREFIX . "autoaction
124 SET name = '" . $bugsys->in['name'] . "',
125 description = '" . $bugsys->in['description'] . "',
126 fieldchanges = '" . $bugsys->escape(serialize($deltas)) . "',
127 comment = '" . $bugsys->in['comment'] . "'
128 WHERE actionid = " . $bugsys->input_clean('actionid', TYPE_UINT)
129 );
130
131 build_auto_actions();
132
133 $admin->redirect('autoaction.php');
134 }
135 }
136
137 // ###################################################################
138
139 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
140 {
141 $add = (($_REQUEST['do'] == 'add') ? true : false);
142 $edit = (($add) ? false : true);
143
144 if ($edit)
145 {
146 NavLinks::autoactionsEdit($bugsys->in['actionid']);
147 $navigator->set_focus('link', 'fields-pages-autoactions', 'fields-pages');
148
149 $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . $bugsys->input_clean('actionid', TYPE_UINT));
150 if (!$action)
151 {
152 $admin->error($lang->getlex('error_invalid_id'));
153 }
154 $action['fields'] = unserialize($action['fieldchanges']);
155 }
156 else
157 {
158 NavLinks::autoactionsAdd();
159 $navigator->set_focus('link', 'autoactions-add', 'autoactions');
160 }
161
162 $admin->page_start(($add ? $lang->string('New Automatic Action') : $lang->string('Edit Automatic Action')));
163
164 $admin->form_start('autoaction.php', ($add ? 'insert' : 'update'));
165
166 if ($edit)
167 {
168 $admin->form_hidden_field('actionid', $action['actionid']);
169 }
170
171 $admin->table_start();
172 $admin->table_head(($add ? $lang->string('New Automatic Action') : $lang->string('Edit Automatic Action')), 2, 'automatic_actions');
173
174 $admin->row_input($lang->string('Name'), 'name', $action['name']);
175 $admin->row_textarea($lang->string('Description'), 'description', $action['description']);
176 $admin->row_textarea($lang->string('Add Comment'), 'comment', $action['comment']);
177
178 $admin->row_span($lang->string('Field Changes'), 'thead', 'center');
179
180 // -------------------------------------------------------------------
181 // built-in fields
182 construct_datastore_select('severity', 'severity', 'severityid', $action['fields']['builtin']['severity'], true, true);
183 $admin->row_list($lang->string('Severity'), 'fields[severity]');
184
185 construct_datastore_select('priority', 'priority', 'priorityid', $action['fields']['builtin']['priority'], true, true);
186 $admin->row_list($lang->string('Priority'), 'fields[priority]');
187
188 construct_datastore_select('status', 'status', 'statusid', $action['fields']['builtin']['status'], true, true);
189 $admin->row_list($lang->string('Status'), 'fields[status]');
190
191 construct_datastore_select('resolution', 'resolution', 'resolutionid', $action['fields']['builtin']['resolution'], true, true);
192 $admin->row_list($lang->string('Resolution'), 'fields[resolution]');
193
194 $admin->row_span('', 'tcat', 'center');
195
196 // -------------------------------------------------------------------
197 // custom fields
198 $fields_fetch = $bugsys->db->query("
199 SELECT bugfield.*
200 FROM " . TABLE_PREFIX . "bugfield AS bugfield
201 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
202 ON (bugfield.fieldid = permission.fieldid)
203 WHERE permission.mask <> 0
204 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
205 AND bugfield.cansearch = 1"
206 );
207 while ($field = $bugsys->db->fetch_array($fields_fetch))
208 {
209 switch ($field['type'])
210 {
211 case 'input_text':
212 $admin->row_input($field['name'], "fields[custom][$field[fieldid]]", $action['fields']['custom']["$field[fieldid]"]);
213 break;
214
215 case 'input_checkbox':
216 $admin->list_item('', 0, ((!$action['fields']['custom']["$field[fieldid]"]) ? true : false));
217 $admin->list_item($lang->string('Checked'), 1, (($action['fields']['custom']["$field[fieldid]"] == 1) ? true : false));
218 $admin->list_item($lang->string('Un-Checked'), 2, (($action['fields']['custom']["$field[fieldid]"] == 2) ? true : false));
219 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
220 break;
221
222 case 'select_single':
223 $selectopts = unserialize($field['selects']);
224
225 $admin->list_item('', -1, ((!$action['fields']['custom']["$field[fieldid]"]) ? true : false));
226
227 foreach ($selectopts AS $id => $select)
228 {
229 $admin->list_item(stripslashes($select), $id, (($action['fields']['custom']["$field[fieldid]"] == $id AND $edit) ? true : false));
230 }
231 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
232 break;
233 }
234 }
235 unset($select);
236
237 $admin->row_submit();
238 $admin->table_end();
239 $admin->form_end();
240
241 $admin->page_end();
242 }
243
244 // ###################################################################
245
246 if ($_REQUEST['do'] == 'modify')
247 {
248 NavLinks::autoactionsAdd();
249 $navigator->set_focus('link', 'fields-pages-autoactions', 'fields-pages');
250
251 $admin->page_start($lang->string('Automatic Actions'));
252
253 $admin->table_start();
254 $admin->table_head($lang->string('Automatic Actions'), 2, 'automatic_actions');
255
256 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
257 while ($action = $db->fetch_array($actions))
258 {
259 $admin->row_text($action['name'] . "\n<div class=\"smallfont\">$action[description]</div>", "<a href=\"autoaction.php?do=edit&amp;actionid=$action[actionid]\">[" . $lang->string('Edit') . "]</a> <a href=\"autoaction.php?do=delete&amp;actionid=$action[actionid]\">[" . $lang->string('Delete') . "]</a>");
260 }
261
262 $admin->table_end();
263
264 $admin->page_end();
265 }
266
267 /*=====================================================================*\
268 || ###################################################################
269 || # $HeadURL$
270 || # $Id$
271 || ###################################################################
272 \*=====================================================================*/
273 ?>