<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：QQ877873666
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//用户检测
$MB->Open('','login',2);

	$menuFileID = 300;
	$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);


switch ($mudi){
	case 'add':
		AddOrRev();
		break;

	case 'rev':
		AddOrRev();
		break;

	case 'send':
		Send();
		break;

	case 'del':
		del();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();





// 添加与修改
function AddOrRev(){
	global $DB,$MB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataID			= OT::PostInt('dataID');
	$num			= OT::PostInt('num');
	$theme			= OT::PostStr('theme');
	$useArea		= OT::Post('useArea');
		if (is_array($useArea)){ $useArea = implode(',',$useArea); }
	$startNum		= OT::PostInt('startNum');
	$maxNum			= OT::PostInt('maxNum');
	$rank			= OT::PostInt('rank');
	$isSel			= OT::PostInt('isSel');
	$state			= OT::PostInt('state');

	if ($theme==''){
		JS::AlertBackEnd('表单内容接收不全');
	}
	
	$record=array();
	$record['XS_num']		= $num;
	$record['XS_theme']		= $theme;
	$record['XS_useArea']	= $useArea;
	$record['XS_startNum']	= $startNum;
	$record['XS_maxNum']	= $maxNum;
	$record['XS_rank']		= $rank;
	$record['XS_isSel']		= $isSel;
	$record['XS_state']		= $state;
	$dealrec=$DB->query('select * from '. OT_dbPref .'xingwaiServ where XS_ID='. $dataID);
		if (! $row = $dealrec->fetch()){
			$alertMode='添加';
			$judRes = $DB->InsertParam('xingwaiServ',$record);
		}else{
			$alertMode='修改';
			$judRes = $DB->UpdateParam('xingwaiServ',$record,'XS_ID='. $dataID);
		}
	unset($dealrec);

	if ($judRes){
		$alertRes = '成功';
	}else{
		$alertRes = '失败';
	}

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】'. $alertMode . $alertRes .'！',
		));

	JS::AlertHrefEnd($alertMode . $alertRes .'！',$backURL);

}



// 数据发送
function Send(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN;

	$numID		= OT::GetInt('typeNum');
	$dataID		= OT::GetInt('dataID');
	$dataMode	= OT::GetStr('dataMode');
	$dataModeStr= OT::GetStr('dataModeStr');

	$sendexe=$DB->query('select * from '. OT_dbPref .'xingwaiServ where XS_ID='. $dataID);
	if (! $row = $sendexe->fetch()){
		JS::AlertEnd('搜索不到指定记录');
	}
	echo('
	<script language="javascript" type="text/javascript">
	parent.$id("numID").innerHTML="'. $numID .'";
	parent.$id("dataID").value="'. $row['XS_ID'] .'";
	parent.$id("num").value="'. $row['XS_num'] .'";
	parent.$id("theme").value="'. $row['XS_theme'] .'";
	parent.$id("theme").focus();
	parent.$id("rank").value="'. $row['XS_rank'] .'";
	parent.$id("state").value="'. $row['XS_state'] .'";
	parent.$id("subButton").src="'. AdmTpl::ImgSrc('button_rev') .'";
	</script>
	');
	unset($sendexe);
}



// 删除
function del(){
	global $DB,$skin,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN;

	$dataID = OT::GetInt('dataID');
	$theme	= OT::GetStr('theme');

	if ($dataID<=0){
		JS::AlertEnd('指定ID错误！');
	}

	$judRes = $DB->query('delete from '. OT_dbPref .'xingwaiServ where XS_ID='. $dataID);
		if ($judRes){
			$alertRes = '成功';
		}else{
			$alertRes = '失败';
		}

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】删除'. $alertRes .'！',
		));

	echo('
	<script language="javascript" type="text/javascript">
	parent.$id("data'. $dataID .'").style.display="none";
	</script>
	');
}

?>