I'm currently in the process of creating a online work schedule for internal use. For this, the client needs to show the days of a single week.
I pass a week number and a year.
From that I get the first day of that week, by using strtotime()
passing an argument in the format [year]-W[weekno]-[dayofweek]
. Example: strtotime('2011-48W-1');
With that function I create my table as mentioned earlier:
<table class="weekly">
<thead>
<tr>
<?php for($i = 1; $i <= 7; $i++): ?>
<th><?php echo $dage[$i] . " ". date("j/m", strtotime($year.'-W'.$week.'-'.$i)); ?></th>
<?php endfor; ?>
</tr>
</thead>
<tbody>
<tr>
<?php for($i = 1; $i <= 7; $i++): ?>
<td<?php if($i == 7) { echo ' class="last"'; } ?>>
<?php
$day = date("Y-m-d", strtotime($year.'-W'.$week.'-'.$i));
if(isset($entries[$day])):
foreach($entries[$day] as $entry):
?>
<div class="workEntry" title="<?php echo $entry->note; ?>">
<span>
<?php echo date("H:i", strtotime($entry->workStart)); ?>
<?php if($entry->workStart != "0000-00-00 00:00:00") { echo " - ".date("H:i", strtotime($entry->workEnd)); } ?>
</span>
<span>
<?php if($entry->userId == 0): ?>
Unspecifed
<?php else: ?>
<?php echo $entry->name; ?>, <?php echo $entry->pgroup; ?>
<?php endif; ?>
</span>
</div>
<?php endforeach;
endif; ?>
</td>
<?php endfor; ?>
</tr>
</tbody>
</table>
Well, it works, but I'm pretty sure that I'm reinventing the wheel, and doing a pretty bad job at it too. I'd like to know what you think and to hear any suggestions.