Kinky Calendar Is Now An Official Kinky Solutions Project
I have just put the my Kinky ColdFusion Calendar system into my Kinky Solutions Projects. It comes complete with the code base and the Microsoft SQL Server build scripts. It only had two database tables, event and event_exception, but the SQL statements are so extremely simple that this ColdFusion calendar system should be usable on just about any database server including the dreaded Microsoft Access.
Please feel free to use and abuse it as you see fit; just let me know if you find any bugs or have any feedback on how the system could be improved. As far as integration goes, there really is no documentation or "best practices" since each application will have its own needs and driving forces. If you can suggest a better way to organize the code so that it could be more easily integrated, please let me know.
The code is not the cleanest code in the world, but I was not sure what best approach was when it comes to designing code that is meant to be used within the context of existing code.
Special thanks to Peter Bell who inspired me to actually get this Calendar system up and running.
Reader Comments
and that from it?
Awesome job Ben! This is great stuff. If I ever need something like this I'll definitely be implementing it. You did a great job with the UI. One of the things I love most about it.
nice job!
Thanks guys. Just hoping it helps some people :)
Just in case anyone wants it....
MySQL script for tables
-----------------------------------------------------
#
# Table structure for table 'event'
#
CREATE TABLE /*!32312 IF NOT EXISTS*/ `event` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL default '',
`description` longtext NOT NULL,
`date_started` date NOT NULL default '0000-00-00',
`date_ended` date default NULL,
`time_started` varchar(5) NOT NULL default '',
`time_ended` varchar(5) NOT NULL default '',
`is_all_day` tinyint(1) unsigned NOT NULL default '0',
`repeat_type` tinyint(2) unsigned NOT NULL default '0',
`color` varchar(6) NOT NULL default '',
`date_updated` datetime NOT NULL default '0000-00-00 00:00:00',
`date_created` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `IX_event_date_started` (`date_started`),
KEY `IX_event_date_ended` (`date_started`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
# Table structure for table 'event_exception'
#
CREATE TABLE /*!32312 IF NOT EXISTS*/ `event_exception` (
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`event_id` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`date`,`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-----------------------------------------------------
Then edit file 'includes/_functions.cfm' and replace all {e.[date]} with {e.date} (not the currly brackets though, d'oh!)
Not that anyone frequenting this site could not have also done that blindfolded, and even better than me.
@Kevin,
Awesome, thanks a lot for posting that. I don't know anything about MySQL, so this rocks.
No Problem. I noticed a few other places where [date] will (maybe depending on version & config) throw MySQL
-------------
I also had a question: in several of the scripts you do a switch / case of repeat_type (from the events table)
I was wondering if this was just old code never updated or if you were planning on doing a QoQ on REQUEST.RepeatTypes to get the name of the repeat_type. From first glance it looked like the repeat_type name lookups could be more efficient and central - unless you had a reason for it, then great!
I built a calendar a few years ago, but your concept of even series and the handling of repeat events is just sweet!
Just wondering... is there an admin of sorts? Or can anyone add an event w/o sometype of authentication?
@Kevin,
The repeat_types is an interesting thing. I put them into a query because there is nothing easier to loop over in ColdFusion and I use a Query-loop when I output the loop choice in the Add/Edit screen. However, when determining the repeat type, I think the CFSwitch statement is the best way to go - see, I don't really care about the name of the repeat type, just how it affects the date selection; I need it to be explicit. Even it was a query of queries, I am not sure that it would help - in fact, I am not even sure how I would do that.... but like I have said before, I am always open to suggestion. I am certainly not afraid of improving the system.
@Eric,
Right now, there is no Admin of any kind because this ColdFusion calendar system is meant to be a demonstration of calendar event scription and a "module" to be integrated into an existing application. There are a number of full fledged calendar systems out there alread - I think there is already 2 or 3 on http://www.riaforge.org already. If you really want a true calendar system, take a look at one of those. This system is meant to be taken a modified to fit whatever your needs are.
Would anyone have any interest in me bulking this out into a stand-alone app? I never intended to, and I am not sure it would have the functionality to compete with other stand-alone systems, but I am always game for more coding :)
Ben... go for it. The CF community could always use a new project on RIAForge. Good luck!
Ok, well, we'll see :) It's on the list... but that list is long ;)
I also have some ideas regarding the repeated code that actually builds the calendar table. Based on start and end dates, and the view parameter, we should be able to use just one file to actually draw the calendar, removing the need to have day, month, week, and year view files.
I used your code as a base for a client and it works sweet.
@Kevin,
I am not sure I exactly understand. Are you basically saying that you take a reoccurring event and create an event instance in the database for each of the reoccurring days?
Na, I mean the _day.cfm,_week.cfm, _month.cfm, _year.cfm can / should be just one file - they all do the same thing, just slightly different variations. all of these files draw the calendar. One file could do what all of them are doing without repeating the code to do it 4 times. Just an idea to make your rockin' calendar rock harder.
@Kevin,
I see what you are saying. I was thinking of doing something like that, but each has its own logic about what start / end day to use and how to calculate those. I suppose you could wrap it all up in to one file and then just use logic to chose which values to calculate.
Hi Ben,
Is there a way to show the event title once covering all the boxes of a date if the event is for multiple days.
For example. If an event "Test" starts at sep 5th and ends at Sep 8th.
Show the event title once with a color blocking the boxes of date from 5th to 8th. Instead of repeating the title "Test" for all the days separately.
@karthik,
There would certainly be a way to do this. What you would probably want to do is keep a struct of the event IDs that have been displayed so far. When you are going to display an event, you would use some code like this:
- check to see if event id is in struct (StructKeyExists)
- If exists
--- Do not show title
- Else does not exists
--- Add id to index
--- Show title
This way, the title will be shown only the first time that the event ID is encountered.
To make it even easier, you could encapsulate the above functionality into some sort of function that maintains the struct so that your page code only need something like this:
<cfif ShouldDisplayEventTitle( qEvent.ID )>
#qEvent.name#
</cfif>
In this case, ShouldDisplayEventTitle() takes the ID and then checks the "index" struct (adding to it when necessary) and then just returns the proper boolean value.
Back again to say this example has been a time saver many times. Maybe some day I'll post up my modifications.
I was thinking of a new feature and concept:
event dates vs repeat dates....
What if we had a two day long event, repeated every month, for example?
Just a thought, I don't have the answer :(
@Kevin,
I think that is absolutely the right idea. There should be a separation between the two date concerns. I bet that can't be too difficult to work out. I'll see if I can come up with anything. Thanks.
"I'll see if I can come up with anything"
I was going to just wait until client asks for it, then see if I can come up with anything :) You are way more motivated than me :)
Cool stuff, thanks
@Kevin Sargent: have you gotten time to "publish" your modifications yet? I'd love to see what you've come up with, as I'm venturing into the Kinky Calendar these days for a simple website setup. You've MySQL-script might be a life-saver - I've already bugged Ben about it but hadn't yet done a serach on his site - found it now, so Ben: disregard my first e-mail ;-)
@Ben: My question on security an modified interface still stands though! Is there a way to not have all visitors change the events? I can think of a simple login that sets a session variable which then is checked for rights to modify the event. But also a JS-popup or mouseover effect to show the deatils of the event.
Hope you guys have the time to look into my requests/questions ;-)
Hi Ben and Kevin,
I've found a small Day View bug using MySQL 5 in the latest build of Kinky Calendar. The story goes as follows:
I have an event that goes from 2nd of June 2008 until the 6th of June 2008. It repeats daily from 11:00 AM until 3:15 PM.
In MSSQL 2005 it shows as expected in the Day View (event with time, title, repeat, description) on all the 5 days.
But in MySQL 5 the above only shows on the 3rd, 4th and 5th of June, not on the 2nd or the 6th of June...
All's well for the other views by the way.
Ideas? Which date-logic do I modify?
@Sebastiaan,
That's an odd error. Can you look in the database and make sure that the start/end dates are storing *only* the dates and not a date/time stamp. The time part of that field should be zeroed out.
OK, so I deleted alle entries (was only one, which for some reason had gotten an exception added to it - an incorrect updateaction by me?) and entered a new one with the same data. I now have the following in the MySQL5 database:
date_started: 2008-06-02
date_ended: 2008-06-02
time_started: 11:00
time_ended: 15:15
repeat_type: 1
date_updated: timestamp
date_created: timestamp
It now shows correct in all views except for the day view. It does however now show the 2nd of june but not the sixth of june.
In MSSQL Server 2005 Express the date's have a time added to them (12:00:00 AM - date_started and date_ended) and the dateformat is AM/PM, whereas in MySQL it is 24h (in the fields date_updated and date_created). I've added ' 00:00:00' to the two fields (date_started and date_ended), but it didn't help. Any ideas?
Hi Ben,
I changed the CFSQLTYPE in '_functions.cfm' in the queries 'LOCAL.RawEvent' and 'LOCAL.EventException' from CF_SQL_TIMESTAMP to CF_SQL_DATE. Now the Day View works like a charm on both DB-platforms for this particular testcase.
I haven't done any more testing, but I'll let you know if the change should produce an error in other circumstances. It seems however to be the correct CF_SQL_TYPE to use as you don't want a time-compare.
Next step is to integrate some kind of security so as to let an editor change the events and normal people only show the event ;-)
@Sebastiaan,
Hmm, interesting. I will take another look at time logic. The data type should not matter.
Ben, this seems to be just the opposite problem of what you wrote about here:
www.bennadel.com/blog/8-CF_SQL_DATE-Issues-with-MS-SQL-Server-2005.htm
I've even commented on it there where I testify that changing the cfsqltype actually did the trick.
For me this works, and hopefully the change (if you choose to implement it of course - if it stands the test of testing) works across other DB-engines as well.
ben,
i try to get the calendar working..
i dont get the idea .. it allways trow an error:
Element DSN.SOURCE is undefined in REQUEST
ok easy as that .. searching thru the code where that variable should be defined.. nothing .. so i could set that .. but there musst be something fundamental wrong.
maybe i getting old and dont get it ;)
Roger
Ben
Thanks for this great little project. I tried emailing you separately asking this question - the ZIP file of this project contains no GNU or public license disclaimer. I am only using the UI front end for my own project, but I want to make sure that I comply with licensing. Can you confirm that this code is free to use without license limitations?