Skip to content

Instantly share code, notes, and snippets.

@franz-isx
Created May 15, 2012 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franz-isx/2702378 to your computer and use it in GitHub Desktop.
Save franz-isx/2702378 to your computer and use it in GitHub Desktop.
iCal Holiday import for TeamCal for non whole day events
Index: holidays.php
===================================================================
--- holidays.php (Revision 117)
+++ holidays.php (Arbeitskopie)
@@ -193,16 +193,26 @@
# get all events of the ical file
preg_match_all("#(?sU)BEGIN:VEVENT.*END:VEVENT#", file_get_contents($_FILES['ical_file']['tmp_name']), $events);
foreach($events[0] as $event){
- preg_match("#(?sU)DTSTART;.*DATE:([0-9]{8})#", $event, $start);
- preg_match("#(?sU)DTEND;.*DATE:([0-9]{8})#", $event, $end);
+ // whole day event
+ $whole_day = preg_match("#(?sU)DTSTART;.*DATE:([0-9]{8})#", $event, $start);
+ $whole_day += preg_match("#(?sU)DTEND;.*DATE:([0-9]{8})#", $event, $end);
+ // none whole day event
+ if ($whole_day == 0){
+ preg_match("#(?sU)DTSTART:([0-9]{8})#", $event, $start);
+ preg_match("#(?sU)DTEND:([0-9]{8})#", $event, $end);
+ }
$start = mktime (0,0,0, substr($start[1],4,2), substr($start[1],6,2), substr($start[1],0,4));
$end = mktime (0,0,0, substr($end[1],4,2), substr($end[1],6,2), substr($end[1],0,4));
+ if ($whole_day == 0){
+ $end += 24*60*60;
+ }
# update begin and end of ical file (later used for purging)
if ($begin_of_ical > $start) $begin_of_ical = $start;
if ($end_of_ical < $end) $end_of_ical = $end;
# stort begin and end of this holiday period
$holidays[$start] = $end;
};
/**
* Purge database object and add new holiday periods
*/
@@ -212,6 +222,7 @@
while ($current < $end_of_ical){
$current_yearmonth = date("Ym", $current);
if ($M->yearmonth != $current_yearmonth){
$M->update("default", $M->yearmonth); // write changes to database
$M->findByName('default', $current_yearmonth); // load new month object
}
@@ -230,7 +241,7 @@
if ($start_of_first_holiday_period <= $current){
if ($holidays[$start_of_first_holiday_period] > $current){
// we are currently between begin and end of a holiday period
- if (substr($M->template, $dayno-1, 1) != 1){
+ if ($_POST['update_weekend'] || substr($M->template, $dayno-1, 1) != 1){
// don't change weekends
$M->template = substr($M->template, 0, $dayno-1).$H->cfgsym.substr($M->template, $dayno);
}
@@ -345,7 +356,8 @@
<input name=\"btn_hol_update\" type=\"submit\" class=\"button\" value=\"".$LANG['btn_update']."\" onmouseover=\"this.className='button-over';\" onmouseout=\"this.className='button';\">&nbsp;";
if ( $H->cfgsym!='0' && $H->cfgsym!='1' ) { // Business Day and Weekend Day cannot be deleted
echo "<input name=\"btn_hol_delete\" type=\"submit\" class=\"button\" value=\"".$LANG['btn_delete']."\" onmouseover=\"this.className='button-over';\" onmouseout=\"this.className='button';\" onclick=\"return confirmSubmit('".$LANG['ed_delete_confirm']."')\">
- <input type=\"file\" accept=\"text/calendar\" name=\"ical_file\">
+ <input type=\"file\" accept=\"text/calendar\" name=\"ical_file\">
+ <input type=\"checkbox\" name=\"update_weekend\" /> Update Weekend
<input type=\"submit\" class=\"button\" value=\"iCal importieren\" name=\"btn_hol_ical_import\"\>";
}
echo "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment