Code:
<%
function dateformat(str)
str = Replace(str,".","/")
dateformat = str
end function
'EventDate = date()
If Request("navi") <> "" Then
EventDate = DateValue(Request("navi"))
Else
EventDate = date
End if
CurrentMonth = Month(EventDate)
mnd = MonthName(CurrentMonth)
CurrentMonthName = ucase(left(mnd, 1)) & right(mnd, len(mnd)-1)
CurrentYear = Year(EventDate)
FirstDayDate = DateSerial(CurrentYear, CurrentMonth, 1)
LastDayDate = DateAdd("d", -1, DateSerial(CurrentYear, CurrentMonth + 1, 1))
FirstDay = WeekDay(FirstDayDate, 0)
CurrentDay = FirstDayDate
padding = FirstDay -1
db_connect 'Sub db_connect i dbfunc.asp
SQL_query = "SELECT id, dato, start, slutt, overskrift" & _
" FROM arrangement " & _
" WHERE dato >= #" & dateformat(FirstDayDate) & "#" & _
" AND dato <= #" & dateformat(LastDayDate) & "#" & _
" ORDER BY dato ASC, start ASC"
db_query(SQL_query) 'function db_query i dbfunc.asp
If rs.EOF And rs.BOF Then
Response.Write "No events found for this month"
rs.close : Set rs = nothing
Else
' Records found, so move it into a array for faster processing
arrRecSet = rs.getrows(-1) : recCount = UBound(arrRecSet, 2)
rs.close : Set rs = nothing
' Start to build the HTML for the month...
html = "<table class='" & css_class_tbl & "' cellpadding='0' cellspacing='0'>" & vbcrlf
html = html & " <tr>" & vbcrlf
html = html & " <td colspan='7' class='" & css_class_month & "'>" & four_months & "</td>" & vbcrlf
html = html & " </tr>" & vbcrlf
html = html & " <tr>" & vbcrlf
html = html & " <td colspan='7' class='" & css_class_month & "'> </td>" & vbcrlf
html = html & " </tr>" & vbcrlf
html = html & " <tr>" & vbcrlf
html = html & " <td colspan='7' class='" & css_class_month & "'><a href=""?navi=" & DateAdd("m",-1, EventDate) & """><img src=""img/paging-back.gif"" width=""15"" height=""15"" border=""0""></a> " & CurrentMonthName & ", " & CurrentYear & " <a href=""?navi=" & DateAdd("m",1, EventDate) & """><img src=""img/paging-next.gif"" width=""15"" height=""15"" border=""0""></a></td>" & vbcrlf
html = html & " </tr>" & vbcrlf
html = html & " <tr>" & vbcrlf
html = html & " <td class='" & css_class_daynames & "'>" & day_names(0, user_lang) & "</td>" & vbcrlf
html = html & " <td class='" & css_class_daynames & "'>" & day_names(1, user_lang) & "</td>" & vbcrlf
html = html & " <td class='" & css_class_daynames & "'>" & day_names(2, user_lang) & "</td>" & vbcrlf
html = html & " <td class='" & css_class_daynames & "'>" & day_names(3, user_lang) & "</td>" & vbcrlf
html = html & " <td class='" & css_class_daynames & "'>" & day_names(4, user_lang) & "</td>" & vbcrlf
html = html & " <td class='" & css_class_daynames & "'>" & day_names(5, user_lang) & "</td>" & vbcrlf
html = html & " <td class='" & css_class_daynames & "'>" & day_names(6, user_lang) & "</td>" & vbcrlf
html = html & " </tr>" & vbcrlf
html = html & " <tr>" & vbcrlf
if FirstDay <> 1 then
html = html & "<td Colspan='" & FirstDay -1 & "' class='" & css_class_blanks & "'> " & vbcrlf
WeekLoop = FirstDay
end if
LastEventChecked = 0
For i = 1 To DatePart("d", LastDayDate)
html = html & " <td>"
LoopDay = CDate(CurrentMonth & "/" & i & CurrentYear)
blnFound = False
EventCount = 0
For x = LastEventChecked To recCount
' Move the array elements into fields to aid in readability of the code...
rsID = arrRecSet(0, x) : rsdato = arrRecSet(1, x)
rsStart = arrRecSet(2, x) : rsSlutt = arrRecSet(3, x)
rsOverskrift = arrRecSet(4, x)
DateDifference = DateDiff("d", LoopDay, CDate(rsdato)
If DateDifference = 0 Then
' Event falls onto this day, so put it in the table cell
blnFound = True
overlib = "onmouseover=""return overlib('" & timeformat(rsStart) & " - " & timeformat(rsSlutt) & " " & rsOverskrift & "',CENTER,OFFSETY,'40',DELAY,'200',WIDTH,'250');"" onmouseout=""return nd();"""
' Create the event table...
If EventCount = 0 Then day_html = " <table class=""cal_content"">" & vbcrlf
day_html = day_html & " <tr>"& vbcrlf
day_html = day_html & " <td>"
If session("user_level") = "admin" Then
day_html = day_html & "<a class='" & css_class_links_events & "' href=""edit.asp?cid="& rsID &"&EventDate=" & LoopDay & """><img src=""img/edit.gif"" width=""10"" height=""10"" border=""0""></a>"
End If
day_html = day_html & "<a class=""" & css_class_links & """ href=""view.asp?cid=" & rsID & "&EventDate=" & LoopDay & """" & overlib & ">" & rsOverskrift & "</a></td>"& vbcrlf
day_html = day_html & "</tr>"& vbcrlf
EventCount = EventCount + 1
ElseIf DateDifference > 0 Then
' Event Date > month date, so stop checking, but setup look to allowe for fewer cycle checks...
LastEventChecked = x '
x = recCount
End If
Next
If blnFound Then
' For a consistent table element size???
while count_events < 4
day_html = day_html & "<tr><td> </td></tr>"& vbcrlf
count_events = count_events + 1
Wend
html = html & day_html & vbCrlf & " </table>" & vbCrLf
Else
html = html & " " & vbCrLf
End If
WeekLoop = WeekLoop + 1
If WeekLoop > 7 Then
' End of the week....
html = html & "<tr>" & vbCrLf
If DateDiff("d", LoopDay, LastDayDate) < 0 Then
' Not at the end of the month...
html = html & "<tr>" & vbCrLf
End If
WeekLoop = 1
End If
Next
html = html & "</table>"
response.write html
End if
db_kill
%>
Bookmarks