<?php 
error_reporting(0);
if(!$userlogined==true){exit("<script type=\"text/javascript\">location.href='".cd_webpath."user/login.php?login_referer=".cd_webpath."user/".rewrite_url('space.php?do=pm')."';</script>");}
?>
  <div class="user"> 
   <div class="user_center"> 
<?php
include_once('source/space_menu.php');
$new = SafeRequest("new","get");
?>
<?php if($view==""){?>
    <div class="user_main"> 
     <div class="uMain_content"> 
      <div class="main_nav"> 
       <ul> 
        <li class="message"> <a href="<?php echo rewrite_url('space.php?do=pm');?>" class="on">我的私信</a> </li> 
       </ul> 
      </div> 
      <div class="big_list"> 
        <li> <a <?php if($new == ""){echo " class=\"current\"";} ?> href="<?php echo rewrite_url('space.php?do=pm');?>">全部私信</a> </li> 
        <li> <a <?php if($new == "1"){echo " class=\"current\"";} ?> href="<?php echo rewrite_url('space.php?do=pm&new=1');?>">未读私信</a> </li>  
      </div> 
      <div id="msg" class="minHeight500"> 
<?php
global $db;
if($new) {
		$sql="select * from " . tname('message') . " where cd_uids='" . $CcTvAi_com_userid . "' and cd_dataid=0 and cd_readid=1 order by cd_addtime desc";
} else {
		$sql="select * from " . tname('message') . " where cd_uids='" . $CcTvAi_com_userid . "' and cd_dataid=0 order by cd_addtime desc";
}
$Arr=getuserpage($sql, 10); //sql,每页显示条数
$result=$db->query($Arr[2]);
$num=$db->num_rows($result);
$a=0;
if($result) {
		if($num>0) {
				echo '<div class="msgIgnore">';
				echo '<span class="name">全部私信列表</span>';
				echo '<span class="delAll" fromUid="1">清空所有私信</span>';
				echo '</div>';
				echo '<div class="msgList">';
				echo '<ul>';
				while($row=$db->fetch_array($result)) {
						$cd_content=preg_replace("/\[em:(\d+)]/is", "<img src=\"" . cd_webpath . "user/static/images/emot/e\\1.gif\" class=\"face\">", $row['cd_content']);
						$a=$a+1;
						if($row['cd_uid']) {
								$user=$db->getrow("select cd_nicheng from " . tname('user') . " where cd_id='" . $row['cd_uid'] . "'");
								echo '<li id="ms-' . $row['cd_id'] . '">';
								echo '<div class="icon"><a href="' . linkweburl($row['cd_uid'], $row['cd_uname']) . '" target="_blank"><img class="avatar-58" src="' . linkuserphoto($row['cd_uid'], 48) . '" title="' . $user['cd_nicheng'] . '"/></a></div>';
								echo '<div class="pm">';
								echo '<div class="h">';
								echo '<div class="f">';
								echo '<p><a href="' . linkweburl($row['cd_uid'], $row['cd_uname']) . '" target="_blank">' . $user['cd_nicheng'] . '</a> <span class="mtime">' . datetime($row['cd_addtime']) . '</span></p>';
								echo '<div class="c">' . $cd_content;
								if($row['cd_readid']==1) {
										echo '<span class="re">(未阅读)</span>';
								} else {
										echo '<span class="nore">(已阅读)</span>';
								}
								echo '<p><a href="' . cd_webpath . 'user/space.php?do=pm&view=msgDetail&day=' . $row['cd_id'] . '" target="_blank">查看详情</a></p></div>';
								echo '<a class="del" mid="' . $row['cd_id'] . '" type="0" toUid="' . $row['cd_id'] . '" fromUid="0">删除</a>';
								echo '</div>';
								echo '</div>';
								echo '</div>';
								echo '</li>';
						} else {
								$db->query("update " . tname('message') . " set cd_readid='0' where cd_id='" . $row['cd_id'] . "'");
								echo '<li id="ms-' . $row['cd_id'] . '">';
								echo '<div class="icon"><img class="avatar-58" src="' . cd_webpath . 'user/static/images/systempm.gif" title="' . $row['cd_uname'] . '"/></a></div>';
								echo '<div class="pm">';
								echo '<div class="h">';
								echo '<div class="f">';
								echo '<p>' . $row['cd_uname'] . ' <span class="mtime">' . datetime($row['cd_addtime']) . '</span></p>';
								echo '<div class="c">' . $cd_content . '</div>';
								echo '<a class="del" mid="' . $row['cd_id'] . '" type="0" toUid="' . $row['cd_id'] . '" fromUid="0">删除</a>';
								echo '</div>';
								echo '</div>';
								echo '</div>';
								echo '</li>';
						}
				}
				echo '</ul>';
				echo '</div>';
		} else {
				if($new) {
						echo '<div class="nothing">没有未读私信!</div>';
				} else {
						echo '<div class="nothing">暂未收到任何私信!</div>';
				}
		}
}
?>
<?php if($num>0){?>       <div class="page"><div class="pages"><?php echo $Arr[0]; ?><input type="text" maxlength="5" onkeydown="function c(event,val){e = event ? event :(window.event ? window.event : null);if(e.keyCode==13){val = parseInt(val);val=isNaN(val)||(val<=0)?1:val;window.location.href='<?php echo cd_webpath?>user/space.php?do=pm&pages='+val+'';return false;}else{return true;}};if(!c(event,this.value))return false;" title="输入页码，按回车快速跳转"/></div></div><div id="currPage"><?php echo SafeRequest("pages","get"); ?></div><?php } ?>
<div id="type" style="display: none"><?php echo $type; ?></div>
      </div> 
     </div> 
    </div> 
   </div> 
  </div> 
<?php }elseif($view=="msgDetail"){?>
    <div class="user_main"> 
     <div class="uMain_content"> 
      <div class="main_nav"> 
       <ul> 
        <li class="letter"><a href="<?php echo rewrite_url('space.php?do=pm');?>"><span>我的私信</span></a></li>
        <li class="particular"><a class="on" href="<?php echo rewrite_url('space.php?do=pm&view=msgDetail&day='.$day.'');?>"><span>查看详情</span></a></li>
       </ul> 
      </div> 
      <div id="msg" class="minHeight500"> 
<?php
global $db;
$sql="select * from " . tname('message') . " where cd_uid<>0 and cd_uids='$CcTvAi_com_userid' and cd_id='$day'";
if($row=$db->getrow($sql)) {
		$db->query("update " . tname('message') . " set cd_readid='0' where cd_id='$day'");
		$user=$db->getrow("select cd_nicheng from " . tname('user') . " where cd_id='" . $row['cd_uid'] . "'");
		echo '<div class="msgIgnore">';
		echo '<span class="name">与 <strong>' . $user['cd_nicheng'] . '</strong> 的短消息对话</span>';
		echo '<span class="reMessage" fromUid="' . $CcTvAi_com_userid . '" toUid="' . $row['cd_uid'] . '">删除本对话</span>';
		echo '</div>';
		echo '<div class="msgList">';
		echo '<ul>';
		$query=$db->query("select * from " . tname('message') . " where cd_dataid='" . $row['cd_id'] . "' order by cd_id asc");
		while($rows=$db->fetch_array($query)) {
				$cd_content=preg_replace("/\[em:(\d+)]/is", "<img src=\"" . cd_webpath . "user/static/images/emot/e\\1.gif\" class=\"face\">", $rows['cd_content']);
				$users=$db->getrow("select cd_nicheng from " . tname('user') . " where cd_id='" . $rows['cd_uid'] . "'");
				echo '<li id="msg-' . $rows['cd_id'] . '">';
				echo '<div class="icon"><a href="' . linkweburl($rows['cd_uid'], $rows['cd_uname']) . '" target="_blank"><img class="avatar-58" src="' . linkuserphoto($rows['cd_uid'], 48) . '" title="' . $users['cd_nicheng'] . '"/></a></div>';
				echo '<div class="pm">';
				echo '<div class="h">';
				echo '<div class="f">';
				echo '<p><a href="' . linkweburl($rows['cd_uid'], $rows['cd_uname']) . '" target="_blank">' . $users['cd_nicheng'] . '</a> <span class="mtime">' . datetime($rows['cd_addtime']) . '</span> <span class="del" mcid="' . $rows['cd_id'] . '" toUid="' . $row['cd_uids'] . '">删除</span></p>';
				echo '<div class="c">' . $cd_content . '</div>';
				echo '</div>';
				echo '</div>';
				echo '</div>';
				echo '</li>';
		}
		echo '<li>';
		echo '<div class="icon"><a href="' . linkweburl($CcTvAi_com_userid, $CcTvAi_com_username) . '" target="_blank"><img class="avatar-58" src="' . linkuserphoto($CcTvAi_com_userid, 48) . '" title="' . $CcTvAi_com_nicheng . '"/></a></div>';
		echo '<div class="pm">';
		echo '<div class="h">';
		echo '<div class="f">';
		echo '<div class="c">';
		echo '<div id="fnote" contenteditable="true" class="messageSend" name="fnote"></div>';
		echo '<div id="emot_fnote" class="emot" to="fnote"></div>';
		echo '<span class="button-main"><span><button class="reMsg" type="button" toUid="' . $row['cd_uid'] . '">回复</button></span></span>';
		echo '</div>';
		echo '</div>';
		echo '</div>';
		echo '</div>';
		echo '</li>';
		echo '</ul>';
		echo '</div>';
} else {
		echo '<div class="nothing">非法操作，请指定操作对象。</div>';
}
?>
      </div> 
     </div> 
    </div> 
   </div> 
  </div> 
<?php }?>
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/js/jquery/jquery.min.js"></script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/js/core.js"></script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/js/card.js"></script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/js/dialog.js"></script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/js/jquery/jquery.plugins.js"></script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/space/js/common.js"></script> 
  <script type="text/javascript">listenMsg.start();nav.init();nav.userMenu();nav.helpNoticeInit();</script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/space/js/message.js"></script>
<?php if($view==""){?>
  <script type="text/javascript">
nav.helpNoticeInit();
messageLib.msgDelInit();
messageLib.msgAllDelInit();	
messageLib.msgIgnoreInit();
  </script>
<?php }elseif($view=="msgDetail"){?>
  <script type="text/javascript">
nav.helpNoticeInit();
messageLib.reMsgDelInit(); 
messageLib.msgAddInit();
messageLib.reMsgOneDelInit();
  </script>
<?php }?>
<?php include_once('source/space_footer.php');?> 
</body>
</html>