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