torsten: server/kolab-resource-handlers/kolab-resource-handlers/resmgr resmgr.php, 1.69.2.1, 1.69.2.2

cvs at intevation.de cvs at intevation.de
Thu Apr 27 18:12:12 CEST 2006


Author: torsten

Update of /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr
In directory doto:/tmp/cvs-serv12752

Modified Files:
      Tag: kolab_2_0_branch
	resmgr.php 
Log Message:
Backported patch for issue1171 from Pieter to 2.0 branch. Patch was
tested and causes no trouble here.


Index: resmgr.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/Attic/resmgr.php,v
retrieving revision 1.69.2.1
retrieving revision 1.69.2.2
diff -u -d -r1.69.2.1 -r1.69.2.2
--- resmgr.php	30 Aug 2005 19:03:35 -0000	1.69.2.1
+++ resmgr.php	27 Apr 2006 16:12:10 -0000	1.69.2.2
@@ -691,10 +691,75 @@
   // normal user accounts
 }
 
-function iCalDate2Kolab($ical_date)
+// resource error when date is used and no timestring
+
+function cleanArray($ical_date)
+{
+	if ( array_key_exists('hour',$ical_date) ) {
+		$temp['hour']   = array_key_exists('hour',$ical_date) ? $ical_date['hour'] :  '00';
+		$temp['minute']   = array_key_exists('minute',$ical_date) ? $ical_date['minute'] :  '00';
+		$temp['second']   = array_key_exists('second',$ical_date) ? $ical_date['second'] :  '00';
+		$temp['zone']   = array_key_exists('zone',$ical_date) ? $ical_date['zone'] :  'UTC';
+	} else { 
+		$temp['DATE'] = '1';
+	}
+	$temp['year']   = array_key_exists('year',$ical_date) ? $ical_date['year'] :  '0000';
+	$temp['month']   = array_key_exists('month',$ical_date) ? $ical_date['month'] :  '00';
+	$temp['mday']   = array_key_exists('mday',$ical_date) ? $ical_date['mday'] :  '00';
+
+	return $temp;
+}
+
+
+
+/*
+
+An all day event must have a dd--mm-yyyy notation and not a yyyy-dd-mmT00:00:00z notation
+Otherwise the event is shown as a 2-day event
+--> do not try to convert everything to epoch first !!
+*/
+
+function iCalDate2Kolab($ical_date,$type= ' ')
 {
+    myLog("Converting to kolab format ".print_r($ical_date,true),RM_LOG_DEBUG);
     // $ical_date should be a timestamp
-    return gmstrftime('%Y-%m-%dT%H:%M:%SZ', $ical_date);
+    if (is_array($ical_date)) {
+	# going to create date again
+	$temp=cleanArray($ical_date);
+    	if (array_key_exists('DATE',$temp)) {
+		if ($type == 'ENDDATE') {
+			# substract a day (86400 seconds) using epochs to take number of days per month into account
+			$epoch=convert2epoch($temp)-86400;
+        		$date = gmstrftime('%Y-%m-%d', $epoch);
+		} else {
+		    	$date= sprintf('%04d-%02d-%02d',$temp['year'], $temp['month'], $temp['mday']);
+		}
+	} else {
+		$time = sprintf('%02d:%02d:%02d', $temp['hour'], $temp['minute'], $temp['second']);
+	        if ($temp['zone'] == 'UTC') {
+        	    $time .= 'Z';
+        	}
+        	$date= sprintf('%04d-%02d-%02d',$temp['year'], $temp['month'], $temp['mday']). "T".$time;
+	}
+    }  else {
+        $date = gmstrftime('%Y-%m-%dT%H:%M:%SZ', $ical_date);
+    }
+    myLog("To <$date>",RM_LOG_DEBUG);
+     return $date;
+}
+
+
+function convert2epoch($values)
+{
+    myLog("Converting to epoch ".print_r($values,true),RM_LOG_DEBUG);
+
+    if (is_array($values)) {
+	$temp=cleanArray($values);
+	$epoch=gmmktime($temp['hour'],$temp['minute'],$temp['second'],$temp['month'],$temp['mday'],$temp['year']);
+    } else { $epoch=$values;} 
+    
+    myLog("Converted <$epoch>",RM_LOG_DEBUG);
+    return $epoch;
 }
 
 function &buildKolabEvent(&$itip)
@@ -752,8 +817,14 @@
 
     $kolab_node = $kolab_event->append_child($kolab_xml->create_element('end-date'));
     $kolab_node->append_child($kolab_xml->create_text_node(
-        iCalDate2Kolab($itip->getAttributeDefault('DTEND', 0))
+        iCalDate2Kolab($itip->getAttributeDefault('DTEND', 0),'ENDDATE')
     ));
+
+    # default is busy, so set free if info is available
+    if ($itip->getAttributeDefault('TRANSP', 0) == 'TRANSPARENT') {
+	$kolab_node = $kolab_event->append_child($kolab_xml->create_element('show-time-as'));
+	$kolab_node->append_child($kolab_xml->create_text_node('free' ));
+   }
     
     // Attendees
     $attendees = $itip->getAttribute('ATTENDEE');
@@ -836,8 +907,8 @@
       $freq = strtolower($rrule['FREQ']);
       $recur_node->append_child( $kolab_xml->create_attribute( 'cycle', $freq ));
       $recurrence->setCycletype( $freq );
-      $recurrence->setStartdate( $itip->getAttributeDefault('DTSTART', 0) );
-      $recurrence->setEnddate( $itip->getAttributeDefault('DTEND', 0) );
+      $recurrence->setStartdate( convert2epoch($itip->getAttributeDefault('DTSTART', 0)) );
+      $recurrence->setEnddate( convert2epoch($itip->getAttributeDefault('DTEND', 0) ));
       switch( $freq ) {
       case 'daily':
 	break;
@@ -1074,11 +1145,11 @@
   // What is the events summary?
   $summary = $itip->getAttributeDefault('SUMMARY', '');
 
-  $dtstart = $itip->getAttributeDefault('DTSTART', 0);
-  $dtend = $itip->getAttributeDefault('DTEND', 0);
+  $dtstart = convert2epoch ($itip->getAttributeDefault('DTSTART', 0));
+  $dtend = convert2epoch ($itip->getAttributeDefault('DTEND', 0));
 
-  myLog('Event starts on ' . strftime('%a, %d %b %Y %H:%M:%S %z', $dtstart) .
-	' and ends on ' . strftime('%a, %d %b %Y %H:%M:%S %z', $dtend), RM_LOG_DEBUG);
+  myLog("Event starts on <$dtstart> " .iCalDate2Kolab($dtstart).
+	" and ends on <$dtend> " . iCalDate2Kolab($dtend), RM_LOG_DEBUG);
 
   if ($params['action'] == RM_ACT_ALWAYS_REJECT) {
     myLog("Rejecting $method method");
@@ -1131,34 +1202,41 @@
 
       $vfbstart = $vfb->getAttributeDefault('DTSTART', 0);
       $vfbend = $vfb->getAttributeDefault('DTEND', 0);
-      myLog('Free/busy info starts on ' . strftime('%a, %d %b %Y %H:%M:%S %z', $vfbstart) .
-	    ' and ends on ' . strftime('%a, %d %b %Y %H:%M:%S %z', $vfbend), RM_LOG_DEBUG);
-
-      // Check whether we are busy or not
-      $busyperiods = $vfb->getBusyPeriods();
-      $extraparams = $vfb->getExtraParams();
-      $conflict = false;	    
-      if( $recurrence !== false ) {
-	$recurrence->busyperiods =& $busyperiods;
-	$recurrence->extraparams =& $extraparams;
-	$recurrence->ignore = $ignore;
-	//myLog("Recurrence is ".print_r($recurrence,true), RM_LOG_DEBUG);
-	$recurrence->expand( $vfbstart, $vfbend );
-	$conflict = $recurrence->hasConflict();
-      } else {	    
-	foreach ($busyperiods as $busyfrom => $busyto) {
-	  myLog('Busy period from ' . strftime('%a, %d %b %Y %H:%M:%S %z', $busyfrom) . ' to ' . strftime('%a, %d %b %Y %H:%M:%S %z', $busyto), RM_LOG_DEBUG);
-	  if ( in_array(base64_decode($extraparams[$busyfrom]['X-UID']), $ignore) ||
-	       in_array(base64_decode($extraparams[$busyfrom]['X-SID']), $ignore) ) {
-	    // Ignore
-	    continue;
-	  }
-	  if (($busyfrom >= $dtstart && $busyfrom < $dtend) || ($dtstart >= $busyfrom && $dtstart < $busyto)) {
-	    myLog('Request overlaps', RM_LOG_DEBUG);
-	    $conflict = true;
-	    break;
-	  }
-	}
+      myLog("Free/busy info starts on <$vfbstart>" .iCalDate2Kolab($vfbstart) .
+	    " and ends on <$fbend>" .iCalDate2Kolab($vfbend), RM_LOG_DEBUG);
+	
+      $outofperiod=0;
+      if ($dtstart > convert2epoch ($vfbend)) {
+		$outofperiod=1;
+      } else {
+	      // Check whether we are busy or not
+	      $busyperiods = $vfb->getBusyPeriods();
+	      myLog("Busyperiods: ".print_r($busyperiods,true),RM_LOG_DEBUG);
+	      $extraparams = $vfb->getExtraParams();
+	      myLog("Extraparams: ".print_r($extraparams,true),RM_LOG_DEBUG);
+	      $conflict = false;	    
+	      if( $recurrence !== false ) {
+		$recurrence->busyperiods =& $busyperiods;
+		$recurrence->extraparams =& $extraparams;
+		$recurrence->ignore = $ignore;
+		myLog("Recurrence is ".print_r($recurrence,true), RM_LOG_DEBUG);
+		$recurrence->expand( $vfbstart, $vfbend );
+		$conflict = $recurrence->hasConflict();
+	      } else {	    
+		foreach ($busyperiods as $busyfrom => $busyto) {
+		  myLog('Busy period from ' . strftime('%a, %d %b %Y %H:%M:%S %z', $busyfrom) . ' to ' . strftime('%a, %d %b %Y %H:%M:%S %z', $busyto), RM_LOG_DEBUG);
+		  if ( in_array(base64_decode($extraparams[$busyfrom]['X-UID']), $ignore) ||
+		       in_array(base64_decode($extraparams[$busyfrom]['X-SID']), $ignore) ) {
+		    // Ignore
+		    continue;
+		  }
+		  if (($busyfrom >= $dtstart && $busyfrom < $dtend) || ($dtstart >= $busyfrom && $dtstart < $busyto)) {
+		    myLog('Request overlaps', RM_LOG_DEBUG);
+		    $conflict = true;
+		    break;
+		  }
+		}
+	      }
       }
 
       if ($conflict) {
@@ -1242,7 +1320,12 @@
       $itip->setAttribute('ATTENDEE', $attendee, $attparams[$i]);
     }
 
-    sendITipReply($cn,$resource,$itip,RM_ITIP_ACCEPT);
+    if ($outofperiod) {
+       sendITipReply($cn,$resource,$itip,RM_ITIP_TENTATIVE);
+       myLog("No freebusy information available", RM_LOG_NOTICE);
+    } else {
+       sendITipReply($cn,$resource,$itip,RM_ITIP_ACCEPT);
+    }
 
     // Delete any old events that we updated
     if( !empty( $updated_messages ) ) {





More information about the commits mailing list