<!--- 
  Filename:     NewMovieCommit2.cfm
  Created by:   Nate Weiss (NMW)
  Date Created: 2/18/2001
--->

<!--- Compute Total Budget --->
<!--- First, add the Director's salary and miscellaneous expenses --->
<CFSET TotalBudget = SESSION.MovWiz.MiscExpense + SESSION.MovWiz.DirectorSal>
<!--- Now add the salary for each actor in the movie --->
<CFLOOP LIST="#SESSION.MovWiz.ActorIDs#" INDEX="ThisActor">
  <CFSET ThisSal = SESSION.MovWiz.ActorSals[ThisActor]>
  <CFSET TotalBudget = TotalBudget + ThisSal>
</CFLOOP>

<!--- Insert Film Record --->
<CFQUERY DATASOURCE="#DataSource#">
  INSERT INTO Films(MovieTitle, PitchText, AmountBudgeted)
  VALUES ('#SESSION.MovWiz.MovieTitle#', '#SESSION.MovWiz.PitchText#', #TotalBudget#)
</CFQUERY>
<!--- Get ID number of just-inserted film --->
<CFQUERY DATASOURCE="#DataSource#" NAME="GetNew">
  SELECT Max(FilmID) As NewID FROM Films
</CFQUERY>
<!--- Insert Director Record --->
<CFQUERY DATASOURCE="#DataSource#">
  INSERT INTO FilmsDirectors(FilmID, DirectorID, Salary)
  VALUES (#GetNew.NewID#, #SESSION.MovWiz.DirectorID#, #SESSION.MovWiz.DirectorSal#)
</CFQUERY>
<!--- Insert Actor Records --->
<CFLOOP LIST="#SESSION.MovWiz.ActorIDs#" INDEX="ThisActor">
  <CFSET IsStar  = IIF(ThisActor EQ SESSION.MovWiz.StarActorID, 1, 0)>
  <CFQUERY DATASOURCE="#DataSource#">
    INSERT INTO FilmsActors(FilmID, ActorID, Salary, IsStarringRole)
    VALUES (#GetNew.NewID#, #ThisActor#, #SESSION.MovWiz.ActorSals[ThisActor]#, #IsStar#)
  </CFQUERY>
</CFLOOP>

<!--- Remove MovWiz variable from SESSION Structure --->
<!--- User will be started over on return to Wizard --->
<CFSET StructDelete(SESSION, "MovWiz")>


<!--- Display message to user --->
<HTML>
<HEAD><TITLE>Movie Added</TITLE></HEAD>
<BODY>
 <H2>Movie Added</H2>
 <P>The movie has been added to the database.

 <!--- Link to go through the Wizard again --->
 <P><A HREF="NewMovieWizard2.cfm">Enter Another Movie</A>
</BODY>
</HTML>
