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