<!-- the code below was adopted from sample codes from javazoom.net-->


<%@ page language="java" import="javazoom.upload.*,java.util.*" import="historyPlaces.*" %>
<%@ page errorPage="ExceptionHandler.jsp" %>


<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
  <jsp:setProperty name="upBean" property="folderstore" value="d:/uploads" />
  <jsp:setProperty name="upBean" property="parser" value="<%= MultipartFormDataRequest.CFUPARSER %>"/>
  <jsp:setProperty name="upBean" property="parsertmpdir" value="d:/temp"/>
</jsp:useBean>

<%@ include file="header.inc" %>
<html>
<head>
<title>Upload a photo </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%-- Initialize DB --%>
    <%
            hp db = new hp();
    %>


<p><font face="Bookman Old Style"><h1>Submit Photo:</h1></font></p>
<b>* fields are not optional</b>

<p>
<form method="post" action="uploadimage.jsp" name="upform" enctype="multipart/form-data">
<font face="Bookman Old Style">

<b>*Name of Place: </b><select name="place" >

 <%
   String output = db.printAllPlace();
   out.println(output);
%>
   </select>


<br>


Name of Photo: <input type="text" name="photo" size="35"><br>

Photographer: <input type = "text" name = "photographer" size="35"><br>

Comment:<br>


  <textarea name="comment" rows="5" cols="50" class = 'textinput' tabindex ='3'></textarea>


<br>
Please enter the date the photo was taken <br>
<b>*</b>Date Taken: format example: 2004-12-26: <input type = "text" name = "date" size="10"><br>

 </font><p><font face="Bookman Old Style">*Enter Photo Location information 
(either give the URL or browse for image)</font></p>
<font face="Bookman Old Style">

<p>Photo URL Address: <input type = "text" name = "url" size="72">  </p>
<p>OR</p>


<p>Upload a photo for this place:
<input type="file" name="uploadfile" size="50">
<input type="hidden" name="todo" value="upload"> 
                  


<p>       


<p> 
<input type="submit" name="Submit" value="Submit">      
<input type="reset" name="Reset" value="Cancel">                                  

</FORM>
 
</font>

<%
if (MultipartFormDataRequest.isMultipartFormData(request)) {
  
  String url="";
  String uploadFile="";
         // Uses MultipartFormDataRequest to parse the HTTP request.
         MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
         String todo = null;
         //"todo" is the name of the field that people put file path in
         //"upload" is the value associated with field name ="todo" value = "upload"
         
  if (mrequest != null) todo = mrequest.getParameter("todo");

  if ( (todo != null) && (todo.equalsIgnoreCase("upload")) ) {
                Hashtable files = mrequest.getFiles();
                if ( (files != null) && (!files.isEmpty()) )
                {
                    UploadFile file = (UploadFile) files.get("uploadfile");
                    if (file != null) {
                    out.println("<li>Form fields : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
                    uploadFile = file.getFileName();
                    url = uploadFile;
                    }// Uses the bean now to store specified by jsp:setProperty at the top.
                    upBean.store(mrequest, "uploadfile");
                    //String uploadFile = mrequest.getParameter("uploadfile");
                }
                else
                {
                  out.println("<li>No uploaded files");
                }
  if (mrequest != null)
  { 
    String place = mrequest.getParameter("place");
    String photo = mrequest.getParameter("photo");
    String photographer = mrequest.getParameter("photographer");
    String date = mrequest.getParameter("date");
    url = mrequest.getParameter("url");
      
    String comment = mrequest.getParameter("comment");
    
    
    
    %>
      
     <%=place %>
   <%=photo %>
   <%=photographer %>
   <%=date %>
   <%=url %>
   <%=comment %> 
   
   
   <%
   
   int s;
    if (url !=""){
	 out.println("place name is " + place);
	  //AddPhoto returns 0 or less if can't insert values into database
      s = db.AddPhoto(photo,url,comment,date,photographer, place);
      //out.println("matching index is " + s);
	  if (s >0) {
        %><br><%out.println("Photo added successfully");}
      else{
        %><br><%out.println("Photo was not added");}
    }
    
  }
 }
  else {
    out.println("<BR> todo="+todo);
  }
}
%>

<%@ include file="footer.inc" %>
</body>

</html>