%@ Language=VBScript %>
<%
dim ID
dim action
dim oConn
dim sql
dim submitLabel
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.ConnectionTimeout = 900
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".") & "\DynamicSession.mdb"
ID = request("ID") & ""
IF not Isnumeric(ID) then
ID = 0
end if
action = request("action") & ""
if cint(ID) > 0 then
submitLabel = "Modify Holiday"
else
submitLabel = "Add Holiday"
end if
if lcase(action) = "add" then
if isdate(request("date_of_holiday") & "") and request("Holiday") > "" then
sql = "SELECT Holiday, Date_of_Holiday FROM Holidays"
if cint(ID) > 0 then
updateRecord oConn, sql, "Holidays"
else
addRecord oConn, sql, "Holidays"
end if
else
msg = "Please fill in all fields."
end if
end if
%>
Compaq LA - Compaq Services - Holiday page
<%=msg%>
<%
sub getData(oConn,sql)
dim RS
dim i
dim ok
dim val
dim dateStr
Set RS = oConn.execute(sql)
ok = false
if not RS.eof then
ok = true
end if
%>
<%
if ok then
val = RS(i)
else
val = ""
end if
if lcase(RS.fields(i).name) = "id" then
%>
<%elseif lcase(RS.fields(i).name) = "date_of_holiday" then
if isdate(val) then
dateStr = formatdatetime(val)
else
dateStr = ""
end if
%>
<%else%>
<%end if%>
<%
next
%>
<%
end sub
function addRecord(oConn, sql, tbl)
dim RS
dim addSQL
dim i
dim valStr
dim fldStr
dim typeSep
dim Val
dim tmpID
tmpID = 0
set RS = oConn.execute(sql)
' for each item in Request.Form
' Response.Write item & "=!" & Request.Form(item) & "! "
' next
If Request.Form("LAPW") = "LAHolidayGL" Then
for i = 0 to RS.Fields.count - 1
Val = replace(Request.Form(RS.fields(i).name) & "","'","''",1,-1,1)
if trim(Val) > "" then
fldStr = fldStr & RS.fields(i).name & ","
typeSep = getTypeSeperator(RS.fields(i).type)
valStr = valStr & typeSep & Val & typeSep & ","
end if
next
RS.close
if len(fldStr & "") > 1 and len(valStr & "") > 1 then
addSQL = "insert into " & tbl & "(" & left(fldStr, len(fldstr) - 1) & ")" & " values (" & left(valStr, len(valStr) - 1) & ")"
oConn.execute(addSQL)
set RS = oConn.execute("Select Max(ID) as MaxID from " & tbl)
if not RS.eof and not RS.bof then
tmpID = RS("MaxID")
RS.close
end if
end if
addRecord = tmpID
else
Response.Write "You do not have access to update the holiday database!!! "
end if
end function
sub updateRecord(oConn, sql, tbl)
dim RS
dim modSQL
dim i
dim typeSep
dim Val
dim tmpID
dim okToUpdate
okToUpdate = false
tmpID = 0
set RS = oConn.execute(sql)
' for each item in Request.Form
' Response.Write item & "=!" & Request.Form(item) & "! "
' next
modSQL = "Update " & tbl & " SET "
for i = 0 to RS.Fields.count - 1
Val = replace(Request.Form(RS.fields(i).name) & "","'","''",1,-1,1)
if trim(Val) > "" then
if lcase(RS.Fields(i).name) = "photo" then
val = copyPhoto(val, photoPath)
end if
typeSep = getTypeSeperator(RS.fields(i).type)
modSQL = modSQL & RS.fields(i).name & " = " & typeSep & val & typeSep & ","
okToUpdate = true
end if
next
RS.close
if okToUpdate then
modSQL = left(modSQL,len(modSQL) - 1) & " WHERE ID = " & ID
oConn.execute(modSQL)
end if
end sub
function getTypeSeperator(fType)
Const adEmpty = 0
Const adTinyInt = 16
Const adSmallInt = 2
Const adInteger = 3
Const adBigInt = 20
Const adUnsignedTinyInt = 17
Const adUnsignedSmallInt = 18
Const adUnsignedInt = 19
Const adUnsignedBigInt = 21
Const adSingle = 4
Const adDouble = 5
Const adCurrency = 6
Const adDecimal = 14
Const adNumeric = 131
Const adBoolean = 11
Const adError = 10
Const adUserDefined = 132
Const adVariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const adGUID = 72
Const adDate = 7
Const adDBDate = 133
Const adDBTime = 134
Const adDBTimeStamp = 135
Const adBSTR = 8
Const adChar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const adWChar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adBinary = 128
Const adVarBinary = 204
Const adLongVarBinary = 205
select case cint(fType)
case adTinyInt,adSmallInt,adInteger,adBigInt,adUnsignedTinyInt,adUnsignedSmallInt,adUnsignedInt,adUnsignedBigInt,adSingle,adDouble,adCurrency,adDecimal,adNumeric,adBoolean
getTypeSeperator = " "
case adDate,adDBDate,adDBTime,adDBTimeStamp
getTypeSeperator = "#"
case else
getTypeSeperator = "'"
end select
end function
'Sub FillDropDown
'
'Fills a dropdown box
'
Sub FillDropDown( sqlstr,oConn, ValField, labField, valSelect)
Dim Resp
Dim rec
Dim Q
Dim selOption
Dim selFound
selFound = false
maxStep = 0
selOption = ""
Set rec = Server.CreateObject("ADODB.Recordset")
set rec = oConn.Execute(sqlStr)
Q = Chr(34)
If Not rec.EOF And Not rec.BOF Then
While Not rec.EOF
If CStr(valSelect) <> "" Then
If cstr(valSelect) = cstr(rec.Fields(ValField)) Then
selOption = "selected"
selFound = true
Else
selOption = ""
End If
End If
Response.Write "" & vbCrLf
rec.MoveNext
Wend
End If
rec.Close
if selFound then
Response.Write "" & vbCrLf
else
Response.Write "" & vbCrLf
end if
End Sub
%>