- Update the copyright notices to use the correct year and not a non-ASCII symbol
[bugdar.git] / includes / api_userhelp.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2008 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once ISSO . '/Api.php';
23
24 require_once('./includes/functions_datastore.php');
25
26 /**
27 * API: User help
28 *
29 * @author Blue Static
30 * @copyright Copyright (c)2004 - 2008, Blue Static
31 * @package Bugdar
32 *
33 */
34 class UserHelpAPI extends BSApi
35 {
36 /**
37 * Fields
38 * @var array
39 */
40 protected $fields = array(
41 'keystring' => array(TYPE_STR, REQ_AUTO),
42 'title' => array(TYPE_STR, REQ_YES),
43 'body' => array(TYPE_STR, REQ_YES)
44 );
45
46 /**
47 * Database table
48 * @var string
49 */
50 protected $table = 'fieldhelp';
51
52 /**
53 * Table prefix
54 * @var string
55 */
56 protected $prefix = TABLE_PREFIX;
57
58 /**
59 * A static function that returns an array of all the keystrings that
60 * are not allowed to be deleted
61 *
62 * @return array Array of keystrings
63 */
64 public static function not_able_to_delete()
65 {
66 return array(
67 'assignedto',
68 'bugid',
69 'dateline',
70 'dependency',
71 'duplicateof',
72 'priority',
73 'product',
74 'reporter',
75 'resolution',
76 'severity',
77 'status',
78 'summary',
79 'newreply',
80 'columnorder'
81 );
82 }
83
84 /**
85 * Post-insert
86 */
87 protected function post_insert()
88 {
89 build_user_help();
90 }
91
92 /**
93 * Post-update
94 */
95 protected function post_update()
96 {
97 build_user_help();
98 }
99
100 /**
101 * Pre-delete
102 */
103 protected function pre_delete()
104 {
105 if (in_array($this->values['keystring'], self::not_able_to_delete()))
106 {
107 throw new FieldException(T('You cannot delete this user help text because the system needs it.'), 'keystring');
108 }
109 }
110
111 /**
112 * Post-delete
113 */
114 protected function post_delete()
115 {
116 build_user_help();
117 }
118
119 /**
120 * Validate: title
121 */
122 protected function validate_title($field)
123 {
124 return $this->_verifyIsNotEmpty($field);
125 }
126
127 /**
128 * Verify: keystring
129 */
130 protected function validate_keystring($field)
131 {
132 if ($this->_verifyIsNotEmpty('keystring'))
133 {
134 return false;
135 }
136
137 if (preg_match('#[^a-z0-9_]#', $this->values['keystring']))
138 {
139 $this->_error(new FieldException(T('The unique key can only contain lowercase letters, underscores, and numbers.'), $field));
140 return false;
141 }
142
143 if (BSApp::$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . BSApp::$input->escape($this->values['keystring']) . "'"))
144 {
145 $this->_error(new FieldException(T('The unique key must be unique.'), $field));
146 return false;
147 }
148
149 return true;
150 }
151 }
152
153 ?>