<?php
require_once("../../libs/adodb/adodb.inc.php");
require_once("../../config.inc.php");
$db = NewADOConnection('mysql');
//$db->debug = true;
$db->Connect($DB,$USR,$PWD,$DBNAME);
$db->Query("Set Names 'utf8'");
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

$htmlcode="";
$rs = $db->Execute("select * from dcms_channel order by channel_order asc");
if (!$rs->EOF){
	while(!$rs->EOF){
		$channel_id=$rs->fields["channel_id"];
		$class2='';
		$strsql="select * from dcms_class where channel_id=$channel_id order by class_order asc";
		$trs = $db->Execute($strsql);
		if (!$trs->EOF){
			while(!$trs->EOF){
				$class_id=$trs->fields["class_id"];
				$class3='';
				// three
				$strsql="select * from dcms_class where class_pid=$class_id order by class_order asc";
				$ors = $db->Execute($strsql);
				if (!$ors->EOF){
					while(!$ors->EOF){
						$class3_t=StrWrap($ors->fields["class_name"],"\"").":".StrWrap($ors->fields["class_id"],"\"").",";
						$class3 = $class3.$class3_t;
						$ors->MoveNext();
					}
					$class3=substr($class3,0,strlen($class3)-1);
					$ors->Close();
				}
				// end three		
				$class2_t=StrWrap($trs->fields["class_name"],"\"").":{val:".StrWrap($trs->fields["class_id"],"\"").",items:{".$class3."}},";
				$class2 = $class2.$class2_t;
				$trs->MoveNext();
			}
			$class2=substr($class2,0,strlen($class2)-1);
			$trs->Close();
		}
		$class1_t=StrWrap($rs->fields["channel_name"],"\"").":{val:".StrWrap($rs->fields["channel_id"],"\"").",items:{".$class2."}},";
		$class1 = $class1.$class1_t;
		$rs->MoveNext();
	}
	$class1=substr($class1,0,strlen($class1)-1);
	$rs->Close();
}
$def_val="\"栏目频道\":{val:\"\",items:{\"一级分类\":{val:\"\",items:{\"二级分类\":\"\"}}}}";
$ret_code="var threeSelectData={".$def_val.",".$class1."};";
echo $ret_code;
function StrWrap($s,$ws){
	return $ws.$s.$ws;
}
?>