/*
Copyright (C) 2004, 2005, 2006, 2007, 2008 Kestas J. Kuliukas
This file is part of phpDiplomacy.
phpDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
phpDiplomacy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with phpDiplomacy. If not, see .
*/
/**
* @package Base
*/
//require('datc.php'); die();
require('header.php');
/* Is the post box open, which thread are we viewing? */
$postboxopen = false;
$viewthread = false;
if( $User->type['User'] AND isset($_REQUEST['postboxopen'])) {
$postboxopen = (bool) $_REQUEST['postboxopen'];
} elseif (isset($_REQUEST['viewthread'])) {
$viewthread = (int) $_REQUEST['viewthread'];
} elseif (isset($_SESSION['viewthread'])) {
$viewthread = $_SESSION['viewthread'];
}
$new = array('message' => "", 'subject' => "", 'id' => (-1));
if(isset($_REQUEST['newmessage']) AND $User->type['User']
AND ($_REQUEST['newmessage'] != "") ) {
// We're being asked to send a message.
$new['message'] = $DB->msg_escape($_REQUEST['newmessage']);
if(isset($_REQUEST['newsubject'])) {
$new['subject'] = $DB->escape($_REQUEST['newsubject']);
}
$new['sendtothread'] = $viewthread;
if ( ! $User->formTicket() )
{
$messageproblem = "You may be attempting to send the same message twice. This problem can occur ".
"if you open multiple threads at once in multiple windows/tabs, or if you refresh a page after ".
"having sent a message.";
}
else
{
if(!$new['sendtothread']) { // New thread to the forum
if(empty($new['subject'])) {
$messageproblem="You haven't given a subject.";
} else {
$new['id'] = Message::send(0,
$User->id,
$new['message'],
$new['subject'],
'ThreadStart');
$messageproblem="Thread posted sucessfully.";
$new['message']=""; $new['subject']=""; $postboxopen=FALSE;
$viewthread = $new['id'];
}
} else { // To a thread
list($id) = $DB->sql_row("SELECT id
FROM pD_ForumMessages
WHERE id=".$new['sendtothread']."
AND type='ThreadStart'");
if(isset($id)) { // It's being sent to an existing thread.
$new['id'] = Message::send( $new['sendtothread'],
$User->id,
$new['message'],
'',
'ThreadReply');
$messageproblem="Reply posted sucessfully.";
$new['message']=""; $new['subject']="";
} else {
$messageproblem="The thread you attempted to reply to doesn't exist.";
}
}
}
if ( isset($messageproblem) and $new['id'] != -1 )
{
$_REQUEST['newmessage'] = '';
$_REQUEST['newsubject'] = '';
}
}
else
{
/*
* This isn't very secure, it could potentially lead to XSS attacks, but it
* is the easiest way to un-escape a failed post without having to use a
* UTF-8 library to replace strings
*/
$_REQUEST['newmessage'] = '';
$_REQUEST['newsubject'] = '';
}
$_SESSION['viewthread'] = $viewthread;
libHTML::starthtml();
if(isset($messageproblem) and !$new['sendtothread']) {
print '
';
if($postboxopen) {
print '
Post a message
If your post relates to a particular game please include the
URL or ID
of the game.
If you are posting a
feature request please check that it is not
already on the
todo list.
If your message is
very long please post a
small message
saying what the long message is about, and then post the long message as a
reply
to the short message.
';
} elseif($User->type['User']) {
print '
Post a message
';
}
//TODO: The forum queries need to be checked against the forum indexes; which are/aren't used, can they be improved?
$tabl = $DB->sql_tabl("SELECT
f.id, fromUserID, timeSent, message, subject, f.type, replies, u.username as fromusername, u.points as points, latestReplyID, IF(s.userID IS NULL,0,1) as online
FROM pD_ForumMessages f INNER JOIN pD_Users u ON ( f.fromUserID = u.id ) LEFT JOIN pD_Sessions s ON ( u.id = s.userID )
WHERE f.type = 'ThreadStart' OR ( f.type = 'Bulletin' AND ( toID = ".$User->id." OR toID = 0 ) )
order BY latestReplyID DESC ".
(isset($_REQUEST['viewall']) ? "" : "LIMIT ".Config::$messagesperpage ));
$switch = '2';
$first = true;
while( $message = $DB->tabl_hash($tabl) ) {
if ( $first ) $first = false;
else print '
';
$switch = ( $switch == '1' ? '2' : '1' );
print '
'.
($User->lastMessageIDViewed < $message['latestReplyID'] ? '

' : '').
'
'.$message['subject'].'
'.$message['message'].'
';
if ( $message['type'] == 'Bulletin' ) {
print '';
}
else
{
if( $message['id'] == $viewthread )
{
$replytabl = $DB->sql_tabl(
"SELECT f.id, fromUserID, f.timeSent, f.message, u.points as points, IF(s.userID IS NULL,0,1) as online,
u.username as fromusername
FROM pD_ForumMessages f, pD_Users u LEFT JOIN pD_Sessions s ON ( u.id = s.userID )
WHERE f.toID=".$message['id']." AND f.type='ThreadReply'
AND f.fromUserID = u.id
order BY f.timeSent ASC");
$replyfirst = true;
$replyswitch = '2';
while($reply = $DB->tabl_hash($replytabl) ) {
$replyswitch = ( $replyswitch == '1' ? '2' : '1' );
print '
'.
'
'.$reply['message'].'
';
$replyfirst = false;
}
unset($replytabl, $replyfirst, $replyswitch);
print '";
}
print '
';
libHTML::footer();
?>