r1048: Converting all $lang->string() stuff to use the gettext call
[bugdar.git] / admin / autoaction.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_autoaction.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 AutoActionAPI($bugsys);
48 $action->set('actionid', $bugsys->in['actionid']);
49 $action->set_condition();
50 $action->delete();
51
52 $admin->redirect('autoaction.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 action?'), "autoaction.php?do=kill&amp;actionid=$action[actionid]");
60 }
61
62 // ###################################################################
63
64 if ($_POST['do'] == 'insert' OR $_POST['do'] == 'update')
65 {
66 foreach ($bugsys->in['fields'] AS $key => $value)
67 {
68 if (!empty($value) AND $value != -1 AND !is_array($value))
69 {
70 $deltas['builtin']["$key"] = $value;
71 }
72 }
73
74 foreach ($bugsys->in['fields']['custom'] AS $key => $value)
75 {
76 if (!empty($value) AND $value != -1)
77 {
78 $deltas['custom']["$key"] = $value;
79 }
80 }
81
82 $action = new AutoActionAPI($bugsys);
83 $action->set('name', $bugsys->in['name']);
84 $action->set('description', $bugsys->in['description']);
85 $action->set('fieldchanges', $deltas);
86 $action->set('comment', $bugsys->in['comment']);
87
88 if ($_POST['do'] == 'insert')
89 {
90 $action->insert();
91
92 $admin->redirect('autoaction.php');
93 }
94 else
95 {
96 $action->set('actionid', $bugsys->in['actionid']);
97 $action->set_condition();
98 $action->update();
99
100 $admin->redirect('autoaction.php');
101 }
102 }
103
104 // ###################################################################
105
106 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
107 {
108 $add = (($_REQUEST['do'] == 'add') ? true : false);
109 $edit = (($add) ? false : true);
110
111 if ($edit)
112 {
113 NavLinks::autoactionsEdit($bugsys->in['actionid']);
114 $navigator->set_focus('link', 'fields-pages-autoactions', 'fields-pages');
115
116 $action = new AutoActionAPI($bugsys);
117 $action->set('actionid', $bugsys->in['actionid']);
118 $action->set_condition();
119 $action->fetch();
120 $action->objdata['fields'] = unserialize($action->objdata['fieldchanges']);
121 }
122 else
123 {
124 NavLinks::autoactionsAdd();
125 $navigator->set_focus('link', 'autoactions-add', 'autoactions');
126 }
127
128 $admin->page_start(($add ? _('New Automatic Action') : _('Edit Automatic Action')));
129
130 $admin->form_start('autoaction.php', ($add ? 'insert' : 'update'));
131
132 if ($edit)
133 {
134 $admin->form_hidden_field('actionid', $action->objdata['actionid']);
135 }
136
137 $admin->table_start();
138 $admin->table_head(($add ? _('New Automatic Action') : _('Edit Automatic Action')));
139
140 $admin->row_input(_('Name'), 'name', $action->objdata['name']);
141 $admin->row_textarea(_('Description'), 'description', $action->objdata['description']);
142 $admin->row_textarea(_('Add Comment'), 'comment', $action->objdata['comment']);
143
144 $admin->row_span(_('Field Changes'), 'thead', 'center');
145
146 // -------------------------------------------------------------------
147 // built-in fields
148 construct_datastore_select('severity', 'severity', 'severityid', $action->objdata['fields']['builtin']['severity'], true, true);
149 $admin->row_list(_('Severity'), 'fields[severity]');
150
151 construct_datastore_select('priority', 'priority', 'priorityid', $action->objdata['fields']['builtin']['priority'], true, true);
152 $admin->row_list(_('Priority'), 'fields[priority]');
153
154 construct_datastore_select('status', 'status', 'statusid', $action->objdata['fields']['builtin']['status'], true, true);
155 $admin->row_list(_('Status'), 'fields[status]');
156
157 construct_datastore_select('resolution', 'resolution', 'resolutionid', $action->objdata['fields']['builtin']['resolution'], true, true);
158 $admin->row_list(_('Resolution'), 'fields[resolution]');
159
160 $admin->row_span('', 'tcat', 'center');
161
162 // -------------------------------------------------------------------
163 // custom fields
164 $fields_fetch = $bugsys->db->query("
165 SELECT bugfield.*
166 FROM " . TABLE_PREFIX . "bugfield AS bugfield
167 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
168 ON (bugfield.fieldid = permission.fieldid)
169 WHERE permission.mask <> 0
170 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
171 AND bugfield.cansearch = 1"
172 );
173 while ($field = $bugsys->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('', 0, ((!$action->objdata['fields']['custom']["$field[fieldid]"]) ? true : false));
183 $admin->list_item(_('Checked'), 1, (($action->objdata['fields']['custom']["$field[fieldid]"] == 1) ? true : false));
184 $admin->list_item(_('Un-Checked'), 2, (($action->objdata['fields']['custom']["$field[fieldid]"] == 2) ? true : false));
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, ((!$action->objdata['fields']['custom']["$field[fieldid]"]) ? true : false));
192
193 foreach ($selectopts AS $id => $select)
194 {
195 $admin->list_item(stripslashes($select), $id, (($action->objdata['fields']['custom']["$field[fieldid]"] == $id AND $edit) ? true : false));
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::autoactionsAdd();
215 $navigator->set_focus('link', 'fields-pages-autoactions', 'fields-pages');
216
217 $admin->page_start(_('Automatic Actions'));
218
219 $admin->table_start();
220 $admin->table_head(_('Automatic Actions'));
221
222 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction 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=\"autoaction.php?do=edit&amp;actionid=$action[actionid]\">[" . _('Edit') . "]</a> <a href=\"autoaction.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 ?>