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


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

	case 'show':
		$MB->IsSecMenuRight('alertClose',58,$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');

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

	$SQLstr='select * from '. OT_dbPref .'message where 1=1';

	if ($refUsername != ''){ $SQLstr .= " and MA_username like '%". $refUsername ."%'"; }
	if ($refContent != ''){ $SQLstr .= " and MA_content like '%". $refContent ."%'"; }
	if (strlen($refType) > 0){
		if ($refType == 'pc'){
			$SQLstr .= ' and MA_type in ("pc","web")';
		}else{
			$SQLstr .= ' and MA_type='. $DB->ForStr($refType);
		}
	}
	if ($refState > -1){ $SQLstr .= ' and MA_state='. $refState; }
	if ($refReply > -1){ $SQLstr .= ' and MA_isReply='. $refReply; }
	if ($refDate1 != ''){ $SQLstr .= ' and MA_time>='. $DB->ForTime($refDate1); }
	if ($refDate2 != ''){ $SQLstr .= ' and MA_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>
				&ensp;&ensp;&ensp;&ensp;审核：
				<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>
			<td>
				&ensp;&ensp;&ensp;
				回复：
				<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>
				留言内容：<input type="text" name="refContent" size="20" value="'. $refContent .'" />
			</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>
			</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('
	<br />

	<form id="listForm" name="listForm" method="post" action="message_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('5%,5%,37%,12%,13%,10%,8%,10%','<input type="checkbox" id="selAll" name="selAll" onclick="CheckBoxAll()" />,序号,【模板端】留言内容,昵称,IP,添加日期,状态,详细&ensp;删除');

	$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit($SQLstr .' order by MA_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]['MA_isReply'] == 1){
				$msgStr = Str::LimitChar(Str::RegExp($showRow[$i]['MA_content'],'html'),20);
				$smTheme	= '留言被回复《'. $msgStr .'》';
				$smContent	= '留言被回复《'. $msgStr .'》！回复内容：'. $showRow[$i]['MA_reply'];
			}

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

			echo('
			<tr '. $bgcolor .' id="data'. $showRow[$i]['MA_ID'] .'">
				<td align="center" class="selCheckbox"><input type="checkbox" name="selDataID[]" value="'. $showRow[$i]['MA_ID'] .'" /></td>
				<td align="center">'. $number .'</td>
				<td align="left" style="word-break:break-all;">
					'. $themeHead .'
					'. Area::FaceSignToImg(Str::LimitChar(Str::RegExp($showRow[$i]['MA_content'],'html'),80),$dbPathPart) . $themeAddi .'
					<span id="themeAddi'. $showRow[$i]['MA_ID'] .'" style="color:blue;"></span></td>
				<td align="center">'. $userTdStr .'</td>
				<td align="center">'. $showRow[$i]['MA_ip'] . $ipCN .'</td>
				<td align="center">'. $showRow[$i]['MA_time'] .'</td>
				<td align="center" style="line-height:1.4;">
					'. Adm::SwitchBtn('message',$showRow[$i]['MA_ID'],$showRow[$i]['MA_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]['MA_ID'] .'")\'>'. Adm::Switch3CN('reply',$showRow[$i]['MA_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]['MA_ID'] .'")\' alt="" />&ensp;&ensp;
					<img src="images/img_del.gif" style="cursor:pointer" onclick=\'if(confirm("你确定要删除？")==true){DataDeal.location.href="message_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['MA_username']) .'&dataID='. $showRow[$i]['MA_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,$systemArr,$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 .'message where MA_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['MA_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['MA_time'] .'</td>
		</tr>
		<tr>
			<td align="right">'. $userTitle .'：</td>
			<td align="left">'. $row['MA_username'] .'</td>
		</tr>
		');
		if (OT::GetStr('judRevContent')=='true'){
			echo('
			<form name="replyForm" method="post" action="message_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['MA_ID'] .'" />
			<tr>
				<td align="right">获得积分：</td>
				<td align="left">
					<select name="isGetScore">
						<option value="0" '. Is::Selected($row['MA_isGetScore'], 0) .'>未获得</option>
						<option value="1" '. Is::Selected($row['MA_isGetScore'], 1) .'>已获得</option>
					</select>
					积分1：<input type="text" name="getScore1" style="width:50px;" value="'. $row['MA_getScore1'] .'" />&ensp;&ensp;
					积分2：<input type="text" name="getScore2" style="width:50px;" value="'. $row['MA_getScore2'] .'" />&ensp;&ensp;
					积分3：<input type="text" name="getScore3" style="width:50px;" value="'. $row['MA_getScore3'] .'" />&ensp;&ensp;
				</td>
			</tr>
			<tr>
				<td align="right">顶踩：</td>
				<td align="left">
						顶：<input type="text" name="vote1" style="width:50px;" value="'. $row['MA_vote1'] .'" />&ensp;&ensp;&ensp;&ensp;
						踩：<input type="text" name="vote2" style="width:50px;" value="'. $row['MA_vote2'] .'" />
				</td>
			</tr>
			<tr style="min-height:60px;">
				<td align="right" valign="top">内容：</td>
				<td align="left" valign="top" style="word-break:break-all;">
					<textarea id="newContent" name="newContent" cols="30" rows="4" style="width:340px; height:120px;">'. Str::MoreReplace($row['MA_content'],'filthtml') .'</textarea>
					<input type="submit" value="修改" />
				</td>
			</tr>
			</form>
			');
		}else{
			echo('
			<tr>
				<td align="right">获得积分：</td>
				<td align="left">
					'. ($row['MA_isGetScore'] == 1 ? '<span style="color:blue;font-weight:bold;">已获得</span>' : '<span style="color:red;">未获得</span>') .'
					&ensp;&ensp;积分1：'. $row['MA_getScore1'] .'，积分2：'. $row['MA_getScore2'] .'，积分3：'. $row['MA_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['MA_vote1'] .'&ensp;&ensp;
					<img src="../inc_img/userCai.gif" align="bottom" valign="top" alt="踩" title="踩" style="margin-right:2px;" />'. $row['MA_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;">
					<div style="padding-bottom:6px;">'. Area::FaceSignToImg($row['MA_content'],$dbPathPart) .'</div>
					'. Area::GenTie($row['MA_ID'], $row['MA_addiContent'], $DB->GetOne('tplSys','TS_messageEvent'), 3, $dbPathPart) .'
					&ensp;<a href="'. $revUrl .'&judRevContent=true" class="font1_2" style="color:red;font-weight:bold;">[修改]</a>
				</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="message_deal.php?mudi=reply">
				<input type="hidden" name="theme" value="'. Str::MoreReplace($row['MA_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['MA_ID'] .'" />
				<textarea id="replyContent" name="replyContent" cols="30" rows="4" style="width:340px; height:80px;">'. $row['MA_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['MA_reply'] .'
				<form name="replyForm" method="post" action="message_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['MA_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['MA_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['MA_state'],0) .'>待审核</option>
				<option value="1" '. Is::Selected($row['MA_state'],1) .'>审核通过</option>
				</select>
				<input type="button" value="设置" onclick=\'document.location.href="message_deal.php?mudi=setState&nohrefStr=close&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $row['MA_ID'] .'&theme='. urlencode($row['MA_username']) .'&backURL="+ encodeURIComponent(document.location.href) +"&newState="+ document.getElementById("selectState").value +""\' />
			</td></tr>
			');
		}
		echo('
		</table>
		');
		if ($row['MA_userID'] > 0 && $row['MA_isGetScore'] == 1){
			echo('<div style="padding:15px;color:red;font-size:16px;">提醒：已获得的积分，不会因为设置【未审核】或【未获得】而收回会员积分，如需要收回请手动对会员进行扣积分操作。</div>');
		}

		$skin->TableBottom();

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

}
?>