Revision [1984]

This is an old revision of GmBowenCalendar made by NilsLindenberg on 2004-10-25 18:17:32.

 

Calendar action

I thought that some of you might find this calendar a useful little action. I can't claim to have written it, just modified an open source calendar script I found so it works in Wikka. -- Mike

Example

The calendar action described on this page was added to Wikka version 1.1.5.4. Here's how it looks:
April 2024
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
<< = >>


Code:

The code has been modified some by JsnX, but it still has room for improvement. For example, the table background color is being set to a non-existent variable. This will be fixed before release. If any other bugs are spotted, please post them to this page or add a comment.

<?php
$month = (!isset($_GET['month'])) ? date("n",mktime()) : $_GET['month'];    
$year = (!isset($_GET['year'])) ? date("Y",mktime()) : $_GET['year'];
?>

<table bgcolor="<?php echo $style['tablebg']; ?>">
    <tr>
        <td valign="top">
<?php
    /*== get what weekday the first is on ==*/
    $tmpd = getdate(mktime(0,0,0,$month,1,$year));
    $monthname = $tmpd["month"];
    $firstwday= $tmpd["wday"];
    $lastday = mk_getLastDayofMonth($month,$year);
?>
<table cellpadding="2" cellspacing="0" border="1">
    <tr>
        <td colspan="7" bgcolor="<?php echo $style['tablebg']; ?>">
            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                <tr>
                    <td width="20"><a href="<?php echo $this->href("", "", "month="); echo (($month-1)<1) ? 12 : $month-1 ; ?>&amp;year=<?php echo (($month-1)<1) ? $year-1 : $year ; ?>">&lt;&lt;</a></td>
                    <td bgcolor="<?php echo $style['tablebg']; ?>" align="center"><font size="2"><?php echo "$monthname $year"; ?></font></td>
                    <td width="20"><a href="<?php echo $this->href("", "", "month="); echo (($month+1)>12) ? 1 : $month+1 ; ?>&amp;year=<?php echo (($month+1)>12) ? $year+1 : $year ; ?>">&gt;&gt;</a></td>
                </tr>
            </table>
      </td>
    </tr>
    <tr>
        <td width="22">Su</td>
        <td width="22">Mo</td>
        <td width="22">Tu</td>
        <td width="22">We</td>
        <td width="22">Th</td>
        <td width="22">Fr</td>
        <td width="22">Sa</td>
    </tr>
    <?php
    $day = 1;
    $wday = $firstwday;
    $firstweek = true;

    /*== loop through all the days of the month ==*/
    while ( $day <= $lastday)
    {
        /*== set up blank days for first week ==*/
        if ($firstweek) {
            print "    <tr>";
            for ($i=1; $i<=$firstwday; $i++)
            { print "        <td><font size=\"2\">&nbsp;</font></td>"; }
            $firstweek = false;
        }

        /*== Sunday start week with <tr> ==*/
        if ($wday==0) { print "    <tr>\n"; }

        /*== check for event ==*/
        print "        <td>";
        if($day<10) {
            if($month<10) {
                $tag = "$year:0$month:0$day";
            } else {
                $tag = "$year:$month:0$day";
            }
        } else {
            if($month<10) {
                $tag = "$year:0$month:$day";
            } else {
                $tag = "$year:$month:$day";
            }
        }
       
        $heute = date("Y:m:d",mktime());    // "01" bis "12"
        if($tag==$heute)
        {
            $font1 = "<font color=\"#FF0000\">";
            $font2 = "</font>";
        }
        else
        {
            $font1 = "";
            $font2 = "";
        }
        print "$font1$day$font2";
        print "</td>\n";

        /*== Saturday week with </tr> ==*/
        if ($wday==6) { print "    </tr>\n"; }

        $wday++;
        $wday = $wday % 7;
        $day++;
    }
?>
    </tr>
</table>
<br />
        </td>
    </tr>
</table>

<?php
/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{

for ($tday=28; $tday <= 31; $tday++)
{
    $tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
    if ($tdate["mon"] != $mon) break;
}

$tday--;
return $tday;

}

?>


"The <a> tags should be replaced with the appropriate function (JsnX, I think it's time to write some Coding Tips in the WikkaCore page ;))" .... I'm all for that. I don't have a clue why what I coded was inappropriate and would happily work at complying with what the overall wakka community is doing. -- Mike


CategoryDevelopment
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki