# This function prints a calendar using tables.
function RecentPage::lay_print_minicalendar() {
#var YearMonth m = $this->get_latest_month();
var YearMonth m = $this->get_latest_month();
var string currentmonth = $m->month_format();
"""
<!-- BEGIN CALENDAR -->
<div class="sidebox">
<h2>Kalendars</h2>
$currentmonth<br />
<table>
<tr><td colspan="7" style="text-align:center; font-weight:bold;">
""";
$this->get_latest_month();
"""
</td></tr>
""";
#generate NewMonth that will display weeks correctly from monday
var YearMonth NewMonth;
var int WeekNum = 0;
var int DayNum;
var int NewDayNum;
var int ii = 0;
foreach var YearWeek w ($m.weeks) {
if($w.pre_empty == 0)
{
$NewDayNum = 6;
}else
{
$NewDayNum = $w.pre_empty - 1;
}
foreach var YearDay d ($w.days) {
if($d.day > 0)
{
$NewMonth.weeks[$WeekNum].days[$ii] = $d;
}
$NewDayNum++;
$ii++;
if($NewDayNum >= 7)
{
if($WeekNum == 0)
{
$NewMonth.weeks[$WeekNum].pre_empty = 7 - $ii;
}else
{
$NewMonth.weeks[$WeekNum].post_empty = 7 - $ii;
}
$NewDayNum = 0;
$ii = 0;
$WeekNum++;
}
}
}
if($ii > 0)
{
$NewMonth.weeks[$WeekNum].post_empty = 7 - $ii;
}
#end of NewMonth generation
foreach var YearWeek w ($NewMonth.weeks) {
"<tr>";
if ($w.pre_empty) { "<td colspan='$w.pre_empty'><div class='calempty'></div></td>"; }
foreach var YearDay d ($w.days) {
if ($d.num_entries) {
"""<td class="calendarActive" >""";
"""<a href="$d.url">$d.day</a>""";
} else {
"""<td>""";
"<div class='calendarInactive'>$d.day</div>";
}
"</td>";
}
if ($w.post_empty) { "<td colspan='$w.post_empty'><div class='calempty'> </div></td>"; }
"</tr>";
}
"""
</table>
</div>
""";
}
function YearPage::print_month(YearMonth m) {
if (not $m.has_entries) { return; }
"""<table style="margin-left: 25%; margin-right: 25%; margin-top: 1em; margin-bottom: 1em;
border-collapse: collapse; border: 1px solid;" border="1">\n
<tr><th colspan="7" style="text-align: center; border: 1px solid;">""";
var YearMonth NewMonth;
var int WeekNum = 0;
var int DayNum;
var int NewDayNum;
var int ii = 0;
foreach var YearWeek w ($m.weeks) {
if($w.pre_empty == 0)
{
$NewDayNum = 6;
}else
{
$NewDayNum = $w.pre_empty - 1;
}
foreach var YearDay d ($w.days) {
if($d.day > 0)
{
$NewMonth.weeks[$WeekNum].days[$ii] = $d;
}
$NewDayNum++;
$ii++;
if($NewDayNum >= 7)
{
if($WeekNum == 0)
{
$NewMonth.weeks[$WeekNum].pre_empty = 7 - $ii;
}else
{
$NewMonth.weeks[$WeekNum].post_empty = 7 - $ii;
}
$NewDayNum = 0;
$ii = 0;
$WeekNum++;
}
}
}
if($ii > 0)
{
$NewMonth.weeks[$WeekNum].post_empty = 7 - $ii;
}
print $m->month_format();
"""</th></tr>\n""";
foreach var int d (weekdays()) {
"<th>"+$*lang_dayname_short[$d]+"</th>\n"
}
"</tr>\n";
$m.weeks[2] = $NewMonth.weeks[2];
foreach var YearWeek w ($NewMonth.weeks) {
if($w)
{
# $w->print();
# okay, this is nasty, but I get this strict refs error
# so instead of calling print method we'll just do it right here
"""<tr valign="top" style="height: 2em;">\n""";
if ($w.pre_empty > 0) {
"""<td class="emptyday" colspan="$w.pre_empty"> </td>\n""";
}
foreach var YearDay d ($w.days) {
"""<td style="border: 1px solid;">\n""";
"""<div style="text-align: right;">$d.day</div>\n""";
if ($d.num_entries > 0) {
"""<div style="text-align: center;"><a href="$d.url">$d.num_entries</a></div>\n"
}
"""</td>\n""";
}
if ($w.post_empty > 0) {
"""<td colspan="$w.post_empty"> </td>\n"""
}
"</tr>";
#end of w->print() simulation
}
}
"""<tr><td colspan="7" style="text-align: center; border: 1px solid;">
<a href="$m.url">$*text_view_month</a></td>
"</table>";
}