<?php
	$quantities_list = array();
	for ($i = 1; $i <= 20; $i++)
	{
		$quantities_list[$i] = $i;
	}
?>
	
<?php /*  Include the Ticket Policies  */ ?>
<?php echo $__env->make('layouts.ticket_policies', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>


<?php
	// Get the config file path
	$config_file = app_path() . '/views/activities/tickets/config.json';

	// Make sure the file exists
	if (!file_exists($config_file)) throw new \Exception ("The tickets configuration file cannot be found.");

	// Read the JSON config file
	$raw_data = file_get_contents($config_file);
	$data = json_decode($raw_data);
	if (is_null($data)) throw new \Exception ("The tickets configuration file cannot be parsed because it is an invalid JSON file.  Refer to this JSON Validator (http://jsonlint.com/) for the specifics on the error, or ask Gibby for assistance.");
?>

<?php if (count($data) > 0): ?>

	<?php

		$displayed = false;
		$unavailable = "Ticket information is unavailable at this time.";
	?>

	<?php foreach ($data as $act): ?>

		<?php /*  Search for this activity  */ ?>
		<?php if (!Helpers::strEqual($activity_slug, $act->activity)) continue;	?>

		
		<?php
			if (!$act->show)
			{
				if (Auth::check() and Auth::user()->isOsaaUser())
				{
					// Show hidden activities for OSAA users
					echo '<div style="padding: 0.5em;" class="ui-state-highlight"><b>OSAA Staff Preview:</b>  The following information is hidden from the public.  To publish this information, change the "show" value to <i>true</i> for this <b>activity</b> in the configuration file.  To show/hide a specific activity event, change the "show" value to <i>true</i> or <i>false</i> accordingly for the <b>event</b> within the activity entry in the configuration file.  To open PayPal ticket availability, add "?override-status=0" to the the URL where -1 = early, 0 = active, and 1 = expired.</div>';
				}
				else
				{
					// This activity is hidden
					$unavailable = $act->unavailable;
					continue;
				}
			}

			$displayed = true;
		?>
		
		<!-- General Information -->
		<h3 style="color: #990000;">Onsite Information</h3>
		<div style="font-size: smaller;">
			<?php echo $act->description; ?>		
		</div>

		<br class="clear" />

		<!-- Events -->		
		<?php if (count($act->events) > 0): ?>

			<?php foreach ($act->events as $event): ?>

				<?php if ($event->show): ?>

					<!-- Event -->
					
					<!-- Title Link -->
					<?php
						$link_name = strtolower(str_replace(' ', '_', str_replace(' - ', '_', $event->title)));

						$glow = null;

						echo "<!-- " . Input::get('focus') . " -->";

						if (Helpers::strEqual($link_name, Input::get('focus', null)))
						{
							$glow = "-webkit-box-shadow: 0px 0px 15px 5px rgba(255, 255, 190, .75); -moz-box-shadow: 0px 0px 15px 5px rgba(255, 255, 190, .75); box-shadow: 0px 0px 15px 5px rgba(255, 255, 190, .75);";
						}
					?>
					<a name="<?php echo $link_name; ?>"></a>

					<!-- Event Box -->
					<div class="ui-corner-all ticket_event_box" style="border: 2px solid #717082; width: 100%; min-height: 185px; background-color: #fcfcfc; margin-bottom: 2em; background-image: url('<?php echo asset('images/icons/vertical_dots.png'); ?>'); background-repeat: repeat-y; background-position: 75% 0; font-size: 9pt; padding-bottom: 0.5em; <?php echo $glow; ?>" data-link-name="<?php echo $link_name; ?>">

						<!-- Right Side -->
						<div style="float: right; width: 24%; height: 95%; display: inline-block; padding: 0.15em 0 0.25em 0.25em;">
							<div style="width: 100%; text-align: center; font-style: italic; font-family: Lucida Console; letter-spacing: 0px;">
								Purchase Tickets Online
							</div>

							<?php						
								$open = strtotime($event->tickets->open);
								$close = strtotime($event->tickets->close);
								$now = time();

								/* Ticket Statuses:
								 *   -1 = Early
								 *    0 = Available  
								 *    1 = Expired
								 *	  2 = Bypass PayPal to Outside Vendor
								 */
								if ($now < $open) $status = -1;
								if ($now >= $open and $now <= $close) $status = 0;
								if ($now > $close) $status = 1;

								if (Input::has('override-status'))
								{
									$status = Input::get('override-status');
								}

								if (property_exists($event->tickets, 'bypass'))
								{								
									$status = 2;
								}
							?>

							<?php if ($status == -1): ?>
								<?php /*  Early  */ ?>

								<div style="text-align: center; margin: 1em 0 2em 0; font-weight: bold; font-size: 10pt; color: #c49331; font-family: Lucida Console; letter-spacing: 1px;  text-transform: uppercase;">
									Coming Soon								
								</div>

								<div style="text-align: center; margin-top: 1em;">
									Available Starting<br />
									<?php echo date('g:i A n/d/Y', $open); ?>
								</div>

							<?php elseif ($status == 0): ?>
								<?php /*  Available  */ ?>

								<div style="text-align: center; margin: 0.5em 0 1em 0; font-weight: bold; font-size: 10pt; color: #147300;">
									Available Now Through<br />								
									<?php echo date('g:i A n/d/Y', $close); ?>
								</div>

								<?php if (count($event->tickets->items) > 0): ?>

									<?php foreach ($event->tickets->items as $item): ?>

										<?php echo Form::open(array('url'    => 'https://www.paypal.com/cgi-bin/webscr',
															'method' => 'post')); ?>			

											<?php echo Form::hidden('cmd', '_cart'); ?>
											<?php echo Form::hidden('add', '1'); ?>
											<?php echo Form::hidden('business', 'tickets@osaa.org'); ?>
											<?php echo Form::hidden('bn', 'OSAA_AddToCart_WPS_US'); ?>
											<?php echo Form::hidden('currency_code', 'USD'); ?>
											<?php echo Form::hidden('handling_cart', '3.00'); ?>
											<?php echo Form::hidden('paymentaction', 'sale'); ?>
											<?php echo Form::hidden('lc', 'US'); ?>
											<?php echo Form::hidden('no_shipping', '0'); ?>
											<?php echo Form::hidden('shipping', '0.00'); ?>
											<?php echo Form::hidden('return', url('/activities/' . $activity_slug . '/tickets')); ?>
											<?php echo Form::hidden('rm', '1'); ?>
											<?php echo Form::hidden('cancel_return', url('/activities/' . $activity_slug . '/tickets')); ?>
											<?php echo Form::hidden('cpp_cart_border_color', '005fa9'); ?>										


											<?php echo Form::hidden('amount', $item->price); ?>
											<?php
												$item_activity = preg_replace('/boys|girls/i', '', $activity_name);
											?>											
											
											<?php if (Helpers::strEqual($activity_slug, array('BSW', 'GSW'))): ?>

												<?php echo Form::hidden('item_name', str_replace('SW', '', $event->short) . ' ' . $item->name . ' ' . $item_activity . ' State Championship Ticket'); ?>
												<?php echo Form::hidden('item_number', strtoupper($event->short . '-' . $item->name)); ?>

											<?php else: ?>

												<?php echo Form::hidden('item_name', $item->name . ' ' . $item_activity . ' Ticket'); ?>
												<?php echo Form::hidden('item_number', strtoupper($event->short . '-' . $activity_slug . '-' . $item->name)); ?>

											<?php endif; ?>

											<div style="font-weight: bold;">
												<?php echo $item->name; ?> Ticket ($<?php echo $item->price; ?>)
											</div>
											Qty: <?php echo Form::select('quantity', $quantities_list, array('style' => 'font-size: 8pt;')); ?>

											<?php echo Form::submit('Add to Cart', array('class' => 'button',
																				 'style' => 'margin-left: 1em; font-size: 8pt;')); ?>

											<?php if (Helpers::strEqual($item->name, 'student')): ?>
												<div style="font-size: 8.5pt; line-height: 8.5pt; margin-top: 0.25em;">(Age 5 thru high school senior)</div>
											<?php endif; ?>



										<?php echo Form::close(); ?>

										<br />

									<?php endforeach; ?>
								<?php else: ?>
									There are no ticket items to sell.
								<?php endif; ?>							

							<?php elseif ($status == 1): ?>
								<?php /*  Expired  */ ?>

								<div style="text-align: center; margin: 1em 0 2em 0; font-weight: bold; font-size: 10pt; color: #8a0000; font-family: Lucida Console; letter-spacing: 1px; text-transform: uppercase;">
									Closed
								</div>

								<div style="text-align: center; margin-top: 1em;">
									<?php echo $event->tickets->closed_note; ?>
								</div>

							<?php elseif ($status == 2): ?>
								<?php /*  Bypass  */ ?>

								<div style="text-align: center; margin: 1em 0 2em 0; font-weight: bold; font-size: 10pt; color: #151515; font-family: Lucida Console; letter-spacing: 1px;  text-transform: uppercase;">
									<?php echo $event->tickets->title; ?>								
								</div>

								<div style="text-align: center; margin-top: 1em;">
									<?php echo $event->tickets->bypass_text; ?>
								</div>

							<?php endif; ?>								
							
						</div>
						<!-- End Right Side -->

						<!-- Left Side -->
						<div style="width: 74%; height: 95%; padding: 0.15em 0 0.25em 0.25em; margin-right: 1%;">
							
							<!-- Event Title -->
							<div style="font-family: Lucida Console; width: 100%; text-align: center; font-weight: bold; letter-spacing: 2px; font-size: 12pt; text-transform: uppercase; background-color: #eeeeee;">
								- <?php echo $event->title; ?> -
							</div>
							
							<!-- Sub-Title Area -->
							<div style="width: 100%;">
								
								<!-- Date -->
								<div style="float: left; width: 50%; font-weight: bold; color: #006363;">
									<?php if (is_array($event->date)): ?>								
										<?php echo date('l, F j', strtotime($event->date[0])); ?> - 	<?php echo date('l, F j', strtotime($event->date[1])); ?>
									<?php else: ?>
										<?php echo date('l, F j', strtotime($event->date)); ?>
									<?php endif; ?>


								</div>

								<!-- Location -->
								<div style="float: left; width: 50%; text-align: right;">
										<?php echo $event->location; ?>
									
								</div>
							</div>

							<!-- Description -->
							<div style="width: 100%; min-height: 10.5em; overflow: hidden;">
								<?php echo $event->description; ?>																
							</div>

							<!-- Links -->
							<?php if (count($event->links) > 0): ?>
								<div style="">
									<?php for ($i = 0; $i < count($event->links); $i++): ?>
										
										<?php if (substr($event->links[$i]->url, 0, 1) != '$'): ?>
											<a href="<?php echo $event->links[$i]->url; ?>" target="_blank"><?php echo $event->links[$i]->name; ?></a>
											<?php if ($i + 1 < count($event->links)): ?>
												|
											<?php endif; ?>
										<?php endif; ?>
									<?php endfor; ?>
								</div>
							<?php endif; ?>

						</div>
						<!-- End Left Side -->						

					</div>
					<!-- End Event -->
				<?php endif; ?>

			<?php endforeach; ?>

			<?php if (Helpers::strEqual($activity_slug, array('BSC', 'GSC')) and false): ?>

				<h3 style="color: #990000;">Updated Soccer Schedules</h3>
				<b>Liberty HS</b><br />
				<ul>
					<li><b>4A Girls</b> 10:30am - Cascade vs. Valley Catholic</li>
					<li><b>4A Boys</b> 1pm - North Marion vs. Stayton</li>
					<li><b>3A/2A/1A Girls</b> 3:30pm - Westside Christian vs. Oregon Episcopal</li>
				</ul>

				<br />

				<b>Hillsboro Stadium</b><br />
				<ul>
					<li><b>5A Boys</b> 1pm - Woodburn vs. Hood River Valley</li>
					<li><b>6A Boys</b> 3:30pm - Grant vs. Central Catholic</li>
					<li><b>6A Girls</b> 6pm - North Medford vs. Tualatin</li>
					<li><b>3A/2A/1A Boys</b> 8:30pm - Portland Adventist vs. Oregon Episcopal</li>
				</ul>

				<br />

				<i><b>5A Girls</b> TBD - Will be played at a later date, please check the bracket for the most up to date information.</i>

				<br /><br />

			<?php endif; ?>

		<?php else: ?>

			<?php if (Helpers::strEqual($activity_slug, 'FBL')): ?>
				<?php /* Ticket information will be available mid-November. */ ?>
			<?php else: ?>
				There are no events setup to sell <?php echo $activity_name; ?> tickets online.
			<?php endif; ?>

		<?php endif; ?>

	<?php endforeach; ?>

	<?php /*  No information was entered for this activity in the config file  */ ?>
	<?php if (!$displayed): ?>				

		<h2><?php echo $activity_name; ?> Tickets</h2>
		
		<p>
			<?php if (Helpers::strEqual($activity_slug, array('BTN', 'GTN', 'BGF', 'GGF', 'SOL', 'SPE'))): ?>
				No tickets sold at this event.  Admission is free.
			<?php else: ?>
				<?php echo $unavailable; ?>
			<?php endif; ?>
		</p>

	<?php endif; ?>

<?php endif; ?>

<script type="text/javascript">

		


</script>