forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1788 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
d29a495925
commit
5cc9d62941
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 43 KiB |
Binary file not shown.
@ -0,0 +1,40 @@
|
||||
package com.evolute.siprp.pagina;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class doGetFicheiro extends siprpServlet
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public doGetFicheiro(HttpServletRequest req, HttpServletResponse res, String query) throws IOException, SQLException, ClassNotFoundException
|
||||
{
|
||||
Class.forName( bdDriver );
|
||||
Connection con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
res.addHeader( "Content-disposition", "attachment;filename=\"" + query + "\"" );
|
||||
res.setContentType("application/octet-stream");
|
||||
OutputStream os = res.getOutputStream();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT file_data FROM fil_file where name='" + query + "'");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs != null)
|
||||
{
|
||||
while(rs.next())
|
||||
{
|
||||
byte[] b = rs.getBytes(1);
|
||||
os.write(b);
|
||||
}
|
||||
}
|
||||
os.flush();
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
package com.evolute.siprp.pagina;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
|
||||
public class doGetFuncionariosFicheiros extends siprpServlet
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public doGetFuncionariosFicheiros( HttpServletRequest req, HttpServletResponse res ) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null;
|
||||
StringBuffer dbQuery, sBuffer;
|
||||
String userRole, empresaId, estabelecimentoId;
|
||||
HttpSession session = req.getSession( false );
|
||||
List< String > links = new LinkedList< String >();
|
||||
List< String > desc = new LinkedList< String >();
|
||||
try
|
||||
{
|
||||
userRole = ( String ) session.getAttribute( sessionUserRole );
|
||||
empresaId = ( String ) session.getAttribute( sessionEmpresaId );
|
||||
estabelecimentoId = ( String ) session.getAttribute( sessionEstabelecimentoId );
|
||||
|
||||
if ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) )
|
||||
{
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "/" + servletName + "/?" + empresaId + "/" + estabelecimentoId + "/func" ); // contruir url
|
||||
links.add( dbQuery.toString() );
|
||||
desc.add( "Funcionários" );
|
||||
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "/" + servletName + "/?" + empresaId + "/" + estabelecimentoId + "/fich" ); // contruir url
|
||||
links.add( dbQuery.toString() );
|
||||
desc.add( "Ficheiros" );
|
||||
|
||||
sBuffer = new StringBuffer();
|
||||
sBuffer.append( "<b>" + nomeEmpresa( con, empresaId ) + "</b><br><br><i>" + nomeEstabelecimento( con, estabelecimentoId ) + "</i>" );
|
||||
|
||||
if ( userRole.equals( "manager" ) )
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, ( String ) session.getAttribute( sessionEmpresaId ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, userRole ) );
|
||||
}
|
||||
|
||||
Map< String, Object > hmValues = new HashMap< String, Object >();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_nome", nomeEstabelecimento( con, estabelecimentoId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate, sBuffer.toString() );
|
||||
hmValues.put( templateUserRole, userRole );
|
||||
hmValues.put( templateQuery, queryStringOpcoes );
|
||||
hmValues.put( templateVector1, links );
|
||||
hmValues.put( templateVector2, desc );
|
||||
hmValues.put( templateVector3, null );
|
||||
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
SiprpWebLogger.logException( e );
|
||||
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,119 @@
|
||||
package com.evolute.siprp.pagina;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.evolute.utils.arrays.ResultSet2DArray;
|
||||
|
||||
public class doGetListaFicheiros extends siprpServlet
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public doGetListaFicheiros(HttpServletRequest req, HttpServletResponse res, boolean geral) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null;
|
||||
Statement stmt = null;
|
||||
ResultSet2DArray rs, rsFich;
|
||||
String dbQuery = null;
|
||||
String userRole, empresaId, estabelecimentoId;
|
||||
HttpSession session = req.getSession( false );
|
||||
List< String > links = new LinkedList< String >();
|
||||
List< Map< String, Object > > desc = new LinkedList< Map< String, Object > >();
|
||||
try
|
||||
{
|
||||
userRole = ( String ) session.getAttribute( sessionUserRole );
|
||||
empresaId = ( String ) session.getAttribute( sessionEmpresaId );
|
||||
estabelecimentoId = ( String ) session.getAttribute( sessionEstabelecimentoId );
|
||||
|
||||
if ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) )
|
||||
{
|
||||
Class.forName( bdDriver );
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
|
||||
if(geral)
|
||||
{
|
||||
dbQuery = "SELECT file_id FROM fil_file_empresa WHERE empresa_id = '" + empresaId + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
dbQuery = "SELECT file_id FROM fil_file_estabelecimento WHERE empresa_id = '" + empresaId + "' AND estabelecimento_id = '" + estabelecimentoId + "'";
|
||||
}
|
||||
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
||||
rsFich = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
|
||||
rsFich.getObjects();
|
||||
|
||||
for(int i = 0; i < rsFich.columnLength(); i++)
|
||||
{
|
||||
Integer ficheiroId = (Integer) rsFich.get(i, 0);
|
||||
dbQuery = "SELECT name, mime_type, inserted_stamp, details FROM fil_file WHERE id = '" + ficheiroId + "'";
|
||||
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
||||
rs = new ResultSet2DArray( stmt.executeQuery(dbQuery) );
|
||||
rs.getObjects();
|
||||
|
||||
Date data = (Date) rs.get(0, 2);
|
||||
|
||||
String query = null;
|
||||
if(geral)
|
||||
{
|
||||
query = "/" + servletName + "/?" + empresaId + "/fich/" + rs.get(0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
query = "/" + servletName + "/?" + empresaId + "/" + estabelecimentoId + "/fich/" + rs.get(0, 0);
|
||||
}
|
||||
|
||||
SimpleDateFormat DDMMYYYY = new SimpleDateFormat( "dd-MM-yyyy" );
|
||||
Map< String, Object > ficheiro = new HashMap< String, Object >();
|
||||
ficheiro.put( "Link", query );
|
||||
ficheiro.put( "Nome", rs.get(0, 0) );
|
||||
ficheiro.put("Tipo", rs.get(0, 1));
|
||||
ficheiro.put("Data", DDMMYYYY.format(data));
|
||||
ficheiro.put("Comentario", rs.get(0, 3) == null ? "" : rs.get(0, 3) );
|
||||
|
||||
desc.add(ficheiro);
|
||||
}
|
||||
|
||||
Map< String, Object > hmValues = new HashMap< String, Object >();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
if(!geral)
|
||||
{
|
||||
hmValues.put( "estabelecimento_nome", nomeEstabelecimento( con, estabelecimentoId ) );
|
||||
}
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( templateUserRole, userRole );
|
||||
hmValues.put( templateQuery, queryStringFicheiros );
|
||||
hmValues.put( templateVector1, links );
|
||||
hmValues.put( templateVector2, desc );
|
||||
hmValues.put( templateVector3, null );
|
||||
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
SiprpWebLogger.logException( e );
|
||||
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue