<?php
header("Content-type: text/html; charset=utf-8");
require('../../../data/common.inc.php');
$conn=new mysqli($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
if(mysqli_connect_errno()){
out("数据库连接失败".mysqli_connect_error());
}
$conn->query("set names 'utf8'");
$action=trim($_GET['action']);
$lang=trim($_GET['lang']);
if($action=='index_product'){
$id=array('gb2312'=>18,'en'=>19);
$sql='select id,typename from '.$cfg_dbprefix.'arctype where reid='.$id[$lang].' and lang="'.$lang.'" order by sortrank asc';
$rs = $conn->query($sql);
$temp='';
while($row = $rs->fetch_assoc()){
$temp.='<li><a href="/plus/list.php?tid='.$row['id'].'" target="_blank">'.$row['typename'].'</a></li>';
}
$rs->close();
out($temp);
}
elseif($action=='list_product'){
$arr=array();
$sql='select id,typename,reid,sortrank from '.$cfg_dbprefix.'arctype where channeltype=6 and lang="'.$lang.'" order by id asc';
$rs=$conn->query($sql);
while($row=$rs->fetch_assoc()){
$arr[$row['id']]=array('id'=>$row['id'],'typename'=>$row['typename'],'reid'=>$row['reid'],'sortrank'=>$row['sortrank']);
}
fenlei(intval(@$_GET['pid']));
out(substr($tree_str,0,strlen($tree_str)-10));
}
function out($str){
$result='document.write(\'';
$result.=$str;
$result.='\');';
exit($result);
}
function fenlei($f_id=0){
global $arr;
global $level;
global $tree_str;
foreach($arr as $key=>$v){
if($v['reid']==$f_id){
if(haschildren($v['id'])){
$tree_str.= '<li><p class="p1"><span class="statu statu1" id="statu_product">+</span><a href="/plus/list.php?tid='.$v['id'].'" class="a1">'.$v['typename'].'</a></p><ul class="nav_ul" style="left:10px;">';
}
else{
$tree_str.= '<li><p class="p1"><a href="/plus/list.php?tid='.$v['id'].'" class="a0">'.$v['typename'].'</a></p></li>';
}
//$tree_str.='</li>';
$level++;
fenlei($v['id']);
}
$temp_id=$v['id'];
}
if($level==1){
$tree_str.= '</ul></li>';
}
$level=1;
}
function haschildren($id){ // 检测是否有下级
global $arr;
foreach($arr as $v){
if($v['reid']==$id){
return true;
break;
}
}
return false;
}
?>