| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id$
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Theming functions.
|
| 8 |
*/
|
| 9 |
|
| 10 |
function theme_holidays_navigation($cal) {
|
| 11 |
global $year, $month;
|
| 12 |
|
| 13 |
drupal_add_js (drupal_get_path('module', 'holidays'). '/holidays_demo.theme.js');
|
| 14 |
drupal_add_css(drupal_get_path('module', 'holidays'). '/holidays_demo.theme.css');
|
| 15 |
|
| 16 |
$output .= "<table class='navigator-table' align='center'><tr>";
|
| 17 |
|
| 18 |
$output .= "<td>";
|
| 19 |
$output .= "<div class='title'>". $cal->title() ."</div>";
|
| 20 |
$output .= "<div class='navigator-today'>";
|
| 21 |
$today = getdate(time());
|
| 22 |
$output .= _holidays_build_link(t('Back to today'), $today['year'], $today['mon']);
|
| 23 |
$output .= "</div>";
|
| 24 |
$output .= "</td>";
|
| 25 |
|
| 26 |
$output .= "<td>";
|
| 27 |
|
| 28 |
$output .= "<div class='navigator'>";
|
| 29 |
$output .= _holidays_build_link(t('Previous year'), $year - 1, $month, _holidays_back_arrow($cal));
|
| 30 |
$output .= ' '. _holidays_get_year_selector() .' ';
|
| 31 |
$output .= _holidays_build_link(t('Next year'), $year + 1, $month, _holidays_forward_arrow($cal));
|
| 32 |
$output .= "</div>"; // <!-- .navigator -->
|
| 33 |
|
| 34 |
$output .= "<div class='navigator'>";
|
| 35 |
$output .= _holidays_build_link(t('Previous month'), $year, $month - 1, _holidays_back_arrow($cal));
|
| 36 |
$output .= ' '. _holidays_get_month_selector() .' ';
|
| 37 |
$output .= _holidays_build_link(t('Next month'), $year, $month + 1, _holidays_forward_arrow($cal));
|
| 38 |
$output .= "</div>"; // <!-- .navigator -->
|
| 39 |
|
| 40 |
$start_date_str = $cal->getLongDate(array('year'=>$year, 'mon'=>$month, 'mday'=>1));
|
| 41 |
$end_date_str = $cal->getLongDate(array('year'=>$year, 'mon'=>$month, 'mday'=>cal_days_in_month(CAL_GREGORIAN, $month, $year)));
|
| 42 |
|
| 43 |
$output .= "<div class='calendar-range'>";
|
| 44 |
$output .= "$start_date_str – $end_date_str";
|
| 45 |
$output .= "</div>";
|
| 46 |
|
| 47 |
$output .= "</td>";
|
| 48 |
$output .= "</table>";
|
| 49 |
|
| 50 |
return $output;
|
| 51 |
}
|
| 52 |
|
| 53 |
function _holidays_get_year_selector() {
|
| 54 |
global $year, $month;
|
| 55 |
$output = '<select id="year-selector">';
|
| 56 |
foreach (range($year - 70, $year + 70) as $y) {
|
| 57 |
$selected = ($y == $year) ? 'selected' : '';
|
| 58 |
$output .= "<option value='$y' $selected>$y</option>";
|
| 59 |
}
|
| 60 |
$output .= '</select>';
|
| 61 |
return $output;
|
| 62 |
}
|
| 63 |
|
| 64 |
function _holidays_get_month_selector() {
|
| 65 |
global $year, $month;
|
| 66 |
$output = '<select id="month-selector">';
|
| 67 |
foreach (range(1, 12) as $m) {
|
| 68 |
$selected = ($m == $month) ? 'selected' : '';
|
| 69 |
$output .= "<option value='$m' $selected>". map_month($m) ."</option>";
|
| 70 |
}
|
| 71 |
$output .= '</select>';
|
| 72 |
return $output;
|
| 73 |
}
|
| 74 |
|
| 75 |
function _holidays_build_url($year, $month) {
|
| 76 |
$url = request_uri();
|
| 77 |
if ($month == 13) {
|
| 78 |
++$year;
|
| 79 |
$month = 1;
|
| 80 |
}
|
| 81 |
if ($month == 0) {
|
| 82 |
--$year;
|
| 83 |
$month = 12;
|
| 84 |
}
|
| 85 |
if (strstr($url, 'year=')) {
|
| 86 |
$url = preg_replace('/(?<=year=)(\d+)/', $year, $url);
|
| 87 |
$url = preg_replace('/(?<=month=)(\d+)/', $month, $url);
|
| 88 |
} else {
|
| 89 |
$url .= strstr($url, '?') ? '&' : '?';
|
| 90 |
$url .= "year=$year&month=$month";
|
| 91 |
}
|
| 92 |
return $url;
|
| 93 |
}
|
| 94 |
|
| 95 |
function _holidays_build_link($text, $year, $month, $img = NULL) {
|
| 96 |
$url = _holidays_build_url($year, $month);
|
| 97 |
if ($img) {
|
| 98 |
$text = theme('image', drupal_get_path('module', 'holidays') .'/'. $img, $text, $text);
|
| 99 |
}
|
| 100 |
return "<a href='$url'>$text</a>";
|
| 101 |
}
|
| 102 |
|
| 103 |
function _holidays_forward_arrow($cal) {
|
| 104 |
return _holidays_calculate_dir($cal) == 'ltr' ? 'right.gif' : 'left.gif';
|
| 105 |
}
|
| 106 |
|
| 107 |
function _holidays_back_arrow($cal) {
|
| 108 |
return _holidays_calculate_dir($cal) == 'ltr' ? 'left.gif' : 'right.gif';
|
| 109 |
}
|
| 110 |
|