28. juni 2001 - 11:08
Der er
5 kommentarer og
1 løsning
Problemer med Kalenderscript
Hej Alle
Jeg har lidt problemer med et kalender script, her er et link til kalenderscriptet som zipfil
http://www.autonorden-it.dk/kal.zipHer er et link for at se scriptet i funktion
http://www.autonorden-it.dk/test/diary.aspMit problem er at når jeg vil ind og editere en given dato i en af disse måneder
marts, maj, juni, juli og oktober
så fungerer scriptet ikke, i alle de andre måneder fungerer det fint.
Det eneste jeg har ændret i kildekoden er
session.LCID, den har jeg ændret fra 2057 til 1030
Venligst hjælp en eller anden, for den her fejl fatter jeg ikke...
Jeg formoder fejlen ligger i diary.asp, men er ikke 100% sikker.
Hilsen
Søren
PS: Dette er en omformulering af et tidligere spørgsmål
http://www.eksperten.dk/spm/85051
Hmm der er temmeligt meget, men okay
Diary.asp:
<%@ LANGUAGE=\"VBScript\" %>
<!--#INCLUDE FILE=\"dbcon.asp\" -->
<%
Session.LCID = 1030
\'Option Explicit
set my_conn= Server.CreateObject(\"ADODB.Connection\")
my_Conn.Open DBCon
Function FormatStr(String)
on Error resume next
String = Replace(String, CHR(13), \"\")
String = Replace(String, CHR(10) & CHR(10), \"</P><P>\")
String = Replace(String, CHR(10), \"<BR>\")
FormatStr = String
End Function
Dim dtToday
dtToday = Date()
Dim dtCurViewMonth \' First day of the currently viewed month
Dim dtCurViewDay \' Current day of the currently viewed month
Dim frmDate \' Date submitted by form
\' if the GO button was used, build the date from the month and year
If InStr(1, Request.Form, \"subGO\", 1) > 0 then
if Request.Form(\"CURDATE_month\") = \"\" then
tmpMonth = month(now())
else
tmpMonth = Request.Form(\"CURDATE_month\")
End If
if Request.Form(\"CURDATE_year\") = \"\" then
tmpyear = year(now())
else
tmpyear = Request.Form(\"CURDATE_year\")
End If
tmpDate = \"1 \" & tmpMonth & \" 1999\"
mnth = Month(tmpDate)
frmDate = DateSerial(tmpyear, mnth, 1)
Else
frmDate = Request.Form(\"CURDATE\")
end if
if Request(\"view_date\") <> \"\" then
frmDate= DateSerial(year(Request(\"view_date\")), month(Request(\"view_date\")), 1)
end if
%>
<% REM This section defines functions to be used later on. %>
<% REM This sets the Previous Sunday and the Current Month %>
<%
\'--------------------------------------------------
Function DtPrevSunday(ByVal dt)
Do While WeekDay(dt) > vbSunday
dt = DateAdd(\"d\", -1, dt)
Loop
DtPrevSunday = dt
End Function
\'--------------------------------------------------
%>
<%REM Set current view month from posted CURDATE, or
\' the current date as appropriate.
\' if posted from the form
\' if prev button was hit on the form
If InStr(1, Request.Form, \"subPrev\", 1) > 0 Then
dtCurViewMonth = DateAdd(\"m\", -1, frmDate)
\' if next button was hit on the form
ElseIf InStr(1, Request.Form, \"subNext\", 1) > 0 Then
dtCurViewMonth = DateAdd(\"m\", 1, frmDate)
\' anyother time
Else
\' date add in text box
If InStr(1, Request.Form, \"subGO\", 1) > 0 then
dtCurViewMonth = frmDate
Else
if Request(\"view_date\") <> \"\" then
dtCurviewMonth = frmDate
else
dtCurViewMonth = DateSerial(Year(dtToday), Month(dtToday), 1)
End If
End If
End If
%>
<% REM --------BEGINNING OF DRAW CALENDAR SECTION-------- %>
<% REM This section executes the event query and draws a matching calendar. %>
<%
Dim iDay, iWeek, sFontColor, dictDte(31,2), intCount
strSql = \"SELECT * FROM diary WHERE month(dte)= \" & month(dtCurViewMonth) & \" and year(dte) = \" & year(dtCurViewMonth) & \" order by dte\"
set rs = my_conn.Execute (StrSql)
intCount= 0
\' populate array with days of month
on Error resume next
do until rs.EOF
if intCount > 31 then exit do
if Day(rs(\"dte\")) = intCount + 1 then
dictDte(intCount, 1) = rs(\"text_field\")
rs.Movenext
Else
dictDte(intCount, 1) = \" \"
End If
dictDte(intCount, 2) = intCount + 1
intCount = intCount + 1
loop
%>
<html>
<head>
</head>
<body>
<center><font FACE=\"Times New Roman\" SIZE=\"5\" color=\"#000080\">Calendar</font>
<form NAME=\"fmNextPrev\" ACTION=\"diary.asp\" METHOD=\"POST\">
<table CELLPADDING=\"3\" CELLSPACING=\"0\" WIDTH=\"95%\" BORDER=\"2\" BGCOLOR=\"#99CCFF\" BORDERCOLORDARK=\"#003399\" BORDERCOLORLIGHT=\"#FFFFFF\">
<tr VALIGN=\"MIDDLE\" ALIGN=\"CENTER\">
<td COLSPAN=\"7\">
<table CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\" BORDER=\"0\">
<tr VALIGN=\"MIDDLE\" ALIGN=\"CENTER\">
<td WIDTH=\"30%\" ALIGN=\"RIGHT\">
<input TYPE=\"IMAGE\" NAME=\"subPrev\" SRC=\"Left.gif\" BORDER=\"0\" WIDTH=\"18\" HEIGHT=\"20\" HSPACE=\"0\" VSPACE=\"0\">
</td>
<td WIDTH=\"40%\">
<font FACE=\"Arial\" COLOR=\"#000000\">
<b><%=MonthName(Month(dtCurViewMonth)) & \" \" & Year(dtCurViewMonth)%></b>
</font>
</td>
<td WIDTH=\"30%\" ALIGN=\"LEFT\">
<input TYPE=\"IMAGE\" NAME=\"subNext\" SRC=\"Right.gif\" BORDER=\"0\" WIDTH=\"18\" HEIGHT=\"20\" HSPACE=\"0\" VSPACE=\"0\">
</td>
</tr>
</table>
</td>
</tr>
<tr VALIGN=\"TOP\" ALIGN=\"CENTER\" BGCOLOR=\"#000099\">
<% For iDay = vbSunday To vbSaturday %>
<th WIDTH=\"14%\"><font FACE=\"Arial\" SIZE=\"-2\" COLOR=\"#FFFFFF\"><%=WeekDayName(iDay)%></font></th>
<%Next %>
</tr>
<%
dtCurViewDay = DtPrevSunday(dtCurViewMonth)
For iWeek = 0 To 5
Response.Write \"<TR VALIGN=TOP>\" & vbCrLf
Dim sBGCOLOR
sBGCOLOR = \"#99ccff\"
For iDay = 0 To 6
sBGCOLOR = \"#99ccff\"
If Month(dtCurViewDay) = Month(dtCurViewMonth) Then
If dtCurViewDay = dtToday Then sBGCOLOR = \"#99ccbb\"
else
sBGCOLOR = \"#99ccff\"
End If
Response.Write \"<TD HEIGHT=50 bgcolor=\'\" & sBGCOLOR & \"\' >\"
If Month(dtCurViewDay) = Month(dtCurViewMonth) Then
If dtCurViewDay = dtToday Then
sFontColor = \"#ff0000\"
Else
sFontColor = \"#00000\"
End If
\'---- Write day of month
Response.Write \"<FONT FACE=\"\"Arial\"\" SIZE=\"\"-2\"\" COLOR=\"\"\" & sFontColor & \"\"\"><B>\"
Response.Write \"<a href=view_day.asp?\" & \"view_date=\" & day(dtCurViewday) & \"-\" & monthname(month(dtCurViewday)) & \"-\" & year(dtCurViewday) & \">\" & Day(dtCurViewDay) & \"</a></B><br>\" & formatStr(dictDte(Day(dtCurViewDay)- 1, 1)) & \"</FONT><BR>\"
\'---Else
\'---Response.Write \" \"
End If
Response.Write \"</TD>\" & vbCrLf
dtCurViewDay = DateAdd(\"d\", 1, dtCurViewDay)
Next
Response.Write \"</TR>\" & vbCrLf
Next
%>
<%REM --------END OF DRAW CALENDAR SECTION--------
my_conn.Close
set my_conn = nothing
%>
</table>
<select name=\"CURDATE_month\">
<option value=\"<%=monthName(month(dtCurViewMonth))%>\" selected><%=monthName(month(dtCurViewMonth))%>
<option value=\"Januar\">Januar
<option value=\"Februar\">Februar
<option value=\"Marts\">Marts
<option value=\"April\">April
<option value=\"Maj\">Maj
<option value=\"Juni\">Juni
<option value=\"Juli\">Juli
<option value=\"August\">August
<option value=\"September\">September
<option value=\"Oktober\">Oktober
<option value=\"November\">November
<option value=\"December\">December
</select>
<input TYPE=\"text\" NAME=\"CURDATE_YEAR\" VALUE=\"<%=year(dtCurViewMonth)%>\" size=\"6\"><br>
<input type=\"hidden\" Name=\"CURDATE\" Value=\"<%=dtCurViewMonth%>\">
<input type=\"submit\" value=\" GO \" name=\"subGO\">
</form>
</center></div>
</font>
</center>
</body>
</html>
View_date.asp:
<!--#INCLUDE FILE=\"dbcon.asp\" -->
<%
Session.LCID = 1030
\'--------------------------------------------------
Function DtPrevSunday(ByVal dt)
Do While WeekDay(dt) > vbSunday
dt = DateAdd(\"d\", -1, dt)
Loop
DtPrevSunday = dt
End Function
\'--------------------------------------------------
Sub diary(dtView)
Dim dtToday
dtToday = Date()
Dim dtCurViewMonth \' First day of the currently viewed month
Dim dtCurViewDay \' Current day of the currently viewed month
\' Get first day of month
dttmp = dtView
dtday = day(dttmp)
dttmp = dateadd(\"d\", (-dtday+1), dttmp)
dtCurViewMonth = dttmp
Dim iDay, iWeek, sFontColor
%>
<TABLE CELLPADDING=3 CELLSPACING=0 WIDTH=\"95%\" BORDER=2 BGCOLOR=\"#99CCFF\" BORDERCOLORDARK=\"#003399\" BORDERCOLORLIGHT=\"#FFFFFF\">
<TR VALIGN=MIDDLE ALIGN=CENTER>
<TD COLSPAN=7>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%\" BORDER=0>
<TR VALIGN=MIDDLE ALIGN=CENTER>
<TD WIDTH=\"10%\" ALIGN=center>
<a href=\"view_day.asp?view_date=<%= dateadd(\"m\", -1, dtCurViewMonth) %>\"><</a>
</TD>
<TD WIDTH=\"80%\">
<FONT FACE=\"Arial\" COLOR=\"#000000\">
<B><small><%=MonthName(Month(dtCurViewMonth)) & \" \" & Year(dtCurViewMonth)%></small></B>
</FONT>
</TD>
<TD WIDTH=\"10%\" ALIGN=center>
<a href=\"view_day.asp?view_date=<%= dateadd(\"m\", 1, dtCurViewMonth) %>\">></a>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR VALIGN=TOP ALIGN=CENTER BGCOLOR=\"#000099\">
<% For iDay = vbSunday To vbSaturday %>
<TH WIDTH=\"14%\"><FONT FACE=\"Arial\" SIZE=\"-2\" COLOR=\"#FFFFFF\"><%=left(WeekDayName(iDay), 3)%></FONT></TH>
<%Next %>
</TR>
<%
dtCurViewDay = DtPrevSunday(dtCurViewMonth)
For iWeek = 0 To 5
Response.Write \"<TR VALIGN=TOP>\" & vbCrLf
Dim sBGCOLOR
sBGCOLOR = \"#99ccff\"
For iDay = 0 To 6
sBGCOLOR = \"#99ccff\"
If Month(dtCurViewDay) = Month(dtCurViewMonth) Then
If dtCurViewDay = dtToday Then sBGCOLOR = \"#99ccbb\"
else
sBGCOLOR = \"#99ccff\"
End If
Response.Write \"<TD HEIGHT=20 bgcolor=\'\" & sBGCOLOR & \"\' >\"
If Month(dtCurViewDay) = Month(dtCurViewMonth) Then
If dtCurViewDay = dtToday Then
sFontColor = \"#ff0000\"
Else
sFontColor = \"#00000\"
End If
Response.Write \"<FONT FACE=\"\"Arial\"\" SIZE=\"\"-2\"\" COLOR=\"\"\" & sFontColor & \"\"\"><B>\"
Response.Write \"<a href=view_day.asp?\" & \"view_date=\" & day(dtCurViewday) & \"-\" & monthname(month(dtCurViewday)) & \"-\" & year(dtCurViewday) & \">\" & Day(dtCurViewDay) & \"</a></B></FONT><BR>\"
End If
Response.Write \"</TD>\" & vbCrLf
dtCurViewDay = DateAdd(\"d\", 1, dtCurViewDay)
Next
Response.Write \"</TR>\" & vbCrLf
Next
%>
<%
\' --------END OF DRAW CALENDAR SECTION--------
Response.Write \"</table>\"
End Sub
%>
<%
set my_conn= Server.CreateObject(\"ADODB.Connection\")
my_Conn.Open DBcon
StrSql= \"Select * from diary where dte = #\" & Request(\"view_Date\") & \"# ORDER BY dte\"
rs = my_conn.Execute (StrSql)
\' If no records found then no worries just trap error
on Error Resume next
%>
<html>
<head>
<title></title>
<BODY bgcolor=#ffffff alink=Red vlink=#800080 link=#000080>
<DIV align=center><FONT color=#000080 face=\"Times new roman, arial\" size=4>Only Authorised
Persons can edit the diary </FONT></DIV>
<DIV align=center><FONT color=#000080 face=\"Times new roman, arial\" size=4> </FONT> </DIV>
<DIV align=center><FONT color=#000080 size=4><%= day(Request(\"view_date\")) & \" \" & monthname(month(Request(\"view_date\"))) & \" \" & year(Request(\"view_date\")) %>
</FONT></DIV>
<DIV align=center><FONT color=#000080 face=\"Times new roman, arial\" size=4>
<TABLE align=center border=0 borderColor=#dcdcdc cellPadding=2 cellSpacing=2 width=\"590\">
<TR>
<TD align=center valign=\"top\"><form action=\"add_date.asp\" method=\"post\">
<TEXTAREA name=\"txt\" cols=35 rows =10><%= rs(\"text_field\")%></TEXTAREA>
<P>Password<br><INPUT name=\"pword\" type=password></P>
<input type=\"hidden\" value=\"<%= Request(\"view_date\") %>\" name=\"view_date\">
<P><INPUT id=submit1 name=submit1 type=submit value=Submit><INPUT id=reset1 name=reset1 type=reset value=Reset><br>
<a href=\"diary.asp?view_date=<%=Request(\"view_date\")%>\">Back To Diary</a></P>
</TD></form>
<TD align=right width=\"100\">
<%
\' call diary(dateadd(\"m\", -1, Request(\"view_date\")))
call diary(Request(\"view_date\"))
call diary(dateadd(\"m\", 1, Request(\"view_date\")))
%>
</TD>
</TR>
</TABLE>
</FONT></DIV>
</BODY>
</HTML>
<%
my_conn.Close
set my_conn = nothing
%>
Add_date.asp:
<!--#INCLUDE FILE=\"dbcon.asp\" -->
<%
Session.LCID = 1030
if Request.Form(\"pword\") <> \"test\" then
Response.AddHeader \"401.1 Unauthorized: \", \"401.1\"
Response.Write \"<H2>HTTP Error 401</H2><P><STRONG>401.1 Unauthorized: Logon Failed</STRONG></P><P>This error indicates that the credentials passed to the server do not match the credentials required to log on to the server.</P>\"
Response.Write \"<center><a href=\'diary.asp\'>Back to Diary</a></center>\"
Response.End
End if
Function ChkString(string)
if string = \"\" then string = \" \"
ChkString = Replace(string, \"\'\", \"\'\'\")
End Function
set my_conn= Server.CreateObject(\"ADODB.Connection\")
my_Conn.Open DBCon
\' Check to see if it\'s a new record to be added or an old one to update
StrSql= \"Select * from diary where dte = #\" & Request(\"view_Date\") & \"#\"
set rs = my_conn.Execute (StrSql)
if rs.BOF or rs.EOF then \' No records found. i.e. New record
StrSql =\"INSERT INTO diary (dte, text_field) values (#\" & request(\"view_date\") & \"#, \'\" & chkString(request(\"txt\")) & \"\')\"
else \' Record found. i.e. update record.
StrSql = \"UPDATE diary SET diary.dte = #\" & request(\"view_date\") & \"#, text_field = \'\" & chkString(request(\"txt\")) & \"\' WHERE id = \" & rs(\"id\")
End If
my_conn.Execute (strSql)
my_Conn.Close
set my_conn = nothing
Response.Redirect (\"diary.asp?view_date=\" & request(\"view_date\"))
%>
Dbcon.asp:
<%
\' Edit the below path to point to your Database. This folder must allow write permissions
\' For the IUSER_????? Account name
DBCon = \"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\" & server.MapPath(\"diary.mdb\")
%>