PHP Quick Calendar V2.4 Updates

* Thanks kirk for suggesting a bunch of changes. I have implemented quite a few – too wordy to describe them here. If you are interested, see the evolt comments that kirk837 has written.
* Added category to events. This impacted the code and query quite abit.
* Added sms and emailing capability. Email alert is straight forward. For sms, you have to add your own code. See cron.php
* Updated admin to include new features. The focus on admin area is still on the functionality. Will work on the look and feel later.
* Made further changes to filenames. Added new css for longdesc file.
* fixed hyperlink jumpiness problem. Removed the use of # as hyperlink.
* Used single quotation instead of double in some places. Not really necessary but good practice.
* Added new tiny calendar template.
* Added new complex calendar template. I attempted to combine different types of calendar together and did some tricks.
* This application is getting quite complicated now. I didn’t expect it to evolve till this stage. But… anyway, have fun.

PHP Quick Calendar V2.3 Updates MVC Implemented

17 Jan (Ver 2.3)
* Made changes to DB. There are different types of link now.
* Implemented full MVC architecture. Well, you can’t escape from not using for-loop but at least everything is more organised. That is why rendering calendar can be complicated. At least the view file looks manageable.
* Major rename of file names and re-organised folders.
* Mass cleanup of CSS in demos. Removed redundant CSS.
* Fixed fillArray logic. User can now start the week with anyday.
* Fixed typos and added comments.
* Updated admin area.
* Added a plain calendar.
* Updated multiple template.
* Still not very happy with the controller… Man, I wanted to stop but my fingers doesn’t allow me to!! Have fun guys.

Quick Calendar: Using Other DB Instead of MYSQL

Using other DB instead of MYSQ is straight forward because mysql built-in functions are only used in 3 areas. The SQL are not perculiar to MYSQL and should be compatible with any other DB.

1. In config.php (about line 20 to 27), change the mysql functions there, ie instead of ‘mysql_connect’, use ‘pg_connect’ for example.

2. In controller.php (about line 54 to 60), replace all mysql related function there.

3. In QCalendarBase.php (about line 109 to 115), replace all mysql related function there.

If you are already using a DB Abstraction Library (such as ADODB or PEAR_DB) in your current CMS, replacing these native mysql functions should be straight forward. I chose to use the native mysql functions for now because I don’t want to complicate the installation process. My philosophy is to not make PHP Quick Calendar depend on external libraries to work.

Creating Your Own Theme

1. Under themes, duplicate the skeleton theme and give a new theme name to the new directory created.

2. In view/calendar.css, replace all style name with .yourtheme.

3. In view/longdesc.css, replace all style name with .yourtheme_longdesc.

4. Change the class name in both model/Calendar.php and model/Longdesc.php to QCalendarYourtheme and LongdescYourtheme.

4. Now the big headache, add in the logic for the model (model/Calendar.php, model/Longdesc.php) and view (view/calendar.phtml, view/longdesc.phtml).

5. Have fun!

Software Architecture

Although the calendar is ajaxian, it is actually 90% PHP and 10% Ajax/Javascript. The core logic is written in PHP and Ajax just comes in to improve user experience. One of the main features of the calendar lies in its efficient method of creating the right date to populate the calendar cells. I wrote about how this is done in evolt.org

There are 2 important files that contain the core logic. Init.php and QCalendarBase.php.

init.php initialises the calendar and also acts like a controller for all incoming ajax request. It has a factory method that creates different calendar templates/theme based on user initialisation parameters.

QCalendarBase.php is the master template/theme file. It contains many commonly used functions for the calendar. All template classes inherits from this class.

The template classes are store under the ‘themes’ directory. Each template is a combination of the ‘Model’ and ‘View’ (MVC). I wanted to separate the view but come to think about it, rendering the view for the calendar still requires significant amount of programming as there would be some sort of looping involved. I suppose other programmers might want to implement the ‘View’ using a templating engine. This is open for discussion.

To customise the calendar, the only files that the user need to change are the template class and css files. At the moment, changing the template class still requires abit of programming skills though. I feel that I can still clean up the logic there abit to make the customisation easier.

Installing Quick Calendar

Installing the quick calendar is easy. Follow the steps below:

  1. Make sure your have LAMP running.
  2. If using PHP 4, need to have magic_quote off. Check that the php directive short_open_tag is 1 (editable via php.ini or .htaccess). The phpinfo() function reveals all your settings.
  3. Download the source code from here
  4. Unzip the downloaded code into a directory of your choice.
  5. Rename config.bak.php to config.php. Configure config.php with the right db and path details.
  6. There should be a sql file in the dowloaded code. Run the sql in your server to create the sample tables and data. You can of course empty the tables and populate with new data later.
  7. Lets try to insert a ‘small’ calendar. Paste the following code into the page where you want your calendar to appear:
  8. <?php
    require_once('path_to/controller.php');
    $cssCalendar= 'float:left;margin-right:30px;';
    $cssLongDesc='float:left;margin-left:50px;width:400px';
    // configure calendar theme
    initQCalendar('small','qCalendarSmall', $cssCalendar, 'myContentSmall', $cssLongDesc, 0,0,0,0,0);
    ?>

    make sure the 'path_to' is the system path to your quick calendar directory.

  9. If you want to customise the calendar, you need to have the right parameters for the initQCalendar() function depending on the theme you choose:

  10. initQCalendar(theme, divCalendar, calendarCss, divLongDesc, longDescCss, day, month, year, category_id, ajax)

    where

    'theme': name of the theme you want to use. It is the directory name under the themes directory.

    'divCalendar': name of the div you want to use to wrap around the calendar.

    'calendarCSS': CSS for DivCalendar above.

    'divLongDesc': name of the div where you want the long description to populate. This can be a new div or an existing one in the page. If it is a new div, you need to create one as shown in the sample above.

    'longDescCss': CSS for the Long Description.

    'day': current day. Leave 0 as the default.

    'month': current month. Leave 0 as the default.

    'year': current year. Leave 0 as the default.

    'category_id': 0 means show all categories.

    'ajax': Determines if this is an ajax call or not. Leave 0 as the default.

  11. That’s it. The best way to learn is to look at the demos. Duplicate the theme in the demo and play around.