<!--- 
 Filename: ActorPhotoForm.cfm
 Edited By: Nate Weiss (NMW)
 Purpose:  Creates an interface for uploading actor photos
--->

<!--- Insist that an ActorID parameter is passed in the URL --->
<cfparam name="URL.actorID" type="numeric">

<!--- Query the database for information about the specified actor --->
<cfquery name="actorQuery" datasource="ows">
 SELECT ActorID, NameLast, NameFirst
 FROM Actors 
 WHERE ActorID = #val(URL.actorID)#
</cfquery>

<!--- Location of the directory where actor photos are stored --->
<!--- The folder name is ActorPhotos, within this page's folder --->
<cfset actorPhotoDir = expandPath("ActorPhotos")>

<!--- Get a listing of any current image files for this actor --->
<cfdirectory action="list" directory="#actorPhotoDir#"
 name="existingPhotos" filter="Actor#URL.ActorID#Photo.*">

<html>
<title>Actor Photo Maintenance Form</title>
<body>
<h2>Actor Photo Maintenance Form</h2>
<!--- Link to return to the list of actors --->
<a href="ActorPhotoList.cfm">Return To List</a>
<cfoutput>
 <!--- This form submits to ActorPhotoAction.cfm, --->
 <!--- passing the ActorID along in the URL. --->
 <cfform action="ActorPhotoAction.cfm?actorID=#URL.actorID#" 
  enctype="multipart/form-data" method="post">
  <!--- Text input field for first name --->
  <p>First Name:<br>
  <cfinput type="text" name="nameFirst" value="#actorQuery.NameFirst#"
   size="30" maxlength="50" required="Yes"
   message="Please don't leave the first name blank.">
   
  <!--- Text input field for last name --->
  <p>Last Name:<br>
  <cfinput type="text" name="nameLast" value="#actorQuery.NameLast#"
   size="30" maxlength="50" required="yes"
   message="Please don't leave the last name blank.">
     
  <!--- File field for user to select or specify a filename --->
  <p>Photo File to upload:<br>
  <cfinput type="file" name="photoFile" size="50"><br>
  <!--- If there are any existing photos for this user, ---> 
  <!--- provide a checkbox for deleting the existing photo --->
  <cfif existingPhotos.recordCount gt 0>
    <cfinput type="checkbox" name="deletePhoto">Delete existing photo 
  </cfif>  
 
  <!--- Submit button to submit the form (and upload the file) --->
  <p>
  <cfinput type="submit" name="submit" value="Update Actor Data">
   
  <!--- Display the photo if available ---> 
  <cfif existingPhotos.recordCount gt 0>
   <p>Existing photo shown below:<br>
   <img src="ActorPhotos/#existingPhotos.Name#" 
    border="0" alt="Photo of #actorQuery.NameFirst# #actorQuery.NameLast#">
  </cfif>
   
 </cfform>
</cfoutput>
</body>
</html>
