Månedskalender
Jeg søger en kalender der ligner dennewww.lund.dk/kalender.asp
Koden for denne er her under - men syntes simpelthen den er så rodet,og giver mig problemer når jeg skal til at synkronisere med en database.
Nogen som kan hjælpe med at omkrive den lidt pænere, eller har anden tilsvarende?
<%
option explicit
session.lcid = 1033
'extracted data
dim current_date, first_day, this_day, this_week, this_month, this_year, last_day, day_of_week
' counters
dim counter, wdays, weeks, start_week, week_calc, num_weeks_in_year, right_year_divided
' Create an array to display the month names
dim month_name(12)
month_name(1)="JANUAR "
month_name(2)="FEBRUAR "
month_name(3)="MARTS "
month_name(4)="APRIL "
month_name(5)="MAJ "
month_name(6)="JUNI "
month_name(7)="JULI "
month_name(8)="AUGUST "
month_name(9)="SEPTEMBER "
month_name(10)="OKTOBER "
month_name(11)="NOVEMBER "
month_name(12)="DECEMBER "
dim day_name(7)
day_name(1)="M "
day_name(2)="T "
day_name(3)="O "
day_name(4)="T "
day_name(5)="F "
day_name(6)="L "
day_name(7)="S "
' create a variable for the current date
current_date=date()
' create a variable for the current year from the current date
this_year=year(current_date)
' create a variable for the current month from the current date
this_month=month(current_date)
' create a variable for the current day from the current date
this_day=day(current_date)
' create a variable for the current week from the current date
this_week = DatePart("WW", current_date)
' create a variable for the week number which the first day of the month is part of
start_week = weekNumber (dateSerial(this_year, this_month , 1))
' create a variable for the current day number from the current date assuming monday is the first day
day_of_week = DatePart("W", current_date, vbMonday)
' create a variable for the first day from the current date
first_day = weekday(dateSerial(this_year, this_month, 00))
' create a variable for the length of the current month
select case this_month
' For the months with 31 wdays set the end date
case "1","3","5","7","8","10","12"
'january
'march
'may
'july
'august
'october
'december
last_day = 31
' For February set the end date by applying the leap year rules
' if the year is evenly divisable by 4 or ending in 00 divisable by 400
case "2"
'february
last_day = 28
right_year_divided=this_year/4
if right_year_divided = cint(right_year_divided) then
last_day = 29
end if
if right(this_year,2)="00" then
right_year_divided=this_year/400
if right_year_divided = cint(right_year_divided) then
last_day = 29
end if ' end check of year values
end if ' end check for new century
' All the rest of the months have 30 wdays
case "4","6","9","11"
'april
'june
'september
'november
last_day = 30
end select ' end selct of month
%>
<html>
<title>Kalender</title>
<head>
<meta http-equiv="Content-Language" content="da">
</head>
<body>
<p align="center"> </p>
<table border="0" width="70%" id="table1" cellspacing="0" align="center">
<%
'page header start
%>
<tr>
<td width="57" style="border-top: solid 2px #000000;border-bottom: solid 2px #000000;"> </td>
<td align="center" style="border-top: solid 2px #000000;border-bottom: solid 2px #000000;"><b><%=month_name(this_month)%> <%=this_year%> - <%=this_month%>. MÅNED</b></td>
<td width="42" style="border-top: solid 2px #000000;border-bottom: solid 2px #000000;"> </td>
</tr>
<%
'page header end
'**************************************************
' Loop for the first week
'**************************************************
for counter = 1 to 7
' Check to see what day the first of the month falls on
if counter > first_day - 1 then
' Count for wdays
wdays = wdays + 1
%>
<tr>
<%
if counter = first_day or counter = 1 then
if DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
' grey the first cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
<%
elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
' sunday - grey out cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
<td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;"> </td>
<td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
<%
else
%>
<td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
<%
end if
elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
' grey the first cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"> </td>
<%
elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
' sunday - grey out cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
<td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;"> </td>
<td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;"> </td>
<%
else
' no grey on normal and saturday
%>
<td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"> </td>
<%
end if
%>
</tr>
<%
end if ' End check for first day of the week
next
'**************************************************
' Loop for the remaining weeks in the month
'**************************************************
for weeks = 1 to 5
start_week = weeknumber(dateserial(this_year,this_month, wdays+1))
'**************************************************
' Loop the week
'**************************************************
for counter = 1 to 7
' increment wdays
wdays = wdays + 1
if wdays <= last_day then
%>
<tr>
<%
if counter = 1 then
if DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
' grey the first cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
<%
elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
' sunday - grey out cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
<td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;"> </td>
<td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
<%
else
%>
<td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%><%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"><%=start_week%></td>
<%
end if
elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 6 then
' grey the first cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"> </td>
<%
elseif DatePart("W", this_year & "-" & this_month & "-" & formatNumber(wdays,0,true,false,false), vbMonday) = 7 then
' sunday - grey out cell
%>
<td bgcolor="#CCCCCC" width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
<td bgcolor="#CCCCCC" style="border-bottom: solid 1px #000000;"> </td>
<td bgcolor="#CCCCCC" width="42" style="border-bottom: solid 1px #000000;"> </td>
<%
else
' no grey on normal and saturday
%>
<td width="57" style="border-bottom: solid 1px #000000;"><%=day_name(counter)%> <%=wdays%></td>
<td style="border-bottom: solid 1px #000000;"> </td>
<td width="42" style="border-bottom: solid 1px #000000;"> </td>
<%
end if
%>
</tr>
<%
end if ' End check for first day of the week
next
next
%>
</table>
</body>
</html>
<%Public Function WeekNumber(InDate)
Dim v1
Dim v2
Dim v3
Dim v4
Dim v5
Dim v6
Dim v7
v1=Days(InDate)
v4=Weekday(DateSerial(Year(InDate),1,1),vbUseSystemDayOfWeek)-1
v5=Weekday(DateSerial(Year(InDate),12,31),vbUseSystemDayOfWeek)-1
v2=7-(v4-1)
v3=7-(v5-1)
If v4=4 Or v5=4 Then v7=True Else v7=False
v6=(v1-v2-4)/7
If v2=>4 Then WeekNumber=cint(v6)+2 Else WeekNumber=cint(v6)+1
If WeekNumber>52 And Not v7 Then WeekNumber=1
If WeekNumber=0 Then WeekNumber=WeekNumber(DateSerial(Year(InDate)-1,12,31))
End Function
Public Function Days(v1)
Days=v1-DateSerial(Year(v1),1,0)
End Function%>
