From d95cee965a052b4df43e103babf44e503030a18d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 19 Jul 2006 16:00:02 +0000 Subject: [PATCH] r906: Adding and implementing the UserHelpAPI --- admin/userhelp.php | 80 +++++------------- includes/api_userhelp.php | 171 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 61 deletions(-) create mode 100644 includes/api_userhelp.php diff --git a/admin/userhelp.php b/admin/userhelp.php index b438de1..5bc437c 100755 --- a/admin/userhelp.php +++ b/admin/userhelp.php @@ -20,6 +20,7 @@ \*=====================================================================*/ require_once('./global.php'); +require_once('./includes/api_userhelp.php'); require_once('./includes/functions_datastore.php'); NavLinks::optionsPages(); @@ -31,23 +32,6 @@ if (!can_perform('canadmintools')) admin_login(); } -// don't allow deleting of these -$nokills = array( - 'assignedto', - 'bugid', - 'dateline', - 'dependency', - 'duplicateof', - 'priority', - 'product', - 'reporter', - 'resolution', - 'severity', - 'status', - 'summary', - 'newreply' -); - // ################################################################### if (empty($_REQUEST['do'])) @@ -59,12 +43,9 @@ if (empty($_REQUEST['do'])) if ($_REQUEST['do'] == 'kill') { - if (in_array($bugsys->in['keystring'], $nokills)) - { - $admin->error($lang->string('You cannot delete this help text because it is part of the default set.')); - } - - $db->query("DELETE FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $bugsys->in['keystring'] . "'"); + $help = new UserHelpAPI($bugsys); + $help->set('keystring', $bugsys->in['keystring']); + $help->delete(); build_user_help(); @@ -75,11 +56,6 @@ if ($_REQUEST['do'] == 'kill') if ($_REQUEST['do'] == 'delete') { - if (in_array($bugsys->in['keystring'], $nokills)) - { - $admin->error($lang->string('You cannot delete this help text because it is part of the default set.')); - } - $admin->page_confirm($lang->string('Are you sure you want to delete help text?'), 'userhelp.php?do=kill&keystring=' . $bugsys->in['keystring']); } @@ -87,24 +63,11 @@ if ($_REQUEST['do'] == 'delete') if ($_POST['do'] == 'insert') { - if (preg_match('#[^a-z0-9_]#', $bugsys->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(); + $help = new UserHelpAPI($bugsys); + $help->set('keystring', $bugsys->in['keystring']); + $help->set('title', $bugsys->in['title']); + $help->set('body', $bugsys->in['body']); + $help->insert(); $admin->redirect('userhelp.php?do=modify'); } @@ -141,21 +104,15 @@ 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'"; - } + $help = new UserHelpAPI($bugsys); + $help->norunners = array('post_update'); + $help->set('keystring', $keystring); + $help->set_condition(); + $help->set('title', $fields['title']); + $help->set('body', $fields['body']); + $help->update(); } - - foreach ($query AS $sql) - { - $db->query($sql); - } - + build_user_help(); $admin->redirect('userhelp.php?do=modify'); @@ -178,11 +135,12 @@ if ($_REQUEST['do'] == 'modify') while ($topic = $db->fetch_array($topics)) { $inputfield = ''; - $delete = (!in_array($topic['keystring'], $nokills) ? '

[' . $lang->string('Delete') . ']' : ''); + $delete = (!in_array($topic['keystring'], UserHelpAPI::not_able_to_delete()) ? '

[' . $lang->string('Delete') . ']' : ''); $admin->row_textarea($inputfield . '
' . $topic['keystring'] . '' . $delete, 'help[' . $topic['keystring'] . '][body]', $topic['body']); } + $admin->row_submit(); $admin->table_end(); $admin->page_end(); diff --git a/includes/api_userhelp.php b/includes/api_userhelp.php new file mode 100644 index 0000000..1493be9 --- /dev/null +++ b/includes/api_userhelp.php @@ -0,0 +1,171 @@ +load('api', null); + +require_once('./includes/functions_datastore.php'); + +/** +* API: User help +* +* @author Iris Studios, Inc. +* @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc. +* @version $Revision$ +* @package Bugdar +* +*/ +class UserHelpAPI extends API +{ + /** + * Fields + * @var array + * @access private + */ + var $fields = array( + 'keystring' => array(TYPE_STR, REQ_YES, ':self'), + 'title' => array(TYPE_STR, REQ_YES, 'verify_noempty'), + 'body' => array(TYPE_STR, REQ_YES) + ); + + /** + * Database table + * @var string + * @access private + */ + var $table = 'fieldhelp'; + + /** + * Table prefix + * @var string + * @access private + */ + var $prefix = TABLE_PREFIX; + + // ################################################################### + /** + * A static function that returns an array of all the keystrings that + * are not allowed to be deleted + * + * @access public + * + * @return array Array of keystrings + */ + function not_able_to_delete() + { + return array( + 'assignedto', + 'bugid', + 'dateline', + 'dependency', + 'duplicateof', + 'priority', + 'product', + 'reporter', + 'resolution', + 'severity', + 'status', + 'summary', + 'newreply' + ); + } + + // ################################################################### + /** + * Post-insert + * + * @access private + */ + function post_insert() + { + build_user_help(); + } + + // ################################################################### + /** + * Post-update + * + * @access private + */ + function post_update() + { + build_user_help(); + } + + // ################################################################### + /** + * Pre-delete + * + * @access private + */ + function pre_delete() + { + if (in_array($this->values['keystring'], UserHelpAPI::not_able_to_delete())) + { + return false; + } + return true; + } + + // ################################################################### + /** + * Post-delete + * + * @access private + */ + function post_delete() + { + build_user_help(); + } + + // ################################################################### + /** + * Verify: keystring + * + * @access private + */ + function verify_keystring() + { + if (!($ne = $this->verify_noempty('keystring'))) + { + return $ne; + } + + if (preg_match('#[^a-z0-9_]#', $this->values['keystring'])) + { + return $this->registry->lang->string('The unique key can only contain lowercase letters, underscores, and numbers.'); + } + + if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $this->registry->escape($this->values['keystring']) . "'")) + { + return $this->registry->lang->string('The unique key must be unique.'); + } + + return true; + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.22.5