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

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

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

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

}

$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');
	$path			= OT::PostStr('path');
	$pathWap		= OT::PostStr('pathWap');
	$rnd			= OT::PostStr('rnd');
	$htmlName		= OT::PostStr('htmlName');
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');
	$event			= OT::PostArrStr('event','');

	if ($theme == ''){
		JS::AlertBackEnd('表单内容接收不全');
	}
	
	$record=array();
	$record['MD_theme']		= $theme;
	$record['MD_path']		= $path;
	$record['MD_pathWap']	= $pathWap;
	$record['MD_rnd']		= $rnd;
	$record['MD_htmlName']	= $htmlName;
	$record['MD_rank']		= $rank;
	$record['MD_state']		= $state;
	$record['MD_event']		= $event;
	$dealrec=$DB->query('select * from '. OT_dbPref .'makeDiy where MD_ID='. $dataID);
		if (! $row = $dealrec->fetch()){
			$alertMode = '添加';
			$record['MD_time']	= TimeDate::Get();
			$judRes = $DB->InsertParam('makeDiy',$record);
		}else{
			$alertMode = '修改';
			$judRes = $DB->UpdateParam('makeDiy',$record,'MD_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 .'makeDiy where MD_ID='. $dataID);
	if (! $row = $sendexe->fetch()){
		JS::AlertEnd('搜索不到指定记录');
	}

	$eventStr = '';
	if (Is::InstrChecked($row['MD_event'],'|301|')){
		$eventStr .= 'parent.$id("event_301").checked=true;';
	}else{
		$eventStr .= 'parent.$id("event_301").checked=false;';
	}
	echo('
	<script language="javascript" type="text/javascript">
	parent.$id("numID").innerHTML="'. $numID .'";
	parent.$id("dataID").value="'. $row['MD_ID'] .'";
	parent.$id("theme").value="'. $row['MD_theme'] .'";
	parent.$id("theme").focus();
	parent.$id("path").value="'. $row['MD_path'] .'";
	parent.$id("pathWap").value="'. $row['MD_pathWap'] .'";
	parent.$id("rnd").value="'. $row['MD_rnd'] .'";
	parent.$id("htmlName").value="'. $row['MD_htmlName'] .'";
	parent.$id("rank").value="'. $row['MD_rank'] .'";
	parent.$id("state").value="'. $row['MD_state'] .'";
	parent.$id("subButton").src="'. AdmTpl::ImgSrc('button_rev') .'";
	'. $eventStr .'
	</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错误！');
	}

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

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

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

?>