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