function check_for_conflicts($dates, $duration, $hour, $minute, $participants, $login, $id) { global $single_user_login, $single_user; global $repeated_events, $limit_appts, $limit_appts_number; if (!count($dates)) { return false; } $evtcnt = array(); $sql = "SELECT distinct webcal_entry_user.cal_login, webcal_entry.cal_time," . "webcal_entry.cal_duration, webcal_entry.cal_name, " . "webcal_entry.cal_id, webcal_entry.cal_ext_for_id, " . "webcal_entry.cal_access, " . "webcal_entry_user.cal_status, webcal_entry.cal_date " . "FROM webcal_entry, webcal_entry_user " . "WHERE webcal_entry.cal_id = webcal_entry_user.cal_id " . "AND ("; for ($x = 0; $x < count($dates); $x++) { if ($x != 0) { $sql .= " OR "; } $sql .= "webcal_entry.cal_date = " . date("Ymd", $dates[$x]); } $sql .= ") AND webcal_entry.cal_time >= 0 " . "AND webcal_entry_user.cal_status IN ('A','W') AND ( "; if ($single_user == "Y") { $participants[0] = $single_user_login; } else { if (strlen($participants[0]) == 0) { // likely called from a form with 1 user $participants[0] = $login; } } for ($i = 0; $i < count($participants); $i++) { if ($i > 0) { $sql .= " OR "; } $sql .= " webcal_entry_user.cal_login = '******'"; } $sql .= " )"; // make sure we don't get something past the end date of the // event we are saving. //echo "SQL: $sql<P>"; $conflicts = ""; $res = dbi_query($sql); $found = array(); $count = 0; if ($res) { $time1 = sprintf("%d%02d00", $hour, $minute); $duration1 = sprintf("%d", $duration); while ($row = dbi_fetch_row($res)) { //Add to an array to see if it has been found already for the next part. $found[$count++] = $row[4]; // see if either event overlaps one another if ($row[4] != $id && (empty($row[5]) || $row[5] != $id)) { $time2 = $row[1]; $duration2 = $row[2]; $cntkey = $user . "-" . $row[8]; $evtcnt[$cntkey]++; $over_limit = 0; if ($limit_appts == "Y" && $limit_appts_number > 0 && $evtcnt[$cntkey] >= $limit_appts_number) { $over_limit = 1; } if ($over_limit || times_overlap($time1, $duration1, $time2, $duration2)) { $conflicts .= "<LI>"; if ($single_user == "Y") { $conflicts .= "{$row['0']}: "; } if ($row[6] == 'R' && $row[0] != $login) { $conflicts .= "(" . translate("Private") . ")"; } else { $conflicts .= "<A HREF=\"view_entry.php?id={$row['4']}"; if ($user != $login) { $conflicts .= "&user={$user}"; } $conflicts .= "\">{$row['3']}</A>"; } if ($duration2 == 24 * 60) { $conflicts .= " (" . translate("All day event") . ")"; } else { $conflicts .= " (" . display_time($time2); if ($duration2 > 0) { $conflicts .= "-" . display_time(add_duration($time2, $duration2)); } $conflicts .= ")"; } $conflicts .= " on " . date_to_str($row[8]); if ($over_limit) { $tmp = translate("exceeds limit of XXX events per day"); $tmp = str_replace("XXX", $limit_appts_number, $tmp); $conflicts .= " (" . $tmp . ")"; } } } } dbi_free_result($res); } else { echo translate("Database error") . ": " . dbi_error(); exit; } //echo "<br>hello"; for ($q = 0; $q < count($participants); $q++) { $time1 = sprintf("%d%02d00", $hour, $minute); $duration1 = sprintf("%d", $duration); //This date filter is not necessary for functional reasons, but it eliminates some of the //events that couldn't possibly match. This could be made much more complex to put more //of the searching work onto the database server, or it could be dropped all together to put //the searching work onto the client. $date_filter = "AND (webcal_entry.cal_date <= " . date("Ymd", $dates[count($dates) - 1]); $date_filter .= " AND (webcal_entry_repeats.cal_end IS NULL OR webcal_entry_repeats.cal_end >= " . date("Ymd", $dates[0]) . "))"; //Read repeated events for the participants only once for a participant for //for performance reasons. $repeated_events = query_events($participants[$q], true, $date_filter); //for ($dd=0; $dd<count($repeated_events); $dd++) { // echo $repeated_events[$dd]['cal_id'] . "<BR>"; //} for ($i = 0; $i < count($dates); $i++) { $dateYmd = date("Ymd", $dates[$i]); $list = get_repeating_entries($participants[$q], $dateYmd); $thisyear = substr($dateYmd, 0, 4); $thismonth = substr($dateYmd, 4, 2); for ($j = 0; $j < count($list); $j++) { //okay we've narrowed it down to a day, now I just gotta check the time... //I hope this is right... $row = $list[$j]; if ($row['cal_id'] != $id && $row['cal_ext_for_id'] != $id) { $time2 = $row['cal_time']; $duration2 = $row['cal_duration']; if (times_overlap($time1, $duration1, $time2, $duration2)) { $conflicts .= "<LI>"; if ($single_user != "Y") { $conflicts .= $row['cal_login'] . ": "; } if ($row['cal_access'] == 'R' && $row['cal_login'] != $login) { $conflicts .= "(" . translate("Private") . ")"; } else { $conflicts .= "<A HREF=\"view_entry.php?id=" . $row['cal_id']; if ($user != $login) { $conflicts .= "&user={$user}"; } $conflicts .= "\">" . $row['cal_name'] . "</A>"; } $conflicts .= " (" . display_time($time2); if ($duration2 > 0) { $conflicts .= "-" . display_time(add_duration($time2, $duration2)); } $conflicts .= ")"; $conflicts .= " on " . date("l, F j, Y", $dates[$i]); } } } } } return $conflicts; }
$tzoffset = array(); if ($res) { while ($row = dbi_fetch_row($res)) { $user = $row[0]; $user_tzoffset = $row[1]; $tzoffset[$user] = $user_tzoffset; if ($debug) { echo "TZ OFFSET for {$user} is \"{$user_tzoffset}\" <br />\n"; } } dbi_free_result($res); } $startdate = date("Ymd"); $enddate = date("Ymd", time() + $DAYS_IN_ADVANCE * 24 * 3600); // Now read events all the repeating events (for all users) $repeated_events = query_events("", true, "AND (webcal_entry_repeats.cal_end > {$startdate} OR webcal_entry_repeats.cal_end IS NULL) "); // Read non-repeating events (for all users) if ($debug) { echo "Checking for events from date {$startdate} to date {$enddate} <br />\n"; } $events = read_events("", $startdate, $enddate); if ($debug) { echo "Found " . count($events) . " events in time range. <br />\n"; } function indent($str) { return " " . str_replace("\n", "\n ", $str); } // Send a reminder for a single event for a single day to all // participants in the event. // Send to participants who have accepted as well as those who have not yet
exit; } $out .= ' <!-- ' . str_replace('XXX ', '', translate('Allowing XXX user to view other users calendar.')) . ' -->'; } // Make sure this user has enabled email reminders. // if ( $EMAIL_REMINDER == 'N' ) { // $out .= str_replace ('XXX', $user, // translate ( 'Error Email reminders disabled for user XXX.' ) ); // dbi_close ( $c ); // exit; // } $startdate = mktime(); $enddate = $startdate + $DAYS_IN_ADVANCE * 86400; // Now read all the repeating events. $repeated_events = query_events($user, true, 'AND ( wer.cal_end > ' . $startdate . ' OR wer.cal_end IS NULL ) '); // Read non-repeating events. $events = read_events($user, $startdate, $enddate); if ($WS_DEBUG) { ws_log_message(str_replace('XXX', count($events), translate('Found XXX events in time range.'))); } /* Send a reminder for a single event for a single day. */ function process_reminder($id, $event_date, $remind_time) { global $DISABLE_ACCESS_FIELD, $DISABLE_PARTICIPANTS_FIELD, $DISABLE_PRIORITY_FIELD, $SERVER_URL, $single_user, $single_user_login, $site_extras, $WS_DEBUG; return ' <reminder> <remindDate>' . date('Ymd', $remind_time) . '</remindDate> <remindTime>' . date('Hi', $remind_time) . '</remindTime> <untilRemind>' . ($remind_time - time()) . '</untilRemind>
function read_tasks($user, $duedate, $cat_id = '') { $due_date = gmdate('Ymd', $duedate); return query_events($user, false, ' AND ( ( we.cal_due_date <= ' . $due_date . ' ) OR ( we.cal_due_date = ' . $due_date . ' AND we.cal_due_time <= ' . gmdate('His', $duedate) . ' ) )', $cat_id, true); }