<CFSETTING ENABLECFOUTPUTONLY="YES">
<!--- ------------------------------------------------------------------------------------------------
The action template to do add/edit/delete contacts
-------------------------------------------------------------------------------------------------- --->
<CFIF Attributes.event EQ "update">
   <CFIF IsDefined("Attributes.MailingList")>
      <CFSET VARIABLES.mailinglist = 1>
   <CFELSE>
      <CFSET VARIABLES.mailinglist = 0>    
   </CFIF>
   <CFQUERY NAME="UpdateContact" DATASOURCE="#DSN#">
      UPDATE Contacts SET
         FirstName = '#Attributes.FirstName#',
         LastName = '#Attributes.LastName#', 
         Address = <CFIF Attributes.Address NEQ "">'#Attributes.Address#' <CFELSE> Null </CFIF>, 
         City = <CFIF Attributes.city NEQ "">'#Attributes.city#' <CFELSE> Null </CFIF>, 
         State = <CFIF Attributes.state NEQ "">'#Attributes.state#' <CFELSE> Null </CFIF>, 
         Zip = <CFIF Attributes.zip NEQ "">'#Attributes.zip#' <CFELSE> Null </CFIF>, 
         Country = <CFIF Attributes.country NEQ "">'#Attributes.country#' <CFELSE> Null </CFIF>,
         Email = <CFIF Attributes.email NEQ "">'#Attributes.email#' <CFELSE> Null </CFIF>, 
         Phone = <CFIF Attributes.phone NEQ "">'#Attributes.phone#' <CFELSE> Null </CFIF>, 
         UserLogin = '#Attributes.userlogin#',
         UserPassword = '#Attributes.UserPassword#',
         MailingList = #Variables.MailingList#
       WHERE ContactID = #Attributes.con_id#  
   </CFQUERY>
   <CFLOCATION URL="index.cfm?fuseaction=contactdetail&con_id=#Attributes.con_id#">
<CFELSEIF Attributes.event EQ "add">
   <CFIF IsDefined("Attributes.MailingList")>
      <CFSET VARIABLES.mailinglist = 1>
   <CFELSE>
      <CFSET VARIABLES.mailinglist = 0>    
   </CFIF>
   <CFQUERY NAME="UpdateContact" DATASOURCE="#DSN#">
      INSERT INTO Contacts (FirstName, LastName, Address, City, State, Zip, Country,
         Email, Phone, UserLogin, UserPassword, MailingList)
      VALUES (
         '#Attributes.FirstName#', 
         '#Attributes.LastName#', 
         <CFIF Attributes.Address NEQ "">'#Attributes.Address#' <CFELSE> Null </CFIF>,
         <CFIF Attributes.city NEQ "">'#Attributes.city#' <CFELSE> Null </CFIF>, 
         <CFIF Attributes.state NEQ "">'#Attributes.state#' <CFELSE> Null </CFIF>, 
         <CFIF Attributes.zip NEQ "">'#Attributes.zip#' <CFELSE> Null </CFIF>, 
         <CFIF Attributes.country NEQ "">'#Attributes.country#' <CFELSE> Null </CFIF>,
         <CFIF Attributes.email NEQ "">'#Attributes.email#' <CFELSE> Null </CFIF>, 
         <CFIF Attributes.phone NEQ "">'#Attributes.phone#' <CFELSE> Null </CFIF>, 
         '#Attributes.userlogin#', '#Attributes.userpassword#',
         #Variables.MailingList# )
   </CFQUERY>
   <CFLOCATION URL="index.cfm?fuseaction=contactlist">
<CFELSE>
   
   <CFIF IsDefined("Attributes.do_delete")>
      <CFQUERY NAME="DELETEContact" DATASOURCE="#DSN#">
         DELETE FROM Contacts
         WHERE ContactID = #Attributes.con_id#
      </CFQUERY>
      <CFLOCATION URL="index.cfm?fuseaction=contactlist">

   <CFELSE>
   
      <CFQUERY NAME="GetContactDetail" DATASOURCE="#DSN#">
         SELECT FirstName, LastName
         FROM Contacts
         WHERE ContactID = #Attributes.Con_ID# 
      </CFQUERY>
      
	   <CFOUTPUT>
      <H1>Confirm Delete</H1>
	   Are you sure you want to delete <b>#GetContactDetail.firstname# #GetContactDetail.lastname#</b>?
   	<FORM ACTION="index.cfm?fuseaction=deletecontact" METHOD="post">
   		<INPUT TYPE="hidden" NAME="event" VALUE="delete">
   		<INPUT TYPE="hidden" NAME="con_id" VALUE="#Attributes.Con_ID#">
   		<INPUT TYPE="submit" NAME="do_delete" VALUE="Yes">
   		<INPUT TYPE="button" VALUE="No" onclick="history.back();">
   	</FORM>
	   </CFOUTPUT>
   </CFIF>
</CFIF>
<CFSETTING ENABLECFOUTPUTONLY="NO">

