/** * Gets the day of the week for this date * * Gets the day of the week for this date (0=Sunday) * * @access public * @return int the day of the week (0=Sunday) */ function getDayOfWeek() { return Date_Calc::dayOfWeek($this->day, $this->month, $this->year); }
/** * Returns textual representation of the next day of week of the decorated calendar object * @param object subclass of Calendar e.g. Calendar_Month * @param string (optional) format of returned months (one,two,short or long) * @return string * @access public * @static */ function nextDayName($Calendar, $format = 'long') { $days = Calendar_Util_Textual::weekdayNames($format); $stamp = $Calendar->nextDay('timestamp'); $cE = $Calendar->getEngine(); require_once 'Date/Calc.php'; $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); return $days[$day]; }
/** * Returns the full weekday name for the given date * * @param string year in format CCYY, default current local year * @param string month in format MM, default current local month * @param string day in format DD, default current local day * * @access public * * @return string full month name */ function getWeekdayFullname($day = "", $month = "", $year = "") { if (empty($year)) { $year = Date_Calc::dateNow("%Y"); } if (empty($month)) { $month = Date_Calc::dateNow("%m"); } if (empty($day)) { $day = Date_Calc::dateNow("%d"); } $weekday_names = Date_Calc::getWeekDays(); $weekday = Date_Calc::dayOfWeek($day, $month, $year); return $weekday_names[$weekday]; }
/** * Calculates the date of the Nth weekday of the month, * such as the second Saturday of January 2000 * * @param int $week the number of the week to get * (1 = first, etc. Also can be 'last'.) * @param int $dow the day of the week (0 = Sunday) * @param int $month the month * @param int $year the year. Use the complete year instead of the * abbreviated version. E.g. use 2005, not 05. * @param string $format the string indicating how to format the output * * @return string the date in the desired format * @access public * @static */ function nWeekdayOfMonth($week, $dow, $month, $year, $format = DATE_CALC_FORMAT) { if (is_numeric($week)) { $DOW1day = ($week - 1) * 7 + 1; $DOW1 = Date_Calc::dayOfWeek($DOW1day, $month, $year); $wdate = ($week - 1) * 7 + 1 + (7 + $dow - $DOW1) % 7; if ($wdate > Date_Calc::daysInMonth($month, $year)) { return -1; } else { return Date_Calc::dateFormat($wdate, $month, $year, $format); } } elseif ($week == 'last' && $dow < 7) { $lastday = Date_Calc::daysInMonth($month, $year); $lastdow = Date_Calc::dayOfWeek($lastday, $month, $year); $diff = $dow - $lastdow; if ($diff > 0) { return Date_Calc::dateFormat($lastday - (7 - $diff), $month, $year, $format); } else { return Date_Calc::dateFormat($lastday + $diff, $month, $year, $format); } } else { return -1; } }
/** * Returns the number of the day of the week (0=sunday, 1=monday...) * @param int year (2003) * @param int month (9) * @param int day (4) * @return int weekday number * @access protected */ function getDayOfWeek($y, $m, $d) { return Date_Calc::dayOfWeek($d, $m, $y); }
/** * Display a single-day calendar view. * * @param integer $year Year to display, default is current year * @param integer $month Starting month * @param integer $day Starting day * @param integer $cat Category to show * @param integer $cal Calendar to show * @return string HTML for calendar page */ function EVLIST_dayview($year = 0, $month = 0, $day = 0, $cat = 0, $cal = 0, $opt = '') { global $_CONF, $_EV_CONF, $LANG_EVLIST; USES_class_date(); EVLIST_setViewSession('day', $year, $month, $day); $retval = ''; list($currentyear, $currentmonth, $currentday) = explode('-', $_EV_CONF['_today']); // Default to the current day if ($year == 0) { $year = $currentyear; } if ($month == 0) { $month = $currentmonth; } if ($day == 0) { $day = $currentday; } $cat = (int) $cat; $cal = (int) $cal; $today = sprintf("%04d-%02d-%02d", $year, $month, $day); $dtToday = new Date(strtotime($today), $_CONF['timezone']); $dtPrev = new Date($dtToday->toUnix() - 86400, $_CONF['timezone']); $dtNext = new Date($dtToday->toUnix() + 86400, $_CONF['timezone']); $monthname = $LANG_MONTH[$month]; $dow = Date_Calc::dayOfWeek($day, $month, $year) + 1; $dayname = $dtToday->format('l'); $tpl = 'dayview'; if ($opt == 'print') { $tpl .= '_print'; } elseif ($_EV_CONF['cal_tmpl'] == 'json') { $tpl .= '_json'; } $T = new Template(EVLIST_PI_PATH . '/templates/dayview'); $T->set_file(array('column' => 'column.thtml', 'event' => 'singleevent.thtml', 'dayview' => $tpl . '.thtml')); $events = EVLIST_getEvents($today, $today, array('cat' => $cat, 'cal' => $cal)); $calendars_used = array(); list($allday, $hourly) = EVLIST_getDayViewData($events, $starting_date); // Get allday events $alldaycount = count($allday); if ($alldaycount > 0) { for ($i = 1; $i <= $alldaycount; $i++) { $A = current($allday); $calendars_used[$A['cal_id']] = array('cal_name' => $A['cal_name'], 'cal_ena_ical' => $A['cal_ena_ical'], 'cal_id' => $A['cal_id'], 'fgcolor' => $A['fgcolor'], 'bgcolor' => $A['bgcolor']); $T->set_var(array('delete_imagelink' => EVLIST_deleteImageLink($A, $token), 'event_time' => $LANG_EVLIST['allday'], 'rp_id' => $A['rp_id'], 'event_title' => stripslashes($A['title']), 'event_summary' => stripslashes($A['summary']), 'bgcolor' => $A['bgcolor'], 'fgcolor' => $A['fgcolor'], 'cal_id' => $A['cal_id'])); if ($i < $alldaycount) { $T->set_var('br', '<br />'); } else { $T->set_var('br', ''); } $T->parse('allday_events', 'event', true); next($allday); } } else { $T->set_var('allday_events', ' '); } for ($i = 0; $i < 24; $i++) { $link = date($_CONF['timeonly'], mktime($i, 0)); if ($_EV_CONF['_can_add']) { $link = '<a href="' . EVLIST_URL . '/event.php?edit=x&month=' . $month . '&day=' . $day . '&year=' . $year . '&hour=' . $i . '">' . $link . '</a>'; } $T->set_var($i . '_hour', $link); } // Get hourly events /*$times = array(); foreach ($hourly as $event) { if (!isset($times[$event['starthour']])) $times[$event['starthour']] = array(); $times[$event['starthour']][] = $event; }*/ for ($i = 0; $i <= 23; $i++) { $hourevents = $hourly[$i]; $numevents = count($hourevents); if ($numevents > 0) { for ($j = 1; $j <= $numevents; $j++) { $A = current($hourevents); $calendars_used[$A['data']['cal_id']] = array('cal_name' => $A['data']['cal_name'], 'cal_ena_ical' => $A['data']['cal_ena_ical'], 'cal_id' => $A['data']['cal_id'], 'fgcolor' => $A['data']['fgcolor'], 'bgcolor' => $A['data']['bgcolor']); if ($A['data']['rp_date_start'] == $starting_date) { $start_time = date($_CONF['timeonly'], strtotime($A['data']['rp_date_start'] . ' ' . $A['time_start'])); //strtotime($A['evt_start'] . ' ' . $A['timestart'])); } else { $start_time = date($_CONF['shortdate'] . ' @ ' . $_CONF['timeonly'], strtotime($A['data']['rp_date_start'] . ' ' . $A['time_start'])); } if ($A['data']['rp_date_end'] == $_EV_CONF['today']) { $end_time = date($_CONF['timeonly'], strtotime($A['data']['rp_date_end'] . ' ' . $A['time_end'])); } else { $end_time = date($_CONF['shortdate'] . ' @ ' . $_CONF['timeonly'], strtotime($A['data']['rp_date_end'] . ' ' . $A['time_end'])); } if ($start_time == ' ... ' && $end_time == ' ... ') { $T->set_var('event_time', $LANG_EVLIST['allday']); } else { $T->set_var('event_time', $start_time . ' - ' . $end_time); } $T->set_var(array('delete_imagelink' => EVLIST_deleteImageLink($A['data'], $token), 'eid' => $A['data']['rp_ev_id'], 'rp_id' => $A['data']['rp_id'], 'event_title' => stripslashes($A['data']['title']), 'event_summary' => htmlspecialchars($A['data']['summary']), 'fgcolor' => $A['data']['fgcolor'], 'bgcolor' => '', 'cal_id' => $A['data']['cal_id'])); if ($j < $numevents) { $T->set_var('br', '<br />'); } else { $T->set_var('br', ''); } $T->parse('event_entry', 'event', $j == 1 ? false : true); next($hourevents); } } else { $T->set_var('event_entry', ' '); } $link = date($_CONF['timeonly'], mktime($i, 0)); if ($_EV_CONF['_can_add']) { $link = '<a href="' . EVLIST_URL . '/event.php?edit=x&month=' . $month . '&day=' . $day . '&year=' . $year . '&hour=' . $i . '">' . $link . '</a>'; } // $T->set_var ($i . '_hour',$link); $T->parse($i . '_cols', 'column', true); } $T->set_var(array('month' => $month, 'day' => $day, 'year' => $year, 'prevmonth' => $dtPrev->format('n', false), 'prevday' => $dtPrev->format('j', false), 'prevyear' => $dtPrev->format('Y', false), 'nextmonth' => $dtNext->format('n', false), 'nextday' => $dtNext->format('j', false), 'nextyear' => $dtNext->format('Y', false), 'urlfilt_cal' => $cal, 'urlfilt_cat' => $cat, 'cal_header' => EVLIST_calHeader($year, $month, $day, 'day', $cat, $cal), 'cal_footer' => EVLIST_calFooter($calendars_used), 'pi_url' => EVLIST_URL, 'currentday' => $dayname . ', ' . $dtToday->format($_CONF['shortdate']), 'week_num' => $dtToday->format('W'), 'cal_checkboxes', EVLIST_cal_checkboxes($calendars_used), 'site_name' => $_CONF['site_name'], 'site_slogan' => $_CONF['site_slogan'])); return $T->parse('output', 'dayview'); }
/** * Returns the full weekday name for the given date * * @param string day in format DD, default is current local day * @param string month in format MM, default is current local month * @param string year in format CCYY, default is current local year * * @access public * * @return string full month name */ function getWeekdayFullname($day = '', $month = '', $year = '') { if (empty($year)) { $year = Date_Calc::dateNow('%Y'); } if (empty($month)) { $month = Date_Calc::dateNow('%m'); } if (empty($day)) { $day = Date_Calc::dateNow('%d'); } $weekday_names = Date_Calc::getWeekDays(); $weekday = Date_Calc::dayOfWeek($day, $month, $year); return $weekday_names[$weekday]; }
/** * Returns the abbreviated weekday name for the given date * * @param string year in format CCYY, default current local year * @param string month in format MM, default current local month * @param string day in format DD, default current local day * @param int optional length of abbreviation, default is 3 * * @access public * * @return string full month name */ function getWeekdayAbbrname($day = "", $month = "", $year = "", $length = 3) { if (empty($year)) { $year = Date_Calc::dateNow("%Y"); } if (empty($month)) { $month = Date_Calc::dateNow("%m"); } if (empty($day)) { $day = Date_Calc::dateNow("%d"); } $weekday_names = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); $weekday = Date_Calc::dayOfWeek($day, $month, $year); return substr($weekday_names[$weekday], 0, $length); }
protected function SkipWeekend($occurrence) { // Figure out the next day if we're supposed to skip one. // We don't need to do this if we're just going to continue // the frequency loop to the next instance. if ($this->skip > 0) { // Split out the components of the new working date. list($y, $m, $d) = explode('-', $occurrence); $dow = Date_Calc::dayOfWeek($d, $m, $y); if ($dow == 6 || $dow == 0) { if ($this->skip == 2) { // Skip to the next weekday $occurrence = Date_Calc::nextWeekday($d, $m, $y); } else { // Monthly recurrences are on specific dates, so don't // just stip to the next one- return NULL so the // calling function knows to ignore this instance $occurrence = NULL; } } } return $occurrence; }
compare('Saturday', Date_Calc::getWeekdayFullname(1, 1, 2005), 'getWeekdayFullname'); compare('Sat', Date_Calc::getWeekdayAbbrname(1, 1, 2005), 'getWeekdayAbbrname'); compare(11, Date_Calc::getMonthFromFullName('November'), 'getMonthFromFullName'); compare(327, Date_Calc::dayOfYear('22', '11', '2000'), 'dayOfYear str'); compare('November', Date_Calc::getMonthFullname('11'), 'getMonthFullname str'); compare('Nov', Date_Calc::getMonthAbbrname('11'), 'getMonthAbbrname str'); compare('Saturday', Date_Calc::getWeekdayFullname('01', '01', '2005'), 'getWeekdayFullname str'); compare('Sat', Date_Calc::getWeekdayAbbrname('01', '01', '2005'), 'getWeekdayAbbrname str'); $exp = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); compare($exp, Date_Calc::getMonthNames(), 'getMonthNames'); $exp = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); compare($exp, Date_Calc::getWeekDays(), 'getWeekDays'); compare(3, Date_Calc::dayOfWeek(22, 11, 2000), 'dayOfWeek'); compare(47, Date_Calc::weekOfYear(22, 11, 2000), 'weekOfYear'); compare(4, Date_Calc::quarterOfYear(22, 11, 2000), 'quarterOfYear'); compare(3, Date_Calc::dayOfWeek('22', '11', '2000'), 'dayOfWeek str'); compare(47, Date_Calc::weekOfYear('22', '11', '2000'), 'weekOfYear str'); compare(4, Date_Calc::quarterOfYear('22', '11', '2000'), 'quarterOfYear str'); compare(28, Date_Calc::daysInMonth(2, 1900), 'daysInMonth 1'); compare(29, Date_Calc::daysInMonth(2, 1996), 'daysInMonth 2'); compare(29, Date_Calc::daysInMonth(2, 2000), 'daysInMonth 3'); compare(28, Date_Calc::daysInMonth(2, 2001), 'daysInMonth 4'); compare(30, Date_Calc::daysInMonth(11, 2000), 'daysInMonth 5'); compare(28, Date_Calc::daysInMonth('02', 1900), 'daysInMonth 1 str'); compare(29, Date_Calc::daysInMonth('02', 1996), 'daysInMonth 2 str'); compare(29, Date_Calc::daysInMonth('02', 2000), 'daysInMonth 3 str'); compare(28, Date_Calc::daysInMonth('02', 2001), 'daysInMonth 4 str'); compare(30, Date_Calc::daysInMonth('11', '2000'), 'daysInMonth 5 str'); compare(5, Date_Calc::weeksInMonth(11, 2000), 'weeksInMonth'); compare(5, Date_Calc::weeksInMonth('11', '2000'), 'weeksInMonth str'); $exp = array('19000226', '19000227', '19000228', '19000301', '19000302', '19000303', '19000304');
/** * Converts the Week number and Day-of-Week to Date * * Calculation algorithm taken from * {@link http://www.merlyn.demon.co.uk/weekcalc.htm}. * * @param int $dow day of week from 1 (Monday) to 7 (Sunday) * @param int $week number of week from 1 to 53 * @param int $year four digits of year * @param string $format the output format * * @return string formatted date * @access public * @static * @since Method available since Release 1.5.0a2 */ function isoWeekToDate($dow, $week, $year, $format = DATE_CALC_FORMAT) { // validates the week number list(, $nweeks) = Date_Calc::isoWeekDate(28, 12, $year); if ($week > $nweeks) { return PEAR::raiseError("ISO week number for {$year} cannot be greater than {$nweeks}", DATE_ERROR_INVALIDDATE); } // validates the day of week if ($dow < 1 || $dow > 7) { return PEAR::raiseError("ISO day of week must be between 1 and 7", DATE_ERROR_INVALIDDATE); } // finds the day of week of January 4th. $jan4th = Date_Calc::dayOfWeek(4, 1, $year); if ($jan4th == 0) { $jan4th = 7; } // offset to the monday of that week $offset = -($jan4th - 1); // increment the days starting from january 4th. $days = Date_Calc::dateToDays(1, 1, $year) + $offset + 7 * ($week - 1) + ($dow - 1) + 3; return Date_Calc::daysToDate($days, $format); }
/** * Upgrades an old install of PostCalendar * * This function is used to upgrade an old version * of PostCalendar. It is accessed via the PostNuke * Admin interface and should not be called directly. * * @return boolean true/false * @param string $oldversion Version we're upgrading * @access public * @author Roger Raymond <*****@*****.**> * @copyright The PostCalendar Team 2002 */ function postcalendar_upgrade($oldversion) { /** * Until PostNuke fixes the bugs * with the module upgrade we are * going to have to do it ourselves. * * Please do not use the Modules admin * to upgrade PostCalendar. Use the * link provided in the PostCalendar * Admin section. */ $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); $pcDir = pnVarPrepForOS($pcModInfo['directory']); list($dbconn) = pnDBGetConn(); $pntable = pnDBGetTables(); $events_table = $pntable['postcalendar_events']; $cat_table = $pntable['postcalendar_categories']; switch ($oldversion) { case '3.0': case '3.01': case '3.02': case '3.03': case '3.04': // we need the Date_Calc class require_once "modules/{$pcDir}/pnincludes/Date/Calc.php"; // Update PostCalendar Variables pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', pnModGetVar(__POSTCALENDAR__, 'time24hours')); pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', pnModGetVar(__POSTCALENDAR__, 'eventsopeninnewwindow')); pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', pnModGetVar(__POSTCALENDAR__, 'useinternationaldates')); pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', pnModGetVar(__POSTCALENDAR__, 'firstdayofweek')); pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', pnModGetVar(__POSTCALENDAR__, 'dayhighlightcolor')); pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', pnModGetVar(__POSTCALENDAR__, 'usepopups')); pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', pnModGetVar(__POSTCALENDAR__, 'displaytopics')); pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', '0'); pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', pnModGetVar(__POSTCALENDAR__, 'listhowmanyevents')); pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', '15'); pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', '0'); pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', '1'); pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', '%Y-%m-%d'); pnModSetVar(__POSTCALENDAR__, 'pcTemplate', 'default'); pnModSetVar(__POSTCALENDAR__, 'pcUseCache', '1'); pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime', '3600'); pnModSetVar(__POSTCALENDAR__, 'pcDefaultView', 'month'); pnModSetVar(__POSTCALENDAR__, 'pcSafeMode', '0'); // alter the events table and change some old columns $sql = "ALTER TABLE {$events_table}\n ADD pc_catid int(11) default '0' NOT NULL,\n\t\t\t\t\tADD pc_duration bigint(20) default '0' NOT NULL,\n ADD pc_sharing int(11) default '0' NOT NULL,\n ADD pc_language varchar(30) default '',\n\t\t\t\t\tCHANGE pc_eid pc_eid int(11) unsigned NOT NULL auto_increment,\n CHANGE pc_location pc_location text,\n CHANGE pc_conttel pc_conttel varchar(50),\n CHANGE pc_contname pc_contname varchar(150),\n CHANGE pc_contemail pc_contemail varchar(255),\n CHANGE pc_website pc_website varchar(255),\n CHANGE pc_fee pc_fee varchar(50),\n CHANGE pc_recurrspec pc_recurrspec text default ''\n "; $dbconn->Execute($sql); if ($dbconn->ErrorNo() != 0) { die('event table alter error : ' . $dbconn->ErrorMsg()); return false; } // create the new categories table $sql = "CREATE TABLE {$cat_table} (\n pc_catid int(11) unsigned NOT NULL auto_increment,\n pc_catname varchar(100) NOT NULL default 'Undefined',\n pc_catcolor varchar(50) NOT NULL default '#EEEEEE',\n pc_catdesc text default '',\n PRIMARY KEY(pc_catid)\n )"; $dbconn->Execute($sql); if ($dbconn->ErrorNo() != 0) { die('cat table create error : ' . $dbconn->ErrorMsg()); return false; } // insert the current hardcoded categories into the new categories table $category1 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category1')); $category2 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category2')); $category3 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category3')); $category4 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category4')); $category5 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category5')); $inserts = array("INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('1','{$category1}','#EEEEEE')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('2','{$category2}','#00ff00')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('3','{$category3}','#0000ff')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('4','{$category4}','#ffffff')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('5','{$category5}','#ffcc00')"); foreach ($inserts as $insert) { $dbconn->Execute($insert); if ($dbconn->ErrorNo() != 0) { die('cat table insert error : ' . $dbconn->ErrorMsg()); return false; } } // update the current events to reflect the category system change $updates = array("UPDATE {$events_table} SET pc_catid = 1 WHERE pc_barcolor = 'r' ", "UPDATE {$events_table} SET pc_catid = 2 WHERE pc_barcolor = 'g' ", "UPDATE {$events_table} SET pc_catid = 3 WHERE pc_barcolor = 'b' ", "UPDATE {$events_table} SET pc_catid = 4 WHERE pc_barcolor = 'w' ", "UPDATE {$events_table} SET pc_catid = 5 WHERE pc_barcolor = 'y' "); foreach ($updates as $update) { $dbconn->Execute($update); if ($dbconn->ErrorNo() != 0) { die('event table update error : ' . $dbconn->ErrorMsg()); return false; } } // alter the events table and drop the old barcolor column $sql = "ALTER TABLE {$events_table} DROP pc_barcolor"; $dbconn->Execute($sql); if ($dbconn->ErrorNo() != 0) { die('cat table alter error : ' . $dbconn->ErrorMsg()); return false; } // remove the old vars as they are no longer needed pnModDelVar(__POSTCALENDAR__, 'category1'); pnModDelVar(__POSTCALENDAR__, 'category2'); pnModDelVar(__POSTCALENDAR__, 'category3'); pnModDelVar(__POSTCALENDAR__, 'category4'); pnModDelVar(__POSTCALENDAR__, 'category5'); pnModDelVar(__POSTCALENDAR__, 'time24hours'); pnModDelVar(__POSTCALENDAR__, 'eventsopeninnewwindow'); pnModDelVar(__POSTCALENDAR__, 'useinternationaldates'); pnModDelVar(__POSTCALENDAR__, 'firstdayofweek'); pnModDelVar(__POSTCALENDAR__, 'dayhighlightcolor'); pnModDelVar(__POSTCALENDAR__, 'displaytopics'); pnModDelVar(__POSTCALENDAR__, 'usepopups'); pnModDelVar(__POSTCALENDAR__, 'listhowmanyevents'); pnModDelVar(__POSTCALENDAR__, 'allowdirectsubmit'); pnModDelVar(__POSTCALENDAR__, 'showeventsinyear'); //====================================================== // now, ideally, we will convert old events to the new // style. this consists of reconfiguring the repeating // events vars. // // we need to establish the current repeating // conditions and convert them to the new system //====================================================== // old repeating defines //====================================================== @define('_EVENT_NONE', -1); @define('_EVENT_DAILY', 0); @define('_EVENT_WEEKLY', 1); @define('_EVENT_MONTHLY', 2); @define('_EVENT_YEARLY', 3); @define('_RECUR_SAME_DAY', 0); @define('_RECUR_SAME_DATE', 1); //====================================================== // new repeating defines // $recurrspec['event_repeat'] //====================================================== @define('NO_REPEAT', 0); @define('REPEAT', 1); @define('REPEAT_ON', 2); //====================================================== // $recurrspec['event_repeat_freq'] //====================================================== @define('REPEAT_EVERY', 1); @define('REPEAT_EVERY_OTHER', 2); @define('REPEAT_EVERY_THIRD', 3); @define('REPEAT_EVERY_FOURTH', 4); //====================================================== // $recurrspec['event_repeat_freq_type'] //====================================================== @define('REPEAT_EVERY_DAY', 0); @define('REPEAT_EVERY_WEEK', 1); @define('REPEAT_EVERY_MONTH', 2); @define('REPEAT_EVERY_YEAR', 3); //====================================================== // $recurrspec['event_repeat_on_num'] //====================================================== @define('REPEAT_ON_1ST', 1); @define('REPEAT_ON_2ND', 2); @define('REPEAT_ON_3RD', 3); @define('REPEAT_ON_4TH', 4); @define('REPEAT_ON_LAST', 5); //====================================================== // $recurrspec['event_repeat_on_day'] //====================================================== @define('REPEAT_ON_SUN', 0); @define('REPEAT_ON_MON', 1); @define('REPEAT_ON_TUE', 2); @define('REPEAT_ON_WED', 3); @define('REPEAT_ON_THU', 4); @define('REPEAT_ON_FRI', 5); @define('REPEAT_ON_SAT', 6); //====================================================== // $recurrspec['event_repeat_on_freq'] //====================================================== @define('REPEAT_ON_MONTH', 1); @define('REPEAT_ON_2MONTH', 2); @define('REPEAT_ON_3MONTH', 3); @define('REPEAT_ON_4MONTH', 4); @define('REPEAT_ON_6MONTH', 6); @define('REPEAT_ON_YEAR', 12); //====================================================== // Set Sharing Paramaters //====================================================== @define('SHARING_PRIVATE', 0); @define('SHARING_PUBLIC', 1); @define('SHARING_BUSY', 2); @define('SHARING_GLOBAL', 3); //====================================================== // Here's some psuedo-code for the conversion // // if _EVENT_NONE // $rtype = NO_REPEAT // $rspec = 0 for all; // $duration = endTime - startTime // // if _EVENT_DAILY // $rtype = REPEAT // $rspec = REPEAT_EVERY|REPEAT_EVERY_DAY // $duration = endTime - startTime // // if _EVENT_WEEKLY // $rtype = REPEAT // $rspec = REPEAT_EVERY|REPEAT_EVERY_WEEK // $duration = endTime - startTime // // if _EVENT_MONTHLY // if _RECUR_SAME_DAY // $rtype = REPEAT_ON // $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ // if _RECUR_SAME_DATE // $rtype = REPEAT // $rspec = REPEAT_EVERY|REPEAT_EVERY_MONTH // $duration = endTime - startTime // // if _EVENT_YEARLY // if _RECUR_SAME_DAY // $rtype = REPEAT_ON // $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ // if _RECUR_SAME_DATE // $rtype = REPEAT // $rspec = REPEAT_EVERY|REPEAT_EVERY_YEAR // $duration = endTime - startTime //====================================================== // attempt reconfiguration //====================================================== $sql = "SELECT pc_eid, pc_eventDate, pc_startTime, pc_endTime, pc_recurrtype, pc_recurrfreq\n FROM {$events_table}"; $result = $dbconn->Execute($sql); if ($dbconn->ErrorNo() != 0) { die($dbconn->ErrorMsg()); return false; } if (!isset($result)) { return false; } // grab the results and start the conversion for (; !$result->EOF; $result->MoveNext()) { $recurrspec = array(); list($eid, $eventdate, $start, $end, $rtype, $rfreq) = $result->fields; if ($rtype == null) { $rtype = _EVENT_NONE; } switch ($rtype) { case _EVENT_NONE: $recurrtype = NO_REPEAT; $recurrspec['event_repeat_freq'] = 0; $recurrspec['event_repeat_freq_type'] = 0; $recurrspec['event_repeat_on_num'] = 0; $recurrspec['event_repeat_on_day'] = 0; $recurrspec['event_repeat_on_freq'] = 0; break; case _EVENT_DAILY: $recurrtype = REPEAT; $recurrspec['event_repeat_freq'] = REPEAT_EVERY; $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_DAY; $recurrspec['event_repeat_on_num'] = 0; $recurrspec['event_repeat_on_day'] = 0; $recurrspec['event_repeat_on_freq'] = 0; break; case _EVENT_WEEKLY: $recurrtype = REPEAT; $recurrspec['event_repeat_freq'] = REPEAT_EVERY; $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_WEEK; $recurrspec['event_repeat_on_num'] = 0; $recurrspec['event_repeat_on_day'] = 0; $recurrspec['event_repeat_on_freq'] = 0; break; case _EVENT_MONTHLY: if ($rfreq == _RECUR_SAME_DATE) { $recurrtype = REPEAT; $recurrspec['event_repeat_freq'] = REPEAT_EVERY; $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_MONTH; $recurrspec['event_repeat_on_num'] = 0; $recurrspec['event_repeat_on_day'] = 0; $recurrspec['event_repeat_on_freq'] = 0; } elseif ($rfreq == _RECUR_SAME_DAY) { $recurrtype = REPEAT_ON; list($y, $m, $d) = explode('-', $eventdate); $recurrspec['event_repeat_freq'] = 0; $recurrspec['event_repeat_freq_type'] = 0; // event day of week $edow = Date_Calc::dayOfWeek($d, $m, $y); // date of first event day of week $firstDay = Date_Calc::NWeekdayOfMonth(1, $edow, $m, $y, '%Y-%m-%d'); // find difference between 1st day and event day list($y2, $m2, $d2) = explode('-', $firstDay); $diff = Date_Calc::dateDiff($d, $m, $y, $d2, $m2, $y2); // assuming $diff is going to be a multiple of 7 if ($diff > 0) { $diff /= 7; } if ($diff > REPEAT_ON_4TH) { $diff = REPEAT_ON_LAST; } $recurrspec['event_repeat_on_num'] = $diff; $recurrspec['event_repeat_on_day'] = $edow; $recurrspec['event_repeat_on_freq'] = REPEAT_ON_MONTH; } break; case _EVENT_YEARLY: if ($rfreq == _RECUR_SAME_DATE) { $recurrtype = REPEAT; $recurrspec['event_repeat_freq'] = REPEAT_EVERY; $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_YEAR; $recurrspec['event_repeat_on_num'] = 0; $recurrspec['event_repeat_on_day'] = 0; $recurrspec['event_repeat_on_freq'] = 0; } elseif ($rfreq == _RECUR_SAME_DAY) { $recurrtype = REPEAT_ON; list($y, $m, $d) = explode('-', $eventdate); $recurrspec['event_repeat_freq'] = 0; $recurrspec['event_repeat_freq_type'] = 0; // event day of week $edow = Date_Calc::dayOfWeek($d, $m, $y); // date of first event day of week $firstDay = Date_Calc::NWeekdayOfMonth(1, $edow, $m, $y, '%Y-%m-%d'); // find difference between 1st day and event day list($y2, $m2, $d2) = explode('-', $firstDay); $diff = Date_Calc::dateDiff($d, $m, $y, $d2, $m2, $y2); // assuming $diff is going to be a multiple of 7 if ($diff > 0) { $diff /= 7; } if ($diff > REPEAT_ON_4TH) { $diff = REPEAT_ON_LAST; } $recurrspec['event_repeat_on_num'] = $diff; $recurrspec['event_repeat_on_day'] = $edow; $recurrspec['event_repeat_on_freq'] = REPEAT_ON_YEAR; } break; } // ok, figure out the event's duration list($sh, $sm, $ss) = explode(':', $start); list($eh, $em, $es) = explode(':', $end); $stime = mktime($sh, $sm, $ss, 1, 1, 1970); // if the ending hour is less than the starting hour // assume that the event spans to the next day if ($eh < $sh) { $etime = mktime($eh, $em, $es, 1, 2, 1970); } else { $etime = mktime($eh, $em, $es, 1, 1, 1970); } $duration = $etime - $stime; // prep the vars for the sql statement $eid = pnVarPrepForStore($eid); $recurrtype = pnVarPrepForStore($recurrtype); $recurrspec = pnVarPrepForStore(serialize($recurrspec)); // create our sql statement $updatesql = "UPDATE {$events_table} SET \n pc_aid = '0',\n\t\t\t\t\t\t\t pc_recurrtype = {$recurrtype},\n pc_recurrspec = '{$recurrspec}',\n pc_duration = {$duration},\n\t\t\t\t\t\t\t pc_sharing = " . SHARING_GLOBAL . "\n WHERE pc_eid = {$eid}"; // execute our sql statement $dbconn->Execute($updatesql); if ($dbconn->ErrorNo() != 0) { die($dbconn->ErrorMsg()); return false; } // next event please } // all done, proceed with next upgrade step if available/necessary return postcalendar_upgrade('3.1'); break; case '3.1': case '3.1.1': case '3.1.2': case '3.1.3': case '3.1.4': return postcalendar_upgrade('3.9.0'); break; case '3.9.0': case '3.9.1': case '3.9.2': // ading pcSafeMode pnModSetVar(__POSTCALENDAR__, 'pcSafeMode', '0'); return postcalendar_upgrade('3.9.3'); break; case '3.9.3': case '3.9.3.1': // adding indexes $sql = "ALTER TABLE {$events_table} \n\t\t\t\t\tADD INDEX basic_event (pc_catid,pc_aid,pc_eventDate,pc_endDate,pc_eventstatus,pc_sharing,pc_topic)"; $dbconn->Execute($sql); if ($dbconn->ErrorNo() != 0) { die($dbconn->ErrorMsg()); return false; } // adding indexes $sql = "ALTER TABLE {$cat_table} \n\t\t\t\t\tADD INDEX basic_cat (pc_catname, pc_catcolor)"; $dbconn->Execute($sql); if ($dbconn->ErrorNo() != 0) { die($dbconn->ErrorMsg()); return false; } return postcalendar_upgrade('3.9.4'); break; case '3.9.4': case '3.9.5': case '3.9.6': case '3.9.7': return postcalendar_upgrade('3.9.8'); break; case '3.9.8': pnModDelVar(__POSTCALENDAR__, 'pcSafeMode'); pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', '0'); pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', pnConfigGetVar('adminmail')); break; case '3.9.9': break; } // if we get this far - load the userapi and clear the cache if (!pnModAPILoad(__POSTCALENDAR__, 'user')) { return false; } $tpl =& new pcSmarty(); $tpl->clear_all_cache(); $tpl->clear_compiled_tpl(); return true; }