2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
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.
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
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 \*=====================================================================*/
22 $GLOBALS['isso:callback']->load('api', null);
24 require_once('./includes/functions_datastore.php');
30 * @copyright Copyright ©2002 - 2007, Blue Static
35 class FieldAPI
extends API
43 'fieldid' => array(TYPE_UINT
, REQ_AUTO
, 'verify_nozero'),
44 'name' => array(TYPE_STR
, REQ_YES
, 'verify_noempty'),
45 'description' => array(TYPE_STR
, REQ_NO
),
46 'type' => array(TYPE_STR
, REQ_YES
, ':self'),
47 'selects' => array(TYPE_STR
, REQ_NO
, ':self'),
48 'required' => array(TYPE_BOOL
, REQ_NO
),
49 'cansearch' => array(TYPE_BOOL
, REQ_NO
),
50 'regexmatch' => array(TYPE_STR
, REQ_NO
),
51 'defaultvalue' => array(TYPE_STR
, REQ_NO
),
52 'usedefault' => array(TYPE_BOOL
, REQ_NO
),
53 'maxlength' => array(TYPE_UINT
, REQ_NO
)
61 var $table = 'bugfield';
68 var $prefix = TABLE_PREFIX
;
70 // ###################################################################
72 * A static method that is used to return an array of all the allowed
77 * @param string Return the display name of a type if the key is passed
79 * @return array An array of all the allowed field types
81 function field_types($type = null)
85 'input_text' => T('Single-Line Text Box'),
86 'input_checkbox' => T('Checkbox Flag'),
87 'select_single' => T('Drop-Down Menu'),
96 return $types["$type"];
100 // ###################################################################
106 function post_insert()
111 // ###################################################################
117 function post_update()
122 // ###################################################################
128 function post_delete()
130 $this->registry->db->query("DELETE FROM
" . TABLE_PREFIX . "bugfield WHERE fieldid
= " . $this->values['fieldid']);
131 $this->registry->db->query("DELETE FROM
" . TABLE_PREFIX . "bugfieldpermission WHERE fieldid
= " . $this->values['fieldid']);
132 $this->registry->db->query("ALTER TABLE
" . TABLE_PREFIX . "bug DROP custom
" . $this->values['fieldid']);
133 $this->registry->db->query("OPTIMIZE TABLE
" . TABLE_PREFIX . "bug
");
138 // ###################################################################
144 function verify_type()
146 if (!in_array($this->values['type'], array_keys(FieldAPI::field_types())))
153 // ###################################################################
159 function verify_selects()
162 if ($this->values['type'] == 'select_single' OR $this->record['type'] == 'select_single')
164 $this->registry->debug('it works');
165 // can't use explode() here because explode() returns !empty() when splitting an empty string
166 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
167 $selects = preg_split("#\n#", trim($this->values['selects']), 0, PREG_SPLIT_NO_EMPTY);
168 array_walk($selects, 'trim');
169 if (sizeof($selects) < 1)
171 return T('You need to specify some select values.');
175 if ($serialized != serialize($selects))
177 $this->values
['selects'] = $serialized = serialize($selects);
186 /*=====================================================================*\
187 || ###################################################################
190 || ###################################################################
191 \*=====================================================================*/