<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
//
// Copyright (C) 2003 - 2007 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., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

?>

<style type="text/css">
<!--
@import url(<?php echo $template_path;?>css/aroundme_form.css);
-->
</style>


<form action="index.php?amn=core_msg_list<?php if(isset($message_box)) echo "&amp;box=" . $message_box;?>" method="post" name="frm" id="id_frm">

<div class="box">
	<div class="box_top">
		<div class="content">
			<h1><?php echo $lang['hdr_messages'];?></h1>
		</div>
	</div>
		
	<div class="box_mid">
		<div class="content">
			<table border="0" cellspacing="0" cellpadding="2" width="100%">
				<tr>
					<td width="200">
						<?php
						if (isset($message_statistics)) {
						?>
						<table cellspacing="1" cellpadding="1" border="0" width="100%">
							<tr>
							<?php
							$message_count = 0;
							foreach ($message_statistics as $key => $i):
							$percentage_used = 0;
							
							if ($message_allocation > 0) {
								$percentage_used = round((100/$message_allocation) * $i['usage']);
							}
							if ($percentage_used > 100) {
								$percentage_used = 100;
							}
							
							$message_count = $message_count + $i['total'];
							if($percentage_used>0) {
							if ($key == $message_box) {
								$background_class = "bg1";
							}
							else {
								$background_class = "bg4";
							}
							?>
								<td width="<?php echo $percentage_used;?>%" class="<?php echo $background_class;?>">
									<img src="<?php echo $template_path;?>img/pixel.png" width="1" height="6" alt="" /><br />
								</td>
							<?php
							}
							endforeach;?>
							
								<td class="bg2">
									<img src="<?php echo $template_path;?>img/pixel.png" width="1" height="6" alt="" /><br />
								</td>
							</tr>
						</table>
						<?php }?>
						<br />
					</td>
					<?php
					if (isset($messages)) {
					?>
					<td align="right">
						<input type="submit" class="input_submit" name="mark_read" value="<?php echo $lang['sub_read'];?>" />&nbsp;
						<input type="submit" class="input_submit" name="mark_unread" value="<?php echo $lang['sub_unread'];?>" />&nbsp;
						<input type="submit" class="input_submit" name="delete" value="<?php echo $lang['sub_delete'];?>" />
						<br />
					</td>
					<td align="right">
						<?php echo $lang['txt_mark_all'];?>&nbsp;
						<input type="checkbox" onClick="checkFormBoxes(this);" /><br />
					</td>
					<?php }?>
				</tr>
			</table>
			
			<img src="<?php echo $template_path;?>img/pixel.png" width="1" height="9" alt="" /><br />
			
			
			<?php
			if (isset($messages)) {
			?>
			<table border="0" cellspacing="0" cellpadding="2" width="100%">
				<tr>
					<td>
						<br />
					</td>
					<td>
						<b><?php echo $lang['txt_from'];?></b><br />
					</td>
					<td>
						<b><?php echo $lang['txt_to'];?></b><br />
					</td>
					<td>
						<b><?php echo $lang['txt_date'];?></b><br />
					</td>
					<td>
						<b><?php echo $lang['txt_subject'];?></b><br />
					</td>
					<td>
						<b><?php echo $lang['txt_priority'];?></b><br />
					</td>
					<td>
						<b><?php echo $lang['txt_response'];?></b><br />
					</td>
					<td>
						<b><?php echo $lang['txt_size'];?></b><br />
					</td>
					<td>
						<br />
					</td>
				</tr>
				<tr>
						
				<?php
				$display_items = trimArray($messages);
				foreach($display_items as $key => $i):
				?>
				
				<tr>
					<td valign="top">
						<?php
						if ($i['message_status'] == $messaging_config['status']['read']) {
						?>
							<a href="index.php?amn=core_msg_view&amp;message_id=<?php echo $i['message_id'];?>"><img src="<?php echo $template_path;?>img/openned_mail.png" vspace="2" border="0" alt="<?php echo $lang['alt_message_read'];?>"></a>&nbsp;<br />
						<?php
						}
						else if ($i['message_status'] == $messaging_config['status']['unread']) {
						?>
							<a href="index.php?amn=core_msg_view&amp;message_id=<?php echo $i['message_id'];?>"><img src="<?php echo $template_path;?>img/unopenned_mail.png" vspace="2" border="0" alt="<?php echo $lang['alt_message_unread'];?>"></a>&nbsp;<br />
						<?php }?>
					</td>
					<td valign="top">
						<?php
						if (empty($i['from_identity_id'])) {
							echo $lang['txt_system']; // a system message was sent
						}
						else {
						?>
						<a href="index.php?amn=core_profile&amp;identity_id=<?php echo $i['from_identity_id'];?>"><?php echo $i['from_identity']['identity_nic'];?></a>
						<?php }?>
						<br />
					</td>
					<td valign="top">
						<a href="index.php?amn=core_profile&amp;identity_id=<?php echo $i['to_identity_id'];?>"><?php echo $i['to_identity']['identity_nic'];?></a><br />
					</td>
					<td valign="top">
						<?php echo $this->date->formatDate($i['message_create_datetime'], 1);?><br />
					</td>
					<td valign="top">
						<a href="index.php?amn=core_msg_view&amp;message_id=<?php echo $i['message_id'];?>"><?php echo $i['message_subject'];?></a><br />
					</td>
					<td valign="top">
						<?php echo $lang['messaging']['priority'][$i['message_priority']];?><br />
					</td>
					<td valign="top">
						<?php echo $lang['messaging']['response'][$i['message_response']];?><br />
					</td>
					<td valign="top">
						<?php echo strlen($i['message_body']);?><br />
					</td>	
					<td align="right" valign="top">
						<input type="checkbox" name="message_ids[]" value="<?php echo $i['message_id'];?>" /><br />
					</td>
				</tr>
				
				<?php
				endforeach;
				?>
			</table>
			
			<?php
			echo createArrayList($messages);
			?>
			
			<?php
			} else {
			?>
			
			<p>
				<?php echo $lang['template_error']['err_no_items'];?><br />
			</p>
			
			<?php }?>
		</div>
	</div>
</div>
</form>

<script language="javascript">
<!--
function checkFormBoxes(id) { //task is check or uncheck
	
	var form = document.frm.elements['message_ids[]'];
	var state = true;
	
	if (id.checked == false) {
		state = false;
	}
	
	if (form.length) {
		for (var i=0; i < form.length; i++) {
			form[i].checked = state;
		}
	}
	else {
		form.checked = state;
	}
}
//-->
</script>