Simple calendar/availability calendar

5 posts by 3 authors in: Forums > CMS Builder
Last Post: July 31, 2013   (RSS)

By Kittybiccy - July 30, 2013

I'm working on a small site for a holiday rental and want to have a calendar to show when the property is/isn't available. I'd like to do this simply, by the background colour of the cell being different when unavailable. Any ideas how I could do this?

I'd need the dates/months to be auto generated somehow.

Thanks in advance!
Hannah

By gregThomas - July 30, 2013

Hi Hannah,

There are a lot of great resources on how to create a PHP calenders on the net, in the past I've used this tutorial by David Walsh to get started:

http://davidwalsh.name/php-event-calendar

I've also integrated full Calendar into a site before, although this can actually be more complicated that creating something custom sometimes 

http://arshaw.com/fullcalendar/

Cheers

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Kittybiccy - July 31, 2013

Thanks Greg!

If I were to go with the full calendar version, so that site visitors could click through the months and check the availability of the rental, how would I then link in the CMS/how would you suggest the records work there?

Hannah

By gregThomas - July 31, 2013

Hi Hannah,

A calender system has been bought to my attention in another post created by Zick, you can find the code here:

http://www.interactivetools.com/forum/forum-posts.php?Calendar-populated-with-CMS-Builder-records-71673

and an example of the finished script here:

http://thecmsbcookbook.com/calendar5.php

If you wanted to use the fullcalender system you'd have to use the ajax system to display the data from CMS Builder. If you download the latest copy of the plugin from here:

http://arshaw.com/fullcalendar/download/

There is a demo called json.html, that you can use, to get it to display events from my blog section I modified the json-events.php file to this:

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('C:/wamp/www/test/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  $ajaxEvents = array();

  foreach($blogRecords as $key => $blog){

   $ajaxEvents[$key]['id'] = $key;
   $ajaxEvents[$key]['title'] = $blog['title'];
   $ajaxEvents[$key]['start'] = date('Y-m-d', strtotime($blog['createdDate']));
   $ajaxEvents[$key]['end']   = date('Y-m-d', strtotime($blog['createdDate']));
   $ajaxEvents[$key]['url'] = $blog['createdDate'];
  }

  echo json_encode($ajaxEvents);

This is just example code, so you'll have to make some changes to get it working with your site. Specifically the tableName that is used to retrieve data, and the date field that you want displaying on the calendar.

So this script will loop through all of my blog posts and create an array item for each record. In this case it's using the createdDate, but you could use any date field. 

After all of the event items have been created the json_encode function is used to return a json encoded array of items, which the json.html page then uses to display the calendar items.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com