<?php
$offset = 0;
$step = $tpl['option_arr']['o_step'] * 60;
foreach($tpl['t_arr'] as $isoDate => $t_arr)
{
    if ($t_arr)
    {
        ?>
    	<table class="pj-table" cellpadding="0" cellspacing="0" style="width: 100%">
    		<thead>
    			<tr>
    				<th style="width: 60px;"><?php echo date($tpl['option_arr']['o_date_format'], strtotime($isoDate));?></th>
        			<?php
        			foreach ($tpl['employee_arr'] as $employee)
        			{
        				?><th style="width: 120px;"><?php echo pjSanitize::html($employee['name']); ?></th><?php
        			}
        			?>
    			</tr>
    		</thead>
    		<tbody>
    		<?php
    		foreach ($tpl['t_arr'][$isoDate] as $dateWT)
    		{
    		    $i = strtotime($isoDate . ' ' . $dateWT['start_time']);
    			?>
    			<tr>
    				<td style="width: 60px;"><?php echo date($tpl['option_arr']['o_time_format'], $i); ?></td>
    				<?php
    				foreach ($tpl['employee_arr'] as $employee)
    				{
    					$bookings = array();
    					if(isset($tpl['bs_arr'][$isoDate]))
    					{
    					    foreach ($tpl['bs_arr'][$isoDate] as $item)
        					{
        						if ($employee['id'] == $item['employee_id'] && $i >= $item['start_ts'] && $i < $item['start_ts'] + $item['total'] * 60)
        						{
        							$bookings[] = $item;
        						}
        					}
    					}
    					?><td style="width: 120px;"><?php
    					if (empty($bookings))
    					{
    						echo str_repeat('-', 3);
    					} else {
    						foreach ($bookings as $booking)
    						{
    							?>
    							<div>
    								<span class="bold"><?php echo pjSanitize::html($booking['c_name']); ?></span><br/>
    								<span class="fs11"><?php echo pjSanitize::html($booking['service_name']); ?></span>
    							</div>
    							<?php
    						}
    					}
    					?></td><?php
    				}
    				?>
    			</tr>
    			<?php
    		}
    		?>
    		</tbody>
    	</table>
    	<?php
	}
}
?>