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

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

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

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


//打开用户表，并检测用户是否登录
$MB->Open('','login');

$skin->WebTop();

echo('
<script language="javascript" type="text/javascript" src="js/inc/list.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/dataDeal.js?v='. OT_VERSION .'"></script>
');


switch($mudi){
	case 'manage':
		$MB->IsAdminRight('alertBack');
		manage();
		break;

}

$skin->WebBottom();

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





// 设置
function manage(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$pageCount,$recordCount;

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');

	$dealMode		= OT::GetStr('dealMode');
	$refTable		= OT::GetStr('refTable');
	$refField		= OT::GetStr('refField');
	// $refStr			= OT::GetRegExpStr('refStr','sql');
	// $repStr			= OT::GetRegExpStr('repStr','sql');
	$refStr			= OT::GetStr('refStr');
	$repStr			= OT::GetStr('repStr');

	$themeEncode = urlencode('数据处理(含关键词“'. $refStr .'”)');
	$dataTypeCNencode = urlencode('数据处理');
	$revEventStr = 'alert("该类型查询无该功能，只有文章才有.");return false;';
	$revUrl = '';
	if ($refTable == 'infoMessage'){
		$moreDelUrl = 'infoMessage_deal.php?mudi=moreDel';
		$delUrl = 'infoMessage_deal.php?mudi=del&dataMode=&dataModeStr=&dataType=news&dataTypeCN='. $dataTypeCNencode .'&theme='. $themeEncode .'&dataID=';
		if (strpos('|IM_username|IM_content|',$refField) === false){ $refField = 'IM_content'; }
	}elseif ($refTable == 'message'){
		$moreDelUrl = 'message_deal.php?mudi=moreDel';
		$delUrl = 'message_deal.php?mudi=del&dataMode=&dataModeStr=&dataType=message&dataTypeCN='. $dataTypeCNencode .'&theme='. $themeEncode .'&dataID=';
		if (strpos('|MA_username|MA_content|',$refField) === false){ $refField='MA_content'; }
	}elseif (strpos($refTable, 'infoContent') !== false){
		$revUrl = 'info.php?mudi=rev&dataType=news&dataTypeCN='. urlencode('文章') .'&backURL="+ escape(document.location.href) +"&dataID=';
		$moreDelUrl = 'info_deal.php?mudi=infoContentMoreDel';
		// $delUrl = 'info_deal.php?mudi=infoContentDel&dataMode=&dataModeStr=&dataType=message&dataTypeCN='. $dataTypeCNencode .'&theme='. $themeEncode .'&dataID=';
		$delUrl = '';
		if (strpos('|IC_content|',$refField) === false){ $refField='IC_content'; }
	}else{
		$refTable = 'info';
		$revEventStr = '';
		$revUrl = 'info.php?mudi=rev&dataType=news&dataTypeCN='. urlencode('文章') .'&backURL="+ escape(document.location.href) +"&dataID=';
		$moreDelUrl = 'info_deal.php?mudi=moreDel';
		$delUrl = 'info_deal.php?mudi=del&dataMode=&dataModeStr=&dataType=news&dataTypeCN='. $dataTypeCNencode .'&theme='. $themeEncode .'&dataID=';
		if (strlen($refField) == 0 || strpos('|IF_theme|IF_source|IF_writer|IF_img|IF_content|IF_encContent|IF_themeKey|IF_contentKey|IF_fileStr|',$refField) === false){ $refField='IF_theme'; }
	}

	$refFieldID = substr($refField,0,3) .'ID';

	$SQLstr = 'select '. $refFieldID .','. $refField .' from '. OT_dbPref . $refTable .' where '. $refField .' like "%'. str_replace(array('_','%'),array('\_','\%'),$refStr) .'%"';

	$replaceNote = '';
	if ($dealMode == 'replace'){
		$replaceNum = 0;
		$chkexe = $DB->query( $SQLstr );
		while ($row = $chkexe->fetch()){
			$replaceNum ++;
			$DB->UpdateParam($refTable, array($refField => str_replace($refStr,$repStr,$row[$refField])), $refFieldID .'='. $row[$refFieldID]);
		}
		$SQLstr = '';
		$replaceNote = '共有<span style="color:red;font-weight:bold;">'. $replaceNum .'</span>条记录被替换';
	}

	/*
	$skin->TableTop('share_refer.gif','','文章批量处理');
		echo('
		<form id="infoForm" name="infoForm" method="get" action="dataDeal_deal.php?mudi=deal" target="infoResultBox">
		<input type="hidden" name="mudi" value="deal" />
		<input type="hidden" name="dataType" value="'. $dataType .'" />
		<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />

		<table width="98%" align="center" border="0" cellSpacing="0" cellPadding="0" summary="" class="padd5">
		<tr>
			<td style="width:100%;">
				
				<select id="refInfoType" name="refInfoType">
					<option value="saveRemImg" '. Is::Selected($refDatabase,'saveRemImg') .'>保存文章内容远程图片</option>
					<option value="keyWord" '. Is::Selected($refDatabase,'keyWord') .'>关键词/标签</option>
				</select>
				&ensp;&ensp;&ensp;&ensp;
				文章ID<input type="text" id="refInfoStartID" name="refInfoStartID" size="8" value="" onkeyup="if (this.value!=FiltInt(this.value)){this.value=FiltInt(this.value)}" />至<input type="text" id="refInfoEndID" name="refInfoEndID" size="8" value="" onkeyup="if (this.value!=FiltInt(this.value)){this.value=FiltInt(this.value)}" />
				&ensp;&ensp;&ensp;&ensp;
				一次处理数量<input type="text" id="refInfoRunNum" name="refInfoRunNum" size="8" value="10" onkeyup="if (this.value!=FiltInt(this.value)){this.value=FiltInt(this.value)}" />
				&ensp;&ensp;&ensp;&ensp;
				<input type="submit" value="执 行" />
				<center style="margin-top:15px;"><iframe id="infoResultBox" name="infoResultBox" frameborder="0" allowTransparency="true" scrolling="no" style="width:710px;height:30px;" src="about:blank"></iframe></center>
			</td>
		</tr>
		</table>
		</form>
		');
	$skin->TableBottom();

	echo('
	<br />
	');
	*/

	$skin->TableTop('share_refer.gif','',$dataTypeCN .'查询');
		echo('
		<form id="refForm" name="refForm" method="get" action="">
		<input type="hidden" name="mudi" value="'. $mudi .'" />
		<input type="hidden" name="dataType" value="'. $dataType .'" />
		<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />
		<input type="hidden" id="dealMode" name="dealMode" value="'. $dealMode .'" />

		<table width="98%" align="center" border="0" cellSpacing="0" cellPadding="0" summary="" class="padd5">
		<tr>
			<td style="width:100%;">
				<select id="refTable" name="refTable" onchange="LoadFiledData()">
					<option value="info" '. Is::Selected($refTable,'info') .'>文章</option>
					<option value="infoMessage" '. Is::Selected($refTable,'infoMessage') .'>评论</option>
					<option value="message" '. Is::Selected($refTable,'message') .'>留言</option>
					<option value="collItem" '. Is::Selected($refTable,'collItem') .'>采集项目</option>
					<option value="collResult" '. Is::Selected($refTable,'collResult') .'>采集结果</option>
					');
					$maxNewsNum = 0;
					$infoSysArr = Cache::PhpFile('infoSys');
					$tabArr = $DB->GetTabArr('xiao');
					for ($i=1; $i<=$infoSysArr['IS_tabNum']; $i++){
						if (in_array(strtolower(OT_dbPref) .'infocontent'. $i, $tabArr)){
							$maxNewsNum = $DB->GetOne('select count(IC_ID) from '. OT_dbPref .'infoContent'. $i);
							echo('<option value="infoContent'. $i .'" '. Is::Selected($refTable,'infoContent'. $i) .'>内容表'. $i .'（'. $maxNewsNum .'篇）</option>');
						}
					}

				echo('
				</select>&ensp;
				<select id="refField" name="refField">
				</select>
				&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;
				关键词<input type="text" id="refStr" name="refStr" size="12" style="width:250px;" value="'. $refStr .'" />
				<input type="button" value="查询" onclick=\'CheckRefForm("refer")\' />
				<!-- <br /> -->&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;
				替换成<input type="text" id="repStr" name="repStr" size="16" style="width:250px;" value="'. $repStr .'" />
				<label><input type="checkbox" id="repEmpty" name="repEmpty" value="1" />无内容</label>
				<input type="button" value="替换" onclick=\'CheckRefForm("replace")\' />&ensp;
				<center style="margin-top:15px;">'. $replaceNote .'</center>
				<div class="font2_2">
					查询：查询并列出含有“关键词”的记录列表。<br />
					替换：把符合条件的记录中“关键词”替换成替换词。<br />
				</div>
			</td>
		</tr>
		</table>
		</form>
		');
	$skin->TableBottom();

	echo('
	<br />
	');

	if (strlen($refStr) > 0 && strlen($SQLstr) > 0){
		echo('
		<form id="listForm" name="listForm" method="post" action="'. $moreDelUrl .'" onsubmit="return CheckListForm()">
		<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'">\')</script>
		<input type="hidden" name="dataType" value="'. $dataType .'" />
		<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />
		<input type="hidden" id="refTableStr" name="refTableStr" value="'. $refTable .'" />
		<input type="hidden" id="refFieldStr" name="refFieldStr" value="'. $refField .'" />
		<input type="hidden" id="refStrStr" name="refStrStr" value="'. $refStr .'" />
		<input type="hidden" id="repStrStr" name="repStrStr" value="'. $repStr .'" />
		');

		$skin->TableTop2('share_list.gif','','含关键词“'. $refStr .'”查询结果');
		$skin->TableItemTitle('4%,5%,7%,76%,8%','<input type="checkbox" id="selAll" name="selAll" onclick="CheckBoxAll()" />,序号,ID值,查询到的信息,修改&ensp;删除');

		$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
		$page		= OT::GetInt('page');
		$showRow=$DB->GetLimit($SQLstr,$pageSize,$page);
		if (! $showRow){
			//$skin->TableNoData();
		}else{
			$recordCount=$DB->GetRowCount();
			$pageCount=ceil($recordCount/$pageSize);
			if ($page < 1 || $page > $pageCount){$page=1;}

			echo('
			<tbody class="tabBody padd3td">
			');
			$number=1+($page-1)*$pageSize;
			$rowCount = count($showRow);
			for ($i=0; $i<$rowCount; $i++){
				if ($i % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }

				echo('
				<tr '. $bgcolor .' id="data'. $showRow[$i][$refFieldID] .'">
					<td align="center" class="selCheckbox"><input type="checkbox" name="selDataID[]" value="'. $showRow[$i][$refFieldID] .'" /></td>
					<td align="center">'. $number .'</td>
					<td align="center">'. $showRow[$i][$refFieldID] .'</td>
					<td align="left">'. str_replace($refStr,'<span style="color:red;">[关键词]</span>',Str::LimitChar(Str::RegExp($showRow[$i][$refField],'html'),180)) .'</td>
					<td align="center">
						<img src="images/img_rev.gif" class="pointer" onclick=\''. $revEventStr .'document.location.href="'. $revUrl . $showRow[$i][$refFieldID] .'";\' alt="修改" title="修改" />&ensp;&ensp;
						'. (strlen($delUrl)>0 ? '<img src="images/img_del.gif" class="pointer" onclick=\'if(confirm("你确定要删除？")==true){DataDeal.location.href="'. $delUrl . $showRow[$i][$refFieldID] .'"}\' alt="" />' : '<img src="images/img_del.gif" class="gray" alt="" />') .'
					</td>
				</tr>
				');
			$number ++;
			}
			echo('
			</tbody>
			<tr class="tabColorB padd5">
				<td align="left" colspan="20">
					<input type="button" value="全选" class="tabBottomBtn allSel" onclick="AllSelBox()" />
					<input type="button" value="反选" class="tabBottomBtn revSel" onclick="RevSelBox()" />
					&ensp;
					<input type="submit" value="批量删除" class="tabBottomBtn del" />
				</td>
			</tr>
			');
		}
		unset($showRow);

		echo('</form>');

		$skin->TableBottom2($pageCount, $pageSize, $recordCount);
	}
		
}

?>