include "../include/before.php";
include "../include/show_navbar.php";
include "../include/show_page_title.php";
include "../include/show_cmd_button.php";
include "messages_fct.php";
include "../include/utils.php";
include "../include/classes/cselect.php";
//protected acces to this page
if ($auth->member_id == '')
{
$_SESSION['original_area']="messages";
header("Location:../signin/signin.php");
die();
}
//end
$LIST_HEIGHT = $PAGE_COUNT * 20 + 50;
$folder = $_GET['folder'];
$page = $_GET['page'];
$message_id = $_GET['message_id'];
$err_id = $_GET['err_id'];
$order = $_GET['order'];
$order_var = $_GET['order_var'];
if ($order=='') $order = "DESC";
switch ($order_var)
{
case 'sender':
$order_clause = 'ORDER BY from_name '.$order;
break;
case 'subject':
$order_clause = 'ORDER BY message_subject '.$order;
break;
case 'message_date':
$order_clause = 'ORDER BY message_date '.$order;
break;
default:
$order_clause = 'ORDER BY message_date '.$order;
break;
}
//error messages
switch ($err_id)
{
case 1:
$err_msg = 'You may not create folders named "Inbox" or "Sent".';
break;
case 2:
$err_msg = "You have allready created a folder with that name.";
break;
case 3:
$err_msg = "You may not delete the Inbox and Sent directories.";
break;
}
//if folder is not set, default is inbox
if ($folder=='') $folder = "0";
//if page is not set, default to 1
if( $page=='' ) $page = 1;
//set the styles for the selected folder
$sender_label = "From";
if ($folder == "0")
{
$index_folder_class="details_link";
$index_bgcolor="#fae592";
$sent_bgcolor=$BG_COLOR1;
}
elseif ($folder == "sent")
{
$sent_folder_class="details_link";
$sent_bgcolor="#fae592";
$index_bgcolor=$BG_COLOR1;
$index_folder_class="details_link";
$sender_label = "To";
}
//other folder
else
{
$index_folder_class="details_link";
$index_bgcolor=$BG_COLOR1;
$sent_folder_class="details_link";
$sent_bgcolor=$BG_COLOR1;
}
//folder dispaly
$query_folder_list = "SELECT folder_id, folder_name FROM m_folders WHERE user_id = ".$auth->member_id;
$rs_folder_list = $conn->query($query_folder_list);
//ready the folder select (values are id's and lables are folder names)
$query_folder_list = "SELECT folder_id, folder_name
FROM m_folders
WHERE user_id = ".$auth->member_id." AND folder_id != '".$folder."'";
$rs_folder_list_select = $conn->query($query_folder_list);
$folder_list_select = new CSelect($folder,$conn);
//if folder is not inbox, there will be an option to move messages to inbox
if ($folder!=0)
{
$inbox_move_option = '';
}
// a message was selected - it will be displayed
if($message_id!="")
{
if ($folder!='sent')
{
//Set status to read.
$query = "UPDATE m_messages SET message_status=1 WHERE message_id = " . $message_id;
$conn->query($query);
}
//Select the message, with member information
$query = "SELECT A.*,UNIX_TIMESTAMP(message_date) AS date,
B.username AS from_username, B.gold AS from_gold,
C.username AS to_username, C.gold AS to_gold
FROM m_messages AS A
LEFT JOIN members AS B on A.from_id=B.id
LEFT JOIN members as C on A.to_id=C.id
WHERE A.message_id = " . $message_id;
$rs = $conn->query($query);
$row_curr_message = $conn->fetch_array($rs);
$current_message_id = $row_curr_message[ "message_id" ];
$current_message_body = $row_curr_message[ "message_body" ];
$current_message_from = $row_curr_message[ "from_username" ];
$current_message_to = $row_curr_message[ "to_username" ];
$current_message_subject = $row_curr_message[ "message_subject" ];
$current_message_date = $row_curr_message[ "date" ];
// implementing abuse
if ($folder=='sent')
{
$current_message_from_id = $row_curr_message['from_id'];
$current_message_to_id = $row_curr_message['to_id'];
}
else
{
$current_message_to_id = $row_curr_message['from_id'];
$current_message_from_id = $row_curr_message['to_id'];
}
//end abuse :D
//ready the add to contacts link, if the member is not a contact
if ( ($folder!='sent') && ($auth->member_id != $row_curr_message['from_id']) )
{
$query = "SELECT * FROM m_contact_list WHERE user_id = ".$auth->member_id." AND cl_user_id=".$row_curr_message['from_id'];
$rs_contacts = $conn->query($query);
if ($conn->num_rows($rs_contacts)==0)
{
$add_contact_link = ' [add to contacts]';
}
}
}
//get the total number of messages - paging needs this
if( $folder == 'sent' )
{
$query_count = "SELECT *, B.username AS from_name
FROM m_messages AS A LEFT JOIN members AS B ON A.to_id = B.id
WHERE A.from_id_status = 0 AND A.from_id = ".$auth->member_id;
}
else
{
$query_count = "SELECT *, B.username AS from_name, B.username AS to_name
FROM m_messages AS A LEFT JOIN members AS B ON A.from_id = B.id
LEFT JOIN members AS C ON A.to_id=C.id
WHERE A.to_id_status=0 AND A.to_id = ".$auth->member_id." AND A.folder_id = ".$folder;
}
$rs = $conn->query($query_count);
$total_messages = $conn->num_rows($rs);
if ($total_message!=0)
{
$LIST_HEIGHT = 30*$total_messages;
}
else
{
$LIST_HEIGHT = 60;
}
// label for the selected message, if any
if($auth->member_type == '1')
{
$message_label = 'No message is selected. Click on the subject to select one.
';
$gold_label = 'You can reply to this message';
}
else
{
$gold_label = 'This message was sent by a gold member';
if($message_id!='')
{
$message_label = '
You may only view and reply to messages sent to you by gold members.
Please upgrade to a paid subscription in order to view all messages and send messages of your own.
';
}
else
{
$message_label = '
You may only view and reply to messages sent to you by gold members.
Please upgrade to a paid subscription in order to view all messages and send messages of your own.
';
}
}
//shows the reply button if memember is gold or message is from gold member
if ( ($row_curr_message['from_gold']==1) || ($auth->member_type==1) )
{
$show_reply_button = 1;
}
?>