Revision [2699]

This is an old revision of GmBowenCalendar made by JavaWoman on 2004-11-30 21:10:30.

 

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        
<< = >>


You can control the appearance of the calendar by modifying the stylesheet and adding a calendar style. For example:
.calendar
{
	background-color: teal;
	color: white;
}
.calendar .currentday {color: yellow;}


Code:

The code has been modified some by JsnX, but it still has room for improvement.

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

<table class="calendar">
    <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">
            <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 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)
        {
            print "<span class='currentday'>$day</span>";
        }
        else
        {
           print "$day";
        }
        print "</td>\n";

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

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

<?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

My variant of this Calendar action is now ready - explanations (lots) and code on JwCalendar. Not just "cleaned up" but with extended functionality and internationalization-ready (in fact, mostly done!), while it still does all yours does. :) --JavaWoman.
Wow....what an incredible amount of work....nice job JW. I'm going to have to start this Scheduler Project all over aren't I?? (to keep the code base coherent) Sigh (grin). -- Mike
Thanks, Mike! Actually, I think you'll see that with the code organization as I'm explaining in "A pattern for an action" it's easier to extend and maintain. And if you make another action, try following that coding pattern, too. --JavaWoman



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