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