<?php

// -----------------------------------------------------------------------
// This file is part of aroundme
// 
// 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., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
// -----------------------------------------------------------------------

?>

<script type="text/javascript" src="js/calendar.js"></script>
<script type="text/javascript" src="<?php echo $languagePath;?>calendar/calendar-en.js"></script>
<script type="text/javascript" src="js/calendar-setup.js"></script>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="180" valign="top">
			<?php
			if (isset($group)) {
			include $templatePath . "g_menu.inc.tpl.php";
			}
			else {
			?>
		
				<div id="box_side2">
					<?php echo $lang['section_schedule_item'];?><br />
				</div>
										
				<div id="box_side1">
					<table border="0" cellspacing="0" cellpadding="2" width="100%">
						<tr>
							<td colspan="2">
								<b><?php echo $lang['hdr_author'];?></b><br />
							</td>
						</tr>
						<?php
						if (isset($author['group_id'])) {
						?>
						<tr>
							<td>
								<?php echo $lang['txt_group_title'];?><br />
							</td>
							<td>
								<a href="g_group.php?group_id=<?php echo $author['group_id'];?>"><?php echo $author['group_title'];?></a><br />
							</td>
						</tr>
						<tr>
							<td>
								<?php echo $lang['txt_group_language'];?><br />
							</td>
							<td>
								<?php
								if (isset($lang['arr_lang_name'][$author['language_id']])) {
									echo $lang['arr_lang_name'][$author['language_id']];
								}
								?><br />
							</td>
						</tr>
						<tr>
							<td>
								<?php echo $lang['txt_group_type'];?><br />
							</td>
							<td>
								<?php 
								if (isset($group['group_registration_type'])) {
									echo $lang['arr_registration_type'][$author['group_registration_type']];
								}
								else {
									echo $lang['txt_hidden'];
								}
								
								?><br />
							</td>
						</tr>
						<tr>
							<td>
								<?php echo $lang['txt_rec_age'];?><br />
							</td>
							<td>
								<?
								if ($author['group_from_age'] && $author['group_to_age']) {
									echo $author['group_from_age'] . "/" . $author['group_to_age'];
								}
								else if ($author['group_from_age'] && !$author['group_to_age']) {
									echo $author['group_from_age'] . " and up";
								}
								else if (!$author['group_from_age'] && $author['group_to_age']) {
									echo "up to " . $author['group_to_age'];
								}
								else {
									echo "all";
								}
								?>
								<br />
							</td>
						</tr>
						<?php
						}
						else {
						?>
						<tr>
							<td>
								<?php echo $lang['txt_profile_nic'];?><br />
							</td>
							<td>
								<a href="sn_profile.php?user_id=<?php echo $author['user_id'];?>"><?php echo $author['profile_nic'];?></a><br />
							</td>
						</tr>
						<tr>
							<td>
								<?php echo $lang['txt_profile_session_status'];?><br />
							</td>
							<td>
								<?php
								if ($author['online_status'] == 1) {
								    echo "<b>" . $lang['arr_user_online_status'][1] . "</b><br />";
								}
								else {
									    echo $lang['arr_user_online_status'][$author['online_status']] . "<br />";
								}
								?>
							</td>
						</tr>
						<tr>
							<td>
								<?php echo $lang['txt_profile_hometown'];?><br />
							</td>
							<td>
								<?php echo $author['profile_hometown'];?><br />
							</td>
						</tr>
						<tr>
							<td valign="top">
								<?php echo $lang['txt_profile_create_datetime'];?><br />
							</td>
							<td>
								<?php echo $author['display_profile_create_datetime'];?><br />
							</td>
						</tr>
						<?php }?>
					</table>
				</div>
				
				<div id="box_bottom">
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
							<td align="left">
								<img src="<?php echo $templatePath;?>img/box_bottom_left.png" width="5" height="18" alt="" border="0" /><br />
							</td>
							<td align="left">
								<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" border="0" /><br />
							</td>
							<td align="right">
								<img src="<?php echo $templatePath;?>img/box_bottom_right.png" width="5" height="18" alt="" border="0" /><br />
							</td>
						</tr>
					</table>
				</div>
			<?php }?>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
			
			<?php
			if (isset($schedule)) {
			if (isset($group)) {
				$hidden_form = array(
					"schedule_id" => $schedule['schedule_id'], 
					"item_id" => $schedule['schedule_id'], 
					"group_id" => $group['group_id']
				);
			}
			else {
				$hidden_form = array(
					"schedule_id" => $schedule['schedule_id'], 
					"item_id" => $schedule['schedule_id']
				);
			}
			
			$show_network = 1;
			
			include $templatePath . "tag.inc.tpl.php";
			}
			?>
		</td>

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

		<td width="560" valign="top">
			<div class="box_top">
				<?php 
				if (isset($schedule['schedule_type_id']) && $schedule['schedule_type_id'] == 2) { //task
				    echo $lang['hdr_schedule_task'];
				}
				else {
					echo $lang['hdr_schedule_event'];
				}
				?>
				<br />
			</div>
			
			<div class="box_mid" style="padding: 9px;">
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td valign="top">
						<table border="0" cellspacing="0" cellpadding="2">
							<tr>
								<td colspan="2">
									<span class="txt_item_title">
									<b><?php echo $schedule['schedule_title'];?></b><br />
									</span>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<?php echo $schedule['schedule_synopsis'];?><br />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['txt_start'];?><br />
								</td>
								<td>
									<?php 
									if (!empty($schedule['display_schedule_start_datetime'])) {
									    echo $schedule['display_schedule_start_datetime'];
										
										if (!empty($schedule['schedule_all_day_item'])) {
										    echo " (" .$lang['txt_all_day_item'] . ")";
										}
									}
									else {
										echo $lang['txt_no_start'];
									}
									?><br />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['txt_end'];?><br />
								</td>
								<td>
									<?php 
									if (!empty($schedule['display_schedule_end_datetime'])) {
									    echo $schedule['display_schedule_end_datetime'];
										
										if (!empty($schedule['schedule_all_day_item'])) {
										    echo " (" .$lang['txt_all_day_item'] . ")";
										}
									}
									else {
										echo $lang['txt_no_end'];
									}
									?><br />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['txt_location'];?><br />
								</td>
								<td>
									<?php echo $schedule['schedule_location'];?><br />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['txt_status'];?><br />
								</td>
								<td>
									<?php 
									if (isset($schedule['status_id'])) {
									    echo $lang['schedule']['arr_event_status'][$schedule['status_id']];
									}?><br />
								</td>
							</tr>
							<?php 
							if (!empty($schedule['schedule_priority'])) {
							?>
							<tr>
								<td>
									<?php echo $lang['txt_priority'];?><br />
								</td>
								<td>
									<?php echo $lang['schedule']['arr_priority'][$schedule['schedule_priority']];?><br />
								</td>
							</tr>
							<?php }?>
							<tr>
								<td>
									<?php echo $lang['txt_p_complete'];?><br />
								</td>
								<td>
									<?php 
									if (!empty($schedule['schedule_complete'])) { //task
									    echo $lang['txt_complete'];
									}
									else {
										echo $schedule['schedule_p_complete'] . "&nbsp;&#37;";
									}
									?>
									<br />
								</td>
							</tr>
						</table>
					</td>
					<td align="right" width="1%" valign="top">
						<img align="left" src="get_file.php?file=<?php echo $schedule['image']['file'];?>" border="0" class="picture" title="<?php echo $schedule['image']['file_title'];?>" alt="" /><br />
					</td>
				</tr>
			</table>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" border="0" /><br />
			<hr />
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" border="0" /><br />
			
			<b><?php echo $lang['hdr_detail'];?></b><br />
			<?php echo $schedule['schedule_body'];?><br />
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" border="0" /><br />
			<hr />
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" border="0" /><br />
			
			<table border="0" cellspacing="0" cellpadding="2" width="100%">
				<tr>
					<td colspan="3">
						<b><?php echo $lang['hdr_attendance'];?></b><br />
					</td>
				</tr>
				<tr>
					<td rowspan=2" width="40%" valign="top">
						<table border="0" cellspacing="0" cellpadding="2">
							<tr>
								<td>
									<?php echo $lang['txt_allocation'];?><br />
								</td>
								<td>
									<?php echo $schedule['schedule_allocation'];?><br />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['txt_applications'];?><br />
								</td>
								<td>
									<?php echo $schedule['schedule_applicants'];?><br />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['txt_confirmed'];?><br />
								</td>
								<td>
									<?php echo $schedule['schedule_confirmed'];?><br />
								</td>
							</tr>
						</table>
					</td>
					<td width="20">
						<img src="<?php echo $templatePath;?>img/pixel.png" width="20" height="1" alt="" border="0" /><br />
					</td>
					<td valign="top">
						<?php
						if (isset($group)) {
						    $url = "sch_item.php?group_id=" . $group['group_id'] . "&amp;schedule_id=" . $schedule['schedule_id'];
						}
						else {
							$url = "sch_item.php?schedule_id=" . $schedule['schedule_id'];
						}
						?>
						
						
						<?php
						if ($schedule['schedule_allocation'] > $schedule['schedule_confirmed']) { //spaces available
							echo $lang['txt_event_allocation_intro'];
							echo "<br /><br />";
						
							if (isset($schedule['allocation']['status_id'])) {
								if ($schedule['allocation']['status_id'] == $schedule_config['allocation_status']['rejected']) {
								    echo "<p>" . $lang['txt_application_rejected'];
								}
								else {
									echo "<p align=\"right\"><b>" . $lang['txt_application'] . " " . $lang['schedule']['allocation_status'][$schedule['allocation']['status_id']] . "</b></p><p align=\"right\">";
								}
								
								
								
								//if task is confirmed allow use to remove it
								if ($schedule['allocation']['status_id'] == $allocation_status['confirmed']) {
									$button = "<a href=\"" . $url . "&amp;withdraw_confirmation=1\" class=\"link_urgent\">" . $lang['href_event_withdraw_confirmation'] . "</a>";
								}
								elseif ($schedule['allocation']['status_id'] == $allocation_status['withdrawn'] || $schedule['allocation']['status_id'] < 1) {
									$button = "<a href=\"" . $url . "&amp;schedule_apply_update=1\" class=\"link_urgent\">" . $lang['href_event_apply'] . "</a>";
								}
							}
							else {
								$button = "<a href=\"" . $url . "&amp;schedule_apply=1\" class=\"link_urgent\">" . $lang['href_event_apply'] . "</a>";
							}
						}
						?><br />
						</p>
					</td>
				</tr>
			</table>
			
			
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<td>
						<div class="box_edit">
						<span style="float: right">
						<?php
						if (isset($group)) {
						if ($this->group_acs->checkPermission($resource_ids['group_schedule'], $privilege_ids['allow_edit']) && isset($schedule['schedule_id'])) {
						?>
						<a href="sch_edit.php?group_id=<?php echo $group['group_id'];?>&amp;schedule_id=<?php echo $schedule['schedule_id'];?>" class="link_stnd"><?php echo $lang['href_edit_this'];?></a>
						&nbsp;
						<a href="sch_allocation.php?group_id=<?php echo $group['group_id'];?>&amp;schedule_id=<?php echo $schedule['schedule_id'];?>" class="link_stnd"><?php echo $lang['href_edit_attendance'];?></a>
						<?php 
						}}
						elseif ($schedule['user_id'] == $me['user_id']) {
						if (!empty($schedule['group_id'])) {
						?>
							<a href="sch_item.php?group_id=<?php echo $schedule['group_id'];?>&amp;schedule_id=<?php echo $schedule['schedule_id'];?>" class="link_stnd"><?php echo $lang['href_goto_group'];?></a>
						<?php 
							}
							else {
							?>
							<a href="sch_item.php?schedule_id=<?php echo $schedule['schedule_id'];?>" class="link_stnd"><?php echo $lang['href_edit_this'];?></a>
						<?php }?>
						&nbsp;
						<a href="sch_allocation.php?schedule_id=<?php echo $schedule['schedule_id'];?>" class="link_stnd"><?php echo $lang['href_edit_attendance'];?></a>
						<?php }?>
						
						<?php
						if (isset($button)) {
						    echo "&nbsp;" . $button;
						}
						?>
						<br />
						</span>
						<?php
						if (isset($schedule['rsp'])) {
							echo "<b>" . $lang['txt_published_to']. ": </b>";
						    foreach($schedule['rsp'] as $key => $i):
								
								echo trim($lang['rsp']['rsp_level'][$i['level_id']] . " " . $i['degree_id']);
								echo " (" .$lang['rsp']['status'][$i['status_id']] . ")";
								if ($key+1 < count($schedule['rsp'])) {
								    echo ", ";
								}
								
							endforeach;
						}
						?><br />
						</div>
					</td>
				</tr>
			</table>
			<?php
			if (isset($schedule['schedule_id'])) {
				//comments
				if ($schedule['user_id'] == $me['user_id']) {
					$unlocked = 1;
				}
					
				if (isset($group)) {
					if ($this->group_acs->checkPermission($resource_ids['group_schedule'], $privilege_ids['allow_comment'])) {
					    $unlocked = 1;
					}
					
					$hidden_form = array(
						"schedule_id" => $schedule['schedule_id'], 
						"group_id" => $group['group_id']
					);
					
					$requested_comment_language_id = $group['language_id'];
				}
				else {
					if (!empty($schedule['schedule_allow_comments'])) {
					    $unlocked = 1;
					}
					
					$hidden_form = array(
						"schedule_id" => $schedule['schedule_id']
					);
					
					$requested_comment_language_id = $me['language_id'];
				}
				
				if (isset($_REQUEST['user_id'])) {
					$hidden_form['user_id'] = $_REQUEST['user_id'];
				}
				
				include $templatePath . "comment.inc.tpl.php";
			}
			?>
			</div>
			
			<div id="box_bottom">
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
					<tr>
						<td align="left">
							<img src="<?php echo $templatePath;?>img/box_bottom_left.png" width="5" height="18" alt="" border="0" /><br />
						</td>
						<td align="left">
							<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" border="0" /><br />
						</td>
						<td align="right">
							<img src="<?php echo $templatePath;?>img/box_bottom_right.png" width="5" height="18" alt="" border="0" /><br />
						</td>
					</tr>
				</table>
			</div>
		</td>
	</tr>
</table>