gusucode.com > 同城苏州黄页系统php源码程序 > lib/webPge.class.php
<? if( !class_exists('lastAbstract') ) include_once( dirname(__FILE__)."/lastAbstract.class.php" ); if( !class_exists('field') ) include_once( dirname(__FILE__)."/field.class.php" ); if( !class_exists('column') ) include_once( dirname(__FILE__)."/column.class.php" ); class webPge extends lastAbstract { var $name = ''; var $extend = ''; var $fields = array(); var $columns = array(); var $data = array(); var $record_id = 0; var $formName = ''; var $dbtable = ''; # 一些特殊字段名 var $primary_key = 'id'; // 主键 var $isopen_column_name = ''; // is_open 字段 为空表示不需要开启此功能 var $parent_column_name = ''; // parent 字段 为空表示不需要开启此功能 /*var $open_state_word = '<font style="background-color: green; padding-right: 3px; padding-left: 3px;color: #FFFFFF;">已审核</font>'; var $close_state_word = '<font style="background-color: red; padding-right: 3px; padding-left: 3px;color: #FFFFFF;">未审核</font>'; var $open_act_word = '省核通过'; var $close_act_word = '撤销发布';*/ var $status_column_name = 'is_open' ; var $status = array( '1' => array( 'act_word' => '审核通过', 'flag' => '<font style="background-color: green; padding-right: 3px; padding-left: 3px;color: #FFFFFF;">已审核</font>' ), '0' => array( 'act_word' => '等待审核', 'flag' => '<font style="background-color: gray; padding-right: 3px; padding-left: 3px;color: #FFFFFF;">等待审核</font>' ), '-1' => array( 'act_word' => '禁止', 'flag' => '<font style="background-color: red; padding-right: 3px; padding-left: 3px;color: #FFFFFF;">已禁止</font>' ), ); function webPge() { $this->lastAbstract(); $this->template_dir = $this->root_path."template/"; $this->compile_dir = $this->root_path."smarty_data/templates_c/"; $this->config_dir = $this->root_path."smarty_data/configs/"; $this->cache_dir = $this->root_path."smarty_data/cache/"; $this->left_delimiter = "<%"; $this->right_delimiter = "%>"; $this->referer = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; $this->_REQUEST = $_REQUEST; } function fill_field_value($date) { foreach ($this->fields as $key=>$fld) { if( isset($date[$fld->name]) ) $this->fields[$key]->value=$date[$fld->name]; } } # 页面显示 函数 --------------------------------- function show_input() { # 参数表 $parameter=array(); $parr = func_get_args(); $fieldName = array_shift($parr); // 第一个参数 是 栏位名 while( $pstr=array_shift($parr) ) { $arr = explode(':',$pstr) ; $key = array_shift($arr); $val = implode( ':', $arr ) ; $parameter[$key] = $val; } if( !isset($this->fields[$fieldName]) ) return "错误:此网页没有声明此栏位对象 {$fieldName}。<br>\r\n"; else { # 登记 需要通过 js 检验的表单 if( $this->fields[$fieldName]->checkType!='ignore' ) $this->check_inputs[]=$this->fields[$fieldName]->inputName; return $this->fields[$fieldName]->show_input( $this,$parameter ); } } function show_all_input() { foreach ($this->fields as $key=>$item) print $item->caption.':'.$item->show_input()."\r\n<br>"; } function show_caption($fieldName) { if( !isset($this->fields[$fieldName]) ) return "错误:此网页没有声明此栏位对象 {$fieldName}。<br>\r\n"; else return $this->fields[$fieldName]->show_caption(); } function show_icon($fieldName) { if( !isset($this->fields[$fieldName]) ) return "错误:此网页没有声明此栏位对象 {$fieldName}。<br>\r\n"; else return $this->fields[$fieldName]->show_icon(); } function show_txt($fieldName) { if( !isset($this->fields[$fieldName]) ) return "错误:此网页没有声明此栏位对象 {$fieldName}。<br>\r\n"; else return $this->fields[$fieldName]->show_txt(); } function show_pic($fieldName) { if( !isset($this->fields[$fieldName]) ) return __CLASS__.'::'.__FUNCTION__."()函数遇到错误:此网页没有声明此栏位对象 {$fieldName}。<br>\r\n"; if( $this->fields[$fieldName]->inputType!='picture' ) return __CLASS__.'::'.__FUNCTION__."()函数遇到错误:栏位对象的输入类型必须为 picture;指定的栏位 {$fieldName} 输入类型为 {$this->fields[$fieldName]->inputType}<br>\r\n"; return $this->fields[$fieldName]->show_pic(); } function show_status( $status='' ) { if( empty($status) ) $status = $this->data[ $this->status_column_name ] ; if( !isset( $this->status[$status] ) ) return __CLASS__.'::'.__FUNCTION__."()函数遇到错误:此网页没有定义属性:status_column_name 或 定义的该属性有误。<br>\r\n"; return $this->status[$status]['flag'] ; } function set_data() { foreach ($this->columns as $key=>$item) { if( !isset($this->data[$item->columnName]) ) { $this->bad("webpage::set_data()异常;实际数据表中没有字段:{$item->columnName},此字段无法完成初始化。"); continue; } if( $this->columns[$key]->set_data($this->data[$item->columnName])===false ) { # 从column 对象中获得 异常信息 $this->get_other_msg($this->columns[$key]); continue; } } return true ; } function get_data() { foreach ($this->columns as $key=>$item) { if( false === ( $value = $this->columns[$key]->get_data() ) ) # 异常处理 { # 从column 对象中获得 异常信息 $this->get_other_msg($this->columns[$key]); continue; } # 无需数据库操作的栏位 if( $value == '--null--' ) continue; $this->data[$item->columnName] = $value; } return true; } function add_field($fldName,$class_path='') { // 添加实例 if( !$this->fields[$fldName] = $this->get_fld_clm_obj('field',$fldName,$class_path) ) { $this->get_other_msg($this->fields[$fldName]); pp($this->system_msg); } } function add_column($clmName,$class_path='') { // 添加实例 if( !$this->columns[$clmName] = $this->get_fld_clm_obj('column',$clmName,$class_path) ) $this->get_other_msg($this->columns[$clmName]); } function get_fld_clm_obj($type,$objName,$class_path='') { $className = ( ($type=='field')?'fld_':'clm_' ).esc_var_name($objName); if( empty($class_path) ) $class_path = "{$this->root_path}lib/class.{$type}/{$className}.class.php"; if( !class_exists($className) ) include $class_path; $obj = new $className( $this ); return $obj; } function display_webPge( $templateName, $at_once = true ) { # 语言包 if( $this->if_multilang ) { if( file_exists( $this->template_dir.$this->current_lang ) and is_dir($this->template_dir.$this->current_lang) ) $templateName = $this->current_lang .'/'. $templateName; } # 全局变量 $this->assign( '_SERVER',$_SERVER ); $this->assign( '_SESSION', @$_SESSION ); $this->assign( '_GET', @$_GET ); $this->assign( '_POST', @$_POST ); $this->assign( '_REQUEST', @$_REQUEST ); unset($_REQUEST['PHPSESSID']); $this->assign( '_REQUEST_SN', http_build_query() ); $this->assign( 'this_url', $this->site_url.$_SERVER['REQUEST_URI'] ); $this->assign('me',$this); if( $at_once ) $this->display($templateName); else return $this->fetch($templateName); if( $this->debug>=9 ) print $this->run_time('网页完成'); } } ?>