Sunday, May 20, 2007

PHP Calendar

I recently decided to update the Important events section of my website. I knew I wanted a full 12-month calendar view for the current year and I also didn't want to spend much time working on this project. So I chose the path of least resistance and found a great open source freeware calendar called PHP Calendar. PHP Calendar Class Version 1.4 was written by David Wilkinson in 2001. It is very lightweight (one PHP file) and flexible. This made it a breeze to integrate into my website;

Here is an image of the Important events layout before any changes were made:

Here is PHP code (this example is also on the PHP Calendar website) to generate a month view for the current month (May 2007 at the time of this post):

    <?

      // Get current month calendar view
      include('calendar.php');
      $c = new Calendar;
      echo $c->getCurrentMonthView();

    ?>


This code produces the resulting HTML:

One nice feature of this calendar is the ability to set a link for a given day in the month. I used this feature to connect my personal events to the calendar. Here is an example of setting a link on the full year calendar for January 1, 2007:

    <?
      include('calendar.php');

      class MyCalendar extends Calendar
      {
        function getDateLink($day, $month, $year)
        {
          // link January 1 of the current year
          $link = "";
          if ($day == 1 && $month == 1)
            $link = "myLink.php";
          return $link;

        }
      }

      $c = new MyCalendar;
      echo $c->getCurrentYearView();

    ?>


Here is the HTML output of the above code:


This is the final version of my Important events website section:

No comments:

 

blogger templates | Make Money Online