MedEx Updates
[openemr.git] / library / appointments.inc.php
blob1c74405f3215eecf9a8b1a92cb5966202386a88a
1 <?php
3 // Copyright (C) 2011 Ken Chapple
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // Holds library functions (and hashes) used by the appointment reporting module
14 require_once(dirname(__FILE__)."/encounter_events.inc.php");
15 require_once(dirname(__FILE__)."/../interface/main/calendar/modules/PostCalendar/pnincludes/Date/Calc.php");
18 $COMPARE_FUNCTION_HASH = array(
19 'doctor' => 'compareAppointmentsByDoctorName',
20 'patient' => 'compareAppointmentsByPatientName',
21 'pubpid' => 'compareAppointmentsByPatientId',
22 'date' => 'compareAppointmentsByDate',
23 'time' => 'compareAppointmentsByTime',
24 'type' => 'compareAppointmentsByType',
25 'comment' => 'compareAppointmentsByComment',
26 'status' => 'compareAppointmentsByStatus',
27 'completed' => 'compareAppointmentsByCompletedDrugScreen',
28 'trackerstatus' => 'compareAppointmentsByTrackerStatus'
31 $ORDERHASH = array(
32 'doctor' => array( 'doctor', 'date', 'time' ),
33 'patient' => array( 'patient', 'date', 'time' ),
34 'pubpid' => array( 'pubpid', 'date', 'time' ),
35 'date' => array( 'date', 'time', 'type', 'patient' ),
36 'time' => array( 'time', 'date', 'patient' ),
37 'type' => array( 'type', 'date', 'time', 'patient' ),
38 'comment' => array( 'comment', 'date', 'time', 'patient' ),
39 'status' => array( 'status', 'date', 'time', 'patient' ),
40 'completed' => array( 'completed', 'date', 'time', 'patient' ),
41 'trackerstatus' => array( 'trackerstatus', 'date', 'time', 'patient' ),
44 /*Arrays for the interpretation of recurrence patterns.*/
45 $REPEAT_FREQ = array(
46 '1' => xl('Every'),
47 '2' => xl('Every 2nd'),
48 '3' => xl('Every 3rd'),
49 '4' => xl('Every 4th'),
50 '5' => xl('Every 5th'),
51 '6' => xl('Every 6th')
54 $REPEAT_FREQ_TYPE = array(
55 '0' => xl('day'),
56 '1' => xl('week'),
57 '2' => xl('month'),
58 '3' => xl('year'),
59 '4' => xl('workday')
62 $REPEAT_ON_NUM = array(
63 '1' => xl('1st'),
64 '2' => xl('2nd'),
65 '3' => xl('3rd'),
66 '4' => xl('4th'),
67 '5' => xl('Last')
70 $REPEAT_ON_DAY = array(
71 '0' => xl('Sunday'),
72 '1' => xl('Monday'),
73 '2' => xl('Tuesday'),
74 '3' => xl('Wednesday'),
75 '4' => xl('Thursday'),
76 '5' => xl('Friday'),
77 '6' => xl('Saturday')
80 function checkEvent($recurrtype, $recurrspec)
83 $eFlag = 0;
85 switch ($recurrtype) {
86 case 1:
87 case 3:
88 if (empty($recurrspec['event_repeat_freq']) || !isset($recurrspec['event_repeat_freq_type'])) {
89 $eFlag = 1; }
91 break;
93 case 2:
94 if (empty($recurrspec['event_repeat_on_freq']) || empty($recurrspec['event_repeat_on_num']) || !isset($recurrspec['event_repeat_on_day'])) {
95 $eFlag = 1; }
97 break;
100 return $eFlag;
103 function fetchEvents($from_date, $to_date, $where_param = null, $orderby_param = null, $tracker_board = false, $nextX = 0, $bind_param = null, $query_param = null)
106 $sqlBindArray = array();
108 if ($query_param) {
109 $query = $query_param;
111 if ($bind_param) {
112 $sqlBindArray = $bind_param;
114 } else {
115 //////
116 if ($nextX) {
117 $where =
118 "((e.pc_endDate >= ? AND e.pc_recurrtype > '0') OR " .
119 "(e.pc_eventDate >= ?))";
121 array_push($sqlBindArray, $from_date, $from_date);
122 } else {
123 //////
124 $where =
125 "((e.pc_endDate >= ? AND e.pc_eventDate <= ? AND e.pc_recurrtype > '0') OR " .
126 "(e.pc_eventDate >= ? AND e.pc_eventDate <= ?))";
128 array_push($sqlBindArray, $from_date, $to_date, $from_date, $to_date);
131 if ($where_param) {
132 $where .= $where_param;
135 $order_by = "e.pc_eventDate, e.pc_startTime";
136 if ($orderby_param) {
137 $order_by = $orderby_param;
140 // Tracker Board specific stuff
141 $tracker_fields = '';
142 $tracker_joins = '';
143 if ($tracker_board) {
144 $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, " .
145 "q.pt_tracker_id, q.start_datetime, q.room, q.status, q.seq, q.user, " .
146 "s.toggle_setting_1, s.toggle_setting_2, s.option_id, ";
147 $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 " .
148 "LEFT OUTER JOIN patient_tracker_element AS q ON q.pt_tracker_id = t.id AND q.seq = t.lastseq " .
149 "LEFT OUTER JOIN list_options AS s ON s.list_id = 'apptstat' AND s.option_id = q.status AND s.activity = 1 " ;
152 $query = "SELECT " .
153 "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_gid, " .
154 "e.pc_title, e.pc_hometext, e.pc_apptstatus, " .
155 "p.fname, p.mname, p.lname, p.pid, p.pubpid, p.phone_home, p.phone_cell, " .
156 "p.hipaa_allowsms, p.phone_home, p.phone_cell, p.hipaa_voice, p.hipaa_allowemail, p.email, " .
157 "u.fname AS ufname, u.mname AS umname, u.lname AS ulname, u.id AS uprovider_id, " .
158 "f.name, " .
159 "$tracker_fields" .
160 "c.pc_catname, c.pc_catid, e.pc_facility " .
161 "FROM openemr_postcalendar_events AS e " .
162 "$tracker_joins" .
163 "LEFT OUTER JOIN facility AS f ON e.pc_facility = f.id " .
164 "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " .
165 "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " .
166 "LEFT OUTER JOIN openemr_postcalendar_categories AS c ON c.pc_catid = e.pc_catid " .
167 "WHERE $where " .
168 "ORDER BY $order_by";
170 if ($bind_param) {
171 $sqlBindArray = array_merge($sqlBindArray, $bind_param);
176 ///////////////////////////////////////////////////////////////////////
177 // The following code is from the calculateEvents function in the //
178 // PostCalendar Module modified and inserted here by epsdky //
179 ///////////////////////////////////////////////////////////////////////
181 $events2 = array();
183 $res = sqlStatement($query, $sqlBindArray);
185 ////////
186 if ($nextX) {
187 global $resNotNull;
188 $resNotNull = (isset($res) && $res != null);
191 while ($event = sqlFetchArray($res)) {
192 ///////
193 if ($nextX) {
194 $stopDate = $event['pc_endDate'];
195 } else {
196 $stopDate = ($event['pc_endDate'] <= $to_date) ? $event['pc_endDate'] : $to_date;
199 ///////
200 $incX = 0;
201 switch ($event['pc_recurrtype']) {
202 case '0':
203 $events2[] = $event;
205 break;
206 //////
207 case '1':
208 case '3':
209 $event_recurrspec = @unserialize($event['pc_recurrspec']);
211 if (checkEvent($event['pc_recurrtype'], $event_recurrspec)) {
212 break; }
214 $rfreq = $event_recurrspec['event_repeat_freq'];
215 $rtype = $event_recurrspec['event_repeat_freq_type'];
216 $exdate = $event_recurrspec['exdate'];
218 list($ny,$nm,$nd) = explode('-', $event['pc_eventDate']);
219 // $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d');
220 $occurance = $event['pc_eventDate'];
222 while ($occurance < $from_date) {
223 $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype);
224 list($ny,$nm,$nd) = explode('-', $occurance);
227 while ($occurance <= $stopDate) {
228 $excluded = false;
229 if (isset($exdate)) {
230 foreach (explode(",", $exdate) as $exception) {
231 // occurrance format == yyyy-mm-dd
232 // exception format == yyyymmdd
233 if (preg_replace("/-/", "", $occurance) == $exception) {
234 $excluded = true;
239 if ($excluded == false) {
240 $event['pc_eventDate'] = $occurance;
241 $event['pc_endDate'] = '0000-00-00';
242 $events2[] = $event;
243 //////
244 if ($nextX) {
245 ++$incX;
246 if ($incX == $nextX) {
247 break;
251 //////
254 $occurance =& __increment($nd, $nm, $ny, $rfreq, $rtype);
255 list($ny,$nm,$nd) = explode('-', $occurance);
257 break;
259 //////
260 case '2':
261 $event_recurrspec = @unserialize($event['pc_recurrspec']);
263 if (checkEvent($event['pc_recurrtype'], $event_recurrspec)) {
264 break; }
266 $rfreq = $event_recurrspec['event_repeat_on_freq'];
267 $rnum = $event_recurrspec['event_repeat_on_num'];
268 $rday = $event_recurrspec['event_repeat_on_day'];
269 $exdate = $event_recurrspec['exdate'];
271 list($ny,$nm,$nd) = explode('-', $event['pc_eventDate']);
273 if (isset($event_recurrspec['rt2_pf_flag']) && $event_recurrspec['rt2_pf_flag']) {
274 $nd = 1;
277 $occuranceYm = "$ny-$nm"; // YYYY-mm
278 $from_dateYm = substr($from_date, 0, 7); // YYYY-mm
279 $stopDateYm = substr($stopDate, 0, 7); // YYYY-mm
281 // $nd will sometimes be 29, 30 or 31 and if used in the mktime functions below
282 // a problem with overflow will occur so it is set to 1 to avoid this (for rt2
283 // appointments set prior to fix $nd remains unchanged). This can be done since
284 // $nd has no influence past the mktime functions.
285 while ($occuranceYm < $from_dateYm) {
286 $occuranceYmX = date('Y-m-d', mktime(0, 0, 0, $nm+$rfreq, $nd, $ny));
287 list($ny,$nm,$nd) = explode('-', $occuranceYmX);
288 $occuranceYm = "$ny-$nm";
291 while ($occuranceYm <= $stopDateYm) {
292 // (YYYY-mm)-dd
293 $dnum = $rnum;
294 do {
295 $occurance = Date_Calc::NWeekdayOfMonth($dnum--, $rday, $nm, $ny, $format = "%Y-%m-%d");
296 } while ($occurance === -1);
298 if ($occurance >= $from_date && $occurance <= $stopDate) {
299 $excluded = false;
300 if (isset($exdate)) {
301 foreach (explode(",", $exdate) as $exception) {
302 // occurrance format == yyyy-mm-dd
303 // exception format == yyyymmdd
304 if (preg_replace("/-/", "", $occurance) == $exception) {
305 $excluded = true;
310 if ($excluded == false) {
311 $event['pc_eventDate'] = $occurance;
312 $event['pc_endDate'] = '0000-00-00';
313 $events2[] = $event;
314 //////
315 if ($nextX) {
316 ++$incX;
317 if ($incX == $nextX) {
318 break;
322 //////
326 $occuranceYmX = date('Y-m-d', mktime(0, 0, 0, $nm+$rfreq, $nd, $ny));
327 list($ny,$nm,$nd) = explode('-', $occuranceYmX);
328 $occuranceYm = "$ny-$nm";
330 break;
334 return $events2;
335 ////////////////////// End of code inserted by epsdky
338 function fetchAllEvents($from_date, $to_date, $provider_id = null, $facility_id = null)
340 $sqlBindArray = array();
342 $where = "";
344 if ($provider_id) {
345 $where .= " AND e.pc_aid = ?";
346 array_push($sqlBindArray, $provider_id);
349 if ($facility_id) {
350 $where .= " AND e.pc_facility = ? AND u.facility_id = ?";
351 array_push($sqlBindArray, $facility_id, $facility_id);
354 $appointments = fetchEvents($from_date, $to_date, $where, null, false, 0, $sqlBindArray);
355 return $appointments;
358 //Support for therapy group appointments added by shachar z.
359 function fetchAppointments($from_date, $to_date, $patient_id = null, $provider_id = null, $facility_id = null, $pc_appstatus = null, $with_out_provider = null, $with_out_facility = null, $pc_catid = null, $tracker_board = false, $nextX = 0, $group_id = null, $patient_name = null)
361 $sqlBindArray = array();
363 $where = "";
365 if ($provider_id) {
366 $where .= " AND e.pc_aid = ?";
367 array_push($sqlBindArray, $provider_id);
370 if ($patient_id) {
371 $where .= " AND e.pc_pid = ?";
372 array_push($sqlBindArray, $patient_id);
373 } elseif ($group_id) {
374 //if $group_id this means we want only the group events
375 $where .= " AND e.pc_gid = ? AND e.pc_pid = ''";
376 array_push($sqlBindArray, $group_id);
377 } else {
378 $where .= " AND e.pc_pid != ''";
381 if ($facility_id) {
382 $where .= " AND e.pc_facility = ?";
383 array_push($sqlBindArray, $facility_id);
386 //Appointment Status Checking
387 if ($pc_appstatus != '') {
388 $where .= " AND e.pc_apptstatus = ?";
389 array_push($sqlBindArray, $pc_appstatus);
392 if ($pc_catid != null) {
393 $where .= " AND e.pc_catid = ?";
394 array_push($sqlBindArray, $pc_catid);
397 if ($patient_name != null) {
398 $where .= " AND (p.fname LIKE CONCAT('%',?,'%') OR p.lname LIKE CONCAT('%',?,'%'))";
399 array_push($sqlBindArray, $patient_name, $patient_name);
402 //Without Provider checking
403 if ($with_out_provider != '') {
404 $where .= " AND e.pc_aid = ''";
407 //Without Facility checking
408 if ($with_out_facility != '') {
409 $where .= " AND e.pc_facility = 0";
412 $appointments = fetchEvents($from_date, $to_date, $where, '', $tracker_board, $nextX, $sqlBindArray);
413 return $appointments;
416 //Support for therapy group appointments added by shachar z.
417 function fetchNextXAppts($from_date, $patient_id, $nextX = 1, $group_id = null)
420 $appts = array();
421 $nextXAppts = array();
422 $appts = fetchAppointments($from_date, null, $patient_id, null, null, null, null, null, null, false, $nextX, $group_id);
423 if ($appts) {
424 $appts = sortAppointments($appts);
425 $nextXAppts = array_slice($appts, 0, $nextX);
428 return $nextXAppts;
431 // get the event slot size in seconds
432 function getSlotSize()
434 if (isset($GLOBALS['calendar_interval'])) {
435 return $GLOBALS['calendar_interval'] * 60;
438 return 15 * 60;
441 function getAvailableSlots($from_date, $to_date, $provider_id = null, $facility_id = null)
443 $appointments = fetchAllEvents($from_date, $to_date, $provider_id, $facility_id);
444 $appointments = sortAppointments($appointments, "date");
445 $from_datetime = strtotime($from_date." 00:00:00");
446 $to_datetime = strtotime($to_date." 23:59:59");
447 $availableSlots = array();
448 $start_time = 0;
449 $date = 0;
450 for ($i = 0; $i < count($appointments); ++$i) {
451 if ($appointments[$i]['pc_catid'] == 2) { // 2 == In Office
452 $start_time = $appointments[$i]['pc_startTime'];
453 $date = $appointments[$i]['pc_eventDate'];
454 $provider_id = $appointments[$i]['uprovider_id'];
455 } else if ($appointments[$i]['pc_catid'] == 3) { // 3 == Out Of Office
456 continue;
457 } else {
458 $start_time = $appointments[$i]['pc_endTime'];
459 $date = $appointments[$i]['pc_eventDate'];
460 $provider_id = $appointments[$i]['uprovider_id'];
463 // find next appointment with the same provider
464 $next_appointment_date = 0;
465 $next_appointment_time = 0;
466 for ($j = $i+1; $j < count($appointments); ++$j) {
467 if ($appointments[$j]['uprovider_id'] == $provider_id) {
468 $next_appointment_date = $appointments[$j]['pc_eventDate'];
469 $next_appointment_time = $appointments[$j]['pc_startTime'];
470 break;
474 $same_day = ( strtotime($next_appointment_date) == strtotime($date) ) ? true : false;
476 if ($next_appointment_time && $same_day) {
477 // check the start time of the next appointment
479 $start_datetime = strtotime($date." ".$start_time);
480 $next_appointment_datetime = strtotime($next_appointment_date." ".$next_appointment_time);
481 $curr_time = $start_datetime;
482 while ($curr_time < $next_appointment_datetime - (getSlotSize() / 2)) {
483 //create a new appointment ever 15 minutes
484 $time = date("H:i:s", $curr_time);
485 $available_slot = createAvailableSlot(
486 $appointments[$i]['pc_eventDate'],
487 $time,
488 $appointments[$i]['ufname'],
489 $appointments[$i]['ulname'],
490 $appointments[$i]['umname']
492 $availableSlots []= $available_slot;
493 $curr_time += getSlotSize(); // add a 15-minute slot
498 return $availableSlots;
501 function createAvailableSlot($event_date, $start_time, $provider_fname, $provider_lname, $provider_mname = "", $cat_name = "Available")
503 $newSlot = array();
504 $newSlot['ulname'] = $provider_lname;
505 $newSlot['ufname'] = $provider_fname;
506 $newSlot['umname'] = $provider_mname;
507 $newSlot['pc_eventDate'] = $event_date;
508 $newSlot['pc_startTime'] = $start_time;
509 $newSlot['pc_endTime'] = $start_time;
510 $newSlot['pc_catname'] = $cat_name;
511 return $newSlot;
514 function getCompareFunction($code)
516 global $COMPARE_FUNCTION_HASH;
517 return $COMPARE_FUNCTION_HASH[$code];
520 function getComparisonOrder($code)
522 global $ORDERHASH;
523 return $ORDERHASH[$code];
527 function sortAppointments(array $appointments, $orderBy = 'date')
529 global $appointment_sort_order;
530 $appointment_sort_order = $orderBy;
531 usort($appointments, "compareAppointments");
532 return $appointments;
535 // cmp_function for usort
536 // The comparison function must return an integer less than, equal to,
537 // or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
538 function compareAppointments($appointment1, $appointment2)
540 global $appointment_sort_order;
541 $comparisonOrder = getComparisonOrder($appointment_sort_order);
542 foreach ($comparisonOrder as $comparison) {
543 $cmp_function = getCompareFunction($comparison);
544 $result = $cmp_function($appointment1, $appointment2);
545 if (0 != $result) {
546 return $result;
550 return 0;
553 function compareBasic($e1, $e2)
555 if ($e1 < $e2) {
556 return -1;
557 } else if ($e1 > $e2) {
558 return 1;
561 return 0;
564 function compareAppointmentsByDate($appointment1, $appointment2)
566 $date1 = strtotime($appointment1['pc_eventDate']);
567 $date2 = strtotime($appointment2['pc_eventDate']);
569 return compareBasic($date1, $date2);
572 function compareAppointmentsByTime($appointment1, $appointment2)
574 $time1 = strtotime($appointment1['pc_startTime']);
575 $time2 = strtotime($appointment2['pc_startTime']);
577 return compareBasic($time1, $time2);
580 function compareAppointmentsByDoctorName($appointment1, $appointment2)
582 $name1 = $appointment1['ulname'];
583 $name2 = $appointment2['ulname'];
584 $cmp = compareBasic($name1, $name2);
585 if ($cmp == 0) {
586 $name1 = $appointment1['ufname'];
587 $name2 = $appointment2['ufname'];
588 return compareBasic($name1, $name2);
591 return $cmp;
594 function compareAppointmentsByPatientName($appointment1, $appointment2)
596 $name1 = $appointment1['lname'];
597 $name2 = $appointment2['lname'];
598 $cmp = compareBasic($name1, $name2);
599 if ($cmp == 0) {
600 $name1 = $appointment1['fname'];
601 $name2 = $appointment2['fname'];
602 return compareBasic($name1, $name2);
605 return $cmp;
608 function compareAppointmentsByType($appointment1, $appointment2)
610 $type1 = $appointment1['pc_catid'];
611 $type2 = $appointment2['pc_catid'];
612 return compareBasic($type1, $type2);
615 function compareAppointmentsByPatientId($appointment1, $appointment2)
617 $id1 = $appointment1['pubpid'];
618 $id2 = $appointment2['pubpid'];
619 return compareBasic($id1, $id2);
622 function compareAppointmentsByComment($appointment1, $appointment2)
624 $comment1 = $appointment1['pc_hometext'];
625 $comment2 = $appointment2['pc_hometext'];
626 return compareBasic($comment1, $comment2);
629 function compareAppointmentsByStatus($appointment1, $appointment2)
631 $status1 = $appointment1['pc_apptstatus'];
632 $status2 = $appointment2['pc_apptstatus'];
633 return compareBasic($status1, $status2);
636 function compareAppointmentsByTrackerStatus($appointment1, $appointment2)
638 $trackerstatus1 = $appointment1['status'];
639 $trackerstatus2 = $appointment2['status'];
640 return compareBasic($trackerstatus1, $trackerstatus2);
643 function compareAppointmentsByCompletedDrugScreen($appointment1, $appointment2)
645 $completed1 = $appointment1['drug_screen_completed'];
646 $completed2 = $appointment2['drug_screen_completed'];
647 return compareBasic($completed1, $completed2);
650 function fetchAppointmentCategories()
652 $catSQL= " SELECT pc_catid as id, pc_catname as category "
653 . " FROM openemr_postcalendar_categories WHERE pc_active=1 and pc_recurrtype=0 and pc_cattype=0";
654 if ($GLOBALS['enable_group_therapy']) {
655 $catSQL .= " OR pc_cattype=3";
658 $catSQL .= " ORDER BY category";
659 return sqlStatement($catSQL);
662 function interpretRecurrence($recurr_freq, $recurr_type)
664 global $REPEAT_FREQ, $REPEAT_FREQ_TYPE, $REPEAT_ON_NUM, $REPEAT_ON_DAY;
665 $interpreted = "";
666 $recurr_freq = unserialize($recurr_freq);
667 if ($recurr_type == 1) {
668 $interpreted = $REPEAT_FREQ[$recurr_freq['event_repeat_freq']];
669 $interpreted .= " " . $REPEAT_FREQ_TYPE[$recurr_freq['event_repeat_freq_type']];
670 } elseif ($recurr_type == 2) {
671 $interpreted = $REPEAT_FREQ[$recurr_freq['event_repeat_on_freq']];
672 $interpreted .= " " . $REPEAT_ON_NUM[$recurr_freq['event_repeat_on_num']];
673 $interpreted .= " " . $REPEAT_ON_DAY[$recurr_freq['event_repeat_on_day']];
674 } elseif ($recurr_type == 3) {
675 $interpreted = $REPEAT_FREQ[1];
676 $comma = "";
677 $day_arr = explode(",", $recurr_freq['event_repeat_freq']);
678 foreach ($day_arr as $day) {
679 $interpreted .= $comma . " " . $REPEAT_ON_DAY[$day - 1];
680 $comma = ",";
684 return $interpreted;
687 function fetchRecurrences($pid)
689 $query = "SELECT pe.pc_title, pe.pc_endDate, pe.pc_recurrtype, pe.pc_recurrspec, pc.pc_catname FROM openemr_postcalendar_events AS pe "
690 . "JOIN openemr_postcalendar_categories AS pc ON pe.pc_catid=pc.pc_catid "
691 . "WHERE pe.pc_pid = ? AND pe.pc_recurrtype > 0;";
692 $sqlBindArray = array();
693 array_push($sqlBindArray, $pid);
694 $res = sqlStatement($query, $sqlBindArray);
695 $result_data = array();
696 while ($row = sqlFetchArray($res)) {
697 $u_recurrspec = unserialize($row['pc_recurrspec']);
698 if (checkEvent($row['pc_recurrtype'], $u_recurrspec)) {
699 continue; }
700 $row['pc_recurrspec'] = interpretRecurrence($row['pc_recurrspec'], $row['pc_recurrtype']);
701 $result_data[] = $row;
703 return $result_data;
706 function ends_in_a_week($end_date)
708 $timestamp_in_a_week = strtotime('+7 day');
709 $timestamp_end_date = strtotime($end_date);
710 if ($timestamp_in_a_week > $timestamp_end_date) {
711 return true; //ends in a week
714 return false; // ends in more than a week
717 //Checks if recurrence is current (didn't end yet).
718 function recurrence_is_current($end_date)
720 $end_date_timestamp = strtotime($end_date);
721 $current_timestamp = time();
722 if ($current_timestamp <= $end_date_timestamp) {
723 return true; //recurrence is current
726 return false;