<% Call fhMan_Main(cgiDir, componentid) Sub fhMan_Main(cgiDir, componentid) On Error Resume Next Dim propFile, writetodb, CustErr, pageSize pageSize = 10 propFile = cgiDir & "FormsHandler.xml" Dim XML set XML = fhOpenXMLFile(Server.MapPath(propFile)) Dim ManagerNode if XML is nothing then Call fhRaiseFatalError(601) Response.End end if set ManagerNode = fhGetNode(XML,,"Component", Array("name","id"), Array("manager", componentid), -1) if ManagerNode is Nothing then Call fhRaiseFatalError(400) Response.End end if Dim CSVFileName CSVFileName = fhGetProperty(ManagerNode, "dbpath") Dim formsHandlerNode set formsHandlerNode = fhGetByDBpath(XML, "formshandler", CSVFileName) if formsHandlerNode is Nothing then Call fhRaiseFatalError(400) Response.End end if writetodb = fhGetProperty(ManagerNode,"writetodb") Dim dbPath dbPath = fhGetProperty(ManagerNode, "dbpath") if dbPath = "" then fhRaiseFatalError("526") Response.End end if if dbPath <> "" then if not inStr(1, dbPath, "\", 1) > 0 then dbPath= Server.MapPath(cgiDir & dbPath) end if end if Dim dbFields Dim tableHead dbFields = fhGetDBFields(formsHandlerNode) if fhFileExist(dbPath) then 'check if the fields are the same tableHead = fhGetLine(dbPath) if LCase(dbFields) <> LCase(tableHead) then fhCreateDB dbPath, dbFields if err.number <> 0 then call fhRaiseFatalError(err.number) err.Clear() Response.End end if tableHead = fhGetLine(dbPath) end if else 'create the database if dbFields = "" then call fhRaiseFatalError(600) Response.End end if fhCreateDB dbPath, dbFields if err.number <> 0 then call fhRaiseFatalError(err.number) err.Clear() Response.End end if tableHead = fhGetLine(dbPath) end if Dim act, un, rd, page, chkAll, msg, fieldDisable, changed msg = "" fieldDisable = "" %> <% Dim Uploader Dim File Dim fileFields Dim fileToUpload Set Uploader = New FileUploader Uploader.Upload() if Len(Uploader.Form("page")) > 0 then page = Uploader.Form("page") else page = 1 end if Dim curAction curAction = Uploader.Form("act") if curAction = "AddForm" OR curAction = "AddRec" OR _ (curAction = "EditForm" AND Len(Uploader.Form("SelectedItem")) > 0 ) OR _ (curAction = "ViewForm" AND Len(Uploader.Form("SelectedItem")) > 0 ) OR _ curAction = "SaveRec" then Dim record Dim ui Dim newFieldValue Dim errFlag Dim fieldErr Dim btnName btnName = "AddRec" Dim recNr recNr = 0 Dim relPath, path relPath = fhGetProperty(ManagerNode, "uploaddir") path = "" if relPath = "." then relPath = cgiDir path = Server.MapPath(relPath) & "\" elseif relPath <> "" then relPath = cgiDir & relPath & "/" path = Server.MapPath(relPath) & "\" end if if curAction <> "AddForm" and curAction <> "AddRec" then recNr = Uploader.Form("SelectedItem") if inStr(recNr, ",") then recNr = CLng(split(recNr, ",")(0)) end if btnName = "SaveRec" end if Dim allTHeads allTHeads = split(tableHead,",") fileFields = "," for i=0 to UBound(allTHeads) fieldName = allTHeads(i) set errEvent = fhGetErrorEvent(formsHandlerNode, fieldName, "invalidextension") if not errEvent is nothing then fileFields = fileFields & allTHeads(i) & "," end if next %>
<% if recNr > 0 and curAction <> "AddRec" and curAction <> "SaveRec" then record = fhGetRecord(recNr, dbPath) if Len(record) > 0 then ui = split(record,""",""") end if end if dim errMark for i=0 to UBound(allTHeads) fieldErr = "" newFieldValue = "" if curAction = "AddRec" or curAction = "SaveRec" then '--- begin check form fields ---' fieldErr = fhCheckField(formsHandlerNode, allTHeads(i), fileFields, curAction, Uploader) '--- end check form fields ---' if not inStr(1, fileFields, "," & allTHeads(i) & ",", 1) > 0 then newFieldValue = fhEncodeValue(Uploader.Form(allTHeads(i))) else if curAction = "SaveRec" then newFieldValue = fhEncodeValue(Uploader.Form(allTHeads(i))) else if Uploader.Files.Exists(LCase(allTHeads(i))) then tmpNr = 1 fileToUpload = fhEncodeValue(Uploader.Files.Item(LCase(allTHeads(i))).FileName) if path <> "" then if fhFileExist(path & fileToUpload) then fileToUpload = Replace(fileToUpload, _ "." & Uploader.Files.Item(LCase(allTHeads(i))).FileExtension, _ CStr(tmpNr) & "." & _ Uploader.Files.Item(LCase(allTHeads(i))).FileExtension, 1, 1, 1) while fhFileExist(path & fileToUpload) fileToUpload = Replace(fileToUpload, _ CStr(tmpNr) & "." & Uploader.Files.Item(LCase(allTHeads(i))).FileExtension, _ CStr(tmpNr + 1) & "." & _ Uploader.Files.Item(LCase(allTHeads(i))).FileExtension, 1, 1, 1) tmpNr = tmpNr + 1 wend end if end if newFieldValue = fileToUpload else newFieldValue ="" end if end if end if elseif recNr > 0 then newFieldValue = ui(i) end if %> <% next %>
<% if curAction = "AddForm" then Response.Write "Add New Record" elseif curAction = "EditForm" then Response.Write "Edit Record" elseif curAction = "ViewForm" then fieldDisable = " disabled" Response.Write "View Record" end if %>
<%=allTHeads(i)%> <% if fieldErr <> "" then CustErr = CustErr & fieldErr errMark = fhGetProperty(formsHandlerNode, "errormark") if ( Left(errMark, 1) = "." or Left(errMark, 1) = "/" ) then errMark = Replace(errMark, Left(errMark, inStr(1, errMark, "/")), Left(cgiDir,inStr(1,cgiDir,"/")), 1) end if Response.write "" end if %> <% if curAction = "ViewForm" then if inStr(1, fileFields, "," & allTHeads(i) & ",", 1) > 0 _ and not inStr(1, newFieldValue, "\", 1) > 0 then Dim fileExists fileExists = "false" if path <> "" then fileExists = fhFileExist(path & newFieldValue) %> <%=newFieldValue%> <% else response.write newFieldValue end if else if (curAction = "AddForm" or _ curAction = "AddRec") and _ inStr(1, fileFields, "," & allTHeads(i) & ",", 1) > 0 _ and Trim(fieldDisable) = "" then %> <% else %> <% end if %> <% end if %>
>     >    
<% if Len(CustErr) = 0 and (curAction = "AddRec" or _ curAction = "SaveRec") then if path <> "" then recNr = fhSave(path, curAction, Uploader, ManagerNode, dbpath, recNr, fileFields) if Err.number = 0 then %> <% end if end if else %>
<%=CustErr%>
<% end if %>
<% else 'show users list' if ( curAction = "EditForm" OR curAction = "ViewForm" OR _ curAction = "delete" ) AND Len(Uploader.Form("SelectedItem")) = 0 then %>
You must select a user first!
<% elseif curAction = "delete" then dim items items = Split(Uploader.Form("SelectedItem"), ",") set rs = fhRSFileContent(dbPath, "all") for i=0 to UBound(items) if fhRecordExist(Trim(items(i))) then r = 0 with rs .MoveFirst do while not .EOF r = r + 1 if r = Clng(Trim(items(i))) then .Delete .Update exit do end if .MoveNext loop end with end if next if fhUpdateDB(dbPath, rs) then else call fhRaiseFatalError("502") Response.End end if rs.close end if %>
<% tableHead = fhGetLine(dbPath) allTHeads = split(tableHead,",") %> <% for i=0 to UBound(allTHeads) %> <% if i = 4 then exit for next %> <% set rs = fhRSFileContent(dbPath, "all") rs.PageSize = pageSize if CLng(page) > rs.PageCount then page = rs.PageCount end if if rs.PageCount > 0 then with rs .MoveFirst for i=1 to CLng(page) * .PageSize if .EOF then exit for if i <= CLng(page) * .PageSize - .PageSize then else if i = CLng(page) * .PageSize - .PageSize + 1 then %> <% end if %> <% for r=0 to UBound(allTHeads) %> <% if r = 4 then exit for next %> <% end if .MoveNext next %> <% end with %> <% else %> <% end if %>
Browse Users
  <%=Replace(allTHeads(i), Left(allTHeads(i),1), UCase(Left(allTHeads(i),1)), 1, 1, 1)%>
<%=Trim(.Fields(r))%>
There is no user in database!
>    0 or not writetodb then response.write " disabled "%> onClick="javascript: this.form.act.value = this.name;">    0 then response.write " disabled "%> onClick="javascript: this.form.act.value = this.name;">    0 or not writetodb then response.write " disabled "%> onClick="javascript: this.form.act.value = this.name;">
<% if CLng(page) > 1 then %> << FirstPage    < Previous <% else %> << FirstPage    < Previous <% end if%> <% if CLng(page) < rs.PageCount then %> Next >>   Last Page > <% else %> Next >    LastPage >> <% end if%>
<% end if %> <% end sub function fhCheckField(ByVal ComponentNode, ByVal fieldName, ByVal fileFields, ByVal actType, ByVal Uploader) On Error Resume Next fhCheckField = "" if not inStr(1, fileFields, "," & fieldName & ",", 1) > 0 then ' --- check form fileld except file fields --- ' fieldValue = fhEncodeValue(Uploader.Form(fieldName)) fhCheckField = fhCheckNormalField(ComponentNode, fieldName, fieldValue) else ' --- check form file fields --- ' fhCheckField = fhCheckFileField(ComponentNode, fieldName, actType, Uploader) end if end function function fhCheckNormalField(ByVal ComponentNode, ByVal fieldName, ByVal fieldValue) On Error Resume Next fhCheckNormalField = "" propValue = "" set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "required") if not errEvent is nothing then propValue = fhGetProperty(errEvent, "message") if not errFlag AND Len(propValue) > 0 AND propValue <> "" then if not Len(fieldValue) > 0 then fhCheckNormalField = "
  • " & propValue & "
  • " exit function end if end if end if set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "short") if not errEvent is nothing then propValue = fhGetProperty(errEvent, "minimumlength") if not errFlag AND Len(propValue) > 0 AND propValue <> "" then if Len(fieldValue) < CLng(propValue) then fhCheckNormalField = "
  • " & fhGetProperty(errEvent, "message") & "
  • " exit function end if end if end if set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "long") if not errEvent is nothing then propValue = fhGetProperty(errEvent, "maximumlength") if not errFlag AND CLng(propValue) > 0 AND propValue <> "" then if Len(fieldValue) > CLng(propValue) then fhCheckNormalField = "
  • " & fhGetProperty(errEvent, "message") & "
  • " exit function end if end if end if end function function fhCheckFileField(ByVal ComponentNode, ByVal fieldName, ByVal actType, ByVal Uploader) On Error Resume Next fhCheckFileField = "" dim errFlag, lpos if actType = "AddRec" then if not Uploader.Files.Exists(LCase(fieldName)) then set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "required") propValue = "" if not errEvent is nothing then propValue = fhGetProperty(errEvent, "message") end if if not errFlag AND Len(propValue) > 0 and propValue <> "" then fhCheckFileField = "
  • " & propValue & "
  • " exit function end if end if set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "invalidextension") propValue = "" if not errEvent is nothing then propValue = fhGetProperty(errEvent, "fileextension") if not errFlag AND Len(propValue) > 0 and propValue <> "" _ and Uploader.Files.Exists(LCase(fieldName)) then if not inStr(1, "|" & LCase(propValue) & "|", "|" & LCase(Uploader.Files.Item(LCase(fieldName)).FileExtension) & "|", 1) > 0 then fhCheckFileField = "
  • " & fhGetProperty(errEvent, "message") & "
  • " exit function end if end if end if set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "filetoolarge") if not errEvent is nothing then propValue = fhGetProperty(errEvent, "maximumsize") if not errFlag AND CLng(propValue) > 0 and propValue <> "" _ and Uploader.Files.Exists(LCase(fieldName)) then if Uploader.Files.Item(LCase(fieldName)).FileSize > CLng(propValue) * 1024 then fhCheckFileField = "
  • " & fhGetProperty(errEvent, "message") & "
  • " exit function end if end if end if else set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "required") propValue = "" if not errEvent is nothing then propValue = fhGetProperty(errEvent, "message") end if if not errFlag AND Len(propValue) > 0 and Uploader.Form(fieldName) = "" then fhCheckFileField = "
  • " & propValue & "
  • " exit function end if lpos = InstrRev(Uploader.Form(fieldName), ".") set errEvent = fhGetErrorEvent(ComponentNode, fieldName, "invalidextension") propValue = "" if not errEvent is nothing then propValue = fhGetProperty(errEvent, "fileextension") if not errFlag AND Len(propValue) > 0 and propValue <> "" _ and Len(Uploader.Form(fieldName)) > 0 then if not Instr(1, "|" & Lcase(propValue) & "|", "|" & _ Mid(Uploader.Form(fieldName), lpos+1, _ Len(Uploader.Form(fieldName))-lpos) & "|", 1) > 0 then fhCheckFileField = "
  • " & fhGetProperty(errEvent, "message") & "
  • " exit function end if end if end if end if end function function fhSave(ByVal path, ByVal actType, ByVal Uploader, ByVal ComponentNode, ByVal DbPath, ByVal RecNr, ByVal fileFields) On Error Resume Next dim rec, rs, filesList fhSave = RecNr if LCase(fhGetProperty(ComponentNode,"writetodb")) = "true" then info = "" set rs = fhRSFileContent(dbpath, "all") if CLng(recNr) > 0 then with rs .MoveFirst rec = 0 do while not .EOF i = 0 rec = rec + 1 if rec = CLng(recNr) then For Each fld In .Fields if not inStr(1, fileFields, "," & fld.Name & ",", 1) > 0 then fld.value = fhEncodeValue(Uploader.form(fld.Name)) info = info & fld.Name & " = " & fhEncodeValue(Uploader.Form(fld.Name)) & vbCRLF else if actType = "AddRec" then if Uploader.Files.Exists(LCase(fld.Name)) then tmpNr = 1 fileToUpload = fhEncodeValue(Uploader.Files.Item(LCase(fld.Name)).FileName) if fhFileExist(path & fileToUpload) then fileToUpload = Replace(fileToUpload, _ "." & Uploader.Files.Item(LCase(fld.Name)).FileExtension, _ CStr(tmpNr) & "." & _ Uploader.Files.Item(LCase(fld.Name)).FileExtension, 1, 1, 1) while fhFileExist(path & fileToUpload) fileToUpload = Replace(fileToUpload, _ CStr(tmpNr) & "." & Uploader.Files.Item(LCase(fld.Name)).FileExtension, _ CStr(tmpNr + 1) & "." & _ Uploader.Files.Item(LCase(fld.Name)).FileExtension, 1, 1, 1) tmpNr = tmpNr + 1 wend end if fld.value = fileToUpload Err.Clear() Call Uploader.Files.Item(LCase(fld.Name)).SaveToDisk(path, fileToUpload) if (Err.Number <> 0) then Call fhRaiseFatalError(Err.number) exit function end if else fileToUpload = fld.value end if else lpos = InstrRev(Uploader.Form(fld.Name), ".") tmpNr = 1 fileToUpload = fhEncodeValue(Uploader.Form(fld.Name)) if fhFileExist(path & fileToUpload) then fileToUpload = Replace(fileToUpload, _ Mid(Uploader.Form(fld.Name), lpos, _ Len(Uploader.Form(fld.Name))-lpos+1), _ CStr(tmpNr) & "." & _ Mid(Uploader.Form(fld.Name), lpos+1, _ Len(Uploader.Form(fld.Name))-lpos), 1, 1, 1) while fhFileExist(path & fileToUpload) fileToUpload = Replace(fileToUpload, _ CStr(tmpNr) & Mid(Uploader.Form(fld.Name), lpos, _ Len(Uploader.Form(fld.Name))-lpos+1), _ CStr(tmpNr + 1) & "." & _ Mid(Uploader.Form(fld.Name), lpos+1, _ Len(Uploader.Form(fld.Name))-lpos), 1, 1, 1) tmpNr = tmpNr + 1 wend end if fld.value = fileToUpload end if info = info & fld.Name & " = " & fileToUpload & vbCRLF end if i = i + 1 next .Update exit do end if .MoveNext loop end with else with rs .AddNew i = 0 For Each fld In .Fields if not inStr(1, fileFields, "," & fld.Name & ",", 1) > 0 then fld.value = fhEncodeValue(Uploader.Form(fld.Name)) info = info & fld.Name & " = " & fhEncodeValue(Uploader.Form(fld.Name)) & vbCRLF else if actType = "AddRec" then if Uploader.Files.Exists(LCase(fld.Name)) then tmpNr = 1 fileToUpload = fhEncodeValue(Uploader.Files.Item(LCase(fld.Name)).FileName) if fhFileExist(path & fileToUpload) then fileToUpload = Replace(fileToUpload, _ "." & Uploader.Files.Item(LCase(fld.Name)).FileExtension, _ CStr(tmpNr) & "." & _ Uploader.Files.Item(LCase(fld.Name)).FileExtension, 1, 1, 1) while fhFileExist(path & fileToUpload) fileToUpload = Replace(fileToUpload, _ CStr(tmpNr) & "." & Uploader.Files.Item(LCase(fld.Name)).FileExtension, _ CStr(tmpNr + 1) & "." & _ Uploader.Files.Item(LCase(fld.Name)).FileExtension, 1, 1, 1) tmpNr = tmpNr + 1 wend end if Err.clear() Call Uploader.Files.Item(LCase(fld.Name)).SaveToDisk(path, fileToUpload) if (err.number <> 0) then Call fhRaiseFatalError(Err.number) exit function end if else fileToUpload = fhEncodeValue(Uploader.Files.Item(LCase(fld.Name)).FileName) end if if Len(filesList) > 0 then filesList = filesList & "," & fileToUpload else filesList = fileToUpload end if else lpos = InstrRev(Uploader.Form(fld.Name), ".") tmpNr = 1 fileToUpload = fhEncodeValue(Uploader.Form(fld.Name)) if fhFileExist(path & fileToUpload) then fileToUpload = Replace(fileToUpload, _ Mid(Uploader.Form(fld.Name), lpos, _ Len(Uploader.Form(fld.Name))-lpos+1), _ CStr(tmpNr) & "." & _ Mid(Uploader.Form(fld.Name), lpos+1, _ Len(Uploader.Form(fld.Name))-lpos), 1, 1, 1) while fhFileExist(path & fileToUpload) fileToUpload = Replace(fileToUpload, _ CStr(tmpNr) & "." & Mid(Uploader.Form(fld.Name), lpos, _ Len(Uploader.Form(fld.Name))-lpos+1), _ CStr(tmpNr + 1) & "." & _ Mid(Uploader.Form(fld.Name), lpos+1, _ Len(Uploader.Form(fld.Name))-lpos), 1, 1, 1) tmpNr = tmpNr + 1 wend end if end if fld.value = fileToUpload info = info & fld.Name & " = " & fileToUpload & vbCRLF end if i = i + 1 next .Update end with fhsave = rs.AbsolutePosition end if isUpdated = fhUpdateDB(dbPath, rs) rs.Close() 'if failed to update db exit function if not isUpdated then exit function else fileToUpload = "" For Each File In Uploader.Files.Items tmpNr = 1 fileToUpload = fhEncodeValue(File.FileName) if fhFileExist(path & fileToUpload) then fileToUpload = Replace(fileToUpload, _ "." & File.FileExtension, _ CStr(tmpNr) & "." & _ File.FileExtension, 1, 1, 1) while fhFileExist(path & fileToUpload) fileToUpload = Replace(fileToUpload, _ CStr(tmpNr) & "." & File.FileExtension, _ CStr(tmpNr+1) & "." & _ File.FileExtension, 1, 1, 1) tmpNr = tmpNr + 1 wend end if if actType = "AddRec" then if Len(filesList) > 0 then filesList = filesList & "," & fileToUpload else filesList = fileToUpload end if Err.Clear() Call File.SaveToDisk(path, fileToUpload) if Err.Number <> 0 Then Call fhRaiseFatalError(Err.number) exit function end if end if next end if end function %>