<?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_user_ledger" method="post" name="frm" id="id_frm">
<input type="hidden" name="user_id" value="<?php if (!empty($_REQUEST['user_id'])) { echo $_REQUEST['user_id'];}?>" />
<input type="hidden" name="ledger_id" value="<?php if (isset($ledger_item['ledger_id'])) { echo $ledger_item['ledger_id'];}?>" />


<?php

if(isset($ledger_item) || (!empty($_REQUEST['add_ledger_item']) && $_REQUEST['user_id'])) {
?>
<div class="box">
	<div class="box_top">
		<div class="content">
			<h1><?php echo $lang['hdr_edit_ledger'];?></h1>
		</div>
	</div>

	<div class="box_mid">
		<div class="content">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td valign="top" width="50%">
						<p>
							<label for="id_ledger_net"><?php echo $lang['txt_net'];?></label>
							<input type="text" id="id_ledger_net" name="ledger_net" class="input1" size="8" value="<?php if(isset($ledger_item['ledger_net'])) { echo $ledger_item['ledger_net'];}?>" /> (<?php echo $lang['curr_symbol'];?>)</br />
						</p>
							
						<p>
							<label for="id_ledger_payment_date"><?php echo $lang['txt_payment_date'];?></label>
							<input type="text" id="id_ledger_payment_date" name="ledger_payment_date" class="input1" size="12" value="<?php if(isset($ledger_item['ledger_payment_date'])) {echo $ledger_item['ledger_payment_date'];}?>" /></br />
						</p>
						
						<p>
							<label for="id_ledger_expiry_date"><?php echo $lang['txt_expiry_date'];?></label>
							<input type="text" id="id_ledger_expiry_date" name="ledger_expiry_date" class="input1" size="12" value="<?php if(isset($ledger_item['ledger_expiry_date'])) {echo $ledger_item['ledger_expiry_date'];}?>" /></br />
						</p>
			
						<?php
						if (!empty($lang['user_ledger_type'])) {
						?>
						<p>
							<label for="id_ledger_type"><?php echo $lang['txt_type'];?></label>
							<select name="ledger_type">
							<?php
							foreach ($lang['user_ledger_type'] as $key => $i):

							$checked = "";

							if (isset($ledger_item['ledger_type']) && $ledger_item['ledger_type'] == $key) {
								$checked = " selected=\"selected\"";
							}
							?>
							<option value="<?php echo $key;?>"<?php echo $checked;?>><?php echo $i;?></option>
							<?php
							endforeach;
							?>
						</p>
						<?php }?>
					</td>
					<td width="20">
						<img src="<?php echo $template_path_core;?>img/pixel.png" width="20" height="1" alt="" /><br />
					</td>
					<td valign="top" width="50%">
						<p>
							<label for="id_ledger_note"><?php echo $lang['ledger_note'];?></label>
							<textarea id="id_ledger_note" name="ledger_note" rows="4" cols="30" class="input1"><?php if(isset($ledger_item['ledger_note'])) {echo $ledger_item['ledger_note'];}?></textarea>
						</p>
					</td>
				</tr>
			</table>

			<hr />

			<p align="right">
				<input name="update_ledger" type="submit" class="input_submit" value="<?php echo $lang['sub_ledger'];?>" /><br />
			</p>
		</div>
	</div>
</div>
<?php }?>


<div class="box">
	<div class="box_top">
		<div class="content">
			<h1><?php echo $lang['hdr_ledger'];?></h1>
		</div>
	</div>

	<div class="box_mid">
		<div class="content">
			<?php
			if (isset($ledger)) {
			?>
			<table border="0" cellspacing="2" cellpadding="2" width="100%">
				<tr>
					<td valign="top">
						<b><?php echo $lang['txt_ledger_id'];?></b><br />
					</td>
					<td valign="top">
						<b><?php echo $lang['txt_ledger_item'];?></b><br />
					</td>
					<td valign="top">
						<b><?php echo $lang['txt_payment_date'];?></b><br />
					</td>
					<td valign="top" align="center">
						<b><?php echo $lang['txt_expiry_date'];?></b><br />
					</td>
					<td valign="top" align="right">
						(<?php echo $lang['curr_symbol'];?>) <b><?php echo $lang['txt_net'];?></b><br />
					</td>
				</tr>
				<?php
				$ledger_total = "0";

				foreach($ledger as $key => $i):
				$ledger_total = $ledger_total+$i['ledger_net'];
				?>
				<tr>
					<td valign="top">
						<a href="index.php?amn=core_user_ledger<?php if (!empty($_REQUEST['user_id'])) { echo "&amp;user_id=" . $_REQUEST['user_id'];}?>&amp;ledger_id=<?php echo $i['ledger_id'];?>"><?php echo $i['ledger_id'];?></a><br />
					</td>
					<td valign="top">
						<?php echo $lang['user_ledger_type'][$i['ledger_type']];?><br />
					</td>
					<td valign="top">
						<?php echo $this->date->formatDate($i['ledger_payment_date']);?><br />
					</td>
					<td valign="top" align="center">
						<?php
						if (!empty($i['ledger_expiry_date'])) {
							echo $this->date->formatDate($i['ledger_expiry_date']);
						}
						else {
							echo "-";
						}
						?><br />
					</td>
					<td valign="top" align="right">
						<?php echo $i['ledger_net'];?><br />
					</td>
				</tr>
				<?php
				if (!empty($i['ledger_note'])) {
				?>
				<tr>
					<td>
						<br />
					</td>
					<td colspan="4">
						<i><?php echo $i['ledger_note'];?></i><br />
					</td>
				</tr>
				<?php
				}
				endforeach;
				?>
				<tr>
					<td colspan="4">
						<br />
					</td>
					<td valign="top" align="right">
						<b><?php echo $ledger_total;?></b><br />
					</td>
				</tr>
			</table>
			<?php
			} else {
			?>

			<p>
				<?php echo $lang['template_error']['err_no_items'];?><br />
			</p>

			<?php }?>
		</div>
	</div>
</div>
</form>