steffen: server/kolab-resource-handlers/kolab-resource-handlers/freebusy freebusy.class.php, 1.4, 1.5 freebusycache.class.php, 1.4, 1.5 freebusycollector.class.php, 1.1, 1.2

cvs at intevation.de cvs at intevation.de
Sat Oct 16 12:05:18 CEST 2004


Author: steffen

Update of /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy
In directory doto:/tmp/cvs-serv621/kolab-resource-handlers/freebusy

Modified Files:
	freebusy.class.php freebusycache.class.php 
	freebusycollector.class.php 
Log Message:
more fb

Index: freebusy.class.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy/freebusy.class.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- freebusy.class.php	14 Oct 2004 02:12:51 -0000	1.4
+++ freebusy.class.php	16 Oct 2004 10:05:16 -0000	1.5
@@ -26,7 +26,10 @@
 
   function imapOpenMailbox($foldername = 'INBOX') {
     $this->foldername = $foldername;
-    return $this->imap->selectMailbox( $foldername );
+    $rc = $this->imap->selectMailbox( $foldername );
+    $a  = $this->imap->getAnnotation( '/vendor/kolab/folder-type', '*' );
+    //myLog( "$folder has annotation: ".print_r($a,true), RM_LOG_DEBUG);
+    return $rc;
   }
 
   function getACL() {
@@ -58,6 +61,8 @@
     
       $endstamp = mktime(0, 0, 0, $month, $day + $this->freebusy_days, $year);
     }
+
+    myLog("Creating pfb from $startstamp to $endstamp", RM_LOG_DEBUG);
   
     // Create the new iCalendar.
     $vCal = &new Horde_iCalendar();
@@ -116,18 +121,43 @@
       // Get the events initial start
       $initial_start = $event['start-date'];
       $initial_end = $event['end-date'];
-    
-      // Don't bother adding the initial event if it's outside our free/busy window
-      if ($initial_start < $startstamp || $initial_end > $endstamp) {
-	continue;
-      }
-    
       $extra = array( 'X-UID'     => base64_encode($uid) );
       if (!empty($summary)) {
 	$extra['X-SUMMARY'] = base64_encode($summary);
       }
-      
-      $vFb->addBusyPeriod('BUSY', $initial_start, $initial_end, null, $extra);
+
+      // PENDING(steffen): Implement this!      
+      if( array_key_exists( 'recurrence', $event ) ) {	
+	// We have a recurring event
+	$rec = $event['recurrence'];
+	$duration = $initial_end-$initial_start;
+	myLog( "Recurring event ".$summary." recurring cycle ".$rec['cycle'], RM_LOG_DEBUG );
+	switch( $rec['cycle'] ) {
+	case 'daily':
+	  // Daily recurrence, every 'interval' days
+	  for( $t = $initial_start; $t < $endstamp; $t += 24*60*60*(int)$rec['interval'] ) {
+	    myLog("Adding recurrence $t -> ".($t+$duration), RM_LOG_DEBUG );
+	    $vFb->addBusyPeriod('BUSY', $t, null, $duration, $extra);	    
+	  }
+	  break;
+	case 'weekly':
+	  // Weekly recurrence, every 'interval' weeks on 'day' days
+	  // TODO
+	case 'monthly':
+	  // TODO
+	case 'yearly':
+	  // TODO
+	}
+      } else {
+	// Normal event
+    
+	// Don't bother adding the initial event if it's outside our free/busy window
+	if ($initial_start < $startstamp || $initial_end > $endstamp) {
+	  continue;
+	}
+		
+	$vFb->addBusyPeriod('BUSY', $initial_start, $initial_end, null, $extra);
+      }
     }
   
     $xvCal = $vCal;
@@ -228,9 +258,27 @@
     
     // Build the event hash
     foreach ($childnodes as $value) {
-      $event_hash[$value->tagname] = $value->get_content();
+      myLog("Looking at tag ".($value->tagname), RM_LOG_DEBUG);
+      if( $value->tagname == 'recurrence' ) {
+	$rhash = array();
+	$attrs = $value->attributes();
+	foreach( $attrs as $attr ) {
+	  $rhash[$attr->name] = $attr->value;
+	}
+	foreach( $value->child_nodes() as $v ) {
+	  $rhash[$v->tagname] = $v->get_content();
+	  if( $v->tagname == 'range' && $v->has_attribute('type') ) {
+	    $rhash['rangetype'] = $v->get_attribute('type');
+	  }
+	}	
+	$event_hash[$value->tagname] = $rhash;
+      } else {
+	$event_hash[$value->tagname] = $value->get_content();
+      }
     }
     
+    myLog("RAW Event: ".print_r($event_hash, true), RM_LOG_DEBUG);
+
     // Perform some sanity checks on the event
     if (
         empty($event_hash['uid']) ||

Index: freebusycache.class.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy/freebusycache.class.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- freebusycache.class.php	13 Oct 2004 14:17:06 -0000	1.4
+++ freebusycache.class.php	16 Oct 2004 10:05:16 -0000	1.5
@@ -14,62 +14,80 @@
       return false;
     }
 
-    myLog("Storing $filename with acl ".var_export($acl,true), RM_LOG_DEBUG);
-
-    // Create directories if missing
     $fbfilename = $this->mkfbfilename($filename);
-    $fbdirname  = dirname( $fbfilename );
-    if (!is_dir($fbdirname)) {
-      if( !$this->mkdirhier($fbdirname) ) {
-	$this->error = _("Error creating dir $fbdirname");
+    if( $fbdata === false ) {
+      // false data means delete the pfb
+      unlink($fbfilename);
+      $oldacl = $this->loadACL( $filename );
+      $db = dba_open( $this->basedir.'/pfbcache.db', 'cd', 'gdbm' );
+      if( $db === false ) return false;
+      foreach( $oldacl as $ac ) {
+	  if( dba_exists( $ac['USER'], $db ) ) {
+	    $lst = dba_fetch( $ac['USER'], $db );
+	    $lst = $this->decodeList( $lst );
+	    $lst = array_diff( $lst, array($fbfilename));
+	    myLog("(delete) dba_replace(".$uid.", \"".$this->encodeList($lst)."\")", RM_LOG_DEBUG);
+	    dba_replace( $uid, $this->encodeList($lst), $db );
+	  }
+      }
+      unlink($fbfilename.'.acl');
+    } else {
+      myLog("Storing $filename with acl ".var_export($acl,true), RM_LOG_DEBUG);
+      
+      // Create directories if missing
+      $fbdirname  = dirname( $fbfilename );
+      if (!is_dir($fbdirname)) {
+	if( !$this->mkdirhier($fbdirname) ) {
+	  $this->error = _("Error creating dir $fbdirname");
+	  return false;
+	}
+      }
+      
+      // Store the fb list
+      $tmpn = tempnam($this->basedir, 'fb');
+      $tmpf = fopen($tmpn, 'w');
+      if( !$tmpf ) return false;
+      fwrite($tmpf, $fbdata);
+      if( !rename($tmpn, $fbfilename) ) {
+	$this->error = _("Error renaming $tmpn to $fbfilename");
 	return false;
       }
-    }
-
-    // Store the fb list
-    $tmpn = tempnam($this->basedir, 'fb');
-    $tmpf = fopen($tmpn, 'w');
-    if( !$tmpf ) return false;
-    fwrite($tmpf, $fbdata);
-    if( !rename($tmpn, $fbfilename) ) {
-      $this->error = _("Error renaming $tmpn to $fbfilename");
-      return false;
-    }
-    fclose($tmpf);
-
-    // Store the ACL
-    $oldacl = $this->loadACL( $filename );
-    if( !$this->storeACL( $filename, $acl ) ) return false;
-    
-    // Update overview db
-    $db = dba_open( $this->basedir.'/pfbcache.db', 'cd', 'gdbm' );
-    if( $db === false ) return false;
-    foreach( $acl as $ac ) {
-      if( strpos( $ac['RIGHTS'], 'r' ) !== false ) {
-	if( dba_exists( $ac['USER'], $db ) ) {
-	  $lst = dba_fetch( $ac['USER'], $db );
-	  $lst = $this->decodeList( $lst );
-	  $lst[] = $filename;
-	  myLog("(add) dba_replace(".$ac['USER'].", \"".$this->encodeList(array_unique($lst))."\")", RM_LOG_DEBUG);
-	  dba_replace( $ac['USER'], $this->encodeList(array_unique($lst)), $db );
-	} else {
-	  myLog("(add) dba_insert(".$ac['USER'].", \"".$filename."\")", RM_LOG_DEBUG);
-	  dba_insert( $ac['USER'], $filename, $db );
+      fclose($tmpf);
+      
+      // Store the ACL
+      $oldacl = $this->loadACL( $filename );
+      if( !$this->storeACL( $filename, $acl ) ) return false;
+      
+      // Update overview db
+      $db = dba_open( $this->basedir.'/pfbcache.db', 'cd', 'gdbm' );
+      if( $db === false ) return false;
+      foreach( $acl as $ac ) {
+	if( strpos( $ac['RIGHTS'], 'r' ) !== false ) {
+	  if( dba_exists( $ac['USER'], $db ) ) {
+	    $lst = dba_fetch( $ac['USER'], $db );
+	    $lst = $this->decodeList( $lst );
+	    $lst[] = $filename;
+	    myLog("(add) dba_replace(".$ac['USER'].", \"".$this->encodeList(array_unique($lst))."\")", RM_LOG_DEBUG);
+	    dba_replace( $ac['USER'], $this->encodeList(array_unique($lst)), $db );
+	  } else {
+	    myLog("(add) dba_insert(".$ac['USER'].", \"".$filename."\")", RM_LOG_DEBUG);
+	    dba_insert( $ac['USER'], $filename, $db );
+	  }
 	}
       }
+      $deleteduids = $this->aclDiff( $oldacl, $acl );
+      foreach( $deleteduids as $uid ) {
+	if( dba_exists( $uid, $db ) ) {
+	  $lst = dba_fetch( $uid, $db );
+	  $lst = $this->decodeList( $lst );
+	  $lst = array_diff( $lst, array($fbfilename));
+	  myLog("(delete) dba_replace(".$uid.", \"".$this->encodeList($lst)."\")", RM_LOG_DEBUG);
+	  dba_replace( $uid, $this->encodeList($lst), $db );
+	}     
+      }
+      dba_close($db);
+      return true;
     }
-    $deleteduids = $this->aclDiff( $oldacl, $acl );
-    foreach( $deleteduids as $uid ) {
-      if( dba_exists( $uid, $db ) ) {
-	$lst = dba_fetch( $uid, $db );
-	$lst = $this->decodeList( $lst );
-	$lst = array_diff( $lst, array($fbfilename));
-	myLog("(delete) dba_replace(".$uid.", \"".$this->encodeList($lst)."\")", RM_LOG_DEBUG);
-	dba_replace( $uid, $this->encodeList($lst), $db );
-      }     
-    }
-    dba_close($db);
-    return true;
   }
 
   function load( $filename, &$ts, &$acl ) {

Index: freebusycollector.class.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy/freebusycollector.class.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- freebusycollector.class.php	28 Sep 2004 13:12:26 -0000	1.1
+++ freebusycollector.class.php	16 Oct 2004 10:05:16 -0000	1.2
@@ -44,12 +44,12 @@
     if( ($sts = $this->vCal->getAttributeDefault('DTSTART', false)) === false ) {
       $this->vCal->setAttribute('DTSTART', $vCal->getAttribute('DTSTART'), array(), false );
     } else {
-      $this->vCal->setAttribute('DTSTART', max( $sts, $vCal->getAttribute('DTSTART') ), array(), false );
+      $this->vCal->setAttribute('DTSTART', min( $sts, $vCal->getAttribute('DTSTART') ), array(), false );
     }
-    if( ($sts = $this->vCal->getAttributeDefault('DTEND', false)) === false ) {
+    if( ($ets = $this->vCal->getAttributeDefault('DTEND', false)) === false ) {
       $this->vCal->setAttribute('DTEND', $vCal->getAttribute('DTEND'), array(), false );
     } else {
-      $this->vCal->setAttribute('DTEND', min( $sts, $vCal->getAttribute('DTEND')), array(), false );
+      $this->vCal->setAttribute('DTEND', max( $ets, $vCal->getAttribute('DTEND')), array(), false );
     }
     return $vFb1->merge( $vFb2 );
   }





More information about the commits mailing list