<% '============================================================== ' This file contains the database configuration. It also opens ' a connection object (Conn) using OpenCnx. ' The file also contains some common function. '============================================================== 'Global scope variables: Dim conn 'Connection object Dim dbPassword 'Database password '=========================================================== ' Sub: OpenCnx ' Desc: 'Opens connection conn if it is not already open. ' >>> Please, modify configuration with correct values <<< '=========================================================== Sub OpenCnx (ByRef conn) If NOT IsObject(conn) Then On Error Resume Next Dim ConnStr 'Connection string Dim dbPassword 'Database password Set conn = Server.CreateObject("ADODB.Connection") dbPassword = "QS2003p" ' <<<< Change any new Access database password here. '------------------------------------------------------- 'Pick ONE of the following configurations and comment the others 'For additional tech. info see ' - http://www.able-consulting.com/ADO_Conn.htm '------------------------------------------------------- '1. Configuration for System DSN 'ConnStr = "DSN=DSN_Name;uid=;pwd=" & dbPassword '2. Configuration for file DSN (DSN-Less) 'ConnStr = "DBQ=d:\inetpub\quadcomm.com\db\store.mdb;Driver={Microsoft Access Driver (*.mdb)};uid=;pwd=" & dbPassword '3. Configuration for OLEDB drivers (more efficient) 'a) Example of OLEDB connection with OLEDB 3.51 (if you have to use this one you may want to 'consider installing a newer version of MDAC 'ConnStr = "Provider=Microsoft.Jet.OLEDB.3.51; Data Source=C:\web\quadcomm\db\store.mdb; Jet OLEDB:Database Password=" & dbPassword 'b)Example of OLEDB connection on Windows 2000 server (version 4.0) 'ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\web\quadcomm\db\store.mdb; Jet OLEDB:Database Password=" & dbPassword ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Web\starquestpublishing\db\store2K.mdb; Jet OLEDB:Database Password=" & dbPassword 'c)Example of OLEDB connection on Windows 2000 server (version 4.0) and MS SQL Server 7.0/2000 'ConnStr = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=QShopDB; User ID=qshop_usr; Password=" & dbPassword 'ConnStr = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=Q-Shop; User ID=sa; Password=" '------------------------------------------------------- conn.open ConnStr 'Open connection object '------------------------------------------------------- 'When the site is working we recommend you to comment 'Option 1 and uncomment option 2 '------------------------------------------------------- If conn.errors.count > 0 then Dim counter For counter = 0 to conn.errors.count-1 If int(conn.errors(counter).number) <> 0 Then ' Option 1 response.write "Error # :" & conn.errors(counter).number & "

" response.write "Error desc. : " & conn.errors(counter).description & "

" If conn.errors(counter).number = -2147467259 Then response.write "Suggestion: Check the connection string ConnStr in conx.asp and make sure that only one option is not commented using '.

" End If set conn = nothing Response.End 'Option 2 'Redirect user to an error page if there is a connetion error. set conn = nothing Response.Redirect("connerror.htm") Response.End End If next conn.errors.Clear End If 'If you leave the following line commented, all errors will be by-passed unless there is 'a line like this somewhere in the code. On Error Goto 0 End If End Sub '=========================================================== ' Sub: CloseCnx ' Desc: Closes and destroys connection object "conn". '=========================================================== Sub CloseCnx (ByRef conn) If IsObject(conn) Then conn.close set conn = nothing End If End Sub '======================================================================== ' Basic Currency Functions '=========================================================== ' Function: FormatPrice ' Desc: Returns a price formatted including taxes when tax ' model is EU and Show_VAT is enabled. '=========================================================== Function FormatPrice (ByVal nCost, ByVal nTax, ByVal nTaxable) If IsNumeric(nCost) Then If Tax_ShowVAT = 1 AND Tax_Model = "EU" AND nTaxable = 1 Then FormatPrice = FormatNumber(nCost * (1+nTax/100.0),2) Else FormatPrice = FormatNumber(nCost,2) End If Else FormatPrice = "Error!" End If End Function '=========================================================== ' Function: FormatDefCurr (num) ' Desc: Returns a price formatted as currency using the default ' currency settings. '=========================================================== Function FormatDefCurr (num) 'Formats a number (num) as a currency figure with 2 decimal digits If IsNumeric(num) Then FormatDefCurr = Replace(shop_DefCurName,"#",FormatNumber(num,2)) Else FormatDefCurr = "Error!" End If End Function '=========================================================== ' Function: FormatSecCurr (ByVal num) ' Desc: Returns a price converted and formatted as currency ' using the secondary currency settings. '=========================================================== Function FormatSecCurr (ByVal num) 'Converts and formats a number (num) as a secondary currency figure with 2 decimal digits If IsNumeric(num) Then FormatSecCurr = Replace(shop_SecCurName,"#",FormatNumber (num / (CDbl(shop_SecCurConv)),2)) Else FormatDefCurr = "Error!" End If End Function '=========================================================== ' Function not currently used '=========================================================== 'Function FormatDefCurrTax (ByVal nCost, ByVal nTaxRate) ' If IsNumeric(nCost) AND IsNumeric(nTaxRate) Then ' FormatDefCurrTax = FormatDefCurr(nCost*(1+ntaxrate/100.0)) ' Else ' FormatDefCurrTax = "Error!" ' End If 'End Function '=========================================================== ' Function: GetDBCurrentDateTime ' Desc: Returns the current date and time in a format ' accepted by the current database (Access or SQL Server) '=========================================================== Function GetDBCurrentDateTime Dim strDateDelim, dtDate If shop_DB = "SQL" Then strDateDelim = "" 'MS SQL Server dtDate = "GETDATE()" Else strDateDelim = "#" 'MS Access 'Use with Access: It must be in US format MM/DD/YY regardless of local settings. dtDate = Month(Date) & "/" & Day(Date) & "/" & Year(Date) & " " & Time End If 'Build and return final date/time GetDBCurrentDateTime = strDateDelim & dtDate & strDateDelim End Function '=========================================================== ' Function: ParseInj ' Desc: Parses a string for SQL injection attacks. '=========================================================== Function ParseInj(strIn) ParseInj = Replace(strIn, "'", "''") End Function '=========================================================== ' Function: RemoveHTML ' Desc: Removes HTML tags from a string '=========================================================== Function RemoveHTML(sText) Dim RegEx Set RegEx = New RegExp RegEx.Pattern = "<[^>]*>" RegEx.Global = True RegEx.IgnoreCase = True RemoveHTML = RegEx.Replace(sText, "") End Function '======================================== 'Create connection object Call OpenCnx (conn) '======================================== %> <% '----------------------------------------------------------- ' Q-Shop Parameter/Settings definition ' Developed by QuadComm Inc. for use with Q-Shop ' © Copyright QuadComm, Inc. 2003. All rights reserved '----------------------------------------------------------- '======================================================================== ' CONSTANTS HARDCODED '======================================================================== '========================================= 'Collect Credit Card Details '========================================= Dim bCollectCCDetails 'Indicates whether credit card details fields should be shown 'If True CC fields are collected and saved to the database (True|False) 'Use True when processing credit cards manually 'Choose of the two options and comment the other one: bCollectCCDetails = False 'Display CC details fields 'bCollectCCDetails = True 'Don't display CC details fields '========================================= '========================================= 'Paypal configuration '========================================= Dim bEnablePaypal 'When True a paypal option will be displayed (True|False). (default is False) 'Choose of the two options and comment the other one: bEnablePaypal = True 'Enable Paypal 'bEnablePaypal = False 'Disable Paypal '========================================= '========================================= 'Cash on Delivery (COD) configuration '========================================= Dim bEnableCOD 'When True a COD option will be displayed (True|False). (default is True) 'Choose of the two options and comment the other one: 'bEnableCOD = True 'Enable COD bEnableCOD = False 'Disable COD '========================================= '========================================= 'External payment gateway link configuration '========================================= Dim bExtGateway 'Indicates whether the credit card payment is processed in an external site 'If True the credit card options including details won't be shown. (True|False) 'Choose of the two options and comment the other one: 'bExtGateway = True 'Use external gateway bExtGateway = False 'No external gateway '========================================= '========================================= 'CC extra fields configuration '========================================= Dim bShow_CCIssueNumber 'Display issue number field? (True|False) bShow_CCIssueNumber = False Dim bShow_CVV 'Display CVV number field? (True|False) bShow_CVV = True Dim bShow_L4SSN 'Display last 4 SNN digits field? (True|False) bShow_L4SSN = False 'Used for Transact-Secure with Authorize.Net '========================================= '========================================= 'Order email confirmation '========================================= Dim bSendMailConf 'Defines whether a mail confirmation should be sent (True|False). Default to True bSendMailConf = True 'Default True: Send email confirmation message. '======================================================================== 'Get secure URL details. If there is a secure URL get the non-secure as well. '======================================================================== Dim strNonSecPath Dim strSecPath strSecPath = Application("SECUREURL") If strSecPath <> "" Then strNonSecPath = Application("URL") 'Hardcode if necessary: 'strSecPath = "https://www.secure-us.net/quadcomm/demo/" 'strNonSecPath = "http://quadcomm.com/demo/" '======================================================================== '======================================================================== ' Logo file paths. If you need to have content other than images, you can ' hardcode the value here. '======================================================================== Dim LogoURL, smLogoURL, LineLogoURL 'URL of the main logo. Double quote all quote characters 'LogoURL = "" If Application("LogoURL") <> "" Then LogoURL = "" Else LogoURL = "" End If 'URL of the small logo on the left-hand side bar. Double quote all quote characters 'smLogoURL = "" If Application("smLogoURL") <> "" Then smLogoURL = "" Else smLogoURL = "" End If 'URL of the small logo displayed when a product has no picture (called in inc/line.asp). Double quote all quote characters. This could also be text or HTML code. 'LineLogoURL = "" If Application("NotAvailImg") <> "" Then LineLogoURL = "" Else LineLogoURL = "(No image)" End If '======================================================================== '======================================================================== Dim MaxItems 'Defines the maximum number of products per page when 'browsing products in the shop '======================================================================== MaxItems = 20 'Maximum number of items displayed at once '======================================================================== 'Set browse layout types: S (single), M (multiple) ' Single: Each product has its own add to cart button ' Multiple: All products in a page share an add to cart button so that ' multiple products can be added to the cart at the same time. '======================================================================== Dim sBrowseSearch 'Browse type for products page Dim sBrowseOffer 'Browse type for Offers page Dim sBrowseManu 'Browse type for Manufacturers page Dim sBrowseFeat 'Browse type for Featured Products page Dim sBrowseMyList 'Browse type for My List page sBrowseSearch = "S" 'Browse search results sBrowseOffer = "M" 'Browse offers page sBrowseManu = "S" 'Browse by brands/manufacturer list page sBrowseFeat = "M" 'Browse featured products sBrowseMyList = "M" 'Browse type for My List page '======================================================================== '======================================================================== ' Related Products Parameters (used in details.asp) '======================================================================== Dim RelProdsLayout 'Related Products Layout Dim RelProdsTableColumns 'Number of related products per line when using "Thumbnail" layout RelProdsLayout = "Thumbnail" '(Thumbnail|List) RelProdsTableColumns = 3 '======================================================================== '======================================================================== ' Email confirmation settings '======================================================================== Dim sMailFormat 'Related Products Layout (TEXT|HTML) sMailFormat = "TEXT" '(TEXT|HTML) 'sMailFormat = "HTML" '(TEXT|HTML) '======================================================================== '======================================================================== ' CONSTANTS LOADED DYNAMICALLY FROM DB, ETC. '======================================================================== ' You shouldn't edit the parameters below in normall circumstances ' unless you want to override the default way of loading them via the ' database and the control panel. '======================================================================== '======================================================================== ' Shop Settings definitions '======================================================================== Dim shop_DefCurName, shop_SecCurName, shop_SecCurConv, shop_CompanyName, shop_Mail, shop_Title, shop_StockControl Dim shop_DB, shop_MailSystem, shop_URL, shop_ShowTerms Dim shop_TempPath 'Temporary folder (to write temporary files). This folder requires write permissions 'for the IUSR_ user (used by the web server). shop_TempPath = Application("TempPath") '***** CONFIGURE IN CONTROL PANEL ***** ' Currency shop_DefCurName = Application("DefCurName") shop_SecCurName = Application("SecCurName") shop_SecCurConv = Application("SecCurConv") 'Others shop_CompanyName = Application("CompanyName") shop_Mail = Application("Mail") shop_Title = Application("Title") If Application("ShowTerms") = "1" Then shop_ShowTerms = True Else shop_ShowTerms = False End If If Application("StockControl") = "1" Then shop_StockControl = True Else shop_StockControl = False End If shop_DB = Application("DBSystem") shop_MailSystem = Application("MailSystem") shop_URL = Application("URL") 'Shop base URL. 'If the URL doesn't end with "/" add it: If RIGHT(shop_URL,1) <> "/" Then shop_URL = shop_URL & "/" 'Colour settings Dim CART_HEAD_BG, CART_HEAD_FONT, CART_BODY_BG, LMENU_BG, LMENU_FONT, LMENU_SUB_FONT, TMENU_BG Dim TMENU_FONT, SEC_BG, SEC_FONT, DETAILS_BG, DETAILS_HEAD_BG, DETAILS_HEAD_FONT CART_HEAD_BG = Application("CART_HEAD_BG") CART_HEAD_FONT = Application("CART_HEAD_FONT") CART_BODY_BG = Application("CART_BODY_BG") LMENU_BG = Application("LMENU_BG") LMENU_FONT = Application("LMENU_FONT") LMENU_SUB_FONT = Application("LMENU_SUB_FONT") TMENU_BG = Application("TMENU_BG") TMENU_FONT = Application("TMENU_FONT") SEC_BG = Application("SEC_BG") SEC_FONT = Application("SEC_FONT") DETAILS_BG = Application("DETAILS_BG") DETAILS_HEAD_BG = Application("DETAILS_HEAD_BG") DETAILS_HEAD_FONT = Application("DETAILS_HEAD_FONT") 'Tax Settings Dim Tax_Model, Tax_ShowVAT Tax_Model = Application("Tax_Model") 'EU, US or CAN supported Tax_ShowVAT = Application("Tax_ShowVAT") '1: Show VAT included. '======================================================================== ' DB Constant definitions (From adovbs.inc) ' Remove if including adovbs.inc '======================================================================== '---- CursorTypeEnum Values ---- Const adOpenForwardOnly = 0 Const adOpenKeyset = 1 Const adOpenDynamic = 2 Const adOpenStatic = 3 '---- LockTypeEnum Values ---- Const adLockReadOnly = 1 Const adLockPessimistic = 2 Const adLockOptimistic = 3 Const adLockBatchOptimistic = 4 '---- CursorLocationEnum Values ---- Const adUseServer = 2 Const adUseClient = 3 '---- Other ---- Const adExecuteNoRecords = &H00000080 %> <% '======================================================================== ' Extract some fundamental variables used later on '======================================================================== ' New order status. Set here to the desired status Id: CONST N_BILLINGSTATUS_NEWORDER = 0 'Billing status for new orders CONST N_STATUS_NEWORDER = 0 'Order status for new orders Dim CartID, UserID 'Extract Cart ID from session, Query String or Form if not available (some SSL) If Session("CartID") <> "" Then CartID = Session("CartID") elseif Request.QueryString("CartID") <> "" Then CartID = Request.QueryString("CartID") Session("CartID") = CartID 'Save in the session else CartID = Request.Form("CartID") End If 'Extract UserID from session, Query String or Form if not available If Session("UserID") <> "" Then UserID = Session("UserID") elseif Request.QueryString("UserID") <> "" Then UserID = Request.QueryString("UserID") else UserID = Request.Form("UserID") End If 'If the Session UserID is different to the one in the querystring then take the one from the 'URL and update the Session variable and the variable UserID. 'This should only happen during checkout on a SSL connection if the ASP application is different 'i.e. using a shared certificate. If Session("UserID") <> Request.QueryString("UserID") AND Request.QueryString("UserID") <> "" Then Session("UserID") = Request.QueryString("UserID") UserID = Request.QueryString("UserID") End If '========================== START OF LIBRARY ============================= '========================================================================= ' Function: WritePriceOptions ' Writes the select box with the contents of the price ' options. '========================================================================= Function WritePriceOptions (ByVal PID,ByVal n) Dim Options, strSQL, strTemp 'Dim aryOptions () strTemp = "" strSQL = "SELECT PriceOptions.Id, PriceOptions.ProdId, PriceOptions.Description, PriceOptions.DifOrAbs, PriceOptions.Cost, Products.Taxable, Products.VATRate FROM PriceOptions, Products WHERE PriceOptions.ProdId ='" & PID & "' AND Products.ProdID = PriceOptions.ProdID" set Options = conn.Execute (strSQL) If NOT (Options.EOF AND Options.BOF) Then aryOptions = Options.GetRows Else set Options = nothing Exit Function End If Options.Close set Options = nothing If UBound(aryOptions,2) - LBound(aryOptions,2) >= 0 Then strTemp = "Select Option: " End If WritePriceOptions = strTemp End Function '========================================================================= ' Function: WritePriceOptions ' Writes the select box with the contents of the price ' options. '========================================================================= Function WritePriceOptionsPrintable (ByVal PID,ByVal n) Dim Options, strSQL, strTemp 'Dim aryOptions () strTemp = "" strSQL = "SELECT PriceOptions.Id, PriceOptions.ProdId, PriceOptions.Description, PriceOptions.DifOrAbs, PriceOptions.Cost, Products.Taxable, Products.VATRate FROM PriceOptions, Products WHERE PriceOptions.ProdId ='" & PID & "' AND Products.ProdID = PriceOptions.ProdID" set Options = conn.Execute (strSQL) If NOT (Options.EOF AND Options.BOF) Then aryOptions = Options.GetRows Else set Options = nothing Exit Function End If Options.Close set Options = nothing If UBound(aryOptions,2) - LBound(aryOptions,2) >= 0 Then strTemp = "Options: " For j = LBound(aryOptions,2) to UBound(aryOptions,2) 'Build string for price difference options If aryOptions(3,j) = 0 AND aryOptions(4,j) > 0 Then strAddDisc = "+" If aryOptions(3,j) = 0 AND aryOptions(4,j) < 0 Then strAddDisc = "-" strTemp = strTemp & "

  • " & aryOptions(2,j) If CStr(aryOptions(4,j)) <> "" AND CStr(aryOptions(4,j)) <> "0" Then strTemp = strTemp & " (" & strAddDisc & FormatDefCurr (FormatPrice(Abs(aryOptions(4,j)), aryOptions(6,j), aryOptions(5,j))) & ")" & vbCrLf End If strAddDisc = null Next strTemp = strTemp & "
    " End If WritePriceOptionsPrintable = strTemp End Function '========================================================================= ' Function: UnitPrs ' Returns units description. Currently only 1 is used '========================================================================= Function UnitPrs (cod) if cod = 1 Then UnitPrs = "Unit/s" if cod = 2 Then UnitPrs = "gr." if cod = 3 Then UnitPrs = "Kg." End Function '========================================================================= ' Function: CutRFWord ' Trim and cut to nlength craracters max the Request.Form(name) passed. '========================================================================= Function CutRFWord (name, nlength) Dim sTmp sTmp = Left(Trim(Request.Form(name)),nlength) If sTmp <> "" Then CutRFWord = sTmp Else CutRFWord = Null End If End Function '========================================================================= ' Function: ProdName ' Returns the name of a product with id cod '========================================================================= Function ProdName (cod) Dim rs, sql Set rs = Server.CreateObject("ADODB.Recordset") sql= "SELECT Name FROM products WHERE ProdID = '" & cod & "'" rs.Open sql,Conn, adOpenStatic, adLockOptimistic If rs.EOF AND rs.BOF Then ProdName = "Product deleted" else ProdName = rs("Name") End If rs.Close set rs = nothing End Function '========================================================================= ' Function: DeleteCart ' Deletes cart with ID IDCart '========================================================================= Function DeleteCart (IDCart) Dim rs, sql sql= "DELETE FROM Carts WHERE CartID = '" & IDCart & "'" set rs = Conn.Execute(sql) set rs = nothing End Function '========================================================================= ' Function: CreateOrder ' Creates order from cart with ID = IDCart in the orders/orderlines tables 'Uses from form: 'TotalTax: Total taxes 'ShipCost: Shipping costr 'e-mail: Email address 'Password: Password 'Billing details 'Name: Customer's Name 'Surname: Customer's Surname 'Company: Customer's Company name 'Address: Customer's Address part 1 'Address2: Customer's Address part 2 'CP: Customer's Post Code/ZIP 'Town: Customer's City/Town 'Province: Customer's State or Province 'Country: Customer's Country 'Telephone: Customer's Telephone number 'mailme: Is customer subscribing to receive news and notifications? (True/False) 'rememberme:Does customer want to be logged in automatically next time? (True/False) 'Shipping/Recepient details 'DName: Ship to Name 'DAddress: Ship to Address part 1 'DAddress2: Ship to Address part 2 'DCompany: Ship to Company 'DCP: Ship to Post Code/ZIP 'DTown: Ship to City/Town 'DProvince: Ship to State or Province 'DTelephone:Ship to Telephone number 'DCountry: Ship to Country ' 'payment: Payment type (VISA,COD, etc) 'CCOwner Name on Credit Card 'CCNumber: Credit Card Number 'CCExpDateMonth: Credit Card Expiration date month 'CCExpDateYear: Credit Card Expiration date year 'CCIssueNumber: Credit Card Issue Number 'CCCVV: Credit Card verification number 'TaxId: Tax code (Tax ID) (eg VAT number) 'strUPS: String returned by UPS real time calculation module ' 'Comments: Customer order comments. 'Uses variables from prochkoutend.asp: 'PriceT: Products total cost 'Taxes: Order tax 'TotalTax: Tax rate 'ShipCost: Shipping cost applied 'PriceTG: Order total 'WeightT: Total products weight '========================================================================= Function CreateOrder (IDCart) Dim rs, rsh, rsu, rsl, rsoid Dim sql Dim NewUSer Dim OrderID 'Get cart Set rs = Server.CreateObject("ADODB.Recordset") sql= "SELECT Carts.*, Products.Name, PriceOptions.Description As PODescription " & _ "FROM (Carts INNER JOIN Products ON Carts.ProdID = Products.ProdID) " & _ "LEFT OUTER JOIN PriceOptions ON Carts.PriceOption = PriceOptions.id " & _ "WHERE CartID = '" & IDCart & "'" rs.Open sql, Conn, adOpenStatic, adLockOptimistic 'Orders Headers DB: rsh 'Note: We query an impossible record to correct a possible 'wrong behaviour with Microsoft's DB drivers Set rsh = Server.CreateObject("ADODB.Recordset") rsh.Open "SELECT * from Orders WHERE (0 = 1)", Conn, adOpenKeySet, adLockOptimistic 'OrderLines DB: rsl Set rsl = Server.CreateObject("ADODB.Recordset") rsl.Open "SELECT * from Orderlines WHERE (0 = 1)", Conn, adOpenStatic, adLockOptimistic 'User Data: rsu Set rsu = Server.CreateObject("ADODB.Recordset") rsu.Open "SELECT * from Users WHERE UserID ='" & UserID & "'", Conn, adOpenStatic, adLockOptimistic If rsu.EOF AND rsu.BOF Then 'If no data found create a new one NewUSer = True rsu.Close rsu.Open "SELECT * from Users WHERE (1=0)", Conn, adOpenStatic, adLockOptimistic Else NewUser = False End If If NewUSer then rsu.AddNew rsu("UserID") = UserID If Request("Company") <> "" Then rsu("Company") = CutRFWord("Company",50) Else rsu("Company") = Null End If rsu("Name") = CutRFWord("Name",50) rsu("Surname") = CutRFWord("Surname",50) rsu("Address") = CutRFWord("Address",100) rsu("Address2") = CutRFWord("Address2",100) rsu("CP") = CutRFWord("CP",10) rsu("City") = CutRFWord("Town",50) If Trim(Request.Form("Province")) <> "" Then rsu("Province") = CutRFWord("Province",50) rsu("Country") = CutRFWord("Country",20) If Trim(Request.Form("Telephone")) <> "" Then rsu("Phone") = CutRFWord("Telephone",50) If Request.Form("e-mail") <> "" Then rsu("mail") = CutRFWord("e-mail",100) If Request.Form("mailme") = "yes" Then rsu("mailme") = 1 else rsu("mailme") = 0 End If else rsu("mailme") = 0 End If If Request.Form("rememberme") = "yes" Then rsu("rememberme") = 1 Else rsu("rememberme") = 0 End If rsu("Date") = Now 'If is a new user and has chosen a password (error if not) and is not logged (extra check) then 'use the suggested password If NewUser AND (NOT Session("Logged")) AND Request.Form("Password") <> "" Then rsu("pwd") = Request.Form("Password") End If ' If IsNull(rsu("pwd")) AND Session("uPwd")<> "" Then rsu("pwd") = Session("uPwd") rsu("LastVisit") = Date Session("DateUpdated") = True rsu.Update rsu.Close set rsu = nothing rsh.AddNew rsh("UserID") = UserID rsh("CartID") = CartID rsh("Date") = Now 'Formatdatetime(now(),2) 'Customer details If Trim(Request.Form("Company")) <> "" Then rsh("Company") = CutRFWord("Company",100) rsh("Name") = CutRFWord("Name",50) rsh("Surname") = CutRFWord("Surname",50) rsh("Address") = CutRFWord("Address",100) rsh("Address2") = CutRFWord("Address2",100) rsh("CP") = CutRFWord("CP",10) rsh("City") = CutRFWord("Town",50) if Request.Form("Province") <> "" Then rsh("Province") = CutRFWord("Province",50) If Request.Form("Telephone") <> "" Then rsh("Phone") = CutRFWord("Telephone",50) rsh("mail") = CutRFWord("e-mail",100) rsh("Country") = CutRFWord("Country",20) 'Delivery Details If Trim(Request.Form("DName")) <> "" Then rsh("DName") = CutRFWord("DName",100) If Trim(Request.Form("DAddress")) <> "" Then rsh("DAddress") = CutRFWord("DAddress",100) If Trim(Request.Form("DAddress2")) <> "" Then rsh("DAddress2") = CutRFWord("DAddress2",100) If Trim(Request.Form("DCompany")) <> "" Then rsh("DCompany") = CutRFWord("DCompany",100) If Trim(Request.Form("DCP")) <> "" Then rsh("DCP") = CutRFWord("DCP",10) If Trim(Request.Form("DTown")) <> "" Then rsh("DCity") = CutRFWord("DTown",50) If Trim(Request.Form("DProvince")) <> "" Then rsh("DProvince") = CutRFWord("DProvince",50) If Trim(Request.Form("DTelephone")) <> "" Then rsh("DPhone") = CutRFWord("DTelephone",50) If Trim(Request.Form("DCountry")) <> "" Then rsh("DCountry") = CutRFWord("DCountry",20) 'Costs rsh("SubTotal") = CDbl(PriceT) rsh("Taxes") = Taxes rsh("TotalTax") = TotalTax rsh("Delivery") = ShipCost rsh("Total") = CDbl(PriceTG) If CStr(WeightT) <> "" Then rsh("Weight") = CDbl(WeightT) else rsh("Weight") = 0 End If 'Store user discount value. rsh("UserDiscount") = nUrDiscountTotal '==================================== ' Order status and billing status ' Change the default values at the top '==================================== ' Set the status of new orders. rsh("Status") = N_STATUS_NEWORDER ' Set the billing status of new orders. rsh("BillingStatus") = N_BILLINGSTATUS_NEWORDER 'Payment method rsh("PaymentMode") = CutRFWord("payment",50) 'Credit card details stored if there is an owner name (CCOwner). If Request.Form("CCOwner") <> "" Then rsh("CCOwner") = CutRFWord("CCOwner",100) 'Remove spaces and "-". Dim sEncCCNumber sEncCCNumber = Replace(Replace(CutRFWord("CCNumber",40)," ",""),"-","") 'Encrypt and encode into HEX string to be safely stored sEncCCNumber = EncryptAndEncode(sEncCCNumber) 'rsh("CCNumber") = Replace(Replace(CutRFWord("CCNumber",40)," ",""),"-","") rsh("CCNumber") = sEncCCNumber 'Store the encrypted and encoded in Hex string CC number rsh("CCExpDate") = EncryptAndEncode(CutRFWord("CCExpDateMonth",2) & "/" & Right(Request.Form("CCExpDateYear"),2)) If Request.Form("CCIssueNumber") <> "" Then rsh("CCIssueNumber") = CutRFWord("CCIssueNumber",10) End If 'Get CVV number (from back of some cards). Cut to 7 characters. If CutRFWord("CCCVV",7) <> "" Then rsh("CCCVV") = CutRFWord("CCCVV",7) End If End If 'UPS returned values. Store here if adding another external company system. If Request.Form("strUPS") <> "" Then rsh("Shipping") = CutRFWord("strUPS",50) End If 'VAT number used in European Union to allow tax exemption for companies If Request.Form("TaxId") <> "" Then rsh("TaxID") = CutRFWord("TaxId",100) End If 'Transaction values return in real time payment processing like Authorize.Net. If strTrans <> "" Then rsh("TransactionData") = Left(strTrans,150) End If 'User comments If Trim(Request.Form("Comments")) <> "" Then rsh("Comments") = Request.Form("Comments") 'User IP address stored as security meassure. rsh("RemoteIP") = LEFT(Request.ServerVariables("REMOTE_ADDR"),15) 'Save details rsh.Update 'Obtain the order Id generated automatically by the database OrderID = rsh("Id") rsh.Close set rsh = nothing 'If the Order id wasn't retrieved correctly, attempt to query the record using the combination 'of Cart Id and User Id. This code should not get to be executed in a normal installation!. If CStr(orderID) = "" Then set rsoid = conn.Execute ("SELECT Id FROM orders WHERE UserID = '" & UserID & "' AND CartId = '" & CartID & "' ORDER BY Id DESC") If rsoid.EOF and rsoid.BOF Then set rsoid = nothing %> Fatal Error occurred, please contact shop administrator. Your order ID could not be retrieved

    [an error occurred while processing this directive] <% 'Close and destroy connection Call CloseCnx(conn) %> <% Response.End else OrderID = rsoid("Id") End If rsoid.Close set rsoid = nothing End If Do while NOT rs.eof rsl.AddNew rsl("OrderID") = OrderID rsl("ProdID") = rs("ProdID") rsl("Price") = rs("Price") rsl("Qtty") = rs("Qtty") rsl("Units") = rs("Units") If rs("Option1") <> "" AND rs("Option1") <> vbNull Then rsl("Option1") = rs("Option1") End If If rs("Option2") <> "" AND rs("Option2") <> vbNull Then rsl("Option2") = rs("Option2") End If If rs("PriceOption") <> "" AND rs("PriceOption") <> vbNull Then rsl("PriceOption") = rs("PriceOption") End If rsl("ProdName") = rs("Name") 'Save the product Name (in case it changes) rsl("PriceOptionDesc") = rs("PODescription") 'Save the Price Option Name (in case it changes) rsl.Update 'Register order line in Historic table RegPurch rs("ProdID"), rs("CatID"), UserID 'Update teh stock level accordingly DecreaseStock rs("ProdId"), rs("Qtty") rs.movenext Loop rs.Close rsl.Close set rs = nothing set rsl = nothing 'If it's a new user then set basic info in the Session If NOT Session("Logged") Then Session("Name") = Request.Form("Name") Session("Surname") = Request.Form("Surname") Session("Mail") = Request.Form("E-Mail") Session("Country") = Request.Form("Country") Session("uPwd") = Request.Form("Password") Session("UserDiscount") = 0 'Set new users discount to 0 as default. End If 'Log the user in automatically Session("Logged") = True 'Return the order Id CreateOrder = OrderID End Function '========================================================================= ' Function: RegPurch ' Registers purchase in the customer's purchase history '========================================================================= Function RegPurch (PID, CID, UID) Dim reg, sql Set reg = Server.CreateObject("ADODB.Recordset") sql= "SELECT * FROM Historic WHERE UserID = '" & UID & "' AND ProdID = '" & PID & "'" reg.Open sql,Conn, adOpenStatic, adLockOptimistic If reg.EOF AND reg.BOF Then 'reg.recordcount = 0 reg.AddNew reg("UserID")= UID reg("ProdID")= PID reg("CatID")= CID reg("Qtty")= 1 reg("Date") = Now reg.Update Else TotalItms = reg("Qtty") reg("Qtty") = TotalItms + 1 reg("Date") = Now reg.Update End If reg.Close set reg = nothing End Function '========================================================================= ' Function: MoveCart ' FUNCTION INCLUDED FOR BACKWARDS COMPATIBILITY: It simply calls CreateOrder if 'an old version of procchkoutend calls MoveCart. '========================================================================= Function MoveCart (nIDCart) MoveCart = CreateOrder (nIDCart) End Function '========================================================================= ' Function: DecreaseStock (PID, Qtty) ' Decreases the Stock for Product Id PID is Stock control is active '========================================================================= Function DecreaseStock (PID, Qtty) Dim stock, sql If shop_StockControl Then Set stock = Server.CreateObject("ADODB.Recordset") sql= "UPDATE Products SET Stock = Stock - " & Qtty & " WHERE ProdID = '" & PID & "'" set stock = conn.Execute(sql) set stock = nothing End If End Function '========================================================================= ' Function: CheckStock ' Checks that all products in cart are in stock. ' Returns True if all products are in stock and False if not '========================================================================= Function CheckStock Dim strSQL, CartRs 'Only check if the stock control is on If shop_StockControl Then strSQL = "SELECT Products.ProdId FROM Carts, Products where Carts.ProdId = Products.ProdId AND Stock < Qtty AND Carts.CartID = '" & CartID & "'" 'Response.Write strSQL Set CartRs = Server.CreateObject("ADODB.Recordset") set CartRs = conn.Execute(strSQL) If CartRs.EOF AND CartRs.BOF Then 'All products are in stock CheckStock = True Else 'Some products are not in stock CheckStock = False End If CartRs.Close set CartRs = nothing else CheckStock = True End If End Function %> <% '================================================================ ' This library contains functions to generate the HTML for carts ' Note: To be called only AFTER conx.asp ' Copyright © QuadComm, Inc. 2000-2002 '================================================================ '================================================================ ' ShowCart (nCartID, strInfo) ' Displays the shopping cart. ' Used during the browsing period. Not during checkout ' nCartID: Cart ID ' strInfo: Message to be displayed (for error handling). '================================================================ Function ShowCart (nCartID, strInfo) Dim Cart, sql Dim PriceT Dim PriceTTaxed 'Total cost including taxes (EU ONLY) Dim i, nRows Dim aryCart Dim fldProdName Dim fldPrice, fldQtty, fldProdId, fdlOption1, fldOption2, fldUnits, fldCartID Dim fldPODescription Dim pricelin 'Cost of the cart line (indiv. price * Quantity) Dim pricelinTaxed 'Cost of the cart line including taxes (EU ONLY) fldProdName = 0 fldCartID = 1 fldProdId = 2 fldQtty = 3 fldPrice = 4 fldOption1 = 5 fldOption2 = 6 fldUnits = 7 fldPODescription = 8 fldVATRate = 9 fldTaxable = 10 Set Cart = Server.CreateObject("ADODB.Recordset") 'sql= "SELECT * FROM Carts WHERE CartID = '" & nCartID & "'" sql = "SELECT Products.Name, carts.ID, carts.ProdId, carts.Qtty, carts.Price, carts.Option1, carts.Option2, carts.Units, PriceOptions.Description, Products.VATRate, Products.Taxable from Products INNER JOIN (carts LEFT JOIN Priceoptions ON carts.Priceoption = PriceOptions.Id) ON Products.ProdId = Carts.ProdId where cartid = '" & nCartID & "'" 'response.Write sql Cart.Open sql,Conn, adOpenForwardOnly, adLockReadOnly If NOT (Cart.EOF AND Cart.BOF) Then aryCart = cart.GetRows 'Clean up recordset cart.Close set cart = nothing nRows = UBound(aryCart, 2) PriceT = 0.0 PriceTTaxed = 0.0 If strInfo <> "" Then Response.Write "
    " & strInfo & "

    " End If %> <% For i = 0 to nRows 'Line cost pricelin = CDbl(aryCart(fldPrice,i)) * int(aryCart(fldQtty,i)) 'Line cost including taxes (EU ONLY) pricelinTaxed = pricelin * (1 + aryCart(fldVATRate,i) / 100.0 * aryCart(fldTaxable,i)) %> <% PriceT = PriceT + pricelin If Tax_ShowVAT = 1 AND Tax_Model = "EU" Then PriceTTaxed = PriceTTaxed + pricelinTaxed Else PriceTTaxed = PriceT End If Next %>
    Product Price Quantity Total <% If Tax_ShowVAT = 1 AND Tax_Model = "EU" Then Response.Write "(VAT inc)" End If %>  
    <%= aryCart(fldProdName,i) %> <% If aryCart(fldOption1,i) <> "" OR aryCart(fldOption2,i) <> "" Then %>
            <%= aryCart(fldOption1,i) %>   <%= aryCart(fldOption2,i) %> <% If aryCart(fldPODescription,i) <> "" Then %>   Option: <%= aryCart(fldPODescription,i) %> <% End If %>
    <% Else If aryCart(fldPODescription,i) <> "" Then %>
            Option: <%= aryCart(fldPODescription,i) %>
    <% End If End If %>
    <%= FormatPrice(aryCart(fldPrice,i),aryCart(fldVATRate,i),aryCart(fldTaxable,i)) %> <%= aryCart(fldQtty,i) %> <%= UnitPrs(aryCart(fldUnits,i)) %> <%= FormatPrice(pricelin,aryCart(fldVATRate,i),aryCart(fldTaxable,i)) %>     Click to Remove    

    Total = <%= FormatDefCurr(FormatPrice(PriceTTaxed,0,0)) %>
    <% If shop_SecCurName <> "" Then Response.Write FormatSecCurr (FormatPrice(PriceTTaxed,0,0)) & "
    " End If %>

    Notes:
    - Click on Click to Remove to remove a product from your cart.
    - Click on a product or quantity to see its details or modify the quantity.
    - Click on Empty Cart to remove all products from your cart.
    <% If shop_SecCurName <> "" Then %> - Prices in secondary currency are approximate only.
    <% End If If Tax_ShowVAT = 1 AND Tax_Model = "EU" Then%> - VAT included. Customer from outside the EU or VAT exempt will be able
      to remove taxes at checkout.
    - Shipping costs will be added during the checkout (when applicable). <% Else %> - Taxes and shipping costs will be added during checkout (when applicable). <% End If %>
    <% Else PriceT = 0.0 'Clean up recordset set cart = nothing Response.Write "

     

    Your shopping cart is empty.

     

    " End If 'Set the session total If Tax_ShowVAT = 1 AND Tax_Model = "EU" Then 'If we are showing taxes then save the total incl. VAT. Session("Total") = PriceTTaxed Else 'Set the total before tax Session("Total") = PriceT End If End Function '================================================================ ' GetHTMLCart ' Returns the shopping cart into a variable ' Used during checkout. ' It needs that the doc that calls this file also includes ' inc/catfunc.asp for prodname ' USES INPUT: ' CartID: Cart ID ' ShipCost: Shipping cost ' TotalTax: Tax percentage to apply ' bTaxExempt: Tax Exempt (for VAT calculations) ' PRODUCES OUTPUT (indirectly through global variables): ' PriceT: Sub-total price ' WeightT: Total weight ' TotalTG: Total cost including delivery and taxes ' Taxes: Total tax amount ' nItems: Total numbers of items in the cart ' nUrDiscountTotal: Total user discount (not rate) '================================================================ Function GetHTMLCart '(nCartID, nPriceT, nWeightT, nShipCost, nTotalTax) Dim pricelin 'Price of the current line Dim HTMLCart 'Cart in HTML format Dim VATTax, AppliedTax 'Taxes Dim nUserDiscount 'User Discount Dim nAdditionalFee 'Additional fee charged in certain circumstances If (Session("UserDiscount") <> "") AND IsNumeric(Session("UserDiscount")) Then nUserDiscount = CDbl(Session("UserDiscount")) Else nUserDiscount = 0 End If 'Calculation of payment method additional charges nAdditionalFee = 0.0 Select Case Request("payment") 'Cash on Delivery charge Case "COD" nAdditionalFee = 17.0 'Any other payment method charge Case else nAdditionalFee = 6.0 End Select 'Obtain cart data Set Cart = Server.CreateObject("ADODB.Recordset") 'sql= "SELECT * FROM Carts WHERE CartID = '" & CartID & "'" sql = "SELECT Products.Name, Products.VATRate, Products.Taxable, carts.*, PriceOptions.Description from Products INNER JOIN (carts LEFT JOIN Priceoptions ON carts.Priceoption = PriceOptions.Id) ON Products.ProdId = Carts.ProdId where cartid = '" & CartID & "'" Cart.Open sql,Conn, adOpenForwardOnly, adLockReadOnly HTMLCart = "" & _ "" & _ "" & _ "" & _ "" & _ "" & _ "" 'Initialise values: nItems = 0 VATTax = 0 Do while NOT cart.EOF HTMLCart = HTMLCart & "" & _ "" & _ "" & _ "" & vbCrLf 'Calculate total price in PriceT PriceT = PriceT + pricelin 'Calculate total weight in WeightT WeightT = WeightT + CDbl(cart("Weight")*cart("Qtty")) 'Move to next item in cart cart.movenext Loop 'Calculate total discount nUrDiscountTotal = PriceT * nUserDiscount / 100 HTMLCart = HTMLCart & "
    Product Price Quantity Total
    " 'Cost of the line = Price * Quantity pricelin = CDbl(cart("Price")) * int(cart("Qtty")) 'Numbers of items so far nItems = nItems + int(cart("Qtty")) 'If EU (VAT) calculate the tax. 'Only calculate if is not TAX exempt: ' - Customer has a VAT number ' - Customers outside the European Union If Tax_Model = "EU" AND NOT bTaxExempt Then VATTax = VATTax + pricelin * (1 - nUserDiscount/100) * (CDbl(cart("VATrate")) / 100) 'HTMLCart = HTMLCart & AppliedTax & "(" & pricelin * (1 - nUserDiscount/100) * (CDbl(cart("VATrate")) / 100) & ") " 'If USA or Canada model then apply tax to non-exempt products (labour or services...) ElseIf Tax_Model = "CAN" OR Tax_Model = "USA" Then 'Response.Write TotalTax & "|" & cart("Taxable") & "/" AppliedTax = AppliedTax + pricelin * (1 - nUserDiscount/100) * TotalTax * cart("Taxable") 'HTMLCart = HTMLCart & AppliedTax & " (" & pricelin * (1 - nUserDiscount/100) * TotalTax * cart("Taxable") & ") - " End If 'Display product Name HTMLCart = HTMLCart & prodname(cart("prodid")) If Tax_Model = "EU" AND NOT bTaxExempt Then HTMLCart = HTMLCart & " (" & cart("VATrate") & "% VAT)" End If 'Display options (if any) If cart("Option1") <> "" OR cart("Option2") <> "" Then HTMLCart = HTMLCart & "
    " & _ "       " & cart("Option1") & _ "  " & cart("Option2") If cart("Description") <> "" Then HTMLCart = HTMLCart & "  Option: " & cart("Description") HTMLCart = HTMLCart & "
    " Else If cart("Description") <> "" Then HTMLCart = HTMLCart & "
            Option: " & cart("Description") & "
    " End If End If HTMLCart = HTMLCart & "
    " & FormatNumber(cart("Price"),2) & "" & Cart("Qtty") & " " & UnitPrs(cart("Units")) & "" & FormatNumber(pricelin,2) & "
    " & _ "
    " If nUrDiscountTotal > 0 Then HTMLCart = HTMLCart & "SubTotal = " & _ FormatDefCurr (PriceT) & "
    " HTMLCart = HTMLCart & "User Discount (" & Session("UserDiscount") & "%) = -" & _ FormatDefCurr (nUrDiscountTotal) & "
    " End If ' If there is a shipping cost then display it If ShipCost > 0 Then HTMLCart = HTMLCart & "Shipping: " & _ FormatDefCurr (ShipCost) & "
    " End If '--------------------------------------------------------------------------------------- ' TAXES 'If there are taxes to apply, calculate taxes and display them. 'IMPORTANT!: It applies taxes to the products cost, not to the shipping cost ' To also apply tax to shipping cost then uncomment lines as explained below. '--------------------------------------------------------------------------------------- 'For taxes outside EU: USA and Canada If TotalTax > 0 AND Tax_Model <> "EU" Then Taxes = AppliedTax 'Use the following calculation instead if you want to apply taxes to shipping cost 'Taxes = AppliedTax + ShipCost * TotalTax 'Apply tax to shipping cost as well HTMLCart = HTMLCart & "Taxes (" & TotalTax*100 & "%): " & _ FormatDefCurr (Taxes) & "
    " 'For European Union taxes: Elseif Tax_Model = "EU" Then Taxes = VATTax 'Note: To add VAT to shipping cost follow this instructions: 'Use the following calculation instead if you want to apply taxes to the shipping cost. 'Replace 0.16 with the tax rate needed 16% = 16/100 = 0.16 'VAT will only be applied if not VAT number has been specified. 'Uncomment the following 3 lines to apply VAT to shipping cost. 'If Trim(Request.Form("TaxId")) <> "" Then ' Taxes = VATTax + ShipCost * 0.16 'End If HTMLCart = HTMLCart & "VAT: " & _ FormatDefCurr (Taxes) & "
    " End If If Request.Form("TaxId") <> "" Then If Tax_Model = "EU" Then HTMLCart = HTMLCart & "VAT Number: " & Request.Form("TaxId") & "
    " ElseIf Tax_Model = "CAN" Then HTMLCart = HTMLCart & "PST Number: " & Request.Form("TaxId") & "
    " Else HTMLCart = HTMLCart & "Tax Id: " & Request.Form("TaxId") & "
    " End If End If 'Calculate total cost including products cost, shipping and taxes. PriceTG = PriceT + ShipCost + Taxes - nUrDiscountTotal HTMLCart = HTMLCart & "Total = " & _ FormatDefCurr (PriceTG) & "
    " If shop_SecCurName <> "" Then HTMLCart = HTMLCart & FormatSecCurr (PriceTG) & "
    " End If HTMLCart = HTMLCart & "
    " 'Clean up recordset Cart.Close set cart = nothing GetHTMLCart = HTMLCart End Function '================================================================ ' GetTextCart ' Returns the shopping cart into a variable in plat text format ' Used during checkout for text mail confirmations. ' USES INPUT: ' CartID: Cart ID ' ShipCost: Shipping cost ' TotalTax: Tax percentage to apply ' bTaxExempt: Tax Exempt (for VAT calculations) ' From GetHTMLCart: ' PriceT: Sub-total price ' WeightT: Total weight ' TotalTG: Total cost including delivery and taxes ' Taxes: Total tax amount ' nItems: Total numbers of items in the cart ' nUrDiscountTotal: Total user discount (not rate) '================================================================ Function GetTextCart '(nCartID, nPriceT, nWeightT, nShipCost, nTotalTax) Dim pricelin 'Price of the current line Dim TextCart 'Cart in HTML format Dim VATTax, AppliedTax 'Taxes Dim nUserDiscount 'User Discount Dim nProductWidth Dim nPriceWidth Dim nQttyWidth Dim nTotalWidth Dim nSepWidth Dim sProdNameString Dim sOptionsString nProductWidth = 43 nPriceWidth = 9 nQttyWidth = 4 nTotalWidth = 9 nSepWidth = 1 If (Session("UserDiscount") <> "") AND IsNumeric(Session("UserDiscount")) Then nUserDiscount = CDbl(Session("UserDiscount")) Else nUserDiscount = 0 End If 'Obtain cart data Set Cart = Server.CreateObject("ADODB.Recordset") 'sql= "SELECT * FROM Carts WHERE CartID = '" & CartID & "'" sql = "SELECT Products.Name, Products.VATRate, Products.Taxable, carts.*, PriceOptions.Description from Products INNER JOIN (carts LEFT JOIN Priceoptions ON carts.Priceoption = PriceOptions.Id) ON Products.ProdId = Carts.ProdId where cartid = '" & CartID & "'" Cart.Open sql,Conn, adOpenForwardOnly, adLockReadOnly TextCart = PadString("Product", txtLeft, nProductWidth) & String(nSepWidth, " ") & _ PadString("Price", txtRight, nPriceWidth) & String(nSepWidth, " ") & _ PadString("Qtty", txtRight, nQttyWidth) & String(nSepWidth, " ") & _ PadString("Total", txtRight, nTotalWidth) & vbCrLf TextCart = TextCart & String(nProductWidth + nPriceWidth + nQttyWidth + nTotalWidth + 3*nSepWidth, "-") & vbCrLf 'Initialise values: nItems = 0 VATTax = 0 Do while NOT cart.EOF 'Cost of the line = Price * Quantity pricelin = CDbl(cart("Price")) * int(cart("Qtty")) 'Numbers of items so far nItems = nItems + int(cart("Qtty")) 'If EU (VAT) calculate the tax. 'Only calculate if is not TAX exempt: ' - Customer has a VAT number ' - Customers outside the European Union If Tax_Model = "EU" AND NOT bTaxExempt Then VATTax = VATTax + pricelin * (1 - nUserDiscount/100) * (CDbl(cart("VATrate")) / 100) 'HTMLCart = HTMLCart & AppliedTax & "(" & pricelin * (1 - nUserDiscount/100) * (CDbl(cart("VATrate")) / 100) & ") " 'If USA or Canada model then apply tax to non-exempt products (labour or services...) ElseIf Tax_Model = "CAN" OR Tax_Model = "USA" Then AppliedTax = AppliedTax + pricelin * (1 - nUserDiscount/100) * TotalTax * cart("Taxable") 'HTMLCart = HTMLCart & AppliedTax & " (" & pricelin * (1 - nUserDiscount/100) * TotalTax * cart("Taxable") & ") - " End If 'Display product Name TextCart = TextCart & PadString(prodname(cart("prodid")), txtLeft, nProductWidth) TextCart = TextCart & String(nSepWidth, " ") & PadString(FormatNumber(cart("Price"),2), txtRight, nPriceWidth) & _ String(nSepWidth, " ") & PadString(CStr(Cart("Qtty")), txtRight, nQttyWidth) TextCart = TextCart & String(nSepWidth, " ") & PadString(FormatNumber(pricelin,2), txtRight, nTotalWidth) & vbCrLf 'Display options (if any) If cart("Option1") <> "" OR cart("Option2") <> "" Then TextCart = TextCart & " " & cart("Option1") & " " & cart("Option2") If cart("Description") <> "" Then TextCart = TextCart & vbCrLf & " Option: " & cart("Description") TextCart = TextCart & vbCrLf Else If cart("Description") <> "" Then TextCart = TextCart & " Option: " & cart("Description") & vbCrLf End If End If 'Calculate total price in PriceT 'PriceT = PriceT + pricelin 'Calculate total weight in WeightT 'WeightT = WeightT + CDbl(cart("Weight")*cart("Qtty")) 'Move to next item in cart cart.movenext Loop 'Calculate total discount nUrDiscountTotal = PriceT * nUserDiscount / 100 TextCart = TextCart & String(nProductWidth + nPriceWidth + nQttyWidth + nTotalWidth + 3*nSepWidth, "-") & vbCrLf If nUrDiscountTotal > 0 Then TextCart = TextCart & PadString("SubTotal = ", txtLeft, nProductWidth + nPriceWidth + 2*nSepWidth) & _ PadString(FormatDefCurr(PriceT), txtRight, nQttyWidth + nTotalWidth + nSepWidth) & vbCrLf 'TextCart = TextCart & "User Discount (" & Session("UserDiscount") & "%) = -" & FormatDefCurr (nUrDiscountTotal) & vbCrLf TextCart = TextCart & _ PadString("User Discount (" & Session("UserDiscount") & "%)", txtLeft, nProductWidth + nPriceWidth + 2*nSepWidth) & _ PadString("- " & FormatDefCurr (nUrDiscountTotal), txtRight, nQttyWidth + nTotalWidth + nSepWidth) & vbCrLf End If ' If there is a shipping cost then display it If ShipCost > 0 Then TextCart = TextCart & "Shipping: " & FormatDefCurr (ShipCost) & vbCrLf End If '--------------------------------------------------------------------------------------- ' TAXES 'If there are taxes to apply, calculate taxes and display them. 'IMPORTANT!: It applies taxes to the products cost, not to the shipping cost ' To also apply tax to shipping cost then uncomment lines as explained below. '--------------------------------------------------------------------------------------- 'For taxes outside EU: USA and Canada If TotalTax > 0 AND Tax_Model <> "EU" Then Taxes = AppliedTax 'Use the following calculation instead if you want to apply taxes to shipping cost Taxes = AppliedTax + ShipCost * TotalTax 'Apply tax to shipping cost as well TextCart = TextCart & PadString("Taxes (" & TotalTax*100 & "%):", txtLeft, nProductWidth + nPriceWidth + 2*nSepWidth) & _ PadString(FormatDefCurr(Taxes), txtRight, nQttyWidth + nTotalWidth + nSepWidth) & vbCrLf 'For European Union taxes: Elseif Tax_Model = "EU" Then Taxes = VATTax 'Note: To add VAT to shipping cost follow this instructions: 'Use the following calculation instead if you want to apply taxes to the shipping cost. 'Replace 0.16 with the tax rate needed 16% = 16/100 = 0.16 'VAT will only be applied if not VAT number has been specified. 'Uncomment the following 3 lines to apply VAT to shipping cost. 'If Trim(Request.Form("TaxId")) <> "" Then ' Taxes = VATTax + ShipCost * 0.16 'End If TextCart = TextCart & PadString("VAT:", txtLeft, nProductWidth + nPriceWidth + 2*nSepWidth) & _ PadString(FormatDefCurr(Taxes), txtRight, nQttyWidth + nTotalWidth + nSepWidth) & vbCrLf End If If Request.Form("TaxId") <> "" Then If Tax_Model = "EU" Then TextCart = TextCart & "VAT Number: " & Request.Form("TaxId") & vbCrLf ElseIf Tax_Model = "CAN" Then TextCart = TextCart & "PST Number: " & Request.Form("TaxId") & vbCrLf Else TextCart = TextCart & "Tax Id: " & Request.Form("TaxId") & vbCrLf End If End If 'Calculate total cost including products cost, shipping and taxes. 'PriceTG = PriceT + ShipCost + Taxes - nUrDiscountTotal TextCart = TextCart & PadString("Total =", txtLeft, nProductWidth + nPriceWidth + 2*nSepWidth) & _ PadString(FormatDefCurr(PriceTG), txtRight, nQttyWidth + nTotalWidth + nSepWidth) & vbCrLf If shop_SecCurName <> "" Then TextCart = TextCart & _ PadString("(" & FormatSecCurr(PriceTG) & ")", txtRight, nProductWidth + nPriceWidth + nQttyWidth + nTotalWidth + 3*nSepWidth) & vbCrLf End If 'Clean up recordset Cart.Close set cart = nothing GetTextCart = TextCart End Function %> <% Dim strStockMsg 'Message regarding stock Dim nCartQtty 'Quantity already in cart '================================================================ ' getPrice(PID, POID, Qtty, CartQtty) ' Gets the price of a product with ProductID = PID ' Output: ' Returns Offer price if it exists, otherwise returns normal price ' If the product is not found or there is not enough stock it returns -1 ' Input: ' PID: Product ID ' POID: Price Option ID ' Qtty: Quantity ' CartQtty: Quantity already in cart '================================================================ Function getPrice(PID, POID, Qtty, CartQtty, nVATRate, nTaxable) Dim adoRs, optSQL, nStock POID = ParseInj(POID) PID = ParseInj(PID) set adoRs = Server.CreateObject("ADODB.Recordset") If POID <> "" Then optSQL = "SELECT Price, Offer, Cost, DifOrAbs, Stock, VATRate, Taxable FROM Products LEFT JOIN PriceOptions ON Products.ProdId = PriceOptions.ProdId WHERE Products.ProdID = '" & PID & "' AND PriceOptions.Id = " & POID else optSQL = "SELECT Price, Offer, Stock, VATRate, Taxable FROM Products WHERE ProdID = '" & PID & "'" End If set adoRs = conn.Execute(optSQL) If adoRs.EOF AND adoRs.BOF Then getPrice = "-1" else 'Check stock only if stock control is on 'Check that the quantity added is lower or equal than in stock and 'that the new added quantity plus the already in stock are lower or equal than in stock. nStock = CInt(adoRs("Stock")) 'Get tax details to return back nVATRate = adoRS("VATRate") nTaxable = adoRS("Taxable") If shop_StockControl AND (nStock < Qtty OR nStock < (CartQtty + Qtty) )Then 'If there is no sotck, return -1: This will prevent the product from being 'added to the cart. strStockMsg = "Sorry, you have requested a quantity higher than we currently have in stock." GetPrice = -1 set adoRs = nothing Exit Function End If If POID <> "" Then 'Handle price options If adoRs("DifOrAbs") = 0 Then 'Relative price / price difference If adoRs("Offer") <> "" Then 'Total = Offer price + Option price GetPrice = adoRs("Offer") + adoRs("Cost") else 'Total = Normal Price + Option Price GetPrice = adoRs("Price") + adoRs("Cost") End If elseif adoRs("DifOrAbs") = 1 Then 'Total Price GetPrice = adoRs("Cost") else 'Error getPrice = "-1" End If else 'No price options If adoRs("Offer") <> "" Then GetPrice = adoRs("Offer") else GetPrice = adoRs("Price") End If End If End If set adoRs = nothing 'Response.Write "Price: " & GetPrice & "

    " End Function Sub WriteCartRelProds (CID) '---------------------------------------------------------- ' Writes a list of all the products related to the one ' shown (Cross-sell) '---------------------------------------------------------- Dim strSQL, RPRs CID = ParseInj(CID) strSQL = "SELECT DISTINCT Products.ProdId, Products.Name FROM Products, RelatedProds WHERE Products.ProdId = RelatedProds.RelProdId " & _ "AND RelatedProds.ProdID IN (SELECT ProdId FROM Carts WHERE CartID = '" & CID & "') " & _ "AND RelatedProds.Type = 1" set RPRs = conn.Execute (strSQL) If NOT (RPRs.EOF AND RPRs.BOF) Then %> Based in your cart we also suggest the following products:

    ") RPRs.Close set RPRs = nothing End Sub '================================================================ ' getProductTaxInfo (sProdID, ByRef nVATRate, ByRef nTaxable) ' Desc: Retrieves the VAT rate and taxable information for a product ' Input: ' - sProdID: Product ID ' Output: ' - nVATRate: VAT Rate ' - nTaxable: Taxable product information (0 or 1) '================================================================ Sub getProductTaxInfo (sProdID, nVATRate, nTaxable) If sProdID <> "" Then Dim rsProd, sSQL set rsProd = Server.CreateObject("ADODB.Recordset") sProdID = ParseInj(sProdID) sSQL = "SELECT VATRate, Taxable FROM Products WHERE ProdID = '" & sProdID & "'" rsProd.Open sSQL, conn, adOpenForwardOnly, adLockReadOnly If rsProd.EOF AND rsProd.BOF Then 'Not found nVATRate = 0 nTaxable = 0 Else 'Found nVATRate = rsProd(0) nTaxable = rsProd(1) rsProd.Close End If set rsProd = nothing Else nVATRate = 0 nTaxable = 0 End If End Sub Dim IsNew Dim Qtty, prevQtty Dim strMsg Dim thisPrice, nVATRate, nTaxable 'Build query string for navigation (category and path) If Request("cat") <> "" Then strNav = "cat=" & Request("cat") & "&path=" & Request("path") '------------------------------------------ ' If the user doesn't have a cart id then ' create a new one '------------------------------------------ If NOT Session("CartID") <> "" Then ' Create new CartID Randomize Session("CartID") = chr (int( 20 * Rnd +65 )) & int ( 9999 * Rnd + 1) & chr (int( 20 * Rnd +65 )) & chr (int( 20 * Rnd +65 )) & chr (int( 20 * Rnd +65 )) & chr (int( 20 * Rnd +65 )) & chr (int( 20 * Rnd +65 )) End If 'Store value in a variable for better performance CartID = Session("CartID") '------------------------------------------ ' Add a list of items to the cart from '------------------------------------------ If Request.Form("addlist.x") <> "" Then IsNew = False 'Loop trough the list of items in the form submitted For i = 1 to int(Request.Form ("listitems")) 'Check that the quantity is numeric If IsNumeric (Request.Form("Qtty" & i)) Then Qtty = CInt(Request.Form("Qtty" & i)) 'If the quantity is less than 1 set to 0 and if is negative also display error message If Qtty < 0 Then strMsg = "Sorry, you have specified a quantity lower than 0 in at least one product." Qtty = 0 End If else 'If the quantity has a non numeric value display error message and set the value to 0 Qtty = 0 If Request.Form("Qtty" & i) <> "" Then strMsg = "Sorry, you have specified an invalid quantity in at least one product." End If 'If the value provided is valid and higher than 0 If Qtty > 0 Then Set Cart = Server.CreateObject("ADODB.Recordset") 'Build query to check whether the same product/options is already in the cart strSQL = "select * from Carts WHERE CartID = '" & CartID & "' AND ProdID = '" & ParseInj(Request.Form("Prod" & i)) & "'" If ParseInj(Request.Form("Option1" & i)) <> "" Then strSQL = strSQL & " AND Option1 = '" & ParseInj(Request.Form("Option1" & i)) & "'" If ParseInj(Request.Form("Option2" & i)) <> "" Then strSQL = strSQL & " AND Option2 = '" & ParseInj(Request.Form("Option2" & i)) & "'" If ParseInj(Request.Form("POption" & i)) <> "" Then strSQL = strSQL & " AND PriceOption = " & ParseInj(Request.Form("POption" & i)) 'Response.Write strSQL Cart.Open strSQL ,Conn, adOpenStatic, adLockOptimistic 'If the same product wasn't found in the existing cart then IsNew = True 'If it is then it will add a new line otherwise will increase the quantity. If Cart.EOF AND Cart.BOF Then IsNew = True 'It is a new product nCartQtty = 0 Else nCartQtty = Cart("Units") 'Get units in Cart End If 'Get the price for this product thisPrice = getPrice (Request.Form ("Prod" & i), Request.Form ("POption" & i), CInt(Trim(Request.Form("Qtty" & i))), nCartQtty, nVATRate, nTaxable) 'If the product is not already in the cart then add it. If IsNew Then 'If it cannot't find the price ignore line (prodid not valid or not in stock!) If thisPrice <> "-1" Then Cart.AddNew Cart("ProdID") = Request.Form ("Prod" & i) Cart("Qtty") = Qtty Cart("Date") = Now Cart("CartID") = CartID Cart("Price") = CDbl (thisPrice) Cart("Units") = int (Request.Form ("Units" & i)) Cart("CatID") = int (Request.Form ("CatID" & i)) If Request.Form ("Option1" & i) <> "" Then Cart("Option1") = Request.Form ("Option1" & i) End If If Request.Form ("Option2" & i) <> "" Then Cart("Option2") = Request.Form ("Option2" & i) End If If Request.Form ("POption" & i) <> "" Then Cart("PriceOption") = Request.Form ("POption" & i) End If If Request.Form("Weight" & i) <> "" Then Cart("Weight") = CDbl(Request.Form("Weight" & i)) else Cart("Weight") = 0 End If Cart("UserID") = Session("UserID") prevQtty = 0 End If 'End thisPrice <> "-1" elseif thisPrice <> "-1" Then 'Update existing line if ProdId is valid and is in stock prevQtty = Cart("Qtty") Cart("Qtty") = prevQtty + Qtty End If 'Update recordset If NOT (Cart.BOF and Cart.EOF) Then Cart.Update 'If "Add to My list" is checked add to the user's personal list If Request.Form ("Habitual" & i) <> "" then Dim sMyListSQL sMyListSQL = "INSERT INTO CommonList (UserID, ProdID, CatID, DateAdded) " & _ "VALUES ('" & Session("UserID") & "', '" & ParseInj(Request.Form("Prod" & i)) & "', " & ParseInj(Request.Form("CatID" & i)) & ", " & GetDBCurrentDateTime & ")" conn.Execute sMyListSQL End If 'Update the Total in the Session object (To be displayed in all pages) If Session("Total") <> "" Then If Tax_ShowVAT = 1 AND Tax_Model = "EU" AND nTaxable = 1 Then Session("Total") = CStr(CDbl(Session("Total")) + thisPrice * CInt(Request.Form("Qtty"&i)) * (1 + nVATRate/100.0)) Else Session("Total") = CStr(CDbl(Session("Total")) + thisPrice * CInt(Request.Form("Qtty"&i))) End If Else If Tax_ShowVAT = 1 AND Tax_Model = "EU" AND nTaxable = 1 Then Session("Total") = CStr(CDbl(thisPrice) * CInt(Request.Form("Qtty"&i)) * (1 + nVATRate/100.0)) Else Session("Total") = CStr(CDbl(thisPrice) * CInt(Request.Form("Qtty"&i))) End If End If 'Clean up recordset Cart.Close set Cart = nothing End If Next End If '------------------------------------------ ' Modify one cart line. '------------------------------------------ If Request.Form("Modline") <> "" Then ' Modify line Set MCart = Server.CreateObject("ADODB.Recordset") sql= "SELECT * FROM Carts WHERE ID = " & ParseInj(Request.Form("ID")) MCart.Open sql,Conn, adOpenStatic, adLockOptimistic If NOT (MCart.BOF AND MCart.EOF) Then Call getProductTaxInfo (MCart("ProdID"), nVATRate, nTaxable) End If If Request.Form("Qtty") = "0" OR Request.Form("Qtty") = "" Then If Session("Total") <> "" Then If Tax_ShowVAT = 1 AND Tax_Model = "EU" AND nTaxable = 1 Then 'When showing VAT: Session("Total") = Cstr(CDbl(Session("Total")) - MCart("Price")*(1 + nVATRate/100.0)* MCart("Qtty")) Else Session("Total") = Cstr(CDbl(Session("Total"))-MCart("Price")*MCart("Qtty")) End If End If MCart.delete MCart.Update MCart.Close ElseIf shop_StockControl AND CInt(Request.Form("Stock")) < CInt(Trim(Request.Form("Qtty"))) Then strStockMsg = "Sorry, you have requested a quantity higher than we currently have in stock." MCart.Close Else If Request.Form("Qtty") <> "" AND IsNumeric (Request.Form("Qtty")) Then If CInt(Request.Form("Qtty")) >= 0 Then If Session("Total") <> "" Then If Tax_ShowVAT = 1 AND Tax_Model = "EU" AND nTaxable = 1 Then 'When showing VAT: Session("Total") = Cstr(CDbl(Session("Total"))-MCart("Price")*MCart("Qtty")*(1 + nVATRate/100.0) + MCart("Price")*(1 + nVATRate/100.0)*int (Request.Form("Qtty"))) Else Session("Total") = Cstr(CDbl(Session("Total"))-MCart("Price")*MCart("Qtty") + MCart("Price")*int (Request.Form("Qtty"))) End If End If MCart("Qtty") = int (Request.Form("Qtty")) MCart.Update MCart.Close End If End If End If set MCart = nothing End If '------------------------------------------ ' Remove one item in cart '------------------------------------------ If Request("remove") <> "" Then Set MCart = Server.CreateObject("ADODB.Recordset") sql= "SELECT ProdID, Price, Qtty FROM Carts WHERE ID = " & ParseInj(Request("remove")) MCart.Open sql,Conn, adOpenStatic, adLockOptimistic If NOT (MCart.EOF AND MCart.BOF) Then Call getProductTaxInfo (MCart("ProdID"), nVATRate, nTaxable) If Session("Total") <> "" Then If Tax_ShowVAT = 1 AND Tax_Model = "EU" AND nTaxable = 1 Then 'When showing VAT: Session("Total") = Cstr(CDbl(Session("Total")) - MCart("Price")*(1 + nVATRate/100.0) * MCart("Qtty")) Else Session("Total") = Cstr(CDbl(Session("Total"))-MCart("Price")*MCart("Qtty")) End If End If MCart.delete MCart.Update End If MCart.Close set MCart = nothing End If '------------------------------------------ ' Remove all items in cart '------------------------------------------ If Request("ClearCart") = "Yes" Then sql= "DELETE FROM Carts WHERE CartID = '" & CartID & "'" Conn.Execute(sql) Session("Total") = "0.00" End If %> <%= shop_Title %> <% '====================================================================================== ' File: head.inc ' Description: This file produces the HTML for the definition of the top of all the ' shop pages. It also includes a call to the include file that creates ' the left hand side navigation bar leftinc.asp and until the creation of ' the cell that contains the main body of the pages. '====================================================================================== ' Initialise cat variable with the contents of Request("cat"). This holds current ' category/section Dim strNav If Request("cat") <> "" Then strNav = "cat=" & Request("cat") & "&path=" & Request("path") %>
     

    <%= LogoURL %>
    Shopping Cart

    <% 'If a quantity requested is not available in stock then display message generated in GetPrice If strStockMsg <> "" Then Response.Write "

    " & strStockMsg & "

    " 'Display Cart (function in inc/carts.asp) ShowCart CartID, strMsg %>

    <% 'Display related products for all products in cart WriteCartRelProds (CartID) %>

    Star Quest Publishing © 2003-2007       www.StarQuestPublishing.com       Email: info@StarQuestPublishing.com      
    <% 'Close and destroy connection Call CloseCnx(conn) %>