Warning: Undefined array key "HTTP_ACCEPT_LANGUAGE" in /www/wwwroot/01xj.net/wp-content/plugins/wp-ue/main.php on line 13
二次开发常用的函数 – 我的空间 · 我做主

二次开发常用的函数

/*** 执行sql查询
   final public function select($where = '', $data = '*', $limit = '', $order = '', $group = '', $key='') {
/*** 查询多条数据并分页*/
   final public function listinfo($where = '', $order = '', $page = 1, $pagesize = 20, $key='', $setpages = 10,$urlrule = '',$array = array()) {
/*** 获取单条记录查询
   final public function get_one($where = '', $data = '*', $order = '', $group = '') {
/*** 执行添加记录操作
   final public function insert($data, $return_insert_id = false, $replace = false) {
/*** 执行更新记录操作
   final public function update($data, $where = '') {
/*** 执行删除记录操作
   final public function delete($where) { 
/**日期时间控件  * @param $name 控件name,id
   public static function date($name, $value = '', $isdatetime = 0, $loadjs = 0, $showweek = 'true')
/*** 下拉选择框
   public static function select($array = array(), $id = 0, $str = '', $default_option = '') {
/**复选框
   public static function checkbox($array=array(), $id= '', $str='', $defaultvalue='', $width =0,$field = '')
/*** 单选框
   public static function radio($array = array(), $id = 0, $str = '', $width = 0, $field = '') {
/*** 获取通过 set_cookie 设置的 cookie 变量 
   public static function get_cookie($var, $default = '') {
/*** 设置 cookie@param string $var     变量名@param string $value   变量值@param int $time    过期时间*/
   public static function set_cookie($var, $value = '', $time = 0) {
 
/**写入缓存,默认为文件缓存,不加载缓存配置。@param $name 缓存名称
function setcache($name, $data, $filepath='', $type='file', $config='', $timeout=0)
/*** 读取缓存,默认为文件缓存,不加载缓存配置。
function getcache($name, $filepath='', $type='file', $config='') {
/* * 删除缓存,默认为文件缓存,不加载缓存配置。
function delcache($name, $filepath='', $type='file', $config='') {
pc_base::load_Model(‘user_model’);        Pc_base::load_sys_class(‘admin’,’admin’,0);
Pc_base::load_sys_class(‘http’);        Pc_base::load_app_class(‘draw’,’abc’)
Pc_base::load_sys_func(‘mail’);             Pc_base::load_app_func(‘abc’)
Include template(‘content’,’header’)      Include $this->admin_tpl(‘content’,’footer’)


 /*** 执行sql查询
    * @param $where      查询条件[例`name`='$name']
    * @param $data       需要查询的字段值[例`name`,`gender`,`birthday`]
    * @param $limit      返回结果范围[例:10或10,10 默认为空]*/
   final public function select($where = '', $data = '*', $limit = '', $order = '', $group = '', $key='') {
      if (is_array($where)) $where = $this->sqls($where);
      return $this->db->select($data, $this->table_name, $where, $limit, $order, $group, $key);
   }
 
   /*** 查询多条数据并分页*/
   final public function listinfo($where = '', $order = '', $page = 1, $pagesize = 20, $key='', $setpages = 10,$urlrule = '',$array = array()) {
      $where = to_sqls($where);
      $this->number = $this->count($where);
      $page = max(intval($page), 1);
      $offset = $pagesize*($page-1);
      $this->pages = pages($this->number, $page, $pagesize, $urlrule, $array, $setpages);
      $array = array();
      if ($this->number > 0) {
         return $this->select($where, '*', "$offset, $pagesize", $order, '', $key);
      } else {
         return array();
      }
   }
 
 
   /**
    * 获取单条记录查询
    * @param $where      查询条件
    * @param $data       需要查询的字段值[例`name`,`gender`,`birthday`]
    * @param $order      排序方式  [默认按数据库默认方式排序]
    * @param $group      分组方式  [默认为空]
    * @return array/null 数据查询结果集,如果不存在,则返回空
    */
   final public function get_one($where = '', $data = '*', $order = '', $group = '') {
      if (is_array($where)) $where = $this->sqls($where);
      return $this->db->get_one($data, $this->table_name, $where, $order, $group);
   }
 
final public function query($sql) {
      $sql = str_replace('phpcms_', $this->db_tablepre, $sql);
      return $this->db->query($sql);
   }
 
/*** 执行添加记录操作
    * @param $data       要增加的数据,参数为数组。数组key为字段值,数组值为数据取值
    * @param $return_insert_id 是否返回新建ID号
    * @param $replace 是否采用 replace into的方式添加数据* @return boolean */
   final public function insert($data, $return_insert_id = false, $replace = false) {
      return $this->db->insert($data, $this->table_name, $return_insert_id, $replace);
   }
 
   /**
    * 执行更新记录操作
    * @param $data       要更新的数据内容,参数可以为数组也可以为字符串,建议数组。
    *                 为数组时数组key为字段值,数组值为数据取值
    *                 为字符串时[例:`name`='phpcms',`hits`=`hits`+1]。
    *                 为数组时[例: array('name'=>'phpcms','password'=>'123456')]
    *                 数组的另一种使用array('name'=>'+=1', 'base'=>'-=1');程序会自动解析为`name` = `name` + 1,
    * @param $where      更新数据时的条件,可为数组或字符串
    * @return boolean
    */
   final public function update($data, $where = '') {
      if (is_array($where)) $where = $this->sqls($where);
      return $this->db->update($data, $this->table_name, $where);
   }
 
/**
    * 执行删除记录操作
    * @param $where      删除数据条件,不充许为空。
    * @return boolean
    */
   final public function delete($where) {
      if (is_array($where)) $where = $this->sqls($where);
      return $this->db->delete($this->table_name, $where);
   }
  
  
/**
    * 日期时间控件  * @param $name 控件name,id
    * @param $value 选中值 *
@param $isdatetime 是否显示时间
    * @param $loadjs 是否重复加载js,防止页面程序加载不规则导致的控件无法显示
    * @param $showweek 是否显示周,使用,true | false*/
   public static function date($name, $value = '', $isdatetime = 0, $loadjs = 0, $showweek = 'true')
 
   /**
    * 下拉选择框
    */
   public static function select($array = array(), $id = 0, $str = '', $default_option = '') {
      $string = '<select '.$str.'>';
      $default_selected = (empty($id) && $default_option) ? 'selected' : '';
      if($default_option) $string .= "<option value='' $default_selected>$default_option</option>";
      if(!is_array($array) || count($array)== 0) return false;
      $ids = array();
      if(isset($id)) $ids = explode(',', $id);
      foreach($array as $key=>$value) {
         $selected = in_array($key, $ids) ? 'selected' : '';
         $string .= '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
      }
      $string .= '</select>';
      return $string;
   }
 
/**
    * 复选框
    * @param $array 选项 二维数组
    * @param $id 默认选中值,多个用 '逗号'分割
    * @param $str 属性
    * @param $defaultvalue 是否增加默认值 默认值为 -99
    * @param $width 宽度
    */
   public static function checkbox($array = array(), $id = '', $str = '', $defaultvalue = '', $width = 0, $field = '') {
      $string = '';
      $id = trim($id);
      if($id != '') $id = strpos($id, ',') ? explode(',', $id) : array($id);
      if($defaultvalue) $string .= '<input type="hidden" '.$str.' value="-99">';
      $i = 1;
      foreach($array as $key=>$value) {
         $key = trim($key);
         $checked = ($id && in_array($key, $id)) ? 'checked' : '';
         if($width) $string .= '<label class="ib" style="width:'.$width.'px">';
         $string .= '<input type="checkbox" '.$str.' id="'.$field.'_'.$i.'" '.$checked.' value="'.htmlspecialchars($key).'"> '.htmlspecialchars($value);
         if($width) $string .= '</label>';
         $i++;
      }
      return $string;
   }
/*** 单选框
    * @param $array 选项 二维数组
    * @param $id 默认选中值
    * @param $str 属性
    */
   public static function radio($array = array(), $id = 0, $str = '', $width = 0, $field = '') {
      $string = '';
      foreach($array as $key=>$value) {
         $checked = trim($id)==trim($key) ? 'checked' : '';
         if($width) $string .= '<label class="ib" style="width:'.$width.'px">';
         $string .= '<input type="radio" '.$str.' id="'.$field.'_'.htmlspecialchars($key).'" '.$checked.' value="'.$key.'"> '.$value;
         if($width) $string .= '</label>';
      }
      return $string;
   }
 
   /**
    * 获取通过 set_cookie 设置的 cookie 变量
    * @param string $var 变量名
    * @param string $default 默认值
    * @return mixed 成功则返回cookie 值,否则返回 false*/
   public static function get_cookie($var, $default = '') {
      $var = pc_base::load_config('system','cookie_pre').$var;
      return isset($_COOKIE[$var]) ? sys_auth($_COOKIE[$var], 'DECODE') : $default;
   }
 
/**
    * 设置 cookie
    * @param string $var     变量名
    * @param string $value   变量值
    * @param int $time    过期时间
    */
   public static function set_cookie($var, $value = '', $time = 0) {
      $time = $time > 0 ? $time : ($value == '' ? SYS_TIME - 3600 : 0);
      $s = $_SERVER['SERVER_PORT'] == '443' ? 1 : 0;
      $var = pc_base::load_config('system','cookie_pre').$var;
      $_COOKIE[$var] = $value;
      if (is_array($value)) {
         foreach($value as $k=>$v) {
            setcookie($var.'['.$k.']', sys_auth($v, 'ENCODE'), $time, pc_base::load_config('system','cookie_path'), pc_base::load_config('system','cookie_domain'), $s);
         }
      } else {
         setcookie($var, sys_auth($value, 'ENCODE'), $time, pc_base::load_config('system','cookie_path'), pc_base::load_config('system','cookie_domain'), $s);
      }
   }
 
 
 
 
/**
 * 写入缓存,默认为文件缓存,不加载缓存配置。
 * @param $name 缓存名称
 * @param $data 缓存数据
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param $type 缓存类型[file,memcache,apc]
 * @param $config 配置名称
 * @param $timeout 过期时间
 */
function setcache($name, $data, $filepath='', $type='file', $config='', $timeout=0)
 
/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */
function getcache($name, $filepath='', $type='file', $config='') {
/**
 * 删除缓存,默认为文件缓存,不加载缓存配置。
 * @param $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param $type 缓存类型[file,memcache,apc]
 * @param $config 配置名称
 */
function delcache($name, $filepath='', $type='file', $config='') {
public function template_parse($str) {
       $str = preg_replace ( "/\{template\s+(.+)\}/", "<?php include template(\\1); ?>", $str );
       $str = preg_replace ( "/\{include\s+(.+)\}/", "<?php include \\1; ?>", $str );
       $str = preg_replace ( "/\{php\s+(.+)\}/", "<?php \\1?>", $str );
       $str = preg_replace ( "/\{if\s+(.+?)\}/", "<?php if(\\1) { ?>", $str );
       $str = preg_replace ( "/\{else\}/", "<?php } else { ?>", $str );
       $str = preg_replace ( "/\{elseif\s+(.+?)\}/", "<?php } elseif (\\1) { ?>", $str );
       $str = preg_replace ( "/\{\/if\}/", "<?php } ?>", $str );
       $str = preg_replace("/\{for\s+(.+?)\}/","<?php for(\\1) { ?>",$str);
       $str = preg_replace("/\{\/for\}/","<?php } ?>",$str);
       $str = preg_replace("/\{\+\+(.+?)\}/","<?php ++\\1; ?>",$str);     //++ --
       $str = preg_replace("/\{\-\-(.+?)\}/","<?php ++\\1; ?>",$str);
       $str = preg_replace("/\{(.+?)\+\+\}/","<?php \\1++; ?>",$str);
       $str = preg_replace("/\{(.+?)\-\-\}/","<?php \\1--; ?>",$str);
       $str = preg_replace ( "/\{loop\s+(\S+)\s+(\S+)\}/", "<?php \$n=1;if(is_array(\\1)) foreach(\\1 AS \\2) { ?>", $str );
       $str = preg_replace ( "/\{\/loop\}/", "<?php \$n++;}unset(\$n); ?>", $str );
       $str = preg_replace ( "/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/", "<?php echo \\1;?>", $str );
       $str = preg_replace ( "/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/", "<?php echo \\1;?>", $str );
       $str = preg_replace ( "/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/", "<?php echo \\1;?>", $str );
       $str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/es", "\$this->addquote('<?php echo \\1;?>')",$str);
       $str = preg_replace ( "/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s", "<?php echo \\1;?>", $str );
       $str = preg_replace("/\{pc:(\w+)\s+([^}]+)\}/ie", "self::pc_tag('$1','$2', '$0')", $str);
       $str = preg_replace("/\{\/pc\}/ie", "self::end_pc_tag()", $str);
       $str = "<?php defined('IN_PHPCMS') or exit('No permission resources.'); ?>" . $str;
       return $str;
    }
      $where = '';  //查找
      if ($_POST ['dosubmit']) {
         extract ( $_POST ['info'] );
         if ($card_g_id) {$where .= "and `card_g_id` = '$card_g_id' "; // 游戏名}
         if ($start_addtime && $end_addtime) {
            $start = strtotime ( $start_addtime . ' 00:00:00' );
            $end = strtotime ( $end_addtime . ' 23:59:59' );
            $where .= "AND `card_lqdate` >= '$start' AND `card_lqdate` <= '$end' ";
}
         if ($stype && $keywords) {
            switch ($stype) {
                case 'cardsn' :
$where .= "AND `card_sn` = '$keywords' ";
break;
                case 'card_lquser' :
$where .= "AND `card_lquser` like '%$keywords%' ";
break;
                case 'card_lqareaid' :$where .= "AND `card_lqareaid` = '$keywords' ";break;
            }
         }
      }
      if ($where)  $where = substr ( $where, 3 );
      $page = isset ( $_GET ['page'] ) && intval ( $_GET ['page'] ) ? intval ( $_GET ['page'] ) : 1;
      $infos = $this->db_gamecard->listinfo ( $where, $order = 'card_id DESC', $page, $pages = '20' );
      $pages = $this->db_gamecard->pages;
 
<script type="text/javascript">
 function edit(id, name) {
      window.top.art.dialog({id:'edit'}).close();
      window.top.art.dialog(
         {
            title:'修改 '+name+' ',
            id:'edit',
            iframe:'?m=game&c=game&a=addmt&id='+id,
            width:'600',
height:'300'
         },
        
         function(){
                var d = window.top.art.dialog({id:'edit'}).data.iframe;
                var form = d.document.getElementById('dosubmit');
                form.click();
                return false;
            },
 
         function(){
                window.top.art.dialog({id:'edit'}).close();
                }
      );
   }
 </script>
 
<script type="text/javascript">
$(function(){
   $.formValidator.initConfig({autotip:true,formid:"re_myform",onerror:function(msg){}});
 
   $("#re_username").formValidator({onshow:"请输入用户名",onfocus:"用户名6到20位"})
   .inputValidator({min:6,max:20,onerror:"用户名6到20位"})
   .regexValidator({regexp:"ps_username",datatype:"enum",onerror:"用户不能为空"});
 
   $("#re_password").formValidator({onshow:"请输入密码",onfocus:"密码在6-20位"})
   .inputValidator({min:6,max:20,onerror:"密码在6-20位"});
   $("#pwdconfirm").formValidator({onshow:"请输入重复密码",onfocus:"请输入重复密码",oncorrect:"格式正确"})
   .compareValidator({desid:"re_password",operateor:"=",onerror:"密码不一致"});
 
   $("#code").formValidator({onshow:"请输入验证码",onfocus:"验证码不能为空"})
   .inputValidator({min:1,max:999,onerror:"验证码不能为空"})
   .ajaxValidator({
       type : "get",url : "",data :"m=pay&c=deposit&a=public_checkcode",datatype : "html",async:'false',
      success : function(data){  
            if(data == 1){return true;}
            else{return false;}
      },
      buttons: $("#dosubmit"),
      onerror : "验证码错误",
      onwait : "验证中..."
   });
   })

您可能还喜欢...

发表回复