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