home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / ASP / calendar.asp < prev    next >
Encoding:
Text File  |  2001-06-08  |  8.9 KB  |  244 lines

  1. <%
  2. '*******************************************************
  3. '*     ASP 101 Sample Code - http://www.asp101.com     *
  4. '*                                                     *
  5. '*   This code is made available as a service to our   *
  6. '*      visitors and is provided strictly for the      *
  7. '*               purpose of illustration.              *
  8. '*                                                     *
  9. '* Please direct all inquiries to webmaster@asp101.com *
  10. '*******************************************************
  11. %>
  12.  
  13. <%
  14. ' ***Begin Function Declaration***
  15. ' New and improved GetDaysInMonth implementation.
  16. ' Thanks to Florent Renucci for pointing out that I
  17. ' could easily use the same method I used for the
  18. ' revised GetWeekdayMonthStartsOn function.
  19. Function GetDaysInMonth(iMonth, iYear)
  20.     Dim dTemp
  21.     dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))
  22.     GetDaysInMonth = Day(dTemp)
  23. End Function
  24.  
  25. ' Previous implementation on GetDaysInMonth
  26. 'Function GetDaysInMonth(iMonth, iYear)
  27. '    Select Case iMonth
  28. '        Case 1, 3, 5, 7, 8, 10, 12
  29. '            GetDaysInMonth = 31
  30. '        Case 4, 6, 9, 11
  31. '            GetDaysInMonth = 30
  32. '        Case 2
  33. '            If IsDate("February 29, " & iYear) Then
  34. '                GetDaysInMonth = 29
  35. '            Else
  36. '                GetDaysInMonth = 28
  37. '            End If
  38. '    End Select
  39. 'End Function
  40.  
  41. Function GetWeekdayMonthStartsOn(dAnyDayInTheMonth)
  42.     Dim dTemp
  43.     dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
  44.     GetWeekdayMonthStartsOn = WeekDay(dTemp)
  45. End Function
  46.  
  47. Function SubtractOneMonth(dDate)
  48.     SubtractOneMonth = DateAdd("m", -1, dDate)
  49. End Function
  50.  
  51. Function AddOneMonth(dDate)
  52.     AddOneMonth = DateAdd("m", 1, dDate)
  53. End Function
  54. ' ***End Function Declaration***
  55.  
  56.  
  57. Dim dDate     ' Date we're displaying calendar for
  58. Dim iDIM      ' Days In Month
  59. Dim iDOW      ' Day Of Week that month starts on
  60. Dim iCurrent  ' Variable we use to hold current day of month as we write table
  61. Dim iPosition ' Variable we use to hold current position in table
  62.  
  63.  
  64. ' Get selected date.  There are two ways to do this.
  65. ' First check if we were passed a full date in RQS("date").
  66. ' If so use it, if not look for seperate variables, putting them togeter into a date.
  67. ' Lastly check if the date is valid...if not use today
  68. If IsDate(Request.QueryString("date")) Then
  69.     dDate = CDate(Request.QueryString("date"))
  70. Else
  71.     If IsDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year")) Then
  72.         dDate = CDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year"))
  73.     Else
  74.         dDate = Date()
  75.         ' The annoyingly bad solution for those of you running IIS3
  76.         If Len(Request.QueryString("month")) <> 0 Or Len(Request.QueryString("day")) <> 0 Or Len(Request.QueryString("year")) <> 0 Or Len(Request.QueryString("date")) <> 0 Then
  77.             Response.Write "The date you picked was not a valid date.  The calendar was set to today's date.<BR><BR>"
  78.         End If
  79.         ' The elegant solution for those of you running IIS4
  80.         'If Request.QueryString.Count <> 0 Then Response.Write "The date you picked was not a valid date.  The calendar was set to today's date.<BR><BR>"
  81.     End If
  82. End If
  83.  
  84. 'Now we've got the date.  Now get Days in the choosen month and the day of the week it starts on.
  85. iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
  86. iDOW = GetWeekdayMonthStartsOn(dDate)
  87.  
  88. %>
  89. <!-- Outer Table is simply to get the pretty border-->
  90. <TABLE BORDER=10 CELLSPACING=0 CELLPADDING=0>
  91. <TR>
  92. <TD>
  93. <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 BGCOLOR=#99CCFF>
  94.     <TR>
  95.         <TD BGCOLOR=#000099 ALIGN="center" COLSPAN=7>
  96.             <TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0>
  97.                 <TR>
  98.                     <TD ALIGN="right"><A HREF="./calendar.asp?date=<%= SubtractOneMonth(dDate) %>"><FONT COLOR=#FFFF00 SIZE="-1"><<</FONT></A></TD>
  99.                     <TD ALIGN="center"><FONT COLOR=#FFFF00><B><%= MonthName(Month(dDate)) & "  " & Year(dDate) %></B></FONT></TD>
  100.                     <TD ALIGN="left"><A HREF="./calendar.asp?date=<%= AddOneMonth(dDate) %>"><FONT COLOR=#FFFF00 SIZE="-1">>></FONT></A></TD>
  101.                 </TR>
  102.             </TABLE>
  103.         </TD>
  104.     </TR>
  105.     <TR>
  106.         <TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Sun</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
  107.         <TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Mon</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
  108.         <TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Tue</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
  109.         <TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Wed</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
  110.         <TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Thu</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
  111.         <TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Fri</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
  112.         <TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Sat</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
  113.     </TR>
  114. <%
  115. ' Write spacer cells at beginning of first row if month doesn't start on a Sunday.
  116. If iDOW <> 1 Then
  117.     Response.Write vbTab & "<TR>" & vbCrLf
  118.     iPosition = 1
  119.     Do While iPosition < iDOW
  120.         Response.Write vbTab & vbTab & "<TD> </TD>" & vbCrLf
  121.         iPosition = iPosition + 1
  122.     Loop
  123. End If
  124.  
  125. ' Write days of month in proper day slots
  126. iCurrent = 1
  127. iPosition = iDOW
  128. Do While iCurrent <= iDIM
  129.     ' If we're at the begginning of a row then write TR
  130.     If iPosition = 1 Then
  131.         Response.Write vbTab & "<TR>" & vbCrLf
  132.     End If
  133.     
  134.     ' If the day we're writing is the selected day then highlight it somehow.
  135.     If iCurrent = Day(dDate) Then
  136.         Response.Write vbTab & vbTab & "<TD BGCOLOR=#00FFFF><FONT SIZE=""-1""><B>" & iCurrent & "</B></FONT><BR><BR></TD>" & vbCrLf
  137.     Else
  138.         Response.Write vbTab & vbTab & "<TD><A HREF=""./calendar.asp?date=" & Month(dDate) & "-" & iCurrent & "-" & Year(dDate) & """><FONT SIZE=""-1"">" & iCurrent & "</FONT></A><BR><BR></TD>" & vbCrLf
  139.     End If
  140.     
  141.     ' If we're at the endof a row then write /TR
  142.     If iPosition = 7 Then
  143.         Response.Write vbTab & "</TR>" & vbCrLf
  144.         iPosition = 0
  145.     End If
  146.     
  147.     ' Increment variables
  148.     iCurrent = iCurrent + 1
  149.     iPosition = iPosition + 1
  150. Loop
  151.  
  152. ' Write spacer cells at end of last row if month doesn't end on a Saturday.
  153. If iPosition <> 1 Then
  154.     Do While iPosition <= 7
  155.         Response.Write vbTab & vbTab & "<TD> </TD>" & vbCrLf
  156.         iPosition = iPosition + 1
  157.     Loop
  158.     Response.Write vbTab & "</TR>" & vbCrLf
  159. End If
  160. %>
  161. </TABLE>
  162. </TD>
  163. </TR>
  164. </TABLE>
  165.  
  166. <BR>
  167.  
  168. <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN="center">
  169. <FORM ACTION="./calendar.asp" METHOD=GET>
  170. <SELECT NAME="month">
  171.     <OPTION VALUE=1>January</OPTION>
  172.     <OPTION VALUE=2>February</OPTION>
  173.     <OPTION VALUE=3>March</OPTION>
  174.     <OPTION VALUE=4>April</OPTION>
  175.     <OPTION VALUE=5>May</OPTION>
  176.     <OPTION VALUE=6>June</OPTION>
  177.     <OPTION VALUE=7>July</OPTION>
  178.     <OPTION VALUE=8>August</OPTION>
  179.     <OPTION VALUE=9>September</OPTION>
  180.     <OPTION VALUE=10>October</OPTION>
  181.     <OPTION VALUE=11>November</OPTION>
  182.     <OPTION VALUE=12>December</OPTION>
  183. </SELECT>
  184. <SELECT NAME="day">
  185.     <OPTION VALUE=1>1</OPTION>
  186.     <OPTION VALUE=2>2</OPTION>
  187.     <OPTION VALUE=3>3</OPTION>
  188.     <OPTION VALUE=4>4</OPTION>
  189.     <OPTION VALUE=5>5</OPTION>
  190.     <OPTION VALUE=6>6</OPTION>
  191.     <OPTION VALUE=7>7</OPTION>
  192.     <OPTION VALUE=8>8</OPTION>
  193.     <OPTION VALUE=9>9</OPTION>
  194.     <OPTION VALUE=10>10</OPTION>
  195.     <OPTION VALUE=11>11</OPTION>
  196.     <OPTION VALUE=12>12</OPTION>
  197.     <OPTION VALUE=13>13</OPTION>
  198.     <OPTION VALUE=14>14</OPTION>
  199.     <OPTION VALUE=15>15</OPTION>
  200.     <OPTION VALUE=16>16</OPTION>
  201.     <OPTION VALUE=17>17</OPTION>
  202.     <OPTION VALUE=18>18</OPTION>
  203.     <OPTION VALUE=19>19</OPTION>
  204.     <OPTION VALUE=20>20</OPTION>
  205.     <OPTION VALUE=21>21</OPTION>
  206.     <OPTION VALUE=22>22</OPTION>
  207.     <OPTION VALUE=23>23</OPTION>
  208.     <OPTION VALUE=24>24</OPTION>
  209.     <OPTION VALUE=25>25</OPTION>
  210.     <OPTION VALUE=26>26</OPTION>
  211.     <OPTION VALUE=27>27</OPTION>
  212.     <OPTION VALUE=28>28</OPTION>
  213.     <OPTION VALUE=29>29</OPTION>
  214.     <OPTION VALUE=30>30</OPTION>
  215.     <OPTION VALUE=31>31</OPTION>
  216. </SELECT>
  217. <SELECT NAME="year">
  218.     <OPTION VALUE=1990>1990</OPTION>
  219.     <OPTION VALUE=1991>1991</OPTION>
  220.     <OPTION VALUE=1992>1992</OPTION>
  221.     <OPTION VALUE=1993>1993</OPTION>
  222.     <OPTION VALUE=1994>1994</OPTION>
  223.     <OPTION VALUE=1995>1995</OPTION>
  224.     <OPTION VALUE=1996>1996</OPTION>
  225.     <OPTION VALUE=1997>1997</OPTION>
  226.     <OPTION VALUE=1998>1998</OPTION>
  227.     <OPTION VALUE=1999>1999</OPTION>
  228.     <OPTION VALUE=2000 SELECTED>2000</OPTION>
  229.     <OPTION VALUE=2001>2001</OPTION>
  230.     <OPTION VALUE=2002>2002</OPTION>
  231.     <OPTION VALUE=2003>2003</OPTION>
  232.     <OPTION VALUE=2004>2004</OPTION>
  233.     <OPTION VALUE=2005>2005</OPTION>
  234.     <OPTION VALUE=2006>2006</OPTION>
  235.     <OPTION VALUE=2007>2007</OPTION>
  236.     <OPTION VALUE=2008>2008</OPTION>
  237.     <OPTION VALUE=2009>2009</OPTION>
  238.     <OPTION VALUE=2010>2010</OPTION>
  239. </SELECT>
  240. <BR>
  241. <INPUT TYPE="submit" VALUE="Show This Date on the Calendar!">
  242. </FORM>
  243. </TD></TR></TABLE>
  244.