<?php

/**
 * Copyright (C) 2009 Wskm Inc.All rights reserved.  
 * [Gart] www.wskmphp.com 
 * $Id: nav.php 17 2010-08-26 11:37:04Z ws99 $ 
 */

!defined('IN_ART') && exit('Access Denied');

class adminmod_nav extends wskm_model_abstract
{
	function getAdminList()
	{
		return $this->db->fetch_all('SELECT * FROM '.TABLE_PREFIX.'nav ORDER BY displaysort DESC ');
	}

	function getList(){
		return $this->db->fetch_all('SELECT * FROM '.TABLE_PREFIX.'nav WHERE status=1 ORDER BY displaysort DESC ');
	}

	function getAdminInfo($id){
		return $this->db->fetch_first('SELECT * FROM '.TABLE_PREFIX."nav WHERE id='{$id}'");
	}

	function updateNav($data,$nid)
	{
		return $this->db->update(TABLE_PREFIX.'nav',$data," id='$nid' ") !== false;
	}

	function insertNav($data){
		return $this->db->insert(TABLE_PREFIX.'nav',$data) !== false;
	}

	function del($nid){
		return $this->db->delete(TABLE_PREFIX.'nav'," id='{$nid}' ") !== false;
	}

	function updateCache(){
		$query=$this->db->query('SELECT plugintitle,pluginname,hook FROM '.TABLE_PREFIX."plugins WHERE status=1 AND isnav=1 ");
		$pluginnav=array();
		while ($tempi=$this->db->fetch($query)){
			if ($tempi['hook']) {
				$tempi['hook']=unserialize($tempi['hook']);
			}

			$tempi['target']=0;
			if ($tempi['hook']['navurl'] && $tempi['hook']['navname']) {
				$tempi['name']=$tempi['hook']['navname'];
				$tempi['url']= ART_URL.$tempi['hook']['navurl'];

				unset($tempi['plugintitle'],$tempi['pluginname'],$tempi['hook']);

				$tempi['key']=basename($tempi['url']);
				$tempi['key']=substr($tempi['key'],0,strpos($tempi['key'],'.'));
				$pluginnav[]=$tempi;
			}

		}

		$query=$this->db->query('SELECT * FROM '.TABLE_PREFIX.'nav WHERE status=1 ORDER BY displaysort DESC ');
		$navs=array();
		while ($tempi=$this->db->fetch($query)){
			$tempi['key']=basename($tempi['url']);
			$tempi['key']=substr($tempi['key'],0,strpos($tempi['key'],'.'));
			$navs[]=$tempi;
		}

		writeCacheSystem('nav',array_merge($navs,$pluginnav));
	}
}
?>