Пример #1
0
/**
*   Display a small monthly calendar for the current month.
*   Dates that have events scheduled are highlighted.
*
*   @param  integer $year   Year to display, default is current year
*   @param  integer $month  Starting month
*   @return string          HTML for calendar page
*/
function EVLIST_smallmonth($year = 0, $month = 0, $opts = array())
{
    global $_CONF, $_EV_CONF, $LANG_MONTH, $_SYSTEM;
    $retval = '';
    // Default to the current year
    if ($year == 0) {
        $year = date('Y');
    }
    if ($month == 0) {
        $month = date('m');
    }
    $monthnum_str = sprintf("%02d", (int) $month);
    // Get all the dates in the period
    $starting_date = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
    $ending_date = date('Y-m-d', mktime(23, 59, 59, $month, 31, $year));
    $calendarView = Date_Calc::getCalendarMonth($month, $year, '%Y-%m-%d');
    $events = EVLIST_getEvents($starting_date, $ending_date, $opts);
    $T = new Template(EVLIST_PI_PATH . '/templates');
    $T->set_file(array('smallmonth' => 'phpblock_month.thtml'));
    $T->set_var('thisyear', $year);
    $T->set_var('month', $month);
    $T->set_var('monthname', $LANG_MONTH[(int) $month]);
    // Set each day column header to the first letter of the day name
    $T->set_block('smallmonth', 'daynames', 'nBlock');
    $daynames = EVLIST_getDayNames(1);
    foreach ($daynames as $key => $dayname) {
        $T->set_var('dayname', $dayname);
        $T->parse('nBlock', 'daynames', true);
    }
    $T->set_block('smallmonth', 'week', 'wBlock');
    USES_class_date();
    $dt = new Date('now', $_CONF['timezone']);
    foreach ($calendarView as $weeknum => $weekdata) {
        list($weekYear, $weekMonth, $weekDay) = explode('-', $weekdata[0]);
        $T->set_var(array('weekyear' => $weekYear, 'weekmonth' => $weekMonth, 'weekday' => $weekDay));
        $T->set_block('smallmonth', 'day', 'dBlock');
        foreach ($weekdata as $daynum => $daydata) {
            list($y, $m, $d) = explode('-', $daydata);
            $T->clear_var('no_day_link');
            if ($daydata == $_EV_CONF['_today']) {
                $dayclass = 'monthtoday';
            } elseif ($m == $monthnum_str) {
                $dayclass = 'monthon';
            } else {
                $T->set_var('no_day_link', 'true');
                $dayclass = 'monthoff';
            }
            $popup = '';
            if (isset($events[$daydata])) {
                // Create the tooltip hover text
                $daylinkclass = $dayclass == 'monthoff' ? 'nolink-events' : 'day-events';
                foreach ($events[$daydata] as $event) {
                    // Show event titles on different lines if more than one
                    if (!empty($popup)) {
                        $popup .= EVLIST_tooltip_newline();
                    }
                    // Don't show a time for all-day events
                    if ($event['allday'] == 0 && $event['rp_date_start'] == $event['rp_date_end']) {
                        $dt->setTimestamp(strtotime($event['rp_date_start'] . ' ' . $event['rp_time_start1']));
                        // Time is a localized string, not a timestamp, so
                        // don't adjust for the timezone
                        $popup .= $dt->format($_CONF['timeonly'], false) . ': ';
                    }
                    $popup .= htmlentities($event['title']);
                }
                $T->set_var('popup', $popup);
            } else {
                $daylinkclass = 'day-noevents';
                $T->clear_var('popup');
            }
            $T->set_var(array('daylinkclass' => $daylinkclass, 'dayclass' => $dayclass, 'day' => substr($daydata, 8, 2), 'pi_url' => EVLIST_URL));
            $T->parse('dBlock', 'day', true);
        }
        $T->parse('wBlock', 'week', true);
        $T->clear_var('dBlock');
    }
    $T->parse('output', 'smallmonth');
    return $T->finish($T->get_var('output'));
}
Пример #2
0
/**
*   Display a yearly calendar.
*   Dates that have events scheduled are highlighted.
*
*   @param  integer $year   Year to display, default is current year
*   @param  integer $month  Starting month
*   @param  integer $day    Starting day
*   @param  integer $cat    Category to show
*   @param  integer $cal    Calendar to show
*   @return string          HTML for calendar page
*/
function EVLIST_yearview($year = 0, $month = 0, $day = 0, $cat = 0, $cal = 0, $opt = '')
{
    global $_CONF, $_EV_CONF, $LANG_MONTH;
    EVLIST_setViewSession('year', $year, $month, $day);
    $retval = '';
    // Default to the current year
    if ($year == 0) {
        $year = date('Y');
    }
    if ($month == 0) {
        $month = date('m');
    }
    if ($day == 0) {
        $day = date('d');
    }
    $cat = (int) $cat;
    $cal = (int) $cal;
    // Get all the dates in the year
    $starting_date = date('Y-m-d', mktime(0, 0, 0, 1, 1, $year));
    $ending_date = date('Y-m-d', mktime(0, 0, 0, 1, 1, $year + 1));
    $calendarView = Date_Calc::getCalendarYear($year, '%Y-%m-%d');
    $daynames = EVLIST_getDayNames(1);
    $events = EVLIST_getEvents($starting_date, $ending_date, array('cat' => $cat, 'cal' => $cal));
    $T = new Template(EVLIST_PI_PATH . '/templates/yearview');
    $tpl = 'yearview';
    if ($opt == 'print') {
        $tpl .= '_print';
    } elseif ($_EV_CONF['cal_tmpl'] == 'json') {
        $tpl .= '_json';
    }
    $T->set_file(array('yearview' => $tpl . '.thtml'));
    $count = 0;
    $T->set_block('yearview', 'month', 'mBlock');
    foreach ($calendarView as $monthnum => $monthdata) {
        $monthnum_str = sprintf("%02d", $monthnum + 1);
        $count++;
        if (($count - 1) % 4 == 0) {
            $T->set_var('st_row', 'true');
        } else {
            $T->clear_var('st_row');
        }
        $M = new Template($_CONF['path'] . 'plugins/evlist/templates/yearview');
        $M->set_file(array('smallmonth' => 'smallmonth.thtml'));
        $M->set_var('thisyear', $year);
        $M->set_var('month', $monthnum + 1);
        $M->set_var('monthname', $LANG_MONTH[$monthnum + 1]);
        $M->set_block('smallmonth', 'daynames', 'nBlock');
        for ($i = 0; $i < 7; $i++) {
            $M->set_var('dayname', $daynames[$i]);
            $M->parse('nBlock', 'daynames', true);
        }
        $M->set_block('smallmonth', 'week', 'wBlock');
        foreach ($monthdata as $weeknum => $weekdata) {
            list($weekYear, $weekMonth, $weekDay) = explode('-', $weekdata[0]);
            $M->set_var(array('weekyear' => $weekYear, 'weekmonth' => $weekMonth, 'weekday' => $weekDay, 'urlfilt_cat' => $cat, 'urlfilt_cal' => $cal));
            $M->set_block('smallmonth', 'day', 'dBlock');
            foreach ($weekdata as $daynum => $daydata) {
                list($y, $m, $d) = explode('-', $daydata);
                $M->clear_var('no_day_link');
                if ($daydata == $_EV_CONF['_today']) {
                    $dayclass = 'today';
                } elseif ($m == $monthnum_str) {
                    $dayclass = 'on';
                } else {
                    $M->set_var('no_day_link', 'true');
                    $dayclass = 'off';
                }
                if (isset($events[$daydata])) {
                    // Create the mootip hover text
                    $popup = '';
                    $daylinkclass = $dayclass == 'off' ? 'nolink-events' : 'day-events';
                    foreach ($events[$daydata] as $event) {
                        // Separate events by a line (if more than one)
                        if (!empty($popup)) {
                            $popup .= '<hr />' . LB;
                        }
                        // Don't show a time for all-day events
                        if ($event['allday'] == 0) {
                            $popup .= date($_CONF['timeonly'], strtotime($event['date_start'] . ' ' . $event['time_start1'])) . ': ';
                        }
                        $popup .= htmlentities($event['title']);
                    }
                    $M->set_var('popup', $popup);
                } else {
                    $daylinkclass = 'day-noevents';
                    $M->clear_var('popup');
                }
                $M->set_var(array('daylinkclass' => $daylinkclass, 'dayclass' => $dayclass, 'day' => substr($daydata, 8, 2), 'pi_url' => EVLIST_URL, 'urlfilt_cat' => $cat, 'urlfilt_cal' => $cal));
                $M->parse('dBlock', 'day', true);
            }
            $M->parse('wBlock', 'week', true);
            $M->clear_var('dBlock');
        }
        $M->parse('onemonth', 'smallmonth');
        $T->set_var('month', $M->finish($M->get_var('onemonth')));
        if ($count % 4 == 0) {
            $T->set_var('end_row', 'true');
        } else {
            $T->clear_var('end_row');
        }
        $T->parse('mBlock', 'month', true);
    }
    $T->set_var(array('pi_url' => EVLIST_URL, 'thisyear' => $year, 'prevyear' => $year - 1, 'nextyear' => $year + 1, 'cal_header' => EVLIST_calHeader($year, $month, $day, 'year', $cat, $cal), 'cal_footer' => EVLIST_calFooter($calendars_used), 'urlfilt_cat' => $cat, 'urlfilt_cal' => $cal));
    $T->parse('output', 'yearview');
    return $T->finish($T->get_var('output'));
}