ted
if Request.QueryString("resetCookie") = "1" then
	Response.Cookies("CustSearch").expires = Date() - 30
else
	'Check if a Cookie Recall was requested
	if Request.QueryString("recallCookie") = "1" then
		for each item in Request.Cookies
			if item = "CustSearch" then
				showArr		= Split(Request.Cookies(item),"*|*")
				curPage		= showArr(0)
				showStatus	= showArr(1)
				showField	= showArr(2)
				showPhrase	= showArr(3)
				showAff		= showArr(4)
				showWholesale= showArr(5)
			end if
		next
	else
		'Save Search Criteria in a Cookie
		Response.Cookies("CustSearch") = navCookie(curPage)
		Response.Cookies("CustSearch").expires = Date() + 30
	end if
end if

'After attempting to retrieve the search criteria through the various 
'mechanisms above (Form/QueryString/Cookie), check that some of the 
'critical values are valid. If not, set to default values.
if len(curPage) = 0 or not isNumeric(curPage) then
	curPage = 1
else
	curPage = CLng(curPage)
end if

'Check what we will be sorting the results on
sortField = Request.Form("sortField")					'Form
if len(sortField) = 0 then
	sortField = Request.QueryString("sortField")		'QueryString
end if
if len(sortField) = 0 then
	sortField = "lastName"
end if

%>

<!--#include file="_INCheader_.asp"-->

<P align=left>
	<b><font size=3>Customer Maintenance</font></b>
	<br><br>
</P>

<%
if len(trim(Request.QueryString("msg"))) > 0 then
%>
	<font color=red><%=Request.QueryString("msg")%></font>
	<br><br>
<%
end if
%>

<table border=0 cellspacing=0 cellpadding=5 width="100%" class="findTable">
	<tr>
	
		<form method="post" action="SA_cust.asp" name="form2">
		<td align=right valign=top nowrap>
			Show Customers where&nbsp;
			<select name=showField id=showField size=1>
				<option value="">-- Select --</option>
				<option value="name"            <%=checkMatch(showField,"name")           %>>First Name</option>
				<option value="lastName"        <%=checkMatch(showField,"lastName")       %>>Last Name</option>
				<option value="customerCompany" <%=checkMatch(showField,"customerCompany")%>>Company</option>
				<option value="email"           <%=checkMatch(showField,"email")          %>>Email</option>
				<option value="address"         <%=checkMatch(showField,"address")        %>>Address</option>
			</select>&nbsp;
			contains the phrase&nbsp;
			<input type=text name=showPhrase id=showPhrase size=20 maxlength=50 value="<%=showPhrase%>">&nbsp;
			<input type=submit name=submit1 id=submit1 value="Find">
		</td>
		</form>
		
	</tr>
	
	<tr>
	
		<form method="post" action="SA_cust.asp" name="form4">
		<td align=right valign=top nowrap>
		<select name=showWholesale id=showWholesale size=1>
<option value="">N/A</option>
<option value="T" <%=checkMatch(showWholesale,"T")%>>Wholesale</option>

</select>&nbsp;
		
			<select name=showStatus id=showStatus size=1>
				<option value="">N/A</option>
				<option value="A" <%=checkMatch(showStatus,"A")%>>Active</option>
				<option value="I" <%=checkMatch(showStatus,"I")%>>InActive</option>
			</select>&nbsp;
			<select name=showAff id=showAff size=1>
				<option value="">N/A</option>
				<option value="Y" <%=checkMatch(showAff,"Y")%>>Affiliate</option>
				<option value="N" <%=checkMatch(showAff,"N")%>>Not Affiliate</option>
				<option value="A" <%=checkMatch(showAff,"A")%>>Applied</option>
			</select>&nbsp;
			<input type=submit name=submit1 id=submit1 value="Find">
		</td>
		</form>
		
	</tr>
	
</table>

<br>

<table border=0 cellspacing=0 cellpadding=5 width="100%" class="listTable">
<%
	'Specify fields and table
		mySQL="SELECT idCust,status,dateCreated,name," _
		& " lastName,email,affiliate,wholesale,wholesalelevel " _
		& "FROM customer " _
	    & "WHERE  1=1 " 'Dummy check to set up conditional checks below
	    
	'Status
	if len(showStatus) > 0 then
		mySQL = mySQL & "AND status = '" & showStatus & "' "
	end if
	
	'Wholesale
	if len(showWholesale) > 0 then
	mySQL = mySQL & "AND wholesale = '" & showWholesale & "' "
	end if

	'Affiliate
	if len(showAff) > 0 then
		mySQL = mySQL & "AND affiliate = '" & showAff & "' "
	end if

	'Field and Search Phrase
	if len(showField) > 0 and len(showPhrase) > 0 then
		mySQL = mySQL & "AND " & showField & " LIKE '%" & replace(showPhrase,"'","''") & "%' "
	end if

	'Sort Order
	mySQL = mySQL & "ORDER BY " & sortField
	
	set rs = openRSopen(mySQL,0,adOpenStatic,adLockReadOnly,adCmdText,pageSize)
	if rs.eof then
%>
		<tr>
			<td align=center valign=middle>
				<br>
				<b>No Customers matched search criteria.</b>
				<br><br>
			</td>
		</tr>
<%
	else
		rs.MoveFirst
		rs.PageSize		= pageSize
		totalPages 		= rs.PageCount
		rs.AbsolutePage	= curPage
%>
		<tr>
			<td colspan=5 class="listRowTop">
<%
				call pageNavigation("selectPageTop")
%>
			</td>
			<td colspan=5 align=right class="listRowTop">
				Sort : 
				<select name=sortField id=sortField size=1 onChange="location.href='SA_cust.asp?recallCookie=1&sortField='+this.options[selectedIndex].value">
					<option value="lastName"    <%=checkMatch(sortField,"lastName")   %>>Last Name</option>
					<option value="email"       <%=checkMatch(sortField,"email")      %>>Email Address</option>
					<option value="dateCreated" <%=checkMatch(sortField,"dateCreated")%>>Date Created</option>
				</select>
			</td>
		</tr>
<%
		rowColor = col1
%>
		<tr>
			<td class="listRowHead"><b>ID</b></td>
			<td class="listRowHead"><b>Name</b></td>
			<td class="listRowHead"><b>EMail</b></td>
			<td class="listRowHead"><b>Created</b></td>
			<td class="listRowHead"><b>Status</b></td>
			<td class="listRowHead"><b>Wholesale(L)</b></td>
			<td class="listRowHead"><b>Affiliate</b></td>
			<td class="listRowHead"><b>Orders</b></td>
			<td class="listRowHead"><b>&nbsp;</b></td>
		</tr>
<%
		rowColor = col2
		do while not rs.eof and count < rs.pageSize
%>
			<tr>
				<td bgcolor="<%=rowColor%>" valign=top nowrap><%=rs("idCust")%></td>
				<td bgcolor="<%=rowColor%>" valign=top nowrap>
					<%=rs("lastName") & ", " & rs("name")%>
				</td>
				<td bgcolor="<%=rowColor%>" valign=top nowrap><%=rs("email")%></td>
				<td bgcolor="<%=rowColor%>" valign=top nowrap><%=formatTheDate(rs("dateCreated"))%></td>
				<td bgcolor="<%=rowColor%>" valign=top nowrap><%=rs("status")%></td>
				<td bgcolor="<%=rowColor%>" valign=top nowrap><%call SA_CustTranslate(rs("wholesale"))%>&nbsp;
				<%if rs("wholesale")="T" then%>
				(<%=rs("wholesalelevel")%>)
				<%end if%>
				</td>
				<td bgcolor="<%=rowColor%>" valign=top nowrap><%=rs("affiliate")%></td>
<%				
		'Get number of Orders for this Customer
		mySQL = "SELECT COUNT(*) AS orderCount " _
			  & "FROM   cartHead " _
			  & "WHERE  idCust=" & rs("idCust") & " "
		set rsTemp = openRSexecute(mySQL)
		orderCount = rsTemp("orderCount")
		call closeRS(rsTemp)
%>
				<td bgcolor="<%=rowColor%>" aling=right valign=top nowrap><%=orderCount%></td>
				<td bgcolor="<%=rowColor%>" align=right valign=top nowrap>
					[ 
					<a href="SA_cust_edit.asp?action=edit&recid=<%=rs("idCust")%>">edit</a> | 
					<a href="SA_cust_edit.asp?action=del&recid=<%=rs("idCust")%>" onclick="return confirm('Are you sure you want to delete?')">delete</a> 
					]
				</td>
			</tr>
<%
			count = count + 1  
			rs.movenext
			
			'Switch Row Color
			if rowColor = col2 then
				rowColor = col1
			else
				rowColor = col2
			end if

		loop
%>
		<tr>
			<td nowrap colspan=9 class="listRowBot">
<%
				call pageNavigation("selectPageBot")
%>
			</td>
		</tr>
<%
	end if
	call closeRS(rs)
%>
</table>

<br>

<span class="textBlockHead">Help and Instructions :</span><br>
<table border=0 cellspacing=0 cellpadding=5 width="100%" class="textBlock">
<tr><td>

	<b>Find Customer(s)</b> - Customers are displayed in Last Name, First Name 
	sequence.<br><br>
	
	1. You can list all Customers which contain a specific phrase in one 
	of several fields.<br><br>
	
	2. You can list Customers based on general Status or Affilate status.<br><br>
	
	<b>Edit Customer</b> - Click to view or change Customer 
	information, order history, affiliate sales, etc.<br><br>
	
	<b>Delete Customer</b> - Click to delete a Customer from the Database. 
	Please note that a Customer record can NOT be deleted if there are 
	Orders linked to it. You will have to delete the Orders linked to the 
	Customer first, then return and delete the Customer. Or you could 
	simply InActivate the Customer.<br><br>
	
	<b>Status</b> - A=Active, I=InActive<br><br>

	<b>Affiliate</b> - Y=Affiliate, N=Not Affiliate, A=Applied<br><br>
	<b>Wholesale(L)</b> - Y=Wholesale Account, N=Not Wholesale Account, L=Wholesale Level<br><br>
	
</td></tr>
</table>

<%
call closeDB()

%><!--#include file="_INCfooter_.asp"--><%
'*********************************************************************
'Make QueryString for Paging
'*********************************************************************
function navQueryStr(pageNum)

	navQueryStr = "?curPage="		& server.URLEncode(pageNum) _
	            & "&showStatus="	& server.URLEncode(showStatus) _
	            & "&showAff="		& server.URLEncode(showAff) _
	            & "&showField="	 & server.URLEncode(showField) _
				& "&showPhrase="	& server.URLEncode(showPhrase) _
				& "&showWholesale="	& server.URLEncode(showWholesale)
end function
'*********************************************************************
'Make Cookie Value for Paging
'*********************************************************************
function navCookie(pageNum)

	navCookie = pageNum		& "*|*" _
	          & showStatus	& "*|*" _
	          & showField	& "*|*" _
			  & showPhrase	& "*|*" _
			  & showAff	 & "*|*" _
			  & showWholesale
end function
'*********************************************************************
'Display page navigation
'*********************************************************************
sub pageNavigation(formFieldName)
	Response.Write "Page "
	Response.Write "<select onChange=""location.href=this.options[selectedIndex].value"" name=" & trim(formFieldName) & ">"
	for I = 1 to TotalPages
		Response.Write "<option value=""SA_cust.asp" & navQueryStr(I) & "&sortField=" & server.URLEncode(sortField) & """ " & checkMatch(curPage,I) & ">" & I & "</option>" & vbCrlf
	next
	Response.Write "</select>&nbsp;of&nbsp;" & TotalPages & "&nbsp;&nbsp;"
	Response.Write "[&nbsp;"
	if curPage > 1 then
		Response.Write "<a href=""SA_cust.asp" & navQueryStr(curPage-1) & "&sortField=" & server.URLEncode(sortField) & """>Back</a>"
	else
		Response.Write "Back"
	end if
	Response.Write "&nbsp;|&nbsp;"
	if curPage < TotalPages then
		Response.Write "<a href=""SA_cust.asp" & navQueryStr(curPage+1) & "&sortField=" & server.URLEncode(sortField) & """>Next</a>"
	else
		Response.Write "Next"
	end if
	Response.Write "&nbsp;]"
end sub
%>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <%@ Language=VBScript %>
<%
'*************************************************************************
' DO NOT MODIFY THIS SCRIPT IF YOU WANT UPDATES TO WORK!
' Function : Customer Maintenance
' Product  : CandyPress Store Administration
' Version  : 4.1

' Modified : May 2007
' Copyright: Copyright (C) 2004 Webs Unlimited, Inc. 
'            See "license.txt" for this product for details regarding 
'            licensing, usage, disclaimers, distribution and general 
'            copyright requirements. If you don't have a copy of this 
'            file, you may request one at http://www.candypress.com
'*************************************************************************
Option explicit
Response.Buffer = true
const adminLevel = 0
%>
<!--#include file="_INCappDBConn_.asp"-->
<!--#include file="../Scripts/_INCconfig_.asp"-->
<!--#include file="_INCsecurity_.asp"-->
<!--#include file="../Scripts/_INCappFunctions_.asp"-->
<!--#include file="_INCadminFunctions_.asp"-->
<!--#include file="../Scripts/_INCrc4_.asp"-->
<!--#include file="../Scripts/CP_Wholesale_Functions.asp"-->
<%

'Database
dim mySQL, rs, rs2

'Customer
dim idCust
dim status
dim dateCreated
dim dateCreatedInt
dim name
dim lastName
dim customerCompany
dim phone
dim email
dim password
dim address
dim city
dim locState
dim locState2
dim locCountry
dim zip
dim paymentType
dim shippingName
dim shippingLastName
dim shippingPhone
dim shippingAddress
dim shippingCity
dim shippingLocState
dim shippingLocState2
dim shippingLocCountry
dim shippingZip
dim futureMail
dim generalComments
dim taxExempt
dim affiliate
dim commPerc
dim addrtype
dim shippingaddrtype
dim heardaboutus

'Work Fields
dim action
dim orderCount
dim affCount
dim errMsg

'added for wholesale
dim Taxid
dim ValidEmail
dim BusinessDescription
dim wholesale
dim BusinessType
dim hiddenstatus
dim WholesaleLevel
dim WholesaleLevelsVal

'*************************************************************************

'Open Database Connection
call openDB()

'Store Configuration
if loadConfig() = false then
	errMsg = "Could not load Store Configuration settings." 
	call closeDB()

	Response.redirect "sysMsg.asp?errMsg=" & server.URLEncode(errMsg)		
end if

%>

<!--#include file="_INCheader_.asp"-->

<P align=left>
	<b><font size=3>Customer Maintenance</font></b>
	<br><br>
</P>

<SCRIPT language="JavaScript">
<!--
	/* Show Affiliate Report */
	function showAffRep(idAffiliate,dateFrom,dateTo) 
	{
		location.href="SA_aff.asp?idAffiliate="+idAffiliate+"&dateFrom="+dateFrom+"&dateTo="+dateTo;
	}
	
	/* Disable Enter Key on a field */
	function disableEnter() 
	{
		if (event.keyCode == 13) return false;
	}

//-->
</SCRIPT>

<%
'Get action
action = trim(Request.QueryString("action"))
if len(action) = 0 then
	action = trim(Request.Form("action"))
end if
action = lCase(action)
if action <> "edit" and action <> "del" then
	errMsg = "Invalid Action Indicator."
	call closeDB()

	Response.redirect "sysMsg.asp?errMsg=" & server.URLEncode(errMsg)
end if

'Get idCust
idCust = trim(Request.QueryString("recId"))
if len(idCust) = 0 then
	idCust = trim(Request.Form("recId"))
end if
if idCust = "" or not isNumeric(idCust) then
	errMsg = "Invalid Record ID."
	call closeDB()

	Response.redirect "sysMsg.asp?errMsg=" & server.URLEncode(errMsg)
end if

'Get customer record
mySQL	= "SELECT status,dateCreated,password,name,lastName," _
		& " customerCompany,phone,email,address,city," _
		& " locState,locState2,locCountry,zip,shippingName," _
		& " shippingLastName,shippingPhone,shippingAddress,"_
		& " shippingCity,shippingLocState,shippingLocState2," _
		& " shippingLocCountry,shippingZip,paymentType," _
		& " futureMail,taxExempt,affiliate,commPerc," _
		& " generalComments,addrtype,shippingaddrtype,heardaboutus," _
		& "	 Wholesale,BusinessType,WholesaleLevel," _
		& " Taxid,ValidEmail,BusinessDescription " _
		& "FROM customer " _
		& "WHERE idCust=" & idCust
set rs = openRSexecute(mySQL)
if rs.eof then
	errMsg = "Invalid Record ID."
	call closeDB()

	Response.redirect "sysMsg.asp?errMsg=" & server.URLEncode(errMsg)
else
	generalComments		= trim(rs("generalComments"))
	status				= trim(rs("status"))
	dateCreated			= rs("dateCreated")
	password			= trim(EnDeCrypt(Hex2Ascii(rs("password")),rc4Key))
	Name				= trim(rs("name"))
	LastName			= trim(rs("LastName"))
	CustomerCompany		= trim(rs("CustomerCompany"))
	Phone				= trim(rs("Phone"))
	Email				= trim(rs("Email"))
	Address				= trim(rs("Address"))
	City				= trim(rs("City"))
	locState			= trim(rs("locState"))
	locState2			= trim(rs("locState2"))
	locCountry			= trim(rs("locCountry"))
	Zip					= trim(rs("Zip"))
	shippingName		= trim(rs("shippingName"))
	shippingLastName	= trim(rs("shippingLastName"))
	shippingPhone		= trim(rs("shippingPhone"))
	shippingAddress		= trim(rs("shippingAddress"))
	ShippingCity		= trim(rs("ShippingCity"))
	shippingLocState	= trim(rs("shippingLocState"))
	shippingLocState2	= trim(rs("shippingLocState2"))
	shippingLocCountry	= trim(rs("shippingLocCountry"))
	shippingZip			= trim(rs("shippingZip"))
	paymentType			= trim(rs("paymentType"))
	futureMail			= trim(rs("futureMail"))
	taxExempt			= trim(rs("taxExempt"))
	affiliate			= trim(rs("affiliate"))
	commPerc			= trim(rs("commPerc"))
	addrtype			= trim(rs("addrType"))
	shippingaddrtype	= trim(rs("shippingaddrType"))
	heardaboutus		= trim(rs("heardaboutus"))
	WholesaleLevel = trim(rs("WholesaleLevel"))
	Taxid = trim(rs("Taxid"))
	ValidEmail = trim(rs("ValidEmail"))
	BusinessDescription = trim(rs("BusinessDescription"))
	Wholesale = trim(rs("Wholesale"))
	BusinessType = trim(rs("BusinessType"))
end if
call closeRS(rs)

'Get number of Orders for this Customer
mySQL = "SELECT COUNT(*) AS orderCount " _
	  & "FROM   cartHead " _
	  & "WHERE  idCust=" & idCust & " "
set rs = openRSexecute(mySQL)
orderCount = rs("orderCount")
call closeRS(rs)

'Get number of Affiliate Sales for this Customer
mySQL = "SELECT COUNT(*) AS affCount " _
	  & "FROM   cartHead " _
	  & "WHERE  idAffiliate=" & idCust & " "
set rs = openRSexecute(mySQL)
affCount = rs("affCount")
call closeRS(rs)

if len(trim(Request.QueryString("msg"))) > 0 then
%>
	<font color=red><%=Request.QueryString("msg")%></font>
	<br><br>
<%
end if

if action = "del" then
%>
	<span class="textBlockHead">Delete Customer</span>
	&nbsp;<%call maintNavLinks()%><br><br>
	
	<table border=0 cellspacing=0 cellpadding=5 width=400 class="textBlock">
		<tr>
			<td align=left nowrap><b>Name</b></td>
			<td align=left><%=name & " " & lastName%>&nbsp;</td>
		</tr>
		<tr>
			<td align=left nowrap><b>Company</b></td>
			<td align=left><%=customerCompany%>&nbsp;</td>
		</tr>
		<tr>
			<td align=left nowrap><b>Email</b></td>
			<td align=left><%=email%>&nbsp;</td>
		</tr>
		<tr>
			<form method="post" action="SA_cust_exec.asp" name="form4">
			<td colspan=2>
				<input type=hidden name=idCust  id=idCust  value="<%=idCust%>">
				<input type=hidden name=action  id=action  value="del">
				<input type=submit name=submit1 id=submit1 value="Delete Customer">
			</td>
			</form>
		</tr>
	</table>
<%
end if

if action = "edit" then
%>
	<span class="textBlockHead">Edit Customer</span>
	&nbsp;<%call maintNav
</center>

</form>


<%
'Close database
call closeDB()

%><!--#include file="_INCfooter_.asp"--><%
'********************************************************************
'Get Number of Orders
'********************************************************************
function numOrders(intDays,orderStatus)

	dim tempDate
	
	if intDays = 0 then
		tempDate = dateInt(dateAdd("yyyy",-25,now()))
	else
		tempDate = dateInt(dateAdd("d",intDays,now()))
	end if
	
	mySQL = "SELECT COUNT(*) AS numOrders " _
	      & "FROM   cartHead " _
	      & "WHERE  orderDateInt > '" & tempDate & "' "
	      
	if orderStatus <> "" then
		mySQL = mySQL & "AND orderStatus = '" & orderStatus & "' "
	end if
	
	set rs = openRSexecute(mySQL)
	
	numOrders = rs("numOrders")
	
	call closeRS(rs)
	
end function
%>                                                                                                                                                                                                         ﻿<%@ Language=VBScript %>
<%
'********************************************************************
' DO NOT MODIFY THIS SCRIPT IF YOU WANT UPDATES TO WORK!
' Function : Administration Home Page
' Product  : CandyPress Store Frontend
' Version  : 4.1

' Modified : May 2007
' Copyright: Copyright (C) 2004 Webs Unlimited, Inc. 
'            See "license.txt" for this product for details regarding 
'            licensing, usage, disclaimers, distribution and general 
'            copyright requirements. If you don't have a copy of this 
'            file, you may request one at http://www.candypress.com
'********************************************************************
Option explicit
Response.Buffer = true
const adminLevel = 0
%>
<!--#include file="_INCappDBConn_.asp"-->
<!--#include file="../Scripts/_INCconfig_.asp"-->
<!--#include file="_INCsecurity_.asp"-->
<!--#include file="../Scripts/_INCappFunctions_.asp"-->
<!--#include file="_INCadminFunctions_.asp"-->

<%
'Declare variables
dim mySQL, rs

'Work
dim errMsg

'*************************************************************************

'Open Database Connection
call openDB()

'Store Configuration
if loadConfig() = false then
	errMsg = "Could not load Store Configuration settings." 
	call closeDB()

	Response.redirect "sysMsg.asp?errMsg=" & server.URLEncode(errMsg)
end if

%>
<!--#include file="_INCheader_.asp"-->

<P align=left>
	<b><font size=3>Payment Settings</font></b>
	<br><br>
</P>

<form method="post" action="utilities_configexec.asp" name="configMod">
<!-- ************************************************************** -->

<span class="textBlockHead">PayPal Payments</span><br>
<table border=0 cellspacing=0 cellpadding=3 width="100%" class="textBlock">
<%call dispYNConfig("Allow payments via PayPal?","pPayPal",pPayPal)%>
<%call dispYNConfig("Test Mode?","payModePayPal",payModePayPal)%>
<%call dispTextConfig("N","PayPal payments description",30,50,"payMsgPayPal",payMsgPayPal)%>
<%call dispTextConfig("Y","Your PayPal member ID",30,100,"payPalMemberID",payPalMemberID)%>
<tr>
	<td bgcolor="#EEEEEE" width="340">
		Currency to use for PayPal (Subject to availability)
	</td>
	<td bgcolor="#EEEEEE">
		<select name=payPalCurrCode id=payPalCurrCode size=1>
			<option 
