<?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_core;?>css/aroundme_form.css);
-->
</style>

<script language="JavaScript" src="<?php echo $template_path_core;?>/js/imageHandling.js" type="text/javascript"></script>

<form action="index.php?amn=core_me_identity" method="post" name="frm" id="id_frm">
<input type="hidden" name="identity_id" value="<?php if (isset($identity['identity_id'])) { echo $identity['identity_id'];}?>" />

<div class="col_left1">
	<div class="box">
		<div class="box_top">
			<div class="content">
				<h1><?php echo $lang['hdr_identities'];?></h1>
			</div>
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php
				if (isset($identities)) {
				foreach ($identities as $idkey => $id):
				
				if (!empty($id['identity_type'])) {
					?>
					<b><?php echo $lang['identity']['type'][$id['identity_type']];?></b><br />	
					<?php
					}
					else {
					?>
					<b><?php echo $lang['txt_identity_spare'];?></b><br />
				<?php
				}	
					
				$id_card = $id;
				include("inc/identity.inc.php");?>
				
				<p align="right">
					<a href="index.php?amn=core_me_identity&amp;identity_id=<?php echo $id['identity_id'];?>"><?php echo $lang['href_identity_edit'];?></a>
				</p>
				
				<hr />
				
				<?php
				endforeach;
				}
				?>
			</div>
		</div>
	</div>
</div>

<div class="col_right1">
	<div class="box">
		<div class="box_top">
			<div class="content">
				<h1><?php echo $lang['hdr_identity_intro'];?></h1>
			</div>
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php echo $lang['txt_identity_intro'];?><br />
				
				<p align="right">
					<a href="index.php?amn=core_me_identity&amp;add_identity=1"><?php echo $lang['href_identity_add'];?></a><br />			
				</p>
			</div>
		</div>
	</div>
	
	<?php
	if (isset($_REQUEST['add_identity']) || isset($identity)) {
	?>
	<div class="box">
		<div class="box_top">
			<div class="content">
				<h1><?php echo $lang['hdr_identity_creator'];?></h1>
			</div>
		</div>
		
		<div class="box_mid">
			<div class="content">
				<p>
					<b><?php echo $lang['txt_card'];?></b></br />
				</p>
				
				<p>
					<label for="identity_name"><?php echo $lang['txt_identity_name'];?></label>
					<input id="identity_name" type="text" class="input1" name="identity_name" value="<?php if (isset($identity['identity_name'])) { echo $identity['identity_name'];}?>" /><br />
				</p>
				
				<p>
					<label for="identity_nic"><?php echo $lang['txt_nic'];?></label>
					<input id="identity_nic" type="text" class="input1" name="identity_nic" value="<?php if (isset($identity['identity_nic'])) { echo $identity['identity_nic'];}?>" /><br />
				</p>
				
				<?php
				if (isset($lang['identity']['custom'])) {
				foreach ($lang['identity']['custom'] as $key => $i):
				
				$value = "";
				if (!empty($identity['custom_fields'])) {
					foreach ($identity['custom_fields'] as $cfkey => $cf):
						if ($key == $cf['custom_item_id']) {
							$value = $cf['custom_item_body'];
							break;
						}
					endforeach;
				}
				?>
				<p>
					<label for="identity_custom_<?php echo $key;?>"><?php echo $i;?></label>
					<input id="identity_custom_<?php echo $key;?>" type="text" class="input1" name="custom[<?php echo $key;?>]" value="<?php echo $value;?>" /><br />
				</p>
				<?php
				endforeach;
				}
				?>
				
				<p>
					<label for="identity_gender"><?php echo $lang['txt_gender'];?></label>
					<input type="radio" id="identity_gender" name="identity_gender" class="checkbox" value="0" checked="checked">&nbsp;<?php echo $lang['txt_undisclosed'];?>&nbsp;
					<input type="radio" id="identity_gender" name="identity_gender" class="checkbox" value="1" <?php if (isset($identity['identity_gender']) && $identity['identity_gender'] == "1") { echo "checked=\"checked\"";}?>>&nbsp;<?php echo $lang['txt_male'];?>&nbsp;
					<input type="radio" id="identity_gender" name="identity_gender" class="checkbox" value="2" <?php if (isset($identity['identity_gender']) && $identity['identity_gender'] == "2") { echo "checked=\"checked\"";}?>>&nbsp;<?php echo $lang['txt_female'];?><br />
				</p>
				
				<p>
					<label for="identity_signature"><?php echo $lang['txt_signature'];?></label>
					<textarea id="identity_signature" name="identity_signature" cols="28" rows="4"><?php if (isset($identity['identity_signature'])) { echo $identity['identity_signature'];}?></textarea><br />
				</p>
				
				
				<?php
				if (isset($images)) {
				?>
				<p>
					<b><label for="frm_file"><?php echo $lang['txt_image'];?></label></b><br />
				</p>
				
				<p>
					<?php echo $lang['txt_image_help'];?><br />
				</p>

				<div style="overflow: auto; width:346px;">
					<table cellspacing="0" cellpadding="2" border="0">
						<tr>
							<td valign="top" align="center">
								<?php echo $lang['txt_none'];?><br />
								<input type="radio" name="file_id" value="0" checked="checked" /><br />
								<img src="<?php echo $template_path_core;?>img/pixel.png" width="60" height="1" alt="" border="0" /><br />
							</td>
							<?php
							foreach($images as $i):
							$selected = "";
							if (isset($identity['file_id']) && $identity['file_id'] == $i['file_id']) {
								$selected = "checked=\"checked\"";
							}
							?>
							<td valign="top" align="center">
								<img class="picture" src="get_file.php?file=<?php echo $i['file_md5_name_view']; ?>" alt="<?php echo $i['file_save_name']; ?>"/><br />
								<input type="radio" name="file_id" value="<?php echo $i['file_id'];?>" <?php echo $selected;?> /><br />
							</td>
							<?php
							endforeach;
							?>
						</tr>
					</table>
				</div>
				<?php }?>
				
				<p>
					<b><?php echo $lang['txt_preferences'];?></b><br />
				</p>
				
				<table cellspacing="4" cellpadding="0" border="0">
					<tr>
						<td valign="top">
							<input id="id_identity_allow_msg" type="checkbox" name="identity_allow_msg" value="1" <?php if (isset($identity['identity_allow_msg'])) { echo "checked=\"checked\"";}?> /><br />
						</td>
						<td valign="top">
							<?php echo $lang['txt_message'];?><br />
						</td>
					</tr>
					<tr>
						<td valign="top">
							<input id="id_identity_allow_export" type="checkbox" name="identity_allow_export" value="1" <?php if (isset($identity['identity_allow_export'])) { echo "checked=\"checked\"";}?> /><br />
						</td>
						<td valign="top">
							<?php echo $lang['txt_export'];?><br />
						</td>
					</tr>
					<tr>
						<td valign="top">
							<input id="id_identity_search" type="checkbox" name="identity_search" value="1" <?php if (isset($identity['identity_search'])) { echo "checked=\"checked\"";}?>  onChange="javascript:showMetaData(this);"/><br />
						</td>
						<td valign="top">
							<?php echo $lang['txt_search'];?><br />
						</td>
					</tr>
				</table>
				
				<script type="text/javascript">
				function showMetaData(id) {
					var displaystate = 'none';
					
					if (id.checked) {
						displaystate = 'block';
					}

					objShowHide('id_div_metadata', displaystate);
				}
				</script>
				
				<div id="id_div_metadata">
				<p>
					<label for="id_metadata"><b><?php echo $lang['txt_metadata'];?></b></label><br />
				</p>
				
				<p>
					<?php echo $lang['txt_metadata_intro'];?><br />
				</p>

				<p>
					<textarea id="id_metadata" type="text" name="identity_metadata" cols="50" style="width: 320px;"><?php if (isset($identity['identity_metadata'])) { echo $identity['identity_metadata'];}?></textarea><br />
				</p>
				</div>
				
				<script type="text/javascript">
					var id = document.getElementById('id_identity_search');
					showMetaData(id);
				</script>
				
				
				<?php
				if (empty($identity['identity_type'])) {
				?>
				<p>
					<b><label for="identity_identity_type"><?php echo $lang['txt_identity_type'];?></label></b><br />				
				</p>
				
				<p>
					<input type="radio" id="identity_identity_type" name="identity_type" class="checkbox" value="0" checked="checked">&nbsp;<?php echo $lang['txt_identity_spare'];?><br />
					<input type="radio" id="identity_identity_type" name="identity_type" class="checkbox" value="<?php echo $identity_config['registered'];?>">&nbsp;<?php echo $lang['txt_identity_type_member'];?><br />
					<input type="radio" id="identity_identity_type" name="identity_type" class="checkbox" value="<?php echo $identity_config['public'];?>">&nbsp;<?php echo $lang['txt_identity_type_public'];?><br />
				</p>
				<?php }?>
				
				<?php if ($identity['identity_type'] != $identity_config['registered']) { ?>
				<p>
					<b><label for="id_activate_identity"><?php echo $lang['txt_activate']; ?></label></b><br />
				</p>
				<?php
					$checked = "";
					if (isset($_REQUEST['add_identity']) && $_REQUEST['add_identity'] == 1) {
						$checked = "checked=\"checked\"";
					}
					elseif (isset($identity['identity_allow_usage']) && !empty($identity['identity_allow_usage'])) {
						$checked = "checked=\"checked\"";
					}
				?>
			
				<table>
					<tr>
						<td valign="top">
							<input id="id_activate_identity" type="checkbox" name="activate_identity" value="1" <?php echo $checked; ?>/><br />
						</td>
						<td valign="top">
							<?php echo $lang['txt_activate_identity'];?><br />
						</td>
					</tr>
				</table>
				<?php }
				else { ?>
					<input type="hidden" name="activate_identity" value="1" />
				<?php } ?>
				<hr />
				
				<p align="right">
					<input type="submit" name="update_identity" class="input_submit" value="<?php echo $lang['sub_update_identity'];?>" /><br />
				</p>
			</div>
		</div>
	</div>
	<?php }?>
</div>
</form>