[ Index ]

krapohl.info

title

Body

[close]

/ -> pninit.php (source)

   1  <?php
   2  @define('__POSTCALENDAR__','PostCalendar');
   3  /**
   4   *  $Id: pninit.php,v 1.1 2004/02/11 17:25:28 larsneo Exp $
   5   *
   6   *  PostCalendar::PostNuke Events Calendar Module
   7   *  Copyright (C) 2002  The PostCalendar Team
   8   *  http://postcalendar.tv
   9   *  
  10   *  This program is free software; you can redistribute it and/or modify
  11   *  it under the terms of the GNU General Public License as published by
  12   *  the Free Software Foundation; either version 2 of the License, or
  13   *  (at your option) any later version.
  14   *  
  15   *  This program is distributed in the hope that it will be useful,
  16   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18   *  GNU General Public License for more details.
  19   *  
  20   *  You should have received a copy of the GNU General Public License
  21   *  along with this program; if not, write to the Free Software
  22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23   *
  24   *  To read the license please read the docs/license.txt or visit
  25   *  http://www.gnu.org/copyleft/gpl.html
  26   *
  27   */
  28  
  29  /**
  30   *    Initializes a new install of PostCalendar
  31   *
  32   *    This function will initialize a new installation of PostCalendar.
  33   *    It is accessed via the PostNuke Admin interface and should
  34   *    not be called directly. 
  35   *
  36   *    @return  boolean    true/false
  37   *    @access  public
  38   *    @author  Roger Raymond <iansym@yahoo.com>
  39   *    @copyright    The PostCalendar Team 2002
  40   */
  41  function postcalendar_init()
  42  {
  43      list($dbconn) = pnDBGetConn();
  44      $pntable = pnDBGetTables();
  45      $events_table = $pntable['postcalendar_events'];
  46      $cat_table    = $pntable['postcalendar_categories'];
  47      
  48      // after reading some posts i've decided to adopt the new
  49      // $pntable style which does not append table names.
  50      // if you use joins in your SQL please remember this!
  51      $sql = "CREATE TABLE $events_table (
  52              pc_eid int(11) unsigned NOT NULL auto_increment,
  53              pc_catid int(11) NOT NULL default '0',
  54              pc_aid varchar(30) NOT NULL default '',
  55              pc_title varchar(150) default '',
  56              pc_time datetime,
  57              pc_hometext text default '',
  58              pc_comments int(11) default '0',
  59              pc_counter mediumint(8) unsigned default '0',
  60              pc_topic int(3) NOT NULL default '1',
  61              pc_informant varchar(20) NOT NULL default '',
  62              pc_eventDate date NOT NULL default '0000-00-00',
  63              pc_endDate date NOT NULL default '0000-00-00',
  64              pc_duration bigint(20) NOT NULL default '0',
  65              pc_recurrtype int(1) NOT NULL default '0',
  66              pc_recurrspec text default '',
  67              pc_recurrfreq int(3) NOT NULL default '0',
  68              pc_startTime time,
  69              pc_endTime time,
  70              pc_alldayevent int(1) NOT NULL default '0',
  71              pc_location text default '',
  72              pc_conttel varchar(50) default '',
  73              pc_contname varchar(50) default '',
  74              pc_contemail varchar(255) default '',
  75              pc_website varchar(255) default '',
  76              pc_fee varchar(50) default '',
  77              pc_eventstatus int(11) NOT NULL default '0',
  78              pc_sharing int(11) NOT NULL default '0',
  79              pc_language varchar(30) default '',
  80              PRIMARY KEY (pc_eid),
  81              KEY basic_event (pc_catid,pc_aid,pc_eventDate,pc_endDate,pc_eventstatus,pc_sharing,pc_topic)
  82              )";
  83      $dbconn->Execute($sql);
  84      if ($dbconn->ErrorNo() != 0) {
  85          pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
  86          return false;
  87      }
  88      
  89      // create the category table
  90      $sql = "CREATE TABLE $cat_table (
  91              pc_catid int(11) unsigned NOT NULL auto_increment,
  92              pc_catname varchar(100) NOT NULL default 'Undefined',
  93              pc_catcolor varchar(50) NOT NULL default '#FF0000',
  94              pc_catdesc text default '',
  95              PRIMARY KEY (pc_catid),
  96              KEY basic_cat (pc_catname,pc_catcolor)
  97              )";
  98      $dbconn->Execute($sql);
  99      if ($dbconn->ErrorNo() != 0) {
 100          pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
 101          return false;
 102      }
 103      
 104      // insert default category
 105      $catid = $dbconn->GenID($cat_table);
 106      $sql = "INSERT INTO $cat_table (pc_catid, pc_catname, pc_catcolor, pc_catdesc)
 107              VALUES($catid,'Default','#ff0000','Default Category')";
 108      $dbconn->Execute($sql);
 109      if ($dbconn->ErrorNo() != 0) {
 110          pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
 111          return false;
 112      }        
 113      
 114      // PostCalendar Default Settings
 115      pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours',              '0');
 116      pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow',    '0');
 117      pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates',    '0');
 118      pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek',           '0');
 119      pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor',        '#FF0000');
 120      pnModSetVar(__POSTCALENDAR__, 'pcUsePopups',                '1');
 121      pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics',            '0');
 122      pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit',        '0');
 123      pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents',        '15');
 124      pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement',            '15');
 125      pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide',            '0');
 126      pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar',        '1');
 127      pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat',            '%Y-%m-%d');
 128      pnModSetVar(__POSTCALENDAR__, 'pcTemplate',                 'default');
 129      pnModSetVar(__POSTCALENDAR__, 'pcUseCache',                 '1');
 130      pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime',             '3600');
 131      pnModSetVar(__POSTCALENDAR__, 'pcDefaultView',                 'month');
 132      pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin',                 '0');
 133      pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail',                 pnConfigGetVar('adminmail'));
 134      return true;
 135  }
 136  
 137  /**
 138   *    Upgrades an old install of PostCalendar
 139   *
 140   *    This function is used to upgrade an old version
 141   *    of PostCalendar.  It is accessed via the PostNuke
 142   *    Admin interface and should not be called directly.
 143   *
 144   *    @return boolean    true/false
 145   *    @param  string    $oldversion Version we're upgrading
 146   *    @access  public
 147   *    @author  Roger Raymond <iansym@yahoo.com>
 148   *    @copyright    The PostCalendar Team 2002
 149   */
 150  function postcalendar_upgrade($oldversion)
 151  {
 152      /**
 153       *    Until PostNuke fixes the bugs
 154       *    with the module upgrade we are
 155       *    going to have to do it ourselves.
 156       *
 157       *    Please do not use the Modules admin
 158       *    to upgrade PostCalendar.  Use the
 159       *    link provided in the PostCalendar
 160       *    Admin section.
 161       */
 162      $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
 163      $pcDir = pnVarPrepForOS($pcModInfo['directory']);
 164      
 165      list($dbconn) = pnDBGetConn();
 166      $pntable = pnDBGetTables();
 167      $events_table   =  $pntable['postcalendar_events'];
 168      $cat_table      =  $pntable['postcalendar_categories'];
 169      
 170      switch($oldversion) {
 171          
 172          case '3.0' :
 173          case '3.01' :
 174          case '3.02' :
 175          case '3.03' :
 176          case '3.04' :
 177              
 178              // we need the Date_Calc class
 179              require_once("modules/$pcDir/pnincludes/Date/Calc.php");
 180              
 181              // Update PostCalendar Variables
 182              pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', pnModGetVar(__POSTCALENDAR__,'time24hours'));
 183              pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', pnModGetVar(__POSTCALENDAR__,'eventsopeninnewwindow'));
 184              pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', pnModGetVar(__POSTCALENDAR__,'useinternationaldates'));
 185              pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', pnModGetVar(__POSTCALENDAR__,'firstdayofweek'));
 186              pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', pnModGetVar(__POSTCALENDAR__,'dayhighlightcolor'));
 187              pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', pnModGetVar(__POSTCALENDAR__,'usepopups'));
 188              pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', pnModGetVar(__POSTCALENDAR__,'displaytopics'));
 189              pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', '0');
 190              pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', pnModGetVar(__POSTCALENDAR__,'listhowmanyevents'));
 191              pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', '15');
 192              pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', '0');
 193              pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', '1');
 194              pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', '%Y-%m-%d');
 195              pnModSetVar(__POSTCALENDAR__, 'pcTemplate', 'default');
 196              pnModSetVar(__POSTCALENDAR__, 'pcUseCache','1');
 197              pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime','3600');
 198              pnModSetVar(__POSTCALENDAR__, 'pcDefaultView','month');
 199              pnModSetVar(__POSTCALENDAR__, 'pcSafeMode','0');
 200              
 201              // alter the events table and change some old columns
 202              $sql = "ALTER TABLE $events_table
 203                      ADD pc_catid int(11) default '0' NOT NULL,
 204                      ADD pc_duration bigint(20) default '0' NOT NULL,
 205                      ADD pc_sharing int(11) default '0' NOT NULL,
 206                      ADD pc_language varchar(30) default '',
 207                      CHANGE pc_eid pc_eid int(11) unsigned NOT NULL auto_increment,
 208                      CHANGE pc_location pc_location text,
 209                      CHANGE pc_conttel pc_conttel varchar(50),
 210                      CHANGE pc_contname pc_contname varchar(150),
 211                      CHANGE pc_contemail pc_contemail varchar(255),
 212                      CHANGE pc_website pc_website varchar(255),
 213                      CHANGE pc_fee pc_fee varchar(50),
 214                      CHANGE pc_recurrspec pc_recurrspec text default ''
 215                      ";
 216                 
 217              $dbconn->Execute($sql);
 218              if ($dbconn->ErrorNo() != 0) {
 219                  die('event table alter error : '.$dbconn->ErrorMsg());
 220                  return false;
 221              }
 222              
 223              // create the new categories table
 224              $sql = "CREATE TABLE $cat_table (
 225                      pc_catid int(11) unsigned NOT NULL auto_increment,
 226                      pc_catname varchar(100) NOT NULL default 'Undefined',
 227                      pc_catcolor varchar(50) NOT NULL default '#FF0000',
 228                      pc_catdesc text default '',
 229                      PRIMARY KEY(pc_catid)
 230                      )";
 231              $dbconn->Execute($sql);
 232              if ($dbconn->ErrorNo() != 0) {
 233                  die('cat table create error : '.$dbconn->ErrorMsg());
 234                  return false;
 235              }
 236              
 237              // insert the current hardcoded categories into the new categories table
 238              $category1 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category1'));
 239              $category2 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category2'));
 240              $category3 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category3'));
 241              $category4 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category4'));
 242              $category5 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__,'category5'));
 243              
 244              $inserts = array(
 245                  "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('1','$category1','#ff0000')",
 246                  "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('2','$category2','#00ff00')",
 247                  "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('3','$category3','#0000ff')",
 248                  "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('4','$category4','#ffffff')",
 249                  "INSERT INTO $cat_table (pc_catid,pc_catname,pc_catcolor) VALUES ('5','$category5','#ffcc00')"
 250                  );
 251                  
 252              foreach($inserts as $insert) {
 253                  $dbconn->Execute($insert);
 254                  if ($dbconn->ErrorNo() != 0) {
 255                      die('cat table insert error : '.$dbconn->ErrorMsg());
 256                      return false;
 257                  }
 258              }
 259              
 260              // update the current events to reflect the category system change
 261              $updates = array(
 262                  "UPDATE $events_table SET pc_catid = 1 WHERE pc_barcolor = 'r' ",
 263                  "UPDATE $events_table SET pc_catid = 2 WHERE pc_barcolor = 'g' ",
 264                  "UPDATE $events_table SET pc_catid = 3 WHERE pc_barcolor = 'b' ",
 265                  "UPDATE $events_table SET pc_catid = 4 WHERE pc_barcolor = 'w' ",
 266                  "UPDATE $events_table SET pc_catid = 5 WHERE pc_barcolor = 'y' "
 267                  );
 268              
 269              foreach($updates as $update) {
 270                  $dbconn->Execute($update);
 271                  if ($dbconn->ErrorNo() != 0) {
 272                      die('event table update error : '.$dbconn->ErrorMsg());
 273                      return false;
 274                  }
 275              }
 276              
 277              // alter the events table and drop the old barcolor column
 278              $sql = "ALTER TABLE $events_table DROP pc_barcolor";
 279              $dbconn->Execute($sql);
 280              if ($dbconn->ErrorNo() != 0) {
 281                  die('cat table alter error : '.$dbconn->ErrorMsg());
 282                  return false;
 283              }
 284              
 285              // remove the old vars as they are no longer needed
 286              pnModDelVar(__POSTCALENDAR__,'category1');
 287              pnModDelVar(__POSTCALENDAR__,'category2');
 288              pnModDelVar(__POSTCALENDAR__,'category3');
 289              pnModDelVar(__POSTCALENDAR__,'category4');
 290              pnModDelVar(__POSTCALENDAR__,'category5');
 291              pnModDelVar(__POSTCALENDAR__,'time24hours');
 292              pnModDelVar(__POSTCALENDAR__,'eventsopeninnewwindow');
 293              pnModDelVar(__POSTCALENDAR__,'useinternationaldates');
 294              pnModDelVar(__POSTCALENDAR__,'firstdayofweek');
 295              pnModDelVar(__POSTCALENDAR__,'dayhighlightcolor');
 296              pnModDelVar(__POSTCALENDAR__,'displaytopics');
 297              pnModDelVar(__POSTCALENDAR__,'usepopups');
 298              pnModDelVar(__POSTCALENDAR__,'listhowmanyevents');
 299              pnModDelVar(__POSTCALENDAR__,'allowdirectsubmit');
 300              pnModDelVar(__POSTCALENDAR__,'showeventsinyear');
 301                          
 302              //======================================================
 303              //  now, ideally, we will convert old events to the new 
 304              //  style. this consists of reconfiguring the repeating 
 305              //  events vars. 
 306              //
 307              //  we need to establish the current repeating 
 308              //  conditions and convert them to the new system
 309              //======================================================
 310              //  old repeating defines
 311              //======================================================
 312              @define('_EVENT_NONE',      -1);
 313              @define('_EVENT_DAILY',      0);
 314              @define('_EVENT_WEEKLY',     1);
 315              @define('_EVENT_MONTHLY',    2);
 316              @define('_EVENT_YEARLY',     3);
 317              @define('_RECUR_SAME_DAY',   0);
 318              @define('_RECUR_SAME_DATE',  1);
 319              //======================================================
 320              //  new repeating defines
 321              //  $recurrspec['event_repeat']
 322              //======================================================
 323              @define('NO_REPEAT',    0);
 324              @define('REPEAT',       1);
 325              @define('REPEAT_ON',    2);
 326              //======================================================
 327              //  $recurrspec['event_repeat_freq']
 328              //======================================================
 329              @define('REPEAT_EVERY',         1);
 330              @define('REPEAT_EVERY_OTHER',   2);
 331              @define('REPEAT_EVERY_THIRD',   3);
 332              @define('REPEAT_EVERY_FOURTH',  4);
 333              //======================================================
 334              //  $recurrspec['event_repeat_freq_type']
 335              //======================================================
 336              @define('REPEAT_EVERY_DAY',     0);
 337              @define('REPEAT_EVERY_WEEK',    1);
 338              @define('REPEAT_EVERY_MONTH',   2);
 339              @define('REPEAT_EVERY_YEAR',    3);
 340              //======================================================
 341              //  $recurrspec['event_repeat_on_num']
 342              //======================================================
 343              @define('REPEAT_ON_1ST',    1);
 344              @define('REPEAT_ON_2ND',    2);
 345              @define('REPEAT_ON_3RD',    3);
 346              @define('REPEAT_ON_4TH',    4);
 347              @define('REPEAT_ON_LAST',   5);
 348              //======================================================
 349              //  $recurrspec['event_repeat_on_day']
 350              //======================================================
 351              @define('REPEAT_ON_SUN',    0);
 352              @define('REPEAT_ON_MON',    1);
 353              @define('REPEAT_ON_TUE',    2);
 354              @define('REPEAT_ON_WED',    3);
 355              @define('REPEAT_ON_THU',    4);
 356              @define('REPEAT_ON_FRI',    5);
 357              @define('REPEAT_ON_SAT',    6);
 358              //======================================================
 359              //  $recurrspec['event_repeat_on_freq']
 360              //======================================================
 361              @define('REPEAT_ON_MONTH',  1);
 362              @define('REPEAT_ON_2MONTH', 2);
 363              @define('REPEAT_ON_3MONTH', 3);
 364              @define('REPEAT_ON_4MONTH', 4);
 365              @define('REPEAT_ON_6MONTH', 6);
 366              @define('REPEAT_ON_YEAR',   12);
 367              //======================================================
 368              //  Set Sharing Paramaters
 369              //======================================================
 370              @define('SHARING_PRIVATE',       0);
 371              @define('SHARING_PUBLIC',        1);
 372              @define('SHARING_BUSY',          2);
 373              @define('SHARING_GLOBAL',        3);
 374              //======================================================
 375              //  Here's some psuedo-code for the conversion
 376              //
 377              //  if _EVENT_NONE 
 378              //      $rtype = NO_REPEAT
 379              //      $rspec = 0 for all;
 380              //      $duration = endTime - startTime
 381              //
 382              //  if _EVENT_DAILY
 383              //      $rtype = REPEAT
 384              //      $rspec = REPEAT_EVERY|REPEAT_EVERY_DAY
 385              //      $duration = endTime - startTime    
 386              //
 387              //  if _EVENT_WEEKLY
 388              //      $rtype = REPEAT
 389              //      $rspec = REPEAT_EVERY|REPEAT_EVERY_WEEK
 390              //      $duration = endTime - startTime
 391              //
 392              //  if _EVENT_MONTHLY
 393              //      if _RECUR_SAME_DAY
 394              //          $rtype = REPEAT_ON
 395              //          $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ
 396              //      if _RECUR_SAME_DATE
 397              //          $rtype = REPEAT
 398              //          $rspec = REPEAT_EVERY|REPEAT_EVERY_MONTH
 399              //      $duration = endTime - startTime
 400              //
 401              //  if _EVENT_YEARLY
 402              //      if _RECUR_SAME_DAY
 403              //          $rtype = REPEAT_ON
 404              //          $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ
 405              //      if _RECUR_SAME_DATE
 406              //          $rtype = REPEAT
 407              //          $rspec = REPEAT_EVERY|REPEAT_EVERY_YEAR
 408              //      $duration = endTime - startTime
 409              //======================================================
 410              //  attempt reconfiguration
 411              //======================================================
 412              $sql = "SELECT pc_eid, pc_eventDate, pc_startTime, pc_endTime, pc_recurrtype, pc_recurrfreq
 413                      FROM $events_table";
 414              $result = $dbconn->Execute($sql);
 415              if($dbconn->ErrorNo() != 0) {
 416                  die($dbconn->ErrorMsg());
 417                  return false;
 418              }
 419              if(!isset($result)) return false;
 420              // grab the results and start the conversion
 421              for(; !$result->EOF; $result->MoveNext()) {
 422                  $recurrspec = array();
 423                  list($eid,$eventdate,$start,$end,$rtype,$rfreq) = $result->fields;
 424  
 425                  if($rtype == null) $rtype = _EVENT_NONE;
 426                  switch($rtype) {
 427                  
 428                      case _EVENT_NONE :
 429                          $recurrtype = NO_REPEAT;
 430                          $recurrspec['event_repeat_freq']        = 0;
 431                          $recurrspec['event_repeat_freq_type']   = 0;
 432                          $recurrspec['event_repeat_on_num']      = 0;
 433                          $recurrspec['event_repeat_on_day']      = 0;
 434                          $recurrspec['event_repeat_on_freq']     = 0;
 435                          break;
 436                      
 437                      case _EVENT_DAILY :
 438                          $recurrtype = REPEAT;
 439                          $recurrspec['event_repeat_freq']        = REPEAT_EVERY;
 440                          $recurrspec['event_repeat_freq_type']   = REPEAT_EVERY_DAY;
 441                          $recurrspec['event_repeat_on_num']      = 0;
 442                          $recurrspec['event_repeat_on_day']      = 0;
 443                          $recurrspec['event_repeat_on_freq']     = 0;
 444                          break;
 445                      
 446                      case _EVENT_WEEKLY :
 447                          $recurrtype = REPEAT;
 448                          $recurrspec['event_repeat_freq']        = REPEAT_EVERY;
 449                          $recurrspec['event_repeat_freq_type']   = REPEAT_EVERY_WEEK;
 450                          $recurrspec['event_repeat_on_num']      = 0;
 451                          $recurrspec['event_repeat_on_day']      = 0;
 452                          $recurrspec['event_repeat_on_freq']     = 0;
 453                          break;
 454                      
 455                      case _EVENT_MONTHLY :
 456                          if($rfreq == _RECUR_SAME_DATE) {
 457                              $recurrtype = REPEAT;
 458                              $recurrspec['event_repeat_freq']        = REPEAT_EVERY;
 459                              $recurrspec['event_repeat_freq_type']   = REPEAT_EVERY_MONTH;
 460                              $recurrspec['event_repeat_on_num']      = 0;
 461                              $recurrspec['event_repeat_on_day']      = 0;
 462                              $recurrspec['event_repeat_on_freq']     = 0;
 463                          } elseif($rfreq == _RECUR_SAME_DAY) {
 464                              $recurrtype = REPEAT_ON;
 465                              list($y,$m,$d) = explode('-',$eventdate);
 466                              $recurrspec['event_repeat_freq']        = 0;
 467                              $recurrspec['event_repeat_freq_type']   = 0;
 468                              // event day of week
 469                              $edow = Date_Calc::dayOfWeek($d,$m,$y);
 470                              // date of first event day of week
 471                              $firstDay = Date_Calc::NWeekdayOfMonth(1,$edow,$m,$y,'%Y-%m-%d');
 472                              // find difference between 1st day and event day
 473                              list($y2,$m2,$d2) = explode('-',$firstDay);
 474                              $diff = Date_Calc::dateDiff($d,$m,$y,$d2,$m2,$y2);
 475                              // assuming $diff is going to be a multiple of 7
 476                              if($diff > 0) { $diff/=7; }
 477                              if($diff > REPEAT_ON_4TH) { $diff = REPEAT_ON_LAST; }
 478                              $recurrspec['event_repeat_on_num']      = $diff;
 479                              $recurrspec['event_repeat_on_day']      = $edow;
 480                              $recurrspec['event_repeat_on_freq']     = REPEAT_ON_MONTH;
 481                          }
 482                          break;
 483                      
 484                      case _EVENT_YEARLY :
 485                          if($rfreq == _RECUR_SAME_DATE) {
 486                              $recurrtype = REPEAT;
 487                              $recurrspec['event_repeat_freq']        = REPEAT_EVERY;
 488                              $recurrspec['event_repeat_freq_type']   = REPEAT_EVERY_YEAR;
 489                              $recurrspec['event_repeat_on_num']      = 0;
 490                              $recurrspec['event_repeat_on_day']      = 0;
 491                              $recurrspec['event_repeat_on_freq']     = 0;
 492                          } elseif($rfreq == _RECUR_SAME_DAY) {
 493                              $recurrtype = REPEAT_ON;
 494                              list($y,$m,$d) = explode('-',$eventdate);
 495                              $recurrspec['event_repeat_freq']        = 0;
 496                              $recurrspec['event_repeat_freq_type']   = 0;
 497                              // event day of week
 498                              $edow = Date_Calc::dayOfWeek($d,$m,$y);
 499                              // date of first event day of week
 500                              $firstDay = Date_Calc::NWeekdayOfMonth(1,$edow,$m,$y,'%Y-%m-%d');
 501                              // find difference between 1st day and event day
 502                              list($y2,$m2,$d2) = explode('-',$firstDay);
 503                              $diff = Date_Calc::dateDiff($d,$m,$y,$d2,$m2,$y2);
 504                              // assuming $diff is going to be a multiple of 7
 505                              if($diff > 0) { $diff/=7; }
 506                              if($diff > REPEAT_ON_4TH) { $diff = REPEAT_ON_LAST; }
 507                              $recurrspec['event_repeat_on_num']      = $diff;
 508                              $recurrspec['event_repeat_on_day']      = $edow;
 509                              $recurrspec['event_repeat_on_freq']     = REPEAT_ON_YEAR;
 510                          }
 511                          break;
 512                  }
 513                  // ok, figure out the event's duration
 514                  list($sh,$sm,$ss) = explode(':',$start);
 515                  list($eh,$em,$es) =