function calculateEvents($days, $events, $viewtype) { $date = postcalendar_getDate(); $cy = substr($date, 0, 4); $cm = substr($date, 4, 2); $cd = substr($date, 6, 2); foreach ($events as $event) { // get the name of the topic $topicname = pcGetTopicName($event['topic']); // parse the event start date list($esY, $esM, $esD) = explode('-', $event['eventDate']); // grab the recurring specs for the event $event_recurrspec = @unserialize($event['recurrspec']); // determine the stop date for this event if ($event['endDate'] == '0000-00-00') { $stop = $end_date; // <--- this isn't previously defined !! } else { $stop = $event['endDate']; } // here the start_date value is set to whatever comes in // on postcalendar_getDate() which is not always the first // date of the days array -- JRM $start_date = "{$cy}-{$cm}-{$cd}"; // here we've made the start_date equal to the first date // of the days array, makes sense, right? -- JRM $days_keys = array_keys($days); $start_date = $days_keys[0]; // Optimization of the stop date to not be much later than required. $tmpsecs = strtotime($start_date); if ($viewtype == 'day') { $tmpsecs += 3 * 24 * 3600; } else { if ($viewtype == 'week') { $tmpsecs += 9 * 24 * 3600; } else { if ($viewtype == 'month') { $tmpsecs += 34 * 24 * 3600; } else { $tmpsecs += 367 * 24 * 3600; } } } $tmp = date('Y-m-d', $tmpsecs); if ($stop > $tmp) { $stop = $tmp; } $eventD = $event['eventDate']; $eventS = $event['startTime']; switch ($event['recurrtype']) { //============================================================== // Events that do not repeat only have a startday //============================================================== case NO_REPEAT: if (isset($days[$event['eventDate']])) { array_push($days[$event['eventDate']], $event); if ($viewtype == "week") { //echo "non repeating date eventdate: $eventD startime:$eventS block #: " . getBlockTime($eventS) ."<br />"; fillBlocks($eventD, $days); //echo "for $eventD loading " . getBlockTime($eventS) . "<br /><br />"; $gbt = getBlockTime($eventS); $days[$eventD]['blocks'][$gbt][$eventD][] = $event; //echo "event is: " . print_r($days[$eventD]['blocks'][$gbt],true) . " <br />"; //echo "begin printing blocks for $eventD<br />"; //print_r($days[$eventD]['blocks']); //echo "end printing blocks<br />"; } } break; //============================================================== // Find events that repeat at a certain frequency // Every,Every Other,Every Third,Every Fourth // Day,Week,Month,Year,MWF,TR,M-F,SS //============================================================== //============================================================== // Find events that repeat at a certain frequency // Every,Every Other,Every Third,Every Fourth // Day,Week,Month,Year,MWF,TR,M-F,SS //============================================================== case REPEAT: $rfreq = $event_recurrspec['event_repeat_freq']; $rtype = $event_recurrspec['event_repeat_freq_type']; $exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http://www.ietf.org/rfc/rfc2445.txt // we should bring the event up to date to make this a tad bit faster // any ideas on how to do that, exactly??? dateToDays probably. $nm = $esM; $ny = $esY; $nd = $esD; $occurance = Date_Calc::dateFormat($nd, $nm, $ny, '%Y-%m-%d'); while ($occurance < $start_date) { $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } while ($occurance <= $stop) { if (isset($days[$occurance])) { // check for date exceptions before pushing the event into the days array -- JRM $excluded = false; if (isset($exdate)) { foreach (explode(",", $exdate) as $exception) { // occurrance format == yyyy-mm-dd // exception format == yyyymmdd if (preg_replace("/-/", "", $occurance) == $exception) { $excluded = true; } } } // push event into the days array if ($excluded == false) { array_push($days[$occurance], $event); } if ($viewtype == "week") { fillBlocks($occurance, $days); //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />"; $gbt = getBlockTime($eventS); $days[$occurance]['blocks'][$gbt][$occurance][] = $event; //echo "begin printing blocks for $eventD<br />"; //print_r($days[$occurance]['blocks']); //echo "end printing blocks<br />"; } } $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } break; //============================================================== // Find events that repeat on certain parameters // On 1st,2nd,3rd,4th,Last // Sun,Mon,Tue,Wed,Thu,Fri,Sat // Every N Months //============================================================== //============================================================== // Find events that repeat on certain parameters // On 1st,2nd,3rd,4th,Last // Sun,Mon,Tue,Wed,Thu,Fri,Sat // Every N Months //============================================================== case REPEAT_ON: $rfreq = $event_recurrspec['event_repeat_on_freq']; $rnum = $event_recurrspec['event_repeat_on_num']; $rday = $event_recurrspec['event_repeat_on_day']; $exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http://www.ietf.org/rfc/rfc2445.txt //============================================================== // Populate - Enter data into the event array //============================================================== $nm = $esM; $ny = $esY; $nd = $esD; if (isset($event_recurrspec['rt2_pf_flag']) && $event_recurrspec['rt2_pf_flag']) { $nd = 1; } // Added by epsdky 2016. // $nd will sometimes be 29, 30 or 31 and if used in the mktime functions // below a problem with overfow will occur so it is set to 1 to prevent this. // (for rt2 appointments set prior to fix it remains unchanged). This can be done // since $nd has no influence past the mktime functions - epsdky 2016. // make us current while ($ny < $cy) { $occurance = date('Y-m-d', mktime(0, 0, 0, $nm + $rfreq, $nd, $ny)); list($ny, $nm, $nd) = explode('-', $occurance); } // populate the event array while ($ny <= $cy) { $dnum = $rnum; // get day event repeats on do { $occurance = Date_Calc::NWeekdayOfMonth($dnum--, $rday, $nm, $ny, $format = "%Y-%m-%d"); } while ($occurance === -1); if (isset($days[$occurance]) && $occurance <= $stop) { // check for date exceptions before pushing the event into the days array -- JRM $excluded = false; if (isset($exdate)) { foreach (explode(",", $exdate) as $exception) { // occurrance format == yyyy-mm-dd // exception format == yyyymmdd if (preg_replace("/-/", "", $occurance) == $exception) { $excluded = true; } } } // push event into the days array if ($excluded == false) { array_push($days[$occurance], $event); } if ($viewtype == "week") { fillBlocks($occurance, $days); //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />"; $gbt = getBlockTime($eventS); $days[$occurance]['blocks'][$gbt][$occurance][] = $event; } } $occurance = date('Y-m-d', mktime(0, 0, 0, $nm + $rfreq, $nd, $ny)); list($ny, $nm, $nd) = explode('-', $occurance); } break; case REPEAT_DAYS: $rfreq = $event_recurrspec['event_repeat_freq']; $rtype = $event_recurrspec['event_repeat_freq_type']; $exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http://www.ietf.org/rfc/rfc2445.txt // we should bring the event up to date to make this a tad bit faster // any ideas on how to do that, exactly??? dateToDays probably. $nm = $esM; $ny = $esY; $nd = $esD; $occurance = Date_Calc::dateFormat($nd, $nm, $ny, '%Y-%m-%d'); while ($occurance < $start_date) { $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } while ($occurance <= $stop) { if (isset($days[$occurance])) { // check for date exceptions before pushing the event into the days array -- JRM $excluded = false; if (isset($exdate)) { foreach (explode(",", $exdate) as $exception) { // occurrance format == yyyy-mm-dd // exception format == yyyymmdd if (preg_replace("/-/", "", $occurance) == $exception) { $excluded = true; } } } // push event into the days array if ($excluded == false) { array_push($days[$occurance], $event); } if ($viewtype == "week") { fillBlocks($occurance, $days); //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />"; $gbt = getBlockTime($eventS); $days[$occurance]['blocks'][$gbt][$occurance][] = $event; //echo "begin printing blocks for $eventD<br />"; //print_r($days[$occurance]['blocks']); //echo "end printing blocks<br />"; } } $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } break; } // <- end of switch($event['recurrtype']) } // <- end of foreach($events as $event) return $days; }
function fetchEvents($from_date, $to_date, $where_param = null, $orderby_param = null, $tracker_board = false, $nextX = 0, $bind_param = null, $query_param = null) { $sqlBindArray = array(); if ($query_param) { $query = $query_param; if ($bind_param) { $sqlBindArray = $bind_param; } } else { ////// if ($nextX) { $where = "((e.pc_endDate >= ? AND e.pc_recurrtype > '0') OR " . "(e.pc_eventDate >= ?))"; array_push($sqlBindArray, $from_date, $from_date); } else { ////// $where = "((e.pc_endDate >= ? AND e.pc_eventDate <= ? AND e.pc_recurrtype > '0') OR " . "(e.pc_eventDate >= ? AND e.pc_eventDate <= ?))"; array_push($sqlBindArray, $from_date, $to_date, $from_date, $to_date); } if ($where_param) { $where .= $where_param; } $order_by = "e.pc_eventDate, e.pc_startTime"; if ($orderby_param) { $order_by = $orderby_param; } // Tracker Board specific stuff $tracker_fields = ''; $tracker_joins = ''; if ($tracker_board) { $tracker_fields = "e.pc_room, e.pc_pid, t.id, t.date, t.apptdate, t.appttime, t.eid, t.pid, t.original_user, t.encounter, t.lastseq, t.random_drug_test, t.drug_screen_completed, " . "q.pt_tracker_id, q.start_datetime, q.room, q.status, q.seq, q.user, " . "s.toggle_setting_1, s.toggle_setting_2, s.option_id, "; $tracker_joins = "LEFT OUTER JOIN patient_tracker AS t ON t.pid = e.pc_pid AND t.apptdate = e.pc_eventDate AND t.appttime = e.pc_starttime AND t.eid = e.pc_eid " . "LEFT OUTER JOIN patient_tracker_element AS q ON q.pt_tracker_id = t.id AND q.seq = t.lastseq " . "LEFT OUTER JOIN list_options AS s ON s.list_id = 'apptstat' AND s.option_id = q.status AND s.activity = 1 "; } $query = "SELECT " . "e.pc_eventDate, e.pc_endDate, e.pc_startTime, e.pc_endTime, e.pc_duration, e.pc_recurrtype, e.pc_recurrspec, e.pc_recurrfreq, e.pc_catid, e.pc_eid, " . "e.pc_title, e.pc_hometext, e.pc_apptstatus, " . "p.fname, p.mname, p.lname, p.pid, p.pubpid, p.phone_home, p.phone_cell, " . "u.fname AS ufname, u.mname AS umname, u.lname AS ulname, u.id AS uprovider_id, " . "f.name, " . "{$tracker_fields}" . "c.pc_catname, c.pc_catid " . "FROM openemr_postcalendar_events AS e " . "{$tracker_joins}" . "LEFT OUTER JOIN facility AS f ON e.pc_facility = f.id " . "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " . "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " . "LEFT OUTER JOIN openemr_postcalendar_categories AS c ON c.pc_catid = e.pc_catid " . "WHERE {$where} " . "ORDER BY {$order_by}"; if ($bind_param) { $sqlBindArray = array_merge($sqlBindArray, $bind_param); } } /////////////////////////////////////////////////////////////////////// // The following code is from the calculateEvents function in the // // PostCalendar Module modified and inserted here by epsdky // /////////////////////////////////////////////////////////////////////// $events2 = array(); $res = sqlStatement($query, $sqlBindArray); //////// if ($nextX) { global $resNotNull; $resNotNull = isset($res) && $res != null; } while ($event = sqlFetchArray($res)) { /////// if ($nextX) { $stopDate = $event['pc_endDate']; } else { $stopDate = $event['pc_endDate'] <= $to_date ? $event['pc_endDate'] : $to_date; } /////// $incX = 0; switch ($event['pc_recurrtype']) { case '0': $events2[] = $event; break; ////// ////// case '1': case '3': $event_recurrspec = @unserialize($event['pc_recurrspec']); $rfreq = $event_recurrspec['event_repeat_freq']; $rtype = $event_recurrspec['event_repeat_freq_type']; $exdate = $event_recurrspec['exdate']; list($ny, $nm, $nd) = explode('-', $event['pc_eventDate']); // $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d'); $occurance = $event['pc_eventDate']; while ($occurance < $from_date) { $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } while ($occurance <= $stopDate) { $excluded = false; if (isset($exdate)) { foreach (explode(",", $exdate) as $exception) { // occurrance format == yyyy-mm-dd // exception format == yyyymmdd if (preg_replace("/-/", "", $occurance) == $exception) { $excluded = true; } } } if ($excluded == false) { $event['pc_eventDate'] = $occurance; $event['pc_endDate'] = '0000-00-00'; $events2[] = $event; ////// if ($nextX) { ++$incX; if ($incX == $nextX) { break; } } ////// } $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } break; ////// ////// case '2': $event_recurrspec = @unserialize($event['pc_recurrspec']); $rfreq = $event_recurrspec['event_repeat_on_freq']; $rnum = $event_recurrspec['event_repeat_on_num']; $rday = $event_recurrspec['event_repeat_on_day']; $exdate = $event_recurrspec['exdate']; list($ny, $nm, $nd) = explode('-', $event['pc_eventDate']); if (isset($event_recurrspec['rt2_pf_flag']) && $event_recurrspec['rt2_pf_flag']) { $nd = 1; } $occuranceYm = "{$ny}-{$nm}"; // YYYY-mm $from_dateYm = substr($from_date, 0, 7); // YYYY-mm $stopDateYm = substr($stopDate, 0, 7); // YYYY-mm // $nd will sometimes be 29, 30 or 31 and if used in the mktime functions below // a problem with overflow will occur so it is set to 1 to avoid this (for rt2 // appointments set prior to fix $nd remains unchanged). This can be done since // $nd has no influence past the mktime functions. while ($occuranceYm < $from_dateYm) { $occuranceYmX = date('Y-m-d', mktime(0, 0, 0, $nm + $rfreq, $nd, $ny)); list($ny, $nm, $nd) = explode('-', $occuranceYmX); $occuranceYm = "{$ny}-{$nm}"; } while ($occuranceYm <= $stopDateYm) { // (YYYY-mm)-dd $dnum = $rnum; do { $occurance = Date_Calc::NWeekdayOfMonth($dnum--, $rday, $nm, $ny, $format = "%Y-%m-%d"); } while ($occurance === -1); if ($occurance >= $from_date && $occurance <= $stopDate) { $excluded = false; if (isset($exdate)) { foreach (explode(",", $exdate) as $exception) { // occurrance format == yyyy-mm-dd // exception format == yyyymmdd if (preg_replace("/-/", "", $occurance) == $exception) { $excluded = true; } } } if ($excluded == false) { $event['pc_eventDate'] = $occurance; $event['pc_endDate'] = '0000-00-00'; $events2[] = $event; ////// if ($nextX) { ++$incX; if ($incX == $nextX) { break; } } ////// } } $occuranceYmX = date('Y-m-d', mktime(0, 0, 0, $nm + $rfreq, $nd, $ny)); list($ny, $nm, $nd) = explode('-', $occuranceYmX); $occuranceYm = "{$ny}-{$nm}"; } break; } } return $events2; ////////////////////// End of code inserted by epsdky }
/** * Build the internal arrays that contain data about holidays. * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { parent::_buildHolidays(); /** * Method that returns the date of the nearest Monday to the specified date * * @return Monday date closest to specified date * */ /** * New Year's Day and Day after New Year's Day * always observed on a working day (1..5) * always show New Year's Day regardless of day of week */ $newYearsDay = new Date($this->_year . '-01-01'); $dayAfterNewYearsDay = new Date($this->_year . '-01-02'); $this->_addHoliday('newYearsDay', $newYearsDay, 'New Year\'s Day'); if ($newYearsDay->getDayOfWeek() == 0) { $this->_addHoliday('dayAfterNewYearsDay', $this->_year . '-01-02', 'Day after New Year\'s Day'); $this->_addHoliday('newYearsDayHoliday', $this->_year . '-01-03', 'New Year\'s Holiday'); } elseif ($newYearsDay->getDayOfWeek() == 5) { $this->_addHoliday('dayAfterNewYearsDay', $this->_year . '-01-04', 'New Year\'s Holiday'); } elseif ($newYearsDay->getDayOfWeek() == 6) { $this->_addHoliday('newYearsDayHoliday', $this->_year . '-01-03', 'New Year\'s Holiday'); $this->_addHoliday('dayAfterNewYearsDay', $this->_year . '-01-04', 'New Year\'s Holiday'); } else { $this->_addHoliday('dayAfterNewYearsDay', $dayAfterNewYearsDay, 'Day after New Year\'s Day'); } /** * Waitangi Day * always observed on 6 February */ $waitangiDay = new Date($this->_year . '-02-06'); $this->_addHoliday('waitangiDay', $waitangiDay, 'Waitangi Day'); /** * Easter */ $easter = Date_Holidays_Driver_Christian::calcEaster($this->_year); $goodFridayDate = new Date($easter); $goodFridayDate = $this->_addDays($easter, -2); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); $this->_addHoliday('easterMonday', $easter->getNextDay(), 'Easter Monday'); /** * Anzac Day * always observed on 25 April * differs from Australia in that there is no working day lost if Anzac Day falls on a weekend */ $anzacDay = new Date($this->_year . '-04-25'); $this->_addHoliday('anzacDay', $anzacDay, 'Anzac Day'); /** * The Queen's Birthday. * always observed on 1st Monday in June */ $queensBirthday = Date_Calc::NWeekdayOfMonth(1, 1, 6, $this->_year); $this->_addHoliday('queensBirthday', $queensBirthday, "Queen\\'s Birthday"); /** * Labour Day. * observed as 4th Monday in October */ $labourDay = Date_Calc::NWeekdayOfMonth(4, 1, 10, $this->_year); $this->_addHoliday('labourDay', $labourDay, "Labour Day"); /** * Christmas and Boxing days * always observed on a working day (1..5) * always show Christmas and Boxing days */ $christmasDay = new Date($this->_year . '-12-25'); $boxingDay = new Date($this->_year . '-12-26'); $this->_addHoliday('christmasDay', $christmasDay, 'Christmas Day'); $this->_addHoliday('boxingDay', $boxingDay, 'Boxing Day'); if ($christmasDay->getDayOfWeek() == 0) { $this->_addHoliday('christmasDayHoliday', $this->_year . '-12-27', 'Christmas Day Holiday'); } elseif ($christmasDay->getDayOfWeek() == 5) { $this->_addHoliday('boxingDayHoliday', $this->_year . '-12-28', 'Boxing Day Holiday'); } elseif ($christmasDay->getDayOfWeek() == 6) { $this->_addHoliday('christmasDayHoliday', $this->_year . '-12-27', 'Christmas Day Holiday'); $this->_addHoliday('boxingDayHoliday', $this->_year . '-12-28', 'Boxing Day Holiday'); } /** * Regional anniversary calculations * http://www.dol.govt.nz/er/holidaysandleave/publicholidays/publicholidaydates/current.asp * ordered by date of observation * Note - where rule may be modified by proximity of Easter, this is NOT taken into account * * Each of 8 regions can use common rule of nearest Monday * Southland 17 Jan * Wellington 22 Jan * Auckland 29 Jan * Nelson 1 Feb * Otago 23 Mar (some local variation) * Marlborough 1 Nov * Chatam Islands 30 Nov * Westland 1 Dec (some local variation) */ $anniversaryDaySd = new Date($this->_year . '-01-17'); $this->_addHoliday('anniversaryDaySd', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDaySd), "Southland Anniversary Day"); $anniversaryDayWn = new Date($this->_year . '-01-22'); $this->_addHoliday('anniversaryDayWn', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayWn), "Wellington Anniversary Day"); $anniversaryDayAk = new Date($this->_year . '-01-29'); $this->_addHoliday('anniversaryDayAk', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayAk), "Auckland Anniversary Day"); $anniversaryDayNn = new Date($this->_year . '-02-01'); $this->_addHoliday('anniversaryDayNn', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayNn), "Nelson Anniversary Day"); $anniversaryDayOo = new Date($this->_year . '-03-23'); $this->_addHoliday('anniversaryDayOo', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayOo), "Otago Anniversary Day"); $anniversaryDayMb = new Date($this->_year . '-11-01'); $this->_addHoliday('anniversaryDayMb', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayMb), "Marlborough Anniversary Day"); $anniversaryDayCi = new Date($this->_year . '-11-30'); $this->_addHoliday('anniversaryDayCi', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayCi), "Chatam Islands Anniversary Day"); $anniversaryDayWd = new Date($this->_year . '-12-01'); $this->_addHoliday('anniversaryDayWd', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayWd), "Westland Anniversary Day"); /** * Taranaki Anniversary. * 2nd Monday in March. */ $anniversaryDayTk = Date_Calc::nWeekdayOfMonth(2, 1, 3, $this->_year); $this->_addHoliday('anniversaryDayTk', $anniversaryDayTk, "Taranaki Anniversary Day"); /** * South Canterbury Anniversary. * 4th Monday in September. */ $anniversaryDaySc = Date_Calc::nWeekdayOfMonth(4, 1, 9, $this->_year); $this->_addHoliday('anniversaryDaySc', $anniversaryDaySc, "South Canterbury Anniversary Day"); /** * Hawkes' Bay Anniversary. * Friday before Labour Day (or 3rd Friday in October). * */ $anniversaryDayHb = Date_Calc::nWeekdayOfMonth(3, 5, 10, $this->_year); $this->_addHoliday('anniversaryDayHb', $anniversaryDayHb, "Hawkes\\' Bay Anniversary"); /** * Canterbury Anniversary or Show Day for North and Central Canterbury. * 2nd Friday after 1st Tuesday in month of November. * find 1st Tuesday then add 10 days */ $anniversaryDayNc = $this->_calcNthWeekDayInMonth(1, 2, 11); $anniversaryDayNc = $this->_addDays($anniversaryDayNc, 10); $this->_addHoliday('anniversaryDayNc', $anniversaryDayNc, "Canterbury Anniversary Day"); /** * Check for errors, and return. */ if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
function fetchEvents($from_date, $to_date, $where_param = null, $orderby_param = null, $tracker_board = false, $flagPSM = false) { ////// if ($flagPSM) { // Patient Summary Mode $where = "((e.pc_endDate >= CURRENT_DATE AND e.pc_recurrtype > '0') OR " . "(e.pc_eventDate >= CURRENT_DATE))"; } else { ////// $where = "((e.pc_endDate >= '{$from_date}' AND e.pc_eventDate <= '{$to_date}' AND e.pc_recurrtype > '0') OR " . "(e.pc_eventDate >= '{$from_date}' AND e.pc_eventDate <= '{$to_date}'))"; } if ($where_param) { $where .= $where_param; } $order_by = "e.pc_eventDate, e.pc_startTime"; if ($orderby_param) { $order_by = $orderby_param; } // Tracker Board specific stuff $tracker_fields = ''; $tracker_joins = ''; if ($tracker_board) { $tracker_fields = "e.pc_room, e.pc_pid, t.id, t.date, t.apptdate, t.appttime, t.eid, t.pid, t.original_user, t.encounter, t.lastseq, t.random_drug_test, t.drug_screen_completed, " . "q.pt_tracker_id, q.start_datetime, q.room, q.status, q.seq, q.user, " . "s.toggle_setting_1, s.toggle_setting_2, s.option_id, "; $tracker_joins = "LEFT OUTER JOIN patient_tracker AS t ON t.pid = e.pc_pid AND t.apptdate = e.pc_eventDate AND t.appttime = e.pc_starttime AND t.eid = e.pc_eid " . "LEFT OUTER JOIN patient_tracker_element AS q ON q.pt_tracker_id = t.id AND q.seq = t.lastseq " . "LEFT OUTER JOIN list_options AS s ON s.list_id = 'apptstat' AND s.option_id = q.status "; } $query = "SELECT " . "e.pc_eventDate, e.pc_endDate, e.pc_startTime, e.pc_endTime, e.pc_duration, e.pc_recurrtype, e.pc_recurrspec, e.pc_recurrfreq, e.pc_catid, e.pc_eid, " . "e.pc_title, e.pc_hometext, e.pc_apptstatus, " . "p.fname, p.mname, p.lname, p.pid, p.pubpid, p.phone_home, p.phone_cell, " . "u.fname AS ufname, u.mname AS umname, u.lname AS ulname, u.id AS uprovider_id, " . "{$tracker_fields}" . "c.pc_catname, c.pc_catid " . "FROM openemr_postcalendar_events AS e " . "{$tracker_joins}" . "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " . "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " . "LEFT OUTER JOIN openemr_postcalendar_categories AS c ON c.pc_catid = e.pc_catid " . "WHERE {$where} " . "ORDER BY {$order_by}"; /////////////////////////////////////////////////////////////////////// // The following code is from the calculateEvents function in the // PostCalendar Module modified and inserted here by epsdky $events2 = array(); $res = sqlStatement($query); //////// if ($flagPSM) { // Patient Summary Mode global $resNotNull; $resNotNull = isset($res) && $res != null; } while ($event = sqlFetchArray($res)) { /////// if ($flagPSM) { $stopDate = $event['pc_endDate']; } else { $stopDate = $event['pc_endDate'] <= $to_date ? $event['pc_endDate'] : $to_date; } /////// switch ($event['pc_recurrtype']) { case '0': $events2[] = $event; break; ////// ////// case '1': $event_recurrspec = @unserialize($event['pc_recurrspec']); $rfreq = $event_recurrspec['event_repeat_freq']; $rtype = $event_recurrspec['event_repeat_freq_type']; $exdate = $event_recurrspec['exdate']; list($ny, $nm, $nd) = explode('-', $event['pc_eventDate']); // $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d'); $occurance = $event['pc_eventDate']; while ($occurance < $from_date) { $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } while ($occurance <= $stopDate) { $excluded = false; if (isset($exdate)) { foreach (explode(",", $exdate) as $exception) { // occurrance format == yyyy-mm-dd // exception format == yyyymmdd if (preg_replace("/-/", "", $occurance) == $exception) { $excluded = true; } } } if ($excluded == false) { $event['pc_eventDate'] = $occurance; $event['pc_endDate'] = '0000-00-00'; $events2[] = $event; ////// if ($flagPSM) { break; } ////// } $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype); list($ny, $nm, $nd) = explode('-', $occurance); } break; ////// ////// case '2': $event_recurrspec = @unserialize($event['pc_recurrspec']); $rfreq = $event_recurrspec['event_repeat_on_freq']; $rnum = $event_recurrspec['event_repeat_on_num']; $rday = $event_recurrspec['event_repeat_on_day']; $exdate = $event_recurrspec['exdate']; list($ny, $nm, $nd) = explode('-', $event['pc_eventDate']); $occuranceYm = "{$ny}-{$nm}"; // YYYY-mm $from_dateYm = substr($from_date, 0, 7); // YYYY-mm $stopDateYm = substr($stopDate, 0, 7); // YYYY-mm // $nd will sometimes be 29, 30 or 31, and if used in mktime below, a problem // with overflow will occur ('01' should be plugged in to avoid this). We need // to mirror the calendar code which has this problem, so $nd has been used. while ($occuranceYm < $from_dateYm) { $occuranceYmX = date('Y-m-d', mktime(0, 0, 0, $nm + $rfreq, $nd, $ny)); list($ny, $nm, $nd) = explode('-', $occuranceYmX); $occuranceYm = "{$ny}-{$nm}"; } while ($occuranceYm <= $stopDateYm) { // (YYYY-mm)-dd $dnum = $rnum; do { $occurance = Date_Calc::NWeekdayOfMonth($dnum--, $rday, $nm, $ny, $format = "%Y-%m-%d"); } while ($occurance === -1); if ($occurance >= $from_date && $occurance <= $stopDate) { $excluded = false; if (isset($exdate)) { foreach (explode(",", $exdate) as $exception) { // occurrance format == yyyy-mm-dd // exception format == yyyymmdd if (preg_replace("/-/", "", $occurance) == $exception) { $excluded = true; } } } if ($excluded == false) { $event['pc_eventDate'] = $occurance; $event['pc_endDate'] = '0000-00-00'; $events2[] = $event; ////// if ($flagPSM) { break; } ////// } } $occuranceYmX = date('Y-m-d', mktime(0, 0, 0, $nm + $rfreq, $nd, $ny)); list($ny, $nm, $nd) = explode('-', $occuranceYmX); $occuranceYm = "{$ny}-{$nm}"; } break; } } return $events2; ////////////////////// End of code inserted by epsdky }
public function MakeRecurrences() { global $_EV_CONF; $intervalA = $this->event->rec_data['interval']; if (!is_array($intervalA)) { $intervalA = array($intervalA); } if (!isset($this->event->rec_data['weekday'])) { // Missing day of week return $this->events; } $occurrence = $this->dt_start; list($y, $m, $d) = explode('-', $occurrence); $num_intervals = count($intervalA); $last_interval = $intervalA[$num_intervals - 1]; $count = 0; // reduce the weekday number, since evlist uses Sun=1 while // Date_Calc uses Sun=0 $datecalc_weekday = (int) $this->event->rec_data['weekday'] - 1; while ($occurrence <= $this->event->rec_data['stop'] && $occurrence >= '1971-01-01' && $count < $_EV_CONF['max_repeats']) { foreach ($intervalA as $interval) { $occurrence = Date_Calc::NWeekdayOfMonth((int) $interval, $datecalc_weekday, $m, $y, '%Y-%m-%d'); // Skip any dates earlier than the starting date if ($occurrence < $this->dt_start) { continue; } // If the new date goes past the end of month, and we're looking // for the last (5th) week, then re-adjust to use the 4th week. // If we already have a 4th, this will just overwrite it if ($occurrence == -1 && $interval == 5) { $occurrence = Date_Calc::NWeekdayOfMonth(4, $datecalc_weekday, $m, $y, '%Y-%m-%d'); } // Stop when we hit the stop date if ($occurrence > $this->event->rec_data['stop']) { break; } // This occurrence is ok, save it $this->storeEvent($occurrence); $count++; list($y, $m, $d) = explode('-', $occurrence); } // foreach intervalA // We've gone through all the intervals this month, now // increment the month $m += $this->event->rec_data['freq']; if ($m > 12) { // Roll over to next year $y += 1; $m = $m - 12; } } // while not at stop date return $this->events; }
compare('20050113', Date_Calc::NWeekdayOfMonth('2', '4', '01', '2005'), 'NWeekdayOfMonth 241'); compare('20050114', Date_Calc::NWeekdayOfMonth('2', '5', '01', '2005'), 'NWeekdayOfMonth 251'); compare('20050131', Date_Calc::NWeekdayOfMonth('last', 1, 1, 2005), 'NWeekdayOfMonth l11'); compare('20050130', Date_Calc::NWeekdayOfMonth('last', 0, 1, 2005), 'NWeekdayOfMonth l01'); compare('20050129', Date_Calc::NWeekdayOfMonth('last', 6, 1, 2005), 'NWeekdayOfMonth l61'); compare('20050128', Date_Calc::NWeekdayOfMonth('last', 5, 1, 2005), 'NWeekdayOfMonth l51'); compare('20050127', Date_Calc::NWeekdayOfMonth('last', 4, 1, 2005), 'NWeekdayOfMonth l41'); compare('20050126', Date_Calc::NWeekdayOfMonth('last', 3, 1, 2005), 'NWeekdayOfMonth l31'); compare('20050125', Date_Calc::NWeekdayOfMonth('last', 2, 1, 2005), 'NWeekdayOfMonth l21'); compare('20050331', Date_Calc::NWeekdayOfMonth('last', 4, 3, 2005), 'NWeekdayOfMonth l43'); compare('20050330', Date_Calc::NWeekdayOfMonth('last', 3, 3, 2005), 'NWeekdayOfMonth l33'); compare('20050329', Date_Calc::NWeekdayOfMonth('last', 2, 3, 2005), 'NWeekdayOfMonth l23'); compare('20050328', Date_Calc::NWeekdayOfMonth('last', 1, 3, 2005), 'NWeekdayOfMonth l13'); compare('20050327', Date_Calc::NWeekdayOfMonth('last', 0, 3, 2005), 'NWeekdayOfMonth l03'); compare('20050326', Date_Calc::NWeekdayOfMonth('last', 6, 3, 2005), 'NWeekdayOfMonth l63'); compare('20050325', Date_Calc::NWeekdayOfMonth('last', 5, 3, 2005), 'NWeekdayOfMonth l53'); compare(false, Date_Calc::isValidDate(29, 2, 1900), 'isValidDate 1'); compare(true, Date_Calc::isValidDate(29, 2, 2000), 'isValidDate 2'); compare(true, Date_Calc::isValidDate('29', '02', '2000'), 'isValidDate 2 str'); compare(false, Date_Calc::isLeapYear(1900), 'isLeapYear 1'); compare(true, Date_Calc::isLeapYear(1996), 'isLeapYear 2'); compare(true, Date_Calc::isLeapYear(2000), 'isLeapYear 3'); compare(false, Date_Calc::isLeapYear(2001), 'isLeapYear 4'); compare(false, Date_Calc::isLeapYear('2001'), 'isLeapYear 4 str'); compare(false, Date_Calc::isFutureDate('22', '11', '2000'), 'isFutureDate 1 str'); compare(false, Date_Calc::isFutureDate(22, 11, 2000), 'isFutureDate 1'); compare(true, Date_Calc::isFutureDate(22, 11, date('Y') + 1), 'isFutureDate 2'); compare(false, Date_Calc::isPastDate(22, 11, date('Y') + 1), 'isPastDate 1'); compare(true, Date_Calc::isPastDate(22, 11, 2000), 'isPastDate 2'); compare(true, Date_Calc::isPastDate('22', '11', '2000'), 'isPastDate 2 str'); compare(10, Date_Calc::dateDiff(22, 11, 2000, 12, 11, 2000), 'dateDiff 1');
/** * 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; }