r665: Renaming product from "BugStrike" to "Bugdar"
[bugdar.git] / admin / autoaction.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 require_once('./global.php');
14 require_once('./includes/functions_datastore.php');
15
16 if (!can_perform('canadminbugs'))
17 {
18 admin_login();
19 }
20
21 // ###################################################################
22
23 if (empty($_REQUEST['do']))
24 {
25 $_REQUEST['do'] = 'modify';
26 }
27
28 // ###################################################################
29
30 if ($_REQUEST['do'] == 'kill')
31 {
32 $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['actionid']));
33 if (!$action)
34 {
35 $admin->error($lang->getlex('error_invalid_id'));
36 }
37
38 $db->query("DELETE FROM " . TABLE_PREFIX . "autoaction WHERE actionid = $action[actionid]");
39
40 build_auto_actions();
41
42 $admin->redirect('autoaction.php?do=modify');
43 }
44
45 // ###################################################################
46
47 if ($_REQUEST['do'] == 'delete')
48 {
49 $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['actionid']));
50 if (!$action)
51 {
52 $admin->error($lang->getlex('error_invalid_id'));
53 }
54
55 $admin->page_confirm($lang->string('Are you sure you want to delete this action?'), "autoaction.php?do=kill&amp;actionid=$action[actionid]");
56 }
57
58 // ###################################################################
59
60 if ($_POST['do'] == 'insert' OR $_POST['do'] == 'update')
61 {
62 if (empty($bugsys->in['name']))
63 {
64 $admin->error($lang->string('You need to specify a name for this action.'));
65 }
66
67 foreach ($bugsys->in['fields'] AS $key => $value)
68 {
69 if (!empty($value) AND $value != -1 AND !is_array($value))
70 {
71 $deltas['builtin']["$key"] = $value;
72 }
73 }
74
75 foreach ($bugsys->in['fields']['custom'] AS $key => $value)
76 {
77 if (!empty($value) AND $value != -1)
78 {
79 $deltas['custom']["$key"] = $value;
80 }
81 }
82
83 if (count($deltas['custom']) < 1 AND count($deltas['builtin']) < 1)
84 {
85 $admin->error($lang->string('You need to specify some fields to change.'));
86 }
87
88 if ($_POST['do'] == 'insert')
89 {
90 $db->query("
91 INSERT INTO " . TABLE_PREFIX . "autoaction
92 (name, description, fieldchanges, comment)
93 VALUES
94 ('" . $bugsys->in['name'] . "', '" . $bugsys->in['description'] . "',
95 '" . $bugsys->escape(serialize($deltas)) . "', '" . $bugsys->in['comment'] . "'
96 )"
97 );
98
99 build_auto_actions();
100
101 $admin->redirect('autoaction.php');
102 }
103 else
104 {
105 if (!$bugsys->in['actionid'])
106 {
107 $admin->error($lang->getlex('error_invalid_id'));
108 }
109
110 $db->query("
111 UPDATE " . TABLE_PREFIX . "autoaction
112 SET name = '" . $bugsys->in['name'] . "',
113 description = '" . $bugsys->in['description'] . "',
114 fieldchanges = '" . $bugsys->escape(serialize($deltas)) . "',
115 comment = '" . $bugsys->in['comment'] . "'
116 WHERE actionid = " . intval($bugsys->in['actionid'])
117 );
118
119 build_auto_actions();
120
121 $admin->redirect('autoaction.php');
122 }
123 }
124
125 // ###################################################################
126
127 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
128 {
129 $add = (($_REQUEST['do'] == 'add') ? true : false);
130 $edit = (($add) ? false : true);
131
132 if ($edit)
133 {
134 $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['actionid']));
135 if (!$action)
136 {
137 $admin->error($lang->getlex('error_invalid_id'));
138 }
139 $action['fields'] = unserialize($action['fieldchanges']);
140 }
141
142 $admin->page_start(($add ? $lang->string('New Automatic Action') : $lang->string('Edit Automatic Action')));
143
144 $admin->form_start('autoaction.php', ($add ? 'insert' : 'update'));
145
146 if ($edit)
147 {
148 $admin->form_hidden_field('actionid', $action['actionid']);
149 }
150
151 $admin->table_start();
152 $admin->table_head(($add ? $lang->string('New Automatic Action') : $lang->string('Edit Automatic Action')), 2, 'automatic_actions');
153
154 $admin->row_input($lang->string('Name'), 'name', $action['name']);
155 $admin->row_textarea($lang->string('Description'), 'description', $action['description']);
156 $admin->row_textarea($lang->string('Add Comment'), 'comment', $action['comment']);
157
158 $admin->row_span($lang->string('Field Changes'), 'thead', 'center');
159
160 // -------------------------------------------------------------------
161 // built-in fields
162 construct_datastore_select('severity', 'severity', 'severityid', $action['fields']['builtin']['severity'], true, true);
163 $admin->row_list($lang->string('Severity'), 'fields[severity]');
164
165 construct_datastore_select('priority', 'priority', 'priorityid', $action['fields']['builtin']['priority'], true, true);
166 $admin->row_list($lang->string('Priority'), 'fields[priority]');
167
168 construct_datastore_select('status', 'status', 'statusid', $action['fields']['builtin']['status'], true, true);
169 $admin->row_list($lang->string('Status'), 'fields[status]');
170
171 construct_datastore_select('resolution', 'resolution', 'resolutionid', $action['fields']['builtin']['resolution'], true, true);
172 $admin->row_list($lang->string('Resolution'), 'fields[resolution]');
173
174 $admin->row_span('', 'tcat', 'center');
175
176 // -------------------------------------------------------------------
177 // custom fields
178 $fields_fetch = $bugsys->db->query("
179 SELECT bugfield.*
180 FROM " . TABLE_PREFIX . "bugfield AS bugfield
181 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
182 ON (bugfield.fieldid = permission.fieldid)
183 WHERE permission.mask <> 0
184 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
185 AND bugfield.cansearch = 1"
186 );
187 while ($field = $bugsys->db->fetch_array($fields_fetch))
188 {
189 switch ($field['type'])
190 {
191 case 'input_text':
192 $admin->row_input($field['name'], "fields[custom][$field[fieldid]]", $action['fields']['custom']["$field[fieldid]"]);
193 break;
194
195 case 'input_checkbox':
196 $admin->list_item('', 0, ((!$action['fields']['custom']["$field[fieldid]"]) ? true : false));
197 $admin->list_item($lang->string('Checked'), 1, (($action['fields']['custom']["$field[fieldid]"] == 1) ? true : false));
198 $admin->list_item($lang->string('Un-Checked'), 2, (($action['fields']['custom']["$field[fieldid]"] == 2) ? true : false));
199 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
200 break;
201
202 case 'select_single':
203 $selectopts = unserialize($field['selects']);
204
205 $admin->list_item('', -1, ((!$action['fields']['custom']["$field[fieldid]"]) ? true : false));
206
207 foreach ($selectopts AS $id => $select)
208 {
209 $admin->list_item(stripslashes($select), $id, (($action['fields']['custom']["$field[fieldid]"] == $id AND $edit) ? true : false));
210 }
211 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
212 break;
213 }
214 }
215 unset($select);
216
217 $admin->row_submit();
218 $admin->table_end();
219 $admin->form_end();
220
221 $admin->page_end();
222 }
223
224 // ###################################################################
225
226 if ($_REQUEST['do'] == 'modify')
227 {
228 $admin->page_start($lang->string('Automatic Actions'));
229
230 $admin->table_start();
231 $admin->table_head($lang->string('Automatic Actions'), 2, 'automatic_actions');
232
233 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
234 while ($action = $db->fetch_array($actions))
235 {
236 $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>");
237 }
238
239 $admin->row_span('<a href="autoaction.php?do=add">[' . $lang->string('New Automatic Action') . ']</a>', 'tfoot', 'center', 3);
240 $admin->table_end();
241
242 $admin->page_end();
243 }
244
245 /*=====================================================================*\
246 || ###################################################################
247 || # $HeadURL$
248 || # $Id$
249 || ###################################################################
250 \*=====================================================================*/
251 ?>