<!---
Name:        edit3.cfm
Author:      Ben Forta (ben@forta.com)
Description: Dual purpose movie edit form
Created:     4/20/01
--->

<!--- Check that FilmID was provided --->
<!--- If yes, edit, else add --->
<CFSET EditMode=IsDefined("URL.FilmID")>

<!--- If edit mode then get row to edit --->
<CFIF EditMode>

    <!--- Get the film record --->
    <CFQUERY DATASOURCE="ows" NAME="film">
    SELECT FilmID, MovieTitle, PitchText,
           AmountBudgeted, RatingID,
           Summary, ImageName, DateInTheaters
    FROM Films
    WHERE FilmID=#URL.FilmID#
    </CFQUERY>

    <!--- Save to variables --->
    <CFSET MovieTitle=Trim(film.MovieTitle)>
    <CFSET PitchText=Trim(film.PitchText)>
    <CFSET AmountBudgeted=Int(film.AmountBudgeted)>
    <CFSET RatingID=film.RatingID>
    <CFSET Summary=Trim(film.Summary)>
    <CFSET ImageName=Trim(film.ImageName)>
    <CFSET DateInTheaters=DateFormat(film.DateInTheaters, "MM/DD/YYYY")>
    
    <!--- Form text --->
    <CFSET FormTitle="Update a Movie">
    <CFSET ButtonText="Update">
    
<CFELSE>

    <!--- Save to variables --->
    <CFSET MovieTitle="">
    <CFSET PitchText="">
    <CFSET AmountBudgeted="">
    <CFSET RatingID="">
    <CFSET Summary="">
    <CFSET ImageName="">
    <CFSET DateInTheaters="">

    <!--- Form text --->
    <CFSET FormTitle="Add a Movie">
    <CFSET ButtonText="Insert">

</CFIF>

<!--- Get ratings --->
<CFQUERY DATASOURCE="ows" NAME="ratings">
SELECT RatingID, Rating
FROM FilmsRatings
ORDER BY RatingID
</CFQUERY>

<!--- Page header --->
<CFINCLUDE TEMPLATE="header.cfm">

<!--- Add/update movie form --->
<CFFORM ACTION="edit4.cfm">

<CFIF EditMode>
    <!--- Embed primary key as a hidden field --->
    <CFOUTPUT>
    <INPUT TYPE="hidden" NAME="FilmID" VALUE="#Film.FilmID#">
    </CFOUTPUT>
</CFIF>

<TABLE ALIGN="center" BGCOLOR="orange">
    <TR>
        <TH COLSPAN="2">
            <CFOUTPUT>
            <FONT SIZE="+1">#FormTitle#</FONT>
            </CFOUTPUT>
        </TH>
    </TR>
    <TR>
        <TD>
            Movie:
        </TD>
        <TD>
            <CFINPUT TYPE="Text"
                     NAME="MovieTitle"
                     VALUE="#MovieTitle#"
                     MESSAGE="MOVIE TITLE is required!"
                     REQUIRED="Yes"
                     SIZE="50"
                     MAXLENGTH="100">
        </TD>
    </TR>
    <TR>
        <TD>
            Tag line:
        </TD>
        <TD>
            <CFINPUT TYPE="Text"
                     NAME="PitchText"
                     VALUE="#PitchText#"
                     MESSAGE="TAG LINE is required!"
                     REQUIRED="Yes"
                     SIZE="50"
                     MAXLENGTH="100">
        </TD>
    </TR>
    <TR>
        <TD>
            Rating:
        </TD>
        <TD>
            <!--- Ratings list --->
            <CFSELECT NAME="RatingID"
                      QUERY="ratings"
                      VALUE="RatingID"
                      DISPLAY="Rating"
                      SELECTED="#VARIABLES.RatingID#">
            </CFSELECT>
        </TD>
    </TR>
    <TR>
        <TD>
            Summary:
        </TD>
        <TD>
            <CFOUTPUT>
            <TEXTAREA NAME="summary"
                      COLS="40"
                      ROWS="5"
                      WRAP="virtual">#Summary#</TEXTAREA>
            </CFOUTPUT>
        </TD>
    </TR>
    <TR>
        <TD>
            Budget:
        </TD>
        <TD>
            <CFINPUT TYPE="Text"
                     NAME="AmountBudgeted"
                     VALUE="#AmountBudgeted#"
                     MESSAGE="BUDGET must be a valid numeric amount!"
                     VALIDATE="integer"
                     REQUIRED="NO"
                     SIZE="10"
                     MAXLENGTH="10">
        </TD>
    </TR>
    <TR>
        <TD>
            Release Date:
        </TD>
        <TD>
            <CFINPUT TYPE="Text"
                     NAME="DateInTheaters"
                     VALUE="#DateInTheaters#"
                     MESSAGE="RELEASE DATE must be a valid date!"
                     VALIDATE="date"
                     REQUIRED="NO"
                     SIZE="10"
                     MAXLENGTH="10">
        </TD>
    </TR>
    <TR>
        <TD>
            Image File:
        </TD>
        <TD>
            <CFINPUT TYPE="Text"
                     NAME="ImageName"
                     VALUE="#ImageName#"
                     REQUIRED="NO"
                     SIZE="20"
                     MAXLENGTH="50">
        </TD>
    </TR>
    <TR>
        <TD COLSPAN="2" ALIGN="center">
            <CFOUTPUT>
            <INPUT TYPE="submit" VALUE="#ButtonText#">
            </CFOUTPUT>
        </TD>
   </TR>
</TABLE>

</CFFORM>

<!--- Page footer --->
<CFINCLUDE TEMPLATE="footer.cfm">

