<?php
    $conf_basedir	= "../../";	//相对主目录的位置
    $conf_where		= "admin";	//选择调用相应模块
    //$directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
    include_once($conf_basedir."base.inc.php");
    checkAuth('90');	//判断登录和权限
    

	//if ($actiontype) doaction($actiontype,$actionid);
	
    $css="<link href='http://esfadmin.house365.com/script/css/autocomplete.css' rel='stylesheet' type='text/css' />";
    $js = "<script type='text/javascript' src='http://esfadmin.house365.com/script/js/showpic.js'></script>
    <script type='text/javascript' src='http://esfadmin.house365.com/script/js/public.js'></script>
    <script type='text/javascript' src='http://esfadmin.house365.com/script/js/formValidator.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.core.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.position.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.widget.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.autocomplete.js'></script>";
    
    $tbl='mobile_broker_shop';

   	if (($action<>"modify")and ($action<>'add')and($action<>"update")and($action<>"insert")) die("无效操作");

	$esta_arr=array('1'=>'有效','2'=>'无效');
	$type_arr=array('sell'=>'二手房','rent'=>'租房');

	if ($action == 'modify'&&$id!='') {

		$id=intval($id);
		$q="select * from $tbl where id=$id " ;
		$data_info=$dbback->GetRow($q);
		
		$data_info[addtime]=date('Y-m-d',$data_info['addtime']);
		$data_info[astime]=date('Y-m-d',$data_info['astime']);
		$data_info[blockname]=$dbback->GetOne("select blockname from block where id='".$data_info[blockid]."'");
		$data_info[username]=$dbback->GetOne("select username from broker where uid='".$data_info[uid]."'");
	}

	if ($action == 'insert') {
	
	    //产生数据
			$ss = array();
			$ss[blockid]=$dbback->GetOne("select id from block where blockname='".trim($blockname)."'");
			$ss[uid]=$dbback->GetOne("select uid from broker where username='".trim($username)."'");
			$ss[type]=$type;
			$ss[addtime]=time();
			$ss[astime]=strtotime($astime);
			$ss[esta]=$esta;  
	
	    //写入数据库
	    $q = insert_sql($tbl, $ss);

		//echo $q;
	
		$db->Execute($q);
	
	    echo "<script>alert('添加成功');window.close();</script>";
	}

	if($action == 'update'){

			$id=intval($id);

			$ss=array();
			$ss[blockid]=$dbback->GetOne("select id from block where blockname='".trim($blockname)."'");
			$ss[uid]=$dbback->GetOne("select uid from broker where username='".trim($username)."'");
			$ss[type]=$type;
			$ss[astime]=strtotime($astime);
			$ss[esta]=$esta;
			
			$q = update_sql($tbl, $ss, " where id = $id");

			//echo $q;

			$db->Execute($q);
		
			echo "<script>alert('已成功修改');window.close();</script>";
	}

    //引用模版文件
    include_once(Template("header"));
    include_once(Template("mobile/broker_shop_modify"));
    include_once(Template("footer"));
?>