r1389: Forgot to add the template diff
[bugdar.git] / includes / api_userhelp.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 $GLOBALS['isso:callback']->load('api', null);
23
24 require_once('./includes/functions_datastore.php');
25
26 /**
27 * API: User help
28 *
29 * @author Blue Static
30 * @copyright Copyright ©2002 - [#]year[#], Blue Static
31 * @version $Revision$
32 * @package Bugdar
33 *
34 */
35 class UserHelpAPI extends API
36 {
37 /**
38 * Fields
39 * @var array
40 * @access private
41 */
42 var $fields = array(
43 'keystring' => array(TYPE_STR, REQ_AUTO),
44 'title' => array(TYPE_STR, REQ_YES, 'verify_noempty'),
45 'body' => array(TYPE_STR, REQ_YES)
46 );
47
48 /**
49 * Database table
50 * @var string
51 * @access private
52 */
53 var $table = 'fieldhelp';
54
55 /**
56 * Table prefix
57 * @var string
58 * @access private
59 */
60 var $prefix = TABLE_PREFIX;
61
62 // ###################################################################
63 /**
64 * A static function that returns an array of all the keystrings that
65 * are not allowed to be deleted
66 *
67 * @access public
68 *
69 * @return array Array of keystrings
70 */
71 function not_able_to_delete()
72 {
73 return array(
74 'assignedto',
75 'bugid',
76 'dateline',
77 'dependency',
78 'duplicateof',
79 'priority',
80 'product',
81 'reporter',
82 'resolution',
83 'severity',
84 'status',
85 'summary',
86 'newreply'
87 );
88 }
89
90 // ###################################################################
91 /**
92 * Pre-insert
93 *
94 * @access private
95 */
96 function pre_insert()
97 {
98 if (($err = $this->verify_keystring()) !== true)
99 {
100 $this->error($err);
101 }
102 }
103
104 // ###################################################################
105 /**
106 * Post-insert
107 *
108 * @access private
109 */
110 function post_insert()
111 {
112 build_user_help();
113 }
114
115 // ###################################################################
116 /**
117 * Post-update
118 *
119 * @access private
120 */
121 function post_update()
122 {
123 build_user_help();
124 }
125
126 // ###################################################################
127 /**
128 * Pre-delete
129 *
130 * @access private
131 */
132 function pre_delete()
133 {
134 if (in_array($this->values['keystring'], UserHelpAPI::not_able_to_delete()))
135 {
136 return false;
137 }
138 return true;
139 }
140
141 // ###################################################################
142 /**
143 * Post-delete
144 *
145 * @access private
146 */
147 function post_delete()
148 {
149 build_user_help();
150 }
151
152 // ###################################################################
153 /**
154 * Verify: keystring
155 *
156 * @access private
157 */
158 function verify_keystring()
159 {
160 if (!is_bool($ne = $this->verify_noempty('keystring')))
161 {
162 return $ne;
163 }
164
165 if (preg_match('#[^a-z0-9_]#', $this->values['keystring']))
166 {
167 return _('The unique key can only contain lowercase letters, underscores, and numbers.');
168 }
169
170 if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $this->registry->escape($this->values['keystring']) . "'"))
171 {
172 return _('The unique key must be unique.');
173 }
174
175 return true;
176 }
177 }
178
179 /*=====================================================================*\
180 || ###################################################################
181 || # $HeadURL$
182 || # $Id$
183 || ###################################################################
184 \*=====================================================================*/
185 ?>