%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,org.opencms.main.*, java.text.*"%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String idResposta = pageContext.getAttribute("idResposta").toString() != null ? pageContext.getAttribute("idResposta").toString() : "0";
int idRes = 0;
String gotoPage = "";
%>
<%
Connection con = OpenCms.getSqlManager().getConnection("sic");
PreparedStatement stmt =null;
ResultSet rs = null;
//Query
String queryInsert = "INSERT INTO tvoto_enquete_almg(id_resposta, ip_usuario) VALUES(?,?)";
String querySelect = "SELECT * FROM tvoto_enquete_almg WHERE id_resposta = ?";
try{
idRes = Integer.parseInt(idResposta);
if(!idResposta.equals("0")){
try{
stmt = con.prepareStatement(queryInsert);
stmt.setInt(1, idRes);
stmt.setString(2, request.getRemoteAddr());
boolean r = stmt.execute();
//out.print("r: "+r);
}catch (SQLException ex) {
ex.printStackTrace();
}finally{
//rs.close();
stmt.close();
con.close();
//gotoPage = "/participe/enquete_aleijadinho/resultado.html?idResposta="+idResposta;
gotoPage = "/participe/enquete_aleijadinho/resultado.html";
session.setAttribute("msgModal", "Voto registrado com sucesso.
Obrigado por participar!");
session.setAttribute("msgIcone", "v");
}
}else{
//out.print("
O voto n�o foi registrado. Tente novamente mais tarde.
");
gotoPage = "/participe/enquete_aleijadinho/";
session.setAttribute("msgModal", "O voto n�o foi registrado. Tente novamente mais tarde.");
session.setAttribute("msgIcone", "x");
}
}catch(NumberFormatException erro){
//out.print("ID Não identificado");
gotoPage = "/participe/enquete_aleijadinho/";
session.setAttribute("msgModal", "ID Não identificado");
session.setAttribute("msgIcone", "x");
}
response.sendRedirect(gotoPage);
%>