]> src.bluestatic.org Git - bugdar.git/blob - admin/automation.php
r1384: It was actually bug 66...
[bugdar.git] / admin / automation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]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/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($bugsys);
48 $action->set('actionid', $bugsys->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(_('Are you sure you want to delete this automation?'), 'automation.php', 'kill', array('actionid' => $bugsys->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($bugsys->in['fields']))
69 {
70 foreach ($bugsys->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($bugsys->in['fields']['custom']))
80 {
81 foreach ($bugsys->in['fields']['custom'] AS $key => $value)
82 {
83 if (!empty($value) AND $value != -1)
84 {
85 $deltas['custom']["$key"] = $value;
86 }
87 }
88 }
89
90 $action = new AutomationAPI($bugsys);
91 $action->set('name', $bugsys->in['name']);
92 $action->set('description', $bugsys->in['description']);
93 $action->set('fieldchanges', $deltas);
94 $action->set('comment', $bugsys->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', $bugsys->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') ? true : false);
117 $edit = (($add) ? false : true);
118
119 if ($edit)
120 {
121 NavLinks::automationsEdit($bugsys->in['actionid']);
122 $navigator->set_focus('link', 'fields-pages-automations', 'fields-pages');
123
124 $action = new AutomationAPI($bugsys);
125 $action->set('actionid', $bugsys->in['actionid']);
126 $action->set_condition();
127 $action->fetch();
128 $action->objdata['fields'] = unserialize($action->objdata['fieldchanges']);
129 }
130 else
131 {
132 NavLinks::automationsAdd();
133 $navigator->set_focus('link', 'automations-add', 'automations');
134 }
135
136 $admin->page_start(($add ? _('New Automation') : _('Edit Automation')));
137
138 $admin->form_start('automation.php', ($add ? 'insert' : 'update'));
139
140 if ($edit)
141 {
142 $admin->form_hidden_field('actionid', $action->objdata['actionid']);
143 }
144
145 $admin->table_start();
146 $admin->table_head(($add ? _('New Automation') : _('Edit Automation')));
147
148 $admin->row_input(_('Name'), 'name', $action->objdata['name']);
149 $admin->row_textarea(_('Description'), 'description', $action->objdata['description']);
150 $admin->row_textarea(_('Add Comment'), 'comment', $action->objdata['comment']);
151
152 $admin->row_span(_('Field Changes'), 'thead', 'center');
153
154 // -------------------------------------------------------------------
155 // built-in fields
156 construct_datastore_select('severity', 'severity', 'severityid', $action->objdata['fields']['builtin']['severity'], true, true);
157 $admin->row_list(_('Severity'), 'fields[severity]');
158
159 construct_datastore_select('priority', 'priority', 'priorityid', $action->objdata['fields']['builtin']['priority'], true, true);
160 $admin->row_list(_('Priority'), 'fields[priority]');
161
162 construct_datastore_select('status', 'status', 'statusid', $action->objdata['fields']['builtin']['status'], true, true);
163 $admin->row_list(_('Status'), 'fields[status]');
164
165 construct_datastore_select('resolution', 'resolution', 'resolutionid', $action->objdata['fields']['builtin']['resolution'], true, true);
166 $admin->row_list(_('Resolution'), 'fields[resolution]');
167
168 $admin->row_span('', 'tcat', 'center');
169
170 // -------------------------------------------------------------------
171 // custom fields
172 $fields_fetch = $bugsys->db->query("
173 SELECT bugfield.*
174 FROM " . TABLE_PREFIX . "bugfield AS bugfield
175 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
176 ON (bugfield.fieldid = permission.fieldid)
177 WHERE permission.mask <> 0
178 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
179 AND bugfield.cansearch = 1"
180 );
181 while ($field = $bugsys->db->fetch_array($fields_fetch))
182 {
183 switch ($field['type'])
184 {
185 case 'input_text':
186 $admin->row_input($field['name'], "fields[custom][$field[fieldid]]", $action->objdata['fields']['custom']["$field[fieldid]"]);
187 break;
188
189 case 'input_checkbox':
190 $admin->list_item('', 0, ((!$action->objdata['fields']['custom']["$field[fieldid]"]) ? true : false));
191 $admin->list_item(_('Checked'), 1, (($action->objdata['fields']['custom']["$field[fieldid]"] == 1) ? true : false));
192 $admin->list_item(_('Un-Checked'), 2, (($action->objdata['fields']['custom']["$field[fieldid]"] == 2) ? true : false));
193 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
194 break;
195
196 case 'select_single':
197 $selectopts = unserialize($field['selects']);
198
199 $admin->list_item('', -1, ((!$action->objdata['fields']['custom']["$field[fieldid]"]) ? true : false));
200
201 foreach ($selectopts AS $id => $select)
202 {
203 $admin->list_item(stripslashes($select), $id, (($action->objdata['fields']['custom']["$field[fieldid]"] == $id AND $edit) ? true : false));
204 }
205 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
206 break;
207 }
208 }
209 unset($select);
210
211 $admin->row_submit();
212 $admin->table_end();
213 $admin->form_end();
214
215 $admin->page_end();
216 }
217
218 // ###################################################################
219
220 if ($_REQUEST['do'] == 'modify')
221 {
222 NavLinks::automationsAdd();
223 $navigator->set_focus('link', 'fields-pages-automations', 'fields-pages');
224
225 $admin->page_start(_('Automations'));
226
227 $admin->table_start();
228 $admin->table_head(_('Automations'));
229
230 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC");
231 while ($action = $db->fetch_array($actions))
232 {
233 $admin->row_text($action['name'] . "\n<div class=\"smallfont\">$action[description]</div>", "<a href=\"automation.php?do=edit&amp;actionid=$action[actionid]\">[" . _('Edit') . "]</a> <a href=\"automation.php?do=delete&amp;actionid=$action[actionid]\">[" . _('Delete') . "]</a>");
234 }
235
236 $admin->table_end();
237
238 $admin->page_end();
239 }
240
241 /*=====================================================================*\
242 || ###################################################################
243 || # $HeadURL$
244 || # $Id$
245 || ###################################################################
246 \*=====================================================================*/
247 ?>