From ace4e4c25613a980bff1d29cab80b2f381e3ccc9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 22 Dec 2005 05:23:08 +0000 Subject: [PATCH] r649: Adding base userhelp system for non-custom fields --- admin/userhelp.php | 150 +++++++++++++++++++++++++++++++ docs/schema_changes.sql | 10 ++- includes/functions_datastore.php | 7 ++ 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100755 admin/userhelp.php diff --git a/admin/userhelp.php b/admin/userhelp.php new file mode 100755 index 0000000..9d240c6 --- /dev/null +++ b/admin/userhelp.php @@ -0,0 +1,150 @@ +in['keystring'])) + { + $admin->error($lang->string('The unique key can only contain lowercase letters, underscores, and numbers.')); + } + + if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $bugsys->in['keystring'] . "'")) + { + $admin->error($lang->string('The unique key must be unique.')); + } + + if (empty($bugsys->in['keystring']) OR empty($bugsys->in['title']) OR empty($bugsys->in['body'])) + { + $admin->error($lang->string('All the fields are required. Please go back and fill each field in properly.')); + } + + $db->query("INSERT INTO " . TABLE_PREFIX . "fieldhelp (keystring, title, body) VALUES ('" . $bugsys->in['keystring'] . "', '" . $bugsys->in['title'] . "', '" . $bugsys->in['body'] . "')"); + + build_user_help(); + + $admin->redirect('userhelp.php?do=modify'); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'add') +{ + $admin->page_start($lang->string('New Help Text')); + + $admin->form_start('userhelp.php', 'insert'); + + $admin->table_start(); + $admin->table_head($lang->string('New Help Text')); + + $admin->row_input($lang->string('Topic Title'), 'title'); + $admin->row_input($lang->string('Unique Key
(lowercase letters, underscores, and numbers only)'), 'keystring'); + $admin->row_textarea($lang->string('Body Text'), 'body'); + + $admin->row_submit(); + + $admin->table_end(); + + $admin->form_end(); + + $admin->page_end(); +} + +// ################################################################### + +if ($_POST['do'] == 'update') +{ + foreach ($bugsys->in['help'] AS $keystring => $fields) + { + if (empty($fields['title']) OR empty($fields['body'])) + { + $admin->error(sprintf($lang->string('No fields can be empty. Please correct this with the text for key %1$s.'), $keystring)); + } + else + { + $query[] = "UPDATE " . TABLE_PREFIX . "fieldhelp SET title = '$fields[title]', body = '$fields[body]' WHERE keystring = '$keystring'"; + } + } + + foreach ($query AS $sql) + { + $db->query($sql); + } + + build_user_help(); + + $admin->redirect('userhelp.php?do=modify'); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'modify') +{ + $admin->page_start($lang->string('Edit User Help')); + + $admin->form_start('userhelp.php', 'update'); + + $admin->table_start(); + $admin->table_head($lang->string('Edit User Help')); + + $topics = $db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp ORDER BY keystring ASC"); + while ($topic = $db->fetch_array($topics)) + { + $inputfield = ''; + $admin->row_textarea($inputfield . '
' . $topic['keystring'] . '', 'help[' . $topic['keystring'] . '][body]', $topic['body']); + } + + $admin->row_submit('[' . $lang->string('Add New Help Text') . ']'); + + $admin->table_end(); + + $admin->page_end(); +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index 87971c3..e6737d5 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -4,4 +4,12 @@ ALTER TABLE `product` DROP `shortname`; ALTER TABLE `usergroup` DROP `opentag`; -ALTER TABLE `usergroup` DROP `closetag`; \ No newline at end of file +ALTER TABLE `usergroup` DROP `closetag`; + +CREATE TABLE `fieldhelp` ( + `keystring` VARCHAR(255) NOT NULL, + `title` VARCHAR(255) NOT NULL, + `body` MEDIUMTEXT NOT NULL +); + +ALTER TABLE `fieldhelp` ADD PRIMARY KEY(`keystring`); \ No newline at end of file diff --git a/includes/functions_datastore.php b/includes/functions_datastore.php index 79963da..426b5f7 100755 --- a/includes/functions_datastore.php +++ b/includes/functions_datastore.php @@ -268,6 +268,13 @@ function build_user_help() $help["field$field[fieldid]"] = array('title' => $field['name'], 'body' => $field['description']); } + // standard help texts + $texts = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp"); + while ($field = $bugsys->db->fetch_array($texts)) + { + $help["$field[keystring]"] = $field; + } + $bugsys->db->query(" ### replacing user help cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) -- 2.43.5