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

	case 'loadFieldInfo':
		$menuFileID = 92;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		LoadFieldInfo();
		break;

	case 'loadProTypeInfo':
		$menuFileID = 92;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		LoadProTypeInfo();
		break;

	default:
		die('err');
}

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




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

	$userSysArr = Cache::PhpFile('userSys');

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

	$theme			= OT::PostStr('theme');
	$themeB			= OT::PostInt('themeB');
	$themeColor		= OT::PostStr('themeColor');
	$themeStyle		= '';
		if ($themeB==1){ $themeStyle .= 'font-weight:bold;'; }
		if ($themeColor!=''){ $themeStyle .= 'color:'. $themeColor .';'; }
	$type1ID		= 0;
	$type2ID		= 0;
	$type3ID		= 0;
	$groupID		= OT::PostInt('groupID');
	$typeStr		= OT::PostStr('typeStr');
		$typeArr = explode(',',$typeStr);
		$typeArrCount=count($typeArr);
		if ($typeArrCount>=3){
			$type1ID = intval($typeArr[1]);
			if ($typeArrCount>=4){
				$type2ID = intval($typeArr[2]);
				if ($typeArrCount>=5){
					$type3ID = intval($typeArr[3]);
				}
			}
		}
	$field1			= OT::PostStr('field1');
	$field2			= OT::PostStr('field2');
	$field3			= OT::PostStr('field3');
	$field4			= OT::PostStr('field4');
	$field5			= OT::PostStr('field5');
	$field6			= OT::PostStr('field6');
	$field7			= OT::PostStr('field7');
	$field8			= OT::PostStr('field8');
	$field9			= OT::PostStr('field9');
	$field10		= OT::PostStr('field10');
	$field11		= OT::PostStr('field11');
	$field12		= OT::PostStr('field12');

	$field1B		= OT::PostInt('field1B');
	$field1Color	= OT::PostStr('field1Color');
	$field1Style	= '';
		if ($field1B == 1){ $field1Style .= 'font-weight:bold;'; }
		if ($field1Color != ''){ $field1Style .= 'color:'. $field1Color .';'; }
	$field2B		= OT::PostInt('field2B');
	$field2Color	= OT::PostStr('field2Color');
	$field2Style	= '';
		if ($field2B == 1){ $field2Style .= 'font-weight:bold;'; }
		if ($field2Color != ''){ $field2Style .= 'color:'. $field2Color .';'; }
	$field3B		= OT::PostInt('field3B');
	$field3Color	= OT::PostStr('field3Color');
	$field3Style	= '';
		if ($field3B == 1){ $field3Style .= 'font-weight:bold;'; }
		if ($field3Color != ''){ $field3Style .= 'color:'. $field3Color .';'; }
	$field4B		= OT::PostInt('field4B');
	$field4Color	= OT::PostStr('field4Color');
	$field4Style	= '';
		if ($field4B == 1){ $field4Style .= 'font-weight:bold;'; }
		if ($field4Color != ''){ $field4Style .= 'color:'. $field4Color .';'; }
	$field5B		= OT::PostInt('field5B');
	$field5Color	= OT::PostStr('field5Color');
	$field5Style	= '';
		if ($field5B == 1){ $field5Style .= 'font-weight:bold;'; }
		if ($field5Color != ''){ $field5Style .= 'color:'. $field5Color .';'; }
	$field6B		= OT::PostInt('field6B');
	$field6Color	= OT::PostStr('field6Color');
	$field6Style	= '';
		if ($field6B == 1){ $field6Style .= 'font-weight:bold;'; }
		if ($field6Color != ''){ $field6Style .= 'color:'. $field6Color .';'; }
	$field7B		= OT::PostInt('field7B');
	$field7Color	= OT::PostStr('field7Color');
	$field7Style	= '';
		if ($field7B == 1){ $field7Style .= 'font-weight:bold;'; }
		if ($field7Color != ''){ $field7Style .= 'color:'. $field7Color .';'; }
	$field8B		= OT::PostInt('field8B');
	$field8Color	= OT::PostStr('field8Color');
	$field8Style	= '';
		if ($field8B == 1){ $field8Style .= 'font-weight:bold;'; }
		if ($field8Color != ''){ $field8Style .= 'color:'. $field8Color .';'; }
	$field9B		= OT::PostInt('field9B');
	$field9Color	= OT::PostStr('field9Color');
	$field9Style	= '';
		if ($field9B == 1){ $field9Style .= 'font-weight:bold;'; }
		if ($field9Color != ''){ $field9Style .= 'color:'. $field9Color .';'; }
	$field10B		= OT::PostInt('field10B');
	$field10Color	= OT::PostStr('field10Color');
	$field10Style	= '';
		if ($field10B == 1){ $field10Style .= 'font-weight:bold;'; }
		if ($field10Color != ''){ $field10Style .= 'color:'. $field10Color .';'; }
	$field11B		= OT::PostInt('field11B');
	$field11Color	= OT::PostStr('field11Color');
	$field11Style	= '';
		if ($field11B == 1){ $field11Style .= 'font-weight:bold;'; }
		if ($field11Color != ''){ $field11Style .= 'color:'. $field11Color .';'; }
	$field12B		= OT::PostInt('field12B');
	$field12Color	= OT::PostStr('field12Color');
	$field12Style	= '';
		if ($field12B == 1){ $field12Style .= 'font-weight:bold;'; }
		if ($field12Color != ''){ $field12Style .= 'color:'. $field12Color .';'; }

	$priceMode		= OT::PostInt('priceMode');
	$priceDiy		= OT::PostStr('priceDiy');
	$priceDay		= OT::PostFloat('priceDay');
	$priceWeek		= OT::PostFloat('priceWeek');
	$priceMonth		= OT::PostFloat('priceMonth');
	$price3Month	= OT::PostFloat('price3Month');
	$price6Month	= OT::PostFloat('price6Month');
	$priceYear		= OT::PostFloat('priceYear');
	$priceOri		= OT::PostFloat('priceOri');
	$proType		= OT::PostStr('proType');
	$proID			= OT::PostInt('proID');
	$goUrl			= OT::PostStr('goUrl');
	$goWapUrl		= OT::PostStr('goWapUrl');
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');
	$wapState		= OT::PostInt('wapState');

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

	$record=array();
	$record['IPD_revTime']		= TimeDate::Get();
	$record['IPD_theme']		= $theme;
	$record['IPD_typeStr']		= $typeStr;
	$record['IPD_type1ID']		= $type1ID;
	$record['IPD_type2ID']		= $type2ID;
	$record['IPD_type3ID']		= $type3ID;
	$record['IPD_groupID']		= $groupID;
	$record['IPD_field1']		= $field1;
	$record['IPD_field2']		= $field2;
	$record['IPD_field3']		= $field3;
	$record['IPD_field4']		= $field4;
	$record['IPD_field5']		= $field5;
	$record['IPD_field6']		= $field6;
	$record['IPD_field7']		= $field7;
	$record['IPD_field8']		= $field8;
	$record['IPD_field9']		= $field9;
	$record['IPD_field10']		= $field10;
	$record['IPD_field11']		= $field11;
	$record['IPD_field12']		= $field12;
	$record['IPD_field1Style']		= $field1Style;
	$record['IPD_field2Style']		= $field2Style;
	$record['IPD_field3Style']		= $field3Style;
	$record['IPD_field4Style']		= $field4Style;
	$record['IPD_field5Style']		= $field5Style;
	$record['IPD_field6Style']		= $field6Style;
	$record['IPD_field7Style']		= $field7Style;
	$record['IPD_field8Style']		= $field8Style;
	$record['IPD_field9Style']		= $field9Style;
	$record['IPD_field10Style']		= $field10Style;
	$record['IPD_field11Style']		= $field11Style;
	$record['IPD_field12Style']		= $field12Style;
	$record['IPD_priceMode']	= $priceMode;
	$record['IPD_priceDiy']		= $priceDiy;
	$record['IPD_priceDay']		= $priceDay;
	$record['IPD_priceWeek']	= $priceWeek;
	$record['IPD_priceMonth']	= $priceMonth;
	$record['IPD_price3Month']	= $price3Month;
	$record['IPD_price6Month']	= $price6Month;
	$record['IPD_priceYear']	= $priceYear;
	$record['IPD_priceOri']		= $priceOri;
	$record['IPD_proType']		= $proType;
	$record['IPD_proID']		= $proID;
	$record['IPD_goUrl']		= $goUrl;
	$record['IPD_goWapUrl']		= $goWapUrl;
	$record['IPD_rank']			= $rank;
	$record['IPD_state']		= $state;
	$record['IPD_wapState']		= $wapState;
	if (AppBase::Jud()){
		$record['IPD_themeStyle']	= $themeStyle;
	}

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

		$record['IPD_time']		= TimeDate::Get();
		$judRes = $DB->InsertParam('idcProData',$record);
	}else{
		$alertMode='修改';

		$judRes = $DB->UpdateParam('idcProData',$record,'IPD_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 .'idcProData where IPD_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 .'idcProData where IPD_ID in (0'. $whereStr .')');

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

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

}



// 读取字段信息
function LoadFieldInfo(){
	global $DB;

	$groupID = OT::GetInt('groupID');
	$typeStr = OT::GetStr('typeStr');

	$typeArr = explode(',',$typeStr);
	$typeArrCount=count($typeArr);
	if ($typeArrCount>=3){
		$dataID = intval($typeArr[$typeArrCount-2]);
		$type1ID = intval($typeArr[1]);
		if ($typeArrCount>=4){
			$type2ID = intval($typeArr[2]);
			if ($typeArrCount>=5){
				$type3ID = intval($typeArr[3]);
			}
		}
		if (! isset($dataID)){ $dataID=$type1ID; }
	}

	$fieldList = '
		groupOption = document.getElementById("groupID").options;
		groupOption.length=0; 
		';

	$chkexe = $DB->query('select IPG_ID,IPG_theme from '. OT_dbPref .'idcProGroup where IPG_type2ID='. $dataID);
	while ($rs = $chkexe->fetch()){
		$fieldList .= '
		groupOption.add(new Option("'. $rs['IPG_theme'] .'","'. $rs['IPG_ID'] .'"));
		';
	}
	unset($chkexe);

	$row = $DB->GetRow('select IPT_fieldNum,IPT_fieldStr,IPT_priceType from '. OT_dbPref .'idcProType where IPT_ID='. $dataID);

	$fieldArr = explode('<arr>', $row['IPT_fieldStr'] .'<arr><arr><arr><arr><arr><arr><arr><arr><arr><arr><arr><arr>');
	$fieldNum = count(array_filter($fieldArr));
	for ($i=1; $i<=12; $i++){
		$itemArr = explode('|', $fieldArr[$i-1] .'|||||');
		if ($itemArr[0] == 0){
			$fieldList .= '
			$id("fieldBox'. $i .'").style.display = "none";
			$id("fieldNameStr'. $i .'").innerHTML = "'. $itemArr[1] .'";
			';
		}else{
			$itemArr = explode('|', $fieldArr[$i-1] .'|||||');
			$fieldList .= '
				$id("fieldBox'. $i .'").style.display = "";
				$id("fieldNameStr'. $i .'").innerHTML = "'. $itemArr[1] .'";
				';
		}
	}
	switch ($row['IPT_priceType']){
		case 'host1':
			$fieldList .= '
				$id("priceDayBox").style.display = "none";
				$id("priceWeekBox").style.display = "none";
				$id("priceMonthBox").style.display = "none";
				$id("price3MonthBox").style.display = "none";
				$id("price6MonthBox").style.display = "none";
				$id("priceYearBox").style.display = "";
				$id("priceOriBox").style.display = "";
				';
			break;

		case 'vps1':
			$fieldList .= '
				$id("priceDayBox").style.display = "none";
				$id("priceWeekBox").style.display = "none";
				$id("priceMonthBox").style.display = "";
				$id("price3MonthBox").style.display = "";
				$id("price6MonthBox").style.display = "none";
				$id("priceYearBox").style.display = "";
				$id("priceOriBox").style.display = "none";
				';
			break;

	}

	echo('
	$id("fieldNum").value = "'. $row['IPT_fieldNum'] .'";
	$id("fieldNumStr").innerHTML = "'. $row['IPT_fieldNum'] .'";
	'. $fieldList .'
	document.getElementById("groupID").value="'. $groupID .'";
	WindowHeight(0);
	');
}



// 读取产品类型信息
function LoadProTypeInfo(){
	global $DB;

	$proType	= OT::GetStr('proType');
	$proID		= OT::GetInt('proID');

	$retList = '
		dealOption = document.getElementById("proID").options;
		dealOption.length=0; 
		';

	switch ($proType){
		case 'host':
			$chkexe = $DB->query('select HD_ID,HD_theme,HD_priceYear from '. OT_dbPref .'hostData where HD_userState=1 order by HD_rank ASC');
			while ($rs = $chkexe->fetch()){
				$retList .= '
				dealOption.add(new Option("'. $rs['HD_theme'] .'（年付：'. floatval($rs['HD_priceYear']) .'）","'. $rs['HD_ID'] .'"));
				';
			}
			unset($chkexe);
			break;
	
		case 'vps':
			$chkexe = $DB->query('select VAD_ID,VAD_theme,VAD_priceMonth,VAD_priceYear from '. OT_dbPref .'vpsApiData where VAD_userState=1 order by VAD_rank ASC');
			while ($rs = $chkexe->fetch()){
				$retList .= '
				dealOption.add(new Option("'. $rs['VAD_theme'] .'（月付：'. floatval($rs['VAD_priceMonth']) .'，年付：'. floatval($rs['VAD_priceYear']) .'）","'. $rs['VAD_ID'] .'"));
				';
			}
			unset($chkexe);
			break;
	
		default :
			JS::AlertEnd('proType参数有误（'. $proType .'）');
			break;
	}

	echo($retList .'document.getElementById("proID").value="'. $proID .'";');
}

?>