Location: PHPKode > projects > PhpBlock > A9.8/script/message/messagelist.php
<?php
//To include in a module file
include_once $PATH_TO_CODE."/script/connect.php";
include_once $PATH_TO_CODE."/script/disconnect.php";
include_once $PATH_TO_CODE."/script/fonction.php";
include_once $PATH_TO_CODE."/script/player.class.php";
include_once $PATH_TO_CODE."/script/block.class.php";
include_once $PATH_TO_CODE."/script/message/playermessage.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/objectmanager.class.php";

getSessionPlayerId($locPlayerId);
global $gloObjectManager;
$locPlayer = $gloObjectManager->getPlayer($locPlayerId);

initLanguageWithPlayer($locPlayer);

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<table border=1 width="100%">
<?php
function getHTMLLinkToCenterToXYZ($x, $y, $z) {
	//FIXME : this function already exists in javascript !
	return "<a href='' onclick='javascript:return centerToZoneReturnFalse($x, $y, $z)'>".Zone::staticGetTextZoneCoord(Zone::getZoneId($x, $y, $z))."</a>";
}
$locFilter=getGetPost("filter", 0);
switch($locFilter) {
	case -4:
		$locIsMessageUnread=PlayerMessage::getInstance()->getPlayerMessages($locPlayerId, PlayerMessage::$VERY_BAD, PlayerMessage::$UNREAD);
		$res = PlayerMessage::getInstance()->getPlayerMessages($locPlayerId, PlayerMessage::$VERY_BAD);
		break;
	case -3:
		$locIsMessageUnread=PlayerMessage::getInstance()->getPlayerMessages($locPlayerId, PlayerMessage::$BAD, PlayerMessage::$UNREAD);
		$res = PlayerMessage::getInstance()->getPlayerMessages($locPlayerId, PlayerMessage::$BAD);
		break;
	case -2:
		$locIsMessageUnread=PlayerMessage::getInstance()->getPlayerMessagesFromExclude(0, $locPlayerId, -1, PlayerMessage::$UNREAD);
		$res = PlayerMessage::getInstance()->getPlayerMessagesFromExclude(0, $locPlayerId);
		break;
	case -1:
		$locIsMessageUnread=PlayerMessage::getInstance()->getPlayerMessagesFrom(0, $locPlayerId, -1, PlayerMessage::$UNREAD);
		$res = PlayerMessage::getInstance()->getPlayerMessagesFrom(0, $locPlayerId);
		break;
	case 0:
		$locIsMessageUnread=PlayerMessage::getInstance()->getPlayerMessages($locPlayerId, -1, PlayerMessage::$UNREAD);
		$res = PlayerMessage::getInstance()->getPlayerMessages($locPlayerId);
		break;
	default:
		$locIsMessageUnread=PlayerMessage::getInstance()->getPlayerMessagesFrom($locFilter, $locPlayerId, -1, PlayerMessage::$UNREAD);
		$res = PlayerMessage::getInstance()->getPlayerMessagesFrom($locFilter, $locPlayerId);
		break;
}
$locIsMessageUnread = mysql_fetch_array($locIsMessageUnread);

//timestamp, fromPlayerId, toPlayerId, gravity, message, zoneId
echo "<tr><th>";
echo dgettext("default", "time");
echo "<th>";
echo dgettext("default", "from");
echo "<th>";
echo dgettext("default", "message");
echo "<th>";
echo dgettext("default", "location");
while($row  = mysql_fetch_array($res)) {
	$locTime=getTimeWithTimeStamp($row['timestamp']);
	$locFrom=$row['fromPlayerId'];

	//One stripslashes for get and post
	$locMessage = $row['message'];
	$locMessage=str_replace("\\n", "<br>", $locMessage);
	$locMessage=stripslashes(stripslashes($locMessage));
	$locMessageExplode = explode("<br>", $locMessage);
	$locMessageArray = array();
	foreach($locMessageExplode as $locCurrent) {
        $locCharWithoutSpace = 0;
        $locLengthOfCurrent = strlen($locCurrent);
        for($i = 0; $i < $locLengthOfCurrent; $i++) {
            if(" " == $locCurrent[$i]) {
                $locCharWithoutSpace++;
            } else {
                $locCharWithoutSpace = 0;
            }
            if($locCharWithoutSpace >= 200) {
                $locMs = str_split($locCurrent, 199);
                foreach($locMs as $locM) {
                    array_push($locMessageArray, " $locM<br>");
                }
                $locCharWithoutSpace = 0;
            }
        }
        if($i == $locLengthOfCurrent) {
            array_push($locMessageArray, "$locCurrent<br>");
        }
	}
	$locMessage = implode("", $locMessageArray);


	$locMessageForAnswer=$row['message'];
	$locMessageForAnswer=str_replace("'", " ", $locMessageForAnswer);

	$locLocation=$row['zoneId'];
	$locGravity=$row['gravity'];
	if($locFrom > 0) {
		$locFromPlayerName = $gloObjectManager->getPlayer($locFrom)->playerName;
		$locMessageAnswerExplode = explode("\\n", $locMessageForAnswer);
		$locMessageAnswerArray = array();
		foreach($locMessageAnswerExplode as $locCurrent) {
			if(strlen($locCurrent) >= 77) {
				$locMs = str_split($locCurrent, 65);
				foreach($locMs as $locM) {
					array_push($locMessageAnswerArray, "> $locM\\n");
				}
			} else {
				array_push($locMessageAnswerArray, "> $locCurrent\\n");
			}
		}
		$locMessageAnswer = implode("", $locMessageAnswerArray);
		$locMessageAnswer = "> $locFromPlayerName wrote:\\n$locMessageAnswer ";
		$locFrom = "<a href='javascript:replyToPlayer(".$row['fromPlayerId'].", \"".$locMessageAnswer."\")'>$locFromPlayerName<a>";
	} else {
		$locFrom = "-";
	}
	$locLocation= ($locLocation > 0?"$locLocation":false);
	$locAbsGravity = abs($locGravity)*255/PlayerMessage::$MAX_GRAVITY;
	if($locGravity >= 0) {
		$locHtmlColor=rgb2html(255-$locAbsGravity, 255, 0);
	} else {
		$locHtmlColor=rgb2html(255, 255-$locAbsGravity, 0);
	}
	echo "<tr bgcolor=\"$locHtmlColor\"><td>$locTime<td>$locFrom<td>$locMessage<td align=center>";
	if($locLocation) {
		list($x, $y, $z) = Zone::getZoneCoord($locLocation);
		echo getHTMLLinkToCenterToXYZ($x, $y, $z);
	} else {
		echo "-";
	}
	echo "<tr/>";
}
if($locIsMessageUnread) {
	?>
	<script language="javascript">
	showMessageList();
</script>
<?php
}
?>
</table>
</div>
</body>
</html>
<?php
PlayerMessage::getInstance()->setAllMessagesStatus($locPlayerId, PlayerMessage::$READ);
disconnect();
?>
Return current item: PhpBlock