<?php
/*
$home['sn']=$home_sn;
$home['title']=$home_title;
$home['url']=$home_url;

$title_arr[$sn]=$title;
$cate_arr[$sn]=$of_sn;
$url_arr[$sn]=$url;
*/
include_once "../../mainfile.php";


class dtree{
	var $name;
	var $title_arr;
	var $cate_arr;
	var $url_arr;
	var $home;

	//建構函數
	function dTree($name="",$home="",$title_arr="",$cate_arr="",$url_arr=""){
		$this->name=$name;
		$this->title_opt=$title_arr;
		$this->cate_opt=$cate_arr;
		$this->url_opt=$url_arr;
		$this->home=$home;
	}

	//產生選單
	function render(){
    if(empty($this->home)){
      $opt="{$this->name}.add(0,-1,'','javascript: void(0);');\n";
    }else{
      $opt="{$this->name}.add({$this->home['sn']},-1,'{$this->home['title']}','{$this->home['url']}');\n";
    }
    foreach($this->title_opt as $ncsn => $title){
      $opt.="{$this->name}.add($ncsn , {$this->cate_opt[$ncsn]} , '{$title}' , '{$this->url_opt[$ncsn]}');\n";
    }
    if(!defined(_TAD_HAVE_DTREE)){
		  $dtree="<link rel='StyleSheet' href='".XOOPS_URL."/Frameworks/tadtools/dtree/dtree.css' type='text/css' />
      <script type='text/javascript' src='".XOOPS_URL."/Frameworks/tadtools/dtree/dtree.php'></script>";
    }
    $dtree.="
    <script type='text/javascript'>
    {$this->name} = new dTree('{$this->name}');
    {$this->name}.config.useCookies=true;
    {$opt}
    document.write({$this->name});
    </script>
    <p>
    <a href='javascript: {$this->name}.openAll();' style='font-size:11px;'>"._MB_TADNEW_EXPAND_ALL."</a> | <a href='javascript: {$this->name}.closeAll();' style='font-size:11px;'>"._MB_TADNEW_CONTACT_ALL."</a>
    </p>";
    define("_TAD_HAVE_DTREE",true);
    return $dtree;
  }
}
?>
