From 165e2e7c36bf79c9d425021986ae760542e4dabf Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 26 Jun 2005 21:21:52 +0000 Subject: [PATCH] r270: - Initial SVN for autoaction.php - Modified admin/global.php to have a menu item for autoaction.php - Added the base table for auto actions - Modified construct_datastore_select() to also be able to construct items using the $admin class --- admin/autoaction.php | 217 ++++++++++++++++++++++++++++++++++++++++ admin/global.php | 3 +- docs/schema_changes.sql | 10 +- includes/functions.php | 38 +++++-- 4 files changed, 259 insertions(+), 9 deletions(-) create mode 100644 admin/autoaction.php diff --git a/admin/autoaction.php b/admin/autoaction.php new file mode 100644 index 0000000..a6074f3 --- /dev/null +++ b/admin/autoaction.php @@ -0,0 +1,217 @@ +in['name'])) + { + $admin->error('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('You need to specify some fields to change.'); + } + + $db->query(" + INSERT INTO " . TABLE_PREFIX . "autoaction + (name, description, fieldchanges) + VALUES + ('" . $bugsys->in['name'] . "', '" . $bugsys->in['description'] . "', + '" . $bugsys->escape(serialize($deltas)) . "' + )" + ); + + $admin->redirect('autoaction.php', 'Action added.'); +} + +// ################################################################### + +if ($_POST['do'] == 'update') +{ + // run code to update item in database +} + +// ################################################################### + +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::p('error_invalid_id')); + } + $action['fields'] = unserialize($action['fieldchanges']); + } + + $admin->page_start((($add) ? 'New Automatic Action' : 'Edit Auto Action')); + + $admin->form_start('autoaction.php', (($add) ? 'insert' : 'update')); + $admin->table_start(); + $admin->table_head((($add) ? 'New Automatic Action' : 'Edit Auto Action')); + + $admin->row_input('Name', 'name', $action['name']); + $admin->row_textarea('Description', 'description', $action['description']); + + $admin->row_span('Field Changes', 'thead', 'center'); + + // ------------------------------------------------------------------- + // built-in fields + construct_datastore_select('severity', 'severity', 'severityid', $action['fields']['builtin']['severity'], true, true); + $admin->row_list('Severity', 'fields[severity]'); + + construct_datastore_select('priority', 'priority', 'priorityid', $action['fields']['builtin']['priority'], true, true); + $admin->row_list('Priority', 'fields[priority]'); + + construct_datastore_select('status', 'status', 'statusid', $action['fields']['builtin']['status'], true, true); + $admin->row_list('Status', 'fields[status]'); + + construct_datastore_select('resolution', 'resolution', 'resolutionid', $action['fields']['builtin']['resolution'], true, true); + $admin->row_list('Resolution', 'fields[resolution]'); + + /*$select['dev'] = ''; + foreach ($bugsys->datastore['assignto'] AS $dev) + { + $value = $dev['userid']; + $label = construct_user_display($dev, false); + eval('$select[dev] .= "' . $template->fetch('selectoption') . '";'); + }*/ + + $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('Checked', 1, (($action['fields']['custom']["$field[fieldid]"] == 1) ? true : false)); + $admin->list_item('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) ? 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('Automatic Actions'); + + $admin->table_start(); + $admin->table_head('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
$action[description]
", "[Edit] [Delete]"); + } + + $admin->row_span('[Add New Action]', 'tfoot', 'center', 3); + $admin->table_end(); + + $admin->page_end(); +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/admin/global.php b/admin/global.php index 91ecf4e..49a84ef 100755 --- a/admin/global.php +++ b/admin/global.php @@ -34,7 +34,8 @@ $globalnav = array( 'Resolutions' => 'resolution.php', 'Severities' => 'severity.php', 'Statuses' => 'status.php', - 'Custom Bug Fields' => 'fields.php' + 'Custom Bug Fields' => 'fields.php', + 'Automatic Actions' => 'autoaction.php' ), 'User Management' => array( diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index 703f963..a471528 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -70,4 +70,12 @@ CREATE TABLE `bugfieldpermission` ( ALTER TABLE `bugfield` CHANGE `private` `cansearch` INT(2) DEFAULT '0' NOT NULL; -ALTER TABLE `bugfield` DROP `shortname`; \ No newline at end of file +ALTER TABLE `bugfield` DROP `shortname`; + +CREATE TABLE `autoaction` ( + `actionid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` VARCHAR(55) NOT NULL, + `description` MEDIUMTEXT NOT NULL, + `fieldchanges` MEDIUMTEXT NOT NULL, + PRIMARY KEY (`actionid`) +); \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 2276892..d2ef4fd 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -271,18 +271,30 @@ function parse_pcv_select($input, $validate = false) // ################# Start construct_datastore_select ################ // loops through the specified datastore to create