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/expressmusic/inc-template-upload.asp
<!-- #include file="uploadhelper.asp" -->
<%
' (SS,23/10/23) new competition page (based on contact page template)
' using uploadhelper "uploadhelper.asp" included above
' (SS,02/11/23) sell your guitar for Express Music, inc-template-upload.asp

Const PU_UPLOADS_FOLDER = "/uploads"
Const PU_DEBUG_MODE = False
Const PU_TYPE = "Sell Your Guitar"

Dim oUpload

Sub ShowUploadHeader
  ' no need to page heading/title just wasting space because we have panels in the two sections which are headings
  ShowPageTitle "Sell Your Guitar", "Sell Your Guitar", ""
%>
<div id="other-pages2">
<%
End Sub

' Sub ShowUploadForm(AErrorMessage, AName, AEmail, AMarketingOptIn)

Sub ShowUploadForm(AErrorMessage)
%>

<div class="row">

<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">  

<%=GetTokenText("Sell Your Guitar Header")%>

</div> <!--cols-->

</div> <!--row-->

<div class="row">

<div class="col-lg-6 col-md-6 col-sm-8 col-xs-12">  
<a id="entry"></a>
  <div class="panel panel-default">
  
    <div class="panel-heading">Sell Your Guitar</div>
    <div class="panel-body">

<form action="products.asp?page=<%=GetPageName%>&cmd=upload" method="post" name="Sell Your Guitar" role="form" enctype="multipart/form-data">
    
    
<%If AErrorMessage <> "" Then
  ShowAlertMesssage "danger", AErrorMessage
End If%>
  
  <div class="form-group">
    <label for="Name">Name</label>
    <input type="text" class="form-control" name="Name" id="Name" placeholder="Enter name" value="<%=oUpload.GetFieldValue("Name")%>" maxlength="100" required>
  </div>
  
  <div class="form-group">
    <label for="Email">Email</label>
    <input type="email" class="form-control" name="Email" id="Email" placeholder="Enter email address" value="<%=oUpload.GetFieldValue("Email")%>" maxlength="100" required>
  </div>
  
  <div class="form-group">
    <label for="Phone">Phone Number</label>
    <input type="text" class="form-control" name="Phone" id="Phone" placeholder="Enter phone address" value="<%=oUpload.GetFieldValue("Phone")%>" maxlength="100"<%=oUpload.FieldRequired("Phone")%>>
  </div>

  <div class="form-group">
    <label for="Postcode">Postcode</label>
    <input type="text" class="form-control" name="Postcode" id="Postcode" placeholder="Enter postcode" value="<%=oUpload.GetFieldValue("Postcode")%>" maxlength="20"<%=oUpload.FieldRequired("Postcode")%>>
  </div>
  
  <div class="form-group">
    <label for="Make">Make</label>
    <input type="text" class="form-control" name="Make" id="Make" placeholder="Enter make" value="<%=oUpload.GetFieldValue("Make")%>" maxlength="100"<%=oUpload.FieldRequired("Make")%>>
  </div>
  
  <div class="form-group">
    <label for="Make">Model</label>
    <input type="text" class="form-control" name="Model" id="Model" placeholder="Enter model" value="<%=oUpload.GetFieldValue("Model")%>" maxlength="100"<%=oUpload.FieldRequired("Model")%>>
  </div>
  
  <div class="form-group">
    <label for="SerialNumber">Serial Number</label>
    <input type="text" class="form-control" name="SerialNumber" id="SerialNumber" placeholder="Enter serial number" value="<%=oUpload.GetFieldValue("SerialNumber")%>" maxlength="100"<%=oUpload.FieldRequired("SerialNumber")%>>
  </div>
  
  <div class="form-group">
    <label for="YearOfManufacture">Year of Manufacture</label>
    <input type="text" class="form-control" name="YearOfManufacture" id="YearOfManufacture" placeholder="Enter year of manufacture" value="<%=oUpload.GetFieldValue("YearOfManufacture")%>" maxlength="4"<%=oUpload.FieldRequired("YearOfManufacture")%>>
  </div>  
   
  <div class="form-group">
    <label for="Condition">Condition</label>
    <input type="text" class="form-control" name="Condition" id="Condition" placeholder="Enter condition" value="<%=oUpload.GetFieldValue("Condition")%>" maxlength="100"<%=oUpload.FieldRequired("Condition")%>>
  </div>
  
  <div class="form-group">
    <div class="radio">
      <label>
        <input type="radio" name="SaleType" id="SaleTypeOutrightSale" value="Outright Sale"<%=oUpload.FieldRequired("Condition")%>>
        Outright sale
      </label>
    </div>
    <div class="radio">
      <label>
        <input type="radio" name="SaleType" id="SaleTypePartExchange" value="Part Exchange">
        Part exchange
      </label>
    </div>
  </div>

  <div class="form-group" id="GrpInterestedIn">
    <label for="InterestedIn">Which product are you interested in?</label>
    <input type="text" class="form-control" name="InterestedIn" id="InterestedIn" placeholder="Enter product" value="<%=oUpload.GetFieldValue("InterestedIn")%>" maxlength="100">
  </div>
  
  <div class="form-group">
    <label for="AdditionalComments">Additional Comments</label>
    
    <textarea class="form-control" name="AdditionalComments" id="AdditionalComments" placeholder="Enter comments" value="<%=oUpload.GetFieldValue("AdditionalComments")%>" maxlength="1000" rows="3"></textarea>
  </div>
    
<%If False Then%>
  <div class="form-group">
    <div class="checkbox">
      <label>
        <input type="checkbox" name="MarketingOptIn" id="MarketingOptIn" value="checked"<%=IIf(oUpload.GetFieldValue("MarketingOptIn") = "checked", " checked", "")%>>Opt in for marketing (optional)
      </label>
    </div>
  </div>
<%End If%>    
    
  <div class="form-group">
    <label for="files">Upload photos</label>
    <input type="file" class="form-control" name="files" id="files" multiple accept="image/*" maxlength="100" required="true">
    <p class="help-block">Choose photos and press submit (maximum 50 MB)<br>Accepted file types: jpg, png, gif</p>
  </div>

  <div class="form-group">
    <button type="submit" class="btn btn-success">Submit</button>
  </div>

</form>

  </div>

  </div> <!--panel-->

</div> <!--cols-->

</div> <!--row-->

<div class="row">

<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">  

<%=GetTokenText("Sell Your Guitar Footer")%>

</div> <!--cols-->

</div> <!--row-->

<%
  AddScript "ScriptUploadFiles"
End Sub

' (SS,26/10/23) for jquery script at the end, after jquery library downloaded
Sub ScriptUploadFiles
%>
<script>
$('#files').change(function() {
  var totalfilesize = 0;
  $.each(this.files, function(i, file) {
    totalfilesize += file.size;
  });
  if (totalfilesize > 52428800) {
    var totalfilesizeMB = (totalfilesize / 1024 / 1024).toFixed(2);
    alert("File(s) are too big\nYou have selected " + totalfilesizeMB.toString() + " MB \nMaximum allowed is 50 MB\nPlease reselect");
    this.value = "";
  }
});
// (SS,7/11/23) following hides/shows depending on choice of SaleType
$(function() {
  // hide by default
  $('#GrpInterestedIn').hide();
});
$('#SaleTypeOutrightSale').click(function() {
  $('#GrpInterestedIn').hide();
  $('#InterestedIn').val("");
  $('#InterestedIn').attr("required", false);
});
$('#SaleTypePartExchange').click(function() {
  $('#GrpInterestedIn').show();
  $('#InterestedIn').attr("required", true);
});

</script>
<%
End Sub

' (SS,2/11/23) not yet used
Sub ShowUploadMaxFileSizeScript
  ' from https://uploadcare.com/blog/how-to-upload-files-using-js/
%>

  
  <p>
    <strong>Uploading status:</strong>
    <span id="statusMessage">Nothing's uploaded</span>
  </p>

<script>

const statusMessage = document.getElementById('statusMessage');
const submitButton = document.querySelector('button');
const fileInput = document.querySelector('input');

function updateStatusMessage(text) {
  statusMessage.textContent = text;
}

function assertFilesValid(fileList) {
  const allowedTypes = ['image/webp', 'image/jpeg', 'image/png'];
  // const sizeLimit = 50 * 1024 * 1024; // 50 megabytes
  const sizeLimit = 1 * 1024 * 1024; // 1 megabyte

  for (const file of fileList) {
    const { name: fileName, size: fileSize } = file;

    if (!allowedTypes.includes(file.type)) {
      throw new Error('❌ File "${fileName}" could not be uploaded. Only images with the following types are allowed: WEBP, JPEG, PNG.');
    }

    // ↓ the new condition ↓
    if (fileSize > sizeLimit) {
      throw new Error('❌ File "${fileName}" could not be uploaded. Only images up to 1 MB are allowed.');
    }
  }
}

function handleInputChange() {
  try {
    assertFilesValid(fileInput.files);
  } catch (err) {
    updateStatusMessage(err.message);
    return;
  }

  submitButton.disabled = false;
}

fileInput.addEventListener('change', handleInputChange);

function resetFormState() {
  submitButton.disabled = true;
  updateStatusMessage("Nothing's uploaded")
}

function handleInputChange(event) {
  resetFormState();

  // the rest of the code goes here
}

</script>
<%
End Sub

Sub ShowUploadThankYou
  ' (SS,25/10/23) removed following for now
  ' oGTM.EventContactForm "Competition"
  Dim LTokenText, LSuccessMessage
  LTokenText = GetTokenText("Sell Your Guitar Thank You")
  ' add upload success status
  LSuccessMessage = GetUploadSuccessMessage
  If LSuccessMessage = "" Then
    LSuccessMessage = "No photos uploaded"
  End If
  LTokenText = ReplaceStr(LTokenText, "[Upload Status]", LSuccessMessage)
%>
  <div class="panel panel-default">  
    <div class="panel-heading">Sell Your Guitar Request Submitted</b></div>
    <div class="panel-body">
    <%=LTokenText%>
    </div>
  </div>
<%
End Sub

Sub ShowUploadFooter
%>
</div> <!-- end #other-pages2 -->
<%
End Sub

Sub DoUploadForm

  Set oUpload = New UploadDef
  oUpload.AdditionalFields = "Make, Model, SerialNumber, YearOfManufacture, Condition, SaleType, InterestedIn, AdditionalComments"
  oUpload.RequiredFields = "Make, Model, Condition, SaleType, InterestedIn"

  ShowUploadHeader

  Dim LErrorMessage, LShowForm
  LErrorMessage = ""
  LShowForm = True

  Dim LCmd, LName, LEmail, LMarketingOptIn
  ' need to ensure that we don't access the Form collection otherwise we'll get the following error:
  ' Cannot call BinaryRead after using Request.Form collection.
  
  LCmd = CleanRequestQueryString("cmd")
  
  If LCmd = "upload" Then      
    If ProcessUploads(LErrorMessage) Then
      ' in debug mode don't redirect
      If PU_DEBUG_MODE Then
        ShowUploadThankYou  
      Else
        SetPageRedirection "products.asp?page=" & GetPageName & "&cmd=thankyou"
      End If
      LShowForm = False
    Else
      LErrorMessage = "Upload failed: " & LErrorMessage
    End If
  ElseIf LCmd = "thankyou" Then
    ShowUploadThankYou
    LShowForm = False
  End If
  If LShowForm Then
    ShowUploadForm LErrorMessage ' , LName, LEmail, LMarketingOptIn          
  End If
  
  ShowUploadFooter
  
  If PU_DEBUG_MODE Then 
    oUpload.ShowFieldList  
    Response.Write "###" & oUpload.GetJSONData & "###" & BR
  End If
  
  Set oUpload = Nothing
End Sub

' (SS,24/10/23) need to make sure max size is increased in IIS to about 30MB
' files are saved to public folder
' Upload works from "Files" or similar field I think?
' Function ProcessUploads(ByRef AErrorMessage, ByRef AName, ByRef AEmail, ByRef AMarketingOptIn)
Function ProcessUploads(ByRef AErrorMessage)
  Dim objUpload, LResult
  LResult = False
  Set objUpload = New UploadHelper
  If objUpload.GetError <> "" Then
    AErrorMessage = "Warning: " & objUpload.GetError
    ' Response.Write("Warning: "  & objUpload.GetError)
  Else  
    If PU_DEBUG_MODE Then 
      Response.Write("found "&objUpload.FileCount&" files...<br />")
    End If
    
    ' get the Name, Email and MarketingOptIn values
    Dim i, LFormFieldName, LImageCount
    LImageCount = 0
    For i = 0 To objUpload.FileCount - 1
      LFormFieldName = objUpload.File(i).FormFieldName
      
      If LFormFieldName = "files" Then
        If ContentTypeIsImage(objUpload.File(i).ContentType) Then LImageCount = LImageCount + 1: End If
      ' save the form field if valid name
      ElseIf oUpload.FieldNameIsValid(LFormFieldName) Then
        oUpload.SetFieldValue LFormFieldName, EscapeHTMLAngleBrackets(objUpload.File(i).ContentAsStr) 
      End If
      
      'If LFormFieldName = "Name" Then
      '  AName = EscapeHTMLAngleBrackets(objUpload.File(i).ContentAsStr)
      'ElseIf LFormFieldName = "Email" Then
      '  AEmail = EscapeHTMLAngleBrackets(objUpload.File(i).ContentAsStr)
      'ElseIf LFormFieldName = "MarketingOptIn" Then
      '  AMarketingOptIn = EscapeHTMLAngleBrackets(objUpload.File(i).ContentAsStr)
      'End If
    Next
    
    
    ' get the fixed fields   
    Dim LName, LEmail, LPhone, LPostcode, LCountry, LMarketingOptIn
    LName = oUpload.GetFieldValue("Name")
    LEmail = oUpload.GetFieldValue("Email")
    LPhone = oUpload.GetFieldValue("Phone")
    LPostcode = oUpload.GetFieldValue("Postcode")
    LCountry = oUpload.GetFieldValue("Country")
    LMarketingOptIn = oUpload.GetFieldValue("MarketingOptIn")
    
    ' check that Name and Email are entered
    If LName = "" Then
      AErrorMessage = "Please enter either your name"
    ElseIf LEmail = "" Then
      AErrorMessage = "Please enter either your email address"
    ElseIf LImageCount = 0 Then
      AErrorMessage = "No images sent"
    Else
      AErrorMessage = ""
    End If
    
    If AErrorMessage = "" Then
      ' reaches here when there is ar least one image
      Dim LFileCount, LTotalFileSize    
      LFileCount = 0
      LTotalFileSize = 0
    
      Dim LUploadID, LUploadedFileID, LOriginalFileName, LSavedFileName, LFileExtension, LFileType, LFileSize, LImageWidth, LImageHeight
      
      Dim LJSONData
      LJSONData = oUpload.GetJSONData
      
      ' create header record
      LUploadID = GetNewUploadID(PU_TYPE, LName, LEmail, LPhone, LPostcode, LCountry, LMarketingOptIn, LJSONData)
    
      Dim x
      For x = 0 To objUpload.FileCount - 1
        If PU_DEBUG_MODE Then
          Response.Write "form field name: " & objUpload.File(x).FormFieldName & BR
          Response.Write "content disposition: "&objUpload.File(x).ContentDisposition & BR
          Response.Write "file name: " & objUpload.File(x).FileName & BR
          Response.Write "file type: " & objUpload.File(x).ContentType & BR
          Response.Write "file size: " & objUpload.File(x).Size & BR
          Response.Write "image width: " & objUpload.File(x).ImageWidth & BR
          Response.Write "image height: " & objUpload.File(x).ImageHeight & BR
        End If
        'If (objUpload.File(x).ImageWidth > 10000) Or (objUpload.File(x).ImageHeight > 10000) Then
        '  Response.Write("the image is too big, file not saved!")
        'Else
        
        If objUpload.File(x).FormFieldName = "files" And ContentTypeIsImage(objUpload.File(x).ContentType) Then
          LFileCount = LFileCount + 1
          LOriginalFileName = objUpload.File(x).FileName
          LFileExtension = objUpload.File(x).Extension
          LFileType = objUpload.File(x).ContentType
          LFileSize = objUpload.File(x).Size
          LTotalFileSize = LTotalFileSize + LFileSize
          LImageWidth = objUpload.File(x).ImageWidth
          LImageHeight = objUpload.File(x).ImageHeight
          ' Response.Write "file ext: " & LFileExtension & BR
          
          ' create detail record
           ' ASavedFileName is composed of AUploadID + "123_1.jpg" "123-1.jpg"
          ' Make sure extension is digits or numbers only
          LUploadedFileID = GetNewUploadedFileID(LUploadID, LOriginalFileName, "", LFileType, LFileSize, LImageWidth, LImageHeight)
          
          ' set the saved file name and update the record with it, file extension is check to ensure its alphanumeric and not longer than 30 chars max
          LFileExtension = Left(GetAlphaNumericStr(LFileExtension), 30)
          LSavedFileName = LUploadID & "-" & LUploadedFileID & "." & LFileExtension
          UpdateUploadedFileSavedFileName LUploadedFileID, LSavedFileName
          
          ' save the file        
          Call objUpload.File(x).SaveToDisk(Server.MapPath(PU_UPLOADS_FOLDER), LSavedFileName)
          ' objUpload.File(x).SaveToDisk "E:\uploads\circ", LSavedFileName
          
          
          LResult = True
          If PU_DEBUG_MODE Then Response.Write("file saved successfully!"): End If
        Else
          If PU_DEBUG_MODE Then Response.Write("not saved"): End If
        End If
        If PU_DEBUG_MODE Then Response.Write "<hr>": End If
      Next
      
      ' SetUploadSuccessMessage "Successfully uploaded " & PluralString(LFileCount, "photo", "photos") & " totalling " & Round2dp(LTotalFileSize / 1024 / 1024) & " MB"      
      ' oUpload.AddFieldValue "UploadResult", GetUploadSuccessMessage
      
      oUpload.AddFieldValue "UploadResult", "Successfully uploaded " & PluralString(LFileCount, "photo", "photos") & " totalling " & Round2dp(LTotalFileSize / 1024 / 1024) & " MB"      
      SetUploadSuccessMessage oUpload.FieldListAsHTML
      
      UploadResultEmail LUploadID
    End If
  End If
  ProcessUploads = LResult

End Function

Function ContentTypeIsImage(AContentType)
  ContentTypeIsImage = LCase(Mid(AContentType, 1, 6)) = "image/"  
End Function

Function GetNewUploadID(AType, AName, AEmail, APhone, APostcode, ACountry, AMarketingOptIn, AJSONData)
  Dim LSQL, LLastInsertID
  LSQL = "INSERT INTO uploads SET Type = '" & AType & "'" &_   
    ", Name = '" & CleanSQLStrMax(AName, 100) & "'" &_
    ", Email = '" & CleanSQLStrMax(AEmail, 100) & "'"
  If APhone <> "" Then LSQL = LSQL & ", Phone = '" & CleanSQLStrMax(APhone, 100) & "'"
  If APostcode <> "" Then LSQL = LSQL & ", Postcode = '" & CleanSQLStrMax(APostcode, 20) & "'"
  If ACountry <> "" Then LSQL = LSQL & ", Country = '" & CleanSQLStrMax(ACountry, 100) & "'"
  If AJSONData <> "" Then LSQL = LSQL & ", AdditionalFields = '" & CleanSQLStrMax(AJSONData, 8192) & "'" ' limit to 8K max
  LSQL = LSQL &_
    ", MarketingOptIn = '" & iif(AMarketingOptIn = "", 0, 1) & "'" &_
    ", DateTimeCreated = NOW()"
  ExecuteQuery LSQL
  GetNewUploadID = GetSQLLastInsertID  
End Function

Function GetNewUploadedFileID(AUploadID, AOriginalFileName, ASavedFileName, AFileType, AFileSize, AImageWidth, AImageHeight) 
  Dim LSQL, LLastInsertID
  LSQL = "INSERT INTO uploaded_files SET UploadID = " & AUploadID & _   
    ", OriginalFileName = '" & CleanSQLStrMax(AOriginalFileName, 255) & "'" &_
    ", SavedFileName = '" & CleanSQLStrMax(ASavedFileName, 50) & "'" &_
    ", FileType = '" & CleanSQLStrMax(AFileType, 50) & "'" &_
    ", FileSize = " & AFileSize &_
    ", ImageWidth = " & AImageWidth &_
    ", ImageHeight = " & AImageHeight &_
    ", DateTimeUploaded = NOW()"     
  ExecuteQuery LSQL
  GetNewUploadedFileID = GetSQLLastInsertID  
End Function

Sub UpdateUploadedFileSavedFileName(AUploadedFileID, ASavedFileName)
  Dim LSQL
  ExecuteQuery "UPDATE uploaded_files SET SavedFileName = '" & CleanSQLStrMax(ASavedFileName, 50) & "' WHERE UploadedFileID = " & AUploadedFileID
End Sub

Sub UploadResultEmail(ARequestID)
  'SendEmailByCDO AEmail, FEmailContactBcc1, FEmailContactBcc2, FEmailContactFrom, LSubject, LBody, "", True, "", LAttachLogoFileName '(SS,31/1/13) changed LOGO_FILE_NAME to LAttachLogoFileName 
  'FEmailContactFrom = ""
  Dim LTableStyle, LBody
  
  LTableStyle = _
  "td, th {" &_
  "font-family: Verdana, Arial, Helvetica, sans-serif;" &_
  "font-size: 12px;" &_
  "border: 1px solid #ccc;" &_
  "padding: 5px;" &_
  "vertical-align: top;" &_
  "}" & NL &_
  "th {" &_
  "text-align: right" &_
  "}"
  
  LBody = "<html>" & NL & "<head>" & NL &_
     "<style>" & NL & LTableStyle & NL & "</style>" & NL &_
     "</head>" & NL & "<body>" & NL
  
  LBody = LBody & oUpload.FieldListAsHTML
  LBody = LBody & NL & "</body>" & NL & "</html>" & NL
  'SendEmail "surinder@itpartnership.com", "", FEmailContactBcc2, FEmailContactFrom, "Sell You Guitar Request - " & ARequestID, LBody, "", True, "", "" 
  'SendEmail AEmailAddress, ABCCEmailAddress, ABCCEmailAddress2, AFromEmailAddress, ASubject, ABody, AIsHTML 
  'SendEmail "surinder@itpartnership.com", "", FEmailContactBcc2, FEmailContactFrom, "Sell You Guitar Request - " & ARequestID, LBody, True'
  
  ' Response.Write "###" & LBody & "###" & FEmailContactFrom & "###"
  
  'SendEmail "surinder@ssbsoft.co.uk", "", "", FEmailContactFrom, "Sell You Guitar Request - " & ARequestID, LBody, True
  ' (SS,10/9/24) corrected Sell You Guitar Request to Sell Your Guitar Request
  SendEmail FEmailContactTo, FEmailContactBcc1, FEmailContactBcc2, FEmailContactFrom, "Sell Your Guitar Request - " & ARequestID, LBody, True
  'SendEmail "surinder@itpartnership.com", "", "", FEmailContactFrom, "Sell You Guitar Request - " & ARequestID, LBody, True
  
End Sub



' remove non alpha numeric characters from given string
' !!! to be placed in dbfunctions.asp
Function GetAlphaNumericStr(AString)
  Dim LLen, LString, LChar, LResult, i
  LLen = Len(AString)
  LString = NB(AString)
  LResult = ""
  If LString <> "" Then
    For i = 1 To LLen
      LChar = Mid(LString, i, 1)
      If IsCharAlpha(LChar) Or IsCharNumeric(LChar) Then
        LResult = LResult + LChar
      End If
    Next
  End If
  GetAlphaNumericStr = LString
End Function

' (SS,8/11/23) adds a space before a leading case e.g. "YearOfManufacture" becomes "Year Of Manufacture"
' !!! to be placed in dbfunctions.asp
Function SeparateUppercase(AStrInput)
	Dim Result, i, LPrevChar, LCurrentChar
  LPrevChar = ""
  Result = ""
  For i = 1 To Len(AStrInput)
    LCurrentChar = Mid(AStrInput, i, 1)
    ' add a space if not first char and it's a capital
    If LPrevChar <> "" And LCurrentChar >= "A" And LCurrentChar <= "Z" Then
      Result = Result + " "
    End If
    Result = Result + LCurrentChar    
    LPrevChar = LCurrentChar
  Next
  SeparateUppercase = Result
End Function


Sub SetUploadSuccessMessage(AMessage)
  Session("UploadSuccessMessage") = AMessage
End Sub

Function GetUploadSuccessMessage
  GetUploadSuccessMessage = Session("UploadSuccessMessage")
End Function

' (SS,2/11/23) form field class
' to process additional form fields from enctype="multipart/form-data"
' store them in the object, fetch them, return JSON SQL to save them
' these are other than Name, Email, MarketingOptIn
' we can also exclude Phone, Postcode and Country
' JSON field is called AdditionalFields
' also return text suitable for simple email

Class UploadDef  
  ' table uploads holds: Type, Name, Email, Phone, Country, Postcode, MarketingOptIn, Closed,     AdditionalFields
  '               sizes: 20,   100,  100,   100,   100,     20,       TINYINT(1),     TINYINT(1), LONGTEXT (JSON) 
  Dim FAdditionalFieldList
  Dim FRequiredFieldList
  
  Dim FFieldValues
  
  'Dim FPhone, FPostcode, FMake, FModel, FSerialNumber, FYearOfManufacture, FCondition, FSaleType, FInterestedIn, FAdditionalComments

  Private Sub Class_Initialize
    FAdditionalFieldList = ""
    FRequiredFieldList = ""
    
    Set FFieldValues = Server.CreateObject("Scripting.Dictionary")
    
    ' set the default fields i.e. Name and Email
    AddFieldValue "Name", ""
    AddFieldValue "Email", ""
    ' also the other fields that have a field in the uploads table
    AddFieldValue "Phone", ""
    AddFieldValue "Postcode", ""
    AddFieldValue "Country", ""
  End Sub

  Public Sub Class_Terminate
    Set FFieldValues = Nothing
  End Sub
  
  ' saves new value in Dictionary object
  Public Sub AddFieldValue(AFieldName, AFieldValue)
    FFieldValues.Add AFieldName, AFieldValue
  End Sub
  
  ' sets value in existing key, if it exists, nothing done if it doesn't exist
  Public Sub SetFieldValue(AFieldName, AFieldValue)
    If FFieldValues.Exists(AFieldName) Then
      FFieldValues.Item(AFieldName) = Trim(AFieldValue)
    End If
  End Sub  
  
  ' returns value from Dictionary object, return "" if not found
  Public Function GetFieldValue(AFieldName)  
    If FFieldValues.Exists(AFieldName) Then
      GetFieldValue = FFieldValues.Item(AFieldName)
    Else
      GetFieldValue = ""
    End If
  End Function
  
  ' add each to dictionary object, AValue is comma separated list of field list, set with a default value of ""
  Public Property Let AdditionalFields(AFieldList) 
    Dim LFields, LField, LFieldName
    FAdditionalFieldList = "," & ReplaceStr(AFieldList, " ", "") & ","
    LFields = Split(AFieldList, ",")
    Dim LSubRef
    For Each LField In LFields
      LFieldName = Trim(LField)
      AddFieldValue LFieldName, ""
    Next
  End Property

  Public Sub ShowFieldList
    Dim i, LKeys, LKey
    LKeys = FFieldValues.Keys
    For i = 0 To FFieldValues.Count - 1
      LKey = LKeys(i)
      Response.Write "###" & LKey & " = " & FFieldValues.Item(LKey) & "###" & "<br>"
    Next
  End Sub
  
  Public Function FieldListAsHTML
    Dim LResult, i, LKeys, LKey, LValue
    ' used class="table table-bordered" for bootstrap 3
    LResult = "<table class=""table table-bordered"">" & NL
    LKeys = FFieldValues.Keys    
    For i = 0 To FFieldValues.Count - 1
      LKey = LKeys(i)
      LValue = FFieldValues.Item(LKey)
      If LValue <> "" Then
        LValue = ReplaceNewLinesWithBR(LValue)
        LResult = LResult & "<tr><th>" & SeparateUppercase(LKey) & "</th><td>" & LValue & "</td></tr>" & NL
      End If
    Next    
    LResult = LResult & "</table>" & NL
    FieldListAsHTML = LResult
  End Function
  
  Public Function FieldNameIsValid(AFieldName)
    FieldNameIsValid = FFieldValues.Exists(AFieldName)
  End Function
  
  Private Function IsAdditionalField(AFieldName)
    IsAdditionalField = InStr(1, FAdditionalFieldList, "," + AFieldName + ",", vbTextCompare) > 0
  End Function  
  
  Public Property Let RequiredFields(ARequiredFieldList)
    FRequiredFieldList = "," & ReplaceStr(ARequiredFieldList, " ", "") & ","
  End Property
  
  Public Function IsFieldRequired(AFieldName)
    IsFieldRequired = InStr(1, FRequiredFieldList, "," + AFieldName + ",", vbTextCompare) > 0
  End Function
  
  ' returns " required" or "" for use directly in form
  Public Function FieldRequired(AFieldName)
    If IsFieldRequired(AFieldName) Then
      FieldRequired = " required"
    Else
      FieldRequired = ""
    End If
  End Function  
  
  ' makes use of JSONobject in virtual="common/asp/jsonObject.class.asp" included in dbfunctions.asp
  Public Function GetJSONData
    Dim oJSON
    Set oJSON = New JSONobject
    
    ' add each value
    
    'oJSON.Add "Test 1", False
    'oJSON.Add "Test 2", 123
    'oJSON.Add "Test 3", "ABC"
    'oJSON.Add "Test 4", "AB""C"
    'oJSON.Add "Test 5", "AB'C"
    'oJSON.Add "Test 6", "AB\C"

    Dim i, LKeys, LKey
    LKeys = FFieldValues.Keys
    For i = 0 To FFieldValues.Count - 1
      LKey = LKeys(i)
      If IsAdditionalField(LKey) Then 
        oJSON.Add LKey, FFieldValues.Item(LKey)
      End If
    Next

    GetJSONData = oJSON.Serialize
    Set oJSON = Nothing  
  End Function
  
End Class

%>