<!--- 
  Filename:     FeaturedMovie.cfm
  Created by:   Nate Weiss (NMW)
  Date Created: 3/2/2001
  Please Note:  Modified from "Application Framework" chapter
--->

<!--- Need to lock when accessing shared data --->
<CFLOCK SCOPE="Session" TIMEOUT="10">

  <!--- List of movies to show (list starts out empty) --->
  <CFPARAM NAME="SESSION.MovieList" TYPE="string" DEFAULT="">
  
  <!--- If this is the first time we're running this,  --->
  <!--- Or we have run out of movies to rotate through --->
  <CFIF SESSION.MovieList EQ "">
    <!--- Get all current FilmIDs from the database --->
    <CFQUERY NAME="GetFilmIDs" DATASOURCE="#DataSource#">
      SELECT FilmID FROM Films
      ORDER BY MovieTitle
    </CFQUERY>

    <!--- Turn FilmIDs into a simple comma-separated list --->
    <CFSET SESSION.MovieList = ValueList(GetFilmIDs.FilmID)>
  </CFIF>

  <!--- Pick the first movie in the list to show right now --->
  <CFSET ThisMovieID = ListFirst(SESSION.MovieList)>
  <!--- Re-save the list, as all movies *except* the first --->
  <CFSET SESSION.MovieList = ListRest(SESSION.MovieList)>

</CFLOCK>


<!--- Now that we have chosen the film to "Feature", --->
<!--- Get all important info about it from database. --->
<CFQUERY NAME="GetFilm" DATASOURCE="#DataSource#">
  SELECT 
    MovieTitle, Summary, 
    AmountBudgeted, DateInTheaters
  FROM Films
  WHERE FilmID = #ThisMovieID#
</CFQUERY>

<!--- Now Display Our Featured Movie --->
<CFOUTPUT>
  <!--- Define formatting for our "feature" display --->
  <STYLE TYPE="text/css">
    TH.fm {background:RoyalBlue;color:white;text-align:left;
           font-family:sans-serif;font-size:10px}
    TD.fm {background:LightSteelBlue;
           font-family:sans-serif;font-size:12px}
  </STYLE>

  <!--- Show info about featured movie in HTML Table --->
  <TABLE WIDTH="150" ALIGN="right" BORDER="0" CELLSPACING="0">
    <TR><TH CLASS="fm">
      Featured Film
    </TH></TR>
    <!--- Movie Title, Summary, Rating --->
    <TR><TD CLASS="fm">
      <B>#GetFilm.MovieTitle#</B><BR>
      #GetFilm.Summary#<BR>
    </TD></TR>
    <!--- Cost (rounded to millions), release date --->
    <TR><TH CLASS="fm">
      Production Cost $#Round(GetFilm.AmountBudgeted / 1000000)# Million<BR>
      In Theaters #DateFormat(GetFilm.DateInTheaters, "mmmm d")#<BR>
    </TH></TR>
  </TABLE>
  <BR CLEAR="all">
</CFOUTPUT>
