<?php
if ( ! defined( 'MOD' )) die("access die");
if (AJAX ){
	$type = trim( $_POST['type'] );
	$val = @explode( ',', trim( $_POST['val'] ));
	$has_page = $_MODULE[$channelselect]['is_showpage'] ? " , a.page" : " ";
	switch ( $type ){
		case 'a':
			//按指定栏目取得数据
			$sql ="select a.id {$has_page} from ".TABLEPRE."{$mod}_{$channelid} as a left join ".TABLEPRE."acategory as c on a.cid=c.cid where a.cid IN (".implode( ',', $val ).") and c.pur_browse=0 and c.html=0 and a.pay=0 ";
		break;

		case 'f':
			//按指定ID范围获取
			if ( $admin_info['groupid'] == 4 || ( $admin_info['groupid'] == 3 &&  ! in_array( $channelid, $manage_channel ))){
				$and = " c.cid IN (".implode( ',', $manage_category[$channelid] ).") and ";
			}else{
				$and = " ";
			}
			$sql ="select a.id {$has_page} from ".TABLEPRE."{$mod}_{$channelid} as a left join ".TABLEPRE."acategory as c on a.cid=c.cid where {$and} a.id >='{$val[0]}' and  a.id <='{$val[1]}' and c.pur_browse=0 and c.html=0 and a.pay = 0";
			break;

		case 't':
		case 'm':
			//按照指定时间范围
			$tm = array();
			$tm[0] = @strtotime($val[0]);
			$tm[1] = @strtotime($val[1]) + 86400;
			$val[0] = min($tm);
			$val[1] = max($tm);
			if ( $admin_info['groupid'] == 4 || ( $admin_info['groupid'] == 3 &&  ! in_array( $channelid, $manage_channel ))){
				$and = " c.cid IN (".implode( ',', $manage_category[$channelid] ).") and ";
			}else{
				$and = " ";
			}
			$field = $type == 't' ? 'dateline' : 'edit_time' ;
			$sql ="select a.id {$has_page} from ".TABLEPRE."{$mod}_{$channelid} as a left join ".TABLEPRE."acategory as c on a.cid=c.cid where {$and} a.{$field} >='{$val[0]}' and  a.{$field} <='{$val[1]}' and c.pur_browse=0 and c.html=0 and a.pay = 0 ";	
		break;

		case 'c':
			if ( $admin_info['groupid'] == 4 || ( $admin_info['groupid'] == 3 &&  ! in_array( $channelid, $manage_channel ))){
				$val = array_intersect($val, $manage_category[$channelid]);
			}
			$and = " cid IN (".implode( ',',  $val).") and ";
			$sql ="select cid from ".TABLEPRE."acategory where channelid='$channelid' and {$and} pur_browse=0 and category_html = 0";
		break;

		case 'd':
			$html = new html;
			if( is_dir( R_P . "/".$channel[$channelid]['channeldir']."/")){
				$html->deletedir( R_P . "/".$channel[$channelid]['channeldir']."/");	
			}

			$html->deletedir(C_P."/content/");
			$html->deletedir(C_P."/acategory/");
			$html->deletedir(C_P."/channel/");
			$html->deletedir(C_P."/ament/");
			$html->deletedir(C_P."/plugin/");
			$html->deletedir(C_P."/temp/");
			$html->deletedir(C_P."/cache/");
			$html->deletedir(C_P."/template_c/");
			qbase::createdir(C_P."/temp/");
			qbase::createdir( C_P."/temp");
			$html->deletedir( C_P."/config");
			qbase::createdir( C_P."/config");
			commonCache();
			servercache();
			qbase::get_object("group")->cache();
			foreach($channel as $channelid=>$val){
				qbase::get_object('category', $channelid)->cache();
			}
			if(method_exists('cache', 'flush')) cache::flush();
			clearstatcache();

			$data = array( status => 200 );
			echo qbase::xmlPrint(qbase::jsonencode( $data ));
			die();
		break;
		
		default:
			qbase::purviewCheckDie( "error request" );
		break;
	}
	$result = qdb::fetchAll( $sql );
	$lists = array();
	foreach($result as $list){
		$lists[] = implode('-', $list);
	}
	unset($result);
	if ( isset( $lists ) && count( $lists ) > 0 ){
		$data = implode( ',', $lists );
		$data = array( status => 200, data => $data );
	}else{
		$data = array( status => 404 );
	}
	echo qbase::xmlPrint(qbase::jsonencode( $data ));
	exit();
}else{
	qbase::purviewCheckDie( "error request" );
}
?>
