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

	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='friend_link';
	//$title="返回上一页";

   if (($action<>"save") and ($action<>'edit')) exit;

if ($action == 'save') {

	$where = " id = ".$id;
	$admin_arr = array("youlian_user_a","youlian_user_b","youlian_user_c","youlian_user_d");
	$username =  $_SESSION[$web_auth]["username"];
	if (in_array($username,$admin_arr))
	{
		$where .= " and addname = '".$username."'";
	}

	$sql = "select * from $tbl where ".$where;
	$data_infos = $dbback->GetRow($sql);
	if(empty($data_infos)) exit;

    $data = array();
    $data["type"] = $type;
	if($data["type"] == 1){
		$data["typename"] = $keyword;
		if($data["typename"] == ""){
			echo "<script>alert('小区名称不能为空');history.go(-1);</script>";
			exit;
		}
	}else if($data["type"] == 2){
		$data["typename"] = $district;
		if($data["typename"] == ""){
			echo "<script>alert('请选择区属');history.go(-1);</script>";
			exit;
		}
	}else if($data["type"] == 3){
		$data["typename"] = $streetid;
		if($data["typename"] == ""){
			echo "<script>alert('请选择板块');history.go(-1);</script>";
			exit;
		}
	}else{
		echo "<script>alert('请选择类型');history.go(-1);</script>";
		exit;
	}
	$data["linkname"] = $linkname;
	if($data["linkname"] == ""){
		echo "<script>alert('友情链接标题不能为空');history.go(-1);</script>";
		exit;
	}
	$data["url"] = $url;
	if($data["url"] == ""){
		echo "<script>alert('友情链接URL不能为空');history.go(-1);</script>";
		exit;
	}

	$sql = update_sql($tbl, $data, " where id = '".$id."'");
    $db->Execute($sql);

    echo "<script>window.opener.location.reload();alert('修改成功');window.close();</script>";
	exit;
 }

if($id < 1) exit;

$where = " id = ".$id;
$admin_arr = array("youlian_user_a","youlian_user_b","youlian_user_c","youlian_user_d");
$username =  $_SESSION[$web_auth]["username"];
if (in_array($username,$admin_arr))
{
	$where .= " and addname = '".$username."'";
}

$sql = "select * from $tbl where ".$where;
$data_info = $dbback->GetRow($sql);

if(empty($data_info)) exit;

$cond_arr_1=array();
$cond_arr_1["0"]		="全部";
$cond_arr_1["1"]	    ="小区";
$cond_arr_1["2"]	    ="区属";
$cond_arr_1["3"]	    ="板块";

if($data_info['type'] == 3){
	$street_str = $db->GetRow("select district from street where id='" . $data_info["typename"] . "'");
	if($street_str["district"] != ""){
		$condext = " WHERE district ='".$street_str["district"]."'";
	}
	$district_str = $street_str["district"];
}else if($data_info['type'] == 2){
	if($data_info["typename"] != ""){
		$condext = " WHERE district ='".$data_info["typename"]."'";
	}
	$district_str = $data_info["typename"];
}


$empty = array (""=>"请选择");
$streetsql = "SELECT id,streetname FROM street ".$condext;
$streetlistsu = $db->GetAssoc($streetsql);
if($streetlistsu){
	$house['street']	= $empty+$streetlistsu;
}else{
	$house['street']	= $empty;
}

if($conf_city=='nj')
{
	$house['cbd']		= $empty+$db->GetAssoc("SELECT id,cbdname FROM cbd");
}

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