set_focus('tab', 'fields', null); if (!can_perform('canadminbugs')) { admin_login(); } // ################################################################### if (empty($_REQUEST['do'])) { $_REQUEST['do'] = 'modify'; } // ################################################################### if ($_REQUEST['do'] == 'kill') { $action = new AutomationAPI($bugsys); $action->set('actionid', $bugsys->in['actionid']); $action->set_condition(); $action->delete(); $admin->redirect('automation.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { $admin->page_confirm(_('Are you sure you want to delete this automation?'), 'automation.php', 'kill', array('actionid' => $bugsys->in['actionid'])); } // ################################################################### if ($_POST['do'] == 'insert' OR $_POST['do'] == 'update') { $deltas = array('builtin' => array(), 'custom' => array()); if (is_array($bugsys->in['fields'])) { foreach ($bugsys->in['fields'] AS $key => $value) { if (!empty($value) AND $value != -1 AND !is_array($value)) { $deltas['builtin']["$key"] = $value; } } } if (is_array($bugsys->in['fields']['custom'])) { foreach ($bugsys->in['fields']['custom'] AS $key => $value) { if (!empty($value) AND $value != -1) { $deltas['custom']["$key"] = $value; } } } $action = new AutomationAPI($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('automation.php'); } else { $action->set('actionid', $bugsys->in['actionid']); $action->set_condition(); $action->update(); $admin->redirect('automation.php'); } } // ################################################################### if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') { $add = (($_REQUEST['do'] == 'add') ? true : false); $edit = (($add) ? false : true); if ($edit) { NavLinks::automationsEdit($bugsys->in['actionid']); $navigator->set_focus('link', 'fields-pages-automations', 'fields-pages'); $action = new AutomationAPI($bugsys); $action->set('actionid', $bugsys->in['actionid']); $action->set_condition(); $action->fetch(); $action->objdata['fields'] = unserialize($action->objdata['fieldchanges']); } else { NavLinks::automationsAdd(); $navigator->set_focus('link', 'automations-add', 'automations'); } $admin->page_start(($add ? _('New Automation') : _('Edit Automation'))); $admin->form_start('automation.php', ($add ? 'insert' : 'update')); if ($edit) { $admin->form_hidden_field('actionid', $action->objdata['actionid']); } $admin->table_start(); $admin->table_head(($add ? _('New Automation') : _('Edit Automation'))); $admin->row_input(_('Name'), 'name', $action->objdata['name']); $admin->row_textarea(_('Description'), 'description', $action->objdata['description']); $admin->row_textarea(_('Add Comment'), 'comment', $action->objdata['comment']); $admin->row_span(_('Field Changes'), 'thead', 'center'); // ------------------------------------------------------------------- // built-in fields construct_datastore_select('severity', 'severity', 'severityid', $action->objdata['fields']['builtin']['severity'], true, true); $admin->row_list(_('Severity'), 'fields[severity]'); construct_datastore_select('priority', 'priority', 'priorityid', $action->objdata['fields']['builtin']['priority'], true, true); $admin->row_list(_('Priority'), 'fields[priority]'); construct_datastore_select('status', 'status', 'statusid', $action->objdata['fields']['builtin']['status'], true, true); $admin->row_list(_('Status'), 'fields[status]'); construct_datastore_select('resolution', 'resolution', 'resolutionid', $action->objdata['fields']['builtin']['resolution'], true, true); $admin->row_list(_('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(_('Checked'), 1, (($action->objdata['fields']['custom']["$field[fieldid]"] == 1) ? true : false)); $admin->list_item(_('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::automationsAdd(); $navigator->set_focus('link', 'fields-pages-automations', 'fields-pages'); $admin->page_start(_('Automations')); $admin->table_start(); $admin->table_head(_('Automations')); $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC"); while ($action = $db->fetch_array($actions)) { $admin->row_text($action['name'] . "\n