Adjusted default left nav width to fit the sliding menu labels
[openemr.git] / library / calendar_events.inc.php
blob3c79f229d809aea1df5c1de334020d7f947a7547
1 <?php
2 // Get a result set of squad events for the given squad, player and day.
3 // This is only useful for sports teams.
4 //
5 function getSquadEvents($date, $squad, $plid) {
6 return sqlStatement("SELECT e.pc_eid, e.pc_hometext, " .
7 "e.pc_eventDate, e.pc_endDate, e.pc_startTime, " .
8 "e.pc_duration, e.pc_recurrtype, e.pc_recurrspec, " .
9 "p.pid, p.minutes, p.fitness_related " .
10 "FROM openemr_postcalendar_events AS e " .
11 "JOIN openemr_postcalendar_categories AS c ON " .
12 "c.pc_catdesc LIKE 'Squad=$squad' AND c.pc_catid = e.pc_catid " .
13 "LEFT JOIN player_event AS p ON " .
14 "p.pid = '$plid' AND p.date = '$date' AND p.pc_eid = e.pc_eid " .
15 "WHERE ((e.pc_endDate >= '$date' AND e.pc_eventDate <= '$date') OR " .
16 "(e.pc_endDate = '0000-00-00' AND e.pc_eventDate = '$date')) " .
17 "ORDER BY e.pc_startTime, e.pc_eid");
20 // Determine if the specified event applies to the specified date (YYYY-MM-DD).
22 function eventMatchesDay($row, $date) {
23 $time1 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2), substr($date, 0, 4));
24 $time2 = $time1 + (24 * 60 * 60);
26 $thistime = strtotime($row['pc_eventDate'] . " 00:00:00");
27 if ($row['pc_recurrtype']) {
29 preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches);
30 $repeattype = $matches[1];
32 preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches);
33 $repeatfreq = $matches[1];
34 if (! $repeatfreq) $repeatfreq = 1;
36 $endtime = strtotime($row['pc_endDate'] . " 00:00:00") + (24 * 60 * 60);
37 if ($endtime > $time2) $endtime = $time2;
39 // Shortcut for events that repeat every day.
40 if ($repeattype == 0 && $repeatfreq == 1)
41 return ($thistime < $time2 && $endtime >= $time1);
43 $repeatix = 0;
44 while ($thistime < $endtime) {
45 if ($repeatix == 0 && $thistime >= $time1) return true;
46 if (++$repeatix >= $repeatfreq) $repeatix = 0;
47 $adate = getdate($thistime);
48 if ($repeattype == 0) { // daily
49 $adate['mday'] += 1;
50 } else if ($repeattype == 1) { // weekly
51 $adate['mday'] += 7;
52 } else if ($repeattype == 2) { // monthly
53 $adate['mon'] += 1;
54 } else if ($repeattype == 3) { // yearly
55 $adate['year'] += 1;
56 } else if ($repeattype == 4) { // work days
57 if ($adate['wday'] == 5) // if friday, skip to monday
58 $adate['mday'] += 3;
59 else if ($adate['wday'] == 6) // saturday should not happen
60 $adate['mday'] += 2;
61 else
62 $adate['mday'] += 1;
63 } else {
64 die("Invalid repeat type '$repeattype'");
66 $thistime = mktime(0, 0, 0, $adate['mon'], $adate['mday'], $adate['year']);
68 } else { // not recurring
69 return ($thistime >= $time1 && $thistime < $time2);
72 return false; // repeating event did not match