<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：QQ877873666
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//用户检测
$MB->Open('','login',10);



switch($mudi){
	case 'infoSet':
		$menuFileID = 525;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		InfoSet();
		break;

	default:
		die('err');
}

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





// 基本设置
function InfoSet(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN;

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

	$fieldArr = array();
	switch ($type){
		case 'apiUsers':
			$fieldArr['apiUrl']		= OT::PostStr('apiUrl');
			break;

		case 'onePage':
			$fieldArr['siteUrl']		= OT::PostStr('siteUrl');
			$fieldArr['endTimeMode']	= OT::PostInt('endTimeMode');
			$fieldArr['endTimeAlert']	= OT::PostStr('endTimeAlert');
			$fieldArr['endTimeUrl']		= OT::PostStr('endTimeUrl');
			$fieldArr['userRevArea']	= OT::PostArrStr('userRevArea');
			$fieldArr['isRevAudit']		= OT::PostInt('isRevAudit');
			break;
	
		default :
			break;
	}

	$succNum = $failNum = $addNum = $revNum = 0;
	foreach ($fieldArr as $key => $val){
		if (in_array($key, array('apiUrl','siteUrl'))){
			if (in_array($val,array('http://','https://',''))){
				$val = '';
			}else{
				if (! Is::HttpUrl($val)){ $val = GetUrl::HttpHead() . $val; }
				if (substr($val,-1) != '/'){ $val .= '/'; }
			}
		}

		$record = array();
		$record['TF_type']		= $type;
		$record['TF_name']		= $key;
		$record['TF_value']		= $val;
		// print_r($record);die();
		$crow = $DB->GetRow('select TF_ID from '. OT_dbPref .'tabField where TF_type='. $DB->ForStr($type) .' and TF_name='. $DB->ForStr($key));
		if ($crow){
			$judRes = $DB->UpdateParam('tabField', $record, 'TF_ID='. $crow['TF_ID']);
			$revNum ++;
		}else{
			$judRes = $DB->InsertParam('tabField', $record);
			$addNum ++;
		}
			if ($judRes){
				$succNum ++;
			}else{
				$failNum ++;
			}
	}

	$typeCN = StrCN::TabFieldType($type);

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】['. $typeCN .']保存成功 '. $succNum .' 项，失败 '. $failNum .' 项（添加'. $addNum .'条，修改'. $revNum .'条）！',
		));

	JS::AlertHrefEnd('【'. $typeCN .'】保存成功 '. $succNum .' 项，失败 '. $failNum .' 项（添加'. $addNum .'条，修改'. $revNum .'条）！', $backURL);

}

?>