Exemplo n.º 1
0
<?php

/* $Id: edit_entry_handler.php,v 1.172.2.23 2012/02/28 02:07:45 cknudsen Exp $ */
include_once 'includes/init.php';
require 'includes/classes/WebCalMailer.class';
$mail = new WebCalMailer();
require_valide_referring_url();
load_user_categories();
$error = '';
$do_override = false;
$old_id = -1;
$dateStr = translate('Date XXX');
$descStr = translate('Description XXX');
$helloStr = translate('Hello, XXX.');
// translate ( 'A new appointment has been made for you by' )
$newAppStr = translate('XXX has made a new appointment.');
$subjStr = translate('Subject XXX');
$timeStr = translate('Time XXX');
// translate ( 'An appointment has been updated by' )
$updAppStr = translate('XXX has updated an appointment.');
/* Put byday values in logical sequence.
 */
function sort_byday($a, $b)
{
    global $byday_values;
    $len_a = strlen($a);
    $len_b = strlen($b);
    $val_a = $byday_values[substr($a, -2)];
    $val_b = $byday_values[substr($b, -2)];
    if ($len_a != $len_b) {
        return $len_a < $len_b ? -1 : 1;
}
$user = getValue('user');
$type = getValue('type');
$id = getValue('id');
// Allow administrators to approve public events.
$app_user = $PUBLIC_ACCESS == 'Y' && !empty($public) && $is_admin ? '__public__' : ($is_assistant || $is_nonuser_admin ? $user : $login);
// If User Access Control is enabled, we check to see if they are
// allowed to approve for the specified user.
if (access_is_enabled() && !empty($user) && $user != $login && access_user_calendar('approve', $user)) {
    $app_user = $user;
}
if (empty($error) && $id > 0) {
    update_status('A', $app_user, $id, $type);
}
if (!empty($comments) && empty($cancel)) {
    $mail = new WebCalMailer();
    // Email event creator to notify that it was approved with comments.
    // Get the name of the event.
    $res = dbi_execute('SELECT cal_name, cal_description, cal_date, cal_time,
    cal_create_by FROM webcal_entry WHERE cal_id = ?', array($id));
    if ($res) {
        $row = dbi_fetch_row($res);
        $name = $row[0];
        $description = $row[1];
        $fmtdate = $row[2];
        $time = sprintf("%06d", $row[3]);
        $creator = $row[4];
        dbi_free_result($res);
    }
    $eventstart = date_to_epoch($fmtdate . $time);
    // TODO figure out if creator wants approved comment email.
Exemplo n.º 3
0
<?php

/* $Id: del_entry.php,v 1.75.2.5 2012/02/28 02:07:45 cknudsen Exp $ */
include_once 'includes/init.php';
require 'includes/classes/WebCalMailer.class';
$mail = new WebCalMailer();
require_valide_referring_url();
$can_edit = $my_event = false;
$other_user = '';
// First, check to see if this user should be able to delete this event.
if ($id > 0) {
    // Then see who has access to edit this entry.
    $can_edit = $is_admin || $readonly != 'Y';
    // If assistant is doing this, then we need to switch login to user in the SQL.
    $query_params = array();
    $query_params[] = $id;
    $sql = 'SELECT we.cal_id, we.cal_type FROM webcal_entry we,
    webcal_entry_user weu WHERE we.cal_id = weu.cal_id AND we.cal_id = ? ';
    if (!$is_admin) {
        $sql .= ' AND ( we.cal_create_by = ? OR weu.cal_login = ? )';
        $sqlparm = $is_assistant ? $user : $login;
        $query_params[] = $sqlparm;
        $query_params[] = $sqlparm;
    }
    $res = dbi_execute($sql, $query_params);
    if ($res) {
        $row = dbi_fetch_row($res);
        if ($row && $row[0] > 0) {
            $can_edit = true;
        }
        $activity_type = $row[1];
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]) ? '&nbsp;&nbsp;&nbsp;' : '   ';
        $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);
        }
    }
}