<?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/infoMessage.js?v='. OT_VERSION .'"></script>
');


switch ($mudi){
	case 'manage':
		$MB->IsSecMenuRight('alertBack',140,$dataType);
		manage();
		break;

	case 'show':
		$MB->IsSecMenuRight('alertClose',144,$dataType);
		show();
		break;

	default:
		die('err');
}

$skin->WebBottom();

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





// 管理
function manage(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$pageCount,$recordCount,$dbPathPart;

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

	$refInfoID		= OT::GetInt('refInfoID');
	$refTheme		= OT::GetRegExpStr('refTheme','sql');
	$refUsername	= OT::GetRegExpStr('refUsername','sql');
	$refContent		= OT::GetRegExpStr('refContent','sql');
	$refType		= OT::GetStr('refType');
		if (! in_array($refType, array('pc','wap'))){ $refType = ''; }
	$refState		= OT::GetInt('refState',-1);
	$refReply		= OT::GetInt('refReply',-1);
	$refDate1		= OT::GetStr('refDate1');
		if (! strtotime($refDate1)){ $refDate1=''; }
	$refDate2		= OT::GetStr('refDate2');
		if (! strtotime($refDate2)){ $refDate2=''; }

	$SQLstr='select IM.*,IF_theme from '. OT_dbPref .'infoMessage as IM left join '. OT_dbPref .'info as IF1 on IM.IM_infoID=IF1.IF_ID where 1=1';

	if ($refInfoID > 0){
		$infoIdStr = '<span class="font2_2">锁定</span>';
		$SQLstr .= ' and IM_infoID='. $refInfoID;
	}else{
		$infoIdStr = '';
	}
	if ($refTheme != ''){ $SQLstr .= " and IF_theme like '%". $refTheme ."%'"; }
	if ($refUsername != ''){ $SQLstr .= " and IM_username like '%". $refUsername ."%'"; }
	if ($refContent != ''){ $SQLstr .= " and IM_content like '%". $refContent ."%'"; }
	if (strlen($refType) > 0){
		if ($refType == 'pc'){
			$SQLstr .= ' and IM_type in ("pc","web")';
		}else{
			$SQLstr .= ' and IM_type='. $DB->ForStr($refType);
		}
	}
	if ($refState > -1){ $SQLstr .= ' and IM_state='. $refState .''; }
	if ($refReply > -1){ $SQLstr .= ' and IM_isReply='. $refReply; }
	if ($refDate1 != ''){ $SQLstr .= ' and IM_time>='. $DB->ForTime($refDate1); }
	if ($refDate2 != ''){ $SQLstr .= ' and IM_time<='. $DB->ForTime(TimeDate::Add('d',1,$refDate2)); }

	$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="dataMode" value="'. $dataMode .'" />
		<input type="hidden" name="dataModeStr" value="'. $dataModeStr .'" />
		<input type="hidden" name="dataType" value="'. $dataType .'" />
		<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />

		<table style="width:99%;" align="center" border="0" cellSpacing="0" cellPadding="0" summary="" class="padd5td">
		<tr>
			<td>
				&ensp;&ensp;&ensp;&ensp;昵称：<input type="text" name="refUsername" size="20" value="'. $refUsername .'" />
			</td>
			<td>
				留言内容：<input type="text" name="refContent" size="20" value="'. $refContent .'" />
			</td>
			<td>
				审核：
				<select id="refState" name="refState">
				<option value=""></option>
				<option value="1" '. Is::Selected($refState,1) .'>已审核</option>
				<option value="0" '. Is::Selected($refState,0) .'>未审核</option>
				</select>
				&ensp;&ensp;&ensp;&ensp;模板端：
				<select id="refType" name="refType">
				<option value=""></option>
				<option value="pc" '. Is::Selected($refType,'pc') .'>pc模板</option>
				<option value="wap" '. Is::Selected($refType,'wap') .'>wap模板</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>
				文章标题：<input type="text" name="refTheme" size="20" value="'. $refTheme .'" />'. $infoIdStr .'
			</td>
			<td>
				发布日期：<input type="text" name="refDate1" size="10" style="width:100px;" value="'. $refDate1 .'" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd\'})" />&ensp;
				至&ensp;<input type="text" name="refDate2" size="10" style="width:100px;" value="'. $refDate2 .'" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd\'})" />
			</td>
			<td>
				回复：
				<select id="refReply" name="refReply">
				<option value=""></option>
				<option value="1" '. Is::Selected($refReply,1) .'>已回复</option>
				<option value="0" '. Is::Selected($refReply,0) .'>未回复</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="center" style="padding:5px;padding-top:20px" colspan="3">
				<input type="image" src="'. AdmTpl::ImgSrc('button_refer') .'" />
				&ensp;&ensp;&ensp;&ensp;
				<img src="'. AdmTpl::ImgSrc('button_reset') .'" onclick=\'document.location.href="?mudi='. $mudi .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'"\' style="cursor:pointer;" alt="" />
			</td>
		</tr>
		</table>
		</form>
		');
	$skin->TableBottom();

	echo('
	<div style="padding:12px 6px 6px 6px;">
		【文章评论数更新】每次<input type="text" id="replyPageNum" name="replyPageNum" value="5000" style="width:80px;" />条，第<input type="text" id="replyPage" name="replyPage" value="1" style="width:50px;" />页&ensp;
		<input type="button" value="开始更新" onclick=\'DataDeal.location.href="infoMessage_deal.php?mudi=updateReplyNum&dataTypeCN='. urlencode($dataTypeCN) .'&pageNum="+ $id("replyPageNum").value +"&page="+ $id("replyPage").value +"&backURL="+ encodeURIComponent(document.location.href);\' />
		&ensp;<span id="replyRes" style="color:red;"></span>
	</div>

	<form id="listForm" name="listForm" method="post" action="infoMessage_deal.php?mudi=moreDel" onsubmit="return CheckListForm()">
	<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'">\')</script>
	<input type="hidden" id="dataType" name="dataType" value="'. $dataType .'" />
	<input type="hidden" id="dataTypeCN" name="dataTypeCN" value="'. $dataTypeCN .'" />
	<input type="hidden" id="dataMode" name="dataMode" value="'. $dataMode .'" />
	<input type="hidden" id="dataModeStr" name="dataModeStr" value="'. $dataModeStr .'" />
	');

	$skin->TableTop2('share_list.gif','',$dataTypeCN .'列表');
	$skin->TableItemTitle('4%,5%,25%,10%,11%,20%,9%,7%,9%','<input type="checkbox" id="selAll" name="selAll" onclick="CheckBoxAll()" />,序号,【模板端】留言内容,昵称,IP,文章标题,添加日期,状态,详细　删除');

	$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit($SQLstr .' order by IM_time DESC',$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=''; }

			$smTheme = $smContent = '';
			if ($showRow[$i]['IM_isReply'] == 1){
				$smTheme	= '文章评论被回复《'. $showRow[$i]['IF_theme'] .'》';
				$smContent	= '文章评论被回复《'. $showRow[$i]['IF_theme'] .'》！回复内容：'. $showRow[$i]['IM_reply'];
			}elseif ($showRow[$i]['IM_state'] == 1){
				$smTheme	= '文章评论审核通过《'. $showRow[$i]['IF_theme'] .'》';
				$smContent	= '恭喜！文章《'. $showRow[$i]['IF_theme'] .'》评论审核通过！';
			}

			$themeHead = $themeAddi = $ipCN = '';
			if (strlen(''. $showRow[$i]['IM_addiContent']) > 3 ){
				$themeAddi .= '&ensp;<span style="color:red;">[含回复]</span>';
			}
			if ($showRow[$i]['IM_isGetScore'] == 1){
				$themeAddi .= '&ensp;<span style="color:blue;" title="积分1：'. $showRow[$i]['IM_getScore1'] .'，积分2：'. $showRow[$i]['IM_getScore2'] .'，积分3：'. $showRow[$i]['IM_getScore3'] .'">[已获得积分]</span>';
			}
			if (strlen($showRow[$i]['IM_ipCN']) > 0 && strpos($showRow[$i]['IM_ipCN'],'*') === false){
				$ipCN = '<div style="color:#c0c0c0;">['. $showRow[$i]['IM_ipCN'] .']</div>';
			}
			if ($showRow[$i]['IM_userID'] > 0){
				$userTdStr = '
					<span style="word-break:break-all;color:red;" title="会员">'. $showRow[$i]['IM_username'] . AdmArea::UserInfoImg($showRow[$i]['IM_userID']) .'</span>
					<div>'. AppSiteMessage::AdminAddBtn($MB->mUserID, $showRow[$i]['IM_userID'], $showRow[$i]['IM_username'], $smTheme, $smContent) .'</div>
					';
			}else{
				$userTdStr = '<span style="word-break:break-all;" title="游客">'. $showRow[$i]['IM_username'] .'</span>';
			}
			if ($showRow[$i]['IM_type'] == 'web'){ $showRow[$i]['IM_type'] = 'pc'; }
			if (in_array($showRow[$i]['IM_type'], array('pc','wap'))){
				$themeHead .= '<span style="color:blue;" title="来至'. $showRow[$i]['IM_type'] .'模板">【'. $showRow[$i]['IM_type'] .'】</span>';
			}

			echo('
			<tr '. $bgcolor .' id="data'. $showRow[$i]['IM_ID'] .'">
				<td align="center" class="selCheckbox"><input type="checkbox" name="selDataID[]" value="'. $showRow[$i]['IM_ID'] .'" /></td>
				<td align="center">'. $number .'</td>
				<td align="left" style="word-break:break-all;">
					'. $themeHead .'
					'. Area::FaceSignToImg(Str::LimitChar(Str::RegExp($showRow[$i]['IM_content'],'html'),60),$dbPathPart) . $themeAddi .'
					<span id="themeAddi'. $showRow[$i]['IM_ID'] .'" style="color:blue;"></span>
				</td>
				<td align="center">'. $userTdStr .'</td>
				<td align="center">'. $showRow[$i]['IM_ip'] . $ipCN .'</td>
				<td align="left">
					'. $showRow[$i]['IF_theme'] .'
					<a href="../news/?'. $showRow[$i]['IM_infoID'] .'.html?rnd=user'. $showRow[$i]['IM_userID'] .'" target="_blank" class="font2_2">[预览]</a>
					<a href="?mudi='. $mudi .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&refInfoID='. $showRow[$i]['IM_infoID'] .'" class="font2_2">[锁定]</a>
				</td>
				<td align="center">'. $showRow[$i]['IM_time'] .'</td>
				<td align="center" style="line-height:1.4;">
					'. Adm::SwitchBtn('infoMessage',$showRow[$i]['IM_ID'],$showRow[$i]['IM_state'],'state','stateAudit') .'
					<div class="pointer" onclick=\'var a=window.open("?mudi=show&nohrefStr=close&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $showRow[$i]['IM_ID'] .'")\'>'. Adm::Switch3CN('reply',$showRow[$i]['IM_reply']) .'</div>
				</td>
				<td align="center">
					<img src="images/img_det.gif" style="cursor:pointer" onclick=\'var a=window.open("?mudi=show&nohrefStr=close&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $showRow[$i]['IM_ID'] .'")\' alt="" />&ensp;&ensp;
					<img src="images/img_del.gif" style="cursor:pointer" onclick=\'if(confirm("你确定要删除？")==true){ DataDeal.location.href="infoMessage_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['IM_username']) .'&dataID='. $showRow[$i]['IM_ID'] .'"}\' 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" />
				&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;
				<select id="moreSetTo" name="moreSetTo" onchange="MoreSetTo()">
					<option value="" style="color:red;"> ------ 批量设置 ------ </option>
					<option value="state1" style="color:#0066CC;">已审√（不加积分）</option>
					<option value="state0" style="color:#707070;">未审ㄨ</option>
				</select>
				<input type="hidden" id="moreSetToCN" name="moreSetToCN" value="" />
			</td>
		</tr>
		');
	}
	unset($showRow);

	echo('</form>');

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



function show(){
	global $DB,$skin,$mudi,$dbPathPart;

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');
	$dataType		= OT::GetStr('dataType');
	$dataTypeCN		= OT::GetStr('dataTypeCN');
	$dataID			= OT::GetInt2( OT::ParaArr('id') );

	$showexe=$DB->query('select * from '. OT_dbPref .'infoMessage where IM_ID='. $dataID .'');
	if (! $row = $showexe->fetch()){
		JS::AlertCloseEnd('指定ID错误');
	}else{
		$revUrl = OT::GetParam(array('judRevContent'));

		echo('
		<script language="javascript" type="text/javascript">
		webPathPart = "../";
		</script>
		<script language="javascript" type="text/javascript" src="'. $dbPathPart .'js/face.js?v='. OT_VERSION .'"></script>
		<script language="javascript" type="text/javascript">document.title="'. $dataTypeCN .'详细信息";</script>

		<table width="700" align="center" cellpadding="0" cellspacing="0" border="0" summary=""><tr><td>
		');
		if ($row['IM_userID'] > 0){
			$userTitle = '<span style="color:red;">会员</span>';
		}else{
			$userTitle = '昵称';
		}

		$skin->TableTop('share_list.gif','',''. $dataTypeCN .'详细信息');
		echo('
		<table style="width:100%" align="center" cellpadding="0" cellspacing="0" border="0" class="padd3">
		<tr>
			<td style="width:100px;"align="right">添加时间：</td>
			<td>'. $row['IM_time'] .'</td>
		</tr>
		<tr>
			<td align="right">'. $userTitle .'：</td>
			<td align="left">'. $row['IM_username'] .'</td>
		</tr>
		');
		if (OT::GetStr('judRevContent')=='true'){
			echo('
			<form name="replyForm" method="post" action="infoMessage_deal.php?mudi=revContent">
			<input type="hidden" name="dataType" value="'. $dataType .'" />
			<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />
			<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'" />\')</script>
			<input type="hidden" name="dataID" value="'. $row['IM_ID'] .'" />
			<tr>
				<td align="right">获得积分：</td>
				<td align="left">
					<select name="isGetScore">
						<option value="0" '. Is::Selected($row['IM_isGetScore'], 0) .'>未获得</option>
						<option value="1" '. Is::Selected($row['IM_isGetScore'], 1) .'>已获得</option>
					</select>
					积分1：<input type="text" name="getScore1" style="width:50px;" value="'. $row['IM_getScore1'] .'" />&ensp;&ensp;
					积分2：<input type="text" name="getScore2" style="width:50px;" value="'. $row['IM_getScore2'] .'" />&ensp;&ensp;
					积分3：<input type="text" name="getScore3" style="width:50px;" value="'. $row['IM_getScore3'] .'" />&ensp;&ensp;
				</td>
			</tr>
			<tr>
				<td align="right">顶踩：</td>
				<td align="left">
					顶：<input type="text" name="vote1" style="width:50px;" value="'. $row['IM_vote1'] .'" />&ensp;&ensp;&ensp;&ensp;
					踩：<input type="text" name="vote2" style="width:50px;" value="'. $row['IM_vote2'] .'" />
				</td>
			</tr>
			<tr style="min-height:60px;">
				<td align="right" valign="top">内容：</td>
				<td align="left" valign="top" style="word-break:break-all;padding-bottom:12px;">
					<textarea id="newContent" name="newContent" cols="30" rows="4" style="width:340px; height:120px;">'. Str::MoreReplace($row['IM_content'],'filthtml') .'</textarea>
					<div style="padding:6px 0;"><input type="submit" value="修改" /></div>
				</td>
			</tr>
			</form>
			');
		}else{
			echo('
			<tr>
				<td align="right">获得积分：</td>
				<td align="left">
					'. ($row['IM_isGetScore'] == 1 ? '<span style="color:blue;font-weight:bold;">已获得</span>' : '<span style="color:red;">未获得</span>') .'
					&ensp;&ensp;积分1：'. $row['IM_getScore1'] .'，积分2：'. $row['IM_getScore2'] .'，积分3：'. $row['IM_getScore3'] .'
				</td>
			</tr>
			<tr>
				<td align="right">顶踩：</td>
				<td align="left">
					<img src="../inc_img/userDing.gif" align="bottom" valign="top" alt="顶" title="顶" style="margin-right:2px;" />'. $row['IM_vote1'] .'&ensp;&ensp;
					<img src="../inc_img/userCai.gif" align="bottom" valign="top" alt="踩" title="踩" style="margin-right:2px;" />'. $row['IM_vote2'] .'&ensp;&ensp;
				</td>
			</tr>
			<tr style="min-height:60px;">
				<td align="right" valign="top">内容：</td>
				<td align="left" valign="top" style="word-break:break-all;padding-bottom:12px;">
					<div style="padding-bottom:6px;">'. Area::FaceSignToImg($row['IM_content'],$dbPathPart) .'</div>
					'. Area::GenTie($row['IM_ID'], $row['IM_addiContent'], $DB->GetOne('tplSys','TS_messageEvent'), 3, $dbPathPart) .'
					<div style="padding:5px 0;"><a href="'. $revUrl .'&judRevContent=true" class="font1_2" style="color:red;font-weight:bold;font-size:16px;">[修改]</a></div>
				</td>
			</tr>
			');
		}

		if (strpos($dataModeStr,'|openReply|') !== false){
			echo('
			<tr><td align="right" valign="top">回复：</td><td align="left">
				<span style="font-weight:bold;" class="font2_2 pointer" onclick=\'FaceShow("faceInitBox","replyContent");\'>[表情]</span>
				<div id="faceInitBox" style="width:330px;display:none;"></div>
				<form name="replyForm" method="post" action="infoMessage_deal.php?mudi=reply">
				<input type="hidden" name="theme" value="'. Str::MoreReplace($row['IM_username'],'input') .'" />
				<input type="hidden" name="dataType" value="'. $dataType .'" />
				<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />
				<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'" />\')</script>
				<input type="hidden" id="dataID" name="dataID" value="'. $row['IM_ID'] .'" />
				<textarea id="replyContent" name="replyContent" cols="30" rows="4" style="width:340px; height:80px;">'. $row['IM_reply'] .'</textarea>
				<input type="submit" value="保存" />
				</form>

			</td></tr>
			');
		}
		if (strpos($dataModeStr,'|openAddReply|') !== false){
			echo('
			<tr><td align="right" valign="top">回复：</td><td align="left">
				'. $row['IM_reply'] .'
				<form name="replyForm" method="post" action="infoMessage_deal.php?mudi=addReply" target="DataDeal" onsubmit=\'if ($id("addReplyContent").value==""){alert("回复内容不能为空.");return false;}\'>
				<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'" />\')</script>
				<input type="hidden" name="theme" value="'. Str::MoreReplace($row['IM_username'],'input') .'" />
				<input type="hidden" name="dataType" value="'. $dataType .'" />
				<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />
				<input type="hidden" id="dataID" name="dataID" value="'. $row['IM_ID'] .'" />
				<textarea id="addReplyContent" name="addReplyContent" cols="30" rows="4"></textarea>
				<input type="submit" value="确定回复" />
				</form>
			</td></tr>
			');
		}
		if (strpos($dataModeStr,'|openSetState|') !== false){
			echo('
			<tr><td align="right">状态：</td><td align="left">
				<select id="selectState" name="selectState">
				<option value="0" '. Is::Selected($row['IM_state'],0) .'>待审核</option>
				<option value="1" '. Is::Selected($row['IM_state'],1) .'>审核通过</option>
				</select>
				<input type="button" value="设置" onclick=\'document.location.href="infoMessage_deal.php?mudi=setState&nohrefStr=close&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $row['IM_ID'] .'&theme='. urlencode($row['IM_username']) .'&backURL="+ encodeURIComponent(document.location.href) +"&newState="+ document.getElementById("selectState").value +""\' />
			</td></tr>
			');
		}
		echo('
		</table>
		');
		if ($row['IM_userID'] > 0 && $row['IM_isGetScore'] == 1){
			echo('<div style="padding:15px;color:red;font-size:16px;">提醒：已获得的积分，不会因为设置【未审核】或【未获得】而收回会员积分，如需要收回请手动对会员进行扣积分操作。</div>');
		}

		$skin->TableBottom();

		echo('
		</td></tr></table>
		');
	}

}
?>