/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package web;

import ejb.KnowledgeFacade;
import ejb.UsersFacade;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import beans.LocationBean;
import ejb.NewsEntityFacade;
import java.util.Iterator;
import javax.servlet.http.HttpSession;

@WebServlet(name="PostMessage", urlPatterns={"/PostMessage"})
public class PostMessage extends HttpServlet {

    @EJB
    private NewsEntityFacade newsEntityFacade;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{

response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
       String userName=null;
        HttpSession session2=request.getSession(true);
        if(session2.getAttribute("userName")!=null && session2.getAttribute("activated") != null &&
                session2.getAttribute("activated").toString().equals("true"))
            userName=session2.getAttribute("userName").toString();
        else {
                response.sendRedirect("jsps/Login.jsp?Error=2");
                return;
        }

        //LocationBean mybean = new LocationBean();
        //Iterator i = mybean.getLocaleNames().iterator();


        PrintWriter out = response.getWriter();

         try{
                       out.println(
                    "<html>"+
                    "<head>"+
                    "<link href=\"design/css/seyirdefteri.css\" type=\"text/css\" rel=\"stylesheet\" />"+
                    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-9\">"+
                    "</head>"+

                    "<body>"+
                    "<div id=\"genel\">"+

                    "<div id=\"baslik\">"+
                    "<img src=\"design/Pictures/homesmall.jpg\" width=\"70px\" height=\"70px\"/><font id=\"basliktext\">Soru Oluşturma</font>"+
                    "</div>"+

                    "<table id=\"anatablo\">"+
                    "<tr><td>"+
                            "<div id=\"links\">"+
                            "<p>"+
                                "<input type=\"button\" value=\"Tren Takip Sistemi\"  id=\"linkbutton\"  />"+
                            "</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='jsps/KnowledgeDB.jsp' \" />"+
                            "</p><p>"+
                                "<input type=\"button\" value=\"Bize Ulaşın\"  id=\"linkbutton\"/>"+
                            "</p>"+
                        "</div>"+
                    "</td>");

                    out.println("<td> <div id=\"secondcell\">");
                    out.println(
                    "<form id=\"addnewsform\" action=\"PostMessage2\" method=\"POST\">" +
                    "<table id='news'>"+
                           "<tr>"+
                               "<td id= '1'> Konu:  </td>");

                                out.println("<td> <select name=\"topic\">");
                                out.println("<option>Giriş Sayfası</option>");
                                out.println("<option>Ana Sayfa</option>");
                                out.println("<option>Tren Takip Sistemi</option>");

                                out.println("<option>Haber Bağlantıları</option>");
                                out.println("<option>Kayıt Olma</option>");
                                out.println("<option>Kişisel Bilgileri Değiştirme</option>");

                                out.println("<option>Bulunan Yolları Kaydetme</option>");
                                out.println("<option>Kullanım Klavuzlarına Ulaşma</option>");
                                out.println("<option>Sorun Bildirme</option>");
                                out.println("<option>Diğerleri</option>");
                                out.println("</select ></td></tr>");

                        out.println(
                         " </tr><tr>"+
                                "<td id='1'>Başlık: </td>"+
                                "<td id='2'><input type=\"text\" name=\"title\" size=\"30\" ></td>"+
                          "</tr><tr>"+
                                "<td id='1'>Sorun: </td>"+
                                "<td id='2'><textarea name='body' rows=\"7\" cols=\"34\"></textarea></td>"+
                           "</tr><tr>" +
                           "<td colspan=\"2\" align='right'>"+"<input type=\"submit\" value=\"Gönder\" >"+
                           "</td></tr>"+
                    "</table>"+

                    "<form>"
                            );
                    out.println("</td></tr></table></div></body></html>");

        } finally {
            out.close();
        }

    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(PostMessage.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(PostMessage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
