<?php
if(!defined('MOD'))  die("access die");
checkAdminReferer();
if(!$channelid) qbase::showmsg("error request");
if(empty($channel[$channelid])) qbase::showmsg("error request");
if($admin_info['groupid'] > 2 ) qbase::purviewCheckDie();
$system=qdb::QueryFirst("select `system`,`channelselect`,`link`,`channeldir` from `".TABLEPRE."channel`  where `channelid`=$channelid");
if($system['system']==1) {
	qbase::purviewCheckDie("系统默认频道,不允许删除");
}else{
	qdb::Query("delete from `".TABLEPRE."channel` where `channelid`=$channelid limit 1");
	if( $system['link'] == 0){
		$html = new html();
		$html->deletedir($_SET['abspath']."/".$system['channeldir']);
	}
	commonCache();
	$param = qdb::queryFirst("select * from ".TABLEPRE."module where id = '{$system['channelselect']}' ");
	if($param['pid'] > 0 ){
		$param = qdb::queryFirst("select * from ".TABLEPRE."module where id = '{$param[pid]}' ");
	}
	$sql = array();
	require_once(A_P . "/module/{$param['table_name']}/action/sql.php");
	if(!empty($sql) && is_array($sql)){
		foreach($sql['drop'] as $val){
			$val = str_replace("__channelid__", '_'.$channelid, $val);
			qdb::query($val);
		}
	}
	$wait = 2;
	qbase::showmsg("频道删除成功<script type='text/javascript'>parent.document.getElementById('menu').src  = \"index.php?action=left&d=\" + (new Date()).toString();</script>",'default',"system.php?sys=channel&action=modify");
}
?>
