steffen: server/kolab-resource-handlers/kolab-resource-handlers/freebusy freebusy.class.php, 1.24, 1.25 misc.php, 1.5, 1.6 recurrence.class.php, 1.8, 1.9

cvs at intevation.de cvs at intevation.de
Sun Jan 16 09:17:51 CET 2005


Author: steffen

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

Modified Files:
	freebusy.class.php misc.php recurrence.class.php 
Log Message:
Fix for Issue243 (recurrence)

Index: freebusy.class.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy/freebusy.class.php,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- freebusy.class.php	12 Jan 2005 02:51:04 -0000	1.24
+++ freebusy.class.php	16 Jan 2005 08:17:49 -0000	1.25
@@ -203,15 +203,17 @@
 	$recurrence->setEndDate( $initial_end );
 	$recurrence->setCycletype( $rec['cycle'] );
 	if( isset($rec['type']) ) $recurrence->setType( $rec['type'] );
-	$recurrence->setInterval( (int)$rec['interval'] );
-	$recurrence->setDaynumber( $rec['daynumber'] );
-	$recurrence->setDay( $rec['day'] );
-	$recurrence->setMonth( $rec['month'] );
+	if( isset($rec['interval']) ) $recurrence->setInterval( (int)$rec['interval'] );
+	if( isset($rec['daynumber']) ) $recurrence->setDaynumber( $rec['daynumber'] );
+	if( isset($rec['day']) ) $recurrence->setDay( $rec['day'] );
+	if( isset($rec['month']) ) $recurrence->setMonth( $rec['month'] );
 	$rangetype = $rec['rangetype'];
 	if( $rangetype == 'number' ) {
 	  $range = (int)$rec['range'];
 	} else if( $rangetype == 'date' ) {
 	  $range = $this->parseDateTime( $rec['range'] );
+	} else {
+	  $range = false;
 	}
 	$recurrence->setRangetype( $rangetype );
 	$recurrence->setRange( $range );

Index: misc.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy/misc.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- misc.php	16 Dec 2004 20:54:46 -0000	1.5
+++ misc.php	16 Jan 2005 08:17:49 -0000	1.6
@@ -21,11 +21,11 @@
 function shutdown() {
     global $fb, $ldap;
 
-    if (defined($fb) && $fb !== false) {
-        $fb->disConnect();
+    if (isset($fb) && $fb !== false) {
+        $fb->imapDisconnect();
         $fb = false;
     }
-    if (defined($ldap) && $ldap !== false) {
+    if (isset($ldap) && $ldap !== false) {
         $ldap->close();
         $ldap = false;
     }

Index: recurrence.class.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy/recurrence.class.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- recurrence.class.php	14 Jan 2005 04:41:13 -0000	1.8
+++ recurrence.class.php	16 Jan 2005 08:17:49 -0000	1.9
@@ -40,149 +40,235 @@
   function setInterval( $interval ) { $this->interval = $interval; }
   function setDaynumber( $num ) { $this->daynumber = is_array($num)?$num:array($num); }
   function setDay( $day ) { $this->day = $day; }
-  function setMonth( $month ) { $this->month = $month; }
+  function setMonth( $month ) { $this->month = is_array($month)?$month:array($month); }
   
   function setRangetype( $type ) { $this->range_type = $type; }
   function setRange( $range ) { $this->range = $range; }
   
   function expand( $startstamp, $endstamp ) {
-    $duration = $this->initial_end-$this->initial_start;
-    //myLog( "Recurrence::expand( $startstamp, $endstamp )", RM_LOG_DEBUG );	
-    //myLog( "cycletype=".$this->cycle_type, RM_LOG_DEBUG);
+    myLog( "Recurrence::expand( $startstamp, $endstamp ), cycletype=".$this->cycle_type, 
+	   RM_LOG_DEBUG);
     switch( $this->cycle_type ) {
     case 'daily':
-      // Daily recurrence, every 'interval' days
-      $count = 0;
-      for( $t = $this->initial_start; $t < $endstamp; $t = strtotime( '+'.$this->interval.' days',$t) ) {
-	    //myLog("Adding recurrence $t -> ".($t+$duration), RM_LOG_DEBUG );
-	    $this->setBusy( $t, null, $duration );
-	    $count++;
-	    if( $this->range_type == 'number' && $count > $this->range ) {
-	      break;
-	    } else if( $this->range_type == 'date' && $t > strtotime( '+1 day',$this->range ) ) {
-	      break;
-	    }
-      }
+      $this-expand_daily( $startstamp, $endstamp );
       break;
     case 'weekly':
-	  // Weekly recurrence, every 'interval' weeks on 'day' days
-	  if( !$this->interval ) $this->interval = 1;
-	  $count = 0;
-	  for( $t = $this->initial_start; $t < $endstamp; $t = strtotime( "+$interval weeks", $t) ) {
-	    foreach( $this->day as $day ) {
-	      $tmp = strtotime( $day, $t);
-	      if( $tmp < $endstamp ) {
-		//myLog("Adding recurrence $tmp -> ".($tmp+$duration), RM_LOG_DEBUG );
-		$this->setBusy( $tmp, null, $duration );
-	      } else {
-		break;
-	      }
-	    }
-	    $count++;
-	    if( $this->range_type == 'number' && $count > $this->range ) {
-	      break;
-	    } else if( $this->range_type == 'date' && $t > strtotime( '+1 day',$this->range ) ) {
-	      break;
-	    }	    
-	  }
+      $this->expand_weekly( $startstamp, $endstamp );
+      break;
     case 'monthly':
-	  // Weekly recurrence, every 'interval' weeks
-	  if( !$this->interval ) $this->interval = 1;
-	  $count = 0;
-	  $delta_days = (int)gmdate('d',$this->initial_start);
-	  for( $t = strtotime( '-'.($delta_days+15).' days', $this->initial_start ); $t < $endstamp; $t = strtotime( "+$interval months", $t)) {
-	    myLog('t = '.gmdate('M d Y H:i:s',strtotime('-15 days', $t)), RM_LOG_DEBUG);
-	    if( $this->type == 'daynumber') {
-	      // On numbered days
-	      foreach( $this->daynumber as $dayno ) {
-		$tmp = strtotime( '+'.($dayno-16).' days', $t);
-		if( $tmp >= $this->initial_start && $tmp < $endstamp ) {
-		  myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp)." -> "
-			.gmdate("M d Y H:i:s",$tmp+$duration), RM_LOG_DEBUG );
-		  $this->setBusy( $tmp, null, $duration );
-		} else {
-		  break;
-		}
-	      }
-	      $count++;
-	    } else if( $this->type == 'weekday' ) {
-	      // On named weekdays
-	      for( $i = 0; $i < count($this->daynumber); $i++ ) {
-		$dayno = $this->daynumber[$i];
-		$wday  = $this->day[$i];
-		$tmp = strtotime( "+$dayno $wday", strtotime('-15 days',$t));
-		if( $tmp >= $this->initial_start && $tmp < $endstamp ) {
-		  myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp)." -> "
-			.gmdate("M d Y H:i:s",$tmp+$duration), RM_LOG_DEBUG );
-		  $this->setBusy( $tmp, null, $duration );
-		} else if($tmp >= $endstamp ) {
-		  break;
-		}
-	      }
-	      $count++;
-	    }
-	    if( $this->range_type == 'number' && $count > $this->range ) {
-	      break;
-	    } else if( $this->range_type == 'date' 
-		       && strtotime('-15 days',$t) > strtotime( '+1 day',$this->range ) ) {
-	      break;
-	    }
-	  }
+      $this->expand_monthly( $startstamp, $endstamp );
+      break;
     case 'yearly':
-	  if( !$this->interval ) $interval = 1;
-	  $count = 0;
-	  $delta_days = (int)gmdate('z',$this->initial_start);
-	  for( $t = strtotime( "-$delta_days days", $this->initial_start ); $t < $endstamp; $t = strtotime( "+$interval years", $t) ) {
-	    if( $this->type == 'yearday') {
-	      foreach( $this->daynumber as $dayno ) {
-		$tmp = strtotime( '+'.($dayno-1).' days', $t);
-		if( $this->initial_start <= $tmp && $tmp < $endstamp ) {
-		  //myLog("Adding recurrence $tmp -> ".($tmp+$duration), RM_LOG_DEBUG );
-		  $this->setBusy( $tmp, null, $duration );
-		} else if($tmp >= $endstamp ) {
-		  break;
-		}
-	      }
-	      $count++;
-	    } else if( $this->type == 'monthday' ) {
-	      for( $i = 0; $i < count($this->daynumber); $i++ ) {
-		$dayno = $this->daynumber[$i];
-		$month = $this->month[$i];
-		$tmp = strtotime( "+$dayno $month", $t);
-		if( $tmp < $endstamp ) {
-		  //myLog("Adding recurrence $tmp -> ".($tmp+$duration), RM_LOG_DEBUG );
-		  $this->setBusy( $tmp, null, $duration );	      
-		} else {
-		  break;
-		}
-	      }
-	      $count++;	      
-	    } else if( $this->type == 'weekday' ) {
-	      for( $i = 0; $i < count($this->daynumber); $i++ ) {
-		$dayno = $this->daynumber[$i];
-		$wday  = $this->day[$i];
-		$tmp = strtotime( "+$dayno $wday", $t);
-		if( $tmp < $endstamp ) {
-		  //myLog("Adding recurrence $tmp -> ".($tmp+$duration), RM_LOG_DEBUG );
-		  $this->setBusy( $tmp, null, $duration );	      
-		} else {
-		  break;
-		}
-	      }
-	      $count++;
-	    } 
-	    if( $this->range_type == 'number' && $count > $this->range ) {
-	      break;
-	    } else if( $this->range_type == 'date' && $t > strtotime( '+1 day',$this->range ) ) {
-	      break;
-	    }
-	  }
-	}
+      $this->expand_yearly( $startstamp, $endstamp );
+      break;
+    default:
+      myLog('Unknown cycletype '.$this->cycle_type, RM_LOG_ERROR);
+    }
   }
 
   /* Abstract function, please override */
   function setBusy( $start, $end, $duration ) {
     mylog( "Warning: Abstract method Recurrence::setBusy( $start, $end, $duration ) called", RM_LOG_ERROR);
+  }
+
+  /* private: */
+
+  function expand_daily( $startstamp, $endstamp ) {
+    // Daily recurrence, every 'interval' days
+    $duration = $this->initial_end-$this->initial_start;
+    $count = 0;
+    if( !$this->interval ) $this->interval = 1;
+    for( $t = $this->initial_start; $t < $endstamp; $t = strtotime( '+'.$this->interval.' days',$t) ) {
+      //myLog("Adding recurrence $t -> ".($t+$duration), RM_LOG_DEBUG );
+      $this->setBusy( $t, null, $duration );
+      $count++;
+      if( $this->range_type == 'number' && $count > $this->range ) {
+	break;
+      } else if( $this->range_type == 'date' && $t > strtotime( '+1 day',$this->range ) ) {
+	break;
+      }
+    }
+  }
+
+  function expand_weekly( $startstamp, $endstamp ) {
+    // Weekly recurrence, every 'interval' weeks on 'day' days
+    $duration = $this->initial_end-$this->initial_start;
+    if( !$this->interval ) $this->interval = 1;
+    $count = 0;
+    $delta_days = (int)gmdate('w',$this->initial_start);
+    for( $t =  strtotime("-$delta_days days", $this->initial_start); $t < $endstamp; 
+	 $t = strtotime( '+'.$this->interval.' weeks', $t) ) {
+      foreach( $this->day as $day ) {
+	$tmp = strtotime( "+$delta_days days", $t );
+	$tmp = strtotime( '+'.$this->dayname2number($day).' days', $tmp);
+	if( $tmp >= $this->initial_start && $tmp < $endstamp ) {
+	  myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp)." -> "
+		.gmdate("M d Y H:i:s",$tmp+$duration), RM_LOG_DEBUG );
+	  $this->setBusy( $tmp, null, $duration );
+	} else {
+	  break;
+	}
+      }
+      $count++;
+      if( $this->range_type == 'number' && $count > $this->range ) {
+	break;
+      } else if( $this->range_type == 'date' && $t > strtotime( '+1 day',$this->range ) ) {
+	break;
+      }	    
+    }
+  }
+  function expand_monthly( $startstamp, $endstamp ) {
+    // Weekly recurrence, every 'interval' weeks
+    $duration = $this->initial_end-$this->initial_start;
+    if( !$this->interval ) $this->interval = 1;
+    $count = 0;
+    $delta_days = (int)gmdate('d',$this->initial_start);
+    for( $t = strtotime( '-'.($delta_days+15).' days', $this->initial_start ); 
+	 $t < $endstamp; $t = strtotime( '+'.$this->interval.' months', $t)) {
+      //myLog('t = '.gmdate('M d Y H:i:s',strtotime('-15 days', $t)), RM_LOG_DEBUG);
+      if( $this->type == 'daynumber') {
+	// On numbered days
+	foreach( $this->daynumber as $dayno ) {
+	  $tmp = strtotime( '+'.($dayno-16).' days', $t);
+	  if( $tmp >= $this->initial_start && $tmp < $endstamp ) {
+	    myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp)." -> "
+		  .gmdate("M d Y H:i:s",$tmp+$duration), RM_LOG_DEBUG );
+	    $this->setBusy( $tmp, null, $duration );
+	  } else {
+	    break;
+	  }
+	}
+	$count++;
+      } else if( $this->type == 'weekday' ) {
+	// On named weekdays
+
+	// Find beginning of first week
+	$tmp = strtotime('-15 days',$t);
+	$firstday = (int)gmdate('w',$tmp);
+	for( $i = 0; $i < count($this->day); $i++ ) {
+	  $dayno = $this->daynumber[$i];
+	  $wday  = $this->dayname2number($this->day[$i]);
+	  if( $wday < $firstday ) $tmp2 = strtotime( '+'.($dayno+1)*7+$wday.' days', $tmp);
+	  else $tmp2 = strtotime( '+'.$dayno*7+$wday.' days', $tmp);
+	  //myLog("daynumber=$dayno, wday=$wday", RM_LOG_DEBUG);
+	  //myLog('tmp2 = '.gmdate('M d Y H:i:s',$tmp2), RM_LOG_DEBUG);
+	  if( $tmp2 >= $this->initial_start && $tmp2 < $endstamp ) {
+	    myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp2)." -> "
+		  .gmdate("M d Y H:i:s",$tmp2+$duration), RM_LOG_DEBUG );
+	    $this->setBusy( $tmp2, null, $duration );
+	  } else if($tmp2 >= $endstamp ) {
+	    break;
+	  }
+	}
+	$count++;
+      }
+      if( $this->range_type == 'number' && $count > $this->range ) {
+	break;
+      } else if( $this->range_type == 'date' 
+		 && strtotime('-15 days',$t) > strtotime( '+1 day',$this->range ) ) {
+	break;
+      }
+    }
+  }
+
+  function expand_yearly( $startstamp, $endstamp ) {
+    $duration = $this->initial_end-$this->initial_start;
+    if( !$this->interval ) $this->interval = 1;
+    $count = 0;
+    $delta_days = (int)gmdate('z',$this->initial_start);
+    for( $t = strtotime( "-$delta_days days", $this->initial_start ); $t < $endstamp; 
+	 $t = strtotime( '+'.$this->interval.' years', $t) ) {
+      //myLog("t= ".gmdate("M d Y H:i:s",$t), RM_LOG_DEBUG );
+      if( $this->type == 'yearday') {
+	foreach( $this->daynumber as $dayno ) {
+	  $tmp = strtotime( '+'.($dayno-1).' days', $t);
+	  if( $this->initial_start <= $tmp && $tmp < $endstamp ) {
+	    myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp)." -> "
+		  .gmdate("M d Y H:i:s",$tmp+$duration), RM_LOG_DEBUG );
+	    $this->setBusy( $tmp, null, $duration );
+	  } else if($tmp >= $endstamp ) {
+	    break;
+	  }
+	}
+	$count++;
+      } else if( $this->type == 'monthday' ) {
+	for( $i = 0; $i < count($this->daynumber); $i++ ) {
+	  $dayno = $this->daynumber[$i];
+	  $month = $this->monthname2number($this->month[$i]);
+	  $year = gmdate('Y', $t );
+	  $time = gmdate('H:i:s', $t);
+	  //myLog("setting tmp to $year-$month-$dayno $time+0000", RM_LOG_DEBUG );
+	  $tmp =  strtotime( "$year-$month-$dayno $time+0000");
+	  //myLog("tmp= ".gmdate("M d Y H:i:s",$tmp), RM_LOG_DEBUG );
+	  if( $this->initial_start <= $tmp && $tmp < $endstamp ) {
+	    myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp)." -> "
+		  .gmdate("M d Y H:i:s",$tmp+$duration), RM_LOG_DEBUG );
+	    $this->setBusy( $tmp, null, $duration );	      
+	  } else {
+	    break;
+	  }
+	}
+	$count++;	      
+      } else if( $this->type == 'weekday' ) {
+	for( $i = 0; $i < count($this->daynumber); $i++ ) {
+	  $dayno = $this->daynumber[$i];
+	  $wday  = $this->day[$i];
+	  $month = $this->month[$i];
+	  $year  = gmdate('Y',$t);
+	  $time  = gmdate('H:i:s',$t);
+	  $tmp = strtotime( "$dayno $wday", strtotime( "1 $month $year") );
+	  $tmp = strtotime( gmdate('Y-m-d',$tmp)." $time+0000");
+	  if( $this->initial_start <= $tmp && $tmp < $endstamp ) {
+	    myLog("Adding recurrence ".gmdate("M d Y H:i:s",$tmp)." -> "
+		  .gmdate("M d Y H:i:s",$tmp+$duration), RM_LOG_DEBUG );
+	    $this->setBusy( $tmp, null, $duration );	      
+	  } else {
+	    break;
+	  }
+	}
+	$count++;
+      } 
+      if( $this->range_type == 'number' && $count > $this->range ) {
+	break;
+      } else if( $this->range_type == 'date' && $t > strtotime( '+1 day',$this->range ) ) {
+	break;
+      }
+    }
+  }
+
+  function dayname2number( $day ) {
+    switch( strtolower($day) ) {
+    case 'sunday': return 0;
+    case 'monday': return 1;
+    case 'tuesday': return 2;
+    case 'wednesday': return 3;
+    case 'thursday': return 4;
+    case 'friday': return 5;
+    case 'saturdayday': return 6;
+    default:
+      myLog("Recurrence::dayname2number($day): Invalid day", RM_LOG_ERROR);
+      return -1;
+    }
+  }
+
+  function monthname2number( $month ) {
+    switch( $month ) {
+    case 'january':  return 1;
+    case 'february': return 2;
+    case 'march':    return 3;
+    case 'april':    return 4;
+    case 'may':      return 5;
+    case 'june':     return 6;
+    case 'july':     return 7;
+    case 'august':   return 8;
+    case 'september':return 9;
+    case 'october':  return 10;
+    case 'november': return 11;
+    case 'december': return 12;
+    default:
+      myLog("Recurrence::monthname2number($month): Invalid month", RM_LOG_ERROR);
+      return -1;
+    }
   }
 
   var $initial_start = NULL; // timestamp





More information about the commits mailing list