<?php
//验证URL是否重复
function checkUrl($table,$url){
	$re = M($table)->where(array('url'=>$url))->find();
	if($re){
		return $re['id'];
	}else{
		return false;
	}
}

//获取分类
function getCatSon($arr,$html='&nbsp;&nbsp;└ '){
	if(!count($arr)){
		return '';
		exit;;
	}
	$return = array();
	foreach($arr as $v){
		$return[] = $v;
		if($v['level'] == 1){
			$return = array_merge($return,getCatChild($v['id'],$html));	
		}
	}
	return $return;
	
}
//获取分类子分类
function getCatChild($pid,$html){
	$db = M('category');
	$init = $db->where(array('pid'=>$pid))->select();
	$return = array();
	foreach($init as $v){
		$v['name'] = $html.$v['name'];
		$return[] = $v;
		if($v['level'] == 1){
			$return = array_merge($return,getCatChild($v['id'],'&nbsp;&nbsp;'.$html));	
		}
	}
	return $return;
}

//获取导航
function getNavSon($arr,$html='&nbsp;&nbsp;└ '){
	if(!count($arr)){
		return '';
		exit;;
	}
	$return = array();
	foreach($arr as $v){
		$return[] = $v;
		if($v['level'] == 1){
			$return = array_merge($return,getNavChild($v['id'],$html));	
		}
	}
	return $return;
	
}
//获取导航子导航
function getNavChild($pid,$html){
	$db = M('navigation');
	$init = $db->where(array('pid'=>$pid))->select();
	$return = array();
	foreach($init as $v){
		$v['name'] = $html.$v['name'];
		$return[] = $v;
		if($v['level'] == 1){
			$return = array_merge($return,getCatChild($v['id'],'&nbsp;&nbsp;'.$html));	
		}
	}
	return $return;
}
