<?php

// -----------------------------------------------------------------------
// This file is part of aroundme
// 
// Copyright (C) 2003, 2005 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
// 
// This program 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 General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
// -----------------------------------------------------------------------

?>


<form action="msg_list.php?<?php echo $message_box;?>=" method="post" name="message">

<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="560" valign="top">
			<div class="box_top">
				<?php echo $lang['section_messages'];?><br />
			</div>
			
			<div class="box_mid" style="padding: 9px;">
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td valign="top">
						<?php
						if (isset($messages)) {
						?>
						<table border="0" cellspacing="0" cellpadding="2" width="100%">
							<?php
							foreach($messages as $key => $i):
							?>
							<tr>
								<td valign="top">
									<?php
									if ($i['message_status'] == $message_status_read) {
									    echo "<a href=\"msg_item.php?message_id=" . $i['message_id'] . "\"><img src='" . $templatePath . "img/openned_mail.png' vspace='2' border='0'></a>&nbsp;<br />";
									}
									else if ($i['message_status'] == $message_status_unread) {
										echo "<a href=\"msg_item.php?message_id=" . $i['message_id'] . "\"><img src='" . $templatePath . "img/unopenned_mail.png' vspace='2' border='0'></a>&nbsp;<br />";
									}
									?>

								</td>
								<td valign="top">
									<?php echo $i['profile_nic'];?><br />
								</td>
								<td valign="top">
									<a href="msg_item.php?message_id=<?php echo $i['message_id'];?>"><?php echo $i['message_subject'];?></a><br />
								</td>
								<td valign="top">
									<?php echo strlen($i['message_body']);?><br />
								</td>
								<td valign="top">
									<?php echo $i['message_create_datetime'];?><br />
								</td>
								<td align="right" valign="top">
									<input type="checkbox" name="message_id[]" value="<?php echo $i['message_id'];?>" /><br />
								</td>
							</tr>
							<?php
							endforeach;
							?>
						</table>
					</td>
				</tr>
				<?php
				} else {
				?>
				<tr>
					<td>
						<?php echo $lang['err_no_messages'];?><br />
					</td>
				</tr>
				<?php }?>
				<tr>
					<td align="right">
						<spanclass="txt_footer">
						<br /><img src="<?php echo $templatePath;?>img/unopenned_mail.png" alt="" />&nbsp;<?php echo $lang['txt_unopened'];?>&nbsp;&nbsp;<img src="<?php echo $templatePath;?>img/openned_mail.png" alt="" />&nbsp;<?php echo $lang['txt_opened'];?>&nbsp;&nbsp;
						</span>
						<a href="msg_compose.php" class="link_urgent"><?php echo $lang['href_compose'];?></a><br />
					</td>
				</tr>
			</table>
			
			
			<?php if (isset($messages)) { ?>
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
			<div class="box_edit">
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td valign="top">
						<table width="100%" border="0" cellspacing="0" cellpadding="2">
							<?php if ($message_box != "save_box") { ?>
							<tr>
								<td colspan="2">
									<b><?php echo $lang['txt_mess_save'];?></b><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<?php echo $lang['txt_move_to_save_help'];?><br />
								</td>
								<td valign="top" align="right">
									<input type="submit" name="move_to_save" value="<?php echo $lang['sub_move_to_save'];?>" class="button_light" /><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<b><?php echo $lang['txt_mess_status'];?></b><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<?php echo $lang['txt_mess-status_help'];?><br />
								</td>
								<td valign="top" align="right" nowrap="nowrap">
									<input type="submit" name="set_read_messages" value="<?php echo $lang['sub_read'];?>" class="button_light" />&nbsp;&nbsp;&nbsp;
									<input type="submit" name="set_unread_messages" value="<?php echo $lang['sub_unread'];?>" class="button_light" /><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<b><?php echo $lang['txt_mess_delete'];?></b><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<?php echo $lang['txt_delete_help'];?><br />
								</td>
								<td valign="top" align="right" nowrap="nowrap">
									<input type="button" onClick="checkFormBoxes('message', 'message_id', 'check');" value="<?php echo $lang['sub_select_all'];?>" class="button_light" />&nbsp;&nbsp;
									<input type="submit" name="delete_messages" value="<?php echo $lang['sub_delete'];?>" class="button_light" /><br />
								</td>
							</tr>
							<?php  } ?>
						</table>
					</td>

					<td width="20">&nbsp;</td>
		
					<td width="100" valign="top">
						 <table border="0" cellspacing="0" cellpadding="2" width="100%">
							<tr>
								<td>
									<table width="100%" cellpadding="4" cellspacing="2" border="0">
						    			<tr>
											<td class="bg2">
												<b><?php echo $lang['txt_box'];?></b><br />
											</td>
											<td class="bg2">
												<?php echo $lang['txt_box_in'];?><br />
											</td>
											<td class="bg2">
												<?php echo $lang['txt_box_out'];?><br />
											</td>
											<td class="bg2">
												<?php echo $lang['txt_box_save'];?><br />
											</td>
											<td class="bg2">
												<?php echo $lang['txt_totals'];?><br />
											</td>
										</tr>
										
										<tr>
											<td class="bg3">
												<b><?php echo $lang['txt_messages'];?></b><br />
											</td>
											<td class="bg4">
												<?php echo $message_statistics['in_box_messages'];?>&nbsp;(<?php echo $message_statistics['unread'];?>)<br />
											</td>
											<td class="bg4">
												<?php echo $message_statistics['out_box_messages'];?><br />
											</td>
											<td class="bg4">
												<?php echo $message_statistics['save_box_messages'];?><br />
											</td>
											<td class="bg4">
												<b><?php echo $message_statistics['total_messages'];?></b><br />
											</td>
										</tr>
										
										<tr>
											<td class="bg3">
												<b><?php echo $lang['txt_size'];?></b><br />
											</td>
											<td class="bg4">
												<?php echo $message_statistics['in_box_size'];?><br />
											</td>
											<td class="bg4">
												<?php echo $message_statistics['out_box_size'];?><br />
											</td>
											<td class="bg4">
												<?php echo $message_statistics['save_box_size'];?><br />
											</td>
											<td class="bg4">
												<b><?php echo $message_statistics['total_size'];?></b><br />
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<?php
							$percentage_used = floor((100/$message_statistics['total_size_allowed']) * $message_statistics['total_size']);
							if ($percentage_used > 100) {
							    $percentage_used = 100;
							}
							?>
							<tr>
								<td colspan="3">
									<table border="0" cellspacing="2" cellpadding="0" width="100%">
										<tr>
											<?php if($percentage_used>0) {?>
											<td width="<?php echo $percentage_used;?>%" class="bg1">
												<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
											</td>
											<?php }?>
											<td class="bg2">
												<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td align="right" colspan="3">
									<?php echo $percentage_used;?>&#37; <?php echo $lang['txt_used'];?><br />
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			</div>
			<?php  } ?>
			</div>
			
			<div id="box_bottom">
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
					<tr>
						<td align="left">
							<img src="<?php echo $templatePath;?>img/box_bottom_left.png" width="5" height="18" alt="" border="0" /><br />
						</td>
						<td align="left">
							<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" border="0" /><br />
						</td>
						<td align="right">
							<img src="<?php echo $templatePath;?>img/box_bottom_right.png" width="5" height="18" alt="" border="0" /><br />
						</td>
					</tr>
				</table>
			</div>
		</td>
	</tr>
</table>
</form>

<script language="javascript">
<!--

function checkFormBoxes() { //task is check or uncheck

	var form = document.message.elements['message_id[]']
	
	var state = true;
	
	if (form[0].checked == true) {
		state = false;
	}
	

	for (var i=0; i < form.length; i++) {
		form[i].checked = state;

	}
}

//-->
</script>
