⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 data.php

📁 太烦了
💻 PHP
📖 第 1 页 / 共 3 页
字号:
            // If there's one error, it's all an error            //            if ( $this->valid->error ) {               $error = true;               $message .= "Line " . $key . ": " . $this->valid->error_message . "<br>";            }            $all_blank = false;         }      }      $this->setData( $data);      if ( ! $error) {                        // Go ahead and save the data         if ( ! array_key_exists('nosave',$opt) ) {            foreach( $save_data as $key => $save ) {               if ( $data[$key][$this->getIdField()] ) {                   $id_key[$this->getIdField()] = $data[$key][$this->getIdField()];                   $save[$this->getIdField()]   = $data[$key][$this->getIdField()];               }               else {                   $id_key[$this->getIdField()] = $key;                   $save[$this->getIdField()] = $key;               };               $result = $this->updateQuery($save, $id_key, $print);               if ( ! $result ) {                  $this->setErrorMessage($this->getEditErrorMsg() );               }               // If there's one error, it's all an error               //               if ( $this->isError() ) {                  $error = true;                  $message .= $this->Message() . "<br>";               }            }         }         // Just run the pre update methods         //         else {            foreach( $save_data as $key => $save ) {               $id_key[$this->getIdField()] = $data[$key][$this->getIdField()];               $save[$this->getIdField()] = $data[$key][$this->getIdField()];            }         }         $this->setMessage($message);         $this->setError($error);      }      else {         $this->setErrorMessage($message);         $this->setData( $data  );      }      if ( $all_blank ) {         $this->setErrorMessage($this->getBlankError() );      }      elseif ( $this->isError() ) {         $this->setErrorMessage($this->getEditErrorMsg() );      }      else {         $this->setMessage($this->getEditMsg() );      }      return $this->getData();   }   // When validating rows, this is a field to ignore to determine if the row is all blank   //   function addIgnoreField($fieldname) {      $this->_ignoreField[] = $fieldname;   }   function getIgnoreFields() {      return $this->_ignoreField;   }   // Returns true if all array values are blank   //   function allBlank($array) {      $blank = true;      foreach( $array as $key => $value ) {         if ( $value != '' && $key != $this->getIdField()  && ! in_array($key, $this->getIgnoreFields() ) ) {            $blank = false;         }      }      return $blank;   }    function validateData($data, $mode = "") {      $this->valid->reset();      $this->clrError();      $this->clrMessage();      $this->valid->data_in       = $data;      if ( $mode == "update" ) {         $this->validateGivenFields();      }      else {         $this->validateAllFields();      }      return $this->valid;   }    function validateGivenFields() {         $data = $this->valid->data_in;         $key_array = array_keys($this->fields);         while (list($index, $key) = each ($key_array)) {            if ( $key != $this->getIdField() ) {               $field  = $this->fields[$key];               // Only validate if it's a field that's already defined.  If it's a type date, it's been defined               //               if ( array_key_exists('type', $field) && $field['type'] == 'password' && $data[$key] ) {                   $this->valid->validate_password($field['min_len'],$field['max_len'],$field['name'],$field['name'] . '2');               }               elseif ( isset($data[$key])                  || (                     array_key_exists('type', $field)                     && $field['type'] == 'time'                     && array_key_exists($key . "_hours", $data)                     && $data[$key . "_hours"] != ""                     && array_key_exists($key . "_minutes", $data)                     && $data[$key . "_minutes"] != ""                     && array_key_exists($key . "_am_pm", $data)                     && $data[$key . "_am_pm"] != ""                  )                  || (                     array_key_exists('type', $field)                     && $field['type'] == 'date'                     && array_key_exists($key . "_m", $data)                     && $data[$key . "_m"] != ""                     && array_key_exists($key . "_y", $data)                     && $data[$key . "_y"] != ""                     && array_key_exists($key . "_d", $data)                     && $data[$key . "_d"] != ""                  )                  || (                     array_key_exists('type', $field)                     && $field['type'] == 'cc_exp'                     && array_key_exists($key . "_m", $data)                     && $data[$key . "_m"] != ""                     && array_key_exists($key . "_y", $data)                     && $data[$key . "_y"] != ""                  )               ) {                  // Just to fix warnings about non-existant keys                  $default = array( 'name' => '', 'description' => '', 'type' => '', 'min_len' => '', 'max_len' => '', 'blank_ok' => '', 'duplicate_ok' => '');                  $field = array_merge($default, $field);                  $this->valid->validate($field['name'], $field['description'], $field['type'], $field['min_len'], $field['max_len'], $field['blank_ok'], $field['duplicate_ok']);               }            }         }    }       function validateAllFields() {      $data_def                   = $this->fields;      $f = array(         'name'      => '',         'description'   => '',         'type'      => '',         'min_len'   => '',         'max_len'   => '',         'blank_ok'   => '',         'duplicate_ok'   => '',      );      while (list($key, $field) = each ($data_def)) {         // Keeps php from complaining about missing fields         $field = array_merge($f,$field);         if ( $field['type'] == 'password' ) {            $this->valid->validate_password($field['min_len'],$field['max_len'],$field['name'],$field['name'] . '2');         }         else {            $this->valid->validate($field['name'], $field['description'], $field['type'], $field['min_len'], $field['max_len'], $field['blank_ok'], $field['duplicate_ok']);         }      }      // If a id field value is provided, validate it      //      if ( array_key_exists($this->getIdField(), $this->valid->data_in)       &&  $this->valid->data_in[ $this->getIdField() ] ) {         $this->valid->validate($this->getIdField(), $this->nameToDescription($this->getIdField()), 'number', '1', '11', '0', '0');      }   }   function getFieldMessage($field) {      return $this->valid->get_field_error($field);   }   function setEof() {      $this->_eof = true;   }   function clrEof() {      $this->_eof = false;   }   function getEof() {      return $this->_eof;   }   function getRow($sql,$print = 0) {      $this->setEof();      $data =  $this->db->get_row($sql,$print);      $this->setData($data);      return $data;   }   function getField($field, $sql,$print = 0) {      $data = $this->db->getOne($sql,$print);      return $data;   }   function query($sql,$print = 0) {      $this->setEof();             return $this->db->query($sql,$print);   }        // Overridable method to change data before an update        //   function updateQuery($data, $key, $print = 0)  {             return $this->_updateQuery($data, $key, $print) ;   }   function _updateQuery($data, $key, $print = 0)  {      $this->setEof();      $table = $this->getDbTableName();       $result = $this->db->update_query($data, $this->getDbTableName(), $key, $print) ;      return $result;   } /**   * Delete the specified record   *   * @param string|array $id either the id for the _idField or a array.  If the id = all, everything is deleted.   * @return   * @access public   */   function deleteRec($id,$confirm = false,$print = 0) {      $this->clrError();      $this->setEof();      $where = $this->where($id);      $this->_deleteRows = $this->db->not_empty("SELECT * FROM " . $this->getDbTableName() . " $where",$print);      if ( ( $where || $confirm ) && $this->_deleteRows ) {         $this->db->query("DELETE FROM " . $this->getDbTableName() . " $where",$print);         $rval = true;         //$this->setMessage($this->getIdMessage($this->getDelMsg()));      }      elseif ( $this->getEmptySetDeleteOk() ) {         $rval = true;     }     else {         $rval = false;         $this->setErrorMessage($this->getDelErrorMsg());      }      return $rval;   }   // After running a delete, returns the number of rows there was to delete   //   function getDeleteRows() {      return $this->_deleteRows;   }   // Adds the record number to the message by figuring out if the id   // is in a array or passed as a number   //   function getIdMessage($message,$id) {      if ( is_array($id) ) {         $number = $id[ $this->getIdField() ];      }      else {         $number = $id;      }      return sprintf($message,$number);   }   function deleteAllData($sure) {         $this->setEof();           $this->clrError();           if ( $sure == "Y" ) {               $this->db->query("DELETE FROM " . $this->getDbTableName() . "",0);               $rval = true;               $this->setMessage($this->config['delMsg']);           }           else {               $rval = false;               $this->setErrorMessage("Syntax Error:  To delete all records pass a 'Y'");           }           return $rval;   }   function rewindRec() {      $this->setEof();   }   //   function _initQuery($sql, $print = 0) {         $this->db->query( $sql,$print);         $this->clrEof();         $this->rows = 0;   }   function buildSql($search = "",$fields = false,$sort = "", $print = 0, $limit = false) {      $order_by = "";      if ( $sort != "" ) {         $order_by = " ORDER BY $sort ";      }      if ( is_array($fields) ) {         $fld = join(',',$fields);      }      else {         $fld = '*';      }      $sql = "SELECT $fld FROM " . $this->getDbTableName() . " " . $this->where($search) . $order_by;      if ( $limit ) {         $sql .= " LIMIT $limit";      }      return $sql;   }   function _initList($search = "",$fields = false,$sort = "", $print = 0, $limit = false) {      $sql = $this->buildSql($search,$fields,$sort, $print, $limit);      $this->db->query($sql,$print);      $this->clrEof();      $this->rows = 0;   }   function displayPrevious($page,$values) {      return $this->more->display_previous($page,$values);   }   function displayNext($page,$values) {      return $this->more->display_next($page,$values);   }   function where($search = "") {      if ( is_array($search) ) {  // Search by array key/value matches                 $where =  $this->db->where_statement($search);      }      elseif ( $search > 0 ) {  // Search by id number                 $where =  "WHERE " . $this->getIdField() . " = '$search'";      }      else {  // list all                 $where = "";      }      return $where;   }/*    while ( $data = $dc->listRec() ) {       while (list($key, $value) = each ($data)) {                print "$key: " . $value . "\n";       }       print "\n";    }*/    function listRec($search = false,$opt = false,$print = 0) {         $fields = false;         $sort = false;         $limit = 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'];            }         }         if ( $this->getEof() ) {            $this->_initList($search,$fields,$sort,$print,$limit);         }         // Read database         //         if ( $this->notEmpty() ) {            $this->getRowArray();         }         else {            $this->setData( array() );            $this->setEof();         }         return $this->getData();    }    function getRowArray() {         $data_out = $this->db->get_row_array();      $this->setData($data_out );       return $this->getData();    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -