r1048: Converting all $lang->string() stuff to use the gettext call
[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_YES, ':self'),
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 * Post-insert
93 *
94 * @access private
95 */
96 function post_insert()
97 {
98 build_user_help();
99 }
100
101 // ###################################################################
102 /**
103 * Post-update
104 *
105 * @access private
106 */
107 function post_update()
108 {
109 build_user_help();
110 }
111
112 // ###################################################################
113 /**
114 * Pre-delete
115 *
116 * @access private
117 */
118 function pre_delete()
119 {
120 if (in_array($this->values['keystring'], UserHelpAPI::not_able_to_delete()))
121 {
122 return false;
123 }
124 return true;
125 }
126
127 // ###################################################################
128 /**
129 * Post-delete
130 *
131 * @access private
132 */
133 function post_delete()
134 {
135 build_user_help();
136 }
137
138 // ###################################################################
139 /**
140 * Verify: keystring
141 *
142 * @access private
143 */
144 function verify_keystring()
145 {
146 if (!is_bool($ne = $this->verify_noempty('keystring')))
147 {
148 return $ne;
149 }
150
151 if (preg_match('#[^a-z0-9_]#', $this->values['keystring']))
152 {
153 return _('The unique key can only contain lowercase letters, underscores, and numbers.');
154 }
155
156 if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $this->registry->escape($this->values['keystring']) . "'"))
157 {
158 return _('The unique key must be unique.');
159 }
160
161 return true;
162 }
163 }
164
165 /*=====================================================================*\
166 || ###################################################################
167 || # $HeadURL$
168 || # $Id$
169 || ###################################################################
170 \*=====================================================================*/
171 ?>