<?php
error_reporting(0);
global $db, $CcTvAi_com_userid;
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {
	exit();
}
close_browse();
if ($CcTvAi_com_userid) {
	$cd_uid=SafeRequest("uid", "post");
	if (!IsNumID($CcTvAi_com_userid)) {exit();}
	if (!IsNumID($cd_uid)) {exit();}
	$cd_wallContent=unescape(SafeRequest("wallContent", "post"));
	if(preg_match("/".cd_messagereplace."/i",$cd_wallContent)){
		exit('50001');
		}
	if ($cd_wallContent=="") {
		exit('10007');
	} else {
		$cookies="wall_add_$cd_uid";
		if ($_COOKIE[$cookies]=="yes") {
			exit('10002');
		} else {
			setcookie($cookies, "yes", time()+30);
			//入库
			$setarr=array(
				'cd_wallid' => 0,
				'cd_dataid' => $cd_uid,
				'cd_content' => $cd_wallContent,
				'cd_uid' => $CcTvAi_com_userid,
				'cd_uname' => $CcTvAi_com_username,
				'cd_uip' => getonlineip(),
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('wall', $setarr, 1);
			if ($cd_uid!=$CcTvAi_com_userid) {
				//检测是否已提交通知
				$query="select cd_id from " . tname('notice') . " where cd_icon='wall' and cd_uid='$CcTvAi_com_userid' and cd_uids='$cd_uid'";
				if ($rows=$db->getrow($query)) {
					$db->query("update " . tname('notice') . " set cd_addtime='" . date('Y-m-d H:i:s') . "' where cd_id='" . $rows['cd_id'] . "'");
				} else {
					$user=$db->getrow("select cd_name from " . tname('user') . " where cd_id='" . $cd_uid . "'");
					$rsc=$db->getrow("select cd_id from " . tname('wall') . " where cd_uid='$CcTvAi_com_userid' and cd_dataid='$cd_uid' order by cd_id desc");
					//入库
					$setarr=array(
						'cd_uid' => $CcTvAi_com_userid,
						'cd_uname' => $CcTvAi_com_username,
						'cd_uids' => $cd_uid,
						'cd_unames' => $user['cd_name'],
						'cd_icon' => 'wall',
						'cd_data' => '给你留言了&nbsp;<a href="' . cd_webpath .cd_webmlsinger. '/index.php?ac=wall&id=' . $cd_uid . '&day=' . $rsc['cd_id'] . '" target="_blank">查看详情</a>',
						'cd_dataid' => 0,
						'cd_state' => 1,
						'cd_addtime' => date('Y-m-d H:i:s')
					);
					inserttable('notice', $setarr, 1);
				}
			}
		}
	}
} else {
	exit('20001');
}
?>