<%-- 
    Document   : PassengerHome
    Created on : Jan 25, 2010, 3:43:54 AM
    Author     : e1502608
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="../design/css/pass_home.css" type="text/css" rel="stylesheet" />
        <title>Yolcu Ana Sayfası</title>
    </head>
<body>
<div id="genel">




<table id="anatablo">
    <tr ><td colspan="2" border-width="0px">
<div id="baslik">
<a href="PassengerHome.jsp"><img src="../design/Pictures/homesmall.jpg" width="65px" height="65px" align="left"/></a><font id="basliktext"> TREN BİLGİ SİSTEMİ</font>
</div>
        </td> </tr>
<tr ><td id="linkcolumn">
<div id="links">

<p><a href='http://www.ceng.metu.edu.tr/~e1502103' target="_blank"><input type="button" value="Tren Takip Sistemi" id="linkbutton" /></a>
</p>
<p>
<input type="button" value="Kişisel Bilgiler" id="linkbutton" ONCLICK="window.location.href='../findperson'"/>
</p><p>
<input type="button" value="Seyir Defteri"  id="linkbutton" ONCLICK="window.location.href='../SeyirDefteri'"/>
</p><p>
    <input type="button" value="Sorun Giderme"  id="linkbutton" ONCLICK="window.location.href='KnowledgeDB.jsp'"/>
</p><p>
<input type="button" value="Bize Ulaşın"  id="linkbutton"/>
</p>

<table id="haberler">
<tr>
<th>Bizden Haberler </th></tr>
<%
System.out.println("buraaaa");
 HttpSession session2=request.getSession(true);
 System.out.println("buraaaa");
 ejb.News news[]=(ejb.News[]) session.getAttribute("news");
 System.out.println("buraaaa");
 if(news!=null)
 {
          for(int i=0;i<3;i++)
          {   
             if(news[i]!=null){
              String str=news[i].getTitle();
      %>
            <tr><td><a href=""><font id="news"><%=str%></font></a></td></tr>
        <%                      }
          }
  }%>
</table>



</div>
</td>

<td>




<div id="secondcell">
<p align="center">
<b>Ana Sayfaya Hoşgeldiniz! </b><br />
Aşağıdaki Yolculuk Planlama Sistemi'ni kullanarak kendinize en uygun tren yolculuğunu seçebilirsiniz.<br />
Listele tuşuna bastıktan sonra aşağıda çıkacak olan tablodan size en uygun olan yolu işaretleyiniz.<br/>
Sonucu kendi sayfanıza kaydedebilir daha sonra bu sonucu tekrar kullanabilirsiniz.<br/>
İyi Yolculuklar Dileriz!
</p>
<form name="fromto" action="../PathFinder" method="POST">

<table id="planinfo" align="center">

<tr>
<th colspan ="3" align="left">Yolculuk Planlama Sistemi</th>
</tr>

<tr>
<td id="left">Kalkış yeri: </td>
<td id="right" colspan="2">

 <select name="from">

    <option selected value="" >. . . . Lütfen bir şehir seçiniz . . . .</option>
<option value="Ankara">Ankara</option>
<option value="Tokat">Tokat</option>
<option value="Cankiri">Cankiri</option>
<option value="Yozgat">Yozgat</option>
<option value="Nevsehir">Nevsehir</option>
<option value="Corum">Corum</option>
<option value="Kayseri">Kayseri</option>
<option value="Sivas">Sivas</option>
    </select>


</td>

<!-- <input type="text" name="from" id="im" value="" size="20" height="30"/> -->

</tr>


<tr>
<td id="left">Varış Yeri: </td>
<td id="right" colspan="2">

   <select name="to">
<option selected value="" >. . . . Lütfen bir şehir seçiniz . . . .</option>
<option value="Ankara">Ankara</option>
<option value="Tokat">Tokat</option>
<option value="Cankiri">Cankiri</option>
<option value="Yozgat">Yozgat</option>
<option value="Nevsehir">Nevsehir</option>
<option value="Corum">Corum</option>
<option value="Kayseri">Kayseri</option>
<option value="Sivas">Sivas</option>
    </select>

</td>


<!-- <input type="text"  name="to" id="im" size="20" value="" height="30"/> -->
</tr>
<tr>
<td id="left">Tarih: </td>
<%
if(session2.getAttribute("depdate")!=null){
    String depdate=session2.getAttribute("depdate").toString();
%>

<td id="right"><input type="text" name="depdate" id="im" size="20" value="<%=depdate%>"height="30"/>
    <img src="calender2.jpg" width="20px" height="30px"> </td>
<td id="right"></td>
<% } else { %>
<td id="right"><input type="text" name="depdate" id="im" size="20" value="" height="30"/>
    <img src="calender2.jpg" width="20px" height="30px"> </td>
<td id="right"></td>
<% } %>



</tr>


<tr>
<td id="left">Zaman Aralığı:</td>

<%
if(session2.getAttribute("deptime")!=null){
    String  deptime=session2.getAttribute("deptime").toString();
    String  arrtime=session2.getAttribute("arrtime").toString();

%>
<td id="right" colspan="2"><input type="text" name="deptime" size="6" id="im" width="20" value="<%=deptime%>" height="30" /> 'den
<input type="text" name="arrtime" size="6"id="im" width="20" height="30" value="<%=arrtime%>" /> 'e</td>
<% } else { %>
<td id="right" colspan="2"><input type="text" name="deptime" size="6" id="im" width="20" height="30" /> 'den
<input type="text" name="arrtime" size="6"id="im" width="20" height="30" /> 'e</td>
<% } %>
</tr>

<tr>
<td id="left">Maximum Ücret: </td>
<%
if(session2.getAttribute("cost")!=null){
    String  cost=session2.getAttribute("cost").toString();
%>
<td id="right"><input type="text" name="cost" size="20" value="<%=cost%>" id="im" /> TL
  <% } else { %>
  <td id="right"><input type="text" name="cost" size="20" value="" id="im" /> TL
<% } %>

</td>

<tr>
<td id="left">Maksimum Aktarma :</td>
<%
if(session2.getAttribute("change")!=null){
    String  change=session2.getAttribute("change").toString();
%>
<td id="right"><input type="text" name="change" size="20" value="<%=change%>" id="im"/></td>
  <% } else { %>
<td id="right"><input type="text" name="change" size="20"  value="" id="im"/></td>
<% } %>
<tr>
<td id="left">Maksimum Bekleme Süresi:</td>
<%
if(session2.getAttribute("wait")!=null){
    String wait=session2.getAttribute("wait").toString();
%>
<td id="right"><input type="text" size="20" name="wait" value="<%=wait%>"id="im"/>Saat</td>
 <% } else { %>
<td id="right"><input type="text" size="20" name="wait" id="im"/>Saat</td>
<% } %>
</tr>

</table>

<p id="logout"><a href="../Logout">Logout</a></p>



<p id="buttonp">
<input  value="Listele" type="submit" id="nbtn"/>
<a href="../Clear">Temizle</a>
</p>

</form>



</div>


        <%
            
            int numOfWays=0;
            java.util.Vector<web.Way> ways=null;
            String traveldate=null;
            String sourceCity=null;
            if(session2.getAttribute("ways")!=null)
                {
                    ways=(java.util.Vector<web.Way>)session2.getAttribute("ways");
                    numOfWays=ways.size();
                    if(session2.getAttribute("depdate")!=null)
                        {
                            System.out.println("depdate set edildi");
                            traveldate=session2.getAttribute("depdate").toString();
                        }
                    if(session2.getAttribute("from")!=null)
                        {
                            System.out.println("from set edildi");
                            sourceCity=session2.getAttribute("from").toString();
                        }
                    //System.out.println("numof " + numOfPaths);
                 }

            if(numOfWays!=0)
                {
                    %>
<form name="SaveSeferForm" action="../SaveSefer" method=\"POST\">

<%


                for(int i=0;i<numOfWays;i++)
                    {

                    %>

            <table id="results" align="center">
            <tr bgcolor="Navy">
            <th><font color="White"> Seçenek</font></th>
            <th><font color="White"> Tarih</font></th>
            <th><font color="White"> Tren No</font></th>
            <th><font color="White"> Kalkış Yeri</font></th>
            <th><font color="White"> Kalkış Saati</font></th>
            <th><font color="White"> Varış Yeri</font></th>
            <th><font color="White"> Varış Saati</font></th>
            <th><font color="White"> Yolculuk Süresi</font></th>
            <th><font color="White"> Ücret</font></th>
            <th><font color="White"> Aktarma</font></th>
            </tr>

<%





                        //int lengthOfPath=Integer.parseInt(session2.getAttribute("length"+Integer.toString(i)).toString());
                        web.Way currentway=ways.get(i);
                        java.util.Vector<web.subpath> currentsubs=currentway.pathSoFar;
                        int numofcities=currentway.pathSoFar.size();
                        

                        java.util.Vector<Long> trainIds=new java.util.Vector<Long>();
                        String sourceName=sourceCity;
                        for(int j=0;j<numofcities;j++)
                        {
                            web.subpath currentSubPath=(web.subpath)currentsubs.get(j);
                            Long cityId=currentSubPath.getCityId();
                            String currCityName=currentSubPath.getCityName();
                            Long trainId=currentSubPath.getTrainId();
                            if(!trainIds.contains(trainId))
                                trainIds.addElement(trainId);
                            java.sql.Time depTime=currentSubPath.getDepTime();
                            java.sql.Time arrTime=currentSubPath.getArrTime();
                            float cost=currentSubPath.getPartialCost();
                            int hourDiff=arrTime.getHours()-depTime.getHours();
                            int minDiff=arrTime.getMinutes()-depTime.getMinutes();

                            if(minDiff<0)
                                {
                                    minDiff+=60;
                                    hourDiff--;
                                 }
                            String timeString="";
                            if(hourDiff<10)
                                timeString=timeString.concat("0"+hourDiff+":");
                            else
                                timeString=timeString.concat(hourDiff+":");
                            if(minDiff<10)
                                timeString=timeString.concat("0"+minDiff);
                            else
                                timeString=timeString.concat(""+minDiff);
                            //calculate time

                            //yolculuk süresi aktarma ücret
                        %>


<tr>
<td><%=i%></td>
<td><%=traveldate%></td>
<td>TR00<%=trainId%></td>
<td><%=sourceName%></td>
<td><%=depTime%></td>
<td><%=currCityName%></td>
<td><%=arrTime%></td>
<td><%=timeString%></td>
<td><%=cost%></td>
<td>-</td>
</tr>
                                  <%
                                  sourceName=currCityName;
                                } //end of for each city in the list
                        java.sql.Time beginTime=((web.subpath)currentsubs.get(0)).getDepTime();
                        java.sql.Time endTime=((web.subpath)currentsubs.get(numofcities-1)).getArrTime();
                        int hourSum=endTime.getHours()-beginTime.getHours();
                        int minSum=endTime.getMinutes()-beginTime.getMinutes();
                        if(minSum<0)
                            {
                                minSum+=60;
                                hourSum--;
                            }
                        String timeString="";
                        if(hourSum<10)
                                timeString=timeString.concat("0"+hourSum+":");
                            else
                                timeString=timeString.concat(hourSum+":");
                        if(minSum<10)
                            timeString=timeString.concat("0"+minSum);
                        else
                            timeString=timeString.concat(""+minSum);

                        sourceCity=session2.getAttribute("from").toString();
                        String destinationCity=session.getAttribute("to").toString();
                        float costsum=currentway.getCostSoFar();
                        int changes=trainIds.size()-1;

                        %>
<tr bgcolor="RoyalBlue">
<td><input type="checkbox" name="wayIndices" value="<%=i%>"/><b>Özet:</b></td> <!-- burdan checkbox id göndereceğiz ways zaten set -->
<td><%=traveldate%></td>
<td>-</td>
<td><%=sourceCity%> </td>
<td><%=beginTime%></td>
<td><%=destinationCity%></td>
<td><%=endTime%></td>
<td><%=timeString%></td>
<td><%=costsum%></td>
<td><%=changes%></td>
</tr>
</table><br /><br />

                        <%}//end of second for
                        %>
                        

<p id="buttonp20" align="center">
<input type="Submit" value="Kaydet"  id="nbtn" />
</p>
        <%
                }//end of if not null
        %>

 </form>
        </td></tr>
</table>

       

</div>




</body>

</html>

