📄 calendar_functions.php
字号:
/***********************************************************
function date_frombits
---- DESCRIPTION -------------------------------------------
Produce a string representing the date given separate
date elements.
---- ARGUMENTS ---------------------------------------------
year : The year
month : The month
day : The date (day)
---- RETURNS -----------------------------------------------
A string containing the specified date in the format of
year-month-day. The input need not be zero-padded; the
returned string will be padded if needed.
***********************************************************/
function date_frombits($year, $month, $day) {
return $year . '-' . sprintf('%02d', $month) . '-' . sprintf('%02d', $day);
}
/***********************************************************
function mktime_q
---- DESCRIPTION -------------------------------------------
Calculate the UNIX timestamp of a month, day, and year
---- ARGUMENTS ---------------------------------------------
year : The year
month : The month
day : The date (day)
---- RETURNS -----------------------------------------------
The UNIX timestamp of midnight on the date specified.
***********************************************************/
function mktime_q($year, $month, $day) {
return mktime(0, 0, 0, $month, $day, $year);
}
/***********************************************************
function in_range
---- DESCRIPTION -------------------------------------------
Determine whether given date is within the given range
---- ARGUMENTS ---------------------------------------------
date : The target date
start : Range start
end : Range end
All values are expected in UNIX timestamp form.
---- RETURNS -----------------------------------------------
The UNIX timestamp of midnight on the date specified.
***********************************************************/
function in_range($date, $start, $end) {
return ($date >= $start && $date <= $end);
}
/***********************************************************
function make_month
---- DESCRIPTION -------------------------------------------
Generate a small monthly calendar, populated with dates
and highlights for current date and appointments if
present.
---- ARGUMENTS ---------------------------------------------
month : Desired month
year : Desired year
data : [Optional] Structure returned by
cachetasks to use in make_month without
querying the database again
watch :
large : used for monthly calendar display
---- RETURNS -----------------------------------------------
HTML containing a table with the specified month.
***********************************************************/
function make_month($month, $year, $data = NULL, $watch = NULL, $large='') {
global $settings, $user, $daysshort_array;
$week = date('W', strtotime("$year-$month-01"));
if (!$view) {
$view = "daily";
}
$time = mktime_q($year, $month, 1); // time
$days = date(t, $time); // number of days in month
$day1 = date(w, $time); // days of the week
$now = explode('-', formatymd(date('Y-m-d')));
$start = "$year-" . sprintf('%02d', $month) . "-01";
$end = date('Y-m-d', strtotime("$year-" . sprintf('%02d', $month) . "-01 + 1 month"));
$end = date('Y-m-01', strtotime($end)); _r();
$end = date('Y-m-d', strtotime($end . " -1 day"));
if (is_array($data)) {
$tasks = $data;
} else {
$tasks = cachetasks($start, $end, NULL, NULL, NULL, NULL, NULL, $watch);
}
if ($large) {
switch ($user['weekstart']) {
case 1:
$weekdays = array(1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 0 => 'Sunday');
$endday = 0;
break;
case 2:
$weekdays = array(2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 0 => 'Sunday', 1 => 'Monday');
$endday = 1;
break;
case 3:
$weekdays = array(3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday');
$endday = 2;
break;
case 4:
$weekdays = array(4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday');
$endday = 3;
break;
case 5:
$weekdays = array(5 => 'Friday', 6 => 'Saturday', 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday');
$endday = 4;
break;
case 6:
$weekdays = array(6 => 'Saturday', 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday');
$endday = 5;
break;
case 7:
$weekdays = array(0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');
$endday = 6;
break;
}
} else {
switch ($user[weekstart]) {
case 1:
$weekdays = array(1 => 'M', 2 => 'T', 3 => 'W', 4 => 'T', 5 => 'F', 6 => 'S', 0 => 'S');
$endday = 0;
break;
case 2:
$weekdays = array(2 => 'T', 3 => 'W', 4 => 'T', 5 => 'F', 6 => 'S', 0 => 'S', 1 => 'M');
$endday = 1;
break;
case 3:
$weekdays = array(3 => 'W', 4 => 'T', 5 => 'F', 6 => 'S', 0 => 'S', 1 => 'M', 2 => 'T');
$endday = 2;
break;
case 4:
$weekdays = array(4 => 'T', 5 => 'F', 6 => 'S', 0 => 'S', 1 => 'M', 2 => 'T', 3 => 'W');
$endday = 3;
break;
case 5:
$weekdays = array(5 => 'F', 6 => 'S', 0 => 'S', 1 => 'M', 2 => 'T', 3 => 'W', 4 => 'T');
$endday = 4;
break;
case 6:
$weekdays = array(6 => 'S', 0 => 'S', 1 => 'M', 2 => 'T', 3 => 'W', 4 => 'T', 5 => 'F');
$endday = 5;
break;
case 7:
default:
$weekdays = array(0 => 'S', 1 => 'M', 2 => 'T', 3 => 'W', 4 => 'T', 5 => 'F', 6 => 'S');
$endday = 6;
break;
}
}
// build day header html
$html = "<table cellspacing=\"1\" " . iff($large, 'width="100%" ') . "cellpadding=\"3\" style=\"background-color: black;\"><tr class=\"calendar_title\"><td colspan=\"8\" align=\"center\"><b><a class=\"calendar_title\" href=\"../calendar/index.php?do=monthly&y=$year&month=$month&watch=$watch\">"
. date('M', $time) . "</a> - <a class=\"calendar_title\" href=\"../calendar/index.php?do=yearly&year=$year&watch=$watch\">$year</a></b></td></tr>";
unset($i);
$html .= "<td class=\"calendar_empty\"></td>";
// Generate empty cells as needed
foreach ($weekdays AS $key => $var) {
if ($key == $day1) {
$y = $i;
}
$html .= "<td class=\"calendar_titles\" align=\"center\"><b>$var</b></td>";
$i++;
}
$html .= "</tr><tr>";
$html .= "<td class=\"calendar_empty\"><a href=\"../calendar/index.php?do=weekly&week=$week&year=$year&watch=$watch\">". html_image('tech/bul083.gif') . "</a></td>";
// add empty cells
$html .= str_repeat("<td class=\"calendar_empty\"></td>", $y);
// build content
$day_no = $day1;
for ($i = 1; $i <= $days; $i++) {
unset($class);
$check = "$year-" . sprintf("%02d", $month) . "-" . sprintf("%02d", $i);
// current day
if (($now[0] == $year) && ($now[1] == sprintf("%02d", $month)) && ($now[2] == sprintf("%02d", $i))) {
$class = 'calendar_current';
}
if (@count($tasks[$check])) {
if (!$class) {
$class = 'calendar_tasks';
}
// there is a task
if ($large) {
$k = "<a class=\"$class\" href=\"../calendar/index.php?do=$view&type=calendar&year=$year&month=$month&day=$i&watch=$watch\">$i</a>";
unset($task_count);
unset($apptdata);
foreach ($tasks[$check] as $task) {
$task_count++;
if ($task_count < 5) {
if (strlen($task[1]) > 30) {
$task[1] = substr($task[1], 0, 30) . "...";
}
$tmp_today = strtotime($today);
$tmp_item = strtotime($task[3]);
$apptdata .= "<br />-$task[1]\n";
// max 4 tasks and then show more link
} elseif ($task_count == 5) {
$apptdata .= "<br /> <a href=\"../calendar/index.php?do=$view&type=calendar&year=$year&month=$month&day=$i&watch=$watch\"class=\"$class\">more ...</a>";
}
}
$k .= $apptdata;
} else {
$k = "<a class=\"$class\" href=\"../calendar/index.php?do=$view&type=calendar&year=$year&month=$month&day=$i&watch=$watch\">$i</a>";
}
} else {
if ($large) {
$k = "$i";
if (!$class) {
$class = 'calendar_no_tasks';
}
} else {
$k = "$i";
if (!$class) {
$class = 'calendar_no_tasks';
}
}
}
$html .= "<td " . iff($large, "width=\"14%\" valign=\"top\" height=\"80\"", "align=\"center\" width=\"25\" height=\"25\"") . " class=\"$class\">$k</td>";
$day_no = $day_no % 7;
$j++;
if ($day_no == $endday) {
unset($j);
$week++;
if ($i != ($days)) {
$html .= "</tr><tr>";
$html .= "<td class=\"calendar_empty\"><a href=\"../calendar/index.php?do=weekly&week=$week&year=$year&watch=$watch\">". html_image('tech/bul083.gif') . "</a></td>";
}
}
$day_no++;
}
// add empty cells
if ($j != 0) {
$html .= str_repeat("<td class=\"calendar_empty\"></td>", 7 - $j);
}
$html .= "</tr></table>\n\n\n";
return $html;
}
/***********************************************************
function format_date
---- DESCRIPTION -------------------------------------------
Returns a human-readable version of the specified date,
such as "1st January" or "23rd March".
---- ARGUMENTS ---------------------------------------------
date : Date to format
---- RETURNS -----------------------------------------------
String containing human-readable version of the date.
***********************************************************/
function format_date ($date) {
$tmp = split('-', $date);
// get rid of leading 0
if ($tmp[2][0] == '0') {
$tmp[2] = $tmp[2][1];
}
$bit = $tmp[2];
if ($tmp[2] == 1 OR $tmp[2] == 21 OR $tmp[2] == 31) {
$bit .= 'st';
} elseif ($tmp[2] == 2 OR $tmp[2] == 22) {
$bit .= 'nd';
} elseif ($tmp[2] == 3 OR $tmp[2] == 23) {
$bit .= 'rd';
} else {
$bit .= 'th';
}
$bit .= ' ';
$bit .= month_name($tmp[1]);
return $bit;
}
/***********************************************************
function month_name
---- DESCRIPTION -------------------------------------------
Returns the long month name ("January," "February",
etc.) of the given month
---- ARGUMENTS ---------------------------------------------
month : Month to format
---- RETURNS -----------------------------------------------
String containing the long month name.
***********************************************************/
function month_name($month) {
switch ($month) {
case 1: return "January";
case 2: return "February";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -