
<?
defined('ROOT_PHPLEFT') or exit('phpleft: Not page');
/*
	phpleftDms Copyright (c) 2011 phpleft.COM
	商业授权：QQ45150208
	
*/
$rs = new admin;
$catid = isset($catid) ? intval($catid) : 0;
function allparent($id,$moduleid,$key = 'allparent'){
	global $PL_CFG;
$file = "catid_".$moduleid.".php";
$catlists = cache_read($file,PL_ROOT.$PL_CFG['cache']."/");
$catlists = $catlists ? $catlists:array();
	foreach($catlists as $i=>$m) { 
      if ($m['id']==$id){
		  $allparent = $m[$key].',';
	  }
	}
	return $allparent;
}
if($show=='bj' and $id<>'' ){
$file = "catid_".$menuid.".php";
$catlist = cache_read($file,PL_ROOT.$PL_CFG['cache']."/");
foreach($catlist as $ids=>$m) {
if ($m['id']==$id){
$alladd=$m;

}
}

}
if ($post=='add'){
$file = "catid_".$alladd[module].".php";
$rs->update_cat($alladd);
$menusp = sql_cache("table=sort&cache=id&where=module=".$alladd['module']."&order=keylist asc,id asc");
$pathcach = PL_ROOT.$PL_CFG['cache']."/";
cache_write($file, $menusp, $pathcach);
msg('<b><font style="color:#F00;font-size:14px;">√ 提交成功</font></b>', 'phpleft.php?file=cat&menuid='.$alladd['module'].'&catid='.$alladd['parent']);
}elseif ($post=='del'){
$file = "catid_".$menuid.".php";
if ($tab=='') {
	msg('请先选择删除的', 'phpleft.php?file=cat&menuid='.$menuid);  
}else{
foreach($tab as $id=>$t) { 
	$db->query("DELETE FROM ".$PL_CFG['tb_pre']."sort WHERE id='".$t."' or allparent like '%,".$t."%'");
}
$menusp = sql_cache("table=sort&cache=id&where=module=".$menuid."&order=keylist asc,id asc");
$pathcach = PL_ROOT.$PL_CFG['cache']."/";
cache_write($file, $menusp, $pathcach);
msg('删除成功', 'phpleft.php?file=cat&menuid='.$menuid);
}

}elseif ($post=='bj'){
if ($alladd['parent']==$id){
	msg('<b><font style="color:#F00;font-size:14px;">× 提交失败</font></b><br>归属分类不能是自己', 'phpleft.php?file=cat&menuid='.$alladd['module']);
}else{
$file = "catid_".$alladd[module].".php";
$rs->update_cat_bj($alladd,$id);
$menusp = sql_cache("table=sort&cache=id&where=module=".$alladd['module']."&order=keylist asc,id asc");
$pathcach = PL_ROOT.$PL_CFG['cache']."/";
cache_write($file, $menusp, $pathcach);
msg('<b><font style="color:#F00;font-size:14px;">√ 提交成功</font></b>', 'phpleft.php?file=cat&menuid='.$alladd['module'].'&catid='.$alladd['parent']);	
}
}else{
$menu = array (
	array('','phpleft.php?file=cat&menuid='.$menuid, '分类管理',0),
    array('add','phpleft.php?file=cat&menuid='.$menuid.'&show=add', '添加分类',0),
);
$file = "catid_".$menuid.".php";
$catlist = cache_read($file,PL_ROOT.$PL_CFG['cache']."/");
if ($catlist == '') $catlist= array();
include FTemplate(ThisFile);
}
?>