<?php
$capacity = 0;
$duration = 0;
$duration_text = '';
$price_per_person = 0;
$price_per_person_format = '';
if(!empty($tpl['line_detail_arr']))
{
	$line_arr = $tpl['line_detail_arr'];
	if($tpl['traveling'] == 'from')
	{
		$duration = (int) $line_arr['duration_dropoff'];
		$price_per_person = $line_arr['price_dropoff'];
		$duration_text = (int) $line_arr['duration_dropoff'] . ' ' . __('lblMinutes', true);
		$price_per_person_format = pjUtil::formatCurrencySign(pjUtil::convertToCurrencyFormat($line_arr['price_dropoff'], $tpl['option_arr']), $tpl['option_arr']['o_currency']) . ' ' . __('lblPerPerson', true);
	}else{
		$duration = (int) $line_arr['duration_pickup'];
		$price_per_person = $line_arr['price_pickup'];
		$duration_text = (int) $line_arr['duration_pickup'] . ' ' . __('lblMinutes', true);
		$price_per_person_format = pjUtil::formatCurrencySign(pjUtil::convertToCurrencyFormat($line_arr['price_pickup'], $tpl['option_arr']), $tpl['option_arr']['o_currency']) . ' ' . __('lblPerPerson', true);
	}
	$capacity = (int) $tpl['line']['seats'];
}
ob_start(); 	
?>
<select name="<?php echo isset($_GET['has_return']) ? 'return_time' : 'booking_time';?>" id="<?php echo isset($_GET['has_return']) ? 'return_time' : 'booking_time';?>" class="pj-form-field w150 required" data-msg-required="<?php __('tr_field_required');?>">
	<?php
	if(isset($tpl['timetable_arr']))
	{
		if(!empty($tpl['timetable_arr']))
		{
			?>
			<option value="">-- <?php __('lblChoose'); ?>--</option>
			<?php
			$iso_date = pjUtil::formatDate($_GET['booking_date'], $tpl['option_arr']['o_date_format']);
			$time_arr = explode("|", $tpl['timetable_arr']['time']);
			foreach($time_arr as $time)
			{
				$time_ts = strtotime($time);
				if($tpl['traveling'] == 'to')
				{
					$time_ts = $time_ts - ($duration * 60);
				}
				$disabled = '';
				$iso_time = date('H:i', $time_ts);
				$time_ts = strtotime($iso_date . ' ' . $iso_time);
				if((array_key_exists($iso_time, $tpl['booked_time_arr']) && ($tpl['booked_time_arr'][$iso_time] + (int)$_GET['passengers'] > $capacity) ) || $time_ts < time())
				{
					$disabled = ' disabled';
				}
				?><option value="<?php echo $iso_time;?>"<?php echo $disabled;?>><?php echo date($tpl['option_arr']['o_time_format'], $time_ts);?></option><?php
			}
		}else{
			?><option value="">-- <?php __('lblNoAvailableTime'); ?>--</option><?php
		}
	} else {
		?><option value="">-- <?php __('lblChoose'); ?>--</option><?php
	}
	?>
</select>
<?php
$timetable = ob_get_contents();
ob_end_clean();

pjAppController::jsonResponse(compact('timetable', 'duration','duration_text', 'price_per_person', 'price_per_person_format'));
?>
