 <cfif mode eq "start">

	<cfif session.UserID NEQ 0>
		
		Welcome to the Payfrit App!<br><br>
		
		Please select a menu item<br>
	
	<cfelse>
	
		Please login or register for an account!<br>
		
	</cfif>
	
<cfelseif mode eq "ack">

	<cfparam name="submode" default="0">
	
	<cfif submode eq "order">

		<cfquery name="ack_order" datasource="#application.datasource#">
			UPDATE 		Orders
			SET 		StatusID = 2
			WHERE		ID = #form.OrderID#
		</cfquery>

		<cfquery name="ack_order_lineitems" datasource="#application.datasource#">
			UPDATE 		OrderLineItems
			SET 		StatusID = 2
			WHERE		OrderID = #form.OrderID#
		</cfquery>

		<cfoutput>	
		<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="kitchen">
		</form>
		</cfoutput>
		
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>

	<cfelse>

		<cfquery name="ack_order_lineitem" datasource="#application.datasource#">
			UPDATE 		OrderLineItems
			SET 		StatusID = 2
			WHERE		ID = #form.OrderLineItemID#
		</cfquery>

		<cfoutput>	
		<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="kitchen">
		</form>
		</cfoutput>
		
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>

	</cfif>
	
<cfelseif mode eq "ready">

	<cfparam name="submode" default="0">
	<cfif submode eq "order">

		<cfquery name="ready_order" datasource="#application.datasource#">
			UPDATE 		Orders
			SET 		StatusID = 3
			WHERE		ID = #form.OrderID#
		</cfquery>

		<cfquery name="ready_order_lineitems" datasource="#application.datasource#">
			UPDATE 		OrderLineItems
			SET 		StatusID = 3
			WHERE		OrderID = #form.OrderID#
		</cfquery>

		<cfoutput>	
		<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="kitchen">
		</form>
		</cfoutput>
		
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>

	<cfelse>

		<cfquery name="ready_order_lineitem" datasource="#application.datasource#">
			UPDATE 		OrderLineItems
			SET 		StatusID = 3
			WHERE		ID = #form.OrderLineItemID#
		</cfquery>

		<cfoutput>	
		<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="kitchen">
		</form>
		</cfoutput>
		
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>

	</cfif>
	
<cfelseif mode eq "kitchen">

	<cfif session.UserID NEQ 0 AND session.BusinessID NEQ 0>
		
		un-ack'd kitchen items:<br>

		<cfquery name="get_orders" datasource="#application.datasource#">
			SELECT	    O.ID
			FROM	    Orders O, Businesses B
			WHERE		O.StatusID = 1
							AND 
						O.BusinessID = B.ID
							AND
						B.ID = #request.BusinessID#
			ORDER BY	O.AddedOn ASC
		</cfquery>

		<cfoutput query="get_orders">

			<div>
				<br><button type="button" class="btn btn-success" data-bs-toggle="collapse" data-bs-target="##myCollapse#get_orders.ID#">Order #get_orders.ID# Detail</button>
						
							<script language="JavaScript">
								function submitformreadyorder#get_orders.ID#()
								{
								document.myformreadyorder#get_orders.ID#.submit();
								}
							</script>
							
							<form action="#request.cgiPath#" method="post" name="myformreadyorder#get_orders.ID#" id="myformreadyorder#get_orders.ID#" style="display:inline;">
								
								<a href="javascript: submitformreadyorder#get_orders.ID#()">ack order</a>
								
								<input type="hidden" name="mode" value="ack">
								<input type="hidden" name="submode" value="order">
								<input type="hidden" name="OrderID" value="#get_orders.ID#">
							
							</form>

				<cfquery name="get_line_items" datasource="#application.datasource#">
					SELECT	    I.Name, OL.Quantity, OL.Remark, O.AddedOn, OL.ID, O.ID, O.Remarks, C.Name
					FROM	    Orders O, OrderLineItems OL, Items I, Categories C
					WHERE		O.StatusID = 1
									AND 
								OL.ItemID = I.ID
									AND 
								OL.IsDeleted = 0
									AND 
								OL.ParentOrderLineItemID = 0
									AND
								I.CategoryID = C.ID
									AND 
								O.ID = #get_orders.ID#
									AND
								O.ID = OL.OrderID
				</cfquery>

				<div class="collapse" id="myCollapse#get_orders.ID#">

					<div class="card card-body">
					
						<cfloop query="get_line_items">
							
							ORDER ON: #dateformat(get_line_items.AddedOn,"YYYY-MM-DD")# @ #timeformat(get_line_items.AddedOn,"HH:NN:SS")#<br>
							(#get_line_items.Quantity#) #Name# : #get_line_items.Name#<br>
							<cfif get_line_items.Remarks GT "">ORDER NOTES: #get_line_items.Remarks#<br></cfif>
									
							<cfquery name="get_child_line_items" datasource="#application.datasource#">
								SELECT	    I.Name, I.ID, I.Price, I.ParentItemID, O.ParentOrderLineItemID, O.Remark
								FROM	    OrderLineItems O, Items I
								WHERE		OrderID = #get_line_items.OrderID#
												AND 
											O.ItemID = I.ID
												AND 
											ParentOrderLineItemID = #get_line_items.OrderLineItemID#
								ORDER BY 	AddedOn DESC
							</cfquery>
			
							<cfif get_child_line_items.recordcount GT 0>
								<cfloop query="get_child_line_items">
									<cfquery name="get_parent_item_Name" datasource="#application.datasource#">
										SELECT 		Name
										FROM	    Items
										WHERE		ID = #get_child_line_items.ParentItemID#
									</cfquery>
			
									&nbsp;&nbsp;#get_parent_item_Name.Name# : #get_child_line_items.Name#<br>
									<cfif get_line_items.Remark gt "">&nbsp;&nbsp;ITEM NOTES: #get_line_items.Remark#</cfif>
									
								</cfloop>

							</cfif>
							
						</cfloop>
						
					</div>				
			
				</div>

			</div>
			
		</cfoutput><br>
		
		Kitchen items being prepared:<br>

		<cfquery name="get_orders" datasource="#application.datasource#">
			SELECT	    O.ID
			FROM	    Orders O, Businesses B
			WHERE		O.StatusID = 2
							AND 
						O.BusinessID = B.ID
							AND
						B.ID = #request.BusinessID#
			ORDER BY	O.AddedOn ASC
		</cfquery>

		<cfloop query="get_orders">

			<div>
				<br><cfoutput><button type="button" class="btn btn-success" data-bs-toggle="collapse" data-bs-target="##myCollapse#get_orders.ID#">Order #get_orders.ID# Detail</button>
						
							<script language="JavaScript">
								function submitformreadyorder#get_orders.ID#()
								{
								document.myformreadyorder#get_orders.ID#.submit();
								}
							</script>
							
							<form action="#request.cgiPath#" method="post" name="myformreadyorder#get_orders.ID#" id="myformreadyorder#get_orders.ID#" style="display:inline;">
								
								<a href="javascript: submitformreadyorder#get_orders.ID#()">ready order</a>
								
								<input type="hidden" name="mode" value="ready">
								<input type="hidden" name="submode" value="order">
								<input type="hidden" name="OrderID" value="#get_orders.ID#">
							
							</form>

				<cfquery name="get_line_items" datasource="#application.datasource#">
					SELECT	    I.Name, OL.Quantity, O.AddedOn, OL.ID
					FROM	    Orders O, OrderLineItems OL, Items I
					WHERE		O.StatusID = 2
									AND 
								OL.StatusID = 2
									AND 
								OL.ItemID = I.ID
									AND 
								OL.IsDeleted = 0
									AND 
								O.ID = #get_orders.ID#
									AND
								O.ID = OL.OrderID
				</cfquery>

				<div class="collapse" id="myCollapse#get_orders.ID#">

					<div class="card card-body"><cfloop query="get_line_items">(#get_line_items.Quantity#) #get_line_items.Name# #dateformat(get_line_items.AddedOn,"YYYY-MM-DD")# @ #timeformat(get_line_items.AddedOn,"HH:NN:SS")#
						
							<script language="JavaScript">
								function submitformreadyorderlineitem#get_line_items.OrderLineItemID#()
								{
								document.myformreadyorderlineitem#get_line_items.OrderLineItemID#.submit();
								}
							</script>
							
							<form action="#request.cgiPath#" method="post" name="myformreadyorderlineitem#get_line_items.OrderLineItemID#" id="myformreadyorderlineitem#get_line_items.OrderLineItemID#" style="display:inline;">
								
								<a href="javascript: submitformreadyorderlineitem#get_line_items.OrderLineItemID#()">ready item</a>
								
								<input type="hidden" name="mode" value="ready">
								<input type="hidden" name="OrderID" value="#get_orders.ID#">
								<input type="hidden" name="OrderLineItemID" value="#get_line_items.OrderLineItemID#">
							
							</form></cfloop></div></cfoutput>
				
			
				</div>

			</div>
			
		</cfloop>

	<cfelseif session.UserID NEQ 0>

		Please become a business first!<br>
	
	<cfelse>
	
		Please login or register for an account!<br>
		
	</cfif>
	
<cfelseif mode eq "login">

	<cfparam name="form.username" default="">
	<cfparam name="form.password" default="">
	
	<cfset form.username = replace(form.username, " ",  "", "all")>
	<cfset form.username = replace(form.username, "(",  "", "all")>
	<cfset form.username = replace(form.username, ")",  "", "all")>
	<cfset form.username = replace(form.username, "-",  "", "all")>

	<cfquery name="check_user" datasource="#application.datasource#">
			SELECT	    ID, FirstName
			FROM	    Users
			WHERE       ((EmailAddress = '#form.username#') OR (ContactNumber = '#form.username#'))
							AND
						Password = '#hash(form.password)#'
							AND
						IsEmailVerified = 1
							AND 
						IsContactVerified > 0
	</cfquery>

    <cfif check_user.recordcount EQ 1 and request.BusinessID eq 0>
    	
		<!--- Update the session variables and request variables --->
		<cflock timeout="15" throwontimeout="Yes" type="EXCLUSIVE" scope="SESSION">
    	    <cfset session.UserID = #check_user.UserID#>
			<!--- Re-duplicate them  --->
			<cfset request.UserID = Duplicate(session.UserID)>
		</cflock>

		<CFQUERY name="get_businesses" datasource="#application.datasource#">
			SELECT      Name, ID
			FROM        Businesses
							WHERE
						UserID = #request.userid#
		</CFQUERY>

		<cfif get_businesses.recordcount eq 1>
		
			<!--- Lock persistent scopes to avoid conflicts --->
			<cflock scope="session" timeout="15" throwontimeout="yes" type="exclusive">
				<!--- Replacing cookie with session variable --->
				<cfset session.BusinessID = #get_businesses.ID#>
				<!--- Duplicate the session variables in the request scope so you don't have to CFLOCK them every time you use them. --->
				<cfset request.BusinessID = Duplicate(session.BusinessID)>
			</cflock>
		
		</cfif>
		
		<cfoutput>	
		<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="businesses">
		</form>
		</cfoutput>
		
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>
		
	<cfelse>
	
		No user found!<br><br>

		Please login.<br>
		
	</cfif>

<cfelseif mode eq "businesses">

	<cfif request.UserID neq 0>

		<cfparam name="form.business_form_submitted" default="0">
		<cfparam name="messages" default="">
		<cfparam name="form.submode" default="edit">
		
		<cfparam name="form.IsDemo" default="0"><!--- initialize checkboxes if they didn't come through in the form --->
		<cfparam name="form.IsPrivate" default="0">
		<cfparam name="form.IsHiring" default="0">

		<cfif form.submode eq "become"> <!--- become new business --->

			<!--- Lock persistent scopes to avoid conflicts --->
			<cflock scope="session" timeout="15" throwontimeout="yes" type="exclusive">
				<!--- Replacing cookie with session variable --->
				<cfset session.BusinessID = #form.BusinessID#>
				<!--- Duplicate the session variables in the request scope so you don't have to CFLOCK them every time you use them. --->
				<cfset request.BusinessID = Duplicate(session.BusinessID)>
			</cflock>

			<cfoutput>	
			<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
				<input type="hidden" name="mode" value="businesses">
				<input type="hidden" name="submode" value="edit">
			</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>
		
		</cfif>	

		<CFQUERY name="get_businesses" datasource="#application.datasource#">
			SELECT      Name, ID
			FROM        Businesses
							WHERE
						UserID = #request.UserID#
		</CFQUERY>
		
		<cfif get_businesses.recordcount GT 1 and request.BusinessID eq "0">			

			You have multiple businesses, please select one:</br></br>

			<table width="400" cellpadding="2" cellspacing="2">

				<tr>
					<td>Name</td>
					<td>Become</td>
				</tr>

				<cfoutput query="get_businesses">
	
					<tr>
						<td>#Name#</td>
						<td>
						
							<script language="JavaScript">
								function submitformbecome#get_businesses.ID#()
								{
								document.myformbecome#get_businesses.ID#.submit();
								}
							</script>
							
							<form action="#request.cgiPath#" method="post" name="myformbecome#get_businesses.ID#" id="myformbecome#get_businesses.ID#" style="display:inline;">
								
								<a href="javascript: submitformbecome#get_businesses.ID#()">Become</a>
								
								<input type="hidden" name="business_form_submitted" value="1">
								<input type="hidden" name="mode" value="businesses">
								<input type="hidden" name="submode" value="become">
								<input type="hidden" name="BusinessID" value="#get_businesses.ID#">
							
							</form>
						
						</td>
					</tr>
					
				</cfoutput>

			</table><br>
				
			<hr><br>
		
			<cfif request.BusinessID neq 0><cfoutput>
			
				<script language="JavaScript">
					function submitformaddbusiness()
					{
					document.myformaddbusiness.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformaddbusiness" id="myformaddbusiness" style="display:inline;">
					
					<a href="javascript: submitformaddbusiness()">Add New Business</a><br><br>
					
					<input type="hidden" name="mode" value="businesses">
					<input type="hidden" name="BusinessID" value="0">
					<input type="hidden" name="submode" value="add">
				
				</form>				

			</cfoutput></cfif>
		
		</cfif>

		<cfif request.BusinessID gt 0>

			<CFQUERY name="get_biz_name" datasource="#application.datasource#">
				SELECT      B.Name
				FROM        Businesses B
				WHERE		B.ID = #request.BusinessID#
			</CFQUERY>

			You are logged in as <cfoutput><h3>#get_biz_name.Name#</h3></cfoutput>

		</cfif>

		<cfif form.business_form_submitted EQ 0>

			<cfparam name="form.BusinessID" default="0">

			<cfif form.BusinessID eq 0 AND (request.BusinessID eq 0 or form.submode eq "add")>
		
				<cfparam name="values.Name" default="">
				<cfparam name="values.Line1" default="">
				<cfparam name="values.Line2" default="">
				<cfparam name="values.City" default="">
				<cfparam name="values.StateID" default="0">
				<cfparam name="values.ZIPCode" default="">
				<cfparam name="values.TaxRate" default="0">
				<cfparam name="values.OrderTypes" default="">
				<cfparam name="values.DeliveryRadius" default="0">
				<cfparam name="values.DeliveryZIPCodes" default="">
				<cfparam name="values.IsHiring" default="0">
				<cfparam name="values.IsDemo" default="1">
				<cfparam name="values.IsPrivate" default="0">

			<cfelse>

				<CFQUERY name="values" datasource="#application.datasource#">
					SELECT      B.*, A.Addressline1, A.Addressline2, A.City, A.StateID, A.ZIPCode
					FROM        Businesses B, Addresses A
					WHERE		B.ID = #request.BusinessID#
									AND 
								A.BusinessID = B.ID
									AND 
								A.AddressTypeID = 2
				</CFQUERY>

			</cfif>
			
		<cfelseif form.business_form_submitted EQ 1 and form.submode neq "">
			
			<cfset values.Name = form.Name>
			<cfset values.Line1 = form.Line1>
			<cfset values.Line2 = form.Line2>
			<cfset values.City = form.City>
			<cfset values.StateID = form.StateID>
			<cfset values.ZIPCode = form.ZIPCode>
			<cfset values.TaxRate = form.TaxRate>
			<cfset values.OrderTypes = form.OrderTypes>
			<cfset values.IsHiring = form.IsHiring>
			<cfset values.DeliveryRadius = form.DeliveryRadius>
			<cfset values.DeliveryZIPCodes = form.DeliveryZIPCodes>
			<cfset values.IsDemo = form.IsDemo>
			<cfset values.IsPrivate = form.IsPrivate>
			
		<cfelse>
			
			Problem!<cfabort>
		
		</cfif>
		
		<cfif form.business_form_submitted EQ 1>
		
			<cfif trim(values.Name) EQ "">
				<cfset messages = listappend(messages, "Business Name is required")>
				<cfset business_form_submitted = 0>
			</cfif>
		
			<cfif trim(values.Line1) EQ "">
				<cfset messages = listappend(messages, "Business Address 1 is required")>
				<cfset business_form_submitted = 0>
			</cfif>
		
			<cfif Len(values.City) LT 2>
				<cfset messages = listappend(messages, "City is required")>
				<cfset business_form_submitted = 0>
			</cfif>
		
			<cfif StateID EQ 0>
				<cfset messages = listappend(messages, "Please select your state")>
				<cfset business_form_submitted = 0>
			</cfif>
		
			<cfif Len(values.ZIPCode) LT 5>
				<cfset messages = listappend(messages, "ZIP Code is required")>
				<cfset business_form_submitted = 0>
			</cfif>
		
			<cfif isnumeric(values.TaxRate) EQ 0>
				<cfset messages = listappend(messages, "Sales tax rate must be numeric")>
				<cfset submitted = 0>
			</cfif>
		
		</cfif>
		
		<cfif messages gt 0>
		
			<CFLOOP INDEX="ListElement" LIST=#messages#> 
			<CFOUTPUT><div align="center"><font color="FF0000"><strong>#ListElement#</strong></font></div></CFOUTPUT>
			</CFLOOP><br><br>
			
		</cfif>
		
		<cfif form.business_form_submitted EQ 0 AND (form.submode eq "edit" or form.submode eq "add")>
			
			<cfif request.BusinessID eq 0>Add a new business to Payfrit:<cfelse>Edit business info:</cfif><br><br>
				
				<cfoutput><form action="#request.cgiPath#" method="post"></cfoutput>
				
				<TABLE border="0">
					<TR> 
						<TD>
							Business Name:
						</TD>
						<TD> 
							<cfoutput><INPUT name="Name" value="#values.Name#" size="25" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Address Line 1:
						</TD>
						<TD>
							<cfoutput><INPUT name="Line1" value="#values.Line1#" size="30" maxlength="100"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Address Line 2:
						</TD>
						<TD>
							<cfoutput><INPUT name="Line2" value="#values.Line2#" size="30" maxlength="100"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							City:
						</TD>
						<TD> 
							<cfoutput><INPUT name="City" value="#values.City#" size="12" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<CFQUERY name="get_States" datasource="#application.datasource#">
						SELECT      ID, Name
						FROM        tt_States
						ORDER BY	Name
					</CFQUERY>
					<TR> 
						<TD>
							Select State:
						</TD>
						<TD>
							<select name="StateID">
								<option value="0">Please Select</option>
								<cfoutput query=#get_States#>
									<option value="#ID#" <cfif #values.StateID# EQ #get_States.ID#>Selected</cfif>>#Name#</option>
								</cfoutput>
							</select>
						</TD>
					</TR>
					<TR> 
						<TD>
							ZIP Code:
						</TD>
						<TD> 
							<cfoutput><INPUT name="ZIPCode" value="#values.ZIPCode#" size="4"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Sales Tax Rate:
						</TD>
						<TD> 
							<cfoutput><INPUT name="TaxRate" value="#values.TaxRate#" size="3">%</cfoutput>
						</TD>
					</TR>
					<CFQUERY name="get_OrderTypes" datasource="#application.datasource#">
						SELECT      ID, Name
						FROM        tt_OrderTypes
						ORDER BY	ID
					</CFQUERY>
					<TR> 
						<TD valign="top">
							Select Order Types:
						</TD>
						<TD>
							<cfoutput query="get_OrderTypes"><input type="CHECKBOX" name="BusinessOrdertypes" value="#get_OrderTypes.ID#"<cfif find(get_OrderTypes.ID, values.BusinessOrdertypes) GT 0> CHECKED</cfif>>#get_OrderTypes.Name#<br></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Hiring?
						</TD>
						<TD> 
							<cfoutput><INPUT type="checkbox" name="IsHiring" value="1" <cfif values.IsHiring eq 1> checked</cfif>></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Business Radius:
						</TD>
						<TD> 
							<cfoutput><INPUT name="DeliveryRadius" value="#values.DeliveryRadius#" size="3"></cfoutput>mi
						</TD>
					</TR>
					<TR> 
						<TD>
							Business Delivery ZIP Codes:
						</TD>
						<TD> 
							<cfoutput><INPUT name="DeliveryZIPCodes" value="#values.DeliveryZIPCodes#" size="10"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Demo Mode?
						</TD>
						<TD> 
							<cfoutput><INPUT type="checkbox" name="IsDemo" value="1" size="3" <cfif values.IsDemo eq 1> checked</cfif>></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Private?
						</TD>
						<TD> 
							<cfoutput><INPUT type="checkbox" name="IsPrivate" value="1" size="3" <cfif values.IsPrivate eq 1> checked</cfif>></cfoutput>
						</TD>
					</TR>
				</TABLE>
				
				<input type="hidden" name="business_form_submitted" value="1">
				<input type="hidden" name="mode" value="businesses">
				<cfoutput><input type="hidden" name="BusinessID" value="#form.BusinessID#"></cfoutput>
				<cfif BusinessID EQ 0>
					<input type="hidden" name="submode" value="add">
				<cfelse>
					<input type="hidden" name="submode" value="edit">
				</cfif>
				
				<input TYPE="SUBMIT" <cfif request.BusinessID NEQ 0>Value="Update Info"<cfelse>Value="Add Business"</cfif>  name=SUBMIT>
					
			</form>

			<cfif request.BusinessID neq 0>

				<hr>
		
				<cfoutput>
				<cfif values.LogoImageExtension neq "">
					<img src="#application.wwwrootprefix#uploads/logos/#request.BusinessID#.#values.LogoImageExtension#" border="0" alt=""><br>
					
					<script language="JavaScript">
						function submitformdeletelogo()
						{
						document.myformdeletelogo.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformdeletelogo" id="myformdeletelogo" style="display:inline;">
						
						<a href="javascript: submitformdeletelogo()">Delete logo</a>
						
						<input type="hidden" name="mode" value="businesses">
						<input type="hidden" name="submode" value="dellogoimage">
						<input type="hidden" name="LogoImageExtension" value="#values.LogoImageExtension#"> <!--- save a query by passing this --->
					
					</form>
					<br><br>

				</cfif>
				</cfoutput>

				<cfoutput>

				<script language="JavaScript">
					function submitformuploadlogoimage()
					{
					document.myformuploadlogoimage.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformuploadlogoimage" id="myformuploadlogoimage" style="display:inline;">
					
					<a href="javascript: submitformuploadlogoimage()">Upload new logo</a>
					
					<input type="hidden" name="mode" value="businesses">
					<input type="hidden" name="submode" value="uploadlogoimage">
				
				</form>

				<br><br><hr>

				<cfif values.BusinessheaderImageExtension neq "">
					<img src="#application.wwwrootprefix#uploads/headers/#request.BusinessID#.#values.BusinessheaderImageExtension#" border="0" alt=""><br>
					
					<script language="JavaScript">
						function submitformdeleteheader()
						{
						document.myformdeleteheader.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformdeleteheader" id="myformdeleteheader" style="display:inline;">
						
						<a href="javascript: submitformdeleteheader()">Delete header</a><br><br>
						
						<input type="hidden" name="mode" value="businesses">
						<input type="hidden" name="submode" value="delheaderimage">
						<input type="hidden" name="HeaderImageExtension" value="#values.HeaderImageExtension#"> <!--- save a query by passing this --->
					
					</form>

				</cfif>

				<script language="JavaScript">
					function submitformuploadheaderimage()
					{
					document.myformuploadheaderimage.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformuploadheaderimage" id="myformuploadheaderimage" style="display:inline;">
					
					<a href="javascript: submitformuploadheaderimage()">Upload new header</a>

					<input type="hidden" name="mode" value="businesses">
					<input type="hidden" name="submode" value="uploadheaderimage">
				
				</form>

				<br><br><hr>

				<h4>Your schedule:</h4>

				<CFQUERY name="get_schedule" datasource="#application.datasource#">
					SELECT      H.*, D.Abbrev
					FROM        Hours H, tt_Days D
					WHERE		BusinessID = #request.BusinessID#
									AND 
								H.DayID = D.ID
					ORDER BY 	DayID
				</CFQUERY>

				<table border=#border_width# cellpadding="4" cellspacing="4">

				<cfoutput query="get_schedule">
					<tr><td>

						<cfif datediff("n", OpenTime, ClosingTime) NEQ 0>
					
							#Abbrev#</td><td>#lcase(timeformat(OpenTime, "h:mmtt"))# to #lcase(timeformat(ClosingTime, "h:mmtt"))#

						<cfelse>

							#Abbrev#</td><td> &nbsp; &nbsp;~ CLOSED ~

						</cfif>
						
					<td><tr>
				</cfoutput>

				</table>

				<script language="JavaScript">
					function submitformschedule()
					{
					document.myformschedule.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformschedule" id="myformschedule" style="display:inline;">
					
					<br><a href="javascript: submitformschedule()">Edit your schedule</a>
					
					<input type="hidden" name="mode" value="businesses">
					<input type="hidden" name="submode" value="schedule">
				
				</form>

				<hr>

				<h4>Hiring Status:</h4>

				<cfif values.IsHiring eq 0>

					Currently you are NOT HIRING<br><br>

				<cfelse>

					Currently you ARE HIRING<br>

				</cfif>

				<script language="JavaScript">
					function submitformtogglehiring()
					{
					document.myformtogglehiring.submit();
					}
				</script>

				<cfoutput>
				
					<form action="#request.cgiPath#" method="post" name="myformtogglehiring" id="myformtogglehiring" style="display:inline;">
						
						<a href="javascript: submitformtogglehiring()">Toggle hiring status</a>
						
						<input type="hidden" name="mode" value="togglehiring">
						<input type="hidden" name="oldstatus" value="#values.IsHiring#">
					
					</form>

				</cfoutput></br></br>
				
				<h5>Your Employees:</h5>

				<CFQUERY name="get_employees" datasource="#application.datasource#">
					SELECT      U.FirstName, U.LastName, U.EmailAddress, U.ContactNumber
					FROM        Users U, Employees E
					WHERE		U.ID = E.UserID
									AND
								E.BusinessID = #request.BusinessID#
									AND
								E.IsActive = 1
									AND
								E.StatusID = 2 <!--- Employee is hired --->
					ORDER BY 	U.LastName
				</CFQUERY>
				
				<table>
					<cfoutput query="get_employees">
					
						<cfmodule credential = "#ContactNumber#" template = "modules/format_phnum.cfm">

						<tr><td>#LastName#, #FirstName# <a href="mailto:#EmailAddress#" target="_blank">#EmailAddress#</a> #formatted_phnum#</td></tr>
						
					</cfoutput>
				</table>
				
				<br><h5>Open applicants:</h5>

				<CFQUERY name="get_open_apps" datasource="#application.datasource#">
					SELECT      U.FirstName, U.LastName, U.EmailAddress, U.ContactNumber
					FROM        Users U, Employees E
					WHERE		U.ID = E.UserID
									AND
								E.BusinessID = #request.BusinessID#
									AND
								E.IsActive = 0
									AND
								E.StatusID = 1 <!--- Application is made --->
					ORDER BY 	U.LastName
				</CFQUERY>
				
				<table>
					<cfoutput query="get_open_apps">
					
						<cfmodule credential = "#ContactNumber#" template = "modules/format_phnum.cfm">

						<tr><td>#LastName#, #FirstName# <a href="mailto:#EmailAddress#" target="_blank">#EmailAddress#</a> #formatted_phnum#</td></tr>
						
					</cfoutput>
				</table>

			</cfoutput>
			</cfif>
		
		<cfelseif form.business_form_submitted EQ 0 AND form.submode eq "uploadlogoimage">
		
			Upload a logo (jpg, jpeg, gif, png) at least 300 pixels wide, images will be resized automatically to a square.<br><br>
		
			<cfparam name="image_logo_form_submitted" default="0">
			
			<cfif image_logo_form_submitted EQ 0>
		
				<cfoutput>
					<form method="post" action="#request.cgiPath#" enctype="multipart/form-data" style="display:inline;">
						<input type="file" name="file_sent" id="file_sent" size="100">
						<input type="hidden" name="image_logo_form_submitted" value="1">
						<input type="hidden" name="BusinessID" value="#request.BusinessID#">
						<input type="hidden" name="mode" value="businesses">
						<input type="hidden" name="submode" value="uploadlogoimage">
						<input type="submit" value="Upload >>>">
					</form>
				</cfoutput>
				
			<cfelse>
		
				<cfset messages="">
				
				<cfif file_sent neq "">
				
					<cffile action="UPLOAD" filefield="file_sent" destination="#application.uploads_dir#logos/" nameconflict="MAKEUNIQUE" mode="755">
						
					<cfif LCase(cffile.ClientFileExt) NEQ "jpg" AND LCase(cffile.ClientFileExt) NEQ "jpeg" AND LCase(cffile.ClientFileExt) NEQ "gif" AND LCase(cffile.ClientFileExt) NEQ "png">
						<cfset messages="Only image files are accepted (jpg, jpeg, gif, png)">
						<cffile action="DELETE" file="#application.uploads_dir#logos/#cffile.ClientFile#">
					<cfelse>
						<cfimage source="#application.uploads_dir#logos/#cffile.ClientFile#" action="info" structName="image_info">
						<cfif image_info.height GT image_info.width and image_info.height GT 1280>
							
							<cfimage action="resize" source="#application.uploads_dir#logos/#cffile.ClientFile#" height="1280" destination="#application.uploads_dir#logos/#cffile.ClientFile#" overwrite="true">
						
						</cfif>
						<cfif image_info.width GT image_info.height and image_info.width GT 1280>
							
							<cfimage action="resize" source="#application.uploads_dir#logos/#cffile.ClientFile#" width="1280" destination="#application.uploads_dir#logos/#cffile.ClientFile#" overwrite="true">
						
						</cfif>

						<cffile action="RENAME" source="#application.uploads_dir#logos/#cffile.ClientFile#" destination="#application.uploads_dir#logos/#form.BusinessID#.#cffile.ClientFileExt#" mode="755">
					
						<CFQUERY name="update_Business" datasource="#application.datasource#">
							UPDATE	Businesses
							SET		LogoImageExtension = '#cffile.ClientFileExt#'
							WHERE	BusinessID = #form.BusinessID#
						</CFQUERY>
						
					</cfif>
					
				<cfelse>
				
					<cfset messages="You did not select a file to upload">
				
				</cfif>
				
				<cfif messages EQ "">
				
					<cfoutput>	
						<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
							<input type="hidden" name="mode" value="businesses">
							<input type="hidden" name="submode" value="edit">
						</form>
					</cfoutput>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
					
				<cfelse>
				
					Your upload attempt has been rejected for the following reason(s):<br><br>
					
					<cfoutput><font color="FF0000">#messages#</font></cfoutput><br><br>
					
					<script language="JavaScript" type="text/javascript">
					function submitform1()
					{
					document.myform1.submit();
					}
					</script>
					
					<cfoutput>
						<form action="#request.cgiPath#" method="post" name="myform1" id="myform1" style="display:inline;">
							<a href="javascript: submitform1()">Return to editing</a>
									<input type="hidden" name="mode" value="businesses">
						</form>
					</cfoutput><br>
				
				</cfif>
				
			</cfif>
		
		<cfelseif form.business_form_submitted EQ 0 AND form.submode eq "uploadheaderimage">
		
			Upload a header image (jpg, jpeg, gif, png) at least 300 pixels wide, H:W ratio of 2:1, images will be resized automatically.<br><br>
		
			<cfparam name="image_header_form_submitted" default="0">
			
			<cfif image_header_form_submitted EQ 0>
		
				<cfoutput>
					<form method="post" action="#request.cgiPath#" enctype="multipart/form-data" style="display:inline;">
						<input type="file" name="file_sent" id="file_sent" size="100">
						<input type="hidden" name="image_header_form_submitted" value="1">
						<input type="hidden" name="BusinessID" value="#request.BusinessID#">
						<input type="hidden" name="mode" value="businesses">
						<input type="hidden" name="submode" value="uploadheaderimage">
						<input type="submit" value="Upload >>>">
					</form>
				</cfoutput>
				
			<cfelse>
		
				<cfset messages="">
				
				<cfif file_sent neq "">
				
					<cffile action="UPLOAD" filefield="file_sent" destination="#application.uploads_dir#headers/" nameconflict="MAKEUNIQUE" mode="755">
						
					<cfif LCase(cffile.ClientFileExt) NEQ "jpg" AND LCase(cffile.ClientFileExt) NEQ "jpeg" AND LCase(cffile.ClientFileExt) NEQ "gif" AND LCase(cffile.ClientFileExt) NEQ "png">
						<cfset messages="Only image files are accepted (jpg, jpeg, gif, png)">
						<cffile action="DELETE" file="#application.uploads_dir#headers/#cffile.ClientFile#">
					<cfelse>
						<cfimage source="#application.uploads_dir#headers/#cffile.ClientFile#" action="info" structName="image_info">
						<cfif image_info.height GT image_info.width and image_info.height GT 1280>
							
							<cfimage action="resize" source="#application.uploads_dir#headers/#cffile.ClientFile#" height="1280" destination="#application.uploads_dir#headers/#cffile.ClientFile#" overwrite="true">
						
						</cfif>
						<cfif image_info.width GT image_info.height and image_info.width GT 1280>
							
							<cfimage action="resize" source="#application.uploads_dir#headers/#cffile.ClientFile#" width="1280" destination="#application.uploads_dir#headers/#cffile.ClientFile#" overwrite="true">
						
						</cfif>

						<cffile action="RENAME" source="#application.uploads_dir#headers/#cffile.ClientFile#" destination="#application.uploads_dir#headers/#form.BusinessID#.#cffile.ClientFileExt#" mode="755">
					
						<CFQUERY name="update_Business" datasource="#application.datasource#">
							UPDATE	Businesses
							SET		HeaderImageExtension = '#cffile.ClientFileExt#'
							WHERE	BusinessID = #form.BusinessID#
						</CFQUERY>
						
					</cfif>
					
				<cfelse>
				
					<cfset messages="You did not select a file to upload">
				
				</cfif>
				
				<cfif messages EQ "">
				
					<cfoutput>	
						<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
							<input type="hidden" name="mode" value="businesses">
							<input type="hidden" name="submode" value="edit">
						</form>
					</cfoutput>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
					
				<cfelse>
				
					Your upload attempt has been rejected for the following reason(s):<br><br>
					
					<cfoutput><font color="FF0000">#messages#</font></cfoutput><br><br>
					
					<script language="JavaScript" type="text/javascript">
					function submitform1()
					{
					document.myform1.submit();
					}
					</script>
					
					<cfoutput>
						<form action="#request.cgiPath#" method="post" name="myform1" id="myform1" style="display:inline;">
							<a href="javascript: submitform1()">Return to editing</a>
									<input type="hidden" name="mode" value="businesses">
						</form>
					</cfoutput><br>
				
				</cfif>
				
			</cfif>
		
		<cfelseif form.business_form_submitted EQ 0 AND form.submode eq "dellogoimage">
			
			<cffile action="DELETE" file="#application.uploads_dir#logos/#request.BusinessID#.#form.LogoImageExtension#">
		
			<CFQUERY name="update_item" datasource="#application.datasource#">
				UPDATE	Businessess
				SET		LogoImageExtension = null
				WHERE	BusinessID = #request.BusinessID#
			</CFQUERY>
				
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="businesses">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>
		
		<cfelseif form.business_form_submitted EQ 0 AND form.submode eq "delheaderimage">
			
			<cffile action="DELETE" file="#application.uploads_dir#headers/#request.BusinessID#.#form.HeaderImageExtension#">
		
			<CFQUERY name="update_item" datasource="#application.datasource#">
				UPDATE	Businesses
				SET		BusinessheaderImageExtension = null
				WHERE	BusinessID = #request.BusinessID#
			</CFQUERY>
				
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="businesses">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>
		
		<cfelseif form.business_form_submitted EQ 0 AND form.submode eq "schedule">

			<cfparam name="schedule_form_submitted" default="0">

			<cfif schedule_form_submitted eq 0>

				<h4>Your schedule:</h4>

				<CFQUERY name="get_schedule" datasource="#application.datasource#">
					SELECT      H.*, D.Abbrev
					FROM        Hours H, tt_Days D
					WHERE		BusinessID = #request.BusinessID#
									AND 
								H.DayID = D.ID
					ORDER BY 	DayID
				</CFQUERY>				

				<script language="JavaScript">
					function submitformupdateschedule()
					{
					document.myformupdateschedule.submit();
					}
				</script>
				
				<cfoutput><form action="#request.cgiPath#" method="post" name="myformupdateschedule" id="myformupdateschedule" style="display:inline;">

					<table border=#border_width# cellpadding="2" cellspacing="2"></cfoutput>

					<cfoutput query="get_schedule">
						<tr>
							<td>#Abbrev#</td>
							<td>
								<input type="text" name="#get_schedule.ID#open" value="#lcase(timeformat(OpenTime, "H:MM"))#" size="4">&nbsp;to&nbsp;<input type="text" name="#get_schedule.ID#closing" value="#lcase(timeformat(ClosingTime, "H:MM"))#" size="4">
							</td>
						<tr>
					</cfoutput>

					</table>
					
					<a href="javascript: submitformupdateschedule()">Save this schedule</a><br><br>					
					
					<cfoutput><input type="hidden" name="schedule_form_submitted" value="1"></cfoutput>
					<input type="hidden" name="mode" value="businesses">
					<input type="hidden" name="submode" value="schedule">
				
				</form>		

			<cfelse>
				
				<CFQUERY name="get_schedule" datasource="#application.datasource#">
					SELECT      H.*, D.Abbrev
					FROM        Hours H, tt_Days D
					WHERE		BusinessID = #request.BusinessID#
									AND 
								H.DayID = D.ID
					ORDER BY 	DayID
				</CFQUERY>
				
				<cfset dotw_looper=1>

				<cfoutput query="get_schedule">
				
					<cfset open_temp = "form."&#get_schedule.ID#&"open">
					<cfset closing_temp = "form."&#get_schedule.ID#&"closing">
	
					<CFQUERY name="update_schedule" datasource="#application.datasource#">
						UPDATE 			Hours
						SET 			OpenTime = '#evaluate(open_temp)#',
										ClosingTime = '#evaluate(closing_temp)#'
						WHERE			BusinessID = #request.BusinessID#
											AND
										DayID = #dotw_looper#								
					</cfquery>

					<cfset dotw_looper = incrementvalue(dotw_looper)>					
				</cfoutput>
				
				<cfoutput>	
					<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
						<input type="hidden" name="mode" value="businesses">
						<input type="hidden" name="submode" value="edit">
					</form>
				</cfoutput>
				
				<script type="text/JavaScript" language="JavaScript">  
					document.go_page.submit();  
				</script>
				
			</cfif>
		
		<cfelseif form.business_form_submitted EQ 1>

			<cfif request.BusinessID neq 0>
			
				<CFQUERY name="update_business" datasource="#application.datasource#">
					UPDATE	Businesses
					SET		Name = '#values.Name#',
							TaxRate = #values.TaxRate#,
							OrderTypes = '#values.OrderTypes#',
							DeliveryRadius = #values.DeliveryRadius#,
							DeliveryZIPCodes = '#values.DeliveryZIPCodes#',
							IsDemo = #values.IsDemo#,
							IsPrivate = #values.IsPrivate#
					WHERE	BusinessID = #request.BusinessID#
				</CFQUERY>
			
				<CFQUERY name="update_business_address" datasource="#application.datasource#">
					UPDATE	Addresses
					SET		Addressline1 = '#values.Addressline1#',
							Addressline2 = '#values.Addressline2#',
							City = '#values.City#',
							StateID = #values.StateID#,
							ZIPCode = '#values.ZIPCode#'
					WHERE	BusinessID = #request.BusinessID#
								AND 
							AddressTypeID = 2 <!--- business address --->
				</CFQUERY>
			
				Business info updated!<br><br><cfflush><cfsleep time='1500'/>
		
				<cfoutput>
				
					<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
						<input type="hidden" name="mode" value="businesses">
					</form>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
				
				</cfoutput>

			<cfelse>
			
				<CFQUERY name="insert_business_address" datasource="#application.datasource#">
					INSERT INTO 	Addresses
									(
									UserID,
									BusinessID,
									AddressTypeID,
									Addressline1,
									Addressline2,
									City,
									StateID, 
									ZIPCode,
									AddedOn
									)
					VALUES 			(
									#request.UserID#,
									0,
									2,
									'#values.Addressline1#',
									'#values.Addressline2#',
									'#values.City#',
									#values.StateID#,
									'#values.ZIPCode#',									
									#createODBCDateTime(now())#
									)
				</CFQUERY>

				<CFQUERY name="get_inserted_address" datasource="#application.datasource#">
									SELECT			ID
									FROM 			Addresses
									ORDER BY 		AddressID DESC
									LIMIT 			0,1
				</cfquery>
			
				<CFQUERY name="insert_business" datasource="#application.datasource#">
					INSERT INTO 	Businesses
									(
									UserID,
									Name,
									AddressID,
									TaxRate,
									OrderTypes,
									DeliveryRadius,
									DeliveryZIPCodes,
									IsDemo,
									IsPrivate,
									AddedOn
									)
					VALUES 			(
									#request.UserID#,
									'#values.Name#',
									#get_inserted_address.ID#,
									#values.TaxRate#,
									'#values.OrderTypes#',
									#values.DeliveryRadius#,
									'#values.DeliveryZIPCodes#',
									#values.IsDemo#,
									#values.IsPrivate#,
									#createODBCDateTime(now())#
									)
				</CFQUERY>

				<CFQUERY name="get_inserted_business" datasource="#application.datasource#">
									SELECT			ID
									FROM 			Businesses
									ORDER BY 		BusinessID DESC
									LIMIT 			0,1
				</cfquery>

				<CFQUERY name="update_business_address" datasource="#application.datasource#">
									UPDATE 		Addresses
									SET 		BusinessID = #get_inserted_business.ID#
									WHERE 		AddressID = #get_inserted_address.ID#
				</cfquery>

				<CFQUERY name="insert_owner_as_employee" datasource="#application.datasource#">
									INSERT INTO		Employees
													(
													 BusinessID,
													 UserID
													)
									VALUES			(
													 #get_inserted_business.ID#,
													 #request.UserID#
													 )
				</cfquery>

				<cfloop index="day_looper" from="1" to="7" step="1">
			
					<CFQUERY name="insert_opening_time" datasource="#application.datasource#">
						INSERT INTO 	Hours
										(
										BusinessID,
										DayID,
										OpenTime,
										ClosingTime
										)
						VALUES 			(
										#get_inserted_business.ID#,
										#day_looper#,
										'07:00',
										'22:00'
										)
					</CFQUERY>
					
				</cfloop>
				
				<cfset request.BusinessID = #get_inserted_business.ID#>
				<cfset session.BusinessID = #get_inserted_business.ID#>
			
				<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="start">
				</form>
				</cfoutput>
				
				<script type="text/JavaScript" language="JavaScript">  
					document.go_page.submit();  
				</script>

			</cfif>
		
		</cfif>
		
	<cfelse>
	
		No user found!<br><br>

		Please login.<br>
		
	</cfif>

<cfelseif mode eq "categories">

	<cfif request.UserID neq 0>

		<cfparam name="form.CategoryID" default="0">
		<cfparam name="form.BusinessID" default="0">
		<cfparam name="form.category_form_submitted" default="0">
		<cfparam name="messages" default="">
		<cfparam name="form.submode" default="">		

		<h2>Categories</h2>

			<cfif form.CategoryID eq 0>

				<CFQUERY name="get_categories" datasource="#application.datasource#">
					SELECT      C.ID, C.Name, B.Name, B.ID
					FROM        Categories C, Businesses B 
					WHERE		C.BusinessID = B.ID
									AND 
								UserID = #request.userid#
									AND
								C.BusinessID = #request.BusinessID#
					ORDER BY	SortOrder
				</CFQUERY>

				<cfif get_categories.recordcount GT 0>

					<table width="400" cellpadding="2" cellspacing="2">

						<tr>
							<td><h3>Name</h3></td>
							<td><h3>Edit</h3></td>
						</tr>

						<cfoutput query="get_categories">
			
							<tr>
								<td>#Name#</td>
								<td>
								
								<script language="JavaScript">
									function submitformedit#get_categories.CategoryID#()
									{
									document.myformedit#get_categories.CategoryID#.submit();
									}
								</script>
								
								<form action="#request.cgiPath#" method="post" name="myformedit#get_categories.CategoryID#" id="myformedit#get_categories.CategoryID#" style="display:inline;">
									
									<a href="javascript: submitformedit#get_categories.CategoryID#()">Edit</a>
									
									<input type="hidden" name="category_form_submitted" value="0">
									<input type="hidden" name="mode" value="Categories">
									<input type="hidden" name="submode" value="edit">
									<input type="hidden" name="CategoryID" value="#get_categories.CategoryID#">
								
								</form>
								
								</td>

							</tr>
							
						</cfoutput>

					</table><br>

				</cfif>

			</cfif>

			<cfif form.submode eq "">
			
				<cfoutput>
				
					<script language="JavaScript">
						function submitformaddCategory()
						{
						document.myformaddCategory.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformaddCategory" id="myformaddCategory" style="display:inline;">
						
						<a href="javascript: submitformaddCategory()">Add New Category</a><br><br>
						
						<input type="hidden" name="mode" value="Categories">
						<input type="hidden" name="submode" value="add">
					
					</form>

				</cfoutput>

			</cfif>

		<cfif form.category_form_submitted EQ 0>

			<cfif form.CategoryID eq 0>
		
				<cfparam name="values.Name" default="">
				<cfparam name="values.SortOrder" default="0">
				<cfparam name="values.BusinessID" default="">
				<cfparam name="values.CategoryID" default="">
				<cfparam name="values.ImageExtension" default="">

			<cfelse>

				<CFQUERY name="values" datasource="#application.datasource#">
					SELECT      C.Name, C.ID, C.SortOrder, B.ID, C.ImageExtension
					FROM        Categories C, Businesses B
					WHERE		CategoryID = #form.CategoryID#
									AND 
								C.BusinessID = B.ID
				</CFQUERY>

			</cfif>
			
		<cfelseif form.category_form_submitted EQ 1 and form.submode neq "">
			
			<cfset values.Name = form.Name>
			<cfset values.SortOrder = form.SortOrder>
			
		<cfelse>
			
			Problem!<cfabort>
		
		</cfif>
		
		<cfif form.category_form_submitted EQ 1>
		
			<cfif trim(values.Name) EQ "">
				<cfset messages = listappend(messages, "Category name is required")>
				<cfset category_form_submitted = 0>
			</cfif>
		
		</cfif>
		
		<cfif messages gt 0>
		
			<CFLOOP INDEX="ListElement" LIST=#messages#> 
			<CFOUTPUT><div align="center"><font color="FF0000"><strong>#ListElement#</strong></font></div></CFOUTPUT>
			</CFLOOP><br><br>
			
		</cfif>
		
		<cfif form.category_form_submitted EQ 0 AND (form.submode eq "edit" or form.submode eq "add")>
			
			<cfif form.submode eq "add">Add new<cfelse>Edit</cfif> Category<br>
				
				<cfoutput><form action="#request.cgiPath#" method="post"></cfoutput>
				
				<TABLE border="0">
					<TR> 
						<TD>
							Category Name:
						</TD>
						<TD> 
							<cfoutput><INPUT name="Name" value="#values.Name#" size="15" maxlength="50" tabindex="1"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Category Sort Order:
						</TD>
						<TD> 
							<cfoutput><INPUT name="SortOrder" value="#values.SortOrder#" size="4" maxlength="4" tabindex="2"></cfoutput>
						</TD>
					</TR>
				</TABLE>
				
				<input type="hidden" name="category_form_submitted" value="1">
				<input type="hidden" name="mode" value="categories">
				<cfoutput><input type="hidden" name="CategoryID" value="#values.CategoryID#"></cfoutput>
				<cfif CategoryID EQ 0>
					<input type="hidden" name="submode" value="add">
				<cfelse>
					<input type="hidden" name="submode" value="edit">
				</cfif>
				
				<input TYPE="SUBMIT" <cfif CategoryID NEQ 0>Value="Update Info"<cfelse>Value="Add Category"</cfif>  name=SUBMIT tabindex="2">
					
			</form>

			<cfoutput>

				<cfif values.ImageExtension neq "">
					<img src="#application.wwwrootprefix#uploads/categories/#form.CategoryID#.#values.ImageExtension#" border="0" alt=""><br>
					
					<script language="JavaScript">
						function submitformdelete()
						{
						document.myformdelete.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformdelete" id="myformdelete" style="display:inline;">
						
						<a href="javascript: submitformdelete()">Delete image</a>
						
						<input type="hidden" name="mode" value="categories">
						<input type="hidden" name="submode" value="delimage">
						<input type="hidden" name="CategoryID" value="#form.CategoryID#">
						<input type="hidden" name="ImageExtension" value="#values.ImageExtension#"> <!--- save a query by passing this --->
					
					</form>
					<br><br>

				</cfif>

				<script language="JavaScript">
					function submitformuploadimage()
					{
					document.myformuploadimage.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformuploadimage" id="myformuploadimage" style="display:inline;">
					
					<a href="javascript: submitformuploadimage()">Upload an image</a><br><br>
					
					
					<input type="hidden" name="CategoryID" value="#form.CategoryID#">
					<input type="hidden" name="mode" value="categories">
					<input type="hidden" name="submode" value="uploadimage">
				
				</form>

			</cfoutput>
		
		<cfelseif form.category_form_submitted EQ 0 AND form.submode eq "uploadimage">
		
			Upload an image (jpg, jpeg, gif, png), images will be resized automatically to a rectangle with dimensions 300px wide and 100 pixels high.<br><br>
		
			<cfparam name="image_form_submitted" default="0">
			
			<cfif image_form_submitted EQ 0>
		
				<cfoutput>
					<form method="post" action="#request.cgiPath#" enctype="multipart/form-data" style="display:inline;">
						<input type="file" name="file_sent" id="file_sent" size="100">
						<input type="hidden" name="image_form_submitted" value="1">
						<input type="hidden" name="CategoryID" value="#form.CategoryID#">
						<input type="hidden" name="mode" value="categories">
						<input type="hidden" name="submode" value="uploadimage">
						<input type="submit" value="Upload >>>">
					</form>
				</cfoutput>
				
			<cfelse>
		
				<cfset messages="">
				
				<cfif file_sent neq "">
				
					<cffile action="UPLOAD" filefield="file_sent" destination="#application.uploads_dir#categories/" nameconflict="MAKEUNIQUE" mode="755">
						
					<cfif LCase(cffile.ClientFileExt) NEQ "jpg" AND LCase(cffile.ClientFileExt) NEQ "jpeg" AND LCase(cffile.ClientFileExt) NEQ "gif" AND LCase(cffile.ClientFileExt) NEQ "png">
						<cfset messages="Only image files are accepted (jpg, jpeg, gif, png)">
						<cffile action="DELETE" file="#application.uploads_dir#categories/#cffile.ClientFile#">
					<cfelse>
						<cfimage source="#application.uploads_dir#categories/#cffile.ClientFile#" action="info" structName="image_info">
						<cfif image_info.width GT image_info.height and image_info.width GT 300>
							
							<cfimage action="resize" source="#application.uploads_dir#categories/#cffile.ClientFile#" width="300" destination="#application.uploads_dir#categories/#cffile.ClientFile#" overwrite="true">
						
						</cfif>
						<cfif image_info.height GT image_info.width and image_info.height GT 300>
							
							<cfimage action="resize" source="#application.uploads_dir#categories/#cffile.ClientFile#" height="300" destination="#application.uploads_dir#categories/#cffile.ClientFile#" overwrite="true">
						
						</cfif>

						<cffile action="RENAME" source="#application.uploads_dir#categories/#cffile.ClientFile#" destination="#application.uploads_dir#categories/#form.CategoryID#.#cffile.ClientFileExt#" mode="755">
					
						<CFQUERY name="update_category" datasource="#application.datasource#">
							UPDATE	Categories
							SET		ImageExtension = '#cffile.ClientFileExt#'
							WHERE	CategoryID = #form.CategoryID#
						</CFQUERY>
						
					</cfif>
					
				<cfelse>
				
					<cfset messages="You did not select a file to upload">
				
				</cfif>
				
				<cfif messages EQ "">
				
					<cfoutput>	
						<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
							<input type="hidden" name="mode" value="categories">
							<input type="hidden" name="submode" value="edit">
							<input type="hidden" name="CategoryID" value="#form.CategoryID#">
						</form>
					</cfoutput>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
					
				<cfelse>
				
					Your upload attempt has been rejected for the following reason(s):<br><br>
					
					<cfoutput><font color="FF0000">#messages#</font></cfoutput><br><br>
					
					<script language="JavaScript" type="text/javascript">
					function submitform1()
					{
					document.myform1.submit();
					}
					</script>
					
					<cfoutput>
						<form action="#request.cgiPath#" method="post" name="myform1" id="myform1" style="display:inline;">
							<a href="javascript: submitform1()">Return to editing</a>
									<input type="hidden" name="mode" value="categories">
									<input type="hidden" name="ItemID" value="#form.ItemID#">
						</form>
					</cfoutput><br>
				
				</cfif>
				
			</cfif>
		
		<cfelseif form.category_form_submitted EQ 0 AND form.submode eq "delimage">
			
			<cffile action="DELETE" file="#application.uploads_dir#categories/#form.CategoryID#.#form.ImageExtension#">
		
			<CFQUERY name="update_item" datasource="#application.datasource#">
				UPDATE	Categories
				SET		ImageExtension = null
				WHERE	CategoryID = #form.CategoryID#
			</CFQUERY>
				
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="categories">
					<input type="hidden" name="submode" value="edit">
					<input type="hidden" name="CategoryID" value="#form.CategoryID#">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>		
		
		<cfelseif form.category_form_submitted EQ 1>

			<cfif form.CategoryID gt 0>
			
				<CFQUERY name="update_Category" datasource="#application.datasource#">
					UPDATE	Categories
					SET		Name = '#values.Name#',
							SortOrder = #values.SortOrder#
					WHERE	CategoryID = #form.CategoryID#
				</CFQUERY>
			
				Category info updated!<br><br><cfflush><cfsleep time='1500'/>
		
				<cfoutput>
				
					<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
						<input type="hidden" name="mode" value="categories">
					</form>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
				
				</cfoutput>

			<cfelse>
			
				<CFQUERY name="insert_Category" datasource="#application.datasource#">
					INSERT INTO 	Categories
									(
									BusinessID,
									Name,
									SortOrder,
									AddedOn
									)
					VALUES 			(
									 #request.BusinessID#,
									'#form.Name#',
									 #form.SortOrder#,
									 #createODBCDateTime(now())#
									)
				</CFQUERY>
			
				Category inserted!<br><br>
		
				<cfoutput>
				
					<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
						<input type="hidden" name="mode" value="categories">
						<input type="hidden" name="submode" value="add">
					</form>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
				
				</cfoutput>

			</cfif>
		
		</cfif>
		
	<cfelse>
	
		No user found!<br><br>

		Please login.<br>
		
	</cfif>

<cfelseif mode eq "items">

	<cfif request.UserID neq 0 AND request.BusinessID neq 0>

		<cfparam name="form.ItemID" default="0">
		<cfparam name="form.Price" default="0">
		<cfparam name="form.CategoryID" default="0">
		<cfparam name="form.item_form_submitted" default="0">
		<cfparam name="messages" default="">
		<cfparam name="form.submode" default="">
		<cfparam name="form.IsActive" default="0"><!--- initialize checkboxes if they didn't come through in the form --->
		<cfparam name="form.IsCheckedByDefault" default="0"><!--- initialize checkboxes if they didn't come through in the form --->
		<cfparam name="form.RequiresChildSelection" default="0"><!--- initialize checkboxes if they didn't come through in the form --->
		<cfparam name="form.MaxNumSelectionReq" default="0"><!--- initialize checkboxes if they didn't come through in the form --->
		<cfparam name="form.IsCollapsible" default="0"><!--- initialize checkboxes if they didn't come through in the form --->
		<cfparam name="form.SortOrder" default="0"><!--- initialize checkboxes if they didn't come through in the form --->

			<cfif form.ItemID eq 0>

				<cfquery name="get_business_categories" datasource="#application.datasource#">
					SELECT	    ID, Name
					FROM	    Categories
					WHERE		BusinessID = #request.BusinessID#
				</cfquery>

				<cfoutput query="get_business_categories">

					<CFQUERY name="get_items_active" datasource="#application.datasource#">
						SELECT      Name, ItemID
						FROM        Items
						WHERE		CategoryID = #get_business_categories.CategoryID#
										AND
									ParentItemID = 0
										AND
									IsActive is true
						ORDER BY	SortOrder DESC
					</CFQUERY>

					<CFQUERY name="get_items_inactive" datasource="#application.datasource#">
						SELECT      Name, ItemID
						FROM        Items
						WHERE		CategoryID = #get_business_categories.CategoryID#
										AND
									ParentItemID = 0
										AND
									IsActive is false
					</CFQUERY>

					<cfif (get_items_active.recordcount GT 0 or  get_items_inactive.recordcount GT 0) AND form.submode eq "">

						<h3>Category: #get_business_categories.Name#</h3>
						
						<table width="600" cellpadding="2" cellspacing="2">

							<tr>
								<td>Name</td>
								<td>Edit</td>
							</tr>
							
							<h4>Active items:</h4>

							<cfloop query="get_items_active">
				
								<tr>
									<td>#Name#</td>
									<td>
									
									<script language="JavaScript">
										function submitformedit#get_items_active.ID#()
										{
										document.myformedit#get_items_active.ID#.submit();
										}
									</script>
									
									<form action="#request.cgiPath#" method="post" name="myformedit#get_items_active.ID#" id="myformedit#get_items_active.ID#" style="display:inline;">
										
										<a href="javascript: submitformedit#get_items_active.ID#()">Edit</a>
										
										<input type="hidden" name="item_form_submitted" value="0">
										<input type="hidden" name="mode" value="items">
										<input type="hidden" name="submode" value="edit">
										<input type="hidden" name="CategoryID" value="#form.CategoryID#">
										<input type="hidden" name="ItemID" value="#get_items_active.ID#">
									
									</form>
									
									</td>
									<td>
									
										<script language="JavaScript">
											function submitforminactivate#get_items_active.ID#()
											{
											document.myforminactivate#get_items_active.ID#.submit();
											}
										</script>
										
										<form action="#request.cgiPath#" method="post" name="myforminactivate#get_items_active.ID#" id="myforminactivate#get_items_active.ID#" style="display:inline;">
											
											<a href="javascript: submitforminactivate#get_items_active.ID#()">Inactivate</a>
											
											<input type="hidden" name="mode" value="items">
											<input type="hidden" name="submode" value="inactivate">
											<input type="hidden" name="ItemID" value="#get_items_active.ID#">
										
										</form>
									
									</td>
								</tr>
								
							</cfloop>
							
							</table><table width="600" cellpadding="2" cellspacing="2">
							
							<h4>Inactive items:</h4>

							<cfloop query="get_items_inactive">
				
								<tr>
									<td>#Name#</td>
									<td>
									
									<script language="JavaScript">
										function submitformedit#get_items_inactive.ID#()
										{
										document.myformedit#get_items_inactive.ID#.submit();
										}
									</script>
									
									<form action="#request.cgiPath#" method="post" name="myformedit#get_items_inactive.ID#" id="myformedit#get_items_inactive.ID#" style="display:inline;">
										
										<a href="javascript: submitformedit#get_items_inactive.ID#()">Edit</a>
										
										<input type="hidden" name="item_form_submitted" value="0">
										<input type="hidden" name="mode" value="items">
										<input type="hidden" name="submode" value="edit">
										<input type="hidden" name="CategoryID" value="#form.CategoryID#">
										<input type="hidden" name="ItemID" value="#get_items_inactive.ID#">
									
									</form>
									
									</td>
									<td>
									
										<script language="JavaScript">
											function submitformactivate#get_items_inactive.ID#()
											{
											document.myformactivate#get_items_inactive.ID#.submit();
											}
										</script>
										
										<form action="#request.cgiPath#" method="post" name="myformactivate#get_items_inactive.ID#" id="myformactivate#get_items_inactive.ID#" style="display:inline;">
											
											<a href="javascript: submitformactivate#get_items_inactive.ID#()">Activate</a>
											
											<input type="hidden" name="mode" value="items">
											<input type="hidden" name="submode" value="activate">
											<input type="hidden" name="ItemID" value="#get_items_inactive.ID#">
										
										</form>
									
									</td>
								</tr>
								
							</cfloop>

						</table><br>

					</cfif>

				</cfoutput>

			</cfif>

			<cfif form.submode eq "">
			
				<cfoutput>
				
					<script language="JavaScript">
						function submitformadditem()
						{
						document.myformadditem.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformadditem" id="myformadditem" style="display:inline;">
						
						<a href="javascript: submitformadditem()">Add New Item</a><br><br>
						
						<input type="hidden" name="mode" value="items">
						<input type="hidden" name="submode" value="add">
					
					</form>

				</cfoutput>

			</cfif>

		<cfif form.item_form_submitted EQ 0>

			<cfif form.ItemID eq 0>
			
				<cfparam name="form.CategoryID" default="0">
		
				<cfparam name="values.Name" default="">
				<cfparam name="values.CategoryID" default="#form.CategoryID#">
				<cfparam name="values.Description" default="">
				<cfparam name="values.ParentItemID" default="">
				<cfparam name="values.Price" default="0">
				<cfparam name="values.IsActive" default="1">
				<cfparam name="values.IsCheckedByDefault" default="0">
				<cfparam name="values.ImageExtension" default="">
				<cfparam name="values.RequiresChildSelection" default="0">
				<cfparam name="values.MaxNumSelectionReq" default="0">
				<cfparam name="values.IsCollapsible" default="0">
				<cfparam name="values.SortOrder" default="0">

			<cfelse>

				<CFQUERY name="values" datasource="#application.datasource#">
					SELECT      *
					FROM        Items
					WHERE		ID = #form.ItemID#
				</CFQUERY>

			</cfif>
			
		<cfelseif form.item_form_submitted EQ 1 and form.submode neq "" and form.submode neq "uploadimage">
			
			<cfset values.Name = form.Name>
			<cfset values.CategoryID = form.CategoryID>
			<cfset values.Description = form.Description>
			<cfset values.ParentItemID = form.ParentItemID>
			<cfset values.Price = form.Price>
			<cfset values.IsActive = form.IsActive>
			<cfset values.IsCheckedByDefault = form.IsCheckedByDefault>
			<cfset values.RequiresChildSelection = form.RequiresChildSelection>
			<cfset values.MaxNumSelectionReq = form.MaxNumSelectionReq>
			<cfset values.IsCollapsible = form.IsCollapsible>
			<cfset values.SortOrder = form.SortOrder>
			
		<cfelse>
			
			Problem!<cfabort>
		
		</cfif>
		
		<cfif form.item_form_submitted EQ 1>
		
			<cfif trim(values.Name) EQ "">
				<cfset messages = listappend(messages, "Item name is required")>
				<cfset submitted = 0>
			</cfif>
		
			<cfif trim(values.CategoryID) EQ "">
				<cfset messages = listappend(messages, "Item category is required")>
				<cfset submitted = 0>
			</cfif>
		
			<!--- <cfif isnumeric(values.Price) EQ 0>
				<cfset messages = listappend(messages, "Item price must be only numbers")>
				<cfset submitted = 0>
			</cfif> --->
		
		</cfif>
		
		<cfif messages gt 0>
		
			<CFLOOP INDEX="ListElement" LIST=#messages#> 
			<CFOUTPUT><div align="center"><font color="FF0000"><strong>#ListElement#</strong></font></div></CFOUTPUT>
			</CFLOOP><br><br>
			
		</cfif>
		
		<cfif form.item_form_submitted EQ 0 AND (form.submode eq "edit" or form.submode eq "add")>
			
			<cfif form.submode eq "add">Add <cfparam name="form.CategoryID" default="0"><cfelse>Edit</cfif> Item<br><br>
				
				<cfoutput><form action="#request.cgiPath#" method="post"></cfoutput>
				
				<TABLE border="0">
					<TR> 
						<TD>
							Item Name:
						</TD>
						<TD> 
							<cfoutput><INPUT name="Name" value="#values.Name#" size="15" maxlength="50" tabindex="1"></cfoutput>
						</TD>
					</TR>
					<cfif values.ParentItemID eq 0 or form.submode eq "add">
					<CFQUERY name="get_categories" datasource="#application.datasource#">
						SELECT      ID, Name
						FROM        Categories
						WHERE		BusinessID = #request.BusinessID#
						ORDER BY	SortOrder
					</CFQUERY>
					<TR> 
						<TD>
							Select Category:
						</TD>
						<TD>
							<select name="CategoryID" tabindex="2">
								<option value="0">Please Select</option>
								<cfoutput query=#get_categories#>
			  						<option value="#get_categories.CategoryID#"<cfif #values.CategoryID# EQ #get_categories.CategoryID#> Selected</cfif>>#get_categories.Name#</option>
								</cfoutput>
							</select>
						</TD>
					</TR></cfif>
					
					<TR> 
						<TD>
							Item Description:
						</TD>
						<TD>
							<cfoutput><textarea cols="20" rows="3" name="Description" tabindex="3">#values.Description#</textarea></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Item Price:
						</TD>
						<TD>
							<cfoutput><INPUT name="Price" value="#values.Price#" size="3" maxlength="10" tabindex="4"></cfoutput>
						</TD>
					</TR>
					<cfif form.ItemID neq 0>
						<TR> 
							<TD>
								Item Is Active?
							</TD>
							<TD> 
								<cfoutput><INPUT type="checkbox" name="IsActive" value="1"<cfif values.IsActive eq 1> checked</cfif> tabindex="5"></cfoutput>
							</TD>
						</TR>
						<TR> 
							<TD>
								Item Is Checked By Default?
							</TD>
							<TD> 
								<cfoutput><INPUT type="checkbox" name="IsCheckedByDefault" value="1" tabindex="6"<cfif values.IsCheckedByDefault eq 1> checked</cfif>></cfoutput>
							</TD>
						</TR>
						<TR> 
							<TD>
								Item requires child selection?
							</TD>
							<TD> 
								<cfoutput><INPUT type="checkbox" name="RequiresChildSelection" value="1"<cfif values.RequiresChildSelection eq 1> checked</cfif> tabindex="7"></cfoutput>
							</TD>
						</TR>
						<TR> 
							<TD>
								If required, max number to select?
							</TD>
							<TD> 
								<cfoutput>
									<select name="MaxNumSelectionReq" tabindex="8">
										<option value="0">Please Select</option>
				  						<option value="1"<cfif (form.submode eq "edit" AND #values.MaxNumSelectionReq# EQ 1)> Selected</cfif>>Only 1 selection allowed</option>
										<option value="2"<cfif (form.submode eq "edit" AND #values.MaxNumSelectionReq# EQ 2)> Selected</cfif>>Up to 2 selections allowed</option>
										<option value="3"<cfif (form.submode eq "edit" AND #values.MaxNumSelectionReq# EQ 3)> Selected</cfif>>Up to 3 selections allowed</option>
										<option value="4"<cfif (form.submode eq "edit" AND #values.MaxNumSelectionReq# EQ 4)> Selected</cfif>>Up to 4 selections allowed</option>
										<option value="5"<cfif (form.submode eq "edit" AND #values.MaxNumSelectionReq# EQ 5)> Selected</cfif>>Up to 5 selections allowed</option>
										<option value="6"<cfif (form.submode eq "edit" AND #values.MaxNumSelectionReq# EQ 6)> Selected</cfif>>Up to 6 selections allowed</option>
									</select>
								</cfoutput>
							</TD>
						</TR>
						<TR> 
							<TD>
								Item children are collapsed?
							</TD>
							<TD> 
								<cfoutput><INPUT type="checkbox" name="IsCollapsible" value="1"<cfif values.IsCollapsible eq 1> checked</cfif> tabindex="9"></cfoutput>
							</TD>
						</TR>
						<TR> 
							<TD>
								Item sort order
							</TD>
							<TD> 
								<cfoutput><INPUT name="SortOrder" value="#values.SortOrder#" size="5" maxlength="5" tabindex="10"></cfoutput>
							</TD>
						</TR>
					</cfif>
				</TABLE>
				
				<cfoutput><input type="hidden" name="item_form_submitted" value="1">
				<input type="hidden" name="mode" value="items">
				<input type="hidden" name="ParentItemID" value="#values.ParentItemID#">
				<input type="hidden" name="ItemID" value="#form.ItemID#">
				<cfif form.ItemID EQ 0>
					<input type="hidden" name="submode" value="add">
				<cfelse>
					<input type="hidden" name="submode" value="edit">
				</cfif></cfoutput>
				
				<input TYPE="SUBMIT"<cfif form.ItemID NEQ 0> Value="Update Info"<cfelse> Value="Add Item"</cfif>  name=SUBMIT tabindex="6">
					
			</form>

			<cfoutput>

				<cfif values.ImageExtension neq "">
					<img src="#application.wwwrootprefix#uploads/items/#form.ItemID#.#values.ImageExtension#" border="0" alt=""><br><br>
					<img src="#application.wwwrootprefix#uploads/items/thumbs/#form.ItemID#.#values.ImageExtension#" border="0" alt=""><br>
					<script language="JavaScript">
						function submitformdelete()
						{
						document.myformdelete.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformdelete" id="myformdelete" style="display:inline;">
						
						<a href="javascript: submitformdelete()">Delete image</a>
						
						<input type="hidden" name="mode" value="items">
						<input type="hidden" name="submode" value="delimage">
						<input type="hidden" name="ItemID" value="#form.ItemID#">
						<input type="hidden" name="ImageExtension" value="#values.ImageExtension#"> <!--- save a query by passing this --->
					
					</form>
					<br><br>

				</cfif>

				<script language="JavaScript">
					function submitformuploadimage()
					{
					document.myformuploadimage.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformuploadimage" id="myformuploadimage" style="display:inline;">
					
					<a href="javascript: submitformuploadimage()">Upload an image</a><br><br>
					
					
					<input type="hidden" name="ItemID" value="#form.ItemID#">
					<input type="hidden" name="mode" value="items">
					<input type="hidden" name="submode" value="uploadimage">
				
				</form>

			</cfoutput>
		
		<cfelseif form.submode eq "activate">

			<cfquery name="make_item_active" datasource="#application.datasource#">
				UPDATE 		Items
				SET 		IsActive = true
				WHERE		ItemID = #form.ItemID#
			</cfquery>	
			
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="items">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>
		
		<cfelseif form.submode eq "inactivate">

			<cfquery name="make_item_active" datasource="#application.datasource#">
				UPDATE 		Items
				SET 		IsActive = false
				WHERE		ItemID = #form.ItemID#
			</cfquery>	
			
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="items">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>
		
		<cfelseif form.submode eq "flipcoll">
		
			<cfquery name="get_coll_status" datasource="#application.datasource#">
				SELECT		IsCollapsible
				FROM 		Items
				WHERE		ID = #form.ItemID#
			</cfquery>
			
			<cfif get_coll_status.IsCollapsible eq 0>

				<cfquery name="make_item_collapsible" datasource="#application.datasource#">
					UPDATE 		Items
					SET 		IsCollapsible = 1
					WHERE		ItemID = #form.ItemID#
				</cfquery>	
			
			<cfelse>

				<cfquery name="make_item_non-collapsible" datasource="#application.datasource#">
					UPDATE 		Items
					SET 		IsCollapsible = 0
					WHERE		ItemID = #form.ItemID#
				</cfquery>	
			
			</cfif>
			
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="viewmenu">
					<input type="hidden" name="submode" value="edit">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>
		
		<cfelseif form.submode eq "uploadimage">
		
			Upload an image (jpg, jpeg, gif, png), images will be resized automatically to a rectangle/square with no dimension larger than 1280 pixels.<br><br>
		
			<cfparam name="image_form_submitted" default="0">
			
			<cfif image_form_submitted EQ 0>
		
				<cfoutput>
					<form method="post" action="#request.cgiPath#" enctype="multipart/form-data" style="display:inline;">
						<input type="file" name="file_sent" id="file_sent" size="100">
						<input type="hidden" name="image_form_submitted" value="1">
						<input type="hidden" name="ItemID" value="#form.ItemID#">
						<input type="hidden" name="mode" value="items">
						<input type="hidden" name="submode" value="uploadimage">
						<input type="submit" value="Upload >>>">
					</form>
				</cfoutput>
				
			<cfelse>
		
				<cfset messages="">
				
				<cfif file_sent neq "">
				
					<cffile action="UPLOAD" filefield="file_sent" destination="#application.uploads_dir#items/" nameconflict="MAKEUNIQUE" mode="755">
						
					<cfif LCase(cffile.ClientFileExt) NEQ "jpg" AND LCase(cffile.ClientFileExt) NEQ "jpeg" AND LCase(cffile.ClientFileExt) NEQ "gif" AND LCase(cffile.ClientFileExt) NEQ "png">
						<cfset messages="Only image files are accepted (jpg, jpeg, gif, png)">
						<cffile action="DELETE" file="#application.uploads_dir#items/#cffile.ClientFile#">
					<cfelse>
						<cfimage source="#application.uploads_dir#items/#cffile.ClientFile#" action="info" structName="image_info">
						<cfif image_info.height GT image_info.width and image_info.height GT 1280>
							
							<cfimage action="resize" source="#application.uploads_dir#items/#cffile.ClientFile#" height="1280" destination="#application.uploads_dir#items/#cffile.ClientFile#" overwrite="true">
						
						</cfif>
						<cfif image_info.width GT image_info.height and image_info.width GT 1280>
							
							<cfimage action="resize" source="#application.uploads_dir#items/#cffile.ClientFile#" width="1280" destination="#application.uploads_dir#items/#cffile.ClientFile#" overwrite="true">
						
						</cfif>
						<cfimage action="resize" source="#application.uploads_dir#items/#cffile.ClientFile#" width="125" destination="#application.uploads_dir#items/thumbs/#cffile.ClientFile#" overwrite="true">

						<cffile action="RENAME" source="#application.uploads_dir#items/#cffile.ClientFile#" destination="#application.uploads_dir#items/#form.ItemID#.#cffile.ClientFileExt#" mode="755">
						<cffile action="RENAME" source="#application.uploads_dir#items/thumbs/#cffile.ClientFile#" destination="#application.uploads_dir#items/thumbs/#form.ItemID#.#cffile.ClientFileExt#" mode="755">
					
						<CFQUERY name="update_item" datasource="#application.datasource#">
							UPDATE	Items
							SET		ImageExtension = '#cffile.ClientFileExt#'
							WHERE	ItemID = #form.ItemID#
						</CFQUERY>
						
					</cfif>
					
				<cfelse>
				
					<cfset messages="You did not select a file to upload">
				
				</cfif>
				
				<cfif messages EQ "">
				
					<cfoutput>	
						<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
							<input type="hidden" name="mode" value="items">
							<input type="hidden" name="submode" value="edit">
							<input type="hidden" name="ItemID" value="#form.ItemID#">
						</form>
					</cfoutput>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
					
				<cfelse>
				
					Your upload attempt has been rejected for the following reason(s):<br><br>
					
					<cfoutput><font color="FF0000">#messages#</font></cfoutput><br><br>
					
					<script language="JavaScript" type="text/javascript">
					function submitform1()
					{
					document.myform1.submit();
					}
					</script>
					
					<cfoutput>
						<form action="#request.cgiPath#" method="post" name="myform1" id="myform1" style="display:inline;">
							<a href="javascript: submitform1()">Return to editing</a>
									<input type="hidden" name="mode" value="items">
									<input type="hidden" name="ItemID" value="#form.ItemID#">
						</form>
					</cfoutput><br>
				
				</cfif>
				
			</cfif>
		
		<cfelseif form.item_form_submitted EQ 0 AND form.submode eq "delimage">
			
			<cffile action="DELETE" file="#application.uploads_dir#items/#form.ItemID#.#form.ImageExtension#">
			<cffile action="DELETE" file="#application.uploads_dir#items/thumbs/#form.ItemID#.#form.ImageExtension#">
		
			<CFQUERY name="update_item" datasource="#application.datasource#">
				UPDATE	Items
				SET		ImageExtension = null
				WHERE	ItemID = #form.ItemID#
			</CFQUERY>
				
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="items">
					<input type="hidden" name="submode" value="edit">
					<input type="hidden" name="ItemID" value="#form.ItemID#">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>
		
		<cfelseif form.item_form_submitted EQ 1>
			
			<cfif values.Price eq "">
				<cfset values.Price=0>
			</cfif>

			<cfif form.ItemID neq 0>
			
				<CFQUERY name="update_item" datasource="#application.datasource#">
					UPDATE	Items
					SET		Name = '#values.Name#',
							<cfif values.ParentItemID eq 0>
								CategoryID = '#values.CategoryID#',
							</cfif>
							Description = '#values.Description#',
							Price = #values.Price#,
							IsActive = #values.IsActive#,
							IsCheckedByDefault = #values.IsCheckedByDefault#,
							RequiresChildSelection = #values.RequiresChildSelection#,
							MaxNumSelectionReq = #values.MaxNumSelectionReq#,
							IsCollapsible = #values.IsCollapsible#,
							SortOrder = #values.SortOrder#
					WHERE	ItemID = #form.ItemID#
				</CFQUERY>
			
				<!--- Item info updated!<br><br> --->
		
				<cfoutput>
				
					<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
						<input type="hidden" name="mode" value="viewmenu">
						<input type="hidden" name="submode" value="edit">
					</form>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
				
				</cfoutput>

			<cfelse>
			
				<CFQUERY name="insert_item" datasource="#application.datasource#">
					INSERT INTO 	Items
									(
									Name,
									CategoryID,
									Description,
									Price,
									IsActive,
									IsCheckedByDefault,
									AddedOn,
									RequiresChildSelection,
									MaxNumSelectionReq,
									IsCollapsible,
									SortOrder
									)
					VALUES 			(
									'#values.Name#',
									 #values.CategoryID#,
									'#values.Description#',
									 #values.Price#,
									 1,
									 #values.IsCheckedByDefault#,
									 #createODBCDateTime(now())#,
									 #values.RequiresChildSelection#,
									 #values.MaxNumSelectionReq#,
									 #values.IsCollapsible#,
									 #values.SortOrder#
									)
				</CFQUERY>
			
				Item inserted!<br><br>
		
				<cfoutput>
				
					<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
						<input type="hidden" name="mode" value="items">
						<input type="hidden" name="submode" value="add">
						<input type="hidden" name="CategoryID" value="#values.CategoryID#">
					</form>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
				
				</cfoutput>

			</cfif>
		
		</cfif>
		
	<cfelseif request.UserID neq 0>

		Please select a business!<br>
	
	<cfelse>
	
		No user found!<br><br>

		Please login.<br>
		
	</cfif>

<cfelseif mode eq "cloneitem">

	<cfparam name="form.submode" default="start">

	<cfif form.submode eq "start">

		This operation will take an existing item structure and clone that item (and all children of that item) onto one or more menu items in one action.</br></br>

		This is a very powerful tool and can make large-scale changes to your menu with just a couple clicks. Please be careful!</br></br>

		You are about to clone the following structure:</br></br>

		<cfquery name="get_main_item" datasource="#application.datasource#">
			SELECT	    Name, Price
			FROM	    Items
			WHERE		ID = #form.ItemID#
		</cfquery>

		<cfoutput query="get_main_item"><strong>#Name#</strong><cfif Price gt 0> - #dollarformat(Price)#</cfif></cfoutput></br>

		<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id.cfm" sending_ItemID=#form.ItemID# looper=0>

		</br><cfoutput>

			<script language="JavaScript">
				function submitformview()
				{
				document.myformview.submit();
				}
			</script>

			<form action="#request.cgiPath#" method="post" name="myformview" id="myformview" style="display:inline;">
				
				<a href="javascript: submitformview()">Proceed &gt; &gt; &gt;</a>
						
				<input type="hidden" name="mode" value="cloneitem">
				<input type="hidden" name="submode" value="choosetargetitems">
				<input type="hidden" name="ItemID" value="#form.ItemID#">

			</form>

		</cfoutput>

	<cfelseif form.submode eq "choosetargetitems">

		<cfoutput><script language="JavaScript">
			function submitformview()
			{
			document.myformview.submit();
			}
		</script>

		<form action="#request.cgiPath#" method="post" name="myformview" id="myformview" style="display:inline;">

			Please select the menu items you would like to apply this child structure to:</br></br>

			<cfquery name="get_business_categories" datasource="#application.datasource#">
				SELECT	    ID, Name
				FROM	    Categories
				WHERE		BusinessID = #request.BusinessID#
			</cfquery>

			<cfloop query="get_business_categories">

				<h3><input type="checkbox"  name="itemIDstoclone" value="c#get_business_categories.CategoryID#"> #get_business_categories.Name#</h3>
			
				<cfquery name="get_items" datasource="#application.datasource#">
					SELECT	    Name, Price, ItemID
					FROM	    Items
					WHERE		ParentItemID = 0
									AND 
								CategoryID = #get_business_categories.CategoryID#
									AND
								IsActive = 1
					ORDER BY	SortOrder DESC
				</cfquery>
				
				<cfloop query="get_items">
					
					<cfoutput><input type="checkbox"  name="itemIDstoclone" value="#get_items.ID#">&nbsp;#get_items.Name# - #dollarformat(get_items.Price)#<br></cfoutput>
					
					<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id_clone.cfm" sending_ItemID=#get_items.ID# looper=0>
				
				</cfloop>

			</cfloop>
				
			</br><a href="javascript: submitformview()">Proceed &gt; &gt; &gt;</a>
					
			<input type="hidden" name="mode" value="cloneitem">
			<input type="hidden" name="submode" value="confirmtargetitems">
			<input type="hidden" name="ItemID" value="#form.ItemID#">

		</form></cfoutput>

	<cfelseif form.submode eq "confirmtargetitems">

		You are about to clone the following structure:</br></br>

		<cfquery name="get_main_item" datasource="#application.datasource#">
			SELECT	    Name, Price
			FROM	    Items
			WHERE		ID = #form.ItemID#
		</cfquery>

		<cfoutput query="get_main_item"><strong>#Name#</strong><cfif Price gt 0> - #dollarformat(Price)#</cfif></cfoutput></br>

		<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id.cfm" sending_ItemID=#form.ItemID# looper=0>

		</br>
		
		<cfif left(form.ItemIDstoclone,1) eq "c">
		
			To the following category:</br></br>
			
			<cfquery name="get_cat_to_clone" datasource="#application.datasource#">
				SELECT	    Name
				FROM	    Categories
				WHERE		ID in (#right(form.itemIDstoclone,(len(ItemIDstoclone)-1))#)
			</cfquery>
	
			<cfoutput query="get_cat_to_clone">
				<h3>#Name#</h3></br>
			</cfoutput>
		
		<cfelse>
		
			To the following items:</br></br>
			
			<cfquery name="get_items_to_clone" datasource="#application.datasource#">
				SELECT	    Name
				FROM	    Items
				WHERE		ID in (#form.itemIDstoclone#)
			</cfquery>
	
			<cfoutput query="get_items_to_clone">
				#Name#</br>
			</cfoutput>
		
		</cfif>

		</br>THIS OPERATION CANNOT BE UNDONE</br>

		<cfoutput>

			<script language="JavaScript">
				function submitformview()
				{
				document.myformview.submit();
				}
			</script>

			</br><form action="#request.cgiPath#" method="post" name="myformview" id="myformview" style="display:inline;">
				
				<a href="javascript: submitformview()">Proceed &gt; &gt; &gt;</a>
						
				<input type="hidden" name="mode" value="cloneitem">
				<input type="hidden" name="submode" value="finalizeclone">
				<input type="hidden" name="ItemID" value="#form.ItemID#">
				<input type="hidden" name="itemIDstoclone" value="#form.itemIDstoclone#">

			</form>

		</cfoutput>

	<cfelseif form.submode eq "finalizeclone">

		<CFLOOP INDEX="clonelooper" LIST="#form.itemIDstoclone#" DELIMITERS=",">

			<cfquery name="get_main_item" datasource="#application.datasource#">
				SELECT	    *
				FROM	    Items
				WHERE		ID = #form.ItemID#
			</cfquery>
			
			<cfif left(form.ItemIDstoclone,1) neq "c">
			
				<CFQUERY name="insert_item" datasource="#application.datasource#">
					INSERT INTO 	Items
									(
									CategoryID,
									Name,
									Description,
									ParentItemID,
									Price,
									IsActive,
									IsCheckedByDefault,
									RequiresChildSelection,
									MaxNumSelectionReq,
									IsCollapsible,
									SortOrder,
									AddedOn
									)
					VALUES 			(
									 #get_main_item.CategoryID#,
									'#get_main_item.Name#',
									'#get_main_item.Description#',
									 #clonelooper#,
									 #get_main_item.Price#,
									 #get_main_item.IsActive#,
									 #get_main_item.IsCheckedByDefault#,
									 #get_main_item.RequiresChildSelection#,
									 #get_main_item.MaxNumSelectionReq#,
									 #get_main_item.IsCollapsible#,
									 #get_main_item.SortOrder#,
									 #createODBCDateTime(now())#
									)
				</CFQUERY>
			
			<cfelse>
			
				<CFQUERY name="insert_item" datasource="#application.datasource#">
					INSERT INTO 	Items
									(
									CategoryID,
									Name,
									Description,
									ParentItemID,
									Price,
									IsActive,
									IsCheckedByDefault,
									RequiresChildSelection,
									MaxNumSelectionReq,
									IsCollapsible,
									SortOrder,
									AddedOn
									)
					VALUES 			(
									 #right(form.itemIDstoclone,(len(ItemIDstoclone)-1))#,
									'#get_main_item.Name#',
									'#get_main_item.Description#',
									 0,
									 #get_main_item.Price#,
									 #get_main_item.IsActive#,
									 #get_main_item.IsCheckedByDefault#,
									 #get_main_item.RequiresChildSelection#,
									 #get_main_item.MaxNumSelectionReq#,
									 #get_main_item.IsCollapsible#,
									 #get_main_item.SortOrder#,
									 #createODBCDateTime(now())#
									)
				</CFQUERY>
			
			</cfif>
			
			<CFQUERY name="get_last_inserted" datasource="#application.datasource#">
				SELECT 			ID
				FROM 		 	Items
				ORDER BY		ItemID DESC 
				Limit 			1
			</CFQUERY>

			<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id_clone_do.cfm" sending_ItemID=#form.ItemID# ParentID=#get_last_inserted.ID#>

		</CFLOOP>

		<cfoutput>	
		<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="viewmenu">
			<input type="hidden" name="submode" value="edit">
		</form>
		</cfoutput>
		
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>

	</cfif>

<cfelseif mode eq "viewmenu">

	<cfif request.UserID neq 0>

		<cfparam name="form.submode" default="view">

		<cfif form.submode eq "view">

			<h1>Current menu</h1>
			
			<cfoutput>
	
				<cfif form.submode neq "edit">
					
					<script language="JavaScript">
						function submitformedit()
						{
						document.myformedit.submit();
						}
					</script>
	
					<form action="#request.cgiPath#" method="post" name="myformedit" id="myformedit" style="display:inline;">
						
						<a href="javascript: submitformedit()">View Your Menu</a>
						
						<input type="hidden" name="mode" value="viewmenu">
	
					</form><br><br>
	
				</cfif>
	
			</cfoutput>
			
			<cfquery name="get_business_categories" datasource="#application.datasource#">
			SELECT	    C.ID, C.Name, B.Name
			FROM	    Categories C, Businesses B
			WHERE		B.ID = #request.BusinessID#
							AND
						C.BusinessID = B.ID
		</cfquery>
		
		<cfoutput query="get_business_categories">
		
			<a data-bs-toggle="collapse" href="##multiCollapseExample#get_business_categories.CategoryID#" role="button" aria-expanded="false" aria-controls="multiCollapseExample#get_business_categories.CategoryID#">#get_business_categories.Name#</a>
			<div class="row">
			  <div class="col">
			    <div class="collapse multi-collapse" id="multiCollapseExample#get_business_categories.CategoryID#">
			     
					<cfquery name="get_category_items" datasource="#application.datasource#">
						SELECT	    C.ID, C.Name, B.Name, I.Name, I.ID, I.Price, I.IsCollapsible
						FROM	    Categories C, Businesses B, Items I
						WHERE		C.ID = #get_business_categories.CategoryID#
										AND
									C.BusinessID = B.ID
										AND
									I.CategoryID = C.ID
										AND
									I.IsActive is true
										AND
									I.ParentItemID = 0
						ORDER BY	I.SortOrder
					</cfquery>
					
					<cfloop query="get_category_items">
					
						<cfif get_category_items.IsCollapsible eq 1>
						
							&nbsp;<a data-bs-toggle="collapse" href="##multiCollapseExample#get_category_items.ID#" role="button" aria-expanded="false" aria-controls="multiCollapseExample#get_category_items.ID#">+</a> #get_category_items.Name# - #dollarformat(get_category_items.Price)#<br>
								
							<div class="row">
							  <div class="col">
							    <div class="collapse multi-collapse" id="multiCollapseExample#get_category_items.ID#">
						
									<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id_browsemenu_new.cfm" sending_ItemID=#get_category_items.ID# looper=0>
							
							    </div>
							  </div>
							</div>
							
						<cfelse>
							
							&nbsp; #get_category_items.Name# - #dollarformat(get_category_items.Price)#<br>
							
							<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id_browsemenu_new.cfm" sending_ItemID=#get_category_items.ID# looper=0>
							
						</cfif>
						
					</cfloop>
					
			    </div>
			  </div>
			</div>
		
		</cfoutput>

		<cfelseif form.submode eq "edit">

			<h2>Edit menu</h2><hr>

			<cfquery name="get_business_categories" datasource="#application.datasource#">
				SELECT	    ID, Name
				FROM	    Categories
				WHERE		BusinessID = #request.BusinessID#
			</cfquery>

			<cfoutput query="get_business_categories">

				<h4>#get_business_categories.Name#</h4>

				<cfquery name="get_items" datasource="#application.datasource#">
					SELECT	    Name, Price, ItemID, IsCheckedByDefault, IsCollapsible
					FROM	    Items
					WHERE		ParentItemID = 0
									AND 
								CategoryID = #get_business_categories.CategoryID#
									AND 
								IsActive = 1
					ORDER BY	SortOrder DESC
				</cfquery>
				
				<cfloop query="get_items">
				
					<cfif get_items.IsCollapsible eq 1>
					
						<a data-bs-toggle="collapse" href="##multiCollapseExample#get_items.ID#" role="button" aria-expanded="false" aria-controls="multiCollapseExample#get_items.ID#">+</a>&nbsp;<strong>#get_items.Name#</strong> - #dollarformat(get_items.Price)#<br>
						
						<div class="row">
						  <div class="col">
						    <div class="collapse multi-collapse" id="multiCollapseExample#get_items.ID#">
						
								<script language="JavaScript">
									function submitformedit#get_items.ID#()
									{
									document.myformedit#get_items.ID#.submit();
									}
								</script>
								
								&nbsp;&nbsp;&nbsp;&nbsp;<form action="index.cfm" method="post" name="myformedit#get_items.ID#" id="myformedit#get_items.ID#" style="display:inline;">
									
									<a href="javascript: submitformedit#get_items.ID#()">edit</a>
									
									<input type="hidden" name="item_form_submitted" value="0">
									<input type="hidden" name="mode" value="items">
									<input type="hidden" name="submode" value="edit">
									<input type="hidden" name="ItemID" value="#get_items.ID#">
								
								</form>&nbsp; &nbsp;
								
								<script language="JavaScript">
									function submitformflipcoll#get_items.ID#()
									{
									document.myformflipcoll#get_items.ID#.submit();
									}
								</script>
								
								<form action="index.cfm" method="post" name="myformflipcoll#get_items.ID#" id="myformflipcoll#get_items.ID#" style="display:inline;">
									
									<a href="javascript: submitformflipcoll#get_items.ID#()"><cfif get_items.IsCollapsible eq 1>no </cfif>coll</a>
									
									<input type="hidden" name="item_form_submitted" value="0">
									<input type="hidden" name="mode" value="items">
									<input type="hidden" name="submode" value="flipcoll">
									<input type="hidden" name="ItemID" value="#get_items.ID#">
								
								</form>&nbsp; &nbsp;
								
								<script language="JavaScript">
									function submitformdelitem#get_items.ID#()
									{
									document.myformdelitem#get_items.ID#.submit();
									}
								</script>
								
								<form action="#request.cgiPath#" method="post" name="myformdelitem#get_items.ID#" id="myformdelitem#get_items.ID#" style="display:inline;">
									
									<a href="javascript: submitformdelitem#get_items.ID#()">delete</a>
									
									<input type="hidden" name="mode" value="viewmenu">
									<input type="hidden" name="submode" value="delitem">
									<input type="hidden" name="ItemID" value="#get_items.ID#">
								
								</form>&nbsp; &nbsp;
						
								<script language="JavaScript">
									function submitformcloneitem#get_items.ID#()
									{
									document.myformcloneitem#get_items.ID#.submit();
									}
								</script>
								
								<form action="#request.cgiPath#" method="post" name="myformcloneitem#get_items.ID#" id="myformcloneitem#get_items.ID#" style="display:inline;">
									
									<a href="javascript: submitformcloneitem#get_items.ID#()">clone</a><br>
									
									<input type="hidden" name="mode" value="cloneitem">
									<input type="hidden" name="ItemID" value="#get_items.ID#">
								
								</form>
							
								<script language="JavaScript">
									function submitforminsertchild#get_items.ID#()
									{
									document.myforminsertchild#get_items.ID#.submit();
									}
								</script>
								
								<form action="#request.cgiPath#" method="post" name="myforminsertchild#get_items.ID#" id="myforminsertchild#get_items.ID#" style="display:inline;">
									
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name:<input name="Name" size="6"> Price:<input name="Price" value="0" size="2"> Default?<input type="checkbox" name="IsCheckedByDefault" value="1" <cfif get_items.IsCheckedByDefault eq 1> checked</cfif>> <a href="javascript: submitforminsertchild#get_items.ID#()">add child here</a>
									
									<input type="hidden" name="mode" value="viewmenu">
									<input type="hidden" name="submode" value="insert">
									<input type="hidden" name="ParentItemID" value="#get_items.ID#">
									<input type="hidden" name="CategoryID" value="#get_business_categories.CategoryID#">
								
								</form><br>
								
								<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id_with_add.cfm" sending_ItemID=#get_items.ID# sending_CategoryID=#get_business_categories.CategoryID# looper=0>
								
								</div>
							</div>
						</div>
					
					<cfelse>
					
						<strong>#get_items.Name#</strong> - #dollarformat(get_items.Price)#<br>
						
						<script language="JavaScript">
							function submitformedit#get_items.ID#()
							{
							document.myformedit#get_items.ID#.submit();
							}
						</script>
						
						&nbsp;&nbsp;&nbsp;&nbsp;<form action="index.cfm" method="post" name="myformedit#get_items.ID#" id="myformedit#get_items.ID#" style="display:inline;">
							
							<a href="javascript: submitformedit#get_items.ID#()">edit</a>
							
							<input type="hidden" name="item_form_submitted" value="0">
							<input type="hidden" name="mode" value="items">
							<input type="hidden" name="submode" value="edit">
							<input type="hidden" name="ItemID" value="#get_items.ID#">
						
						</form>&nbsp; &nbsp;
						
						<script language="JavaScript">
							function submitformflipcoll#get_items.ID#()
							{
							document.myformflipcoll#get_items.ID#.submit();
							}
						</script>
						
						<form action="index.cfm" method="post" name="myformflipcoll#get_items.ID#" id="myformflipcoll#get_items.ID#" style="display:inline;">
							
							<a href="javascript: submitformflipcoll#get_items.ID#()"><cfif get_items.IsCollapsible eq 1>no </cfif>coll</a>
							
							<input type="hidden" name="item_form_submitted" value="0">
							<input type="hidden" name="mode" value="items">
							<input type="hidden" name="submode" value="flipcoll">
							<input type="hidden" name="ItemID" value="#get_items.ID#">
						
						</form>&nbsp; &nbsp;
						
						<script language="JavaScript">
							function submitformdelitem#get_items.ID#()
							{
							document.myformdelitem#get_items.ID#.submit();
							}
						</script>
						
						<form action="#request.cgiPath#" method="post" name="myformdelitem#get_items.ID#" id="myformdelitem#get_items.ID#" style="display:inline;">
							
							<a href="javascript: submitformdelitem#get_items.ID#()">delete</a>
							
							<input type="hidden" name="mode" value="viewmenu">
							<input type="hidden" name="submode" value="delitem">
							<input type="hidden" name="ItemID" value="#get_items.ID#">
						
						</form>&nbsp; &nbsp;
				
						<script language="JavaScript">
							function submitformcloneitem#get_items.ID#()
							{
							document.myformcloneitem#get_items.ID#.submit();
							}
						</script>
						
						<form action="#request.cgiPath#" method="post" name="myformcloneitem#get_items.ID#" id="myformcloneitem#get_items.ID#" style="display:inline;">
							
							<a href="javascript: submitformcloneitem#get_items.ID#()">clone</a><br>
							
							<input type="hidden" name="mode" value="cloneitem">
							<input type="hidden" name="ItemID" value="#get_items.ID#">
						
						</form>
					
						<script language="JavaScript">
							function submitforminsertchild#get_items.ID#()
							{
							document.myforminsertchild#get_items.ID#.submit();
							}
						</script>
						
						<form action="#request.cgiPath#" method="post" name="myforminsertchild#get_items.ID#" id="myforminsertchild#get_items.ID#" style="display:inline;">
							
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name:<input name="Name" size="6"> Price:<input name="Price" value="0" size="2"> Default?<input type="checkbox" name="IsCheckedByDefault" value="1" <cfif get_items.IsCheckedByDefault eq 1> checked</cfif>> <a href="javascript: submitforminsertchild#get_items.ID#()">add child here</a>
							
							<input type="hidden" name="mode" value="viewmenu">
							<input type="hidden" name="submode" value="insert">
							<input type="hidden" name="ParentItemID" value="#get_items.ID#">
							<input type="hidden" name="CategoryID" value="#get_business_categories.CategoryID#">
						
						</form><br>
						
						<cfmodule template="#application.wwwrootprefix#modules/get_children_of_item_id_with_add.cfm" sending_ItemID=#get_items.ID# sending_CategoryID=#get_business_categories.CategoryID# looper=0>
					
					</cfif>
					
				</cfloop>

					<script language="JavaScript">
						function submitforminsertroot#get_business_categories.CategoryID#()
						{
						document.myforminsertroot#get_business_categories.CategoryID#.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myforminsertroot#get_business_categories.CategoryID#" id="myforminsertroot#get_business_categories.CategoryID#" style="display:inline;">
						
						Name:<input name="Name" size="6"> Price:<input name="Price" value="0" size="2"> <a href="javascript: submitforminsertroot#get_business_categories.CategoryID#()">Add New Top-Level Item to #get_business_categories.Name#</a>
						
						<input type="hidden" name="mode" value="viewmenu">
						<input type="hidden" name="submode" value="insert">
						<input type="hidden" name="ParentItemID" value="0">
						<input type="hidden" name="CategoryID" value="#get_business_categories.CategoryID#">
					
					</form><br><br>

			</cfoutput>

		<cfelseif form.submode eq "insert">
		
			<cfparam name="form.ItemID" default="0">
			<cfparam name="form.Price" default="0">
			<cfif form.Price lt 0><cfset form.Price = 0></cfif>
			<cfparam name="form.IsCheckedByDefault" default="0">
			
			<cfquery name="insert_item" datasource="#application.datasource#">
				INSERT INTO		    Items
										(
											Name,
											Price,
											IsCheckedByDefault,
											CategoryID,
											ParentItemID,
											AddedOn
										)
				VALUES
										(
										   '#form.Name#',
											#form.Price#,
											#form.IsCheckedByDefault#,
											#form.CategoryID#,
											#form.ParentItemID#,
											#createODBCDateTime(now())#
										)	    
			</cfquery>
			
			<cfoutput>
			
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="viewmenu">
					<input type="hidden" name="submode" value="edit">
				</form>
				
				<script type="text/JavaScript" language="JavaScript">  
					document.go_page.submit();  
				</script>
			
			</cfoutput>

		<cfelseif form.submode eq "delitem">
			
			<cfquery name="delete_item" datasource="#application.datasource#">
				UPDATE		    	Items
				SET					IsActive = 0
				WHERE				ItemID=#form.ItemID#
			</cfquery>
			
			<cfoutput>
			
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="viewmenu">
					<input type="hidden" name="submode" value="edit">
				</form>
				
				<script type="text/JavaScript" language="JavaScript">  
					document.go_page.submit();  
				</script>
			
			</cfoutput>

		<cfelse>

			no mode!<br>

		</cfif>
	
	<cfelse>
	
		No user found!<br><br>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "account">

	<cfif request.UserID GT 0>

		<cfparam name="user_form_submitted" default="0">
		<cfparam name="messages" default="">
	
		<cfif user_form_submitted EQ 0>
	
			<CFQUERY name="values" datasource="#application.datasource#">
				SELECT      U.*, A.*
				FROM        Users U, Addresses A
				WHERE		U.ID = #request.UserID#
								AND 
							A.UserID = U.ID 
								AND 
							A.AddressTypeID = 1 <!--- home address --->
			</CFQUERY>
		    
		<cfelseif user_form_submitted EQ 1>
			
		    <cfset values.FirstName = form.FirstName>
		    <cfset values.LastName = form.LastName>
		    <cfset values.Line1 = form.Line1>
		    <cfset values.Line2 = form.Line2>
		    <cfset values.City = form.City>
		    <cfset values.StateID = form.StateID>
		    <cfset values.ZIPCode = form.ZIPCode>
		    
		<cfelse>
			
			Problem!<cfabort>
		
		</cfif>
		
		<cfif submitted EQ 1>
		
		 	<cfif trim(values.FirstName) EQ "">
				<cfset messages = listappend(messages, "First Name is required")>
				<cfset user_form_submitted = 0>
			</cfif>
		
		 	<cfif trim(values.LastName) EQ "">
				<cfset messages = listappend(messages, "Last Name is required")>
				<cfset user_form_submitted = 0>
			</cfif>
		
		 	<cfif Len(trim(values.Line1)) LT 2>
				<cfset messages = listappend(messages, "Address is required")>
				<cfset user_form_submitted = 0>
			</cfif>
		
		 	<cfif Len(trim(values.City)) LT 2>
				<cfset messages = listappend(messages, "City is required")>
				<cfset user_form_submitted = 0>
			</cfif>
		
		 	<cfif StateID EQ 0>
				<cfset messages = listappend(messages, "Please select your state")>
				<cfset user_form_submitted = 0>
			</cfif>
		
		</cfif>
		
		<cfif messages gt 0>
		
			<CFLOOP INDEX="ListElement" LIST=#messages#> 
			<CFOUTPUT><div align="center"><font color="FF0000"><strong>#ListElement#</strong></font></div></CFOUTPUT>
			</CFLOOP><br><br>
			
		</cfif>
		
		<cfif user_form_submitted EQ 0>
			
				Edit account<br><br>
					
					<script language="JavaScript" type="text/javascript">
					function submitform1()
					{
					document.myform1.submit();
					}
					</script>
					
					<cfoutput>
						<form action="#request.cgiPath#" method="post" name="myform1" id="myform1" style="display:inline;">
							<a href="javascript: submitform1()">Edit business</a>
									<input type="hidden" name="mode" value="businesses">
									<input type="hidden" name="submode" value="edit">
						</form>
					</cfoutput><br><br><br>
				
				
				
				<cfoutput><form action="#request.cgiPath#" method="post"></cfoutput>
				
				<TABLE border="0">
					<TR> 
						<TD>
							First Name:
						</TD>
						<TD> 
							<cfoutput><INPUT name="FirstName" value="#values.FirstName#" size="15" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Last Name:
						</TD>
						<TD> 
							<cfoutput><INPUT name="LastName" value="#values.LastName#" size="25" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Address Line 1:
						</TD>
						<TD>
							<cfoutput><INPUT name="Line1" value="#values.Line1#" size="30" maxlength="100"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Address Line 2:
						</TD>
						<TD>
							<cfoutput><INPUT name="Line2" value="#values.Line2#" size="30" maxlength="100"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							City:
						</TD>
						<TD> 
							<cfoutput><INPUT name="City" value="#values.City#" size="25" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<CFQUERY name="get_States" datasource="#application.datasource#">
						SELECT      ID, Name
						FROM        tt_States
						ORDER BY	Name
					</CFQUERY>
					<TR> 
						<TD>
							Select State:
						</TD>
						<TD>
							<select name="StateID">
								<option value="0">Please Select</option>
								<cfoutput query=#get_States#>
			  						<option value="#ID#" <cfif #values.StateID# EQ #get_States.ID#>Selected</cfif>>#Name#</option>
								</cfoutput>
							</select>
						</TD>
					</TR>
					<TR> 
						<TD>
							ZIP Code:
						</TD>
						<TD> 
							<cfoutput><INPUT name="ZIPCode" value="#values.ZIPCode#" size="6"></cfoutput>
						</TD>
					</TR>
			    </TABLE>
				
				<input type="hidden" name="user_form_submitted" value="1">
				<input type="hidden" name="mode" value="account">
				
				<input TYPE="SUBMIT" Value="Update Info"  name=SUBMIT>
					
			</form>

			<cfoutput>

				<cfif values.ImageExtension neq "">
					<img src="#application.image_display_prefix#users/#request.UserID#.#values.ImageExtension#" border="0" alt=""><br>
					
					<script language="JavaScript">
						function submitformdelete()
						{
						document.myformdelete.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformdelete" id="myformdelete" style="display:inline;">
						
						<a href="javascript: submitformdelete()">Delete image</a>
						
						<input type="hidden" name="mode" value="account">
						<input type="hidden" name="submode" value="delimage">
						<input type="hidden" name="ImageExtension" value="#values.ImageExtension#"> <!--- save a query by passing this --->
					
					</form>
					<br><br>

				</cfif>

				<script language="JavaScript">
					function submitformuploadimage()
					{
					document.myformuploadimage.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformuploadimage" id="myformuploadimage" style="display:inline;">
					
					<a href="javascript: submitformuploadimage()">Upload an image</a><br><br>
					
					
					<input type="hidden" name="mode" value="account">
					<input type="hidden" name="submode" value="uploadimage">
				
				</form>

			</cfoutput>
		
		<cfelseif form.user_form_submitted EQ 0 AND form.submode eq "uploadimage">
		
			Upload an image (jpg, jpeg, gif, png), images will be resized automatically to a rectangle with max dimensions 600px wide and 600 pixels high.<br><br>
		
			<cfparam name="image_form_submitted" default="0">
			
			<cfif image_form_submitted EQ 0>
		
				<cfoutput>
					<form method="post" action="#request.cgiPath#" enctype="multipart/form-data" style="display:inline;">
						<input type="file" name="file_sent" id="file_sent" size="100">
						<input type="hidden" name="image_form_submitted" value="1">
						<input type="hidden" name="mode" value="account">
						<input type="hidden" name="submode" value="uploadimage">
						<input type="submit" value="Upload >>>">
					</form>
				</cfoutput>
				
			<cfelse>
		
				<cfset messages="">
				
				<cfif file_sent neq "">
				
					<cffile action="UPLOAD" filefield="file_sent" destination="#application.uploads_dir#users/" nameconflict="MAKEUNIQUE" mode="755">
						
					<cfif LCase(cffile.ClientFileExt) NEQ "jpg" AND LCase(cffile.ClientFileExt) NEQ "jpeg" AND LCase(cffile.ClientFileExt) NEQ "gif" AND LCase(cffile.ClientFileExt) NEQ "png">
						<cfset messages="Only image files are accepted (jpg, jpeg, gif, png)">
						<cffile action="DELETE" file="#application.uploads_dir#users/#cffile.ClientFile#">
					<cfelse>
						<cfimage source="#application.uploads_dir#users/#cffile.ClientFile#" action="info" structName="image_info">
						<cfif image_info.height GT image_info.width and image_info.height GT 600>
							
							<cfimage action="resize" source="#application.uploads_dir#users/#cffile.ClientFile#" height="600" destination="#application.uploads_dir#users/#cffile.ClientFile#" overwrite="true">
						
						</cfif>
						<cfif image_info.width GT image_info.height and image_info.width GT 600>
							
							<cfimage action="resize" source="#application.uploads_dir#users/#cffile.ClientFile#" width="600" destination="#application.uploads_dir#users/#cffile.ClientFile#" overwrite="true">
						
						</cfif>
						<cfimage action="resize" source="#application.uploads_dir#users/#cffile.ClientFile#" width="100" destination="#application.uploads_dir#users/thumbs/#cffile.ClientFile#" overwrite="true">

						<cffile action="RENAME" source="#application.uploads_dir#users/#cffile.ClientFile#" destination="#application.uploads_dir#users/#request.UserID#.#cffile.ClientFileExt#" mode="755">
						<cffile action="RENAME" source="#application.uploads_dir#users/thumbs/#cffile.ClientFile#" destination="#application.uploads_dir#users/thumbs/#request.UserID#.#cffile.ClientFileExt#" mode="755">
					
						<CFQUERY name="update_item" datasource="#application.datasource#">
							UPDATE	Users
							SET		ImageExtension = '#cffile.ClientFileExt#'
							WHERE	ID = #request.UserID#
						</CFQUERY>

					</cfif>
					
				<cfelse>
				
					<cfset messages="You did not select a file to upload">
				
				</cfif>
				
				<cfif messages EQ "">
				
					<cfoutput>	
						<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
							<input type="hidden" name="mode" value="account">
						</form>
					</cfoutput>
					
					<script type="text/JavaScript" language="JavaScript">  
						document.go_page.submit();  
					</script>
					
				<cfelse>
				
					Your upload attempt has been rejected for the following reason(s):<br><br>
					
					<cfoutput><font color="FF0000">#messages#</font></cfoutput><br><br>
					
					<script language="JavaScript" type="text/javascript">
					function submitform1()
					{
					document.myform1.submit();
					}
					</script>
					
					<cfoutput>
						<form action="#request.cgiPath#" method="post" name="myform1" id="myform1" style="display:inline;">
							<a href="javascript: submitform1()">Return to editing</a>
									<input type="hidden" name="mode" value="account">
						</form>
					</cfoutput><br>
				
				</cfif>
				
			</cfif>
		
		<cfelseif form.user_form_submitted EQ 0 AND form.submode eq "delimage">
			
			<cffile action="DELETE" file="#application.uploads_dir#users/#request.UserID#.#form.ImageExtension#">
		
			<CFQUERY name="update_item" datasource="#application.datasource#">
				UPDATE	Users
				SET		ImageExtension = null
				WHERE	ID = #request.UserID#
			</CFQUERY>
				
			<cfoutput>	
				<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
					<input type="hidden" name="mode" value="account">
					<input type="hidden" name="submode" value="edit">
				</form>
			</cfoutput>
			
			<script type="text/JavaScript" language="JavaScript">  
				document.go_page.submit();  
			</script>	
		
		<cfelse>
			
			<CFQUERY name="update_user" datasource="#application.datasource#">
				UPDATE	Users
				SET		FirstName =  '#values.FirstName#',
						LastName =  '#values.LastName#'
				WHERE	ID = #request.UserID#
			</CFQUERY>
			
			<CFQUERY name="update_user_address" datasource="#application.datasource#">
				UPDATE	Addresses
				SET		Line1 = '#values.Line1#',
						Line2 = '#values.Line2#',
						City = '#values.City#',
						StateID = #values.StateID#,
						ZIPCode = '#values.ZIPCode#'
				WHERE	ID = #request.UserID#
							AND 
						AddressTypeID = 1
			</CFQUERY>
		
			User info updated!<br><br>
		
		</cfif>
	
	<cfelse>
	
		No user found!<br><br>
		
		Please login!<br>
		
	</cfif>
	
<cfelseif mode eq "togglehiring">
			
	<CFQUERY name="update_hiring" datasource="#application.datasource#">
		UPDATE	Businesses
		SET		IsHiring = <cfif form.oldstatus eq 0>1<cfelse>0</cfif>
		WHERE	BusinessID = #request.BusinessID#
	</CFQUERY>
				
	<cfoutput>	
		<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="businesses">
			<input type="hidden" name="submode" value="edit">
		</form>
	</cfoutput>
	
	<script type="text/JavaScript" language="JavaScript">  
		document.go_page.submit();  
	</script>	
	
<cfelseif mode eq "forgot">

    <script language="JavaScript">
        function submitformforgot1()
        {
        document.myformforgot1.submit();
        }
    </script>
    
    <cfoutput><form action="#request.cgiPath#" method="post" name="myformforgot1" id="myformforgot1" style="display:inline;">

        Please input either your email address or cell phone:<br><br>
        
        <input type="text" name="credential" size="15">
    
        <a href="javascript: submitformforgot1()">Submit</a>
        
        <input type="hidden" name="mode" value="forgot1">
    
    </form></cfoutput><br>

<cfelseif mode eq "forgot1">

    <cfoutput><cfmodule credential = "#form.credential#" template = "modules/parse_phnum.cfm"></cfoutput>

    <cfif REFindNocase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", form.credential) EQ 0 AND len(parsed_phnum) neq 10>
		<cfset messages = listappend(messages, "invalid info entered - please input only an email address or mobile nuber.")>
	</cfif>

    <cfquery name="Get_user" datasource="#application.datasource#">
        SELECT	    EmailAddress, ContactNumber, UUID
        FROM	    Users
        WHERE       (EmailAddress = '#form.credential#'
                        OR 
                    ContactNumber =  '#parsed_phnum#')
                        AND 
                    IsEmailVerified = 1
                        AND 
                    IsContactVerified > 0
                    
    </cfquery>

    <cfif get_user.recordcount EQ 1>

        <cfset link_to_build = "https://"&cgi.server_name&application.wwwrootprefix&"index.cfm?UUID="&Get_user.UUID&"&mode=forgot2">

        <cfset isMessageSent = application.twilioObj.sendSMS(recipientNumber=#Get_user.ContactNumber#, messageBody = "Password change requested for Payfrit, please visit #link_to_build#")>

        <cfset this_email_body = "Please click here to update your password:<br><br>
        <br>
        <cfoutput><a href='#link_to_build#'>click here</a></cfoutput><br>
        <br>
        if that doesn't work you can try to copy and paste this link into your browser:<br>
        <br>
        <cfoutput>#link_to_build#<br>
        <br>
        if you didn't request this action, please <a href='admin@payfrit.com'>email</a> us and we will figure out what happened.<br><br><br>
        regards,<br>
        <br>
        Payfrit<br>
        <cfoutput>"&cgi.server_name&"</cfoutput><br>">
        
        <cfmodule template="#application.wwwrootprefix#modules/notifier.cfm"
            domain="box.payfrit.com"
            from_email="admin@payfrit.com"
            to_email="#Get_user.EmailAddress#"
            subject="Payfrit - reset your password"
            email_body="#this_email_body#"
            >
        
        <br>

        If there is registered Payfrit account with that information you will receive instructions on how to reset your password.<br>

    <cfelse>
        User not found!<br><br>
    </cfif>

<cfelseif mode eq "forgot2">

    <script language="JavaScript">
        function submitformforgot1()
        {
        document.myformforgot1.submit();
        }
    </script>
    
    <cfoutput><form action="#request.cgiPath#" method="post" name="myformforgot1" id="myformforgot1" style="display:inline;">

        Please input your new password:<br><br>
        
        <input type="password" name="new_password" size="15"><br><br>
    
        Please type it again:<br><br>
        
        <input type="password" name="new_password_confirm" size="15"><br><br>
    
        <a href="javascript: submitformforgot1()">Submit</a>
        
        <input type="hidden" name="mode" value="forgot3">
        <input type="hidden" name="UUID" value="#url.UUID#">
    
    </form></cfoutput><br>

<cfelseif mode eq "forgot3">

    <cfif form.new_password eq form.new_password_confirm>

        <cfquery name="update_password" datasource="#application.datasource#">
           UPDATE	    Users
           SET          Password = '#hash(new_password)#'
           WHERE        UUID = '#form.UUID#'
        </cfquery>

        Password updated!<br><br>
		
		Please login.<br>

    <cfelse>

       <script language="JavaScript">
            function submitformforgot1()
            {
            document.myformforgot1.submit();
            }
        </script>
    
      <cfoutput><form action="#request.cgiPath#" method="post" name="myformforgot1" id="myformforgot1" style="display:inline;">

            Values did not match, please try again!<br><br>
            
            Please input your new password:<br><br>
            
            <input type="password" name="new_password" size="15"><br><br>
        
            Please type it again:<br><br>
            
            <input type="password" name="new_password_confirm" size="15"><br><br>
        
            <a href="javascript: submitformforgot1()">Submit</a>
            
            <input type="hidden" name="mode" value="forgot3">
            <input type="hidden" name="UUID" value="#url.UUID#">
        
        </form></cfoutput><br>

    </cfif>

<cfelseif mode eq "reports">

	<h3>Orders Reporting</h3>

	<cfparam name="submode" default="last_ten">
	
	<script language="JavaScript">
		function submitformtoday()
		{
		document.myformtoday.submit();
		}
	</script>
	
	<cfoutput><form action="#request.cgiPath#" method="post" name="myformtoday" id="myformtoday" style="display:inline;"></cfoutput>
		
		<a href="javascript: submitformtoday()">Today</a>
		
		<input type="hidden" name="mode" value="reports">
		<input type="hidden" name="submode" value="today">
	
	</form> | 
	
	<script language="JavaScript">
		function submitformyesterday()
		{
		document.myformyesterday.submit();
		}
	</script>
	
	<cfoutput><form action="#request.cgiPath#" method="post" name="myformyesterday" id="myformyesterday" style="display:inline;"></cfoutput>
		
		<a href="javascript: submitformyesterday()">Yesterday</a>
		
		<input type="hidden" name="mode" value="reports">
		<input type="hidden" name="submode" value="yesterday">
	
	</form> | 
	
	<script language="JavaScript">
		function submitformlastweek()
		{
		document.myformlastweek.submit();
		}
	</script>
	
	<cfoutput><form action="#request.cgiPath#" method="post" name="myformlastweek" id="myformlastweek" style="display:inline;"></cfoutput>
		
		<a href="javascript: submitformlastweek()">Last week</a>
		
		<input type="hidden" name="mode" value="reports">
		<input type="hidden" name="submode" value="last_week">
	
	</form><br><br>
	
	Custom range:
	
	<script src="https://unpkg.com/gijgo@1.9.14/js/gijgo.min.js" type="text/javascript"></script>
	<link href="https://unpkg.com/gijgo@1.9.14/css/gijgo.min.css" rel="stylesheet" type="text/css" />
	
	<script language="JavaScript">
		function submitformcustom()
		{
		document.myformcustom.submit();
		}
	</script>
	
	<cfoutput><form action="#request.cgiPath#" method="post" name="myformcustom" id="myformcustom" style="display:inline;"></cfoutput>
	
		<input id="datepicker" name="startdate" width="150" />
		<script>
		    $('#datepicker').datepicker({
		        uiLibrary: 'bootstrap5'
		    });
		</script>
		
		<input id="datepicker1" name="enddate" width="150" />
		<script>
		    $('#datepicker1').datepicker({
		        uiLibrary: 'bootstrap5'
		    });
		</script>
		
		<input type="hidden" name="mode" value="reports">
		<input type="hidden" name="submode" value="custom">
		
		<a href="javascript: submitformcustom()">Custom Range</a>
	
	</form><br><br>
	
	<cfif submode eq "today">

		Today's orders<br><br>
		
		<cfquery name="get_today" datasource="#application.datasource#">
		   SELECT		*
		   FROM			Orders
		   WHERE		BusinessID = #request.BusinessID#
		   					AND
						AddedOn > #createODBCDate(now())#
		   ORDER BY		AddedOn DESC
		   LIMIT		0,10
		</cfquery>
		
		<cfdump var="#get_today#">
	
	<cfelseif submode eq "last_ten">

		Last ten orders<br><br>
		
		<cfquery name="get_last_ten" datasource="#application.datasource#">
		   SELECT		*
		   FROM			Orders
		   WHERE		BusinessID = #request.BusinessID#
		   ORDER BY		AddedOn DESC
		   LIMIT		0,10
		</cfquery>
		
		<cfdump var="#get_last_ten#">
	
	<cfelseif submode eq "yesterday">
	
		Yesterday's orders<br><br>
		
		<cfquery name="get_yesterday" datasource="#application.datasource#">
		   SELECT		*
		   FROM			Orders
		   WHERE		BusinessID = #request.BusinessID#
		   					AND
						AddedOn > #createODBCDate(dateadd("d", -1, now()))#
		   					AND
						AddedOn < #createODBCDate(now())#
		   ORDER BY		AddedOn DESC
		   LIMIT		0,10
		</cfquery>
		
		<cfdump var="#get_yesterday#">
	
	<cfelseif submode eq "last_week">
	
		Last seven day's orders<br><br>
		
		<cfquery name="get_last_seven" datasource="#application.datasource#">
		   SELECT		AddedOn, U.FirstName, U.LastName, O.ID, O.UUID, U.EmailAddress, U.ContactNumber
		   FROM			Orders O, Users U
		   WHERE		O.BusinessID = #request.BusinessID#
		   					AND
						O.UserID = U.ID
		   					AND
						O.AddedOn < #createODBCDate(now())#
							AND
						O.StatusID > 3
		   ORDER BY		O.AddedOn DESC
		   LIMIT		0,10
		</cfquery>
		
		<table cellspacing="2" cellpadding="2">
			<tr><td>Detail</td><td>Date</td><td>Customer</td></tr>		
		<cfoutput query="get_last_seven">
		
			<cfmodule credential = "#ContactNumber#" template = "modules/format_phnum.cfm">
		
			<tr><td align="center">
			
				<script language="JavaScript">
					function submitformorderdetail#OrderID#()
					{
					document.myformorderdetail#OrderID#.submit();
					}
				</script>
				
				<form action="show_order.cfm" method="post" name="myformorderdetail#OrderID#" id="myformorderdetail#OrderID#" style="display:inline;">
					
					<a href="javascript: submitformorderdetail#OrderID#()">#OrderID#</a></td><td>#dateformat(AddedOn, "mm-dd-yyyy")#</td><td>#formatted_phnum# #EmailAddress# #FirstName# #LastName#</td></tr>
					
					<input type="hidden" name="UUID" value="#UUID#">
				
				</form>
			
			</tr>
		
		</cfoutput>
		
		</table>
	
	<cfelse>
	
		<cfoutput>Orders from #dateformat(form.startdate, "mm-dd-yyyy")# to #dateformat(form.enddate, "mm-dd-yyyy")#<br><br></cfoutput>
		
		<cfquery name="get_custom" datasource="#application.datasource#">
		   SELECT		*
		   FROM			Orders
		   WHERE		BusinessID = #request.BusinessID#
		   					AND
						AddedOn > #createODBCDate(form.startdate)#
		   					AND
						AddedOn < #createODBCDate(form.enddate)#
		   ORDER BY		AddedOn DESC
		   LIMIT		0,10
		</cfquery>
		
		<cfdump var="#get_custom#">
	
	</cfif>

<cfelseif mode eq "register">

	<cfoutput><cfinclude template="#application.wwwrootprefix#register.cfm"></cfoutput>

<cfelseif mode eq "logout">

	<cfset request.UserID = 0>
	<cfset session.UserID = 0>
	<cfset request.BusinessID = 0>
	<cfset session.BusinessID = 0>
	
	<cflocation url="index.cfm" addtoken="No">

<cfelse>

	No primary mode provided!<br>
	
</cfif>