<!--- 
  Filename:     NewMovieWizard.cfm
  Created by:   Nate Weiss (NMW)
  Date Created: 3/2/2001
  Please Note:  Session variables must be enabled
--->

<!--- Total Number of Steps in the Wizard --->
<CFSET NumberOfSteps = 5>

<!--- The SESSION.MovWiz struct holds user's entries --->
<!--- as they move thru wizard. Make sure it exists! --->
<CFIF NOT IsDefined("SESSION.MovWiz")>
  <!--- If structure undefined, create/initialize it --->
  <CFSET SESSION.MovWiz = StructNew()>
  <!--- Represents current wizard step; start at one --->
  <CFSET SESSION.MovWiz.StepNum = 1>
  <!--- We will collect these from user; start blank --->
  <CFSET SESSION.MovWiz.MovieTitle  = "">
  <CFSET SESSION.MovWiz.PitchText   = "">
  <CFSET SESSION.MovWiz.DirectorID  = "">
  <CFSET SESSION.MovWiz.ActorIDs    = "">
  <CFSET SESSION.MovWiz.StarActorID = "">
</CFIF>


<!--- If user just submitted MovieTitle, remember it --->
<!--- Do same for the DirectorID, Actors, and so on. --->
<CFIF IsDefined("Form.MovieTitle")>
  <CFSET SESSION.MovWiz.MovieTitle = Form.MovieTitle>
  <CFSET SESSION.MovWiz.PitchText  = Form.PitchText>
<CFELSEIF IsDefined("Form.DirectorID")>
  <CFSET SESSION.MovWiz.DirectorID = Form.DirectorID>
<CFELSEIF IsDefined("Form.ActorID")>
  <CFSET SESSION.MovWiz.ActorIDs = Form.ActorID>
<CFELSEIF IsDefined("Form.StarActorID")>
  <CFSET SESSION.MovWiz.StarActorID = Form.StarActorID>
</CFIF>


<!--- If user clicked "Back" button, go back a step --->
<CFIF IsDefined("Form.GoBack")>
  <CFSET SESSION.MovWiz.StepNum = URL.StepNum - 1>
<!--- If user clicked "Next" button, go forward one --->
<CFELSEIF IsDefined("Form.GoNext")>
  <CFSET SESSION.MovWiz.StepNum = URL.StepNum + 1>
<!--- If user clicked "Finished" button, we're done --->
<CFELSEIF IsDefined("Form.GoDone")>
  <CFLOCATION URL="NewMovieCommit.cfm">
</CFIF>


<HTML>
<HEAD><TITLE>New Movie Wizard</TITLE></HEAD>
<BODY>

<!--- Show title and current step --->
<CFOUTPUT>
  <B>New Movie Wizard</B><BR>
  Step #SESSION.MovWiz.StepNum# of #NumberOfSteps#<BR>
</CFOUTPUT>


<!--- Data Entry Form, which submits back to itself --->
<CFFORM 
  ACTION="NewMovieWizard.cfm?StepNum=#SESSION.MovWiz.StepNum#" 
  METHOD="POST">
 
  <!--- Display the appropriate wizard step --->
  <CFSWITCH EXPRESSION="#SESSION.MovWiz.StepNum#">
    <!--- Step One: Movie Title --->
    <CFCASE VALUE="1">
      <!--- Show text entry field for title --->
      What is the title of the movie?<BR>
      <CFINPUT 
        NAME="MovieTitle" 
        SIZE="50"
        VALUE="#SESSION.MovWiz.MovieTitle#">

      <!--- Show text entry field for short description --->
      <P>What is the "pitch" or "one-liner" for the movie?<BR>
      <CFINPUT 
        NAME="PitchText" 
        SIZE="50"
        VALUE="#SESSION.MovWiz.PitchText#">
    </CFCASE>  

    <!--- Step Two: Pick Director --->
    <CFCASE VALUE="2">
      <!--- Get list of directors from database --->
      <CFQUERY NAME="GetDirectors" DATASOURCE="#DataSource#">
        SELECT DirectorID, FirstName+' '+LastName As FullName
        FROM Directors
        ORDER BY LastName
      </CFQUERY>
    
      <!--- Show all Directors in SELECT list --->
      <!--- Pre-select if user has chosen one --->
      Who will be directing the movie?<BR>
      <CFSELECT
        SIZE="#GetDirectors.RecordCount#"
        QUERY="GetDirectors"
        NAME="DirectorID"
        DISPLAY="FullName"
        VALUE="DirectorID"
        SELECTED="#SESSION.MovWiz.DirectorID#"/>
    </CFCASE>  

    <!--- Step Three: Pick Actors --->
    <CFCASE VALUE="3">
      <!--- Get list of actors form database --->
      <CFQUERY NAME="GetActors" DATASOURCE="#DataSource#">
        SELECT * FROM Actors
        ORDER BY NameLast
      </CFQUERY>

      What actors will be in the movie?<BR>
      <!--- For each actor, display checkbox --->
      <CFLOOP QUERY="GetActors">
        <!--- Should checkbox be pre-checked? --->
        <CFSET IsChecked = ListFind(SESSION.MovWiz.ActorIDs, ActorID)>
        <!--- Checkbox itself --->
        <CFINPUT 
          TYPE="Checkbox"
          NAME="ActorID"
          VALUE="#ActorID#"
          CHECKED="#IsChecked#">
        <!--- Actor name --->
        <CFOUTPUT>#NameFirst# #NameLast#</CFOUTPUT><BR>
      </CFLOOP>  
    </CFCASE>  

    <!--- Step Four: Who is the star? --->
    <CFCASE VALUE="4">
      <CFIF SESSION.MovWiz.ActorIDs EQ "">
        Please go back to the last step and choose at least one
        actor or actress to be in the movie.  
      <CFELSE>
        <!--- Get actors who are in the film --->
        <CFQUERY NAME="GetActors" DATASOURCE="#DataSource#">
          SELECT * FROM Actors
          WHERE ActorID IN (#SESSION.MovWiz.ActorIDs#)
          ORDER BY NameLast
        </CFQUERY>
  
        Which one of the actors will get top billing?<BR>    
        <!--- For each actor, display radio button --->
        <CFLOOP QUERY="GetActors">
          <!--- Should radio be pre-checked? --->
          <CFSET IsChecked = SESSION.MovWiz.StarActorID EQ ActorID>
          <!--- Radio button itself --->
          <CFINPUT 
            TYPE="Radio"
            NAME="StarActorID"
            VALUE="#ActorID#"
            CHECKED="#IsChecked#">
          <!--- Actor name --->
          <CFOUTPUT>#NameFirst# #NameLast#</CFOUTPUT><BR>
        </CFLOOP>  
      </CFIF>
    </CFCASE>  
    
    <!--- Step Five: Final Confirmation --->
    <CFCASE VALUE="5">
      You have successfully finished the New Movie Wizard.<BR>
      Click the Finish button to add the movie to the database.<BR>
      Click Back if you need to change anything.<BR>
    </CFCASE>  
  </CFSWITCH>
  

  <P>
  <!--- Show Back button, unless at first step --->  
  <CFIF SESSION.MovWiz.StepNum GT 1>
    <INPUT TYPE="Submit" NAME="GoBack" VALUE="&lt;&lt; Back">
  </CFIF>  
  <!--- Show Next button, unless at last step --->
  <!--- If at last step, show "Finish" button --->
  <CFIF SESSION.MovWiz.StepNum LT NumberOfSteps>
    <INPUT TYPE="Submit" NAME="GoNext" VALUE="Next &gt;&gt;">
  <CFELSE>
    <INPUT TYPE="Submit" NAME="GoDone" VALUE="Finish">
  </CFIF>
</CFFORM>

</BODY>
</HTML>
