Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100 off


PHP Tutorials and Scripts   




Title: Active Calendar    Marked Cool    (Review this resource)
Author: georgiost
Posted On: 2004-11-27
Category: Home > PHP Classes

Popularity: 2 points out of 10    

Description: A PHP class that generates calendars (month or year view) as HTML tables (XHTML-Valid). It can produce static calendars without any links or calendars with navigation controls, a date picker control, event days with content and event URLs, and linkable days (optionally URL or Javascript).

Total Hits: 3661     Total Votes: 6     Total Points: 28 (7 reviews)        [ Download ]   

Page Navigation:  [1]


Active Calendar Class v1.0 Documentation


The source code included in this package is free. You can modify or pass it on under the conditions of the GNU Lesser General Public License, published by the Free Software Foundation.
I would appreciate any comments or suggestions.

Contents

About Active Calendar Class

Active Calendar is PHP Class, that generates calendars (month or year view) as a HTML Table (XHTML-Valid).

    The calendars created by this class:
  • can be static (without any links)
  • can optionally have navigation controls
  • can optionally have a date picker control
  • can optionally have linkable days (url or javascript)
  • can optionally have 'event days' with 'event links'
  • can optionally have 'event content' with 'links'
  • support month and day names, depending on your language
  • can be configured using CSS
  • do not require Javascript to be displayed or navigated (server side generation)
  • can be generated with just 2-3 lines of code

Active Calendar is based on the PHP native date functions (default) and supports optionally the ADOdb Date Library.

    Supported dates (on systems using a 32-bit signed integer Unix time_t):
  • Using PHP native date functions: 1902 - 2037 (UNIX) and 1971 - 2037 (Windows)
  • Using ADOdb Date Library: 100 - 3000 and later [ limited by the computation time of adodb_mktime() ] on both UNIX and Windows. To use the ADOdb Date Library just include it in your scripts. The Active Calendar class will use the library functions automatically.

How to use the Active Calendar Class

Class methods overview:

    $cal = new activeCalendar([$year,$month,$day]);
    Create first a new object of the class. The parameters $year, $month and $day are optional. If these parameters are not set, the current year, month and day will be passed to the program. The parameter $year should have the form "yyyy" e.g "2005" or "1996", the parameter $month should have the form "m" e.g "1" for January or "10" for October and the parameter $day should have the form "d" e.g "4" for the 4th month day or "24" for the 24th month day. So for the date e.g 7th January 2005 please set $cal = new activeCalendar("2005","1","7").

    $cal->enableMonthNav([$link,$arrowBack,$arrowForw]);
    Call this method, if you want the generated calendar to have month navigation controls (e.g "previous month" and "next month"). The parameter $link is optional. You can use this parameter to set the url for the calendar links (e.g "mycalendar.php" or "mycalendar.php?mode=4&item=test", if you need more complex urls). You should modify the private method mkUrl(), if you want to change the general structure of the generated links. The parameters $arrowBack and $arrowForw are optional as well: they set other month navigation controls, than the ones set in the configuration (an image link can be set too).

    $cal->enableYearNav([$link,$arrowBack,$arrowForw]);
    Call this method, if you want the generated calendar to have year navigation controls (e.g "previous year" and "next year"). The parameter $link is optional. You can use this parameter to set the url for the calendar links (e.g "mycalendar.php" or "mycalendar.php?mode=4&item=test", if you need more complex urls). You should modify the private method mkUrl(), if you want to change the general structure of the generated links. The parameters $arrowBack and $arrowForw are optional as well: they set other year navigation controls, than the ones set in the configuration (an image link can be set too).

    $cal->enableDatePicker([$startYear,$endYear,$link,$button]);
    Call this method, if you want the generated month calendar to have a date picker control. The parameters $startYear and $endYear define the range of the years, that can be selected (e.g $startYear=2000, $endYear=2010). This range is limited by the private class variables $startYear and $endYear. Please modify them according to your configuration. The parameter $link is optional. You can use this parameter to set the url for the calendar links (e.g "mycalendar.php" or "mycalendar.php?mode=4&item=test", if you need more complex urls). You should modify the private method mkUrl(), if you want to change the general structure of the generated links. The parameter $button is optional as well: it sets some other value for the date picker submit button, than the one set in the configuration.

    $cal->enableDayLinks([$link,$javaScript]);
    Call this method, if you want the generated calendar to have linkable dates. The parameter $link is optional. You can use this parameter to set the url for the calendar links (e.g "mycalendar.php" or "mycalendar.php?mode=4&item=test", if you need more complex urls). You should modify the private method mkUrl(), if you want to change the general structure of the generated links. The parameter $javaScript is optional as well. You can use this parameter to set a JavaScript function instead of an url for the calendar links. So if you set $cal->enableDayLinks(false,"selectDate"), this link will be created on e.g 27 May 2007: ..href="javascript:selectDate(2007,5,27)".. The content of the Javascript function 'selectDate' will not be created by the class. You should develop it according to your needs.

    $cal->setMonthNames($monthNamesArray);
    Call this method, if you want the class generate different names for the calendar months, than the ones set in the configuration. The parameter $monthNamesArray must be an array of 12 month names starting with January.

    $cal->setDayNames($dayNamesArray);
    Call this method, if you want the class generate different names for the calendar weekdays, than the ones set in the configuration. The parameter $dayNamesArray must be an array of 7 day names starting with Sunday.

    $cal->setEvent($year,$month,$day,[$id,$eventUrl]);
    Call this method, if you want the class to create an HTML td class=$id on the date specified by the parameters $year, $month, $day. You can configure every 'event date' in your CSS, so that it would have e.g a different background color. The parameter $id is optional. If you do not set an $id, a default HTML class='event' will be generated. The parameter $eventUrl is optional as well: If you set an $eventUrl, an event specific link (..href='$eventUrl'..) will be generated on the 'event date', even if the method $cal->enableDayLinks($link) was not called.

    $cal->setEventContent($year,$month,$day,$content,[$contentUrl]);
    Call this method, if you want the class to create a new HTML table within the date specified by the parameters $year, $month, $day. The parameter $content can be a string or an array. If $content is a string, then the new generated table will contain one row with the value of $content. If it is an array, the generated table will contain as many rows as the array length and each row will contain the value of each array item. The parameter $contentUrl is optional: If you set a $contentUrl, an event content specific link (..href='$contentUrl'..) will be generated in the 'event content' table row(s), even if the method $cal->enableDayLinks($link) was not called.

    $cal->showMonth();
    This method will generate the html string of the month calendar. You can display the calendar by "print $cal->showMonth()". This method calls several private class functions, that create each tr tag of the generated table. So if you would like to change the table structure, you could simply modifiy the order, that these private functions are called (mkMonthHead() must remain first and mkMonthFoot() must remain last though).

    $cal->showYear([$columns]);
    This method will generate the html string of the year calendar. You can display the calendar by "print $cal->showYear()". This method calls several private class functions, that create each tr tag of the generated table. So if you would like to change the table structure, you could simply modify the order, that these private functions are called (mkYearHead() must remain first and mkYearFoot() must remain last though). The parameter $columns is optional: it sets the number of the generated months in each row of the year calendar (default: 4).

Code Examples:

    Current month static calendar
    <?php
    include("activecalendar.php");
    $cal = new activeCalendar();
    echo $cal->showMonth();
    ?>

    Current month calendar with navigation
    <?php
    include("activecalendar.php");
    $myurl=$_SERVER['PHP_SELF']; // the links url is this page
    $yearID=false; // init false to display current year
    $monthID=false; // init false to display current month
    $dayID=false; // init false to display current day
    extract($_GET); // get the new values (if any) of $yearID,$monthID,$dayID
    $cal = new activeCalendar($yearID,$monthID,$dayID);
    $cal->enableMonthNav($myurl);
    echo $cal->showMonth();
    ?>

    Current month calendar with date picker (year range: 2000-2010)
    <?php
    include("activecalendar.php");
    $myurl=$_SERVER['PHP_SELF']; // the links url is this page
    $yearID=false; // init false to display current year
    $monthID=false; // init false to display current month
    $dayID=false; // init false to display current day
    extract($_GET); // get the new values (if any) of $yearID,$monthID,$dayID
    $cal = new activeCalendar($yearID,$monthID,$dayID);
    $cal->enableDatePicker(2000,2010,$myurl);
    echo $cal->showMonth();
    ?>

    Month calendar (November 2007) with day links
    <?php
    include("activecalendar.php");
    $myurl=$_SERVER['PHP_SELF']; // the links url is this page
    $cal = new activeCalendar("2007","11");
    $cal->enableDayLinks($myurl);
    echo $cal->showMonth();
    ?>

    Month calendar (November 2007) with multiple 'event days'
    <?php
    include("activecalendar.php");
    $cal = new activeCalendar("2007","11");
    $cal->setEvent("2007","11","17","meeting"); //it will create a class="meeting"
    $cal->setEvent("2007","11","7","birthday"); //it will create a class="birthday"
    //The following will create a class="myevent" and an <a href="myevent.html">
    $cal->setEvent("2007","11","20","myevent","myevent.html");
    echo $cal->showMonth();
    ?>

    Current year static calendar with 2 months in each row
    <?php
    include("activecalendar.php");
    $cal = new activeCalendar();
    echo $cal->showYear(2); // 2 months in each row
    ?>

    Current year calendar with navigation
    <?php
    include("activecalendar.php");
    $myurl=$_SERVER['PHP_SELF']; // the links url is this page
    $yearID=false; // init false to display current year
    $monthID=false; // init false to display current month
    $dayID=false; // init false to display current day
    extract($_GET); // get the new values (if any) of $yearID,$monthID,$dayID
    $cal = new activeCalendar($yearID,$monthID,$dayID);
    $cal->enableYearNav($myurl);
    echo $cal->showYear();
    ?>

    Year calendar (2007) with day links
    <?php
    include("activecalendar.php");
    $myurl=$_SERVER['PHP_SELF']; // the links url is this page
    $cal = new activeCalendar("2007");
    $cal->enableDayLinks($myurl);
    echo $cal->showYear();
    ?>

    Year calendar (2007) with multiple 'event days'
    <?php
    include("activecalendar.php");
    $cal = new activeCalendar("2007");
    $cal->setEvent("2007","1","24","meeting");
    $cal->setEvent("2007","5","12","birthday");
    $cal->setEvent("2007","6","24","event");
    $cal->setEvent("2007","6","25");
    echo $cal->showYear();
    ?>

    Year calendar (2007) with multiple 'event contents'
    <?php
    include("activecalendar.php");
    $cal = new activeCalendar("2007");
    $cal->setEventContent("2007","1","24","meeting");
    $cal->setEventContent("2007","5","12","birthday");
    $cal->setEventContent("2007","6","24","Google","http://www.google.com");
    $multipleLinesEvent=array("Title: News","Time: 16.00","Status: ok"); $cal->setEventContent("2007","6","25",$multipleLinesEvent);
    echo $cal->showYear();
    ?>

Calendar layout:

    The layout of the generated calendar can be configured with CSS. The Active Calendar Class returns html tags with various classes, which can be used for the layout configuration. Please check the following sample css (that uses the default configuration):

    .year {border-style: outset; border-width: 1px; background-color: #cbeaca; text-align: center;}
    .month {border-style: none; background-color: #cbeaca; text-align: center;}
    .yearname {text-align: center; font-size: 20px; font-weight: bold;}
    .monthname {text-align: center; font-size: 13px; height: 30px; background-color: #e9e9e9;}
    .yearnavigation {background-color: #dddddd;}
    .monthnavigation {background-color: #dddddd;}
    .datepicker {background-color: #ffffff;}
    .datepickerform {margin: 0px;}
    .monthpicker {background-color: #eeeeee;}
    .yearpicker {background-color: #eeeeee;}
    .pickerbutton {background-color: #eeeeee; border-style: none;}
    .dayname td {text-align: center; font-size: 13px; background-color: #dddddd;}
    .nomonthday {background-color: #cbeaca; height:25px; width:25px;}
    .monthday {text-align: center; background-color: #e9e9e9; height:25px; width:25px;}
    .today {text-align: center; background-color: #ffff99; height:25px; width:25px;}
    .selectedday {text-align: center; background-color: #66ff66; height:25px; width:25px;}
    .sunday {text-align: center; font-weight: bold; color: red; height:20px; width:20px;}
    .sunday a {color: red;}
    .saturday {text-align: center; font-weight: bold; color: red; height:20px; width:20px;}
    .saturday a {color: red;}
    .event {text-align: center; color: red; background-color: #ffff99; height:20px; width:20px;}
    .event a {background-color: #ffff99; color: red;}
    .selectedevent {text-align: center; color: red; background-color: #ffff99; height:20px; width:20px;}
    .selectedevent a {background-color: #ffff99; color: red;}
    .todayevent {text-align: center; color: red; background-color: #ffff99; height:20px; width:20px;}
    .todayevent a {background-color: #ffff99; color: red;}
    .eventcontent {font-size: 10px; border-style: outset; border-width: 1px;}

    Here is a table with the classes of the html tags, generated by the Active Calendar Class and their configuration variables. To avoid conflicts with your existing CSS, the names of the generated classes can be changed in the Active Calendar class configuration.
    Configuration variableHTML ClassHTML TAG
    $cssYearTableyeartable tag: calendar year
    $cssYearTitleyearnametd tag: calendar year title
    $cssYearNavyearnavigationtd tag: calendar year navigation
    $cssMonthTablemonthtable tag: calendar month
    $cssMonthTitlemonthnametd tag: calendar month title
    $cssMonthNavmonthnavigationtd tag: calendar month navigation
    $cssWeekDaydaynametr tag: calendar weekdays
    $cssPickerdatepickertd tag: date picker
    $cssPickerFormdatepickerformform tag: date picker form
    $cssPickerMonthmonthpickerselect tag: month picker
    $cssPickerYearyearpickerselect tag: year picker
    $cssPickerButtonpickerbuttoninput (submit) tag: date picker button
    $cssMonthDaymonthdaytd tag: days, that belong to the current month
    $cssNoMonthDaynomonthdaytd tag: days, that do not belong to the current month
    $cssTodaytodaytd tag: the current day
    $cssSelecDayselecteddaytd tag: the selected day
    $cssSundaysundaytd tag: all Sundays
    $cssSaturdaysaturdaytd tag: all Saturdays
    $cssEventeventtd tag: Event day set by setEvent(). Multiple classes can be generated (e.g 'meeting')
    $cssPrefixSelecEventselectedtd tag: Event day set by setEvent(), when it is selected. This prefix will be added to the event class name (e.g 'selectedevent'). Multiple classes (e.g 'selectedmeeting') can be generated
    $cssPrefixTodayEventtodaytd tag: Event day set by setEvent(), when it is the current day. This prefix will be added to the event class name (e.g 'todayevent'). Multiple classes (e.g 'todaymeeting') can be generated
    $cssEventContenteventcontenttable tag : event content

Quick installation

1. Edit the configuration section in Active Calendar Class file activecalendar.php, if you want to change the default configuration.

    The following public variables can be modified:
  • ********* Month names *********
    [This is just the default configuration. You may set the month names by calling the method setMonthNames()]
  • var $jan = "Name to display for January";
  • var $feb = "Name to display for February";
  • var $mar = "Name to display for March";
  • var $apr = "Name to display for April";
  • var $may = "Name to display for May";
  • var $jun = "Name to display for June";
  • var $jul = "Name to display for July";
  • var $aug = "Name to display for August";
  • var $sep = "Name to display for September";
  • var $oct = "Name to display for October";
  • var $nov = "Name to display for November";
  • var $dec = "Name to display for December";
  • ******** Weekday names ********
    [This is just the default configuration. You may set the day names by calling the method setDayNames()]
  • var $sun = "Name to display for Sunday";
  • var $mon = "Name to display for Monday";
  • var $tue = "Name to display for Tuesday";
  • var $wed = "Name to display for Wednesday";
  • var $thu = "Name to display for Thursday";
  • var $fri = "Name to display for Friday";
  • var $sat = "Name to display for Saturday";
  • ****** Navigation controls ******
    [This is just the default configuration. You may set the controls by calling the methods enableYearNav(), enableMonthNav() and enableDatePicker()]
  • var $yearNavBack = "Previus year control (it could be an image link e.g.:<img src=\"leftarrow.gif\">";
  • var $yearNavForw = "Next year control (it could be an image link e.g.:<img src=\"rightarrow.gif\">";
  • var $monthNavBack = "Previus month control (it could be an image link e.g.:<img src=\"leftarrow.gif\">";
  • var $monthNavForw = "Next month control (it could be an image link e.g.:<img src=\"rightarrow.gif\">";
  • var $selBtn = "Date picker button value";
  • ****** Day links variables ******
  • var $yearID = "Name of the year GET VARIABLE for the links";
  • var $monthID = "Name of the month GET VARIABLE for the links";
  • var $dayID = "Name of the day GET VARIABLE for the links";
  • ******** Monthview display ********
  • var $monthYearDivider = "Divider between month and year in the month`s title e.g '/'";
  • var $startOnSun = "True: first day of week is Sunday, False: first day of week is Monday";
  • var $crSunClass = "True: creates a HTML class 'sunday' on every Sunday";
  • var $crSatClass = "True: creates a HTML class 'saturday' on every Saturday";
  • ******** Yearview display ********
  • var $rowCount = "Number of months in a row in yearview";
    [This is just the default configuration. You may set the number of months in a row by calling the method showYear()]

  • You should leave the other variables in the class file unchanged.

2. Upload the Active Calendar Class file activecalendar.php on your server and include it in your scripts.


(c) Giorgos Tsiledakis, Crete Greece



Page Navigation:  [1]



© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.