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

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

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

	case 'del':
		$menuFileID = 289;
		$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');
	$type			= OT::PostStr('type');
	$theme			= OT::PostStr('theme');
	$img			= OT::PostStr('img');
	$bgColor		= OT::PostStr('bgColor');
	$url			= OT::PostStr('url');
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');
	$wapState		= OT::PostInt('wapState');

	if ($theme == ''){
		JS::AlertBackEnd('表单内容接收不全');
	}
	
	$record = array();
	$record['BN_type']		= $type;
	$record['BN_theme']		= $theme;
	$record['BN_img']		= $img;
	$record['BN_bgColor']	= $bgColor;
	$record['BN_url']		= $url;
	$record['BN_rank']		= $rank;
	$record['BN_state']		= $state;
	$record['BN_wapState']	= $wapState;
	$dealrec=$DB->query('select * from '. OT_dbPref .'banner where BN_ID='. $dataID);
		if (! $row = $dealrec->fetch()){
			$alertMode = '添加';

			$judRes = $DB->InsertParam('banner',$record);
		}else{
			$alertMode = '修改';

			$judRes = $DB->UpdateParam('banner',$record,'BN_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::GetInt2( OT::ParaArr('id') );
	$dataMode	= OT::GetStr('dataMode');
	$dataModeStr= OT::GetStr('dataModeStr');

	$sendexe=$DB->query('select * from '. OT_dbPref .'banner where BN_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['BN_ID'] .'";
	parent.$id("type").value="'. $row['BN_type'] .'";
	parent.$id("theme").value="'. $row['BN_theme'] .'";
	parent.$id("theme").focus();
	parent.$id("img").value="'. $row['BN_img'] .'";
	parent.$id("bgColor").value="'. $row['BN_bgColor'] .'";
	parent.$id("url").value="'. $row['BN_url'] .'";
	parent.$id("rank").value="'. $row['BN_rank'] .'";
	parent.$id("state").value="'. $row['BN_state'] .'";
	parent.$id("wapState").value="'. $row['BN_wapState'] .'";
	parent.$id("subButton").src="'. AdmTpl::ImgSrc('button_rev') .'";
	</script>
	');
	unset($sendexe);
}



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

	$dataID = OT::GetInt2( OT::ParaArr('id') );
	$theme	= OT::GetStr('theme');

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

	$chkexe = $DB->query('select BN_noDel from '. OT_dbPref .'banner where BN_ID='. $dataID);
	if ($row = $chkexe->fetch()){
		if ($row['BN_noDel'] == 1){
			JS::AlertEnd('该记录不允许删除！');
		}
	}else{
			JS::AlertEnd('该记录不存在！');
	}
	unset($chkexe);

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

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

	JS::ParentHiddenEnd('data'. $dataID);
}

?>