<!--- If no Actor ID passed, diplay list of links --->
<CFIF IsDefined("URL.ActorID") EQ False>
  <!--- Get a list of actors from database --->
  <CFQUERY NAME="GetActors" DATASOURCE="ows">
    SELECT ActorID, NameFirst, NameLast
    FROM Actors
    ORDER BY NameLast, NameFirst
  </CFQUERY>
    
  <!--- Page Title, etc --->  
  <html>
  <head><title>Actor Retirement System</title></head>
  <body>
  <h3>Which Actor Would You Like To Retire?</h3>
  
  <!--- For each Actor, include simple link to --->  
  <!--- this page, passing the Actor ID in URL --->
  <CFOUTPUT QUERY="GetActors">
    <CFSET LinkURL = "#CGI.SCRIPT_NAME#?ActorID=#ActorID#">
    <a href="#LinkURL#">#NameFirst# <B>#NameLast#</B></a><br>
  </CFOUTPUT>

  </body>
  </html>  
 
 
<!--- If Actor ID passed, generate Word doc --->  
<CFELSE>
  <!--- Make sure Actor ID in URL is a number --->
  <CFPARAM NAME="URL.ActorID" TYPE="numeric">
  
  <!--- Get this Actor's name from database --->
  <CFQUERY NAME="GetActor" DATASOURCE="ows">
    SELECT NameFirst, NameLast, 
      NameFirstReal, NameLastReal,
      (SELECT Min(DateInTheaters)
       FROM Films f, FilmsActors fa
       WHERE fa.FilmID = f.FilmID
       AND fa.ActorID = a.ActorID) AS DateFirstFilm
    FROM Actors a
    WHERE ActorID = #URL.ActorID#
  </CFQUERY>
  
  <!--- How long has Actor been with company? --->
  <CFSET MonthsEmployed = DateDiff("m", GetActor.DateFirstFilm, Now())>

  <!--- Determine severance package --->
  <CFIF MonthsEmployed GTE 12>
    <CFSET SevPackage = "Gold Watch (Digital)">
  <CFELSEIF MonthsEmployed GTE 6>  
    <CFSET SevPackage = "$100 Starbucks Gift Certificate">
  <CFELSE>  
    <CFSET SevPackage = "ColdFusion Web Application Construction Kit">
  </CFIF>
  

  <!--- Location of our RTF "template" document --->
  <CFSET ThisFolder   = GetDirectoryFromPath(GetCurrentTemplatePath())>   
  <CFSET TemplatePath = ThisFolder & "DocTemplate.rtf">  
  
  <!--- Read RTF template into variable called "RTF" --->
  <CFFILE 
    ACTION="Read"
    FILE="#TemplatePath#"
    VARIABLE="RTF">
  
  <!--- Replace "placeholders" with specific information --->  
  <CFSET TodaysDate = DateFormat(Now(), "dddd, mmmm d, yyyy")>
  <CFSET RTF = Replace(RTF, "%CurrentDate%", TodaysDate)>
  <CFSET RTF = Replace(RTF, "%FreePrize%", SevPackage)>  
  <CFSET RTF = Replace(RTF, "%NameFirst%", GetActor.NameFirst)>  
  <CFSET RTF = Replace(RTF, "%NameLast%",  GetActor.NameLast )>  
  <CFSET RTF = Replace(RTF, "%NameFirstReal%", GetActor.NameFirstReal)> 
  <CFSET RTF = Replace(RTF, "%NameLastReal%", GetActor.NameLastReal )>  

  <!--- Suggest default filename for document --->
  <CFHEADER NAME="Content-Disposition" VALUE="filename=RetireMemo.doc">

  <!--- Set the content-type so Word is invoked --->
  <CFCONTENT TYPE="application/msword"><CFOUTPUT>#RTF#</CFOUTPUT>

</CFIF>
