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


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

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

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


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



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

	case 'createTab':
		CreateTab();
		break;

	case 'clear':
		ClearDeal();
		break;

	default:
		die('err');
}

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





// 添加、修改
function deal(){
	global $DB,$MB,$mudi,$menuFileID,$menuTreeID;

	$backURL			= OT::PostStr('backURL');
	$dataType			= OT::PostRegExpStr('dataType','sql');
	$dataTypeCN			= OT::PostRegExpStr('dataTypeCN','sql');

	$addition			= OT::Post('addition');
		if (is_array($addition)){ $addition = implode(',',$addition); }
	$defIsAudit			= OT::PostInt('defIsAudit');
	$defIsNew			= OT::PostInt('defIsNew');
	$defIsHomeThumb		= OT::PostInt('defIsHomeThumb');
	$defIsThumb			= OT::PostInt('defIsThumb');
	$defIsImg			= OT::PostInt('defIsImg');
	$defIsFlash			= OT::PostInt('defIsFlash');
	$defIsMarquee		= OT::PostInt('defIsMarquee');
	$defIsRecom			= OT::PostInt('defIsRecom');
	$defIsTop			= OT::PostInt('defIsTop');
	$defMarkNews		= OT::PostInt('defMarkNews');
	$defVoteMode		= OT::PostInt('defVoteMode');
	$defVoteStr			= OT::PostStr('defVoteStr');
	$defIsReply			= OT::PostInt('defIsReply');
	$defTopicList		= OT::Post('defTopicList');
		if (is_array($defTopicList)){ $defTopicList = ','. implode(',',$defTopicList) .','; }
	$defTopAddiID		= OT::PostInt('defTopAddiID');
	$defAddiID			= OT::PostInt('defAddiID');
	$defIsCheckUser		= OT::PostInt('defIsCheckUser');
	$defUserGroupList	= OT::Post('defUserGroupList');
		if (is_array($defUserGroupList)){ $defUserGroupList = implode(',',$defUserGroupList); }
	$defUserLevel		= OT::PostInt('defUserLevel');
	$defScore1			= OT::PostInt('defScore1');
	$defScore2			= OT::PostInt('defScore2');
	$defScore3			= OT::PostInt('defScore3');
	$defCutScore1		= OT::PostInt('defCutScore1');
	$defCutScore2		= OT::PostInt('defCutScore2');
	$defCutScore3		= OT::PostInt('defCutScore3');
	$defReadNum1		= OT::PostInt('defReadNum1');
	$defReadNum2		= OT::PostInt('defReadNum2');
	$defTemplate		= OT::PostStr('defTemplate');
	$defTemplateWap		= OT::PostStr('defTemplateWap');
	$defIsSitemap		= OT::PostInt('defIsSitemap');
	$defIsXiongzhang	= OT::PostInt('defIsXiongzhang');
	$tabID				= OT::PostInt('tabID');
	$tabMaxNum			= OT::PostInt('tabMaxNum');
		if ($tabMaxNum < 5000 || $tabMaxNum > 80000){ $tabMaxNum = 10000; }
	$tabCheckMin			= OT::PostInt('tabCheckMin');
	$moreArea			= OT::Post('moreArea');
		if (is_array($moreArea)){ $moreArea = implode(',',$moreArea); }
	$prevNextArrow		= OT::PostInt('prevNextArrow');
	$prevAndNext		= OT::PostInt('prevAndNext');
	$is360meta			= OT::PostInt('is360meta');
	$isXiongzhang		= OT::PostInt('isXiongzhang');
	$xiongzhangId		= OT::PostStr('xiongzhangId');
	$isContentKey		= OT::PostInt('isContentKey');
	$isTime				= OT::PostInt('isTime');
	$isWriter			= OT::PostInt('isWriter');
	$isSource			= OT::PostInt('isSource');
	$isReadNum			= OT::PostInt('isReadNum');
	$isReplyNum			= OT::PostInt('isReplyNum');
	$isWapQrcode		= OT::PostInt('isWapQrcode');
	$newsVerCodeAnswer	= OT::PostStr('newsVerCodeAnswer');
	$newsVerCodeImg		= OT::PostStr('newsVerCodeImg');
	$newsVerCodeNote	= OT::PostStr('newsVerCodeNote');
	$keyWordNum			= OT::PostInt('keyWordNum');
	$readNum1			= OT::PostInt('readNum1');
		if ($readNum1 < 1){ $readNum1 = 1; }
	$readNum2			= OT::PostInt('readNum2');
		if ($readNum2 < 1){ $readNum2 = 1; }
	$oneReadNum			= OT::PostInt('oneReadNum');
	$isNewsVote			= OT::PostInt('isNewsVote');
	$isMarkNews			= OT::PostInt('isMarkNews');
	$newsVoteSecond		= OT::PostInt('newsVoteSecond');
	$isNewsReply		= OT::PostInt('isNewsReply');
	$newsReplyMode		= OT::PostInt('newsReplyMode');
	$changyanId1		= OT::PostStr('changyanId1');
	$changyanId2		= OT::PostStr('changyanId2');
	$changyanIsDashang	= OT::PostInt('changyanIsDashang');
	$changyanIsFace		= OT::PostInt('changyanIsFace');
	$newsReplyNum		= OT::PostStr('newsReplyNum');
		if ($newsReplyNum<1){ $newsReplyNum=20; }
	$newsReplySecond	= OT::PostInt('newsReplySecond');
	$newsReplyAudit		= OT::PostInt('newsReplyAudit');
	$newsReplyMaxLen	= OT::PostInt('newsReplyMaxLen');
	$newsReplyName		= OT::PostStr('newsReplyName');
	$isShareNews		= OT::PostInt('isShareNews');
	$shareNewsCode		= OT::PostStr('shareNewsCode');
	$newsVoteCode		= OT::PostStr('newsVoteCode');
	$isWumii			= OT::PostInt('isWumii');
	$isNoCollPage		= OT::PostInt('isNoCollPage');
	$isGoPage			= OT::PostInt('isGoPage');
	$isInte				= OT::PostInt('isInte');
	$inteContent		= OT::PostStr('inteContent');
	$inteMode			= OT::PostInt('inteMode');
	$eventStr			= OT::PostStr('eventStr');
	$copyAddiStr		= OT::PostRStr('copyAddiStr');
	$fileTitle			= OT::PostStr('fileTitle');
		if (strlen($fileTitle) == 0){ $fileTitle = '附件下载'; }
	$fileStyle			= OT::PostStr('fileStyle');
	$isHideFilePath		= OT::PostInt('isHideFilePath');
	$isUserView			= OT::PostInt('isUserView');
	$isUserMark			= OT::PostInt('isUserMark');
	$isUserReport		= OT::PostInt('isUserReport');
	$defFreeGroupList	= OT::Post('defFreeGroupList');
		if (is_array($defFreeGroupList)){ $defFreeGroupList = implode(',',$defFreeGroupList); }
	$defIsEnc			= OT::PostInt('defIsEnc');
	$defCutQuickMoney	= OT::PostFloat('defCutQuickMoney');
	$hiddenContent1		= OT::PostStr('hiddenContent1');
	$hiddenContent2		= OT::PostStr('hiddenContent2');
	$copyBtnName		= OT::PostStr('copyBtnName');
	$markNewsDay		= OT::PostInt('markNewsDay');
	$prevNextDay		= OT::PostInt('prevNextDay');
	$defIsUserFile		= OT::PostInt('defIsUserFile');

	$defScore4			= OT::PostInt('defScore4');
	$defScore5			= OT::PostInt('defScore5');
	$defCutScore4		= OT::PostInt('defCutScore4');
	$defCutScore5		= OT::PostInt('defCutScore5');
	$field1Name			= OT::PostStr('field1Name');
		// if (strlen($field1Name) == 0){ $field1Name = '自定义1'; }
	$field2Name			= OT::PostStr('field2Name');
		// if (strlen($field2Name) == 0){ $field2Name = '自定义2'; }
	$field3Name			= OT::PostStr('field3Name');
		// if (strlen($field3Name) == 0){ $field3Name = '自定义3'; }
	$payUserMul			= OT::PostInt('payUserMul');

	$title_family	= OT::PostStr('title_family');
	$title_size		= OT::PostInt('title_size');
	$title_color	= OT::PostStr('title_color');
	$titleStyle2	= OT::PostStr('titleStyle2');
	$titleStyle = '';
		if (strlen($title_family) > 0){ $titleStyle .= 'font-family:"'. $title_family .'";'; }
		if ($title_size > 10){ $titleStyle .= 'font-size:'. $title_size .'px;'; }
		if (strlen($title_color) > 0){ $titleStyle .= 'color:'. $title_color .';'; }

	$content_family	= OT::PostStr('content_family');
	$content_size	= OT::PostInt('content_size');
	$content_color	= OT::PostStr('content_color');
	$content_lineH	= OT::PostStr('content_lineH');
	$contentStyle2	= OT::PostStr('contentStyle2');
	$contentStyle = '';
		if (strlen($content_family) > 0){ $contentStyle .= 'font-family:"'. $content_family .'";'; }
		if ($content_size > 10){ $contentStyle .= 'font-size:'. $content_size .'px;'; }
		if (strlen($content_color) > 0){ $contentStyle .= 'color:'. $content_color .';'; }
		if (strlen($content_lineH) > 0){ $contentStyle .= 'line-height:'. $content_lineH .';'; }

	$sign				= OT::PostStr('sign');
	$authState			= OT::PostStr('authState');

	if ($backURL=='' || ($sign=='' && $authState!='false') ){
		JS::AlertBackEnd('表单内容接收不全');
	}

	$record=array();
	$record['IS_addition']			= $addition;
	$record['IS_defIsAudit']		= $defIsAudit;
	$record['IS_defIsNew']			= $defIsNew;
	$record['IS_defIsHomeThumb']	= $defIsHomeThumb;
	$record['IS_defIsThumb']		= $defIsThumb;
	$record['IS_defIsImg']			= $defIsImg;
	$record['IS_defIsFlash']		= $defIsFlash;
	$record['IS_defIsMarquee']		= $defIsMarquee;
	$record['IS_defIsRecom']		= $defIsRecom;
	$record['IS_defIsTop']			= $defIsTop;
	$record['IS_defMarkNews']		= $defMarkNews;
	$record['IS_defVoteMode']		= $defVoteMode;
	$record['IS_defVoteStr']		= $defVoteStr;
	$record['IS_defIsReply']		= $defIsReply;
	$record['IS_defTopAddiID']		= $defTopAddiID;
	$record['IS_defAddiID']			= $defAddiID;
	$record['IS_defIsCheckUser']	= $defIsCheckUser;
	$record['IS_defUserGroupList']	= $defUserGroupList;
	$record['IS_defUserLevel']		= $defUserLevel;
	$record['IS_defScore1']			= $defScore1;
	$record['IS_defScore2']			= $defScore2;
	$record['IS_defScore3']			= $defScore3;
	$record['IS_defCutScore1']		= $defCutScore1;
	$record['IS_defCutScore2']		= $defCutScore2;
	$record['IS_defCutScore3']		= $defCutScore3;
	$record['IS_defReadNum1']		= $defReadNum1;
	$record['IS_defReadNum2']		= $defReadNum2;
	$record['IS_defTopicList']		= $defTopicList;
	$record['IS_defIsSitemap']		= $defIsSitemap;
	$record['IS_defIsXiongzhang']	= $defIsXiongzhang;
	$record['IS_tabID']				= $tabID;
	$record['IS_tabMaxNum']			= $tabMaxNum;
	$record['IS_tabCheckMin']		= $tabCheckMin;
	$record['IS_moreArea']			= $moreArea;
	$record['IS_prevAndNext']		= $prevAndNext;
	$record['IS_is360meta']			= $is360meta;
	$record['IS_isXiongzhang']		= $isXiongzhang;
	$record['IS_xiongzhangId']		= $xiongzhangId;
	$record['IS_isContentKey']		= $isContentKey;
	$record['IS_isTime']			= $isTime;
	$record['IS_isWriter']			= $isWriter;
	$record['IS_isSource']			= $isSource;
	$record['IS_isReadNum']			= $isReadNum;
	$record['IS_isReplyNum']		= $isReplyNum;
	$record['IS_isWapQrcode']		= $isWapQrcode;
	$record['IS_isMarkNews']		= $isMarkNews;
	$record['IS_readNum1']			= $readNum1;
	$record['IS_readNum2']			= $readNum2;
	$record['IS_oneReadNum']		= $oneReadNum;
	$record['IS_isNewsVote']		= $isNewsVote;
	$record['IS_newsVoteSecond']	= $newsVoteSecond;
	$record['IS_isNewsReply']		= $isNewsReply;
	$record['IS_newsReplyName']		= $newsReplyName;
	$record['IS_newsReplyNum']		= $newsReplyNum;
	$record['IS_newsReplySecond']	= $newsReplySecond;
	$record['IS_newsReplyAudit']	= $newsReplyAudit;
	$record['IS_newsReplyMaxLen']	= $newsReplyMaxLen;
	$record['IS_isShareNews']		= $isShareNews;
	$record['IS_shareNewsCode']		= $shareNewsCode;
	$record['IS_newsVoteCode']		= $newsVoteCode;
	$record['IS_fileTitle']			= $fileTitle;
	$record['IS_fileStyle']			= $fileStyle;
	$record['IS_isHideFilePath']	= $isHideFilePath;
	$record['IS_defFreeGroupList']	= $defFreeGroupList;
	$record['IS_defIsEnc']			= $defIsEnc;
	$record['IS_defCutQuickMoney']	= $defCutQuickMoney;
	$record['IS_hiddenContent1']	= $hiddenContent1;
	$record['IS_hiddenContent2']	= $hiddenContent2;
	$record['IS_copyBtnName']		= $copyBtnName;
	$record['IS_markNewsDay']		= $markNewsDay;
	$record['IS_prevNextDay']		= $prevNextDay;
	$record['IS_defIsUserFile']		= $defIsUserFile;
	$record['IS_defScore4']			= $defScore4;
	$record['IS_defScore5']			= $defScore5;
	$record['IS_defCutScore4']		= $defCutScore4;
	$record['IS_defCutScore5']		= $defCutScore5;
	$record['IS_field1Name']		= $field1Name;
	$record['IS_field2Name']		= $field2Name;
	$record['IS_field3Name']		= $field3Name;
	$record['IS_payUserMul']		= $payUserMul;
	$record['IS_titleStyle']		= $titleStyle;
	$record['IS_titleStyle2']		= $titleStyle2;
	$record['IS_contentStyle']		= $contentStyle;
	$record['IS_contentStyle2']		= $contentStyle2;
	if (AppBase::Jud()){
		$record['IS_defTemplate']	= $defTemplate;
	}
	if (AppWap::Jud()){
		$record['IS_defTemplateWap']= $defTemplateWap;
	}
	// if (AppReport::Jud()){
		$record['IS_isUserReport']	= $isUserReport;
	// }
	// if (AppUserView::Jud()){
		$record['IS_isUserView']	= $isUserView;
	// }
	// if (AppUserMark::Jud()){
		$record['IS_isUserMark']	= $isUserMark;
	// }

	if ($authState != 'false'){
		$record['IS_keyWordNum']		= $keyWordNum;
		$record['IS_prevNextArrow']		= $prevNextArrow;
		$record['IS_newsReplyMode']		= $newsReplyMode;
		$record['IS_changyanId1']		= $changyanId1;
		$record['IS_changyanId2']		= $changyanId2;
		$record['IS_changyanIsDashang']	= $changyanIsDashang;
		$record['IS_changyanIsFace']	= $changyanIsFace;
		$record['IS_eventStr']			= $eventStr;
		$record['IS_copyAddiStr']		= $copyAddiStr;
		$record['IS_isNoCollPage']		= $isNoCollPage;
		$record['IS_isGoPage']			= $isGoPage;
	}

	$judRes = $DB->UpdateParam('infoSys',$record,'IS_ID=1');


	$fileResStr = '';
	$Cache = new Cache();
	$isJsRes =$Cache->Js('infoSys');
		if ($isJsRes){
			$fileResStr .= '\n../cache/infoSys.js 生成成功！';
		}else{
			$fileResStr .= '\n../cache/infoSys.js 生成失败，请检查该目录或者文件是否有写入/修改权限！';
		}
	$isCacheRes = $Cache->Php('infoSys');
		if ($isCacheRes){
			$fileResStr .= '\n../cache/infoSys.php 生成成功！';
		}else{
			$fileResStr .= '\n../cache/infoSys.php 生成失败，请检查该目录或者文件是否有写入/修改权限！';
		}
	$isSiteCss = AdmArea::MakeSiteCss();
		if ($isSiteCss){
			$fileResStr .= '\n../cache/web/site.css 生成成功！';
		}else{
			$fileResStr .= '\n../cache/web/site.css 生成失败，请检查该目录或者文件是否有写入/修改权限！';
		}

	if (Cache::UpdateConfigJs()){
		$fileResStr .= '\n../cache/js/configJs.js 生成成功！';
	}else{
		$fileResStr .= '\n../cache/js/configJs.js 生成失败，请检查该目录或者文件是否有写入/修改权限！';
	}

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】修改成功！',
		));

	JS::AlertHrefEnd('修改成功\n'. $fileResStr, $backURL);
}



function CreateTab(){
	global $DB,$dbName;

	$backURL		= OT::GetStr('backURL');
	$tabID			= OT::GetInt('tabID');

	$tabNum = $DB->GetOne('select IS_tabNum from '. OT_dbPref .'infoSys');
	$tabName = 'infoContent'. $tabID;
	if ($DB->IsTab($tabName)){
		if ($tabID > $tabNum){
			$DB->UpdateParam('infoSys', array('IS_tabNum'=>$tabID), 'IS_ID=1');
		}
		JS::AlertBackEnd('该表（'. $tabName .'）已存在不需要再创建。');
	}

	if (OT_Database == 'sqlite'){
		$DB->query('CREATE TABLE "OT_'. $tabName .'" (
					"IC_ID"  INTEGER(11) NOT NULL,
					"IC_content"  TEXT,
					PRIMARY KEY ("IC_ID")
					);');
	}else{
		$DB->query('CREATE TABLE '. OT_dbPref . $tabName .' (
				  IC_ID int(11) NOT NULL DEFAULT "0",
				  IC_content longtext,
				  PRIMARY KEY (IC_ID)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8;');

		// 判断如果 OT_infoContent1表IC_content字段编码是utf8mb4，也更改
		$charset = $DB->GetOne('SELECT CHARACTER_SET_NAME FROM information_schema.`COLUMNS` WHERE TABLE_SCHEMA="'. $dbName .'" AND TABLE_NAME="'. OT_dbPref .'infoContent1" AND COLUMN_NAME="IC_content"');
			if ($charset == 'utf8mb4'){
				$DB->query('ALTER TABLE `'. OT_dbPref . $tabName .'` MODIFY COLUMN `IC_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci');
			}
	}

	if ($tabID > $tabNum){
		$DB->UpdateParam('infoSys', array('IS_tabNum'=>$tabID), 'IS_ID=1');
	}

	JS::AlertBackEnd('创建表 '. $tabName .' 完成。', $backURL);
}



function ClearDeal(){
	global $DB;

	$mudi2 = OT::GetStr('mudi2');

	switch ($mudi2){
		case 'prevNextId':
			$DB->query('update '. OT_dbPref .'info set IF_prevNewsId=0,IF_nextNewsId=0');
			JS::Alert('清空自动保存上/下一篇的信息完成');
			break;
	
		case 'markNewsId':
			$DB->query("update ". OT_dbPref ."info set IF_themeKeyIdStr=''");
			JS::Alert('清空自动保存相关文章信息完成');
			break;
	}

}
?>