set_focus('tab', 'fields', null); if (!can_perform('canadminbugs')) { admin_login(); } // ################################################################### if (empty($_REQUEST['do'])) { $_REQUEST['do'] = 'modify'; } // ################################################################### if ($_REQUEST['do'] == 'kill') { $action = new AutoActionAPI($bugsys); $action->set('actionid', $bugsys->in['actionid']); $action->set_condition(); $action->delete(); $admin->redirect('autoaction.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { $admin->page_confirm($lang->string('Are you sure you want to delete this action?'), "autoaction.php?do=kill&actionid=$action[actionid]"); } // ################################################################### if ($_POST['do'] == 'insert' OR $_POST['do'] == 'update') { foreach ($bugsys->in['fields'] AS $key => $value) { if (!empty($value) AND $value != -1 AND !is_array($value)) { $deltas['builtin']["$key"] = $value; } } foreach ($bugsys->in['fields']['custom'] AS $key => $value) { if (!empty($value) AND $value != -1) { $deltas['custom']["$key"] = $value; } } $action = new AutoActionAPI($bugsys); $action->set('name', $bugsys->in['name']); $action->set('description', $bugsys->in['description']); $action->set('fieldchanges', $deltas); $action->set('comment', $bugsys->in['comment']); if ($_POST['do'] == 'insert') { $action->insert(); $admin->redirect('autoaction.php'); } else { $action->set('actionid', $bugsys->in['actionid']); $action->set_condition(); $action->update(); $admin->redirect('autoaction.php'); } } // ################################################################### if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') { $add = (($_REQUEST['do'] == 'add') ? true : false); $edit = (($add) ? false : true); if ($edit) { NavLinks::autoactionsEdit($bugsys->in['actionid']); $navigator->set_focus('link', 'fields-pages-autoactions', 'fields-pages'); $action = new AutoActionAPI($bugsys); $action->set('actionid', $bugsys->in['actionid']); $action->set_condition(); $action->fetch(); $action->objdata['fields'] = unserialize($action->objdata['fieldchanges']); } else { NavLinks::autoactionsAdd(); $navigator->set_focus('link', 'autoactions-add', 'autoactions'); } $admin->page_start(($add ? $lang->string('New Automatic Action') : $lang->string('Edit Automatic Action'))); $admin->form_start('autoaction.php', ($add ? 'insert' : 'update')); if ($edit) { $admin->form_hidden_field('actionid', $action->objdata['actionid']); } $admin->table_start(); $admin->table_head(($add ? $lang->string('New Automatic Action') : $lang->string('Edit Automatic Action'))); $admin->row_input($lang->string('Name'), 'name', $action->objdata['name']); $admin->row_textarea($lang->string('Description'), 'description', $action->objdata['description']); $admin->row_textarea($lang->string('Add Comment'), 'comment', $action->objdata['comment']); $admin->row_span($lang->string('Field Changes'), 'thead', 'center'); // ------------------------------------------------------------------- // built-in fields construct_datastore_select('severity', 'severity', 'severityid', $action->objdata['fields']['builtin']['severity'], true, true); $admin->row_list($lang->string('Severity'), 'fields[severity]'); construct_datastore_select('priority', 'priority', 'priorityid', $action->objdata['fields']['builtin']['priority'], true, true); $admin->row_list($lang->string('Priority'), 'fields[priority]'); construct_datastore_select('status', 'status', 'statusid', $action->objdata['fields']['builtin']['status'], true, true); $admin->row_list($lang->string('Status'), 'fields[status]'); construct_datastore_select('resolution', 'resolution', 'resolutionid', $action->objdata['fields']['builtin']['resolution'], true, true); $admin->row_list($lang->string('Resolution'), 'fields[resolution]'); $admin->row_span('', 'tcat', 'center'); // ------------------------------------------------------------------- // custom fields $fields_fetch = $bugsys->db->query(" SELECT bugfield.* FROM " . TABLE_PREFIX . "bugfield AS bugfield LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission ON (bugfield.fieldid = permission.fieldid) WHERE permission.mask <> 0 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']} AND bugfield.cansearch = 1" ); while ($field = $bugsys->db->fetch_array($fields_fetch)) { switch ($field['type']) { case 'input_text': $admin->row_input($field['name'], "fields[custom][$field[fieldid]]", $action->objdata['fields']['custom']["$field[fieldid]"]); break; case 'input_checkbox': $admin->list_item('', 0, ((!$action->objdata['fields']['custom']["$field[fieldid]"]) ? true : false)); $admin->list_item($lang->string('Checked'), 1, (($action->objdata['fields']['custom']["$field[fieldid]"] == 1) ? true : false)); $admin->list_item($lang->string('Un-Checked'), 2, (($action->objdata['fields']['custom']["$field[fieldid]"] == 2) ? true : false)); $admin->row_list($field['name'], "fields[custom][$field[fieldid]]"); break; case 'select_single': $selectopts = unserialize($field['selects']); $admin->list_item('', -1, ((!$action->objdata['fields']['custom']["$field[fieldid]"]) ? true : false)); foreach ($selectopts AS $id => $select) { $admin->list_item(stripslashes($select), $id, (($action->objdata['fields']['custom']["$field[fieldid]"] == $id AND $edit) ? true : false)); } $admin->row_list($field['name'], "fields[custom][$field[fieldid]]"); break; } } unset($select); $admin->row_submit(); $admin->table_end(); $admin->form_end(); $admin->page_end(); } // ################################################################### if ($_REQUEST['do'] == 'modify') { NavLinks::autoactionsAdd(); $navigator->set_focus('link', 'fields-pages-autoactions', 'fields-pages'); $admin->page_start($lang->string('Automatic Actions')); $admin->table_start(); $admin->table_head($lang->string('Automatic Actions')); $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC"); while ($action = $db->fetch_array($actions)) { $admin->row_text($action['name'] . "\n