<?php
/**Display an html calendar.
* Used within pages and/or through javascript.
*
* @version 2.1.4
* @since 2.0 Aug 6, 2008
* @package kwalbum
*/
require_once 'include/DBConnection.php';
$DB = new DBConnection();
if (!empty($G['monthOffset']))
$time = strtotime($G['monthOffset'].' month');
else
if (!empty($G['year']) and !empty($G['month']))
$time = strtotime($G['month'].' '.(int)$G['year']);
else
$time = time();
$month = date('m', $time);
$year = date('Y', $time);
$currentDay = 1;
$daysInMonth = date('t', $time);
$firstDay = date('w', mktime(0, 0, 0, $month, 1, $year));
$dayOfWeek = 0;
$query = 'SELECT count(*) FROM '.ITEM_TABLE.
" WHERE ItemOrderBy >= '$year-$month-00 00:00:00' AND ItemOrderBy <= '$year-$month-32 23:59:59'";
$result = $DB->Query($query);
if (0 < $result->num_rows)
$row = $result->fetch_array();
else
$row[0] = 0;
?>
<table border='1'>
<tr><th colspan='7'><?=($row[0] > 0 ? "<a href='".PAGE_URL."date=$year-$month-00'>".date('F Y', $time)." ($row[0] item".($row[0] > 1 ? 's' : null).")</a>" : date('F Y', $time))?></th></tr>
<tr>
<td class='calDay'><small>Sunday</small></td>
<td class='calDay'><small>Monday</small></td>
<td class='calDay'><small>Tuesday</small></td>
<td class='calDay'><small>Wednesday</small></td>
<td class='calDay'><small>Thursday</small></td>
<td class='calDay'><small>Friday</small></td>
<td class='calDay'><small>Saturday</small></td></tr>
<?
$blank = true;
while ($currentDay <= $daysInMonth or 0 != $dayOfWeek % 7)
{
if (0 == $dayOfWeek % 7)
echo '<tr>';
if (true == $blank and $dayOfWeek != $firstDay)
{
echo '<td> </td>';
}
else
{
$blank = false;
$date = date('Y-m-d', mktime(0, 0, 0, $month, $currentDay, $year));
$query = 'SELECT count(*)' .
' FROM ' . ITEM_TABLE .
" WHERE ItemOrderBy>='".$date." 00:00:00' AND ItemOrderBy<='".$date." 23:59:59'".(USER_CAN_VIEW_QUERY ? ' AND '.USER_CAN_VIEW_QUERY : null);
$result = $DB->Query($query);
$row = $result->fetch_array();
$numItems = $row[0];
if (0 == $numItems)
$dayLink = '';
else
$dayLink = "<a href='".PAGE_URL."date=$date'>$numItems item".($numItems > 1 ? 's' : null)."</a>";
echo "<td>$currentDay<br/> $dayLink</td>";
if ($currentDay == $daysInMonth)
$blank = true;
$currentDay++;
}
if (6 == $dayOfWeek % 7)
echo '</tr>';
$dayOfWeek++;
}
?>
</table>