<?php 
$index = $_GET['index'];
if($_GET['view'] != 'calendar')
{
	?>
	<br />
	<?php
	include_once PJ_VIEWS_PATH . 'pjFrontPublic/elements/header.php';
}
?>
<div id="pjEbcTableCalendar_<?php echo $_GET['index']; ?>" class="pjIcContainer pjEbcBookingWrapper">
	<div class="pjIcCalendar">
		<header class="pjIcCalendarHead clearfix text-center">
			<?php
			if($_GET['view'] != 'calendar')
			{ 
				?>
				<div class="pull-left">
					<a href="#" class="<?php echo $_GET['view'] == 'list' ? 'pjEbcBackToList' : 'pjEbcBackToCalendar'; ?>" data-view="<?php echo $_GET['view'];?>"><span class="glyphicon glyphicon-chevron-left"></span> <?php $_GET['view'] == 'list' ? __('front_back_to_list') : __('front_back_to_calendar');?></a>
				</div><!-- /.pull-left -->
				<?php
			}else{
				?>
				<div class="pull-right">
					<a href="#" class="pull-right btn btn-primary pjEbcBackToCalendar" data-view="<?php echo $_GET['view'];?>"><span class="glyphicon glyphicon-remove"></span></a>
				</div><!-- /.pull-left -->
				<?php
			} 
			?>
		</header><!-- /.pjIcCalendarHead -->
	</div>
</div>
<div class="pjEbcBookingWrapper pjEbcBookingForm">
	<div class="pjEbcFormHeader">
		<div class="datetime">
			<?php __('front_label_event_details');?>
		</div>
	</div>
	<div class="pjEbcEventContent">
		<label><?php echo stripslashes($tpl['arr']['title']) ;?></label>
		<span><?php echo $event_date = pjUtil::getEventDateTime($tpl['arr']['event_start_ts'], $tpl['arr']['event_end_ts'], $tpl['option_arr']['o_date_format'], $tpl['option_arr']['o_time_format'], $tpl['arr']['o_show_start_time'], $tpl['arr']['o_show_end_time']) ;?></span>
	</div>
	<div class="pjEbcFormContainer">
		<form id="pjEbcBookingForm_<?php echo $index;?>" action="" method="post" class="pjEbcForm">
			<input type="hidden" name="total_price" value="0" />
			<input type="hidden" name="event_id" value="<?php echo $tpl['arr']['id'];?>" />
			<div class="pjEbcFormHeader">
				<div class="datetime">
					<?php __('front_label_select_tickets');?>
				</div>
			</div>
			<div class="pjEbcFormBody">
				<?php
				$front_error = __('front_error', true);
				$front_required = __('front_required', true);
				$cc_types = __('cc_types', true);
				$months = __('months', true);
				ksort($months);
				
				if(count($tpl['price_arr']) > 0)
				{
					foreach($tpl['price_arr'] as $k => $v)
					{
						?>
						<div class="form-group">
							<label class="title"><?php echo stripslashes($v['price_name']);?></label>

							<div class="row">
								<div class="col-lg6 col-md-6 col-sm-6 col-xs-12">
									<div class="input-group">
										<select name="price_<?php echo $v['id']; ?>" data-price="<?php echo $v['price'];?>" class="pjEbcField form-control ebc-w50 pjEbcPriceSelector">
											<?php
											$max = intval($v['available']) - intval($v['cnt_booked']);
											$max = (int) $max < 1 ? 0 : $max;
											foreach (range(0, $max) as $i)
											{
												if (isset($_POST['price_' . $v['id']]) && $_POST['price_' . $v['id']] == $i)
												{
													?><option value="<?php echo $i; ?>" selected="selected"><?php echo $i; ?></option><?php
												} else {
													?><option value="<?php echo $i; ?>"><?php echo $i; ?></option><?php
												}
											}
											?>
										</select>
									
										<span class="input-group-addon">x <?php echo pjUtil::formatCurrencySign($v['price'], $tpl['option_arr']['o_currency']);?></span>
									</div><!-- /.input-group -->
								</div><!-- /.col-lg6 col-md-6 col-sm-6 col-xs-12 -->
							</div><!-- /.row -->
							<?php
							if($k + 1 == count($tpl['price_arr'])) 
							{
								?>
								<input type="hidden" id="pjEbcTicketValidate_<?php echo $index;?>" name="validate_ticket" class="required" value="" data-msg-required="<?php echo pjSanitize::html($front_error['min']);?>" />
								<?php
							} 
							?>
						</div>
						<?php
					}
				} 
				?>
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
					<p class="pjEbcPriceRow" style="display: none">
						<label class="title"><?php __('front_label_price'); ?></label>
						<label id="pjEbcPrice_<?php echo $index; ?>" class="content">---</label>
					</p>
					<p class="pjEbcPriceRow" style="display: none">
						<label class="title"><?php __('front_label_tax'); ?></label>
						<label id="pjEbcTax_<?php echo $index; ?>" class="content">---</label>
					</p>
					<p class="pjEbcPriceRow" style="display: none">
						<label class="title"><?php __('front_label_total_price'); ?></label>
						<label id="pjEbcTotalPrice_<?php echo $index; ?>" class="content">---</label>
					</p>
					<p class="pjEbcPriceRow" style="display: none">
						<label class="title"><?php __('front_label_deposit'); ?></label>
						<label id="pjEbcDeposit_<?php echo $index; ?>" class="content">---</label>
					</p>
				</div><!-- /.col-lg-12 col-md-12 col-sm-12 col-xs-12 -->
			</div>
			<div class="pjEbcFormHeader">
				<div class="datetime">
					<?php __('front_label_fill_in');?>
				</div>
			</div>
			<div class="row pjEbcFormBody">
				<?php
				if (in_array($tpl['option_arr']['o_bf_include_email'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_email');?></label>
							<input type="text" name="customer_email" class="pjEbcField form-control ebc-w300 email<?php echo $tpl['option_arr']['o_bf_include_email'] == 3 ? ' required' : NULL; ?>" value="<?php echo isset($_POST['customer_email']) ? htmlspecialchars($_POST['customer_email']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['email']); ?>" />
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_name'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_name');?></label>
							<input type="text" name="customer_name" class="pjEbcField form-control ebc-w300<?php echo $tpl['option_arr']['o_bf_include_name'] == 3 ? ' required' : NULL; ?>" value="<?php echo isset($_POST['customer_name']) ? htmlspecialchars($_POST['customer_name']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['name']); ?>" />
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_phone'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_phone');?></label>
							<input type="text" name="customer_phone" class="pjEbcField form-control ebc-w300<?php echo $tpl['option_arr']['o_bf_include_phone'] == 3 ? ' required' : NULL; ?>" value="<?php echo isset($_POST['customer_phone']) ? htmlspecialchars($_POST['customer_phone']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['phone']); ?>" />
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_country'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_country');?></label>
							<select name="customer_country" class="pjEbcField form-control ebc-w300<?php echo $tpl['option_arr']['o_bf_include_country'] == 3 ? ' required' : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['country']); ?>">
								<option value="">---</option>
								<?php
								if (isset($tpl['country_arr']) && is_array($tpl['country_arr']))
								{
									foreach ($tpl['country_arr'] as $v)
									{
										?><option value="<?php echo $v['id']; ?>"<?php echo isset($_POST['customer_country']) && $_POST['customer_country'] == $v['id'] ? ' selected="selected"' : NULL; ?>><?php echo stripslashes($v['country_title']); ?></option><?php
									}
								}
								?>
							</select>
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_city'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_city');?></label>
							<input type="text" name="customer_city" class="pjEbcField form-control ebc-w300<?php echo $tpl['option_arr']['o_bf_include_city'] == 3 ? ' required' : NULL; ?>" value="<?php echo isset($_POST['customer_city']) ? htmlspecialchars($_POST['customer_city']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['city']); ?>" />
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_state'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_state');?></label>
							<input type="text" name="customer_state" class="pjEbcField form-control ebc-w300<?php echo $tpl['option_arr']['o_bf_include_state'] == 3 ? ' required' : NULL; ?>" value="<?php echo isset($_POST['customer_state']) ? htmlspecialchars($_POST['customer_state']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['state']); ?>" />
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_zip'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_zip');?></label>
							<input type="text" name="customer_zip" class="pjEbcField form-control ebc-w300<?php echo $tpl['option_arr']['o_bf_include_zip'] == 3 ? ' required' : NULL; ?>" value="<?php echo isset($_POST['customer_zip']) ? htmlspecialchars($_POST['customer_zip']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['zip']); ?>" maxlength="8" />
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_address'], array(2, 3)))
				{
					?>
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_address');?></label>
							<input type="text" name="customer_address" class="pjEbcField form-control ebc-w300<?php echo $tpl['option_arr']['o_bf_include_address'] == 3 ? ' required' : NULL; ?>" value="<?php echo isset($_POST['customer_address']) ? htmlspecialchars($_POST['customer_address']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['address']); ?>" />
						</div>
					</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
					<?php
				}
				if (in_array($tpl['option_arr']['o_bf_include_notes'], array(2, 3)))
				{
					?>
					<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
						<div class="form-group">
							<label class="title"><?php __('front_label_notes');?></label>
							<textarea name="customer_notes" class="pjEbcField form-control ebc-w300 ebc-h100<?php echo $tpl['option_arr']['o_bf_include_notes'] == 3 ? ' required' : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['notes']); ?>"><?php echo isset($_POST['customer_notes']) ? htmlspecialchars($_POST['customer_notes']) : NULL; ?></textarea>
						</div>
					</div><!-- /.col-lg-12 col-md-12 col-sm-12 col-xs-12 -->
					<?php
				}
				if ($tpl['option_arr']['o_payment_disable'] == 'No')
				{
					?>
					<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
						<div class="form-group pjEbcPriceRow" style="display: none;">
							<label class="title"><?php __('front_label_payment_method'); ?></label>
							<select id="pjEbcPaymentMethod_<?php echo $index;?>" name="payment_method" class="pjEbcField form-control ebc-w300 required" data-msg-required="<?php echo $front_error['payment']; ?>">
								<option value="">---</option>
								<?php
								$payment_methods = __('payment_methods', true);
								foreach ($payment_methods as $k => $v)
								{
									if (@$tpl['option_arr']['o_allow_' . $k] == 'Yes')
									{
										?><option value="<?php echo $k; ?>"<?php echo isset($_POST['payment_method']) && $_POST['payment_method'] == $k ? ' selected="selected"' : NULL; ?>><?php echo stripslashes($v); ?></option><?php
									}
								}
								?>
							</select>
						</div>
					</div><!-- /.col-lg-12 col-md-12 col-sm-12 col-xs-12 -->
					
					<p class="ebcal-bankdata" style="display: <?php echo isset($_POST['payment_method']) && $_POST['payment_method'] == 'bank' ? 'block' : 'none'; ?>">
						<label class="title">&nbsp;</label>
						<label class="content ebc-overflow"><?php echo nl2br($tpl['option_arr']['o_bank_account']);?></label>
					</p>
					
					<div class="pjEbcPriceRow" style="display: <?php echo isset($_POST['payment_method']) && $_POST['payment_method'] == 'creditcard' ? 'block' : 'none'; ?>">
						<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
							<div class="form-group ebcal-ccdata" style="display: <?php echo isset($_POST['payment_method']) && $_POST['payment_method'] == 'creditcard' ? 'block' : 'none'; ?>">
								<label class="title"><?php __('front_label_cc_type'); ?></label>
								<select name="cc_type" class="pjEbcField form-control ebc-w300 pjEbcCCField" data-msg-required="<?php echo htmlspecialchars($front_required['cc_type']); ?>">
									<option value="">---</option>
									<?php
									foreach ($cc_types as $k => $v)
									{
										if (isset($_POST['cc_type']) && $_POST['cc_type'] == $k)
										{
											?><option value="<?php echo $k; ?>" selected="selected"><?php echo $v; ?></option><?php
										} else {
											?><option value="<?php echo $k; ?>"><?php echo $v; ?></option><?php
										}
									}
									?>
								</select>
							</div>
						</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-6 -->
						<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
							<div class="form-group ebcal-ccdata" style="display: <?php echo isset($_POST['payment_method']) && $_POST['payment_method'] == 'creditcard' ? 'block' : 'none'; ?>">
								<label class="title"><?php __('front_label_cc_number'); ?></label>
								<input type="text" name="cc_num" class="pjEbcField form-control ebc-w300 pjEbcCCField" value="<?php echo isset($_POST['cc_num']) ? htmlspecialchars($_POST['cc_num']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['cc_number']); ?>" />
							</div>
						</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-6 -->
						<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
							<div class="form-group ebcal-ccdata" style="display: <?php echo isset($_POST['payment_method']) && $_POST['payment_method'] == 'creditcard' ? 'block' : 'none'; ?>">
								<label class="title"><?php __('front_label_cc_expiration_date'); ?></label>
								<div class="row">
									<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
										<select name="cc_exp_month" class="pjEbcField form-control ebc-w120 pjEbcCCField" data-msg-required="<?php echo htmlspecialchars($front_required['cc_exp_month']); ?>">
											<?php
											foreach ($months as $key => $val)
											{
												?><option value="<?php echo $key;?>" <?php echo isset($_POST['cc_exp_month']) && $_POST['cc_exp_month'] == $key ? 'selected="selected"' : NULL;?> ><?php echo $val;?></option><?php
											}
											?>
										</select>
									</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-6 -->
									<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
										<select name="cc_exp_year" class="pjEbcField form-control ebc-w120 pjEbcCCField" data-msg-required="<?php echo htmlspecialchars($front_required['cc_exp_year']); ?>">
											<?php
											$y = (int) date('Y');
											for ($i = $y; $i <= $y + 10; $i++)
											{
												?><option value="<?php echo $i; ?>"<?php echo isset($_POST['cc_exp_year']) && (int) $_POST['cc_exp_year'] == $i ? ' selected="selected"' : NULL; ?>><?php echo $i; ?></option><?php
											}
											?>
										</select>
									</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-6 -->
								</div><!-- /.row -->
							</div>
						</div><!-- /.col-lg-12 col-md-12 col-sm-12 col-xs-12 -->
						<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
							<div class="form-group ebcal-ccdata" style="display: <?php echo isset($_POST['payment_method']) && $_POST['payment_method'] == 'creditcard' ? 'block' : 'none'; ?>">
								<label class="title"><?php __('front_label_cc_code'); ?></label>
								<input type="text" name="cc_code" class="pjEbcField form-control ebc-w300 pjEbcCCField" value="<?php echo isset($_POST['cc_code']) ? htmlspecialchars($_POST['cc_code']) : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['cc_code']); ?>" />
							</div>
						</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-6 -->
					</div>
					<?php 
				}
				if (in_array($tpl['option_arr']['o_bf_include_captcha'], array(2, 3)))
				{
					?>
					<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
						<div class="form-group">
							<label class="title"><?php echo __('front_label_captcha'); ?></label>
							<div class="row">
								<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
									<div class="input-group pjEbcCaptcha">
										<input type="text" name="captcha" maxlength="6" autocomplete="off" class="pjEbcField form-control ebc-w80<?php echo $tpl['option_arr']['o_bf_include_captcha'] == 3 ? ' required' : NULL; ?>" data-msg-required="<?php echo htmlspecialchars($front_required['captcha']); ?>" />
										<span class="input-group-addon">
											<img src="<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjFrontEnd&amp;action=pjActionCaptcha&amp;rand=<?php echo rand(1, 999999); ?><?php echo isset($_GET['session_id']) ? '&session_id=' . $_GET['session_id'] : NULL;?>" alt="Captcha" />
										</span>
									</div><!-- /.input-group -->
								</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-12 -->
							</div><!-- /.row -->
						</div>
					</div><!-- /.col-lg-12 col-md-12 col-sm-12 col-xs-12 -->
					<?php
				}
				if(!empty($tpl['arr']['booking_terms']))
				{
					?>
					<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
						<div class="form-group">
							<div class="pjEbcTermWrapper">
								<?php echo nl2br(stripslashes($tpl['arr']['booking_terms']));?>
							</div>
							<br/>
							<div class="">
								<input type="checkbox" id="ebc_accept_term_<?php echo $index;?>" name="accept_term" class="pjEbcField required" style="display: block; float: left; margin-right: 5px;" <?php echo isset($_POST['accept_term']) ? 'checked="checked"' : NULL; ?> data-msg-required="<?php echo htmlspecialchars($front_required['accept_terms']); ?>" />
								<label for="ebc_accept_term_<?php echo $index;?>"><?php __('front_label_accept_terms');?></label>
							</div>
						</div>
					</div><!-- /.col-lg-12 col-md-12 col-sm-12 col-xs-12 -->
					<?php
				}
				?>
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
					<label class="title">&nbsp;</label>
					<input type="submit" value="<?php __('front_button_submit'); ?>" class="pjEbcButton btn btn-primary" />
					<input type="button" value="<?php __('front_button_cancel'); ?>" class="pjEbcButton btn btn-primary pjEbcCancelBooking" data-id="<?php echo $tpl['arr']['id'];?>"/>
				</div>
			</div>
		</form>
	</div>
</div>