<%@ page import="javax.naming.*" %> <%@ page import="javax.sql.*" %> <%@ page import="java.sql.Connection" %> <%@ page import="com.hlt.sql.Statement" %> <%@ page import="com.hlt.sql.Query" %> <%@ page import="com.hlt.sql.SysError" %> <%@ page import="com.hlt.util.*" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Date"%> <%@ page import="br.com.relato.EntryPoint" %> <%! private void atualizaEsseAcesso( int nId, int qtde, Statement stmt ) { //cExpSql = "UPDATE acessos SET quantidade = " + qtde + " WHERE id = " + nId; String updateFields[] = {"quantidade = ?"}; String filter[] = {"id = ?"}; stmt.update("acessos").fields(updateFields).where(filter); stmt.buildParams(); stmt.setParamInt(1, qtde); stmt.setParamInt(2, nId); stmt.execute(); } private void incluiNovoAcesso( int nIdEmail, int nIdLink, long nIdLog, int nIdJob, Statement stmt ) { //cExpSql = "INSERT INTO acessos ( data, quantidade, id_link, id_email, id_log, id_job ) VALUES ( now(), " & quantidade & ", " & cId_Link & ", " & cId_Email & ", " & cId_Log & ", " & cId_Job & ")" ArrayList prm = new ArrayList(); ArrayList cps = new ArrayList(); cps.add("data"); cps.add("quantidade"); cps.add("id_link"); cps.add("id_email"); cps.add("id_log"); cps.add("id_job"); prm.add("?"); prm.add("?"); prm.add("?"); prm.add("?"); prm.add("?"); prm.add("?"); String prmt[] = (String[])prm.toArray(new String[prm.size()]); String cpos[] = (String[])cps.toArray(new String[cps.size()]); // Insere registro stmt.insert("acessos").fields(cpos).values(prmt); stmt.buildParams(); stmt.setParamDate(1, new Date()); stmt.setParamInt(2, 1); stmt.setParamInt(3, nIdLink); stmt.setParamInt(4, nIdEmail); stmt.setParamLong(5, nIdLog); stmt.setParamInt(6, nIdJob); //System.out.println("acessos -----------> " + stmt.toStringWithParams()); SysError.clear(); stmt.execute(); //SysError.showErrors(); } %><% //Context ctx = null; //DataSource ds = null; Statement stmt = null; Connection con = null; Query qr = null; Query qrAux = null; String cExpSql = null; String urlRedirect = "http://www.expressemail.com.br"; Date dataUrl; int nIdLink = (request.getParameter("id") != null ? Integer.parseInt(request.getParameter("id")) : -1 ); int nIdEmail = (request.getParameter("email") != null ? Integer.parseInt(request.getParameter("email")) : -1 ); long nIdLog = (request.getParameter("log") != null ? Long.parseLong(request.getParameter("log")) : -1 ); int qtdeAcessos = 0; int nIdAcesso; int nIdJobLink = 0; SysError.clear(); //parametros invalido if(nIdLink != -1 && nIdEmail != -1 && nIdLog != -1) { //try { // ctx = new InitialContext(); // if (ctx != null) { // ds = (DataSource) ctx.lookup("java:comp/env/jdbc/ExpressEmail"); // if (ds != null) { // con = ds.getConnection(); //con = util.ConnHelper.getConnection(ds, this, request, response); con = EntryPoint.getConnection(); if(con == null) return; if (con != null) { try { qr = new Query(con); qrAux = new Query(con); stmt = new Statement(con); try { // pegando dados do link //case o link nao exista, simplemente redirecionamos para expressemail.com.br cExpSql = "SELECT url_redirect, data_validade, url_msg_invalidou, id_job FROM links WHERE id = " + nIdLink; qrAux.command( cExpSql ); if(qrAux.open() && !qrAux.eof()) { urlRedirect = qrAux.getString(1); dataUrl = qrAux.getDate(2); nIdJobLink = qrAux.getInt(4); if ((dataUrl != null) && (qr.getString(3)!=null) && ( dataUrl.before(new Date()))) urlRedirect = qrAux.getString(3); qrAux.close(); cExpSql = "SELECT id, quantidade FROM acessos WHERE id_link = " + nIdLink + " AND id_email = " + nIdEmail + " AND id_log = " + nIdLog; qr.command( cExpSql ); if (qr.open()) { if (!qr.eof()) { qtdeAcessos = qr.getInt(2); qtdeAcessos ++; nIdAcesso = qr.getInt(1); atualizaEsseAcesso( nIdAcesso, qtdeAcessos, stmt ); } else { incluiNovoAcesso( nIdEmail, nIdLink, nIdLog, nIdJobLink, stmt ); } } } } finally { qr.close(); qrAux.close(); qr = null; qrAux = null; } } finally { //con.close(); } } } // } //}catch(org.apache.commons.dbcp.DbcpException x) { // log("erro ao se conectar ao banco", x); // response.sendRedirect("jam.html"); //} catch (Exception e) { // e.printStackTrace(new java.io.PrintWriter(out)); // qr = null; // qrAux = null; // con = null; // ctx = null; // ds = null; // urlRedirect = "http://www.expressemail.com.br"; // return; //} //} response.sendRedirect(urlRedirect); %>