<?php
if(isset($tpl['avail_arr'][$date]))
{
    if(isset($tpl['avail_arr'][$date]['avail']) && $tpl['avail_arr'][$date]['avail'] == true)
    {
        if(!isset($tpl['t_arr'][$date]['is_dayoff'])){
            if(isset($tpl['t_arr'][$date]) && is_array($tpl['t_arr'][$date]))
            {
            	$period = $tpl['t_arr'][$date];
            	if (isset($period['start_time']) && ($date > date('Y-m-d') || ($date == date('Y-m-d') && $period['start_time'] >= date('H:i'))))
            	{
	                ?>
	        	    <div style="background-color: #5ac5b6;border-color: #5ac5b6;">
	                    <?php echo date($tpl['option_arr']['o_time_format'], strtotime($period['start_time']));?> - <?php echo date($tpl['option_arr']['o_time_format'], strtotime($period['end_time']));?>
	                </div>
	        	    <?php
            	}
            }
	    }
    }else if(isset($tpl['avail_arr'][$date]['is_dayoff']) && $tpl['avail_arr'][$date]['is_dayoff'] == true){
    }else{
        foreach($tpl['avail_arr'][$date] as $items)
        {
        	if (isset($items['start_time']) && !isset($items[0])) 
            {
            	if (isset($items['start_time']) && ($date > date('Y-m-d') || ($date == date('Y-m-d') && $items['start_time'] >= date('H:i'))))
            	{
	                ?>
	    	        <div style="background-color: #5ac5b6;border-color: #5ac5b6;">
	                    <?php echo date($tpl['option_arr']['o_time_format'], strtotime($items['start_time']));?> - <?php echo date($tpl['option_arr']['o_time_format'], strtotime($items['end_time']));?>
	                </div>
	    	        <?php
            	}
            }else {
            	$tmp_booking_service_ids_arr = array();
            	foreach($items as $item) {
	                if(isset($tpl['booking_arr'][$date][$item]))
	                {
	                    $booking = $tpl['booking_arr'][$date][$item];
	                    if (in_array($booking['id'], $tmp_booking_service_ids_arr)) continue;
	                    if (isset($tpl['booking_schedule_arr'][$date][$booking['start_ts']]) && count($tpl['booking_schedule_arr'][$date][$booking['start_ts']]) > 1) {
	                    	?>
	                    	<div style="margin: 0; padding: 0; border: 0;">
	                    		<?php 
	                    		$idx = 0;
	                    		foreach ($tpl['booking_schedule_arr'][$date][$booking['start_ts']] as $k => $v) { 
	                    			$tmp_booking_service_ids_arr[] = $v['id'];
				                    $status = 'background-color: #fbc994;border-color: #fbc994;';
				                    if($v['booking_status'] == 'confirmed')
				                    {
				                        $status = 'background-color: #ed5565;border-color: #ed5565;';
				                    }
	                    			?>
	                    			<div style="<?php echo $status;?>; width: 46%; <?php echo $idx == 0 ? 'float: left; margin-right: 5px;' : 'float: right; margin-left: 5px;'?>;">
				                        <?php echo date($tpl['option_arr']['o_time_format'], $v['start_ts']);?> - <?php echo date($tpl['option_arr']['o_time_format'], $v['end_ts']);?>
				                        <br/>
				                        <?php echo pjSanitize::html($v['c_name']);?>
				                        <br/>
				                        <?php 
				                        echo __('booking_employee', true).': '.pjSanitize::html($v['employee_name']);
			                    		if (!empty($v['apprentice_name'])) {
				                    		echo '<br/>'.__('booking_service_apprentice', true).': '.$v['apprentice_name'];	
				                    	}
				                        ?>
				                    </div>
	                    		<?php $idx++;} ?>
	                    		<div style="margin: 0; padding: 0; border: 0;clear:both;"></div>
	                    	</div>
	                    	<?php 
	                    } else {
	                    	$tmp_booking_service_ids_arr[] = $booking['id'];
		                    $status = 'background-color: #fbc994;border-color: #fbc994;';
		                    if($booking['booking_status'] == 'confirmed')
		                    {
		                        $status = 'background-color: #ed5565;border-color: #ed5565;';
		                    }
		                    ?>
		           	    	<div style="<?php echo $status;?>">
		                        <?php echo date($tpl['option_arr']['o_time_format'], $booking['start_ts']);?> - <?php echo date($tpl['option_arr']['o_time_format'], $booking['end_ts']);?>
		                        <br/>
		                        <?php echo pjSanitize::html($booking['c_name']);?>
		                        <br/>
		                        <?php 
		                        echo __('booking_employee', true).': '.pjSanitize::html($booking['employee_name']);
	                    		if (!empty($booking['apprentice_name'])) {
		                    		echo '<br/>'.__('booking_service_apprentice', true).': '.$booking['apprentice_name'];	
		                    	}
		                        ?>
		                    </div>
		                    <?php
	                    }
	                }
            	}
            	
            }
        }
    }
}
?>