<?php

// -----------------------------------------------------------------------
// This file is part of Igloo
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

?>

<script language="JavaScript" src="js/imageHandling.js" type="text/javascript"></script>

<form action="my_profile.php" method="post" name="frm" id="id_frm">

<?php
if (isset($display) && $display == "edit_profile") {
?>
<input type="hidden" name="profile_id" value="<?php if (isset($profile['profile_id'])) { echo $profile['profile_id'];}?>" />
<input type="hidden" name="profile_default" value="<?php if (isset($profile['profile_default'])) { echo $profile['profile_default'];}?>" />
<input type="hidden" name="profile_true_self" value="<?php if (isset($profile['profile_true_self'])) { echo $profile['profile_true_self'];}?>" />
<input type="hidden" name="profile_name" value="<?php if (isset($profile['profile_name'])) { echo $profile['profile_name'];}?>" />

<div class="box">
	<div class="box_top">
		<?php
		echo $lang['hdr_profile'];
		
		if ($profile['profile_true_self'] == 1) {
			echo ": " . $lang['txt_true_self'];
		}
		else {
			echo ": " . $lang['txt_alias'];
		}
		?><br />
	</div>
	
	<div class="box_mid">
		<div class="content">
			<table border="0" cellspacing="0" cellpadding="2" width="100%">
				<tr>
					<td>
						<?php
						if ($profile['profile_true_self'] == 1) {
							echo $lang['txt_intro_true_self'];
						}
						else {
							echo $lang['txt_intro_alias'];
						}
						?><br />
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="12" alt="" /><br />

					</td>
					<td valign="top" colspan="2" align="right">
						<br />
					</td>
				</tr>
				<tr>
					<td valign="top">
						<fieldset>
						<legend><?php echo $lang['txt_header_1'];?>:
						</legend>
						<p>
						<?php echo $lang['txt_overview_intro'];?><br />
						</p>

						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />

						<table border="0" cellspacing="0" cellpadding="0" width="100%">
							<tr>
								<td valign="top" width="310">
									<?php
									if ($profile['profile_true_self'] == 1) {
									?>
									<p>
									<label for="id_user_firstname"><?php echo $lang['txt_user_firstname'];?></label>
									<input id="id_user_firstname" type="text" maxlength="50" name="user_firstname" size="35" value="<?php if (isset($user['user_firstname'])) { echo $user['user_firstname'];}?>" /><br />
									</p>
									
									<p>
									<label for="id_user_surname"><?php echo $lang['txt_user_surname'];?></label>
									<input id="id_user_surname" type="text" maxlength="50" name="user_surname" size="35" value="<?php if (isset($user['user_surname'])) { echo $user['user_surname'];}?>" /><br />
									</p>
									
									<p>
									<label for="id_user_hometown"><?php echo $lang['txt_profile_hometown'];?></label>
									<input id="id_user_hometown" type="text" name="user_hometown" size="35" value="<?php if (isset($user['user_hometown'])) { echo $user['user_hometown'];}?>" /><br />
									</p>
									<?php
									}
									else{
									?>
									<p>
									<label for="id_profile_nic"><?php echo $lang['txt_profile_nic'];?></label>
									<input id="id_profile_nic" type="text" maxlength="50" name="profile_nic" size="35" value="<?php if (isset($profile['profile_nic'])) { echo $profile['profile_nic'];}?>" /><br />
									</p>
									
									<p>
									<label for="id_profile_hometown"><?php echo $lang['txt_profile_hometown'];?></label>
									<input id="id_profile_hometown" type="text" name="profile_hometown" size="35" value="<?php if (isset($profile['profile_hometown'])) { echo $profile['profile_hometown'];}?>" /><br />
									</p>
									
									<?php }?>
									
									

									<?php
									if (!empty($lang['txt_profile_text1'])) {
									?>
									<p>
									<label for="id_profile_text1"><?php echo $lang['txt_profile_text1'];?></label>
									<input id="id_profile_text1" type="text" name="profile_text1" size="35" value="<?php if (isset($profile['profile_text1'])) { echo $profile['profile_text1'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text2'])) {
									?>
									<p>
									<label for="id_profile_text2"><?php echo $lang['txt_profile_text2'];?></label>
									<input id="id_profile_text2" type="text" name="profile_text2" size="35" value="<?php if (isset($profile['profile_text2'])) { echo $profile['profile_text2'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text3'])) {
									?>
									<p>
									<label for="id_profile_text3"><?php echo $lang['txt_profile_text3'];?></label>
									<input id="id_profile_text3" type="text" name="profile_text3" size="35" value="<?php if (isset($profile['profile_text3'])) { echo $profile['profile_text3'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text4'])) {
									?>
									<p>
									<label for="id_profile_text4"><?php echo $lang['txt_profile_text4'];?></label>
									<input id="id_profile_text4" type="text" name="profile_text4" size="35" value="<?php if (isset($profile['profile_text4'])) { echo $profile['profile_text4'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text5'])) {
									?>
									<p>
									<label for="id_profile_text5"><?php echo $lang['txt_profile_text5'];?></label>
									<input id="id_profile_text5" type="text" name="profile_text5" size="35" value="<?php if (isset($profile['profile_text5'])) { echo $profile['profile_text5'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text6'])) {
									?>
									<p>
									<label for="id_profile_text6"><?php echo $lang['txt_profile_text6'];?></label>
									<input id="id_profile_text6" type="text" name="profile_text6" size="35" value="<?php if (isset($profile['profile_text6'])) { echo $profile['profile_text6'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text7'])) {
									?>
									<p>
									<label for="id_profile_text7"><?php echo $lang['txt_profile_text7'];?></label>
									<input id="id_profile_text7" type="text" name="profile_text7" size="35" value="<?php if (isset($profile['profile_text7'])) { echo $profile['profile_text7'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text8'])) {
									?>
									<p>
									<label for="id_profile_text8"><?php echo $lang['txt_profile_text8'];?></label>
									<input id="id_profile_text8" type="text" name="profile_text8" size="35" value="<?php if (isset($profile['profile_text8'])) { echo $profile['profile_text8'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text9'])) {
									?>
									<p>
									<label for="id_profile_text9"><?php echo $lang['txt_profile_text9'];?></label>
									<input id="id_profile_text9" type="text" name="profile_text9" size="35" value="<?php if (isset($profile['profile_text9'])) { echo $profile['profile_text9'];}?>" /><br />
									</p>
									<?php }?>

									<?php
									if (!empty($lang['txt_profile_text10'])) {
									?>
									<p>
									<label for="id_profile_text10"><?php echo $lang['txt_profile_text10'];?></label>
									<input id="id_profile_text10" type="text" name="profile_text10" size="35" value="<?php if (isset($profile['profile_text10'])) { echo $profile['profile_text10'];}?>" /><br />
									</p>
									<?php }?>
								</td>
								<td>
									<img src="<?php echo $templatePath;?>img/pixel.png" width="10" height="1" alt="" /><br />
								</td>
								<td valign="top">
									<p>
									<label for="id_gender"><?php echo $lang['txt_gender'];?></label><br />

									<input type="radio" id="id_gender" name="profile_gender" class="checkbox" value="0" checked="checked">&nbsp;<?php echo $lang['txt_none'];?><br />
									<input type="radio" id="id_gender" name="profile_gender" class="checkbox" value="1" <?php if (isset($profile['profile_gender']) && $profile['profile_gender'] == "1") { echo "checked=\"checked\"";}?>>&nbsp;<?php echo $lang['txt_male'];?><br />
									<input type="radio" id="id_gender" name="profile_gender" class="checkbox" value="2" <?php if (isset($profile['profile_gender']) && $profile['profile_gender'] == "2") { echo "checked=\"checked\"";}?>>&nbsp;<?php echo $lang['txt_female'];?><br />
									</p>

									<table border="0" cellspacing="0" cellpadding="4" width="100%">
										<tr>
											<td valign="top">
												<input type="checkbox" id="id_profile_allow_msg" class="checkbox" name="profile_allow_msg" value="1" <?php if (isset($profile['profile_allow_msg']) && $profile['profile_allow_msg'] == 1) echo "checked=\"checked\"";?> />
											</td>
											<td valign="top">
												<label style="width:100%" for="id_profile_allow_msg"><?php echo $lang['txt_profile_allow_msg'];?></label><br />
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
						</fieldset>


						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />

						<fieldset>
						<legend><?php echo $lang['txt_header_2'];?></legend>
						<p>
						<?php echo $lang['txt_detail_intro'];?><br />
						</p>

						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />

						<table border="0" cellspacing="0" cellpadding="2" width="10%">
							<tr>
								<td valign="top">
									<label for="id_profile_summary"><?php echo $lang['form_body'];?></label>
									<div id="gui_wiki" align="right" valign="bottom">
										<script language="JavaScript" type="text/javascript" src="js/gui_wiki.js"></script>
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<textarea id="id_profile_summary" name="profile_summary" cols="78" rows="10" onchange="textChanged = true;" tabindex="1"><?php if (isset($profile['profile_summary'])) { echo $profile['profile_summary'];}?></textarea><br />
									<script language="JavaScript" type="text/javascript">
										var txtarea = document.frm.profile_summary;
									</script>
								</td>
							</tr>
							<?php
							if (isset($allow_spellcheck)) {
							?>
							<tr>
								<td align="right">
									<input type="submit" name="preview" value="<?php echo $lang['form_submit_preview'];?>" class="button_light" />&nbsp;&nbsp;
									<input type="button" value="<?php echo $lang['sub_check_spelling'];?>" onClick="openSpellChecker();" class="button_light" /><br />
								</td>
							</tr>
							<?php }?>

							<?php
							if (!empty($profile['profile_summary_preview'])) {
							?>

							<tr>
								<td>
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['form_label_preview'];?><br />
								</td>
							</tr>
							<tr>
								<td class="picture_light">
									<?php echo $profile['profile_summary_preview'];?><br />
								</td>
							</tr>
							<?php }?>
						</table>
						</fieldset>

					</td>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="10" height="1" alt="" /><br />
					</td>
					<td valign="top" width="200">
						<fieldset>
						<legend><?php echo $lang['txt_header_3'];?></legend>
						<p>
						<?php echo $lang['txt_image_intro'];?><br />
						</p>

						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />

						<?php
						if (isset($images)) {
						?>
						<p>
						<?php echo $lang['form_label_file'];?></label><br />
						</p>

						<div>
						<p>
						<select id="id_file_id" size=4 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($profile['file_id']) && $profile['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_name'];?></option>
						<?php
						$img_divs .= "<div style=\"display:" . $display_state . ";\" id=img" . $i['file_id'] . "><img src=\"get_file.php?file=" . $i['file'] . "\" border=\"0\" class=\"picture\" /><br />" . $i['file_title'] . "</div>";
						endforeach;
						?>
						</select>
						</p>
						</div>
						<?php echo $img_divs;?>
						<?php }?>
						</fieldset>

						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />

						<fieldset>
						<legend><?php echo $lang['txt_header_5'];?></legend>
						<p>
						<?php echo $lang['txt_save_intro'];?><br />
						</p>

						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						<p>
							<input type="submit" name="save" class="button_urgent" value="<?php echo $lang['form_submit_save'];?>" />&nbsp;
							<input type="submit" name="save_go" class="button_urgent" value="<?php echo $lang['form_submit_save_go'];?>" /><br />
						</p>
						</fieldset>
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
	
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
<?php
}
else if (isset($display) && $display == "view_profile") {
?>
<div class="col_main">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_summary'];
			if ($profile['profile_true_self'] == 1) {
				echo ": " . $lang['txt_true_self'];
			}
			else {
				echo ": " . $lang['txt_alias'];
			}
			?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<table width="100%" cellpadding="4" cellspacing="0" border="0">
					<tr>
						<td valign="top">
							<?php echo $profile['profile_summary_display'];?><br />
						</td>
					</tr>
				</table>
	
				<hr />
				<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" /><br />
	
				<table width="100%" cellpadding="4" cellspacing="0" border="0">
					<tr>
						<td>
							<b><?php echo $lang['hdr_contact'];?></b><br />
						</td>
					</tr>
					<?php
					if (!empty($lang['txt_profile_text1'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text1'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text1'];?><br />
						</td>
					</tr>
					<?php }?>
	
					<?php
					if (!empty($lang['txt_profile_text2'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text2'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text2'];?><br />
						</td>
					</tr>
					<?php }?>
	
					<?php
					if (!empty($lang['txt_profile_text3'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text3'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text3'];?><br />
						</td>
					</tr>
					<?php }?>
	
					<?php
					if (!empty($lang['txt_profile_text4'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text4'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text4'];?><br />
						</td>
					</tr>
					<?php }?>
	
					<?php
					if (!empty($lang['txt_profile_text5'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text5'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text5'];?><br />
						</td>
					</tr>
					<?php }?>
	
					<?php
					if (!empty($lang['txt_profile_text6'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text6'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text6'];?><br />
						</td>
					</tr>
					<?php }?>
	
					<?php
					if (!empty($lang['txt_profile_text7'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text7'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text7'];?><br />
						</td>
					</tr>
					<?php }?>
	
					<?php
					if (!empty($lang['txt_profile_text8'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text8'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text8'];?><br />
						</td>
					</tr>
					<?php }?>
					
					<?php
					if (!empty($lang['txt_profile_text9'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text9'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text9'];?><br />
						</td>
					</tr>
					<?php }?>
					
					<?php
					if (!empty($lang['txt_profile_text10'])) {
					?>
					<tr>
						<td>
							<?php echo $lang['txt_profile_text10'];?><br />
						</td>
						<td>
							<?php echo $profile['profile_text10'];?><br />
						</td>
					</tr>
					<?php }?>
					
					
					<?php 
					if (isset($profile['profile_id'])) {
					?>
					<tr>
						<td colspan="2">
							<div class="box_edit">
								<table width="100%" cellpadding="2" cellspacing="0" border="0">
									<tr>
										<td nowrap="nowrap" valign="top" align="right">
											<?php
											if (isset($profile) && $profile['user_id'] == $me['user_id']) {
											?>
											<a href="my_profile.php?edit_profile=1&amp;profile_id=<?php echo $profile['profile_id'];?>" class="link_stnd"><?php echo $lang['href_edit_profile'];?></a>
											&nbsp;&nbsp;
											<?php }?>
											<a href="my_profile.php" class="link_stnd"><?php echo $lang['href_list_profiles'];?></a><br />
										</td>
									</tr>
								</table>
							</div>
						</td>
					</tr>
					<?php }?>
				</table>
	
				<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
	
				<table width="100%" cellpadding="4" cellspacing="0" border="0">
					<tr>
						<td colspan="2">
							<b><?php echo $lang['hdr_privacy'];?></b><br />
						</td>
					</tr>
					<tr>
						<td>
							<?php
							if (isset($profile['profile_allow_msg']) && $profile['profile_allow_msg'] == 1) {
								echo $lang['txt_msg_allow'];
							}
							else {
								echo $lang['txt_msg_deny'];
							}
							?>
							<br />
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>

<div class="col_side">
	<div class="box">
		<div class="box_top">
			<?php
			if ($profile['profile_true_self'] == 1) {
				echo $user['user_firstname'] . " " . $user['user_surname'];
			}
			else {
				echo $profile['profile_nic'];
			}
			?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<table border="0" cellspacing="0" cellpadding="2" width="100%">
					<tr>
						<td colspan="2" align="center">
							<img src="get_file.php?file=<?php echo $profile['image']['file'];?>" border="0" alt="<?php echo $profile['image']['file_title'];?>" class="picture_light" /><br />
						</td>
					</tr>
					<tr>
						<td>
							<?php echo $lang['txt_profile_hometown'];?><br />
						</td>
						<td>
							<?php
							if ($profile['profile_true_self'] == 1) {
								echo $user['user_hometown'];
							}
							else {
								echo $profile['profile_hometown'];
							}
							?><br />
						</td>
					</tr>
					<tr>
						<td valign="top">
							<?php echo $lang['txt_profile_create_datetime'];?><br />
						</td>
						<td>
							<?php echo $this->date->formatDate($profile['profile_create_datetime'], 1);?><br />
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>
<?php
}
else {
?>
<div class="col_left1">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_intro'];?><br />
		</div>

		<div class="box_mid">
			<div class="content">
				<?php echo $lang['txt_personas_intro'];?><br />
			</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_profiles'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<table border="0" cellspacing="0" cellpadding="4" width="100%">
					<?php
					if (isset($profiles)) {
					foreach($profiles as $key => $i):
					?>
					<tr>
						<td valign="top">
							<a href="my_profile.php?profile_id=<?php echo $i['profile_id'];?>"><?php echo $i['profile_name'];?></a><br />
						</td>
						<td valign="top">
							<?php
							if ($i['profile_true_self'] == 1) {
								echo $me['user_firstname'] . " " . $me['user_surname'];
							}
							else{
								echo $i['profile_nic'];
							}
							?><br />
						</td>
					</tr>
					<?php
					endforeach;
					}
					else {
					?>
					<tr>
						<td colspan="2">
							<?php echo $lang['err_no_profile_usage'];?><br />
						</td>
					</tr>
					<?php }?>
				</table>
			</div>
		</div>
	</div>
	
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	<?php }?>
</div>
</form>
