コード例 #1
0
/**
 * Return the basic HTML for a message (given its database row),
 * where the title is a heading 2 and the body is in a paragraph.
 *
 * @param string $message the message body
 * @return string HTML output
 * @todo TODO refactor, separate display and logic
 * @author Ben WerdMuller <*****@*****.**>
 */
function display_message($message)
{
    global $CFG;
    if ($message->from_id == -1) {
        $from->name = __gettext("System");
    } else {
        $from = get_record_sql("select * from " . $CFG->prefix . "users where ident = " . $message->from_id);
    }
    $title = "[" . __gettext("Message from ");
    if ($message->from_id != -1) {
        $title .= "<a href=\"" . $CFG->wwwroot . user_info("username", $message->from_id) . "/\">";
    }
    $title .= $from->name;
    if ($message->from_id != -1) {
        $title .= "</a>";
    }
    $title .= "] " . $message->title;
    $body = "<p>" . nl2br(str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", activate_urls($message->body))) . "</p>";
    $body = templates_draw(array('context' => 'databox1', 'name' => $title, 'column1' => $body));
    return $body;
}
コード例 #2
0
ファイル: register.php プロジェクト: rhertzog/lcs
            user_add_user($user, $upassword1, $ufirstname, $ulastname, $uemail, $uis_admin);
            activity_log(0, 'system', $user, LOG_NEWUSER_FULL, translate('New user via self-registration.'));
        }
    } elseif ($control == 'email') {
        // Process account info for email submission.
        // Need to generate unique passwords and email them to the new user.
        $new_pass = generate_password();
        // TODO allow admin to approve account and emails prior to processing.
        user_add_user($user, $new_pass, $ufirstname, $ulastname, $uemail, $uis_admin);
        $tempName = trim($ufirstname . ' ' . $ulastname);
        $msg = str_replace(', XXX.', strlen($tempName) ? ', ' . $tempName . '.' : '.', translate('Hello, XXX.')) . "\n\n" . translate('A new WebCalendar account has been set up for you.') . "\n\n" . str_replace('XXX', $user, translate('Your username is XXX.')) . "\n\n" . str_replace('XXX', $new_pass, translate('Your password is XXX.')) . "\n\n" . str_replace('XXX', $appStr, translate('Please visit XXX to log in and start using your account!')) . "\n";
        // Add URL to event, if we can figure it out.
        if (!empty($SERVER_URL)) {
            $url = $SERVER_URL . 'login.php';
            if ($htmlmail == 'Y') {
                $url = activate_urls($url);
            }
            $msg .= "\n\n" . $url;
        }
        $msg .= "\n\n" . translate('You may change your password after logging in the first time.') . "\n\n" . translate('If you received this email in error') . "\n\n";
        $adminStr = translate('Administrator', true);
        $name = $appStr . ' ' . translate('Welcome') . ': ' . $ufirstname;
        // Send  via WebCalMailer class.
        $mail->WC_Send($adminStr, $uemail, $ufirstname . ' ' . $ulastname, $name, $msg, $htmlmail, $EMAIL_FALLBACK_FROM);
        activity_log(0, 'system', $user, LOG_NEWUSER_EMAIL, translate('New user via email.'));
    }
}
echo send_doctype($appStr);
echo '
    <script type="text/javascript" src="includes/js/prototype.js"></script>
    <script type="text/javascript">
コード例 #3
0
function print_detailed_entry($id, $date, $time, $duration, $name, $description, $status, $pri, $access, $event_owner)
{
    global $eventinfo, $login, $user, $TZ_OFFSET;
    static $key = 0;
    global $layers;
    if ($login != $event_owner && strlen($event_owner)) {
        $class = "layerentry";
    } else {
        $class = "entry";
        if ($status == "W") {
            $class = "unapprovedentry";
        }
    }
    if ($pri == 3) {
        echo "<strong>";
    }
    $divname = "eventinfo-{$id}-{$key}";
    $key++;
    echo "<a title=\"" . translate("View this entry") . "\" class=\"{$class}\" href=\"view_entry.php?id={$id}&amp;date={$date}";
    if (strlen($user) > 0) {
        echo "&amp;user="******"\" onmouseover=\"window.status='" . translate("View this entry") . "'; return true;\" onmouseout=\"window.status=''; return true;\">";
    echo "<img src=\"circle.gif\" class=\"bullet\" alt=\"view icon\" />";
    if ($login != $event_owner && strlen($event_owner)) {
        if ($layers) {
            foreach ($layers as $layer) {
                if ($layer['cal_layeruser'] == $event_owner) {
                    echo "<span style=\"color:#" . $layer['cal_color'] . ";\">";
                }
            }
        }
    }
    $timestr = "";
    $my_time = $time + $TZ_OFFSET * 10000;
    if ($time >= 0) {
        if ($GLOBALS["TIME_FORMAT"] == "24") {
            printf("%02d:%02d", $my_time / 10000, $my_time / 100 % 100);
        } else {
            $h = (int) ($my_time / 10000) % 12;
            if ($h == 0) {
                $h = 12;
            }
            echo $h;
            $m = $my_time / 100 % 100;
            if ($m > 0) {
                printf(":%02d", $m);
            } else {
                print ":00";
            }
            echo (int) ($my_time / 10000) < 12 ? translate("am") : translate("pm");
        }
        $timestr = display_time($time);
        if ($duration > 0) {
            // calc end time
            $h = (int) ($time / 10000);
            $m = $time / 100 % 100;
            $m += $duration;
            $d = $duration;
            while ($m >= 60) {
                $h++;
                $m -= 60;
            }
            $end_time = sprintf("%02d%02d00", $h, $m);
            $timestr .= " - " . display_time($end_time);
            echo " - " . display_time($end_time) . "";
            echo "&raquo;&nbsp;";
        } else {
            echo "&raquo;&nbsp;";
        }
    }
    if ($login != $user && $access == 'R' && strlen($user)) {
        $PN = "(" . translate("Private") . ")";
        $PD = "(" . translate("Private") . ")";
    } elseif ($login != $event_owner && $access == 'R' && strlen($event_owner)) {
        $PN = "(" . translate("Private") . ")";
        $PD = "(" . translate("Private") . ")";
    } elseif ($login != $event_owner && strlen($event_owner)) {
        $PN = htmlspecialchars($name) . "</span>";
        $PD = activate_urls(htmlspecialchars($description));
    } else {
        $PN = htmlspecialchars($name);
        $PD = activate_urls(htmlspecialchars($description));
    }
    echo $PN;
    echo "</a>";
    if ($pri == 3) {
        echo "</strong>";
    }
    # Only display description if it is different than the event name.
    if ($PN != $PD) {
        echo " - " . $PD;
    }
    echo "<br />\n";
}
コード例 #4
0
ファイル: report.php プロジェクト: neymanna/fusionforge
function event_to_text($id, $date, $time, $duration, $name, $description, $status, $pri, $access, $event_owner)
{
    global $login, $user, $event_template, $report_id, $allow_html_description;
    $time_str = $start_time_str = $end_time_str = '';
    if ($duration == 24 * 60) {
        $time_str = translate("All day event");
    } else {
        if ($time == -1) {
            $time_str = translate("Untimed event");
        } else {
            $time_str = display_time($time);
            $start_time_str = $time_str;
            $time_short = preg_replace("/(:00)/", '', $time_str);
            if ($duration > 0) {
                if ($duration == 24 * 60) {
                    $time_str = translate("All day event");
                } else {
                    // calc end time
                    $h = (int) ($time / 10000);
                    $m = $time / 100 % 100;
                    $m += $duration;
                    $d = $duration;
                    while ($m >= 60) {
                        $h++;
                        $m -= 60;
                    }
                    $end_time = sprintf("%02d%02d00", $h, $m);
                    $time_str .= " - " . display_time($end_time);
                    $end_time_str = display_time($end_time);
                }
            }
        }
    }
    if ($login != $user && $access == 'R' && strlen($user)) {
        $name_str = "(" . translate("Private") . ")";
        $description_str = translate("This event is confidential");
    } else {
        if ($login != $event_owner && $access == 'R' && strlen($event_owner)) {
            $name_str = "(" . translate("Private") . ")";
            $description_str = translate("This event is confidential");
        } else {
            $name_str = htmlspecialchars($name);
            if (!empty($allow_html_description) && $allow_html_description == 'Y') {
                $str = str_replace('&', '&amp;', $description);
                $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($description)));
            }
        }
    }
    $date_str = date_to_str($date, "", false);
    $date_full_str = date_to_str($date, "", true, false);
    if ($duration > 0) {
        $duration_str = $duration . ' ' . translate("minutes");
    } else {
        $duration_str = '';
    }
    if ($pri == 1) {
        $pri_str = translate("Low");
    } else {
        if ($pri == 2) {
            $pri_str = translate("Medium");
        } else {
            if ($pri == 3) {
                $pri_str = translate("High");
            }
        }
    }
    if ($status == 'W') {
        $status_str = translate("Waiting for approval");
    } else {
        if ($status == 'D') {
            $status_str = translate("Deleted");
        } else {
            if ($status == 'R') {
                $status_str = translate("Rejected");
            } else {
                if ($status == 'A') {
                    $status_str = translate("Approved");
                } else {
                    $status_str = translate("Unknown");
                }
            }
        }
    }
    $href_str = "view_entry.php?id={$id}";
    // Replace all variables in the event template.
    $text = $event_template;
    $text = str_replace('${name}', $name_str, $text);
    $text = str_replace('${description}', $description_str, $text);
    $text = str_replace('${date}', $date_str, $text);
    $text = str_replace('${dateYmd}', $date, $text);
    $text = str_replace('${fulldate}', $date_full_str, $text);
    $text = str_replace('${time}', $time_str, $text);
    $text = str_replace('${starttime}', $start_time_str, $text);
    $text = str_replace('${endtime}', $end_time_str, $text);
    $text = str_replace('${duration}', $duration_str, $text);
    $text = str_replace('${priority}', $pri_str, $text);
    $text = str_replace('${href}', $href_str, $text);
    $text = str_replace('${id}', $id, $text);
    $text = str_replace('${user}', $event_owner, $text);
    $text = str_replace('${report_id}', $report_id, $text);
    return $text;
}
コード例 #5
0
<h2><?php 
echo htmlspecialchars($name);
?>
</h2>
<table style="border-width:0px;">
<tr><td style="vertical-align:top; font-weight:bold;">
  <?php 
etranslate("Description");
?>
:</td><td>
  <?php 
if (!empty($allow_html_description) && $allow_html_description == 'Y') {
    $str = str_replace('&', '&amp;', $description);
    echo str_replace('&amp;amp;', '&amp', $str);
} else {
    echo nl2br(activate_urls(htmlspecialchars($description)));
}
?>
</td></tr>

<?php 
if ($event_status != 'A' && !empty($event_status)) {
    ?>
<tr><td style="vertical-align:top; font-weight:bold;">
  <?php 
    etranslate("Status");
    ?>
:</td><td>
  <?php 
    if ($event_status == 'W') {
        etranslate("Waiting for approval");
コード例 #6
0
ファイル: view_entry.php プロジェクト: rhertzog/lcs
      </tr>';
}
if (Doc::commentsEnabled()) {
    echo '
      <tr>
        <td class="aligntop bold">' . translate('Comments') . ':</td>
        <td>';
    $comList = new CommentList($id);
    $num_comment = $comList->getSize();
    $comment_text = '';
    for ($i = 0; $i < $num_comment; $i++) {
        $cmt = $comList->getDoc($i);
        user_load_variables($cmt->getLogin(), 'cmt_');
        $comment_text .= '
          <strong>' . htmlspecialchars($cmt->getDescription()) . '</strong> - ' . $cmt_fullname . ' ' . translate('at') . ' ' . date_to_str($cmt->getModDate(), '', false, true) . ' ' . display_time($cmt->getModTime(), 2) . ($is_admin || $login == $cmt->getLogin() || user_is_assistant($login, $cmt->getLogin()) || $login == $create_by || user_is_assistant($login, $create_by) ? ' [<a href="docdel.php?blid=' . $cmt->getId() . '" onclick="return confirm( \'' . $areYouSureStr . '\' );">' . translate('Delete') . '</a>]' : '') . '<br />
          <blockquote id="eventcomment">' . nl2br(activate_urls(htmlspecialchars($cmt->getData()))) . '
        </blockquote><div style="clear:both"></div>';
    }
    if ($num_comment == 0) {
        echo translate('None') . '<br />';
    } else {
        echo '
          ' . $num_comment . ' ' . translate('comments') . '
          <input id="showbutton" type="button" value="' . translate('Show') . '" onclick="showComments();" />
          <input id="hidebutton" type="button" value="' . translate('Hide') . '" onclick="hideComments();" /><br />
          <div id="comtext">' . $comment_text . '</div>';
        // We could put the following JS in includes/js/view_entry.php,
        // but we won't need it in many cases and we don't know whether
        // we need it until after would need to include it.
        // So, we will include it here instead.
        ?>
コード例 #7
0
ファイル: report.php プロジェクト: rhertzog/lcs
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;
}
コード例 #8
0
function print_detailed_entry($id, $date, $time, $duration, $name, $description, $status, $pri, $access, $event_owner, $hide_icons)
{
    global $eventinfo, $login, $user, $TZ_OFFSET;
    static $key = 0;
    global $layers;
    #echo "<font size=\"-1\">";
    if ($login != $event_owner && strlen($event_owner)) {
        $class = "layerentry";
    } else {
        $class = "entry";
        if ($status == "W") {
            $class = "unapprovedentry";
        }
    }
    if ($pri == 3) {
        echo "<b>";
    }
    if (!$hide_icons) {
        $divname = "eventinfo-{$id}-{$key}";
        $key++;
        echo "<a class=\"{$class}\" href=\"view_entry.php?id={$id}&date={$date}";
        if (strlen($user) > 0) {
            echo "&user="******"\" onMouseOver=\"window.status='" . translate("View this entry") . "'; return true;\" onMouseOut=\"window.status=''; return true;\">";
        echo "<img src=\"circle.gif\" width=\"5\" height=\"7\" alt=\"view icon\" border=\"0\"> ";
    }
    if ($login != $event_owner && strlen($event_owner)) {
        for ($index = 0; $index < sizeof($layers); $index++) {
            if ($layers[$index]['cal_layeruser'] == $event_owner) {
                echo "<font color=\"" . $layers[$index]['cal_color'] . "\">";
            }
        }
    }
    $timestr = "";
    $my_time = $time + $TZ_OFFSET * 10000;
    if ($time >= 0) {
        if ($GLOBALS["TIME_FORMAT"] == "24") {
            printf("%02d:%02d", $my_time / 10000, $my_time / 100 % 100);
        } else {
            $h = (int) ($my_time / 10000) % 12;
            if ($h == 0) {
                $h = 12;
            }
            echo $h;
            $m = $my_time / 100 % 100;
            if ($m > 0) {
                printf(":%02d", $m);
            } else {
                print ":00";
            }
            echo (int) ($my_time / 10000) < 12 ? translate("am") : translate("pm");
        }
        //echo "&gt;";
        $timestr = display_time($time);
        if ($duration > 0) {
            // calc end time
            $h = (int) ($time / 10000);
            $m = $time / 100 % 100;
            $m += $duration;
            $d = $duration;
            while ($m >= 60) {
                $h++;
                $m -= 60;
            }
            $end_time = sprintf("%02d%02d00", $h, $m);
            $timestr .= " - " . display_time($end_time);
            echo " - " . display_time($end_time) . " ";
        }
    }
    if ($login != $user && $access == 'R' && strlen($user)) {
        $PN = "(" . translate("Private") . ")";
        $PD = "(" . translate("Private") . ")";
    } elseif ($login != $event_owner && $access == 'R' && strlen($event_owner)) {
        $PN = "(" . translate("Private") . ")";
        $PD = "(" . translate("Private") . ")";
    } elseif ($login != $event_owner && strlen($event_owner)) {
        $PN = htmlspecialchars($name) . "</font>";
        $PD = activate_urls(htmlspecialchars($description));
    } else {
        $PN = htmlspecialchars($name);
        $PD = activate_urls(htmlspecialchars($description));
    }
    echo $PN;
    echo "</a>";
    if ($pri == 3) {
        echo "</b>";
    }
    # Only display description if it is different than the event name.
    if ($PN != $PD) {
        echo " - " . $PD;
    }
    echo "</font><br><br>";
}
コード例 #9
0
ファイル: week_details.php プロジェクト: rhertzog/lcs
function print_detailed_entry($event, $date)
{
    global $eventinfo, $layers, $login, $user;
    static $key = 0;
    $descStr = $event->getDescription();
    $evAccessStr = $event->getAccess();
    $evPri = $event->getPriority() < 4;
    $getExtStr = $event->getExtForID();
    $loginStr = $event->getLogin();
    $name = $event->getName();
    $class = ($login != $loginStr && strlen($loginStr) ? 'layer' : ($event->getStatus() == 'W' ? 'unapproved' : '')) . 'entry';
    if ($getExtStr != '') {
        $id = $getExtStr;
        $name .= ' (' . translate('cont.') . ')';
    } else {
        $id = $event->getID();
    }
    $linkid = 'pop' . "{$id}-{$key}";
    $key++;
    echo ($evPri ? '
            <strong>' : '') . '
            <a title="' . translate('View this entry') . '" class="' . $class . '" id="' . $linkid . '" href="view_entry.php?id=' . $id . '&amp;date=' . $date;
    if (strlen($user) > 0) {
        echo '&amp;user='******'layerentry') {
            echo '&amp;user='******'<img src="images/circle.gif" class="bullet" alt="view icon" />';
    if ($login != $loginStr && strlen($loginStr)) {
        if ($layers) {
            foreach ($layers as $layer) {
                if ($layer['cal_layeruser'] == $loginStr) {
                    $in_span = true;
                    echo '
              <span style="color:#' . $layer['cal_color'] . ';">';
                }
            }
        }
    }
    $timestr = '';
    if ($event->isAllDay()) {
        $timestr = translate('All day event');
    } else {
        if ($event->getDuration() > 0) {
            $timestr = display_time($event->getDateTime()) . ' - ' . display_time($event->getEndDateTime());
            echo $timestr . '&raquo;&nbsp;';
        }
    }
    if ($login != $user && $evAccessStr == 'R' && strlen($user)) {
        $PN = $PD = '(' . translate('Private') . ')';
    } elseif ($login != $loginStr && $evAccessStr == 'R' && strlen($loginStr)) {
        $PN = $PD = '(' . translate('Private') . ')';
    } elseif ($login != $loginStr && strlen($loginStr)) {
        $PN = htmlspecialchars($name);
        $PD = activate_urls(htmlspecialchars($descStr));
    } else {
        $PN = htmlspecialchars($name);
        $PD = activate_urls(htmlspecialchars($descStr));
    }
    if (!empty($in_span)) {
        $PN .= '</span>';
    }
    echo $PN . '</a>' . ($evPri ? '
            </strong>' : '') . ($PN != $PD ? ' - ' . $PD : '') . '<br />';
    $eventinfo .= build_entry_popup('eventinfo-' . $linkid, $loginStr, $descStr, $timestr, site_extras_for_popup($id));
}
コード例 #10
0
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);
        }
    }
}