<!--- 
Module:         act_ContactUpdate.cfm
Author:         M Jeo, L Chalnick
Function:       The action template to do add/edit/delete contacts.
Date created:   4/25/2002
Modified:       11/28/2004
--->

<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#,
         UserRoleID = 5
       WHERE ContactID = #Attributes.con_id#  
   </cfquery>
   <cflocation url="#self#?fuseaction=#XFA.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, UserRoleID )
      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#,
         5 )
   </cfquery>
   <cflocation url="#self#?fuseaction=#XFA.contactList#">
<cfelse>
   
   <cfif isdefined("Attributes.do_delete")>
      <cfquery name="DELETEContact" datasource="#DSN#">
         DELETE FROM Contacts
         WHERE ContactID = #Attributes.con_id#
      </cfquery>
      <cflocation url="#self#?fuseaction=#XFA.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="#self#?fuseaction=#XFA.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>
