Event Calendar

<% @ Language="JavaScript" %>

<HTML>

etc...

<%

etc...

/********** BODY OF THE TABLE **********/

etc...

/********** SET UP CONNECTION & RECORDSET OBJECTS **********/

var adOpenStatic = 3;
var adLockOptimistic = 3;
var adCmdText = 0x0001;

// DSN-less connection string
var strDSN = "DRIVER={Microsoft Access Driver (*.mdb)};
                        DBQ=" + Server.MapPath("calendar.mdb") +  ";"

/*
create a new instance of the ADO, same idea we use for
var someArrayVar = new Array();
var someDateVar = new Date(); or
var someImageVar = new Image();
*/
var conn = Server.
CreateObject("ADODB.Connection");

// open a connection to the database
conn.
Open(strDSN);

// create a new instance of the ADO Recordset Object
var
rsCal = Server.CreateObject("ADODB.RecordSet");

var nMonth = Month + 1;

var strSQL = "SELECT * FROM calendar
                       WHERE Month = " + nMonth + " AND Year = " + Year + "";

var rsCal = Server.CreateObject("ADODB.RecordSet");

// Recordset Object
rsCal.Open(strSQL, conn, adOpenStatic, adLockOptimistic, adCmdText);

/********** END OF SET UP CONNECTION & RECORDSET OBJECTS **********/

for (i = 0; i < daysInMonth;) {
     if (column++ != 7) {
         
// checking to see if this particular is today -
         
// if it is make the number color blue else the number will be the default color
          if (now.getMonth() == Month && now.getDate() == Day && now.getYear() == Year) {
               Response.write('<TD VALIGN="top" ALIGN="left" HEIGHT="60">
                                           <FONT COLOR="blue"><B>' + Day++ + '</FONT>');

               // if not at the 1st record then move to the 1st record
               if (!
rsCal.BOF) rsCal.MoveFirst();

               while (!rsCal.EOF) { // while not at End of "File" - while records still exist
                    if (rsCal("Day") == Day - 1) { // is there a record (an Event) for that day
                        
// if there is an Event Create a Link to display this particular Event
                         Response.write('<BR><FONT SIZE="2">
                                                    <A HREF="display_event.asp?ID=' +
rsCal("ID") + '">' +
                                                   
rsCal("Subject") +
                                                    '</A></FONT><BR>');
                    }
                    rsCal.MoveNext(); // move to next record
               }
               Response.write('</B></TD>');
          }
          else { // if there is no Event(s) for that particular day leave the day "empty"
               Response.write('<TD VALIGN="top" ALIGN="left" HEIGHT="60"><B>' +
                                           Day++ + '</FONT>');

               // if Date is not today's Date then - identical to the above code
               if (!rsCal.BOF) rsCal.MoveFirst();

               while (!rsCal.EOF) {
                    if (rsCal("Day") == Day - 1) {
                         Response.write('<BR><FONT SIZE="2">
                                                     <A HREF="display_event.asp?ID=' +
rsCal("ID") + '">' +
                                                    
rsCal("Subject") +
                                                     '</A></FONT><BR>');
                    }
                    rsCal.MoveNext();
               }
               Response.write('</B></TD>'); // finish of column
    
     }
          i++;
     }
     else {
          Response.write("</TR><TR>"); // finish of row
          column = 0;
     }
}

/********** CLOSE & DESTROY ADO OBJECTS **********/

// close & delete the Recordset Object
rsCal.Close();
rsCal = null;

// close & delete the Connection Object
conn.
Close();
conn = null;

/*
Once you have finished with an Object, you should Close() it and free any associated system resources. NOTE: This doesn't actually remove the object from memory; so you can Open() it again if you need to. To completely free the memory for the object you should set it to null.
*/

/********** END OF CLOSE & DESTROY ADO OBJECTS **********/

if (column != 0 && column < 7) {
     for (i = column; i < 7; i++) {
          Response.write('<TD BGCOLOR="#c0c0c0">&nbsp;</TD>'); // ending blank cells
     }
}

/********** END OF BODY OF THE TABLE **********/

%>

</TR>

</TABLE>

<SCRIPT>

// this function allows us to open any Month & Year we choose
function
getCal(form) {
     var month = form.Month.value;
     var year = form.Year.value;

     location.href = 'calendar.asp?Month=' + month + '&' + 'Year=' + year;
}

</SCRIPT>

<FORM NAME="display">

Month
<SELECT
NAME="Month">
     <OPTION
VALUE="1">Jan</OPTION>
     <OPTION
VALUE="2">Feb</OPTION>
     <OPTION
VALUE="3">Mar</OPTION>
     <OPTION
VALUE="4">Apr</OPTION>
     <OPTION
VALUE="5">May</OPTION>
     <OPTION
VALUE="6">Jun</OPTION>
     <OPTION
VALUE="7">Jul</OPTION>
     <OPTION
VALUE="8">Aug</OPTION>
     <OPTION
VALUE="9">Sep</OPTION>
     <OPTION
VALUE="10">Oct</OPTION>
     <OPTION
VALUE="11">Nov</OPTION>
     <OPTION
VALUE="12">Dec</OPTION>
</SELECT>

Year
<SELECT
NAME="Year">
     <OPTION
VALUE="2000">00</OPTION>
     <OPTION
VALUE="2001" SELECTED>01</OPTION>
     <OPTION
VALUE="2002">02</OPTION>
     <OPTION
VALUE="2003">03</OPTION>
     <OPTION
VALUE="2004">04</OPTION>
     <OPTION
VALUE="2005">05</OPTION>
</SELECT>

<A HREF="javascript:getCal(display)"
 
onMouseOver="status='Display Calendar'; return true"
 
onMouseOut="status=''">
<IMG
SRC="images/display.gif">
</A>

<INPUT TYPE="button" VALUE="Add an Event"
 
onClick="location.href='add_event.asp'">

</FORM>

</BODY>