query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['actionid'])); if (!$action) { $admin->error($lang->getlex('error_invalid_id')); } $db->query("DELETE FROM " . TABLE_PREFIX . "autoaction WHERE actionid = $action[actionid]"); $admin->redirect('autoaction.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['actionid'])); if (!$action) { $admin->error($lang->getlex('error_invalid_id')); } $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') { if (empty($bugsys->in['name'])) { $admin->error($lang->string('You need to specify a name for this action.')); } 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; } } if (count($deltas['custom']) < 1 AND count($deltas['builtin']) < 1) { $admin->error($lang->string('You need to specify some fields to change.')); } if ($_POST['do'] == 'insert') { $db->query(" INSERT INTO " . TABLE_PREFIX . "autoaction (name, description, fieldchanges, comment) VALUES ('" . $bugsys->in['name'] . "', '" . $bugsys->in['description'] . "', '" . $bugsys->escape(serialize($deltas)) . "', '" . $bugsys->in['comment'] . "' )" ); $admin->redirect('autoaction.php'); } else { if (!$bugsys->in['actionid']) { $admin->error($lang->getlex('error_invalid_id')); } $db->query(" UPDATE " . TABLE_PREFIX . "autoaction SET name = '" . $bugsys->in['name'] . "', description = '" . $bugsys->in['description'] . "', fieldchanges = '" . $bugsys->escape(serialize($deltas)) . "', comment = '" . $bugsys->in['comment'] . "' WHERE actionid = " . intval($bugsys->in['actionid']) ); $admin->redirect('autoaction.php'); } } // ################################################################### if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') { $add = (($_REQUEST['do'] == 'add') ? true : false); $edit = (($add) ? false : true); if ($edit) { $action = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['actionid'])); if (!$action) { $admin->error($lang->getlex('error_invalid_id')); } $action['fields'] = unserialize($action['fieldchanges']); } $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['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['name']); $admin->row_textarea($lang->string('Description'), 'description', $action['description']); $admin->row_textarea($lang->string('Add Comment'), 'comment', $action['comment']); $admin->row_span($lang->string('Field Changes'), 'thead', 'center'); // ------------------------------------------------------------------- // built-in fields construct_datastore_select('severity', 'severity', 'severityid', $action['fields']['builtin']['severity'], true, true); $admin->row_list($lang->string('Severity'), 'fields[severity]'); construct_datastore_select('priority', 'priority', 'priorityid', $action['fields']['builtin']['priority'], true, true); $admin->row_list($lang->string('Priority'), 'fields[priority]'); construct_datastore_select('status', 'status', 'statusid', $action['fields']['builtin']['status'], true, true); $admin->row_list($lang->string('Status'), 'fields[status]'); construct_datastore_select('resolution', 'resolution', 'resolutionid', $action['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['fields']['custom']["$field[fieldid]"]); break; case 'input_checkbox': $admin->list_item('', 0, ((!$action['fields']['custom']["$field[fieldid]"]) ? true : false)); $admin->list_item($lang->string('Checked'), 1, (($action['fields']['custom']["$field[fieldid]"] == 1) ? true : false)); $admin->list_item($lang->string('Un-Checked'), 2, (($action['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['fields']['custom']["$field[fieldid]"]) ? true : false)); foreach ($selectopts AS $id => $select) { $admin->list_item(stripslashes($select), $id, (($action['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') { $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