r270: - Initial SVN for autoaction.php
[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 // run code to remove item in database
32 }
33
34 // ###################################################################
35
36 if ($_REQUEST['do'] == 'delete')
37 {
38 // display delete confirmation message
39 }
40
41 // ###################################################################
42
43 if ($_POST['do'] == 'insert')
44 {
45 if (empty($bugsys->in['name']))
46 {
47 $admin->error('You need to specify a name for this action.');
48 }
49
50 foreach ($bugsys->in['fields'] AS $key => $value)
51 {
52 if (!empty($value) AND $value != -1 AND !is_array($value))
53 {
54 $deltas['builtin']["$key"] = $value;
55 }
56 }
57
58 foreach ($bugsys->in['fields']['custom'] AS $key => $value)
59 {
60 if (!empty($value) AND $value != -1)
61 {
62 $deltas['custom']["$key"] = $value;
63 }
64 }
65
66 if (count($deltas['custom']) < 1 AND count($deltas['builtin']) < 1)
67 {
68 $admin->error('You need to specify some fields to change.');
69 }
70
71 $db->query("
72 INSERT INTO " . TABLE_PREFIX . "autoaction
73 (name, description, fieldchanges)
74 VALUES
75 ('" . $bugsys->in['name'] . "', '" . $bugsys->in['description'] . "',
76 '" . $bugsys->escape(serialize($deltas)) . "'
77 )"
78 );
79
80 $admin->redirect('autoaction.php', 'Action added.');
81 }
82
83 // ###################################################################
84
85 if ($_POST['do'] == 'update')
86 {
87 // run code to update item in database
88 }
89
90 // ###################################################################
91
92 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
93 {
94 $add = (($_REQUEST['do'] == 'add') ? true : false);
95 $edit = (($add) ? false : true);
96
97 if ($edit)
98 {
99 $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['actionid']));
100 if (!$action)
101 {
102 $admin->error(lang::p('error_invalid_id'));
103 }
104 $action['fields'] = unserialize($action['fieldchanges']);
105 }
106
107 $admin->page_start((($add) ? 'New Automatic Action' : 'Edit Auto Action'));
108
109 $admin->form_start('autoaction.php', (($add) ? 'insert' : 'update'));
110 $admin->table_start();
111 $admin->table_head((($add) ? 'New Automatic Action' : 'Edit Auto Action'));
112
113 $admin->row_input('Name', 'name', $action['name']);
114 $admin->row_textarea('Description', 'description', $action['description']);
115
116 $admin->row_span('Field Changes', 'thead', 'center');
117
118 // -------------------------------------------------------------------
119 // built-in fields
120 construct_datastore_select('severity', 'severity', 'severityid', $action['fields']['builtin']['severity'], true, true);
121 $admin->row_list('Severity', 'fields[severity]');
122
123 construct_datastore_select('priority', 'priority', 'priorityid', $action['fields']['builtin']['priority'], true, true);
124 $admin->row_list('Priority', 'fields[priority]');
125
126 construct_datastore_select('status', 'status', 'statusid', $action['fields']['builtin']['status'], true, true);
127 $admin->row_list('Status', 'fields[status]');
128
129 construct_datastore_select('resolution', 'resolution', 'resolutionid', $action['fields']['builtin']['resolution'], true, true);
130 $admin->row_list('Resolution', 'fields[resolution]');
131
132 /*$select['dev'] = '<option value="0" selected="selected"></option>';
133 foreach ($bugsys->datastore['assignto'] AS $dev)
134 {
135 $value = $dev['userid'];
136 $label = construct_user_display($dev, false);
137 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
138 }*/
139
140 $admin->row_span('', 'tcat', 'center');
141
142 // -------------------------------------------------------------------
143 // custom fields
144 $fields_fetch = $bugsys->db->query("
145 SELECT bugfield.*
146 FROM " . TABLE_PREFIX . "bugfield AS bugfield
147 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
148 ON (bugfield.fieldid = permission.fieldid)
149 WHERE permission.mask <> 0
150 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}
151 AND bugfield.cansearch = 1"
152 );
153 while ($field = $bugsys->db->fetch_array($fields_fetch))
154 {
155 switch ($field['type'])
156 {
157 case 'input_text':
158 $admin->row_input($field['name'], "fields[custom][$field[fieldid]]", $action['fields']['custom']["$field[fieldid]"]);
159 break;
160
161 case 'input_checkbox':
162 $admin->list_item('', 0, ((!$action['fields']['custom']["$field[fieldid]"]) ? true : false));
163 $admin->list_item('Checked', 1, (($action['fields']['custom']["$field[fieldid]"] == 1) ? true : false));
164 $admin->list_item('Un-Checked', 2, (($action['fields']['custom']["$field[fieldid]"] == 2) ? true : false));
165 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
166 break;
167
168 case 'select_single':
169 $selectopts = unserialize($field['selects']);
170
171 $admin->list_item('', -1, ((!$action['fields']['custom']["$field[fieldid]"]) ? true : false));
172
173 foreach ($selectopts AS $id => $select)
174 {
175 $admin->list_item(stripslashes($select), $id, (($action['fields']['custom']["$field[fieldid]"] == $id) ? true : false));
176 }
177 $admin->row_list($field['name'], "fields[custom][$field[fieldid]]");
178 break;
179 }
180 }
181 unset($select);
182
183 $admin->row_submit();
184 $admin->table_end();
185 $admin->form_end();
186
187 $admin->page_end();
188 }
189
190 // ###################################################################
191
192 if ($_REQUEST['do'] == 'modify')
193 {
194 $admin->page_start('Automatic Actions');
195
196 $admin->table_start();
197 $admin->table_head('Automatic Actions');
198
199 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
200 while ($action = $db->fetch_array($actions))
201 {
202 $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>");
203 }
204
205 $admin->row_span('<a href="autoaction.php?do=add">[Add New Action]</a>', 'tfoot', 'center', 3);
206 $admin->table_end();
207
208 $admin->page_end();
209 }
210
211 /*=====================================================================*\
212 || ###################################################################
213 || # $HeadURL$
214 || # $Id$
215 || ###################################################################
216 \*=====================================================================*/
217 ?>