<?php
if(!defined('MOD'))  die("access die");
purviewCheck( $channelid, 'channel');
if($_POST['myFormAc'] == 'update'){
	$fcid = $_POST['fcid'];
	$tcid = intval($_POST['tcid']);
	$type = $_POST['type'];
	$id   = $_POST['id'];
	if(!$tcid || $tcid == $fcid) qbase::showmsg("出错了：没有选择目标栏目，或目标栏目与原栏目相同",'default',"system.php?sys=module&action=move&mod={$mod}&channelid={$channelid}");
	$child  = qdb::QueryAlone("select `child` from `".TABLEPRE."acategory` where `cid`=".$tcid);
	if($type==2){
		if($child){
			qbase::showmsg("出错了：目标栏目有子栏目，不能操作",'default',"system.php?sys=module&action=move&mod={$mod}&channelid={$channelid}");
		}
		$ids = array();
		foreach($fcid as $val){
			$val = intval($val);
			$arrchildids = qdb::QueryAlone("select `arrchildids` from `".TABLEPRE."acategory` where `cid`=".$val);
			$temp = explode(",", $arrchildids);
			foreach($temp as $c){
				$ids[] = $c;
			}
		}
		$ids = array_unique($ids);
		if(!empty($ids)){
			$arrchildids = implode(',', $ids);
			qdb::Query("update `".TABLEPRE."{$mod}_{$channelid}` set `cid`=".$tcid.", edit_time = '{$_SERVER['REQUEST_TIME']}'  where cid IN(".$arrchildids.")");
		}
	}else{
		if(!$id) qbase::showmsg("出错了：你既然选择了指定ID,有为什么不给出".$channeltitle."ID",'default',"system.php?sys=module&action=move&mod={$mod}&channelid={$channelid}");
		$id = explode(",",$id);
		foreach($id as $val){
			$sql="update `".TABLEPRE."{$mod}_{$channelid}` set `cid`=".$tcid." , edit_time = '{$_SERVER['REQUEST_TIME']}'  where  `id`=".$val;
			qdb::Query( $sql);
		}
	}
	adminLog("批量移动文档");
	qbase::showmsg("操作成功",'default', "system.php?sys=module&action=move&mod={$mod}&channelid={$channelid}");
}else{
	include qbase::template($path . 'move');
}
?>
