'MiniWebCal: Option Public Option Explicit %REM This agent will display the calendar entries in your Notes mail file in a compact calendar format for use on a web page or on your Windows Active Desktop. To use this agent, do the following: 1. Create a new, shared, LotusScript agent in your Notes mail file, with a runtime target of "None" 2. Name the agent whatever you want (we'll be using the name "MiniWebCal" for the sake of example here) 3. Paste or import all of this code into the agent and save it 4. YOU MUST HAVE RIGHTS TO RUN RESTRICTED LOTUSSCRIPT AGENTS, AS DEFINED IN THE SERVER DOCUMENT THAT YOUR MAIL FILE IS ON. If this is not the case, you should sign the agent with an ID that does have those rights, along with rights to read your calendar (usually the server ID will work just fine for this purpose) 5. Call the agent with a URL similar to this: http://yourmailserver/mail/yourmailfile.nsf/MiniWebCal?OpenAgent where "yourmailserver" is the DNS name of your mail server, "/mail/yourmailfile.nsf" is the path to your mail file, and "MiniWebCal" is the name you used when you saved this agent Two obvious uses of this agent are to provide a small calendar on a web page (probably in an iFrame), or to include your Notes calendar as a component on your Windows desktop using Active Desktop. I'm sure there are other clever uses as well. I've tested this agent lightly with R5 and 6.51. It worked with both versions for me, although your mileage may vary. One thing this agent doesn't do is to display events that stretch across multiple days as multiple day events (it will show it on the first day only). Now that I think about it, I'm not sure if it shows repeating events or holidays either. This is all due to the view that I'm using for lookups. If you want to change this functionality, you can just create your own view and point to it in the GetTag function. version 1.0 -- 24 July 2004 Julian Robichaux http://www.nsftools.com %END REM '** constants we use to determine what kind of '** display format to use Const CAL_MONTHLY = 0 Const CAL_WEEKLY = 1 Const CAL_DAILY = 2 '** the URL reference to this agent, used in several places Dim agentURL As String '** names of days and months (populated in Initialize sub) Dim dayArrayShort As Variant Dim dayArrayMed As Variant Dim dayArrayLong As Variant Dim monthArrayShort As Variant Dim monthArrayMed As Variant Dim monthArrayLong As Variant '** newline character (for convenience) Const newline = | | '** CSS style information used by the HTML pages that are '** output by this agent. You should be very experimental '** with the styles below, to get the look and feel you want. '** You can also just point to a global stylesheet, and keep '** all the CSS there. Const css = | | Sub Initialize Dim session As New NotesSession Dim requestDoc As NotesDocument Dim dt As NotesDateTime Dim queryString As String Dim displayType As Integer Dim highlightDate As Integer Dim returnString As String '** process the Query String (if any) and get the URL of this agent Set requestDoc = session.DocumentContext If Not (requestDoc Is Nothing) Then queryString = requestDoc.Query_String_Decoded(0) agentURL = "http://" & requestDoc.Server_Name(0) & _ requestDoc.Path_Info(0) If (Len(queryString) > 0) Then agentURL = Left$(agentURL, _ Len(agentURL) - Len(requestDoc.Query_String(0)) - 1) End If End If '** figure out what we're displaying, based on the Query String displayType = GetDisplayType(queryString) highlightDate = GetHighlightPreference(queryString) Set dt = GetQueryDate(queryString) '** initialize the day and month labels dayArrayShort = r5Split("Su;Mo;Tu;We;Th;Fr;Sa", ";") dayArrayMed = r5Split("Sun;Mon;Tue;Wed;Thu;Fri;Sat", ";") dayArrayLong = r5Split("Sunday;Monday;Tuesday;Wednesday;" & _ "Thursday;Friday;Saturday", ";") monthArrayShort = r5Split("Jan;Feb;Mar;Apr;May;" & _ "Jun;Jul;Aug;Sep;Oct;Nov;Dec", ";") monthArrayMed = r5Split("Jan;Feb;Mar;Apr;May;" & _ "June;July;Aug;Sept;Oct;Nov;Dec", ";") monthArrayLong = r5Split("January;February;March;April;May;" & _ "June;July;August;September;October;November;December", ";") '** get the return string, based on what was requested Select Case displayType Case CAL_MONTHLY : returnString = GetMonthlyData(dt, highlightDate) Case CAL_WEEKLY : returnString = GetWeeklyData(dt, highlightDate) Case CAL_DAILY : returnString = GetDailyData(dt, highlightDate) Case Else : returnString = "Unknown format requested" End Select '** and print the return string to the browser to display it '** as a web page Print returnString End Sub Function GetDisplayType (queryString As String) As Integer '** figure out what format we should be using '** (default to monthly) Select Case GetQueryElement(queryString, "display") Case "MONTHLY" : GetDisplayType = CAL_MONTHLY Case "WEEKLY" : GetDisplayType = CAL_WEEKLY Case "DAILY" : GetDisplayType = CAL_DAILY Case Else : GetDisplayType = CAL_MONTHLY End Select End Function Function GetHighlightPreference (queryString As String) As Integer '** should we highlight the given date (default is yes) Select Case GetQueryElement(queryString, "highlight") Case "NO", "FALSE", "0" : GetHighlightPreference = False Case Else : GetHighlightPreference = True End Select End Function Function GetQueryDate (queryString As String) As NotesDateTime '** if we got a date on the query string, try to use it On Error Goto processError Dim dt As New NotesDateTime(Today) Dim dtString As String Dim dtVar As Variant dtString = GetQueryElement(queryString, "date") If (Len(dtString) > 0) Then dtVar = Cdat(dtString) Set dt = New NotesDateTime(dtVar) End If processError: Set GetQueryDate = dt Exit Function End Function Function GetMonthlyData (dt As NotesDateTime, highlightDate As Integer) As String '** this is the function that will display a monthly calendar, '** which is the default calendar format. To adjust the look '** and feel of the calendar, you can play with the HTML tags '** directly in this code, or modify the CSS styles, as defined in '** the Declarations section as a string constant. Dim returnString As String Dim tag As String Dim link As String Dim hday As Integer Dim dayNum As Integer Dim i As Integer '** hday is the day we're supposed to highlight, if the '** highlightDate flag is True hday = Day(dt.DateOnly) '** start with the first day of this month, and grab a '** reference to the previous and next months for '** later use Call dt.AdjustDay(1 - hday) Dim lastMonth As New NotesDateTime(dt.DateOnly) Call lastMonth.AdjustMonth(-1) Dim nextMonth As New NotesDateTime(dt.DateOnly) Call nextMonth.AdjustMonth(1) '** start writing out the HTML string we'll be sending back returnString = |
| & monthArrayLong(Month(dt.DateOnly) - 1) & | | & _
Year(dt.DateOnly) & | |
||||||
| & dayName & | | | End Forall returnString = returnString & newline & |||||||
| Next '** all the days of the month (with links, if there are '** any events/meetings on a particular day) Do dayNum = Day(dt.DateOnly) tag = r5Replace(r5Replace(GetTag(dt), "", ""), "", "") tag = r5Replace(tag, " |
| & link & |
| | & newline
Else
returnString = returnString & | | & link & _ | | | & newline End If '** if this is the end of a row, start a new one If (Weekday(dt.DateOnly) = 7) Then returnString = returnString & |||||
| Next returnString = returnString & | | ||||||
| & GetRealCalendarLinks() & | |
| & dayArrayMed(Weekday(dt.DateOnly) - 1) & |, | & _
Day(dt.DateOnly) & | | & _
monthArrayMed(Month(dt.DateOnly) - 1) & | | & _
Year(dt.DateOnly) & | |
||
| & tag & | | ||
switch to | & |monthly view | ||
| & GetRealCalendarLinks() & | |