View source
<?php
module_load_include('inc', 'availability_calendars', 'availability_calendars');
function availability_calendars_page_node_view($node, $view_mode) {
$calendar_node = $node->tnid && $node->tnid != $node->nid ? node_load($node->tnid) : $node;
$settings = availability_calendars_get_settings('node', $calendar_node->nid);
if ($settings->nodeview === 1 && ($view_mode == 'full' || $view_mode == 'teaser' && $settings->showteaser == 1)) {
$year = date('Y');
$month = date('m');
$node->content['availability_calendars'] = array(
'#value' => theme('availability_calendars_node', $calendar_node, $year, $month, $settings),
'#weight' => 10,
);
}
}
function theme_availability_calendars_node($node, $year = 2008, $month = 01, $settings = NULL) {
$rows = array();
$day = 1;
$output = '';
if ($settings->showkey === 1) {
$output .= theme('availability_calendars_key');
}
$monthsremaining = availability_calendars_can_edit($node) ? $settings->editormonthcount : $settings->monthcount;
while ($monthsremaining > 0) {
$output .= theme('availability_calendars_month', $node, $year, $month, $settings);
$monthsremaining--;
$month++;
if ($month > 12) {
$month = 1;
$year++;
}
}
return $output;
}
function theme_availability_calendars_month($node, $year, $month, $settings) {
$month_meta = availability_calendars_month_meta($year, $month, $settings);
$days = array(
13 => t('Mon'),
12 => t('Tue'),
11 => t('Wed'),
10 => t('Thu'),
9 => t('Fri'),
8 => t('Sat'),
7 => t('Sun'),
6 => t('Mon'),
5 => t('Tue'),
4 => t('Wed'),
3 => t('Thu'),
2 => t('Fri'),
1 => t('Sat'),
0 => t('Sun'),
);
$counter = -$month_meta['firstday'];
for ($j = 0; $j < $month_meta['weeksinmonth']; $j++) {
for ($i = 0; $i < 7; $i++) {
$counter++;
$week[$j][$i] = $counter;
if ($week[$j][$i] < 1 || $week[$j][$i] > $month_meta['daysinmonth']) {
$week[$j][$i] = "";
}
}
}
$month_title = format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y');
if (availability_calendars_can_edit($node)) {
$month_title .= ' ' . l(t('edit'), 'availability-calendars/' . $node->nid . '/' . date('Y/m', mktime(12, 0, 0, $month, 1, $year)) . '/edit', array(
'query' => array(
'destination' => 'node/' . $node->nid,
),
));
}
$headers = array();
if ($settings->showweeknotes) {
array_push($headers, array(
'data' => ' ',
'class' => 'calempty',
));
}
for ($i = $settings->startofweek + 7; $i > $settings->startofweek && $i <= 7 + $settings->startofweek; $i--) {
$day = $settings->firstletter == 0 ? $days[$i] : drupal_substr($days[$i], 0, 1);
array_push($headers, array(
'data' => $day,
'class' => 'dayofweek',
));
}
$notes = availability_calendars_get_node_notes($node->nid, $year, $month);
$states = availability_calendars_get_node_states($node->nid, $year, $month, $settings);
$today = date(AC_ISODATE);
$rows = array();
$cells = array();
foreach ($week as $key => $val) {
$weeknumber = $key + 1;
if ($settings->showweeknotes) {
$note = !empty($notes[$weeknumber]) ? '<div>' . filter_xss($notes[$weeknumber]) . '</div>' : '<div class="calweeknote-empty"></div>';
array_push($cells, array(
'data' => $note,
'class' => 'calweeknote',
));
}
for ($i = 0; $i < 7; $i++) {
$day = $week[$key][$i];
if ($day) {
$daystamp = date(AC_ISODATE, mktime(0, 0, 0, $month, $day, $year));
$status = $states[$daystamp];
$classes = array();
if ($daystamp < $today) {
$classes[] = 'calpastdate';
if ($settings->hideold != 1) {
$classes[] = $status;
}
}
else {
if ($today == $daystamp) {
$classes[] = 'caltoday';
}
$classes[] = $status;
}
$day_cell = availability_calenders_day($day, $settings);
$classes = implode(' ', $classes);
array_push($cells, array(
'data' => $day_cell,
'class' => $classes,
));
}
else {
array_push($cells, array(
'data' => '<span></span>',
'class' => 'calother',
));
}
}
array_push($rows, array(
'data' => $cells,
'class' => 'calweek',
));
$cells = array();
}
if ($weeknumber == 5) {
if ($settings->showweeknotes) {
$note = '<div class="calweeknote-empty"></div>';
array_push($cells, array(
'data' => $note,
'class' => 'calweeknote',
));
}
for ($i = 0; $i < 7; $i++) {
array_push($cells, array(
'data' => '<span></span>',
'class' => 'calother',
));
}
array_push($rows, array(
'data' => $cells,
));
}
$output = theme('table', $headers, $rows, array(
'class' => 'cal',
), $month_title);
return '<div class="calmonth-wrapper">' . $output . '</div>';
}
function availability_calenders_day($day, $settings) {
if (!$settings->splitday) {
$result = "<span>{$day}</span>";
}
else {
$result = "<span>{$day}<span></span></span>";
}
return $result;
}
function theme_availability_calendars_key() {
$keytitle = t('Key');
$headers = array(
t('Availability'),
);
$rows = array();
$states = availability_calendars_get_states();
foreach ($states as $class => $state) {
$rows[] = array(
array(
'data' => '<span>' . check_plain(t($state['label'])) . '</span>',
'class' => "{$class} keystatus",
),
);
}
$rows[] = array(
array(
'data' => '<span>' . t('Current Day') . '</span>',
'class' => 'caltoday keystatus',
),
);
$key = theme('table', $headers, $rows, array(
'class' => 'cal',
), $keytitle);
return '<div class="calmonth-wrapper key-wrapper">' . $key . '</div>';
}