一个日历函数
长沙北大青鸟作者:科泰校区匿名
摘要:<? ##################################################### # Based on PHP-NUKE: eCalendar System # by Don Grabowski Don@ecomjunk.com - <a href="http://ecomjunk.com" target="_blank">http://ecomjunk.co
<?
#####################################################
# Based on PHP-NUKE: eCalendar System
# by Don Grabowski Don@ecomjunk.com - <a href="http://ecomjunk.com" target="_blank">http://ecomjunk.com</a>
#
# Calendrier version 2.2 Beta for Xoops 1.0 RC3
# Copyright ?2002, Pascal Le Boustouller
# pascal@xoopsien.net - <a href="http://www.xoopsien.net" target="_blank">http://www.xoopsien.net</a>
# Licence: GPL
#
# Merci de laisser ce copyright en place...
#####################################################
# This function come from PostCalendar
# <a href="http://www.bahraini.tv" target="_blank">http://www.bahraini.tv</a>
#####################################################
/* 预定义常量,适合制作多语种主页 */
define("_CALJAN","一月");
define("_CALFEB","二月");
define("_CALMAR","三月");
define("_CALAPR","四月");
define("_CALMAY","五月");
define("_CALJUN","六月");
define("_CALJUL","七月");
define("_CALAUG","八月");
define("_CALSEP","九月");
define("_CALOCT","十月");
define("_CALNOV","十一月");
define("_CALDEC","十二月");
define("_SUN","星期日");
define("_MON","星期一");
define("_TUE","星期二");
define("_WED","星期三");
define("_THU","星期四");
define("_FRI","星期五");
define("_SAT","星期六");
define("_CAL_SUN","日");
define("_CAL_MON","一");
define("_CAL_TUE","二");
define("_CAL_WED","三");
define("_CAL_THU","四");
define("_CAL_FRI","五");
define("_CAL_SAT","六");
/* 以上预定义一般在其它文件如config.inc中进行 */
/* 用网站本国语言书写十二个月的名称,以下常量需预先定义 */
function getMonthName($month) {
if ($month == "01") {
$monthname = _CALJAN;
} elseif ($month == "02") {
$monthname = _CALFEB;
} elseif ($month == "03") {
$monthname = _CALMAR;
} elseif ($month == "04") {
$monthname = _CALAPR;
} elseif ($month == "05") {
$monthname = _CALMAY;
} elseif ($month == "06") {
$monthname = _CALJUN;
} elseif ($month == "07") {
$monthname = _CALJUL;
} elseif ($month == "08") {
$monthname = _CALAUG;
} elseif ($month == "09") {
$monthname = _CALSEP;
} elseif ($month == "10") {
$monthname = _CALOCT;
} elseif ($month == "11") {
$monthname = _CALNOV;
} elseif ($month == "12") {
$monthname = _CALDEC;
}
return $monthname;
}
/* 制作十二个月的下拉选单 */
function buildMonthSelect($month) {
for ($i = 1; $i <= 12; $i++) {
if ($i == $month) $sel = "SELECTED";
else $sel = "";
$nm = getMonthName($i);
echo "<option $sel value="$i">$nmn</option>";
}
}
/* 制作日期的下拉选单 */
function buildDaySelect($day) {
for ($i = 1; $i <= 31; $i++) {
if ($i == $day) $sel = "SELECTED";
else $sel = "";
echo "<option $sel value="$i">$in</option>";
}
}
/* 制作年份的下拉选单 */
function buildYearSelect($year) {
for ($i = 1997; $i <= 2030; $i++) {
if ($i == $year) $sel = "SELECTED";
else $sel = "";
echo "<option $sel value="$i">$in</option>";
}
}
$time24Hour = 1; // 1 = 24 hour time... 0 = AM/PM time
/* 制作小时计时的下拉选单 */
function buildHourSelect($hour) {
global $time24Hour, $pntable;
if (!($time24Hour)) {
for ($i = 1; $i <= 12; $i++) {
if ($i == $hour) $sel = "SELECTED";
else $sel = "";
echo "<option $sel value="$i">$i</option>n";
}
} else {
for ($i = 0; $i <= 23; $i++) {
if ($i == $hour) $sel = "SELECTED";
else $sel = "";
echo "<option $sel value="$i">";
if ($i<10) echo "0";
echo "$i</option>n";
}
}
}
/* 制作分钟的下拉选单 */
function buildMinSelect($min) {
for ($i = 0; $i <= 55<img src="images/smilies/wink.gif" border="0" alt=""> {
echo $i;
if (($i == $min) | (($i == 0) & ($min == "00"))) $sel = "SELECTED";
else $sel = "";
echo "<option $sel value="";
if ($i<10) echo "0";
echo "$i">";
if ($i<10) echo "0";
echo "$i</option>n";
$i = $i + 5;
}
}
/* 选择上午还是下午 */
function buildAMPMSelect($ampm) {
if ($ampm == "AM") $sel = "SELECTED";
else $sel = "";
echo "<option $sel value="AM">AM</option>n";
if ($ampm == "PM") $sel = "SELECTED";
else $sel = "";
echo "<option $sel value="PM">PM</option>n";
}
/* 格式化时间 */
function getTimeFormat($hour,$min,$ampm) {
if (($ampm == "AM") & ($hour == "12")) {
$hour = "00";
} elseif (($ampm == "PM") & ($hour != "12")) {
$hour = 12 + $hour;
}
$time = "$hour:$min:00";
return $time;
}
/* 显示日历 */
function littlecal($month, $year) {
/* 默认状态下取当月历 */
if (empty($year))
$year=date("Y");
if (empty($month))
$month=date("m");
$date=01; // 当月日期数
$day=01; // 日期
$off=0; // off>7时表示一周满,换行
/* 求出本月天数 */
while (checkdate($month,$date,$year)):
$date++;
endwhile;
/* 输出星期日到星期六,常量需预先定义 */
echo "<table border='0' cellpadding='1' cellspacing='1' class='even'><tr class='odd' align="center">";
echo "<td>"._CAL_SUN."</td>";
echo "<td>"._CAL_MON."</td>";
echo "<td>"._CAL_TUE."</td>";
echo "<td>"._CAL_WED."</td>";
echo "<td>"._CAL_THU."</td>";
echo "<td>"._CAL_FRI."</td>";
echo "<td>"._CAL_SAT."</td>";
/* 输出日期 */
echo "<tr>";
while ($day<$date):
if ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Sunday') {
echo "<td valign='top' height='10' width='10' class='head'>";
echo "<input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
$off = '01';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Monday') {
echo "<td></td><td valign='top' height='10' width='10' class='head'><input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
$off= '02';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Tuesday') {
echo "<td></td><td></td><td valign='top' height='10' width='10' class='head'><input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
$off= '03';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Wednesday') {
echo "<td></td><td></td><td></td><td valign='top' height='10' width='10' class='head'><input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
$off= '04';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Thursday') {
echo "<td></td><td></td><td></td><td></td><td valign='top' height='10' width='10' class='head'><input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
$off= '05';
}
elseif ($day == '01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Friday') {
echo "<td></td><td></td><td></td><td></td><td></td><td valign='top' height='10' width='10' class='head'><input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
$off= '06';
}
elseif ($day =='01' and date('l', mktime(0,0,0,$month,$day,$year)) == 'Saturday') {
echo "<td></td><td></td><td></td><td></td><td></td><td></td><td valign='top' height='10' width='10' class='head'><input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
$off= '07';
}
else {
echo "<td valign='top' height='10' width='10' class='head'><input type='checkbox' name='Day[$i]' value='$day'>$day</td>";
}
$day++;
$off++;
if ($off>7) {
echo "</tr><tr>";
$off='01';
} else {
echo "";
}
endwhile;
echo "</tr></table>";
}
/* 窗口定位 */
function move() {
echo "<SCRIPT LANGUAGE="javascript">
<!--
window.moveTo(10,10);
//-->
</SCRIPT>";
}
?>