<?php
if($_POST[from_to]) 
{
	$sourcespecialid  =  intval( $_POST[sourcespecialid]);
	$targetspecialid  =  intval( $_POST[targetspecialid]);
	if ( $sourcespecialid && $targetspecialid)
	{
		$sql  =  "select `aid` from ".TABLEPRE."{$_MODULE[$channelselect][table_name]}_{$channelid}_special where `sid`='$sourcespecialid'";
		$result = qdb::Query($sql);
		while( $dids = qdb::FetchArray($result))
		{
			$s_arr[] = $dids[aid];	
		}
		if ( isset( $s_arr) && is_array( $s_arr))
		{
			unset($dids);
			$sql  =  "select `aid` from ".TABLEPRE."{$_MODULE[$channelselect][table_name]}_{$channelid}_special where `sid`='$targetspecialid'";
			$result = qdb::Query($sql);
			while( $dids = qdb::FetchArray($result))
			{
				if ( in_array($dids[aid], $s_arr))
				{	

				}
				else
				{
					$up_arr[]  = $dids[aid];//待转入的元素
				}		
			}
			if ( is_array($up_arr))
			{
				qdb::Query("update ".TABLEPRE."{$_MODULE[$channelselect][table_name]}_{$channelid}_special set sid='$targetspecialid' where sid='$sourcespecialid' and aid IN (".implode(',', $up_arr).")");
			}
			qdb::Query("delete from ".TABLEPRE."{$_MODULE[$channelselect][table_name]}_{$channelid}_special where sid='$sourcespecialid'");
		}
		qbase::showmsg("专题已经合并成功",'default',"system.php?sys=special&channelid=".$channelid."&action=manage");
	}
	else
	{
		qbase::showmsg("您提交的参数出现错误",'default',"system.php?sys=special&channelid=".$channelid."&action=manage");
	}
}
	
$special_result  = qdb::Query("select `specialid`,`specialname` from `".TABLEPRE."special` where `channelid`=".$channelid." and `open`=1");
while($special   = qdb::FetchArray($special_result)) 
{
	$specials[]  =  $special;
}
?>