Tip

Web Based Calendar Control

In the Notes client you have calendar controls for date/time fields in layout regions; here's an agent that builds a calendar control for using on the Web.

' Create an agent using this code and call it by using a link on a web page that opens it up in its own window and having a parameter of &Field=FieldName where 'FieldName is the Name of the field in your form you want the date the user selects 'from this window to goto

' For example:
' Create a javascipt function on a html form like
' function ShowCalander(FieldName){
'windows.open('/database.nsf/AgentName/?OpenAgent&Field=' + FieldName,'CalendarWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=320,height=200');
'}

' And create a link a the form next to the field you want the calander to put its date into in the format <a onclick="ShowCalandar('FieldName')">Click</a>

' Code for Initialize method of agent

Dim Sess As New NotesSession()
Dim ThisDB As NotesDatabase
Dim AgentDoc As NotesDocument
Dim TodaysDate As NotesDateTime
Dim TimeNow As NotesDateTime
Dim FirstofMonth As NotesDateTime
Dim NextMonth As NotesDateTime
Dim LastMonth As NotesDateTime
Dim RowCounter As Integer
Dim DayNum As Integer
Dim MonNum As Integer
Dim YearNum As Integer
Dim ThisMonth As String
Dim ParseInt As Integer
Dim ParseString,FieldName,DateString As String
Dim BackLink,NextLink As String

DateString = ""

Set AgentDoc = Sess.DocumentContext
Set ThisDb = AgentDoc.ParentDatabase
' Get the field name and the date required from the URL string

ParseInt = Instr(AgentDoc.Path_Info(0), "&Field=")

If ParseInt = 0 Then Print "You must run this agent with a ""Field"" parameter or the calendar does not know which field to place the data in the parent window"
Exit Sub
End If

ParseString =Right(AgentDoc.Path_Info(0),Len(AgentDoc.Path_Info(0)) - ParseInt -6 )

ParseInt = Instr(ParseString, "&Date=")

If ParseInt = 0 Then

FieldName = Trim(ParseString)

Else

FieldName = Left(ParseString, ParseInt- 1)

DateString = Right(ParseString,Len(ParseString) - ParseInt -5 )

End If

' If the URL has not given us a date assume today
If DateString = "" Then
Set TodaysDate = New NotesDateTime("")
Call TodaysDate.SetNow
Set FirstofMonth=New NotesDateTime("")
Call FirstofMonth.SetNow
Set NextMonth=New NotesDateTime("")
Call NextMonth.SetNow
Set LastMonth=New NotesDateTime("")
Call LastMonth.SetNow

Else

Set TodaysDate = New NotesDateTime(DateString)
Set FirstofMonth = New NotesDateTime(DateString)
Set LastMonth = New NotesDateTime(DateString)
Set NextMonth = New NotesDateTime(DateString)

End If

' Set lastMonth to be a month ago
Call LastMonth.AdjustMonth(-1)

' Set NextMonth to be a month ahead Call NextMonth.AdjustMonth(1)

Set TimeNow = New NotesDateTime("") Call TimeNow.SetNow

MonNum = Month(TodaysDate.lslocaltime)
YearNum = Year(TodaysDate.lslocaltime)
'Find out how many days this is front the start of the Month
DayNum = Day(TodaysDate.lslocaltime)

Select Case MonNum

Case 1
ThisMonth = "January"
Case 2
ThisMonth = "February"
Case 3
ThisMonth = "March"
Case 4
ThisMonth = "April"
Case 5
ThisMonth = "May"
Case 6
ThisMonth = "June"
Case 7
ThisMonth = "July"
Case 8
ThisMonth = "August"
Case 9
ThisMonth = "September"
Case 10
ThisMonth = "October"
Case 11
ThisMonth = "November"
Case 12
ThisMonth = "December"
End Select
' Now adjust FirstofMonthBack to the start of the month
Call FirstofMonth.AdjustDay(1-DayNum)

Print "<HTML>"
Print "<HEAD>"

' Print the javascript function to send the date selected back to the parent window and close the calendar window
Print "<SCRIPT>"
Print "function DateSetter(Date)"
Print "{"
Print "window.opener.document.forms[0]." + FieldName + ".value=Date;"
Print "window.close()"
Print "}"
Print "</SCRIPT>"
Print "</HEAD>"
Print "<BODY BGCOLOR=""#FFFFF"">"
Print "<TABLE WIDTH=""300"" CELLPADDING=0 CELLSPACING=0 BORDER=1>"
Print "<TR>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1 COLOR=""BLUE""><A HREF=""/" + ConvtoURLString(ThisDB.FilePath) + "/CalendarWindow/?OpenAgent&Field=" + _ FieldName + "&Date=" + LastMonth.DateOnly + """>>></A></TD>"


Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1 COLOR=""BLUE""><CENTER>" + ThisMonth + " - " + Cstr(YearNum) +"</CENTER></FONT></B></TD>"

Print "<TD ALIGN=""RIGHT""><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1 COLOR=""BLUE""><A HREF=""/" + ConvtoURLString(ThisDB.FilePath) + "/CalendarWindow/?OpenAgent&Field=" + _
FieldName + "&Date=" + NextMonth.DateOnly + """>>></A></TD>"

Print "<TR>"
Print "</TABLE>"

Print "<TABLE WIDTH=""300"" CELLPADDING=0 CELLSPACING=0 BORDER=1>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Sun  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Mon  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Tue  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Wed  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Thu  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Fri  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Sat  </FONT></B></TD>"
Print "</TR>"

RowCounter = 1

Print "<TR>"
' Now Build up the spaces for the forst row of the calendar that pad before the first day
While RowCounter < Weekday(FirstofMonth.lslocaltime)
RowCounter = RowCounter + 1
Print "<TD BGCOLOR=""#C0C0C0""><FONT FACE=""TAHOMA,ARIAL"" SIZE=1> </FONT></TD>"
Wend

' Now Buildup the rest of the calendar for this month

While Month(FirstofMonth.lslocaltime) = MonNum

If Month(TimeNow.lslocaltime) = Month(FirstofMonth.lslocaltime) And Year(TimeNow.lslocaltime) = Year(FirstofMonth.lslocaltime) And Day(TimeNow.lslocaltime) = Day(FirstofMonth.lslocaltime) Then

Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1><CENTER><A HREF=""javascript:DateSetter('" +FirstofMonth.DateOnly + "')"">" + Cstr(Day(FirstofMonth.lslocaltime)) + "</A></B></CENTER></FONT></TD>"

Else

Print "<TD><FONT FACE=""TAHOMA,ARIAL"" SIZE=1><CENTER><A HREF=""javascript:DateSetter('" +FirstofMonth.DateOnly + "')"">" + Cstr(Day(FirstofMonth.lslocaltime)) + "</A></CENTER></FONT></TD>"

End If

RowCounter = RowCounter + 1

' If we are at the end of a row then print out the end of row marker and start a new row
If RowCounter = 8 Then
RowCounter = 1
Print "</TR>"
Print "<TR>"
End If
' Now Move to the nextday
Call FirstofMonth.AdjustDay(1)
Wend

' and Finally fill in the boxes that are blank at the end
While RowCounter < 8

Print "<TD BGCOLOR=""#C0C0C0""><FONT FACE=""TAHOMA,ARIAL"" SIZE=1> </FONT></TD>"
RowCounter = RowCounter + 1

Wend

Print "</TR>"
Print "</TABLE>"
Print "</BODY>"
Print "</HTML>"

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.