<?php
if($tpl['status'] == 'OK')
{
	if($tpl['event_arr']['status'] == 'T')
	{
		?>
		<div class="panel panel-default pjTbMain">
			<?php
			include_once dirname(__FILE__) . '/elements/header.php';
			$FORM = @$_SESSION[$controller->defaultForm];
			?>
			<form id="pjEtsCheckoutForm_<?php echo $_GET['id'];?>" action="" method="post">
			<input type="hidden" name="csrf_token" value="<?php echo pjAppController::getCsrfToken(); ?>">
				<input type="hidden" name="ets_checkout" value="1" />
				<input type="hidden" name="sub_total" value="<?php echo $tpl['price_arr']['subtotal'];?>" />
				<input type="hidden" name="tax" value="<?php echo $tpl['price_arr']['tax'];?>" />
				<input type="hidden" name="total" value="<?php echo $tpl['price_arr']['total'];?>" />
				<input type="hidden" name="deposit" value="<?php echo $tpl['price_arr']['deposit'];?>" />
				
				<div class="panel-body pjTbBody">
					<section class="pjTbSectionCheckout">
						<div class="pjTbForm pjTbFormCheckout">
							<?php
							include_once dirname(__FILE__) . '/elements/booking_details.php';
							
							if(isset($tpl['price_arr']['ticket_arr']))
							{
								foreach($tpl['price_arr']['ticket_arr'] as $k => $ticket)
								{
									if($ticket['attendee_name'] == 'yes')
									{
										?>
										<section class="pjTbFormSection">
											<p class="pjTbFormSectionTitle"><?php echo pjSanitize::html($ticket['title']);?></p><!-- /.pjTbFormSectionTitle -->
				
											<div class="form-horizontal">
												<?php
												for($i = 1; $i <= $ticket['qty']; $i++)
												{	 
													?>
													<div class="form-group">
														<label for="" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_name');?> #<?php echo $i;?>: </label>
														<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
															<input type="text" name="attendee[<?php echo $ticket['id']?>][<?php echo $i;?>]" value="<?php echo isset($FORM['attendee'][$ticket['id']][$i]) ? $FORM['attendee'][$ticket['id']][$i] : NULL;?>" class="form-control required" data-msg-required="<?php __('front_field_required');?>"/>
					
															<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
														</div><!-- /.col-lg-7 col-md-7 col-sm-7 col-xs-12 -->
													</div><!-- /.form-group -->
													<?php
												} 
												?>
											</div><!-- /.form-horizontal -->
										</section><!-- /.pjTbFormSection -->
										<?php
									}
								}
							} 
							?>
							
							<section class="pjTbFormSection">
								<p class="pjTbFormSectionTitle"><?php __('front_ticket_buyer');?></p><!-- /.pjTbFormSectionTitle -->
	
								<div class="form-horizontal">
									<?php
									if (in_array((int) $tpl['option_arr']['o_bf_include_title'], array(2,3)))
									{ 
										?>
										<div class="form-group">
											<label for="c_title" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_title'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<select id="c_title" name="c_title" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_title'] === 3 ? ' required' : null;?>" data-msg-required="<?php __('front_field_required'); ?>">
													<option value=""></option>
													<?php
													foreach(__('personal_titles', true) as $k => $v) 
													{
														?><option value="<?php echo $k;?>"<?php echo isset($FORM['c_title']) ? ($FORM['c_title'] == $k ? ' selected="selected"' : null) : null;?>><?php  echo $v;?></option><?php
													}
													?>
												</select>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_name'], array(2,3)))
									{ 
										?>
										<div class="form-group">
											<label for="c_name" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_name'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_name" name="c_name" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_name'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_name']); ?>" data-msg-required="<?php __('front_field_required'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_email'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_email" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_email'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_email" name="c_email" class="form-control email<?php echo (int) $tpl['option_arr']['o_bf_include_email'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_email']); ?>" data-msg-required="<?php __('front_field_required'); ?>" data-msg-email="<?php __('front_invalid_email'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_phone'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_phone" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_phone'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_phone" name="c_phone" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_phone'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_phone']); ?>" data-msg-required="<?php __('front_field_required'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_company'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_company" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_company'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_company" name="c_company" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_company'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_company']); ?>" data-msg-required="<?php __('front_field_required'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_address'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_address" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_address'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_address" name="c_address" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_address'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_address']); ?>" data-msg-required="<?php __('front_field_required'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_country'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_country" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_country'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<select id="c_country" name="c_country" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_country'] === 3 ? ' required' : null;?>" data-msg-required="<?php __('front_field_required'); ?>">
													<option value="">-- <?php __('front_choose');?> --</option>
													<?php
													foreach($tpl['country_arr'] as $k => $v) 
													{
														?><option value="<?php echo $v['id'];?>"<?php echo isset($FORM['c_country']) ? ($FORM['c_country'] == $v['id'] ? ' selected="selected"' : null) : null;?>><?php  echo $v['country_title'];?></option><?php
													}
													?>
												</select>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_state'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_state" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_state'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_state" name="c_state" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_state'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_state']); ?>" data-msg-required="<?php __('front_field_required'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_city'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_city" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_city'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_city" name="c_city" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_city'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_city']); ?>" data-msg-required="<?php __('front_field_required'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_zip'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_zip" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_zip'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" id="c_zip" name="c_zip" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_zip'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_zip']); ?>" data-msg-required="<?php __('front_field_required'); ?>">
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_notes'], array(2,3)))
									{
										?>
										<div class="form-group">
											<label for="c_notes" class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_notes'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<textarea id="c_notes" name="c_notes" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_notes'] === 3 ? ' required' : NULL; ?>" style="height: 150px;" data-msg-required="<?php __('front_field_required'); ?>"><?php echo pjSanitize::html(@$FORM['c_notes']); ?></textarea>
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<?php
									} 
									if ($tpl['option_arr']['o_payment_disable'] == 'No')
									{
										?>
										<div class="form-group">
											<label class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_payment_method')?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<select name="payment_method" class="form-control required" data-msg-required="<?php __('front_field_required'); ?>">
													<option value="">-- <?php __('front_choose');?> --</option>
													<?php
													foreach (__('payment_methods', true) as $k => $v)
													{
														if ($tpl['option_arr']['o_allow_' . $k] === "Yes")
														{
															?><option value="<?php echo $k; ?>"<?php echo @$FORM['payment_method'] != $k ? NULL : ' selected="selected"'; ?>><?php echo $v; ?></option><?php
														}
													}
													?>
												</select>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<div class="form-group pjEtsBankWrap" style="display: <?php echo @$FORM['payment_method'] != 'bank' ? 'none' : NULL; ?>">
											<label class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_bank_account')?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<label class="text-muted"><strong><?php echo nl2br(pjSanitize::html($tpl['option_arr']['o_bank_account'])); ?></strong></label>
											</div>
										</div>
										<div class="form-group pjEtsCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
											<label class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_cc_type')?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<select name="cc_type" class="form-control required" data-msg-required="<?php __('front_field_required'); ?>">
										    		<option value="">---</option>
										    		<?php
													foreach (__('cc_types', true) as $k => $v)
													{
														?><option value="<?php echo $k; ?>"<?php echo @$FORM['cc_type'] != $k ? NULL : ' selected="selected"'; ?>><?php echo $v; ?></option><?php
													}
													?>
										    	</select>
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<div class="form-group pjEtsCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
											<label class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_cc_num')?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" name="cc_num" class="form-control required" value="<?php echo pjSanitize::html(@$FORM['cc_num']); ?>"  autocomplete="off" data-msg-required="<?php __('front_field_required'); ?>"/>
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<div class="form-group pjEtsCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
											<label class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_cc_code')?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<input type="text" name="cc_code" class="form-control required" value="<?php echo pjSanitize::html(@$FORM['cc_code']); ?>"  autocomplete="off" data-msg-required="<?php __('front_field_required'); ?>"/>
										    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
										<div class="form-group pjEtsCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
											<label class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_cc_exp')?></label>
											
											<div class="col-sm-4">
												<?php
												$rand = rand(1, 99999);
												$time = pjTime::factory()
													->attr('name', 'cc_exp_month')
													->attr('id', 'cc_exp_month_' . $rand)
													->attr('class', 'form-control required')
													->prop('format', 'F');
												if (isset($FORM['cc_exp_month']) && !is_null($FORM['cc_exp_month']))
												{
													$time->prop('selected', $FORM['cc_exp_month']);
												}
												echo $time->month();
												?>
											</div>
											<div class="col-sm-3">
												<?php
												$time = pjTime::factory()
													->attr('name', 'cc_exp_year')
													->attr('id', 'cc_exp_year_' . $rand)
													->attr('class', 'form-control required')
													->prop('left', 0)
													->prop('right', 10);
												if (isset($FORM['cc_exp_year']) && !is_null($FORM['cc_exp_year']))
												{
													$time->prop('selected', $FORM['cc_exp_year']);
												}
												echo $time->year();
												?>
											</div>
										</div>
										<?php
									}
									if (in_array((int) $tpl['option_arr']['o_bf_include_captcha'], array(3)))
									{ 
										?>
										<div class="form-group">
											<label class="col-lg-3 col-md-3 col-sm-3 col-xs-12 control-label"><?php __('front_captcha'); ?></label>
											
											<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
												<div class="row">
													<div class="col-sm-3">
														<img src="<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjFront&amp;action=pjActionCaptcha&amp;rand=<?php echo rand(1, 99999); ?><?php echo isset($_GET['session_id']) ? '&session_id=' . $_GET['session_id'] : NULL;?>" alt="Captcha" style="vertical-align: middle" />
													</div><!-- /.col-sm-4 -->
					
													<div class="col-sm-6">
														<input type="text" name="captcha" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_captcha'] === 3 ? ' required' : NULL; ?>" maxlength="6" autocomplete="off" data-msg-required="<?php __('front_field_required'); ?>" data-msg-remote="<?php __('front_incorrect_captcha');?>">
				  								    	<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
													</div><!-- /.col-sm-4 -->
												</div><!-- /.row -->
											</div>
										</div>
										<?php
									}
									$terms = __('front_agree_with_terms', true);
									if(!empty($tpl['terms_conditions']))
									{ 
										$terms = str_replace("{STAG}", '<a href="#" class="pjTbModalTrigger" data-pj-toggle="modal" data-pj-target="#pjNcbTermModal" data-title="'.__('front_terms_title', true).'">', $terms);
										$terms = str_replace("{ETAG}", '</a>', $terms);
									}else{
										$terms = str_replace("{STAG}", '', $terms);
										$terms = str_replace("{ETAG}", '', $terms);
									}
									?>
									<div class="form-group">
										<div class="col-sm-offset-3 col-lg-7 col-md-7 col-sm-7 col-xs-12">
											<div class="checkbox">
												<label>
													<input type="checkbox" name="terms" value="1" checked="checked" class="required" data-msg-required="<?php __('front_field_required'); ?>">
											      	<?php echo $terms;?>
													<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
												</label>
												
											</div>
										</div>
									</div>
	
								</div><!-- /.form-horizontal -->
							</section><!-- /.pjTbFormSection -->
						</div><!-- /.pjTbForm pjTbFormCheckout -->
					</section><!-- /.pjTbSectionCheckout -->
				</div><!-- /.panel-body pjTbBody -->
				
				<footer class="panel-footer clearfix pjTbFooter">
					<?php
					if(!empty($tpl['event_arr']['map']))
					{ 
						?>
						<a href="#" class="btn btn-default pull-left pjEtsMenuItem" data-load="loadSeats"><?php __('front_btn_back');?></a>
						<?php
					}else{
						?>
						<a href="#" class="btn btn-default pull-left pjEtsMenuItem" data-load="loadTickets"><?php __('front_btn_back');?></a>
						<?php
					} 
					?>
					<button type="submit" class="btn btn-primary pull-right"><?php __('front_btn_submit');?></button>
				</footer><!-- /.panel-footer clearfix pjTbFooter -->
			</form>
		</div><!-- /.panel panel-default pjTbMain -->
		<div class="modal fade pjTbModal" id="pjNcbTermModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  	<div class="modal-dialog">
		    	<div class="modal-content">
		      		<div class="modal-header">
		        		<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"><?php __('front_btn_close');?></span></button>
		        		<h4 class="modal-title pjTbModalTitle" id="myModalLabel"><?php __('front_terms_title', false, true); ?></h4>
		      		</div>
				    <div class="modal-body">
				    	<?php echo nl2br(stripslashes($tpl['terms_conditions'])); ?>
				    </div>
		    	</div>
		  	</div>
		</div>
		<?php
	}else{
		?>
		<div class="panel panel-default pjTbMain">
			<div class="panel-body pjTbBody">
				<?php __('front_event_not_available');?>
			</div>
		</div>
		<?php
	}
}else{
	?>
	<div class="panel panel-default pjTbMain">
		<div class="panel-body pjTbBody">
			<?php __('front_event_not_exist');?>
		</div>
	</div>
	<?php
}
?>