Google analytics code

Tuesday, October 19, 2010

PHP: bCalendar - Free PHP calendar with international support

I've been working on a calendar class for awhile now and I've decided to release it to the public. I've refactored the class quite a bit so the names and methods make since. It's PHP5 compatible, very skinable, supports multiple languages and comes with documentation. You can download the project here.

Here is a quick example of how to set it up. You can view a running copy here.
// Update the language by using setLocal
//setlocale(LC_ALL, 'Japanese');

// Include the calendar class
include_once "classes/class.bCalendar.php";

// Create the class. The first option is the URL the navigation will use. The second is the path to the css file. The third is the date for the calendar to start on. The last determines which day the calendar will start on.
$obj_cal = new bCalendar("index.php","css/calStyle.css", null, 1);

####################
# Optional methods
####################
// Set the range of the date picker combobox
$obj_cal->setComboboxYearRange(2000,2010);

// Add a date to the calendar
$obj_cal->addEvent("10/19/2010", "This is a test event");

// Link a date on the calendar to a url
$obj_cal->linkDate("10/15/2010", "http://google.com");

// Change the behavior of the date picker to not snap to the current date
$obj_cal->setComboBoxToCurrentDate(false);

// Change the order of the calendar header
$obj_cal->setCalendarHeader(array(bCalendar::CAL_PREVIOUS_MONTH,
                                     bCalendar::CAL_MONTH_YEAR,
                                     bCalendar::CAL_SELECTOR,
                                     bCalendar::CAL_NEXT_MONTH));
####################
# Optional methods
####################

// Draw the calendar
$obj_cal->drawCalendar();

There are other properties that control the formatting of the month, year and day on the display. Those are outlined in the documentation under Variable Summary. If you have any questions of feedback please let me know in the comments. Also if you use it in a project let me know. It would be cool to see how people use it.

1 comment:

If you found this page useful, or you have any feedback, please leave a comment.