<?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">
			<?php echo $lang['hdr_identities'];?><br />
		</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 class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>

<div class="col_right1">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_identity_intro'];?><br />
		</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>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	
	
	<?php
	if (isset($_REQUEST['add_identity']) || isset($identity)) {
	?>
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_identity_creator'];?><br />
		</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>
				
				<table cellspacing="0" cellpadding="2" border="0" width="100%">
					<tr>
						<td valign="top">
							<select style="width:150px;" id="id_file_id" size=3 name="file_id" onChange='javascript:setimg(this)'>
								<option value="0" selected="selected"><?php echo $lang['txt_none'];?></option>
								<?php
								$img_divs = "";
								foreach($images as $key => $i):
								$display_state = "none";
								$selected = "";
								if (isset($identity['file_id']) && $identity['file_id'] == $i['file_id']) {
									$selected = "selected=\"selected\"";
									$display_state = "block";
								}
								?>
								<option value="<?php echo $i['file_id'];?>" <?php echo $selected;?>><?php echo $i['file_save_name'];?></option>
								<?php
								$img_divs .= "<div style=\"display:" . $display_state . ";\" id=img" . $i['file_id'] . "><img src=\"get_file.php?file=" . $i['file_md5_name_view'] . "&amp;type=" . $i['type'] . "&amp;directory=" . $i['directory'] . "\" border=\"0\" class=\"picture\" /></div>";
								endforeach;
								?>
							</select>
						</td>
						<td valign="top" align="right">
							<?php echo $img_divs;?>
						</td>	
					</tr>
				</table>
				
				<?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'];?>
					<textarea id="id_metadata" type="text" name="identity_metadata" cols="50"><?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 }?>
				
				<hr />
				
				<p align="right">
					<input type="submit" name="delete_identity" class="input_submit" value="<?php echo $lang['sub_delete_identity'];?>" />&nbsp;&nbsp;
					<input type="submit" name="update_identity" class="input_submit" value="<?php echo $lang['sub_update_identity'];?>" /><br />
				</p>
			</div>
		</div>
	</div>
			
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	<?php }?>
</div>
</form>