gusucode.com > 同城苏州黄页系统php源码程序 > lib/detailPge.class.php

    <?
if( !class_exists('FldClm_Container') )
	include_once($root_path."lib/webPge.class.php");
class detailPge extends webPge
{
	var $check_inputs			= array();
	var $act					= '';	
	var $isopen_default_state	= '1';			// 刊登一笔记录后, is_open 的预设状态
	
	var $successed ;
	
#### 私有函數 #####################################################

#### 公有函數 #####################################################

	function detailPge()
	{
		if( !empty($_REQUEST['act']) )
			$this->act = $_REQUEST['act'];

		$this->webPge();
	}

	
	/**
	 * 输出检验表单的 js 格式列表
	 *
	 * @return unknown
	 */
	function out_js_checkValue_list()
	{
		$str='';
		foreach ($this->check_inputs as $inputName)
		{
			if( !empty($str) )
				$str.=',';
			
			$str.="'{$inputName}'";
		}
		
		return "new Array({$str})";
	}
	
	function _get_db_data($where='1',$record_id=0)
	{
		$sql="select * from `$this->dbtable` where {$where}";
		if( !$r=mysql_query($sql) )
		{
			$this->bad('webpage::get_db_data()数据库查询错误;'.mysql_error());
			return false;
		}
		
		if( !mysql_num_rows($r) )
		{
			$this->bad("webpage::get_db_data()数据库查询异常;数据表:{$this->dbtable}内没有相关纪录(... where {$where})。");
			return false;
		}

		$this->data=mysql_fetch_assoc($r);

		if( $record_id > 0 )
			$this->record_id = $record_id;
		return true;
	}

	# 刊登和修改 相关函数 ---------------------------------
	/**
	 * 从数据库查询出数据 保存到 $this->data中
	 *
	 * @param unknown_type $where
	 */
	function get_db_data($where='1',$record_id=0)
	{
		if( !$this->_get_db_data( $where, $record_id ) )
			return false ;

		$this->set_data();
		return true ;
	}
	
	/**
	 * 从用户提交的表单中获取数据 保存到 $this->data中
	 *
	 */
	function get_input_data()
	{	
		foreach ($this->fields as $key=>$item)
		{
			if( empty($this->fields[$key]->inputType) )
				continue;

			$this->fields[$key]->get_data($this->act);		// 从用户提交的表单中 获得 数据 到栏位对象
			$this->get_other_msg($this->fields[$key]);		// 从 栏位对象中 获得 执行信息
		}
		
		$this->get_data();
		return true;
	}

	function insert_dbtab()
	{
		if( empty($this->act) )
		{
			$this->bad('webpage::insert_dbtab()遇到错误:$this->act属性必须存在。');
			return false;
		}

		if( empty($this->dbtable) )
		{
			$this->bad('webpage::insert_dbtab()遇到错误:$this->dbtable属性必须存在。');
			return false;
		}		
		
		if( empty($this->data) )
		{
			if( !$this->get_data() )
				return false;
		}
		
		# is_open 字段
		if( !empty($this->isopen_column_name) and !isset($this->data[ $this->isopen_column_name ]) )
		{
			echo $this->data[ $this->isopen_column_name ] = $this->isopen_default_state ;
		}

		foreach($this->data as $key=>$value)
		{
			$fld[]="`$key`";
			$values[]="'$value'";
		}
		$fld=implode(',',$fld);
		$values=implode(',',$values);
		
		$sql_str="insert into `{$this->dbtable}` ({$fld}) values ({$values})";
		if( $this->debug >= __DEBUG_OUTSQL )
			pp($sql_str);
		if( $this->debug >= __DEBUG_OUTDATA )
			pp($this->data);

		if( mysql_query($sql_str) )
		{
			// $this->ok('保存成功。');
			$this->record_id = mysql_insert_id();		// 纪录id
			return true;
		}
		else
		{
			$this->bad(mysql_error());
			return false;
		}
	}
	
	function update_dbtab($where='1')
	{
		if( empty($this->act) )
		{
			$this->bad('webpage::update_dbtab()遇到错误:$this->act属性必须存在。');
			return false;
		}

		if( empty($this->dbtable) )
		{
			$this->bad('webpage::update_dbtab()遇到错误:$this->dbtable属性必须存在。');
			return false;
		}

		if( empty($this->data) )
		{
			if( !$this->get_data() )
				return false;
		}
		
		foreach($this->data as $key=>$value)
		{
			$values[]="`$key`='$value'";
		}
		$sql_str=implode(',',$values);
		$sql_str="update `{$this->dbtable}` set $sql_str where {$where}";
		
		if( $this->debug >= __DEBUG_OUTSQL )
			pp($sql_str);
		if( $this->debug >= __DEBUG_OUTDATA )
			pp($this->data);

		if( mysql_query($sql_str) )
		{
			// $this->ok('更新成功。');
			return true;
		}
		else
		{
			$this->bad(mysql_error());
			return false;
		}
	}


	/**
	 * 将栏位中的数据传递到另一个 smarty 对象中
	 *
	 * @param unknown_type $t
	 * @param unknown_type $fields
	 */
	function display_fields(&$t,$value_name='',$fields='all')
	{
		if($fields=='all')					// 全部
			$fields=array_keys($this->fields);
		elseif ( !is_array($fields) )		// 单个栏位,可不使用数组传递
			$fields=array($fields);
		
		
		// 开始
		$arr=array();
		foreach ($fields as $theFld)
			$arr[$theFld]=$this->show_txt($theFld);


		// 输出
		if( !empty($value_name) )
			$t->assign($value_name,$arr);
		else
			$t->assign($arr);

		
		// 完成
		return true;
	}
	
	
	/**
	 * 检查重复
	 * 
	 * 如注册时检查用户名
	 *
	 * @param unknown_type $columnName	须检查的字段对象名称
	 * @return unknown
	 */
	function checkRepeat( $columnName )
	{
		if( !isset($this->columns[$columnName]) )
		{
			$this->bad( __CLASS__.'::'.__FUNCTION__.'()函数 遇到错误,指定的字段{$columnName} 不存在。');
			return false;
		}

		global $db;
		$sql = "select * from `{$this->dbtable}` where `{$this->columns[$columnName]->columnName}`='{$this->columns[$columnName]->data}'";
		if( $db->getrow( $sql ) )
			return true;
		else 
			return false;
	}


}
?>