<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	$titles = __('error_titles', true);
	$bodies = __('error_bodies', true);
	if (isset($_GET['err']))
	{
		pjUtil::printNotice(@$titles[$_GET['err']], @$bodies[$_GET['err']]);
	}
	if ($controller->isEmployee())
	{
		include dirname(__FILE__) . '/elements/menu_employees.php';
		pjUtil::printNotice(@$titles['AT07'], @$bodies['AT07']);
	} elseif (isset($_GET['foreign_id']) && isset($_GET['type'])) {
		$employee_id = $_GET['foreign_id'];
		include dirname(__FILE__) . '/elements/menu_admin.php';
		pjUtil::printNotice(@$titles['AT07'], @$bodies['AT07']);
	} else {
		include PJ_VIEWS_PATH . 'pjLayouts/elements/optmenu.php';
		include dirname(__FILE__) . '/elements/menu_options.php';
		
		pjUtil::printNotice(@$titles['AT05'], @$bodies['AT05']);
	}
	
	$week_start = isset($tpl['option_arr']['o_week_start']) && in_array((int) $tpl['option_arr']['o_week_start'], range(0,6)) ? (int) $tpl['option_arr']['o_week_start'] : 0;
	$jqDateFormat = pjUtil::jqDateFormat($tpl['option_arr']['o_date_format']);
	$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';
	}
	?>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminTime&amp;action=pjActionCustom" method="post" class="form" id="frmTimeCustom">
		<input type="hidden" name="custom_time" value="1" />
		<?php
		if (isset($_GET['foreign_id']) && (int) $_GET['foreign_id'] > 0)
		{
			?><input type="hidden" name="foreign_id" value="<?php echo (int) $_GET['foreign_id']; ?>" /><?php
		}
		if (isset($_GET['type']) && !empty($_GET['type']))
		{
			?><input type="hidden" name="type" value="<?php echo pjSanitize::html($_GET['type']); ?>" /><?php
		}
		?>
		<fieldset class="fieldset white">
			<legend><?php __('time_custom'); ?></legend>
			<div class="float_left w300">
				<p>
					<label class="title"><?php __('lblDateFrom'); ?></label>
					<span class="pj-form-field-custom pj-form-field-custom-after">
						<input type="text" name="date_from" id="date_from" class="pj-form-field w80 datepick pointer required" readonly="readonly" rel="<?php echo $week_start; ?>" rev="<?php echo $jqDateFormat; ?>" />
						<span class="pj-form-field-after"><abbr class="pj-form-field-icon-date"></abbr></span>
					</span>
				</p>
				<p>
					<label class="title"><?php __('lblDateTo'); ?></label>
					<span class="pj-form-field-custom pj-form-field-custom-after">
						<input type="text" name="date_to" id="date_to" class="pj-form-field w80 datepick pointer required" readonly="readonly" rel="<?php echo $week_start; ?>" rev="<?php echo $jqDateFormat; ?>" />
						<span class="pj-form-field-after"><abbr class="pj-form-field-icon-date"></abbr></span>
					</span>
				</p>
				<p>
					<label class="title"><?php __('time_from'); ?></label>
					<span class="inline-block">
						<input name="start" class="pj-timepicker pj-form-field w80 required"/>
					</span>
				</p>
				<p>
					<label class="title"><?php __('time_to'); ?></label>
					<span class="inline-block">
						<input name="end" class="pj-timepicker pj-form-field w80 required"/>
					</span>
				</p>
				<p>
					<label class="title">&nbsp;</label>
					<input type="submit" value="<?php __('btnSave', false, true); ?>" class="pj-button"  />
				</p>
			</div>
			<div class="float_right w370">
				<strong><?php __('lblDayAvailability'); ?>:</strong>

				<input type="hidden" name="monday_dayoff" value="T" />
				<input type="checkbox" name="monday_dayoff" id="monday_dayoff" value="F" />
				<label for="monday_dayoff"><?php __('lblShortMonday'); ?></label>

				<input type="hidden" name="tuesday_dayoff" value="T" />
				<input type="checkbox" name="tuesday_dayoff" id="tuesday_dayoff" value="F" />
				<label for="tuesday_dayoff"><?php __('lblShortTuesday'); ?></label>

				<input type="hidden" name="wednesday_dayoff" value="T" />
				<input type="checkbox" name="wednesday_dayoff" id="wednesday_dayoff" value="F" />
				<label for="wednesday_dayoff"><?php __('lblShortWednesday'); ?></label>

				<input type="hidden" name="thursday_dayoff" value="T" />
				<input type="checkbox" name="thursday_dayoff" id="thursday_dayoff" value="F" />
				<label for="thursday_dayoff"><?php __('lblShortThursday'); ?></label>

				<input type="hidden" name="friday_dayoff" value="T" />
				<input type="checkbox" name="friday_dayoff" id="friday_dayoff" value="F" />
				<label for="friday_dayoff"><?php __('lblShortFriday'); ?></label>

				<input type="hidden" name="saturday_dayoff" value="T" />
				<input type="checkbox" name="saturday_dayoff" id="saturday_dayoff" value="F" />
				<label for="saturday_dayoff"><?php __('lblShortSaturday'); ?></label>

				<input type="hidden" name="sunday_dayoff" value="T" />
				<input type="checkbox" name="sunday_dayoff" id="sunday_dayoff" value="F" />
				<label for="sunday_dayoff"><?php __('lblShortSunday'); ?></label>
				<br/><br/>
				<strong><?php __('lblDaysOff'); ?>:</strong>
				<input type="checkbox" name="is_dayoff" id="is_dayoff" value="F" />
			</div>
			<br class="clear_both" />
		</fieldset>
	</form>
	
	<div id="grid"></div>
	<?php
	$day_names = __('day_names', true);
	$months = __('months', true);
	ksort($day_names);
	ksort($months);
	?>
	<script type="text/javascript">
	var pjGrid = pjGrid || {};
	pjGrid.jsDateFormat = "<?php echo pjUtil::jsDateFormat($tpl['option_arr']['o_date_format']); ?>";
	var myLabel = myLabel || {};
	myLabel.showperiod = <?php echo $show_period; ?>;
	myLabel.time_date_from = "<?php __('lblDateFrom', false, true); ?>";
	myLabel.time_date_to = "<?php __('lblDateTo', false, true); ?>";
	myLabel.time_start = "<?php __('time_from', false, true); ?>";
	myLabel.time_end = "<?php __('time_to', false, true); ?>";
	myLabel.time_day_availability = "<?php __('lblDayAvailability', false, true); ?>";
	myLabel.time_days_off = "<?php __('lblDaysOff', false, true); ?>";
	myLabel.time_yesno = <?php echo pjAppController::jsonEncode(__('_yesno', true)); ?>;
	myLabel.delete_selected = "<?php __('delete_selected', false, true); ?>";
	myLabel.delete_confirmation = "<?php __('delete_confirmation', false, true); ?>";

	myLabel.monthNames = ["<?php echo join('","', $months); ?>"];
	myLabel.dayNamesMin = ["<?php echo join('","', $day_names); ?>"];
	</script>
	<?php
}
?>