load('api', null); require_once('./includes/functions_datastore.php'); /** * API: Field * * @author Blue Static * @copyright Copyright ©2002 - 2007, Blue Static * @version $Revision$ * @package Bugdar * */ class FieldAPI extends API { /** * Fields * @var array * @access private */ var $fields = array( 'fieldid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'), 'name' => array(TYPE_STR, REQ_YES, 'verify_noempty'), 'description' => array(TYPE_STR, REQ_NO), 'type' => array(TYPE_STR, REQ_YES, ':self'), 'selects' => array(TYPE_STR, REQ_NO, ':self'), 'required' => array(TYPE_BOOL, REQ_NO), 'cansearch' => array(TYPE_BOOL, REQ_NO), 'regexmatch' => array(TYPE_STR, REQ_NO), 'defaultvalue' => array(TYPE_STR, REQ_NO), 'usedefault' => array(TYPE_BOOL, REQ_NO), 'maxlength' => array(TYPE_UINT, REQ_NO) ); /** * Database table * @var string * @access private */ var $table = 'bugfield'; /** * Table prefix * @var string * @access private */ var $prefix = TABLE_PREFIX; // ################################################################### /** * A static method that is used to return an array of all the allowed * field types. * * @access public * * @param string Return the display name of a type if the key is passed * * @return array An array of all the allowed field types */ function field_types($type = null) { global $lang; $types = array( 'input_text' => T('Single-Line Text Box'), 'input_checkbox' => T('Checkbox Flag'), 'select_single' => T('Drop-Down Menu'), ); if ($type == null) { return $types; } else { return $types["$type"]; } } // ################################################################### /** * Post-insert * * @access private */ function post_insert() { build_user_help(); } // ################################################################### /** * Post-update * * @access private */ function post_update() { build_user_help(); } // ################################################################### /** * Post-delete * * @access private */ function post_delete() { $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . $this->values['fieldid']); $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = " . $this->values['fieldid']); $this->registry->db->query("ALTER TABLE " . TABLE_PREFIX . "bug DROP custom" . $this->values['fieldid']); $this->registry->db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bug"); build_user_help(); } // ################################################################### /** * Verify: type * * @access private */ function verify_type() { if (!in_array($this->values['type'], array_keys(FieldAPI::field_types()))) { return false; } return true; } // ################################################################### /** * Verify: selects * * @access private */ function verify_selects() { static $serialized; if ($this->values['type'] == 'select_single' OR $this->record['type'] == 'select_single') { $this->registry->debug('it works'); // can't use explode() here because explode() returns !empty() when splitting an empty string // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this $selects = preg_split("#\n#", trim($this->values['selects']), 0, PREG_SPLIT_NO_EMPTY); array_walk($selects, 'trim'); if (sizeof($selects) < 1) { return T('You need to specify some select values.'); } else { if ($serialized != serialize($selects)) { $this->values['selects'] = $serialized = serialize($selects); } } } return true; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>