]> src.bluestatic.org Git - bugdar.git/blob - admin/automation.php
r1522: Adding a PHP4 constructor to the Authentication class
[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 ($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');
117 $edit = !$add;
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 = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid ASC");
173 while ($field = $db->fetch_array($fields_fetch))
174 {
175 switch ($field['type'])
176 {
177 case 'input_text':
178 $admin->row_input($field['name'], "fields[custom][$field[fieldid]]", $action->objdata['fields']['custom']["$field[fieldid]"]);
179 break;
180
181 case 'input_checkbox':
182 $admin->list_item('', -1, (!$action->objdata['fields']['custom']["$field[fieldid]"] OR $action->objdata['fields']['custom']["$field[fieldid]"] == -1));
183 $admin->list_item(_('Checked'), 1, ($action->objdata['fields']['custom']["$field[fieldid]"] == 1));
184 $admin->list_item(_('Un-Checked'), 0, (isset($action->objdata['fields']['custom']["$field[fieldid]"]) AND $action->objdata['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->objdata['fields']['custom']["$field[fieldid]"]) OR $action->objdata['fields']['custom']["$field[fieldid]"] == -1));
192
193 foreach ($selectopts AS $id => $select)
194 {
195 $admin->list_item(stripslashes($select), $id, (isset($action->objdata['fields']['custom']["$field[fieldid]"]) AND $action->objdata['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(_('Automations'));
218
219 $admin->table_start();
220 $admin->table_head(_('Automations'));
221
222 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC");
223 while ($action = $db->fetch_array($actions))
224 {
225 $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>");
226 }
227
228 $admin->table_end();
229
230 $admin->page_end();
231 }
232
233 /*=====================================================================*\
234 || ###################################################################
235 || # $HeadURL$
236 || # $Id$
237 || ###################################################################
238 \*=====================================================================*/
239 ?>