<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	?>
	<div class="ui-tabs ui-widget ui-widget-content ui-corner-all b10">
		<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
			<li class="ui-state-default ui-corner-top ui-tabs-active ui-state-active"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminTimetable&amp;action=pjActionUpdate&amp;id=<?php echo (int)$tpl['arr']['id'];?>"><?php __('tabDetails'); ?></a></li>
			<li class="ui-state-default ui-corner-top"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminTimetable&amp;action=pjActionSchedule&amp;id=<?php echo (int)$tpl['arr']['id'];?>"><?php __('tabSchedule'); ?></a></li>
		</ul>
	</div>
	<?php
	pjUtil::printNotice(__('infoUpdateTimetableTitle', true, false), __('infoUpdateTimetableDesc', true, false));
	?>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminTimetable&amp;action=pjActionUpdate" method="post" id="frmUpdateTimetable" class="pj-form form" enctype="multipart/form-data">
		<input type="hidden" name="timetable_update" value="1" />
		<input type="hidden" name="id" value="<?php echo (int)$tpl['arr']['id'];?>" />
		
		<div class="clear_both">
			<p>
				<label class="title"><?php __('lblDepartureArrivalLocation'); ?></label>
				<span class="inline-block">
					<select name="location_id" id="location_id" class="pj-form-field w300 required" data-msg-required="<?php __('tr_field_required'); ?>">
						<option value="">-- <?php __('lblChoose'); ?>--</option>
						<?php
						foreach($tpl['da_arr'] as $k => $v)
						{
							?><option value="<?php echo $v['id'];?>"<?php echo $v['id'] == $tpl['arr']['location_id'] ? ' selected="selected"' : NULL;?>><?php echo $v['title'];?></option><?php
						} 
						?>
					</select>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblLine'); ?></label>
				<span id="pjLineWrapper" class="inline-block">
					<select name="line_id" id="line_id" class="pj-form-field w300 required" data-msg-required="<?php __('tr_field_required'); ?>">
						<option value="">-- <?php __('lblChoose'); ?>--</option>
						<?php
						if(isset($tpl['line_arr']))
						{
							foreach($tpl['line_arr'] as $v)
							{
								?><option value="<?php echo $v['id'];?>"<?php echo $v['id'] == $tpl['arr']['line_id'] ? ' selected="selected"' : NULL;?>><?php echo $v['title'];?></option><?php
							}
						} 
						?>
					</select>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblDirection'); ?></label>
				<span class="inline-block">
					<span class="block float_left t5 r20">
						<input type="radio" name="direction" id="direcion_arriving" value="arriving"<?php echo $tpl['arr']['direction'] == 'arriving' ? ' checked="checked"': NULL;?> class="block float_left r3"/>
						<label for="direcion_arriving" class="block float_left"><?php __('lblArriving');?></label>
					</span>
					<span class="block float_left t5">
						<input type="radio" name="direction" id="direcion_departing" value="departing"<?php echo $tpl['arr']['direction'] == 'departing' ? ' checked="checked"': NULL;?> class="block float_left r3"/>
						<label for="direcion_departing" class="block float_left"><?php __('lblDeparting');?></label>
					</span>
				</span>
			</p>
			<?php
			$days = __('days', true, true);
			$week_days = explode("|", $tpl['arr']['every']); 
			?>
			<p>
				<label class="title"><?php __('lblEvery'); ?></label>
				<span class="inline-block">
					<?php
					foreach($days as $k => $v)
					{ 
						?>
						<span class="block float_left t5 r20">
							<input type="checkbox" name="every[]" id="every_<?php echo $k?>" value="<?php echo $k?>"<?php echo in_array($k, $week_days) ? ' checked="checked"' : NULL;?> class="block float_left r3"/>
							<label for="every_<?php echo $k?>" class="block float_left"><?php echo $v;?></label>
						</span>
						<?php
					} 
					?>
				</span>
			</p>
			<?php
			$time_arr = explode("|", $tpl['arr']['time']);
			?>
			<p>
				<label class="title pjTimeLabel pjTimeLabel-arriving" style="display:<?php echo $tpl['arr']['direction'] == 'arriving' ? '': 'none';?>;"><?php __('lblArrivingAt'); ?></label>
				<label class="title pjTimeLabel pjTimeLabel-departing" style="display:<?php echo $tpl['arr']['direction'] == 'arriving' ? 'none': '';?>;"><?php __('lblDepartingAt'); ?></label>
				<span id="pjTimeWrapper" class="block overflow">
					<?php
					foreach($time_arr as $k => $time)
					{ 
						$index = 'new_' . rand(1, 999999);
						if($k > 0)
						{
							?>
							<span class="block float_left r15">
								<input id="time_<?php echo $index;?>" name="time[<?php echo $index;?>]" value="<?php echo date($tpl['option_arr']['o_time_format'], strtotime($time));?>" class="pj-form-field w60 float_left pjTimePicker required r3 b10" readonly="readonly"/>
								<a href="#" class="linkRemoveRow float_left"></a>
							</span>
							<?php
						}else{
							?>
							<span class="block float_left" style="margin-right: 38px;">
								<input id="time_<?php echo $index;?>" name="time[<?php echo $index;?>]" value="<?php echo date($tpl['option_arr']['o_time_format'], strtotime($time));?>" class="pj-form-field w60 float_left pjTimePicker required r3 b10" readonly="readonly"/>								
							</span>
							<?php
						}
					} 
					?>
				</span>
			</p>
			<p style="margin-top: -20px;">
				<label class="title">&nbsp;</label>
				<input type="button" value="<?php __('btnAddTime'); ?>" class="pj-button pjAddTime"/>
			</p>
			<p>
				<label class="title"><?php __('lblStatus'); ?></label>
				<span class="inline_block">
					<select name="status" id="status" class="pj-form-field required" data-msg-required="<?php __('tr_field_required');?>">
						<option value="">-- <?php __('lblChoose'); ?>--</option>
						<?php
						foreach (__('u_statarr', true) as $k => $v)
						{
							?><option value="<?php echo $k; ?>"<?php echo $k == $tpl['arr']['status'] ? ' selected="selected"' : NULL; ?>><?php echo $v; ?></option><?php
						}
						?>
					</select>
				</span>
			</p>
			<p>
				<label class="title">&nbsp;</label>
				<input type="submit" value="<?php __('btnSave'); ?>" class="pj-button" />
				<input type="button" value="<?php __('btnCancel'); ?>" class="pj-button" onclick="window.location.href='<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjAdminTimetable&action=pjActionIndex';" />
			</p>
		</div>
	</form>
	
	<div id="pjTimeClone" style="display: none;">
		<span class="block float_left r15">
			<input id="time_{INDEX}" name="time[{INDEX}]" class="pj-form-field w60 float_left {TIMEPICKER} required r3 b10" readonly="readonly"/>
			<a href="#" class="linkRemoveRow float_left"></a>
		</span>
	</div>
	
	<?php
	$show_period = 'false';
	if((strpos($tpl['option_arr']['o_time_format'], 'a') > -1 || strpos($tpl['option_arr']['o_time_format'], 'A') > -1))
	{
		$show_period = 'true';
	} 
	?>
	<script type="text/javascript">
	var myLabel = myLabel || {};
	myLabel.showperiod = <?php echo $show_period; ?>;
	</script>
	<?php
}
?>