<?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);


switch ($mudi){
	case 'add':
		$menuFileID = 300;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$menuFileID = 300;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'del':
		$menuFileID = 300;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		del();
		break;

	default:
		die('err');
}

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





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

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataID			= OT::PostInt('dataID');

	$theme			= OT::PostStr('theme');
	$note			= OT::PostStr('note');
	$rateDay		= OT::PostFloat('rateDay');
	$rateWeek		= OT::PostFloat('rateWeek');
	$rateMonth		= OT::PostFloat('rateMonth');
	$rate3Month		= OT::PostFloat('rate3Month');
	$rate6Month		= OT::PostFloat('rate6Month');
	$rateYear		= OT::PostFloat('rateYear');
	$rate2Year		= OT::PostFloat('rate2Year');
	$rate3Year		= OT::PostFloat('rate3Year');
	$rate4Year		= OT::PostFloat('rate4Year');
	$rate5Year		= OT::PostFloat('rate5Year');
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');

/*	if ($theme==''){
		JS::AlertBackEnd('表单内容接收不全');
	} */
	

	$record=array();
	$record['VA_rateDay']		= $rateDay;
	$record['VA_rateWeek']		= $rateWeek;
	$record['VA_rateMonth']		= $rateMonth;
	$record['VA_rate3Month']	= $rate3Month;
	$record['VA_rate6Month']	= $rate6Month;
	$record['VA_rateYear']		= $rateYear;
	$record['VA_rate2Year']		= $rate2Year;
	$record['VA_rate3Year']		= $rate3Year;
	$record['VA_rate4Year']		= $rate4Year;
	$record['VA_rate5Year']		= $rate5Year;
	$record['VA_note']			= $note;
	$record['VA_rank']			= $rank;
	$record['VA_state']			= $state;

	$addrec=$DB->query('select * from '. OT_dbPref .'vpsApi where VA_ID='. $dataID);
		if (! $row = $addrec->fetch()){
			$alertMode='添加';
			$record['VA_theme']	= $theme;
			$judRes = $DB->InsertParam('vpsApi',$record);
		}else{
			$alertMode='修改';
			$judRes = $DB->UpdateParam('vpsApi',$record,'VA_ID='. $dataID);
		}
	unset($addrec);
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

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

	JS::AlertHref(''. $alertMode .'成功！',$backURL);

}







// 删除
function del(){
	global $DB,$dataType,$dataTypeCN;

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

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

	$useNum = $DB->GetOne('select count(VC_ID) from '. OT_dbPref .'vpsCompany where VC_apiID='. $dataID);
		if ($useNum > 0){ JS::AlertEnd('该记录已有上级渠道商占用，禁止删除！'); }

	$DB->query('delete from '. OT_dbPref .'vpsApi where VA_ID='. $dataID);


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


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

}

?>