if ($old_participant != $login && !empty($tempemail) && $do_send == 'Y' && $SEND_EMAIL != 'N') { reset_language(empty($user_language) || $user_language == 'none' ? $LANGUAGE : $user_language); $fmtdate = $timetype == 'T' ? date('Ymd', $eventstart) : gmdate('Ymd', $eventstart); $msg = str_replace('XXX', $tempfullname, $helloStr) . "\n\n" . str_replace('XXX', $login_fullname, translate('XXX has canceled an appointment.')) . "\n" . str_replace('XXX', $name, $subjStr) . "\n\n" . str_replace('XXX', $description, $descStr) . "\n" . str_replace('XXX', date_to_str($fmtdate), $dateStr) . "\n" . ($timetype != 'T' ? '' : str_replace('XXX', display_time('', 2, $eventstart, $t_format), $timeStr . "\n\n\n")); // Add URL to event, if we can figure it out. if (!empty($SERVER_URL)) { // DON'T change & to & here. Email will handle it. $url = $SERVER_URL . 'view_entry.php?id=' . $id . '&em=1'; if ($htmlmail == 'Y') { $url = activate_urls($url); } $msg .= $url . "\n\n"; } $wantsAttach = get_pref_setting($old_participant, 'EMAIL_ATTACH_ICS', 'N'); $attachId = $wantsAttach == 'Y' ? $id : ''; $mail->WC_Send($login_fullname, $tempemail, $tempfullname, $name, $msg, $htmlmail, $from, $attachId); activity_log($id, $login, $old_participant, LOG_NOTIFICATION, translate('User removed from participants list.')); } } } } $send_own = get_pref_setting($login, 'EMAIL_EVENT_CREATE'); // Now add participants and send out notifications. for ($i = 0; $i < $partcnt; $i++) { // Is the person adding the nonuser calendar admin? $is_nonuser_admin = user_is_nonuser_admin($login, $participants[$i]); // If public access, require approval unless // $PUBLIC_ACCESS_ADD_NEEDS_APPROVAL is set to 'N' if ($login == '__public__') { $status = !empty($PUBLIC_ACCESS_ADD_NEEDS_APPROVAL) && $PUBLIC_ACCESS_ADD_NEEDS_APPROVAL == 'N' ? 'A' : 'W'; // Percent will always be 0 for Public
$user_language = get_pref_setting($creator, 'LANGUAGE'); if ($send_user_mail == 'Y' && strlen($tempemail) && $SEND_EMAIL != 'N') { reset_language(empty($user_language) || $user_language == 'none' ? $LANGUAGE : $user_language); // translate ( 'Hello' ) $msg = str_replace('XXX', $tempfullname, translate('Hello, XXX.')) . "\n\n" . str_replace('XXX', $login_fullname, translate('XXX has approved an appointment and added comments.')) . "\n\n" . str_replace('XXX', $name, translate('Subject XXX')) . "\n" . str_replace('XXX', $description, translate('Description XXX')) . "\n" . str_replace('XXX', date_to_str($fmtdate), translate('Date XXX')) . ' ' . (empty($hour) && empty($minute) ? '' : str_replace('XXX', display_time('', 2, $eventstart, get_pref_setting($creator, 'TIME_FORMAT')), translate('Time XXX'))) . "\n"; if (!empty($SERVER_URL)) { // DON'T change & to & here. email will handle it $url = $SERVER_URL . 'view_entry.php?id=' . $id . '&em=1'; if ($htmlmail == 'Y') { $url = activate_urls($url); } $msg .= "\n" . $url; } if (!empty($comments)) { // translate ( 'Comments' ) $msg .= "\n\n" . str_replace('XXX', $comments, translate('Comments XXX')); } $from = strlen($login_email) ? $login_email : $EMAIL_FALLBACK_FROM; // Send mail. $mail->WC_Send($login_fullname, $tempemail, $tempfullname, $name, $msg, $htmlmail, $from); activity_log($id, $login, $creator, LOG_NOTIFICATION, str_replace('XXX', $app_user, translate('Approved w/Comments by XXX.'))); } } // Return to login TIMEZONE. set_env('TZ', $TIMEZONE); if (empty($error) && empty($mailerError)) { do_redirect(!empty($ret) && $ret == 'listall' ? 'list_unapproved.php' : (!empty($ret) && $ret == 'list' ? 'list_unapproved.php?' : 'view_entry.php?id=' . $id . '&') . 'user=' . $app_user); exit; } // Process errors. $mail->MailError($mailerError, $error);
$eventstart = date_to_epoch($fmtdate . $time); $TIME_FORMAT = 24; for ($i = 0, $cnt = count($partlogin); $i < $cnt; $i++) { // Log the deletion. activity_log($id, $login, $partlogin[$i], $log_delete, ''); // Check UAC. $can_email = access_is_enabled() ? access_user_calendar('email', $partlogin[$i], $login) : false; // Don't email the logged in user. if ($can_email && $partlogin[$i] != $login) { set_env('TZ', get_pref_setting($partlogin[$i], 'TIMEZONE')); $user_language = get_pref_setting($partlogin[$i], 'LANGUAGE'); user_load_variables($partlogin[$i], 'temp'); if (!$is_nonuser_admin && $partlogin[$i] != $login && get_pref_setting($partlogin[$i], 'EMAIL_EVENT_DELETED') == 'Y' && boss_must_be_notified($login, $partlogin[$i]) && !empty($tempemail) && $SEND_EMAIL != 'N') { reset_language(empty($user_language) || $user_language == 'none' ? $LANGUAGE : $user_language); // Use WebCalMailer class. $mail->WC_Send($login_fullname, $tempemail, $tempfullname, $name, str_replace('XXX', $tempfullname, translate('Hello, XXX.')) . ".\n\n" . str_replace('XXX', $login_fullname, translate('XXX has canceled an appointment.')) . "\n" . str_replace('XXX', $name, translate('Subject XXX')) . "\"\n" . str_replace('XXX', date_to_str($thisdate), translate('Date XXX')) . "\n" . (!empty($eventtime) && $eventtime != '-1' ? str_replace('XXX', display_time('', 2, $eventstart, get_pref_setting($partlogin[$i], 'TIME_FORMAT')), translate('Time XXX')) : '') . "\n\n", get_pref_setting($partlogin[$i], 'EMAIL_HTML'), $login_email); } } } // Instead of deleting from the database... // mark it as deleted by setting the status for each participant to "D" // (instead of "A"/Accepted, "W"/Waiting-on-approval or "R"/Rejected). if ($override_repeat) { dbi_execute('INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date, cal_exdate ) VALUES ( ?, ?, ? )', array($id, $date, 1)); // Should we log this to the activity log??? } else { // If it's a repeating event, delete any event exceptions that were entered. if ($event_repeats) { $res = dbi_execute('SELECT cal_id FROM webcal_entry WHERE cal_group_id = ?', array($id)); if ($res) {
function send_reminder($id, $event_date) { global $ALLOW_EXTERNAL_USERS, $debug, $def_tz, $emails, $EXTERNAL_REMINDERS, $attachics, $htmlmail, $is_task, $LANGUAGE, $languages, $names, $only_testing, $SERVER_URL, $site_extras, $t_format, $tz; $ext_participants = $participants = array(); $num_ext_participants = $num_participants = 0; $pri[1] = translate('High'); $pri[2] = translate('Medium'); $pri[3] = translate('Low'); // Get participants first... $res = dbi_execute('SELECT cal_login, cal_percent FROM webcal_entry_user WHERE cal_id = ? AND cal_status IN ( \'A\',\'W\' ) ORDER BY cal_login', array($id)); if ($res) { while ($row = dbi_fetch_row($res)) { $participants[$num_participants++] = $row[0]; $percentage[$row[0]] = $row[1]; } } $partcnt = count($participants); // Get external participants. if (!empty($ALLOW_EXTERNAL_USERS) && $ALLOW_EXTERNAL_USERS == 'Y' && !empty($EXTERNAL_REMINDERS) && $EXTERNAL_REMINDERS == 'Y') { $res = dbi_execute('SELECT cal_fullname, cal_email FROM webcal_entry_ext_user WHERE cal_id = ? AND cal_email IS NOT NULL ORDER BY cal_fullname', array($id)); if ($res) { while ($row = dbi_fetch_row($res)) { $ext_participants[$num_ext_participants] = $row[0]; $ext_participants_email[$num_ext_participants++] = $row[1]; } } } $ext_partcnt = count($ext_participants); if (!$num_participants && !$num_ext_participants) { if ($debug) { echo 'No participants found for event id' . ": {$id}<br />\n"; } return; } // Get event details. $res = dbi_execute('SELECT cal_create_by, cal_date, cal_time, cal_mod_date, cal_mod_time, cal_duration, cal_priority, cal_type, cal_access, cal_name, cal_description, cal_due_date, cal_due_time FROM webcal_entry WHERE cal_id = ?', array($id)); if (!$res) { echo translate('Database error') . ': ' . translate('could not find event id') . " {$id}.\n"; return; } if (!($row = dbi_fetch_row($res))) { echo translate('Error') . ': ' . str_replace('XXX', $id, translate('could not find event id XXX in database.')) . "\n"; return; } // Send mail. We send one user at a time so that we can switch // languages between users if needed (as well as HTML vs plain text). $mailusers = $recipients = array(); if (isset($single_user) && $single_user == 'Y') { $mailusers[] = $emails[$single_user_login]; $recipients[] = $single_user_login; } else { for ($i = 0; $i < $partcnt; $i++) { if (strlen($emails[$participants[$i]])) { $mailusers[] = $emails[$participants[$i]]; $recipients[] = $participants[$i]; } else { if ($debug) { echo "No email for user {$participants[$i]}.<br />\n"; } } } for ($i = 0; $i < $ext_partcnt; $i++) { $mailusers[] = $ext_participants_email[$i]; $recipients[] = $ext_participants[$i]; } } $mailusercnt = count($mailusers); if ($debug) { echo 'Found ' . $mailusercnt . " with email addresses<br />\n"; } for ($j = 0; $j < $mailusercnt; $j++) { $recip = $mailusers[$j]; $user = $recipients[$j]; $isExt = !in_array($user, $participants); $userlang = empty($languages[$user]) ? $LANGUAGE : $languages[$user]; $userTformat = !empty($t_format[$user]) ? $t_format[$user] : 24; // Gotta pick something. if ($userlang == 'none') { $userlang = 'English-US'; } // Gotta pick something. if ($debug) { echo "Setting language to \"{$userlang}\".<br />\n"; } reset_language($userlang); $adminStr = translate('Administrator'); // Reset timezone setting for current user. if (!empty($tz[$user])) { $display_tzid = 2; // Display TZ. $user_TIMEZONE = $tz[$user]; } else { if (!empty($def_tz)) { $display_tzid = 2; $user_TIMEZONE = $def_tz; } else { $display_tzid = 3; // Do not use offset & display TZ. // I think this is the only real timezone set to UTC...since 1972 at least. $user_TIMEZONE = 'Africa/Monrovia'; } } // This will allow date functions to use the proper TIMEZONE. set_env('TZ', $user_TIMEZONE); $useHtml = !empty($htmlmail[$user]) ? 'Y' : 'N'; $padding = !empty($htmlmail[$user]) ? ' ' : ' '; $body = str_replace('XXX', $is_task ? translate('task') : translate('event'), translate('This is a reminder for the XXX detailed below.')) . "\n\n"; $create_by = $row[0]; $event_time = date_to_epoch($row[1] . ($row[2] != -1 ? sprintf("%06d", $row[2]) : '')); $name = $row[9]; $description = $row[10]; // Add trailing '/' if not found in server_url. // Don't include link for External users. if (!empty($SERVER_URL) && !$isExt) { $eventURL = $SERVER_URL . (substr($SERVER_URL, -1, 1) == '/' ? '' : '/') . 'view_entry.php?id=' . $id . '&em=1'; if ($useHtml == 'Y') { $eventURL = activate_urls($eventURL); } $body .= $eventURL . "\n\n"; } $body .= strtoupper($name) . "\n\n" . translate('Description') . ":\n" . $padding . $description . "\n" . ($is_task ? translate('Start Date') : translate('Date')) . ': ' . date_to_str($row[2] > 0 ? date('Ymd', $event_date) : gmdate('Ymd', $event_date)) . "\n" . ($row[2] > 0 ? ($is_task ? translate('Start Time') : translate('Time')) . ': ' . display_time('', $display_tzid, $event_time, $userTformat) . "\n" : ($row[2] == 0 && ($row[5] = 1440) ? translate('Time') . ': ' . translate('All day event') . "\n" : '')) . ($row[5] > 0 && !$is_task ? translate('Duration') . ': ' . $row[5] . ' ' . translate('minutes') . "\n" : ($is_task ? translate('Due Date') . ': ' . date_to_str($row[11]) . "\n" . translate('Due Time') . ': ' . display_time($row[12], $display_tzid, '', $userTformat) . "\n" : '')) . ($is_task && isset($percentage[$user]) ? translate('Pecentage Complete') . ': ' . $percentage[$user] . "%\n" : '') . (empty($DISABLE_PRIORITY_FIELD) || $DISABLE_PRIORITY_FIELD != 'Y' ? translate('Priority') . ': ' . $row[6] . '-' . $pri[ceil($row[6] / 3)] . "\n" : ''); if (empty($DISABLE_ACCESS_FIELD) || $DISABLE_ACCESS_FIELD != 'Y') { $body .= translate('Access') . ': '; if ($row[8] == 'C') { $body .= translate('Confidential') . "\n"; } elseif ($row[8] == 'P') { $body .= translate('Public') . "\n"; } elseif ($row[8] == 'R') { $body .= translate('Private') . "\n"; } } $body .= (!empty($single_user_login) && !$single_user_login ? translate('Created by') . ': ' . $row[0] . "\n" : '') . translate('Updated') . ': ' . date_to_str($row[3]) . ' ' . display_time($row[3] . sprintf("%06d", $row[4]), $display_tzid, '', $userTformat) . "\n"; // Site extra fields. $extras = get_site_extra_fields($id); $site_extracnt = count($site_extras); for ($i = 0; $i < $site_extracnt; $i++) { if ($site_extras[$i] == 'FIELDSET') { continue; } $extra_name = $site_extras[$i][0]; $extra_descr = $site_extras[$i][1]; $extra_type = $site_extras[$i][2]; $extra_arg1 = $site_extras[$i][3]; $extra_arg2 = $site_extras[$i][4]; if (!empty($site_extras[$i][5])) { $extra_view = $site_extras[$i][5] & EXTRA_DISPLAY_REMINDER; } if (!empty($extras[$extra_name]['cal_name']) && $extras[$extra_name]['cal_name'] != '' && !empty($extra_view)) { $val = ''; $body .= $extra_descr; if ($extra_type == EXTRA_DATE) { $body .= ': ' . $extras[$extra_name]['cal_date'] . "\n"; } elseif ($extra_type == EXTRA_MULTILINETEXT) { $body .= "\n" . $padding . $extras[$extra_name]['cal_data'] . "\n"; } elseif ($extra_type == EXTRA_RADIO) { $body .= ': ' . $extra_arg1[$extras[$extra_name]['cal_data']] . "\n"; } else { // Default method for EXTRA_URL, EXTRA_TEXT, etc... $body .= ': ' . $extras[$extra_name]['cal_data'] . "\n"; } } } if ((empty($single_user) || $single_user != 'Y') && (empty($DISABLE_PARTICIPANTS_FIELD) || $DISABLE_PARTICIPANTS_FIELD != 'N')) { $body .= translate('Participants') . ":\n"; for ($i = 0; $i < $partcnt; $i++) { $body .= $padding . $names[$participants[$i]] . "\n"; } for ($i = 0; $i < $ext_partcnt; $i++) { $body .= $padding . $ext_participants[$i] . ' ( ' . translate('External User') . ")\n"; } } $subject = translate('Reminder') . ': ' . stripslashes($name); if ($debug) { echo "Sending mail to {$recip} (in {$userlang}).<br />\n"; } if ($only_testing) { if ($debug) { echo '<hr /> <pre> To: ' . $recip . ' Subject: ' . $subject . ' From:' . $adminStr . ' ' . $body . ' </pre> '; } } else { $mail = new WebCalMailer(); user_load_variables($user, 'temp'); $recipName = $isExt ? $user : $GLOBALS['tempfullname']; // Send ics attachment to External Users or // or users who explicitly chose to receive it. $attach = $isExt || isset($attachics[$user]) ? $id : ''; $mail->WC_Send($adminStr, $recip, $recipName, $subject, $body, $useHtml, $GLOBALS['EMAIL_FALLBACK_FROM'], $attach); $cal_text = ($isExt ? translate('External User') : '') . $recipName; activity_log($id, 'system', $user, LOG_REMINDER, $cal_text); } } }