<%@page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,m05bClasses.*" %>
<%@include file="/mantenimientosJSP/includes/m05b.inc"%>

<%	// _______________________________XLNETs______________________________________
	// Evaluar variable de session que indica si esta conectado a XLNets
	if ((session.getAttribute("objetoSeguridad")) == null)  { 
		// Verificar que no ha transcurrido el tiempo de sesion (web.xml) %>
			<%@ include file="/m05bControlAcceso.inc"%> 
	<% } %>
	<%@ include file="/m05bIdioma.inc"%>

<HTML>
<head>
		<title><%= resTit.getString("titRelAvisos")%></title>
		<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05Funciones.js"></script>
		<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
		<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
</head>
<BODY style="cursor: wait" onkeydown="cancelaEnter();" onload="document.body.style.cursor='default';InitMenu();" onunload="document.body.style.cursor='wait';">
		<SCRIPT language=JavaScript>
			var urlIdioma;		//URL recarga en funcion del idioma
			var rutaCabecera;	//Camino de migas
			var detActual;		//Ventana actual
			urlIdioma = "<%=m05bConstantesPaginas.MTO_REL_AVISOS%>";
			detActual = '<%=resCM.getString("cmRelAvisos")%>';
			rutaCabecera = "";
		</SCRIPT>
		<%@ include file="/mantenimientosJSP/includes/m05Cabecera_c.jsp"%>
<p>	
<table  width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr><td colspan=3></td></tr>
	<tr valign="top">
		<td width="2%">
			<DIV ID="thessm" style="visibility:hidden;Position : Absolute ;Left : 0 ;Top : 80 ;Z-Index : 20;">
	      		<DIV ID="thessm2" style="Position : Absolute ;Left : (-150) ;Top : 0 ;Z-Index : 20;">
	                <%@ include file="/m05bMenuInicial.inc"%>
	       		</DIV>
			</DIV>
		</td>
		<td>&nbsp</td>
		<td width="98%">
			<%
						int contador = 0;
						String sql = "", sql2 = "";
						String matricula="", texto="",vehiculo="N", asig="N", ot="N";
                        java.sql.Connection conn=null;
                        PreparedStatement pstmt = null;
                        ResultSet rs = null;							
							
			try{
						session.removeAttribute("Aviso");
						matricula = request.getParameter("Codigo")==null?"":request.getParameter("Codigo");
						if ((matricula == null) || (!(matricula.equals("Nuevo")))) { 
						   if (matricula != null)
						   		matricula = matricula.toUpperCase();
						   texto = request.getParameter("Texto");
					   	   if (texto != null)
						   		texto = texto.toUpperCase();
						}
							sql = "select " + m05bConstantes.COL_02_MATRICULA + ", "+ "NVL("+ campoTexto+m05bConstantes.COL_02_TEXTO+","+m05bConstantes.COL_02_TEXTO+")"	+							
								", " + m05bConstantes.COL_02_VEHICULO + ", "+ m05bConstantes.COL_02_ASIGNACION + 
								", " + m05bConstantes.COL_02_OT + 
								" from " + m05bConstantes.TAB_AVISOS ;
						if ( (matricula == null) || (matricula.equals("") ))
							sql2 = sql2;
						else {	
							sql2 = sql2 + " where " + m05bConstantes.COL_02_MATRICULA + " like '%" + matricula + "%'";
						}
						if ( (texto == null) || (texto.equals("")))
							sql2 = sql2;
						else {
							if (sql2.equals(""))
						 		sql2 = sql2 + " where " + campoTexto+ m05bConstantes.COL_02_TEXTO	+ " like '%" + texto + "%'";
							else
						 		sql2 = sql2 + " and " + campoTexto + m05bConstantes.COL_02_TEXTO	+" like '%" + texto + "%'";
						}
						sql = sql + sql2 + " order by " + m05bConstantes.COL_02_MATRICULA + ", 2" 	;
						
					    //m05bbBeginSelect(sql);
                        m05bConexion miConex = new m05bConexion();
                        conn = miConex.getConnection();
                        conn.setAutoCommit(false);  // Al final si todo ha ido bien se hace commit	 
                		pstmt = conn.prepareStatement(sql);
                		rs = pstmt.executeQuery();        	   					        
						//m05bRS = m05bPStmt.executeQuery();
			%>
				<FORM NAME="FormRelAvisos" METHOD="POST">
					 <TABLE  class="general">
						 <tr>
 						      <td width="90%" align="right"> 
 						      	<input type="button" class="boton" name="<%= res.getString("etBOT_PRESENTAR")%>" value="<%= res.getString("etBOT_PRESENTAR")%>" ONCLICK="JavaScript:fncImprimir(); return false" onMouseOver="top.status='<%= res.getString("etBOT_STATUSPRESENTAR")%>'; return false" onMouseOut="top.status=''; return false" />
 						      </td>
						      <td width="10%"align="right"> 
						      	<input type="button" class="boton" name="<%= res.getString("etBOT_NUEVO")%>" value="<%= res.getString("etBOT_NUEVO")%>" ONCLICK="JavaScript:fncNuevo();return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSNUEVO")%>'; return false" onMouseOut="top.status=''; return false" />
						      </td>
						</tr>
					 </TABLE>
					 <TABLE class="general" width="20%">
						 <tr>
							  <td class="searchTitle"><%= res.getString("etBuscarMatricula")%> </td>
						</tr>
						 <tr>
							  <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Matr" value="<%=matricula%>" size="13" maxlength="20" onBlur="javascript:fncBuscar();"/> </td>
						</tr>
					 </TABLE>
					 <TABLE class="general" align="center">
					    <tr > 
					       <td class="searchTitle" width="20%"><%= res.getString("etMatricula")%></td>
					       <td class="searchTitle" width="50%"><%= res.getString("etTexto")%></td>
					       <td class="searchTitle" width="10%"><%= res.getString("etGestionVehiculos")%></td>
					       <td class="searchTitle" width="10%"><%= res.getString("etAsignacion")%></td>
					       <td class="searchTitle" width="10%"><%= res.getString("etOT")%></td>
					    </tr>
				<%		contador=0;
						while (rs.next() == true){
							matricula = rs.getString(1);
							texto= rs.getString(2);
							vehiculo= rs.getString(3);							
							asig= rs.getString(4);
							ot= rs.getString(5);
							if(!idiomaSes.equals("es")){//Traducir S y N a B yE
								if(vehiculo.equals("S"))
									vehiculo="B";
								else
									vehiculo="E";
								if(asig.equals("S"))
									asig="B";
								else
									asig="E";
								if(ot.equals("S"))
									ot="B";
								else
									ot="E";
							}
							contador = contador + 1;  %>
							<tr>
							   <td class="inputFieldTitle"><FONT size="2"><A href="JavaScript:fncModificar('<%=matricula%>')"><%=matricula%></A></FONT></td>
					   		   <td class="inputFieldTitle"><FONT size="2"><%=texto%></FONT></td>
							   <td class="inputFieldTitle"><FONT size="2"><%=vehiculo%></FONT></td>
					   		   <td class="inputFieldTitle"><FONT size="2"><%=asig%></FONT></td>
							   <td class="inputFieldTitle"><FONT size="2"><%=ot%></FONT></td>
							</tr>
					<%}%>
							<tr></tr>
						    <tr align="center">
								    <td class="inputField" colspan="5"><%= res.getString("etTotal")%> <%=contador%></td>
						    </tr>
						</TABLE>
			</FORM>
		</td>
	</tr>
	<tr>
			<td colspan="3"><%@ include file="/mantenimientosJSP/includes/m05Pie_c.jsp"%></td>
	</tr>
</table>
<SCRIPT language=JavaScript>
	function fncNuevo() {
       	FormRelAvisos.action="m05bAvisosJsp.jsp?Codigo=&Mensaje=false";
       	FormRelAvisos.submit();
	}
	function fncModificar(codigo) {
        FormRelAvisos.action="m05bGenerarAvisoServlet?Matricula=" + codigo + "&Mensaje=" + <%=m05bConstantes.MSG_FALSE%>;
        FormRelAvisos.submit();
    }
    function fncImprimir() {
		var docu = document.FormRelAvisos;
        docu.action="m05bAvisosPDFJsp.jsp?Codigo="+docu.Matr.value;
        docu.submit();
    }    
    function fncBuscar() {
		var docu = document.FormRelAvisos;
		if(existeCaracter(docu.Matr.value,"\'")||existeCaracter(docu.Matr.value,'\"')){
 			alert(dameAlerta(idioma, 1));
 			docu.Matr.focus();
 			return;
 		}
        docu.action="m05bRelAvisosJsp.jsp?Codigo="+docu.Matr.value;
        docu.submit();
    }    
    setTimeout('initSlide();', 1);
</SCRIPT>
<%
	  } catch (Exception SQLException){
		  m05bClasses.m05bFileLog miLog = new m05bClasses.m05bFileLog();
	   		miLog.addTraza(SQLException);
	  } finally {
				if (rs != null)
					rs.close();
				if (pstmt != null)
					pstmt.close();
				if (conn != null)
					conn.close();
	  } %>
</BODY>
</HTML>