📄 data.php
字号:
function isEmpty($where = false, $print = 0) { // Run a query if data was given // if ( $where ) { $this->_initList($where,false,false,$print); } return $this->db->is_empty("",$print); } function notEmpty($where = false, $print = 0) { // Run a query if data was given // if ( $where ) { $this->_initList($where,false,"", $print); } return $this->db->not_empty(false,$print); } function getAllRecSql($sql) { return $this->db->getAllRows($sql); } function getAllRec($search = false,$opt = false) { $dataout = ''; $fields = false; $sort = false; $limit = false; $print = false; if ( is_array($opt) ) { if ( array_key_exists('fields', $opt) ) { $fields = $opt['fields']; } if ( array_key_exists('sort', $opt) ) { $sort = $opt['sort']; } if ( array_key_exists('print', $opt) ) { $print = $opt['print']; } if ( array_key_exists('limit', $opt) ) { $limit = $opt['limit']; } } $sql = $this->buildSql($search,$fields,$sort, $print, $limit);; return $this->db->getAllRows($sql); } // Gets one row of data from a matching database record // function getRec($search,$opt = false, $print = 0) { $this->rewindRec(); $data = $this->listRec($search,$opt, $print); return $data; } // Gets one field of data from a matching database record // function getRecField($search,$field,$opt = false,$print = 0) { $this->setEof(); // Only search if there really is a value in the search // if ( is_array($search) || $search > 0 ) { $data = $this->getRec($search,$opt,$print); } else { $data[$field] = ''; } if ( isset( $data[$field]) ) { $result = $data[$field]; } else { $result = false; } return $result; } function setRecField($search,$field,$value, $opt = false,$print = 0) { $this->setEof(); // Only search if there really is a value in the search // if ( is_array($search) || $search > 0 ) { $search[$field] = $value; $this->editRec($search,$form,$print); $result = ! $this->getError(); } else { $result = false; } return $result; } function translateType($type, $name) { if ($type == "string") { $type = "text"; } elseif ($type == "blob") { $type = "text"; } elseif ($type == "real") { $type = "amount"; } elseif ($type == "int") { $type = "number"; } return $type; } function nameToDescription($string) { return ucwords(str_replace("_", " ", $string)); } function form_values($form_values) { $line = ''; if ( is_array($form_values) ) { while(list($k,$v)=each($form_values)) { $line .= "&" . $k . "=$v"; } } return $line; } function now() { return date("Y-m-d H:i:s"); } function today() { return date("Y-m-d"); } function dumpConfig() { return var_export( $this->config, true ); } function setMsg($key, $value) { if ( array_key_exists($name, $this->config) ) { $this->config[$key] = $value; } } function setEditMsg($string) { $this->config['editMsg'] = $string; } function setAddMsg($string) { $this->config['addedMsg'] = $string; } function getAddMsg() { return $this->config['addedMsg']; } function setEditErrorMsg($string) { $this->config['editErr'] = $string; } function setAddErrorMsg($string) { $this->config['addedErr'] = $string; } function setDelErrorMsg($string) { $this->config['delErr'] = $string; } function setDelMsg($string) { $this->config['delMsg'] = $string; } function getEditMsg() { return $this->config['editMsg']; } function getEditErrorMsg() { return $this->config['editErr']; } function getAddErrorMsg() { return $this->config['addedErr']; } function getDelErrorMsg() { return $this->config['delErr']; } function getDelMsg() { return $this->config['delMsg']; } function setBlankErrorMsg($string) { $this->config['blankErr'] = $string; } function getBlankErrorMsg() { return $this->config['blankErr']; } // See if the table exists. If it doesn't and the create sql is present, create it // function numRows() { return $this->db->num_rows(); } function makeConfig() { $table_name = $this->getTableName(); $stable_name = $this->nameToDescription($table_name); $idField = $table_name . "_id"; $fields = $this->db->table_info( $this->getDbTableName() ); //$rows = $this->db->num_rows(); //$table = mysql_field_table($result, 0); $this->config = array( 'table' => $table_name, 'idField' => $table_name . '_id', 'addedMsg' => "$stable_name %s Added", 'added_err' => "Can\'t Add $stable_name", 'editMsg' => "$stable_name %s Updated", 'editErr' => "Can\'t Update $stable_name", 'delErr' => "Can\'t Delete $stable_name", 'delMsg' => "$stable_name %s Deleted", 'blankErr' => "$stable_name Empty", 'fields' => array() ); foreach ($fields AS $field ) { $type = $field['type']; $name = $field['name']; $type = $this->translateType($type,$name); $len = $field['len']; $flags = explode(' ',$field['flags']); $description = $this->nameToDescription($name); if ( $idField != $name ) { $field_array[$name] = array( 'name' => $name, 'description' => $description, 'type' => $type, 'min_len' => 0, 'max_len' => $len, 'blank_ok' => $this->isBlankOk($flags), 'duplicate_ok' => $this->isDuplicateOk($flags) ); } } $this->config['fields'] = $field_array; //print "<pre>"; //print_r($this->config); //print "</pre>"; } function isblankOk($flags) { if ( $this->inArray($flags, 'not_null') ) { $blank_ok = 0; } else { $blank_ok = 1; } return $blank_ok; } function isDuplicateOk($flags) { if ( $this->inArray($flags, 'unique_key') ) { $duplicate_ok = 0; } else { $duplicate_ok = 1; } return $duplicate_ok; } function inArray($array,$needle) { $match = false; foreach ($array as $value) { if ( $value == $needle) { $match = true; } } return $match; } function setDuplicateFieldMsg($message) { $this->valid->set_duplicate_field_set_msg($message); } function clrDuplicateOk($field) { $this->fields[$field]['duplicate_ok'] = 0; } function setDuplicateOk($field) { $this->fields[$field]['duplicate_ok'] = 1; } function clrBlankOk($field) { $this->fields[$field]['blank_ok'] = 0; } function setBlankOk($field) { $this->fields[$field]['blank_ok'] = 1; } // Sets the data type for a field used in validation and determining the type of form // function setFieldType($field,$type) { $this->fields[$field]['type'] = $type; } function setFieldName($field,$name) { $this->fields[$field]['name'] = $name; } // Sets the data type for a field used in validation and determining the type of form // function setFieldDescription($field,$description) { $this->fields[$field]['description'] = $description; } // Defines variables for checkboxes from forms since they don't return anything if not checked // // Accessor to set the value of a key or the entire array // function setData($key, $value = false) { return $this->_setData($key, $value); } function _setData($key, $value = false) { if ( is_array($key) ) { $this->_data = $key; } else { $this->_data[$key] = $value; } return $this->_data; } // Accessor to read the value of a key or the entire array if blank // function clrData() { $this->_data = array(); } function getData($key = false) { return $this->_getData($key); } function getDataRows() { return $this->_DataRows; } function _getData($key = false) { $value = false; if ( $key && is_array( $this->_data) ) { if ( array_key_exists($key, $this->_data ) ) { $value = $this->_data[$key]; } } else { $value = $this->_data; } return $value; } function FormatAmount($number) { $result = ''; if ( is_numeric($number) ) { $result = sprintf("%0.2f",$number); } return $result; } function getTableName($showprefix = true) { $name = $this->_tableName; if ( $showprefix ) { $name = $this->_table_prefix . $this->_tableName; } return $name; } function setTableName($name) { if ( strpos($name, '.') !== false ) { list($db, $name) = explode('.', $name); $this->setDbName($db); } $this->_tableName = $name; } function getDbTableName() { if ( $this->_dbName ) { $table = "$this->_dbName.$this->_tableName"; } else { $table = $this->_tableName; } return $table; } function getDbName() { return $this->_dbName; } function setDbName($name) { $this->_dbName = $name; } function formatDate($date, $format = "m/d/y H:i") { return date($format, strtotime($date) ); } function getAlphaRand($length = 20) { $sid = 0; srand ((double) microtime() * 1000000); $Puddle = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( $index = 0; $index < $length - 1; $index++ ) { $sid .= substr($Puddle, (rand()%(strlen($Puddle))), 1); } return $sid; }} // End of Class?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -