HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/circ.itp/calendar.asp
<%@ Language="VBScript" %>
<% Option Explicit %>
<%
' 1. Declare variables
Dim conn, cmd, rs, cmdYears, rsYears
Dim selectedYear, currentYear, yr
Dim minYear, maxYear
Dim chkBankHoliday, isBankHolFilter
Dim sqlQuery

' 2. Helper function to format boolean 1/0 into friendly text
Function FormatBool(val)
    If CStr(val) = "1" Or CStr(val) = "True" Then
        FormatBool = "<strong>Yes</strong>"
    Else
        FormatBool = "<span style='color:#ccc;'>-</span>"
    End If
End Function

currentYear = Year(Date())

' 3. Handle Inputs (Year and Checkbox)
selectedYear = Request.Form("selYear")
chkBankHoliday = Request.Form("chkBankHoliday")

If Trim(selectedYear) = "" Then
    selectedYear = currentYear
Else
    If IsNumeric(selectedYear) Then
        selectedYear = CInt(selectedYear)
    Else
        selectedYear = currentYear
    End If
End If

isBankHolFilter = False
If chkBankHoliday = "1" Then isBankHolFilter = True

' 4. Initialize Database Connection
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=MySQL_castironradcen;"

' 5. Determine Min and Max Years from the Database
Set cmdYears = Server.CreateObject("ADODB.Command")
cmdYears.ActiveConnection = conn
cmdYears.CommandText = "SELECT MIN(YEAR(CalendarDate)) AS MinYr, MAX(YEAR(CalendarDate)) AS MaxYr FROM common.calendar"

Set rsYears = cmdYears.Execute()
If Not rsYears.EOF Then
    If Not IsNull(rsYears("MinYr")) Then minYear = CInt(rsYears("MinYr")) Else minYear = currentYear
    If Not IsNull(rsYears("MaxYr")) Then maxYear = CInt(rsYears("MaxYr")) Else maxYear = currentYear
Else
    minYear = currentYear
    maxYear = currentYear
End If

rsYears.Close
Set rsYears = Nothing
Set cmdYears = Nothing

' 6. Set up the main parameterized query
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn

sqlQuery = "SELECT CalendarDate, IsBankHoliday, IsWeekend, IsWorkingDay FROM common.calendar WHERE YEAR(CalendarDate) = ?"

If isBankHolFilter Then
    sqlQuery = sqlQuery & " AND IsBankHoliday = 1"
End If

sqlQuery = sqlQuery & " ORDER BY CalendarDate"

cmd.CommandText = sqlQuery
cmd.CommandType = 1 ' adCmdText

' Append the year parameter for SQL Injection protection
cmd.Parameters.Append cmd.CreateParameter("@YearParam", 3, 1, 4, selectedYear)

' Execute the main command
Set rs = cmd.Execute()
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Calendar Data</title>
    <link href="css/all.min.css" rel="stylesheet" />
    
    <style>
        body { 
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
            margin: 20px; 
            color: #333; 
        }
        
        h2 { color: #2c3e50; }
        
        .form-container { 
            margin-bottom: 20px; 
            padding: 15px; 
            background-color: #f8f9fa; 
            border: 1px solid #dee2e6; 
            border-radius: 6px; 
            display: inline-block; 
        }
        
        .form-group { margin-right: 15px; display: inline-block; }
        select { padding: 6px; font-size: 15px; border: 1px solid #ccc; border-radius: 4px; }
        label { cursor: pointer; }

        /* --- Table Improvements --- */
        table { 
            border-collapse: collapse; 
            width: 100%; 
            max-width: 900px; 
            margin-top: 15px; 
            table-layout: fixed; /* Forces columns to be equally sized */
            box-shadow: 0 1px 3px rgba(0,0,0,0.1); 
        }
        
        th, td { 
            border: 1px solid #dee2e6; 
            padding: 12px 15px; 
            text-align: left; 
        }
        
        /* Center the contents of the 3rd, 4th, and 5th columns */
        th:nth-child(n+3), td:nth-child(n+3) {
            text-align: center;
        }
        
        th { 
            background-color: #e9ecef; 
            font-weight: 600;
            color: #495057;
        }
        
        /* Zebra striping */
        tbody tr:nth-child(even) {
            background-color: #fcfcfc;
        }
        
        /* Row hover effect */
        tbody tr:hover {
            background-color: #f1f3f5; 
        }
    </style>
</head>
<body>

    <h2>Calendar Overview for <%= Server.HTMLEncode(selectedYear) %></h2>

    <div class="form-container">
        <form method="post" action="<%= Server.HTMLEncode(Request.ServerVariables("SCRIPT_NAME")) %>">
            
            <div class="form-group">
                <label for="selYear"><strong>Select Year:</strong></label>
                <select name="selYear" id="selYear" onchange="this.form.submit()">
                    <%
                    ' Generate combo box from the database's minimum to maximum year
                    For yr = minYear To maxYear
                        Response.Write "<option value=""" & yr & """"
                        If CInt(yr) = CInt(selectedYear) Then
                            Response.Write " selected=""selected"""
                        End If
                        Response.Write ">" & yr & "</option>"
                    Next
                    %>
                </select>
            </div>

            <div class="form-group">
                <label>
                    <input type="checkbox" name="chkBankHoliday" value="1" <% If isBankHolFilter Then Response.Write "checked=""checked""" %> onchange="this.form.submit()">
                    <strong>Bank Holidays Only</strong>
                </label>
            </div>

            <noscript>
                <input type="submit" value="Update View">
            </noscript>
        </form>
    </div>

    <table>
        <thead>
            <tr>
                <th>Day</th>
                <th>Calendar Date</th>
                <th>Bank Holiday</th>
                <th>Weekend</th>
                <th>Working Day</th>
            </tr>
        </thead>
        <tbody>
            <%
            ' 7. Loop through records
            If Not rs.EOF Then
                Dim currentDate, dayNameAbbr
                
                Do While Not rs.EOF
                    currentDate = rs("CalendarDate")
                    
                    ' Change 'True' to 'False' to get the full day name (e.g., Thursday)
                    dayNameAbbr = WeekdayName(Weekday(currentDate, 1), False)

                    Response.Write "<tr>"
                    Response.Write "<td>" & Server.HTMLEncode(dayNameAbbr) & "</td>"
                    Response.Write "<td>" & Server.HTMLEncode(currentDate) & "</td>"
                    
                    ' Using the helper function to format the booleans nicely
                    Response.Write "<td>" & FormatBool(rs("IsBankHoliday")) & "</td>"
                    Response.Write "<td>" & FormatBool(rs("IsWeekend")) & "</td>"
                    Response.Write "<td>" & FormatBool(rs("IsWorkingDay")) & "</td>"
                    Response.Write "</tr>"
                    
                    rs.MoveNext
                Loop
            Else
                Response.Write "<tr><td colspan='5'>No calendar data found for this selection.</td></tr>"
            End If
            %>
        </tbody>
    </table>

<%
' 8. Memory Cleanup
If rs.State = 1 Then rs.Close
Set rs = Nothing
Set cmd = Nothing
If conn.State = 1 Then conn.Close
Set conn = Nothing
%>
</body>
</html>