function print_entry($event, $date)
{
    global $categories, $DISPLAY_END_TIMES, $DISPLAY_LOCATION, $DISPLAY_TASKS_IN_GRID, $eventinfo, $is_assistant, $is_nonuser_admin, $layers, $login, $PHP_SELF, $TIME_SPACER, $user;
    static $key = 0;
    static $viewEventStr, $viewTaskStr;
    if (empty($viewEventStr)) {
        $viewEventStr = translate('View this event');
        $viewTaskStr = translate('View this task');
    }
    $catIcon = $in_span = $padding = $popup_timestr = $ret = $timestr = '';
    $cal_type = $event->getCalTypeName();
    $loginStr = $event->getLogin();
    if (access_is_enabled()) {
        $can_access = access_user_calendar('view', $loginStr, '', $event->getCalType(), $event->getAccess());
        $time_only = access_user_calendar('time', $loginStr);
        if ($cal_type == 'task' && $can_access == 0) {
            return false;
        }
    } else {
        $can_access = CAN_DOALL;
        $time_only = 'N';
    }
    // No need to display if show time only and not a timed event.
    if ($time_only == 'Y' && !$event->Istimed()) {
        return false;
    }
    $class = ($login != $loginStr && strlen($loginStr) ? 'layer' : ($event->getStatus() == 'W' ? 'unapproved' : '')) . 'entry';
    // If we are looking at a view, then always use "entry".
    if (strstr($PHP_SELF, 'view_m.php') || strstr($PHP_SELF, 'view_t.php') || strstr($PHP_SELF, 'view_v.php') || strstr($PHP_SELF, 'view_w.php')) {
        $class = 'entry';
    }
    if ($event->getPriority() < 4) {
        $ret .= '<strong>';
    }
    $cloneStr = $event->getClone();
    $id = $event->getID();
    $linkid = 'pop' . "{$id}-{$key}";
    $name = $event->getName();
    $view_text = $cal_type == 'task' ? $viewTaskStr : $viewEventStr;
    $key++;
    // Build entry link if UAC permits viewing.
    if ($can_access != 0 && $time_only != 'Y') {
        // Make sure clones have parents URL date.
        $href = 'href="view_entry.php?id=' . $id . '&amp;date=' . ($cloneStr ? $cloneStr : $date) . (strlen($user) > 0 ? '&amp;user=' . $user : ($class == 'layerentry' ? '&amp;user=' . $loginStr : '')) . '"';
        $title = ' title="' . $view_text . '" ';
    } else {
        $href = $title = '';
    }
    $ret .= '
      <a ' . $title . ' class="' . $class . '" id="' . "{$linkid}\" {$href}" . '><img src="';
    $catNum = abs($event->getCategory());
    $icon = $cal_type . '.gif';
    if ($catNum > 0) {
        $catIcon = 'icons/cat-' . $catNum . '.gif';
        if (!file_exists($catIcon)) {
            $catIcon = '';
        }
    }
    if (empty($catIcon)) {
        $ret .= 'images/' . $icon . '" class="bullet" alt="' . $view_text . '" width="5" height="7" />';
    } else {
        // Use category icon.
        $catAlt = empty($categories[$catNum]) ? '' : translate('Category') . ': ' . $categories[$catNum]['cat_name'];
        $ret .= $catIcon . '" alt="' . $catAlt . '" title="' . "{$catAlt}\" />";
    }
    if ($login != $loginStr && strlen($loginStr)) {
        if ($layers) {
            foreach ($layers as $layer) {
                if ($layer['cal_layeruser'] == $loginStr) {
                    $in_span = true;
                    $ret .= '<span style="color:' . $layer['cal_color'] . ';">';
                }
            }
        }
        // Check to see if Category Colors are set.
    } else {
        if (!empty($categories[$catNum]['cat_color'])) {
            $cat_color = $categories[$catNum]['cat_color'];
            if ($cat_color != '#000000') {
                $in_span = true;
                $ret .= '<span style="color:' . $cat_color . ';">';
            }
        }
    }
    if ($event->isAllDay()) {
        $timestr = $popup_timestr = translate('All day event');
    } else {
        if (!$event->isUntimed()) {
            $timestr = $popup_timestr = display_time($event->getDateTime());
            if ($event->getDuration() > 0) {
                $popup_timestr .= ' - ' . display_time($event->getEndDateTime());
            }
            if ($DISPLAY_END_TIMES == 'Y') {
                $timestr = $popup_timestr;
            }
            if ($cal_type == 'event') {
                $ret .= getShortTime($timestr) . ($time_only == 'Y' ? '' : $TIME_SPACER);
            }
        }
    }
    return $ret . build_entry_label($event, 'eventinfo-' . $linkid, $can_access, $popup_timestr, $time_only) . (!empty($location) && !empty($DISPLAY_LOCATION) && $DISPLAY_LOCATION == 'Y' ? '<br /><span class="location">(' . htmlspecialchars($location) . ')</span>' : '') . ($in_span == true ? '</span>' : '') . '</a>' . ($event->getPriority() < 4 ? '</strong>' : '') . '<br />';
}
Example #2
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;
}