<?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 = 308;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

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

	case 'send':
		$menuFileID = 309;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		Send();
		break;

	case 'del':
		$menuFileID = 310;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		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');
	$theme			= OT::PostStr('theme');
	$prefName		= OT::PostStr('prefName');
	$numLen			= OT::PostInt('numLen');
		if ($numLen > 10){ $numLen = 10; }
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');

	if (strlen($theme)==0 || strlen($prefName)==0){
		JS::AlertBackEnd('表单内容接收不全');
	}
	
	$record=array();
	$record['VC_prefName']	= $prefName;
	$record['VC_numLen']	= $numLen;
	$record['VC_rank']		= $rank;
	$record['VC_state']		= $state;

	$dealrec=$DB->query('select * from '. OT_dbPref .'vpsClass where VC_ID='. $dataID);
		if (! $row = $dealrec->fetch()){
			$alertMode='添加';
			$record['VC_theme']	= $theme;
			$judRes = $DB->InsertParam('vpsClass',$record);
		}else{
			$alertMode='修改';
			if ($dataID > 10){
				$record['VC_theme']	= $theme;
			}
			$judRes = $DB->UpdateParam('vpsClass',$record,'VC_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 .'vpsClass where VC_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['VC_ID'] .'";
	parent.$id("theme").value="'. ($row['VC_ID'] > 10 ? $row['VC_theme'] : '内置名称不可改') .'";
	parent.$id("prefName").value="'. $row['VC_prefName'] .'";
	parent.$id("prefName").focus();
	parent.$id("numLen").value="'. $row['VC_numLen'] .'";
	parent.$id("rank").value="'. $row['VC_rank'] .'";
	parent.$id("state").value="'. $row['VC_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错误！');
	}elseif ($dataID<=10){
		JS::AlertEnd('该记录为内置记录，禁止删除！');
	}

	$useNum = $DB->GetOne('select count(VT_ID) from '. OT_dbPref .'vpsType where VT_classID='. $dataID);
		if ($useNum > 0){ JS::AlertEnd('该记录已有产品类型占用，禁止删除！'); }

	$judRes = $DB->query('delete from '. OT_dbPref .'vpsClass where VC_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>
	');
}

?>