Remove includes/class_api_error.php and all of the places we require() it
[bugdar.git] / admin / automation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 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 2 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_automation.php');
24
25 APIError(array(new API_Error_Handler($admin), 'admin_error'));
26
27 NavLinks::fieldsPages();
28 $navigator->set_focus('tab', 'fields', null);
29
30 if (!can_perform('canadminbugs'))
31 {
32 admin_login();
33 }
34
35 // ###################################################################
36
37 if (empty($_REQUEST['do']))
38 {
39 $_REQUEST['do'] = 'modify';
40 }
41
42 // ###################################################################
43
44 if ($_REQUEST['do'] == 'kill')
45 {
46 $action = new AutomationAPI();
47 $action->set('actionid', $input->in['actionid']);
48 $action->set_condition();
49 $action->delete();
50
51 $admin->redirect('automation.php?do=modify');
52 }
53
54 // ###################################################################
55
56 if ($_REQUEST['do'] == 'delete')
57 {
58 $admin->page_confirm(T('Are you sure you want to delete this automation?'), 'automation.php', 'kill', array('actionid' => $input->in['actionid']));
59 }
60
61 // ###################################################################
62
63 if ($_POST['do'] == 'insert' OR $_POST['do'] == 'update')
64 {
65 $deltas = array('builtin' => array(), 'custom' => array());
66
67 if (is_array($input->in['fields']))
68 {
69 foreach ($input->in['fields'] AS $key => $value)
70 {
71 if (!empty($value) AND $value != -1 AND !is_array($value))
72 {
73 $deltas['builtin']["$key"] = $value;
74 }
75 }
76 }
77
78 if (is_array($input->in['fields']['custom']))
79 {
80 foreach ($input->in['fields']['custom'] AS $key => $value)
81 {
82 if ($value != '' AND $value != -1)
83 {
84 $deltas['custom']["$key"] = $value;
85 }
86 }
87 }
88
89 $action = new AutomationAPI();
90 $action->set('name', $input->in['name']);
91 $action->set('description', $input->in['description']);
92 $action->set('fieldchanges', $deltas);
93 $action->set('comment', $input->in['comment']);
94
95 if ($_POST['do'] == 'insert')
96 {
97 $action->insert();
98
99 $admin->redirect('automation.php');
100 }
101 else
102 {
103 $action->set('actionid', $input->in['actionid']);
104 $action->set_condition();
105 $action->update();
106
107 $admin->redirect('automation.php');
108 }
109 }
110
111 // ###################################################################
112
113 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
114 {
115 $add = ($_REQUEST['do'] == 'add');
116 $edit = !$add;
117
118 if ($edit)
119 {
120 NavLinks::automationsEdit($input->in['actionid']);
121 $navigator->set_focus('link', 'fields-pages-automations', 'fields-pages');
122
123 $action = new AutomationAPI();
124 $action->set('actionid', $input->in['actionid']);
125 $action->set_condition();
126 $action->fetch();
127 $action->record['fields'] = unserialize($action->record['fieldchanges']);
128 }
129 else
130 {
131 NavLinks::automationsAdd();
132 $navigator->set_focus('link', 'automations-add', 'automations');
133 }
134
135 $admin->page_start(($add ? T('New Automation') : T('Edit Automation')));
136
137 $admin->form_start('automation.php', ($add ? 'insert' : 'update'));
138
139 if ($edit)
140 {
141 $admin->form_hidden_field('actionid', $action->record['actionid']);
142 }
143
144 $admin->table_start();
145 $admin->table_head(($add ? T('New Automation') : T('Edit Automation')));
146
147 $admin->row_input(T('Name'), 'name', $action->record['name']);
148 $admin->row_textarea(T('Description'), 'description', $action->record['description']);
149 $admin->row_textarea(T('Add Comment'), 'comment', $action->record['comment']);
150
151 $admin->row_span(T('Field Changes'), 'thead', 'center');
152
153 // -------------------------------------------------------------------
154 // built-in fields
155 construct_datastore_select('severity', 'severity', 'severityid', $action->record['fields']['builtin']['severity'], true, true);
156 $admin->row_list(T('Severity'), 'fields[severity]');
157
158 construct_datastore_select('priority', 'priority', 'priorityid', $action->record['fields']['builtin']['priority'], true, true);
159 $admin->row_list(T('Priority'), 'fields[priority]');
160
161 construct_datastore_select('status', 'status', 'statusid', $action->record['fields']['builtin']['status'], true, true);
162 $admin->row_list(T('Status'), 'fields[status]');
163
164 construct_datastore_select('resolution', 'resolution', 'resolutionid', $action->record['fields']['builtin']['resolution'], true, true);
165 $admin->row_list(T('Resolution'), 'fields[resolution]');
166
167 $admin->row_span('', 'tcat', 'center');
168
169 // -------------------------------------------------------------------
170 // custom fields
171 $fields_fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid ASC");
172 foreach ($fields_fetch as $field)
173 {
174 switch ($field['type'])
175 {
176 case 'input_text':
177 $admin->row_input($field['name'], "fields[custom][$field[fieldid]]", $action->record['fields']['custom']["$field[fieldid]"]);
178 break;
179
180 case 'input_checkbox':
181 $admin->list_item('', -1, (!$action->record['fields']['custom']["$field[fieldid]"] OR $action->record['fields']['custom']["$field[fieldid]"] == -1));
182 $admin->list_item(T('Checked'), 1, ($action->record['fields']['custom']["$field[fieldid]"] == 1));
183 $admin->list_item(T('Un-Checked'), 0, (isset($action->record['fields']['custom']["$field[fieldid]"]) AND $action->record['fields']['custom']["$field[fieldid]"] == 0));
184 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
185 break;
186
187 case 'select_single':
188 $selectopts = unserialize($field['selects']);
189
190 $admin->list_item('', -1, (!isset($action->record['fields']['custom']["$field[fieldid]"]) OR $action->record['fields']['custom']["$field[fieldid]"] == -1));
191
192 foreach ($selectopts AS $id => $select)
193 {
194 $admin->list_item(stripslashes($select), $id, (isset($action->record['fields']['custom']["$field[fieldid]"]) AND $action->record['fields']['custom']["$field[fieldid]"] == $id));
195 }
196 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
197 break;
198 }
199 }
200 unset($select);
201
202 $admin->row_submit();
203 $admin->table_end();
204 $admin->form_end();
205
206 $admin->page_end();
207 }
208
209 // ###################################################################
210
211 if ($_REQUEST['do'] == 'modify')
212 {
213 NavLinks::automationsAdd();
214 $navigator->set_focus('link', 'fields-pages-automations', 'fields-pages');
215
216 $admin->page_start(T('Automations'));
217
218 $admin->table_start();
219 $admin->table_head(T('Automations'));
220
221 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC");
222 foreach ($actions as $action)
223 {
224 $admin->row_text($action['name'] . "\n<div class=\"smallfont\">$action[description]</div>", "<a href=\"automation.php?do=edit&amp;actionid=$action[actionid]\">[" . T('Edit') . "]</a> <a href=\"automation.php?do=delete&amp;actionid=$action[actionid]\">[" . T('Delete') . "]</a>");
225 }
226
227 $admin->table_end();
228
229 $admin->page_end();
230 }
231
232 /*=====================================================================*\
233 || ###################################################################
234 || # $HeadURL$
235 || # $Id$
236 || ###################################################################
237 \*=====================================================================*/
238 ?>