[Php-calendar-discussion] Fix for adding weekend only and weekday only events
Brought to you by:
sproctor
From: Steve <the...@gm...> - 2006-06-05 05:56:27
|
Hi. I downloaded PHP Calendar for a way for my business partner and I to communicate dates between eachother, but after playing with it for a few minutes, I realized there wasnt a feature for weekend only and weekday only events, and the TODO list requested it. So I added to it after spending a good half hour navigating the code. This is my first code contrubution to any open source community, and it was a real quick fix. I modified two files. The first was globals.php starting on line 73. The definition for $event_types should read as follows: $event_types = array( 1 => _('Normal'), _('Full Day'), _('To Be Announced'), _('No Time'), _('Weekly'), _('Monthly'), _('Weekdays'), _('Weekends') ); The second file is calendar.php starting on line 264. The definition for function get_events_by_date() should read as follows: function get_events_by_date($day, $month, $year) { global $calendar_name, $db; /* event types: 1 - Normal event 2 - full day event 3 - unknown time event 4 - reserved 5 - weekly event 6 - monthly event 7 - weeday only 8 - weekend only */ $startdate = $db->SQLDate('Y-m-d', 'startdate'); $enddate = $db->SQLDate('Y-m-d', 'enddate'); $date = "DATE '" . date('Y-m-d', mktime(0, 0, 0, $month, $day, $year)) . "'"; $dayofweek = date("D", mktime(0, 0, 0, $month, $day, $year)); // day of week $dow_startdate = $db->SQLDate('w', 'startdate'); $dow_date = $db->SQLDate('w', $date); // day of month $dom_startdate = $db->SQLDate('d', 'startdate'); $dom_date = $db->SQLDate('d', $date); $query = 'SELECT * FROM '.SQL_PREFIX."events\n" ."WHERE $date >= $startdate AND $date <= $enddate\n" // find normal events ."AND (eventtype = 1 OR eventtype = 2 OR eventtype = 3 " ."OR eventtype = 4\n" // find weekly events ."OR (eventtype = 5 AND $dow_startdate = $dow_date)\n" // find monthly events ."OR (eventtype = 6 AND $dom_startdate = $dom_date)\n" // find weeday events ."OR (eventtype = 7 AND ('$dayofweek' != 'Sat' AND '$dayofweek' != 'Sun'))\n" // find weekend events ."OR (eventtype = 8 AND ('$dayofweek' = 'Sat' OR '$dayofweek' = 'Sun'))\n" .")\n" // in the current calendar ."AND calendar = '$calendar_name'\n" ."ORDER BY starttime"; $result = $db->Execute($query) or db_error(_('Error in get_events_by_date'), $query); return $result; } I hope this helps or, if I forgot something, someone can point out a bug or two. Thanks, Steve Massey |