Esempio n. 1
0
function process_event($id, $name, $event_date, $event_time)
{
    global $CUTOFF, $site_extras, $WS_DEBUG;
    $out = '';
    $debug = str_replace('XXX', array($id, $name, $event_time, $event_date), translate('Event id=XXX XXX at XXX on XXX.')) . "\n" . str_replace('XXX', count($site_extras), translate('Number of site_extras XXX.'));
    // Check to see if this event has any reminders.
    $extras = get_site_extra_fields($id);
    for ($j = 0, $seCnt = count($site_extras); $j < $seCnt; $j++) {
        $extra_name = $site_extras[$j][0];
        $extra_type = $site_extras[$j][2];
        $extra_arg1 = $site_extras[$j][3];
        $extra_arg2 = $site_extras[$j][4];
        if (!empty($extras[$extra_name]['cal_remind'])) {
            $debug .= "\n" . translate('Reminder set for event.');
            // How many minutes before event should we send the reminder?
            $event_time = mktime(intval($event_time / 10000), $event_time / 100 % 100, 0, substr($event_date, 4, 2), substr($event_date, 6, 2), substr($event_date, 0, 4));
            if (($extra_arg2 & EXTRA_REMINDER_WITH_OFFSET) > 0) {
                $minsbefore = $extras[$extra_name]['cal_data'];
                $remind_time = $event_time - $minsbefore * 60;
            } elseif (($extra_arg2 & EXTRA_REMINDER_WITH_DATE) > 0) {
                $rd = $extras[$extra_name]['cal_date'];
                $remind_time = mktime(0, 0, 0, substr($rd, 4, 2), substr($rd, 6, 2), substr($rd, 0, 4));
            } else {
                $minsbefore = $extra_arg1;
                $remind_time = $event_time - $minsbefore * 60;
            }
            $debug .= '
  ' . str_replace('XXX', $minsbefore, translate('Mins Before XXX.')) . '
  ' . str_replace('XXX', date('m/d/Y H:i', $event_time), translate('Event time is XXX.')) . '
  ' . str_replace('XXX', date('m/d/Y H:i', $remind_time), translate('Remind time is XXX.'));
            // Send a reminder.
            if (time() >= $remind_time - $CUTOFF * 86400) {
                if ($debug) {
                    $debug .= '
  SENDING REMINDER!';
                }
                $out .= process_reminder($id, $event_date, $remind_time);
            }
        }
    }
    if ($WS_DEBUG) {
        ws_log_message($debug);
    }
    return $out;
}
Esempio n. 2
0
            echo "<label><input type=\"radio\" name=\"endampm\" value=\"am\" {$endamsel} />&nbsp;" . translate("am") . "</label>\n";
            echo "<label><input type=\"radio\" name=\"endampm\" value=\"pm\" {$endpmsel} />&nbsp;" . translate("pm") . "</label>\n";
        }
        ?>
 </span>
</td></tr>
<?php 
    }
    ?>
</table>
<table>
<?php 
    // site-specific extra fields (see site_extras.php)
    // load any site-specific fields and display them
    if ($id > 0) {
        $extras = get_site_extra_fields($id);
    }
    for ($i = 0; $i < count($site_extras); $i++) {
        $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];
        //echo "<tr><td>Extra " . $extra_name . " - " . $site_extras[$i][2] .
        //  " - " . $extras[$extra_name]['cal_name'] .
        //  "arg1: $extra_arg1, arg2: $extra_arg2 </td></tr>\n";
        if ($extra_type == $EXTRA_MULTILINETEXT) {
            echo "<tr><td style=\"vertical-align:top; font-weight:bold;\"><br />\n";
        } else {
            echo "<tr><td style=\"font-weight:bold;\">";
        }
Esempio n. 3
0
function process_event($id, $name, $event_date, $event_time)
{
    global $site_extras, $debug, $only_testing;
    global $EXTRA_REMINDER_WITH_OFFSET, $EXTRA_REMINDER_WITH_DATE;
    if ($debug) {
        printf("Event %d: \"%s\" at %s on %s <br />\n", $id, $name, $event_time, $event_date);
    }
    // Check to see if this event has any reminders
    $extras = get_site_extra_fields($id);
    for ($j = 0; $j < count($site_extras); $j++) {
        $extra_name = $site_extras[$j][0];
        $extra_type = $site_extras[$j][2];
        $extra_arg1 = $site_extras[$j][3];
        $extra_arg2 = $site_extras[$j][4];
        //if ( $debug )
        //  printf ( "  name: %s\n  type: %d\n  arg1: %s\n  arg2: %s\n",
        //  $extra_name, $extra_type, $extra_arg1, $extra_arg2 );
        if (!empty($extras[$extra_name]['cal_remind'])) {
            if ($debug) {
                echo "  Reminder set for event. <br />\n";
            }
            // how many minutes before event should we send the reminder?
            $ev_h = (int) ($event_time / 10000);
            $ev_m = $event_time / 100 % 100;
            $ev_year = substr($event_date, 0, 4);
            $ev_month = substr($event_date, 4, 2);
            $ev_day = substr($event_date, 6, 2);
            $event_time = mktime($ev_h, $ev_m, 0, $ev_month, $ev_day, $ev_year);
            if (($extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET) > 0) {
                $minsbefore = $extras[$extra_name]['cal_data'];
                $remind_time = $event_time - $minsbefore * 60;
            } else {
                if (($extra_arg2 & $EXTRA_REMINDER_WITH_DATE) > 0) {
                    $rd = $extras[$extra_name]['cal_date'];
                    $r_year = substr($rd, 0, 4);
                    $r_month = substr($rd, 4, 2);
                    $r_day = substr($rd, 6, 2);
                    $remind_time = mktime(0, 0, 0, $r_month, $r_day, $r_year);
                } else {
                    $minsbefore = $extra_arg1;
                    $remind_time = $event_time - $minsbefore * 60;
                }
            }
            if ($debug) {
                echo "  Mins Before: {$minsbefore} <br />\n";
            }
            if ($debug) {
                echo "  Event time is: " . date("m/d/Y H:i", $event_time) . "<br />\n";
                echo "  Remind time is: " . date("m/d/Y H:i", $remind_time) . "<br />\n";
            }
            if (time() >= $remind_time) {
                // It's remind time or later. See if one has already been sent
                $last_sent = 0;
                $res = dbi_query("SELECT MAX(cal_last_sent) FROM " . "webcal_reminder_log WHERE cal_id = " . $id . " AND cal_event_date = {$event_date}" . " AND cal_name = '" . $extra_name . "'");
                if ($res) {
                    if ($row = dbi_fetch_row($res)) {
                        $last_sent = $row[0];
                    }
                    dbi_free_result($res);
                }
                if ($debug) {
                    echo "  Last sent on: " . date("m/d/Y H:i", $last_sent) . "<br />\n";
                }
                if ($last_sent < $remind_time) {
                    // Send a reminder
                    if ($debug) {
                        echo "  SENDING REMINDER! <br />\n";
                    }
                    send_reminder($id, $event_date);
                    // now update the db...
                    log_reminder($id, $extra_name, $event_date);
                }
            }
        }
    }
}
function site_extras_for_popup($id)
{
    global $SITE_EXTRAS_IN_POPUP;
    if ($SITE_EXTRAS_IN_POPUP != 'Y') {
        return '';
    }
    $extras = format_site_extras(get_site_extra_fields($id), EXTRA_DISPLAY_POPUP);
    if (empty($extras)) {
        return '';
    }
    $ret = '';
    foreach ($extras as $extra) {
        $ret .= '<dt>' . $extra['name'] . ":</dt>\n<dd>" . $extra['data'] . "</dd>\n";
    }
    return $ret;
}
Esempio n. 5
0
function site_extras_for_popup($id)
{
    global $site_extras_in_popup, $site_extras;
    // These are needed in case the site_extras.php file was already
    // included.
    global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE, $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $EXTRA_SELECTLIST;
    global $EXTRA_REMINDER_WITH_DATE, $EXTRA_REMINDER_WITH_OFFSET, $EXTRA_REMINDER_DEFAULT_YES;
    $ret = '';
    if ($site_extras_in_popup != 'Y') {
        return '';
    }
    include_once 'includes/site_extras.php';
    $extras = get_site_extra_fields($id);
    for ($i = 0; $i < count($site_extras); $i++) {
        $extra_name = $site_extras[$i][0];
        $extra_type = $site_extras[$i][2];
        $extra_arg1 = $site_extras[$i][3];
        $extra_arg2 = $site_extras[$i][4];
        if (!empty($extras[$extra_name]['cal_name'])) {
            $ret .= "<dt>" . translate($site_extras[$i][1]) . ":</dt>\n<dd>";
            if ($extra_type == $EXTRA_DATE) {
                if ($extras[$extra_name]['cal_date'] > 0) {
                    $ret .= date_to_str($extras[$extra_name]['cal_date']);
                }
            } else {
                if ($extra_type == $EXTRA_TEXT || $extra_type == $EXTRA_MULTILINETEXT) {
                    $ret .= nl2br($extras[$extra_name]['cal_data']);
                } else {
                    if ($extra_type == $EXTRA_REMINDER) {
                        if ($extras[$extra_name]['cal_remind'] <= 0) {
                            $ret .= translate("No");
                        } else {
                            $ret .= translate("Yes");
                            if (($extra_arg2 & $EXTRA_REMINDER_WITH_DATE) > 0) {
                                $ret .= "&nbsp;&nbsp;-&nbsp;&nbsp;";
                                $ret .= date_to_str($extras[$extra_name]['cal_date']);
                            } else {
                                if (($extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET) > 0) {
                                    $ret .= "&nbsp;&nbsp;-&nbsp;&nbsp;";
                                    $minutes = $extras[$extra_name]['cal_data'];
                                    $d = (int) ($minutes / (24 * 60));
                                    $minutes -= $d * 24 * 60;
                                    $h = (int) ($minutes / 60);
                                    $minutes -= $h * 60;
                                    if ($d > 0) {
                                        $ret .= $d . "&nbsp;" . translate("days") . "&nbsp;";
                                    }
                                    if ($h > 0) {
                                        $ret .= $h . "&nbsp;" . translate("hours") . "&nbsp;";
                                    }
                                    if ($minutes > 0) {
                                        $ret .= $minutes . "&nbsp;" . translate("minutes");
                                    }
                                    $ret .= "&nbsp;" . translate("before event");
                                }
                            }
                        }
                    } else {
                        $ret .= $extras[$extra_name]['cal_data'];
                    }
                }
            }
            $ret .= "</dd>\n";
        }
    }
    return $ret;
}
Esempio n. 6
0
function event_to_text($event, $date)
{
    global $ALLOW_HTML_DESCRIPTION, $event_template, $login, $report_id, $user;
    $allDayStr = translate('All day event');
    $confStr = translate('This event is confidential.');
    // translate ( 'Private' )
    $privStr = translate('(Private)');
    $end_time_str = $start_time_str = $time_str = '';
    $tempAllDay = $event->isAllDay();
    $tempDurStr = $event->getDuration();
    if ($tempAllDay) {
        $time_str = $allDayStr;
    } else {
        if ($event->isUntimed()) {
            $time_str = translate('Untimed event');
        } else {
            $start_time_str = $time_str = display_time($event->getDateTime());
            $time_short = getShortTime($time_str);
            if ($tempDurStr > 0) {
                if ($tempAllDay) {
                    $time_str = $allDayStr;
                } else {
                    $tempEDT = $event->getEndDateTime();
                    $end_time_str = display_time($tempEDT);
                    $time_str .= ' - ' . display_time($tempEDT);
                }
            }
        }
    }
    $name = $event->getName();
    $tempAcc = $event->getAccess();
    $tempDesc = $event->getDescription();
    $tempExtForID = $event->getExtForID();
    $tempLog = $event->getLogin();
    if ($tempExtForID != '') {
        $id = $tempExtForID;
        // translate ( 'cont.' )
        $name .= ' ' . translate('(cont.)');
    } else {
        $id = $event->getID();
    }
    if ($tempAcc == 'R') {
        if ($login != $user && strlen($user) || $login != $tempLog && strlen($tempLog)) {
            $description_str = $confStr;
            $name_str = $privStr;
        }
    } else {
        $name_str = htmlspecialchars($name);
        if (!empty($ALLOW_HTML_DESCRIPTION) && $ALLOW_HTML_DESCRIPTION == 'Y') {
            $str = str_replace('&', '&amp;', $tempDesc);
            //fix any broken special characters
            $str = preg_replace("/&amp;(#[0-9]+|[a-z]+);/i", "&\$1;", $str);
            $description_str = str_replace('&amp;amp;', '&amp;', $str);
            if (strstr($description_str, '<') && strstr($description_str, '>')) {
                // Found some HTML.
            } else {
                // No HTML found. Add line breaks.
                $description_str = nl2br($description_str);
            }
        } else {
            $description_str = nl2br(activate_urls(htmlspecialchars($tempDesc)));
        }
    }
    $date_full_str = date_to_str($date);
    $date_str = date_to_str($date, '', false);
    $duration_str = $tempDurStr > 0 ? $tempDurStr . ' ' . translate('minutes') : '';
    $temp = $event->getPriority();
    $pri_str = $temp > 6 ? translate('Low') : ($temp < 4 ? translate('High') : translate('Medium'));
    $temp = $event->getStatus();
    if ($temp == 'A') {
        $status_str = translate('Approved');
    } elseif ($temp == 'D') {
        $status_str = translate('Deleted');
    } elseif ($temp == 'R') {
        $status_str = translate('Rejected');
    } elseif ($temp == 'W') {
        $status_str = translate('Waiting for approval');
    } else {
        $status_str = translate('Unknown');
    }
    $location = $event->getLocation();
    $url = $event->getUrl();
    $href_str = 'view_entry.php?id=' . $id;
    // Get user's fullname.
    user_load_variables($tempLog, 'report_');
    $fullname = $GLOBALS['report_fullname'];
    // Replace all variables in the event template.
    $text = str_replace(array('${date}', '${dateYmd}', '${description}', '${duration}', '${endtime}', '${fulldate}', '${fullname}', '${href}', '${id}', '${location}', '${name}', '${priority}', '${report_id}', '${starttime}', '${time}', '${url}', '${user}'), array($date_str, $date, $description_str, $duration_str, $end_time_str, $date_full_str, $fullname, $href_str, $id, $location, $name_str, $pri_str, $report_id, $start_time_str, $time_str, $url, $tempLog), $event_template);
    $text = replace_site_extras_in_template($text, format_site_extras(get_site_extra_fields($id), EXTRA_DISPLAY_REPORT));
    return $text;
}
Esempio n. 7
0
function print_event_xml($id, $event_date)
{
    global $site_extras, $debug, $server_url, $application_name;
    global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE, $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $LANGUAGE;
    $pri[1] = translate("Low");
    $pri[2] = translate("Medium");
    $pri[3] = translate("High");
    // get participants first...
    $sql = "SELECT cal_login FROM webcal_entry_user " . "WHERE cal_id = {$id} AND cal_status IN ('A','W') " . "ORDER BY cal_login";
    $res = dbi_query($sql);
    $participants = array();
    $num_participants = 0;
    if ($res) {
        while ($row = dbi_fetch_row($res)) {
            $participants[$num_participants++] = $row[0];
        }
    }
    // get external participants
    $ext_participants = array();
    $num_ext_participants = 0;
    if (!empty($allow_external_users) && $allow_external_users == "Y" && !empty($external_reminders) && $external_reminders == "Y") {
        $sql = "SELECT cal_fullname, cal_email FROM webcal_entry_ext_user " . "WHERE cal_id = {$id} AND cal_email IS NOT NULL " . "ORDER BY cal_fullname";
        $res = dbi_query($sql);
        if ($res) {
            while ($row = dbi_fetch_row($res)) {
                $ext_participants[$num_ext_participants] = $row[0];
                $ext_participants_email[$num_ext_participants++] = $row[1];
            }
        }
    }
    if (!$num_participants && !$num_ext_participants) {
        if ($debug) {
            echo "No participants found for event id: {$id}\n";
        }
        return;
    }
    // get event details
    $res = dbi_query("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 FROM webcal_entry WHERE cal_id = {$id}");
    if (!$res) {
        echo "Db error: could not find event id {$id}.\n";
        return;
    }
    if (!($row = dbi_fetch_row($res))) {
        echo "Error: could not find event id {$id} in database.\n";
        return;
    }
    $create_by = $row[0];
    $name = $row[9];
    $description = $row[10];
    echo "<event>\n";
    echo "  <id>{$id}</id>\n";
    echo "  <name>" . escapeXml($name) . "</name>\n";
    if (!empty($server_url)) {
        if (substr($server_url, -1, 1) == "/") {
            echo "  <url>" . $server_url . "view_entry.php?id=" . $id . "</url>\n";
        } else {
            echo "  <url>" . $server_url . "/view_entry.php?id=" . $id . "</url>\n";
        }
    }
    echo "  <description>" . escapeXml($description) . "</description>\n";
    echo "  <dateFormatted>" . date_to_str($event_date) . "</dateFormatted>\n";
    echo "  <date>" . $event_date . "</date>\n";
    if ($row[2] >= 0) {
        echo "  <time>" . sprintf("%04d", $row[2] / 100) . "</time>\n";
        echo "  <timeFormatted>" . display_time($row[2]) . "</timeFormatted>\n";
    }
    if ($row[5] > 0) {
        echo "  <duration>" . $row[5] . "</duration>\n";
    }
    if (!$disable_priority_field) {
        echo "  <priority>" . $pri[$row[6]] . "</priority>\n";
    }
    if (!$disable_access_field) {
        echo "  <access>" . ($row[8] == "P" ? translate("Public") : translate("Confidential")) . "</access>\n";
    }
    if (!strlen($single_user_login)) {
        echo "  <createdBy>" . $row[0] . "</createdBy>\n";
    }
    echo "  <updateDate>" . date_to_str($row[3]) . "</updateDate>\n";
    echo "  <updateTime>" . display_time($row[4]) . "</updateTime>\n";
    // site extra fields
    $extras = get_site_extra_fields($id);
    echo "  <siteExtras>\n";
    for ($i = 0; $i < count($site_extras); $i++) {
        $extra_name = $site_extras[$i][0];
        $extra_descr = $site_extras[$i][1];
        $extra_type = $site_extras[$i][2];
        if ($extras[$extra_name]['cal_name'] != "") {
            $tag = preg_replace("/[^A-Za-z0-9]+/", "", translate($extra_descr));
            $tag = strtolower($tag);
            $tagname = str_replace('"', '', $extra_name);
            echo "    <siteExtra>\n";
            echo "      <number>{$i}</number>\n";
            echo "      <name>" . escapeXml($extra_name) . "</name>\n";
            echo "      <description>" . escapeXml($extra_descr) . "</description>\n";
            echo "      <type>" . $extra_type . "</type>\n";
            echo "      <value>";
            if ($extra_type == $EXTRA_DATE) {
                //echo date_to_str ( $extras[$extra_name]['cal_date'] );
                echo $extras[$extra_name]['cal_date'];
            } else {
                if ($extra_type == $EXTRA_MULTILINETEXT) {
                    echo escapeXml($extras[$extra_name]['cal_data']);
                } else {
                    if ($extra_type == $EXTRA_REMINDER) {
                        echo $extras[$extra_name]['cal_remind'] > 0 ? translate("Yes") : translate("No");
                    } else {
                        // default method for $EXTRA_URL, $EXTRA_TEXT, etc...
                        echo escapeXml($extras[$extra_name]['cal_data']);
                    }
                }
            }
            echo "</value>\n    </siteExtra>\n";
        }
    }
    echo "  </siteExtras>\n";
    if ($single_user != "Y" && !$disable_participants_field) {
        echo "  <participants>\n";
        for ($i = 0; $i < count($participants); $i++) {
            echo "    <participant>" . $participants[$i] . "</participant>\n";
        }
        for ($i = 0; $i < count($ext_participants); $i++) {
            echo "    <participant>" . $ext_participants[$i] . "</participant>\n";
        }
        echo "  </participants>\n";
    }
    echo "</event>\n";
}
Esempio n. 8
0
function process_event($id, $name, $event_date, $event_time)
{
    global $site_extras, $debug;
    global $EXTRA_REMINDER_WITH_OFFSET, $EXTRA_REMINDER_WITH_DATE, $CUTOFF;
    if ($debug) {
        printf("Event %d: \"%s\" at %s on %s \n", $id, $name, $event_time, $event_date);
    }
    // Check to see if this event has any reminders
    $extras = get_site_extra_fields($id);
    for ($j = 0; $j < count($site_extras); $j++) {
        $extra_name = $site_extras[$j][0];
        $extra_type = $site_extras[$j][2];
        $extra_arg1 = $site_extras[$j][3];
        $extra_arg2 = $site_extras[$j][4];
        //if ( $debug )
        //  printf ( "  name: %s\n  type: %d\n  arg1: %s\n  arg2: %s\n",
        //  $extra_name, $extra_type, $extra_arg1, $extra_arg2 );
        if (!empty($extras[$extra_name]['cal_remind'])) {
            if ($debug) {
                echo "  Reminder set for event. \n";
            }
            // how many minutes before event should we send the reminder?
            $ev_h = (int) ($event_time / 10000);
            $ev_m = $event_time / 100 % 100;
            $ev_year = substr($event_date, 0, 4);
            $ev_month = substr($event_date, 4, 2);
            $ev_day = substr($event_date, 6, 2);
            $event_time = mktime($ev_h, $ev_m, 0, $ev_month, $ev_day, $ev_year);
            if (($extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET) > 0) {
                $minsbefore = $extras[$extra_name]['cal_data'];
                $remind_time = $event_time - $minsbefore * 60;
            } else {
                if (($extra_arg2 & $EXTRA_REMINDER_WITH_DATE) > 0) {
                    $rd = $extras[$extra_name]['cal_date'];
                    $r_year = substr($rd, 0, 4);
                    $r_month = substr($rd, 4, 2);
                    $r_day = substr($rd, 6, 2);
                    $remind_time = mktime(0, 0, 0, $r_month, $r_day, $r_year);
                } else {
                    $minsbefore = $extra_arg1;
                    $remind_time = $event_time - $minsbefore * 60;
                }
            }
            if ($debug) {
                echo "  Mins Before: {$minsbefore} \n";
            }
            if ($debug) {
                echo "  Event time is: " . date("m/d/Y H:i", $event_time) . "\n";
                echo "  Remind time is: " . date("m/d/Y H:i", $remind_time) . "\n";
            }
            // Send a reminder
            if (time() >= $remind_time - $CUTOFF * 24 * 3600) {
                if ($debug) {
                    echo "  SENDING REMINDER! \n";
                }
                list_reminder($id, $event_date, $remind_time);
            }
        }
    }
}
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);
        }
    }
}
Esempio n. 10
0
File: ws.php Progetto: rhertzog/lcs
function ws_print_event_xml($id, $event_date, $extra_tags = '')
{
    global $ALLOW_EXTERNAL_USERS, $DISABLE_PARTICIPANTS_FIELD, $DISABLE_PRIORITY_FIELD, $EXTERNAL_REMINDERS, $SERVER_URL, $single_user, $single_user_login, $site_extras, $WS_DEBUG;
    // Get participants first...
    $res = dbi_execute('SELECT cal_login, cal_status FROM webcal_entry_user
    WHERE cal_id = ? AND cal_status IN (\'A\',\'W\') ORDER BY cal_login', array($id));
    $participants = array();
    if ($res) {
        while ($row = dbi_fetch_row($res)) {
            $participants[] = array('cal_login' => $row[0], 'cal_status' => $row[1]);
        }
    }
    // Get external participants.
    $ext_participants = array();
    $num_ext_participants = 0;
    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];
            }
        }
    }
    if (count($participants) == 0 && !$num_ext_participants && $WS_DEBUG) {
        $out .= '
<!-- ' . str_replace('XXX', $id, translate('No participants found for event id XXX.')) . ' -->';
        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 FROM webcal_entry WHERE cal_id = ?', array($id));
    if (!$res) {
        $out .= '
' . str_replace('XXX', $id, translate('Db error Could not find event id XXX.'));
        return;
    }
    if (!($row = dbi_fetch_row($res))) {
        $out .= '
' . str_replace('XXX', $id, translate('Error Could not find event id XXX in database.'));
        return;
    }
    $create_by = $row[0];
    $name = $row[9];
    $description = $row[10];
    $out = '
<event>
  <id>' . $id . '</id>
  <name>' . ws_escape_xml($name) . '</name>' . (!empty($SERVER_URL) ? '
  <url>' . $SERVER_URL . (substr($SERVER_URL, -1, 1) == '/' ? '' : '/') . 'view_entry.php?id=' . $id . '</url>' : '') . '
  <description>' . ws_escape_xml($description) . '</description>
  <dateFormatted>' . date_to_str($event_date) . '</dateFormatted>
  <date>' . $event_date . '</date>
  <time>';
    if ($row[2] == 0 && $row[5] == 1440) {
        $out .= '0</time>
  <timeFormatted>All Day';
    } elseif ($row[2] >= 0) {
        $out .= sprintf("%04d", $row[2] / 100) . '</time>
  <timeFormatted>' . display_time($event_date . sprintf("%06d", $row[2]));
    } else {
        $out .= '-1</time>
  <timeFormatted>Untimed';
    }
    $out .= '</timeFormatted>' . ($row[5] > 0 ? '
  <duration>' . $row[5] . '</duration>' : '');
    if (!empty($DISABLE_PRIORITY_FIELD) && $DISABLE_PRIORITY_FIELD == 'Y') {
        $pri[1] = translate('High');
        $pri[2] = translate('Medium');
        $pri[3] = translate('Low');
        $out .= '
  <priority>' . $row[6] . '-' . $pri[ceil($row[6] / 3)] . '</priority>';
    }
    $out .= (!empty($DISABLE_ACCESS_FIELD) && $DISABLE_ACCESS_FIELD == 'Y' ? '
  <access>' . ($row[8] == 'P' ? translate('Public') : translate('Confidential')) . '</access>' : '') . (!strlen($single_user_login) ? '
  <createdBy>' . $row[0] . '</createdBy>' : '') . '
  <updateDate>' . date_to_str($row[3]) . '</updateDate>
  <updateTime>' . display_time($row[4]) . '</updateTime>';
    // Site extra fields.
    $extras = get_site_extra_fields($id);
    $se = '';
    for ($i = 0, $cnt = count($site_extras); $i < $cnt; $i++) {
        $extra_name = $site_extras[$i][0];
        $extra_descr = $site_extras[$i][1];
        $extra_type = $site_extras[$i][2];
        if (!empty($extras[$extra_name]['cal_name'])) {
            $tag = strtolower(preg_replace('/[^A-Za-z0-9]+/', '', translate($extra_descr)));
            $tagname = str_replace('"', '', $extra_name);
            $se .= '
    <siteExtra>
      <number>' . $i . '</number>
      <name>' . ws_escape_xml($extra_name) . '</name>
      <description>' . ws_escape_xml($extra_descr) . '</description>
      <type>' . $extra_type . '</type>
      <value>';
            if ($extra_type == EXTRA_DATE) {
                // $se .= date_to_str ( $extras[$extra_name]['cal_date'] );
                $se .= $extras[$extra_name]['cal_date'];
            } elseif ($extra_type == EXTRA_MULTILINETEXT) {
                $se .= ws_escape_xml($extras[$extra_name]['cal_data']);
            } elseif ($extra_type == EXTRA_REMINDER) {
                $se .= $extras[$extra_name]['cal_remind'] > 0 ? translate('Yes') : translate('No');
            } else {
                // Default method for EXTRA_URL, EXTRA_TEXT, etc...
                $se .= ws_escape_xml($extras[$extra_name]['cal_data']);
            }
            $se .= '</value>
    </siteExtra>';
        }
    }
    $out .= $se != '' ? '
  <siteExtras>' . $se . '
  </siteExtras>' : '';
    if ($single_user != 'Y' && (empty($DISABLE_PARTICIPANTS_FIELD) || $DISABLE_PARTICIPANTS_FIELD != 'Y')) {
        $out .= '
  <participants>';
        for ($i = 0, $cnt = count($participants); $i < $cnt; $i++) {
            $out .= '
    <participant status="' . $participants[$i]['cal_status'] . '">' . $participants[$i]['cal_login'] . '</participant>';
        }
        for ($i = 0, $cnt = count($ext_participants); $i < $cnt; $i++) {
            $out .= '
    <participant>' . ws_escape_xml($ext_participants[$i]) . '</participant>';
        }
        $out .= '
  </participants>';
    }
    return $out . (!empty($extra_tags) ? $extra_tags : '') . '
</event>
';
}