<%@ page language="java" import="historyPlaces.*,java.util.*" %>
<%@ include file="header.inc" %>
<html>

<head>

<title>Browse timeline</title>
</head>

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

<%
boolean start = false;
if ((request.getParameter("javaType")!=null))
  start = true;

//periodSpec occur NO PLACE, YES TIME
//all is true when NO PLACE, NO TIME PERIOD is selected
//allSpec is true when YES PLACE, NO TIME
//period is true NO PLACE, YES TIME


boolean periodSpec = false;
if ( (request.getParameter("javaType") !=null)
	&& (!request.getParameter("javaType").equals(""))
	&& (request.getParameter("period")!=null)
	&& (request.getParameter("period").equals("Submit")))
	
	periodSpec = true;
	

boolean period = false;
if ( (request.getParameter("period") !=null)
	&& (request.getParameter("period").equals("Submit")) 
	&& (!periodSpec))
	period = true;


boolean all = false;

boolean allSpec = false;

if ( (request.getParameter("time") != null )
	&& ( request.getParameter("time").equals("See all"))
	 && (request.getParameter("javaType").equals("")   ) )

	all = true;


if ( (request.getParameter("javaType") != null)
	&& (!request.getParameter("javaType").equals(""))
	&& (request.getParameter("time") !=null)
	&& (request.getParameter("time").equals("See all")) )

	allSpec = true;
	

%>



<br>

<p><font face="Bookman Old Style"><h1>Browse Timeline:</h1></font></p>

<p><p>

<font face="Bookman Old Style">

<FORM ACTION="timeline.jsp" METHOD=POST>
    
    
	Name of Place: <select name="javaType" >
	<%
			String output = db.printAllPlace();
			out.println(output);
%>
			</select>
    
   
</font></p>
<p>
<INPUT TYPE=SUBMIT VALUE="See all" name = "time"></p>
<p>OR</p>
<p>From: <input type = "text" size="13" name ="from">

To: <input type = "text" name="to" size="15"><br>
Please enter the data in this format example: 2004-12-26
<p><INPUT TYPE=SUBMIT VALUE="Submit" name ="period"></p>

</form>	
<%
String link = "";
if (periodSpec && !all) {
  	String s1 = request.getParameter("from");
	String s2 = request.getParameter("to");
	String s3 = request.getParameter("javaType");
	LinkedList timeline = db.getPeriodSpec(s1,s2,s3);
	int n = timeline.size();
	out.println(" Result count is " + n + " for " + s3 + " from " + s1 + " to " + s2);
	if (n == 0) { out.write ("Sorry, No photo result for this place"); }
	else{

	  for (int i = 0; i < n; i++) {
		photo currPhoto = (photo)db.getPeriodSpec(s1,s2,s3).get(i);
		
		out.println("<br>" + "Photo Name:" + currPhoto.getFilename()+"<br>");
		//out.println("<p style=margin-left:15px;>");
		out.println("Date: " + currPhoto.getDate() + "<br>");
		out.println("Comment: " + currPhoto.getComment() + "<br>");
		link = currPhoto.getURL();
		if (link !="") {
   			out.write("<a href =" + link + ">Photo</a>");
			out.write("<br><img width = 100 height = 100 src =" + link + "></src>");
		}

	  }
	}


}
//returns all photos given a time period
if (period && !all) {
	String s1 = request.getParameter("from");
	String s2 = request.getParameter("to");
	LinkedList timeline = db.getAllInPeriod(s1,s2);
	int n = timeline.size();
	
	out.println(" Result count is " + n + " for all places "  + " from " + s1 + " to " + s2);
	if (n == 0) { out.write ("Sorry, No photo result for this place"); }
	else{

	  for (int i = 0; i < n; i++) {
		photo currPhoto = (photo)db.getAllInPeriod(s1,s2).get(i);
		
		out.println("<br>" + "Photo Name:" + currPhoto.getFilename()+"<br>");
		//out.println("<p style=margin-left:15px;>");
		out.println("Date: " + currPhoto.getDate() + "<br>");
		out.println("Comment: " + currPhoto.getComment() + "<br>");
		 link = currPhoto.getURL();
		 if (link !="") {
   			out.write("<a href =" + link + ">Photo</a>");
			out.write("<br><img width = 100 height = 100 src =" + link + "></src>");
		}
	  }

	}

	
}

//returns all photos in the photo table
if (all) {
		
	LinkedList timeline = db.getAllPhoto();
	int n = timeline.size();
	
	out.println(" Result count is " + n + " for all places available at any time");
	if (n == 0) { out.write ("Sorry, No photo result for this place"); }
	else{

	 for (int i = 0; i < n; i++) {
		photo currPhoto = (photo)db.getAllPhoto().get(i);
		
		out.println("<br>" + "Photo Name:" + currPhoto.getFilename()+"<br>");
		//out.println("<p style=margin-left:15px;>");
		out.println("Date: " + currPhoto.getDate() + "<br>");
		out.println("Comment: " + currPhoto.getComment() + "<br>");
		 link = currPhoto.getURL();
		 if (link !="") {
   			out.write("<a href =" + link + ">Photo</a>");
			out.write("<br><img width = 100 height = 100 src =" + link + "></src>");
		}
     }
	}
	

}
//returns all photos for a specific place
if (allSpec){
 String q = request.getParameter("javaType");
 //out.write("INSIDE ALL SPEC");
 if (q != null) {
  LinkedList timeline = db.getSpecPlaceAllTime(q);
  int n = timeline.size();
  out.println(" Result count is " + n + " for " + q + " at any time");
   if (n == 0) { out.write ("Sorry, No photo result for this place"); }
   else{
    for (int i = 0; i < n; i++) {
      photo currPhoto = (photo)db.getSpecPlaceAllTime(q).get(i);
  
      out.println("<br>" + "Photo Name:" + currPhoto.getFilename()+"<br>");
      //out.println("<p style=margin-left:15px;>");
      out.println("Date: " + currPhoto.getDate() + "<br>");
      out.println("Comment: " + currPhoto.getComment() + "<br>");
      link = currPhoto.getURL();
	  if (link !="") {
   			out.write("<a href =" + link + ">Photo</a>");
			out.write("<br><img width = 100 height = 100 src =" + link + "></src>");
		}
       

    }
  }

 } 
 else 
 { //nothing 
 
 }
  
}
else {

//nothing
}


%>
   


</body>


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

</html>