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

	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/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';

    //顶部查询部分开始
    $wherecond = "1=1";

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

	$cond_arr_2=array();
	$cond_arr_2[""]	="全部";
    //$cond_arr_2["youlian_user_a"]	="友链管理员A";
	//$cond_arr_2["youlian_user_b"]	="友链管理员B";
    //$cond_arr_2["youlian_user_c"]	="友链管理员C";
    //$cond_arr_2["youlian_user_d"]	="友链管理员D";
	$cond_arr_2["youlian_user_a"]	="youlian_user_a";
	$cond_arr_2["youlian_user_b"]	="youlian_user_b";
    $cond_arr_2["youlian_user_c"]	="youlian_user_c";
    $cond_arr_2["youlian_user_d"]	="youlian_user_d";

    $cond_arr_3=array();
    $cond_arr_3["0"] ="全部";
    $cond_arr_3["a"] ="有效";
    $cond_arr_3["b"] ="无效";

	if(in_array($_SESSION[$web_auth]["username"],array("youlian_user_a","youlian_user_b","youlian_user_c","youlian_user_d")))
	{
		$addname = $_SESSION[$web_auth]["username"];
		$cond_arr_2 = '';
		$cond_arr_2[$addname] = $addname;
	}

    //$cond_district_1	= tonyForm("select","cond_s_3",$conf_house['district'],$cond_s_3);

    //$cond_search_1	= tonyForm("select","type",$cond_arr_1,$type);
    $cond_search_2	= tonyForm("select","addname",$cond_arr_2,$addname);
	$cond_search_3	= tonyForm("select","status",$cond_arr_3,$status);

    //查询条件处理开始
	if($type == 1){
		$wherecond.= " and type = '".$type."'";
		if(!empty($keyword)){
			$wherecond.= " and typename = '".$keyword."'";
		}
	}else if($type == 2){
		$wherecond.= " and type = '".$type."'";
		if(!empty($district)){
			$wherecond.= " and typename = '".$district."'";
		}
	}else if($type == 3){
		$wherecond.= " and type = '".$type."'";
		if(!empty($street_id)){
			$wherecond.= " and typename = '".$street_id."'";
		}
	}
	if(!empty($addname)){
		$wherecond.= " and addname = '".$addname."'";
	}
	if($status == 'a'){
		$wherecond.= " and status = 1";
	}else if($status == 'b'){
		$wherecond.= " and status = 0";
	}

	if(!empty($start_time) || !empty($end_time))
	{
		if(empty($start_time)){
			$stime = strtotime("2014-7-1 00:00:01");
		}else{
			$stime = strtotime($start_time." 00:00:01");
		}
		if(empty($end_time)){
			$etime = time();
		}else{
			$etime = strtotime($end_time." 23:59:59");
		}
		$wherecond.= " and ctime BETWEEN ".$stime." AND ".$etime." ";
	}

    //查询条件处理结束

    //分页参数
    $pagesize	= 20;
    $page_now	= $page_now ? max(1, intval($page_now)) : 1 ; // 获取当前页数
    $offset		= ( $page_now - 1 ) * $pagesize;


    //获得数据总条数
    $sql = "select COUNT(*) from $tbl  where ".$wherecond;
    $totalrows = $dbback->GetOne($sql);
    $numrows=$totalrows;

    //获得数据当前页面数据
    $sql = "select * from $tbl where  $wherecond  ORDER BY id DESC  LIMIT ".$offset.",".$pagesize." ";
    $data_info = $dbback->GetAll($sql);
	if(is_array($data_info)){
		foreach($data_info as $k => $v){
			$data_info[$k]['type'] = $cond_arr_1[$v['type']];
			$data_info[$k]['linkname'] = "<a target='_black' href='".$v['url']."'>".$v['linkname']."</a>";
			//$data_info[$k]['addname'] = $cond_arr_2[$v['addname']];
			$data_info[$k]['ctime'] = date("Y-m-d H:i",$v['ctime']);
			if($v['status'] == 0){
				$data_info[$k]['failtime'] = date("Y-m-d H:i",$v['failtime']);
				$data_info[$k]['status'] = "无效";
			}else{
				$data_info[$k]['status'] = "有效";
			}
			if($v['type'] == 3){
				$sqlstr = "select streetname from street where id='" . $v["typename"] . "'";
				$street_str = $db->GetRow($sqlstr);
				$data_info[$k]['typename'] = $street_str['streetname'];
			}
		}
	}

    $pagenum = count($data_info);//当前页面数量

    $numrows = $numrows >0 ? $numrows : 0;
    if( $numrows <= 0 || $pagenum <=0){
        $pages = 0 ;  //计算总页数
    }else{
        $pages = ceil($numrows/$pagesize) ;  //计算总页数
        $new_pagenavi = new_pagenavi2($page_now,$pages,$numrows);
    }
	if(!empty($district)){
		$house['street'] = $dbback->GetAssoc("select id,streetname from street where district='$district'");
	}

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