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

<!--- Query the database to get a listing of actors to choose from --->
<cfquery datasource="ows" name="actorsQuery">
 SELECT ActorID, NameFirst, NameLast 
 FROM Actors
 ORDER BY NameLast, NameFirst
</cfquery>

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

<!--- If the photo directory doesn't exist yet... --->
<cfif not directoryExists(actorPhotoDir)>
 <!--- ...go ahead and create the photo directory --->
 <cfdirectory action="create" directory="#actorPhotoDir#">
</cfif>

<html>
<head>
 <title>Maintain Actor Photos</title>
</head>
<body>
<h2>Maintain Actor Photos</h2>
<h3>Click on Actor Name to Add Photo</h3>
<table border="1" width="300">
 <tr>
  <th>Name</th>
  <th>Photo</th>
 </tr>
 <!--- For each actor in the database... ---> 
 <cfoutput query="actorsQuery">
 
  <!--- Get a listing of any current image files for this actor --->
  <cfdirectory action="List" directory="#actorPhotoDir#"
   name="existingPhotos" filter="Actor#ActorsQuery.ActorID#Photo.*">
 
  <tr>
   <td>
    <!--- Provide link to upload page, passing actor's ID in the URL --->
    <a href="ActorPhotoForm.cfm?ActorID=#ActorID#">#NameFirst# #NameLast#</a>
   </td>
   <td height="50">
    <!--- If there is a photo for this actor --->
    <cfif existingPhotos.recordCount neq 0>
     <!--- Display a thumbnail view of the photo --->
     <a href="ActorPhotoForm.cfm?actorID=#actorID#">
     <img src="ActorPhotos/#ExistingPhotos.Name#"
      width="50" height="50"
      border="0" alt="Click to edit"></a>
    <cfelse>
    [no photo]  
    </cfif> 
   </td>
  </tr>
 </cfoutput>
</table>
</body>
</html>
