<?php
/*-------------------------------------
	版权所有：南京牛昆网络科技有限公司（TEL-15896098989）
	程序版本：1.0
	更新日期：//last modified on 2015-06-10  
-------------------------------------*/
class nav
{
	private $db;
	private $table;

	function __construct()
	{
		global $db;
		$this->db=$db;
		$this->table=LA_PRE.'nav';
	}
	
	function navlist($typeid=0,$parentid=0)
	{
		global $page,$_siteid,$siteidobj,$LA;
		$typeid=intval($typeid);
		$parentid=intval($parentid);

		$where=$_siteid?'siteid IN('.implode(',',$siteidobj->getchildid($_siteid)).') AND (template=\'\' OR template=\''.$LA['template'].'\')':'(template=\'\' OR  template=\''.$LA['template'].'\')';
		$where.=$typeid?' AND typeid='.$typeid:'';
		$where.=$parentid?' AND parentid='.$parentid:' AND parentid=0';

		return $this->db->fetch_all("SELECT * FROM `$this->table` WHERE $where ORDER BY orderby ASC");
	}

	function set($parentid=0,$typeid=0,$ids,$old_orderby,$old_name,$old_url,$old_color,$orderby,$name,$url,$color)
	{
		global $cacheobj,$LA;
		$this->db->query("DELETE FROM `$this->table` WHERE `$this->table`.`parentid`=$parentid AND `$this->table`.`typeid`=$typeid AND `$this->table`.`template`='".$LA['template']."'");
		if($ids)foreach($ids as $id)
		{
			$info=array();
			if($old_name[$id])
			{
				$info['id']=$id;
				$info['template']=$LA['template'];
				$info['typeid']=$typeid;
				$info['parentid']=$parentid;
				$info['orderby']=$old_orderby[$id];
				$info['name']=$old_name[$id];
				$info['url']=$old_url[$id];
				$info['color']=$old_color[$id];
				$info['siteid']=$_SESSION['siteid'];
				$this->db->insert($this->table,$info,true);
			}
		}

		if($name)foreach($name as $key => $val)
		{
			$info=array();
			if($val)
			{
				$info['typeid']=$typeid;
				$info['template']=$LA['template'];
				$info['parentid']=$parentid;
				$info['orderby']=$orderby[$key];
				$info['name']=$name[$key];
				$info['url']=$url[$key];
				$info['color']=$color[$key];
				$info['siteid']=$_SESSION['siteid'];
				$this->db->insert($this->table,$info,true);
			}
		}
		
		$cacheobj->clear();
		return true;
	}

	function get($id)
	{
		$id=intval($id);
		return $this->db->fetch_one("SELECT * FROM `$this->table` WHERE `$this->table`.`id`=$id");
	}
}
