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


@ini_set('max_execution_time', 0);
@set_time_limit(0); 


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

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

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

	case 'moreDel':
		$menuFileID = 11;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreDel();
		break;

	default:
		die('err');
}

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




//添加、修改
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$menuFileID,$menuTreeID,$sysAdminArr,$systemArr;

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

	$type		= OT::PostStr('type');
	$theme		= OT::PostStr('theme');
	$img		= OT::PostStr('img');
	$desc		= OT::PostStr('desc');
	$price1		= OT::PostStr('price1');
	$price2		= OT::PostStr('price2');
	$btnName	= OT::PostStr('btnName');
	$url		= OT::PostStr('url');
	$rank		= OT::PostInt('rank');
	$state		= OT::PostInt('state');
	$wapState	= OT::PostInt('wapState');

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

	$record=array();
	$record['HP_type']		= 'home';
	$record['HP_theme']		= $theme;
	$record['HP_img']		= $img;
	$record['HP_desc']		= $desc;
	$record['HP_price1']	= $price1;
	$record['HP_price2']	= $price2;
	$record['HP_btnName']	= $btnName;
	$record['HP_url']		= $url;
	$record['HP_rank']		= $rank;
	$record['HP_state']		= $state;
	$record['HP_wapState']	= $wapState;

	$addrec=$DB->query('select * from '. OT_dbPref .'homePro where HP_ID='. $dataID);
	if (! $row = $addrec->fetch()){
		$alertMode='新增';

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

		$judRes = $DB->UpdateParam('homePro',$record,'HP_ID='. $dataID);
	}

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

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

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



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

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

	$judRes = $DB->query('delete from '. OT_dbPref .'homePro where HP_ID='. $dataID);
	if ($judRes == true){
		$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>
	');
}



// 批量删除
function MoreDel(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$systemArr;

	$backURL	= OT::PostStr('backURL');
	$dataType	= OT::PostStr('dataType');
	$dataTypeCN	= OT::PostStr('dataTypeCN');
	$selDataID	= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$judRes = $DB->query('delete from '. OT_dbPref .'homePro where HP_ID in (0'. $whereStr .')');

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

	JS::AlertHrefEnd('批量删除完成.',$backURL);

}

?>