<% if Session("status") <> "login" then response.redirect "login.asp" %>
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"
%>

<% 
displayRecs = 5
recRange = 10
%>

<%
' Get table name
tablename = "[Edificios]"
%>


<%
' Get search criteria
pSearch = Request.Form("psearch")
If pSearch <> "" Then
	dbwhere = ""
	pSearch = replace(pSearch,"'","''")
	pSearch = replace(pSearch,"[","[[]")
	dbwhere = dbwhere & "[Nombre] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[Direccion] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[Descripcion] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[Superficie] like '%" & pSearch & "%' or "
    dbwhere = dbwhere & "[sup_busqueda] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[Imagen] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[Plano] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[Tile] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[sup_propia] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[sup_util] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[sup_servicios] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[sup_comun] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[desc_ascensores] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[desc_aire_ac] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[desc_det_incendio] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[desc_ext_incendio] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[desc_c_accesos] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[desc_seguridad] like '%" & pSearch & "%' or "
	dbwhere = dbwhere & "[desc_cochera] like '%" & pSearch & "%' or "
	dbwhere = mid(dbwhere,1,len(dbwhere)-3)
	Session("tablename") = tablename
	Session("dbwhere") = dbwhere
	'reset start record counter
	startRec = 1
	Session("startRec") = startRec
Else
	If tablename = Session("tablename") Then
		dbwhere = Session("dbwhere")
	Else
		'reset search criteria
		dbwhere = ""
		Session("dbwhere") = dbwhere
	End If
End If

'Get clear search cmd
If Request.QueryString("cmd").Count > 0 then
	cmd=Request.QueryString("cmd")
	If ucase(cmd) = "RESET" Then
		'reset search criteria
		dbwhere = ""
		Session("dbwhere") = dbwhere
	End If
End If

%>


<%
'Get key & command
If Request.QueryString("id").Count > 0 Then
	id=Request.QueryString("id")
	Session("id") = id
Else
	id = Session("id")
End If

' Load Default Order
DefaultOrder = ""
DefaultOrderType = ""

' Check for an Order parameter
OrderBy = ""
If Request.QueryString("order").Count > 0 Then
	OrderBy = Request.QueryString("order")
	' Check if an ASC/DESC toggle is required
	If Session("OrderBy") = OrderBy Then
		If Session("OrderType") = "ASC" Then
			Session("OrderType") = "DESC"
		Else
			Session("OrderType") = "ASC"
		End if
	Else
		Session("OrderType") = "ASC"
	End If
	Session("tablename") = tablename
	Session("OrderBy") = OrderBy
	Session("startRec") = 1
Else
	If tablename = Session("tablename") Then
		OrderBy = Session("OrderBy")
	Else
		OrderBy = DefaultOrder
		Session("OrderBy") = OrderBy
		Session("OrderType") = DefaultOrderType
	End If
End If

' Check for a START parameter
If Request.QueryString("start").Count > 0 Then
	startRec = Request.QueryString("start")
	Session("tablename") = tablename
	Session("startRec") = startRec
Else
	If tablename = Session("tablename") Then
		startRec = Session("startRec")
	Else
		'reset start record counter
		startRec = 1
		Session("startRec") = startRec
	End If
End If

'Set the last record to display
stopRec = startRec + displayRecs - 1

' Open Connection to the database
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("../db/edificios.mdb") & ";"

' Build Query
strsql = "select * from [Edificios]"

If dbwhere <> "" Then
	strsql = strsql & " WHERE " & dbwhere
End If

if OrderBy <> "" then 
		strsql = strsql & " ORDER BY [" & OrderBy & "] " & Session("OrderType")
end if	

'response.write strsql

set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn, 1, 2 

' Display message when error found
If Err.Number <> 0 Then
	Response.write("SQL: " & strsql & "<br>")
	Response.write("Error Code: " & Err.Number & "<br>")
	Response.write("Error Description: " & Err.Description & "<br>")
	Response.write("Error Source: " & Err.Source & "<br>")
	Response.write("Error Line: " & Err.Line & "<br>")
	response.end
End If
totalRecs = rs.RecordCount
%>

<!--#include file="header.asp"-->

      <p>&nbsp;<span class="titular">&nbsp;TABLA : Edificios&nbsp;</span></p>


      <table border="0" cellspacing="0" cellpadding="0" width="376">
        <FORM ACTION="Edificioslist.asp" METHOD="POST">
          <tr> 
            <td height="0" align="left" width="177"> 
              <div align="left"><span class="textselect">buscar (*)</span>&nbsp;&nbsp; 
                <input type="Text" name="psearch" size=10>
              </div>
            </td>
            <td height="0" align="left" width="18">&nbsp; </td>
            <td height="0" align="left" width="62"> 
              <input type="Submit" name="Submit" value="buscar" class="boton">
            </td>
            <td height="0" align="left" width="10">&nbsp;</td>
            <td height="0" align="left" width="109">&nbsp;&nbsp;&nbsp;&nbsp;<a href="Edificioslist.asp?cmd=reset">restablecer</a></td>
          </tr>
        </FORM>
      </table>
<p>



<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		  <td height="0" align="left"><a href="Edificiosadd.asp">Agregar</a></td>
	</tr>
</table>
<p>


      <table border="0" cellspacing="1" cellpadding="5" bgcolor="#DCDCDC">
        <tr bgcolor="#D9D9D9"> 
          <td width="26"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("ID_no") %>">ID 
            no&nbsp;</a> </td>
          <td width="85"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("Nombre") %>">Nombre&nbsp;(*)</a> 
          </td>
          <td width="95"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("Direccion") %>">Direccion&nbsp;(*)</a> 
          </td>
          <td width="110"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("Descripcion") %>">Descripcion&nbsp;(*)</a> 
          </td>
          <td width="100"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("Superficie") %>">Superficie&nbsp;(*)</a> 
          </td>
          <td width="83"><a href="Edificioslist.asp?order=<%= Server.URLEncode("sup_busqueda") %>">Superficie 
            de b&uacute;squeda&nbsp;(*)</a></td>
          <td width="83"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("Imagen") %>">Imagen&nbsp;(*)</a> 
          </td>
          <td width="70"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("Plano") %>">Plano&nbsp;(*)</a> 
          </td>
          <td width="75"><a href="Edificioslist.asp?order=<%= Server.URLEncode("Tile") %>">Tile&nbsp;(*)</a> 
          </td>
          <td width="75"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("sup_propia") %>">superficie 
            propia&nbsp;(*)</a> </td>
          <td width="69"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("sup_util") %>">superficie 
            util&nbsp;(*)</a> </td>
          <td width="84"> 
            <p><a href="Edificioslist.asp?order=<%= Server.URLEncode("sup_servicios") %>">superficie 
              servicios&nbsp;(*)</a> 
          </td>
          <td width="84"><a href="Edificioslist.asp?order=<%= Server.URLEncode("sup_comun") %>">superficie 
            común&nbsp;(*)</a></td>
          <td width="84"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("ascensores") %>">ascensores&nbsp;</a> 
          </td>
          <td width="107"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_ascensores") %>">descripci&oacute;n 
            ascensores&nbsp;(*)</a> </td>
          <td width="104"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("aire_ac") %>">aire 
            acondicionado&nbsp;</a> </td>
          <td width="79"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_aire_ac") %>">descripci&oacute;n 
            aire ac&nbsp;(*)</a> </td>
          <td width="67"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("det_incendio") %>">detecci&oacute;n 
            de incendio&nbsp;</a> </td>
          <td width="88"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_det_incendio") %>">descripci&oacute;n 
            det incendio&nbsp;(*)</a> </td>
          <td width="65"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("ext_incendio") %>">extinci&oacute;n 
            de incendio&nbsp;</a> </td>
          <td width="96"> 
            <p><a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_ext_incendio") %>">descripci&oacute;n 
              ext </a><a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_ext_incendio") %>">incendio&nbsp;(*)</a> 
            </p>
          </td>
          <td width="71"> 
            <p><a href="Edificioslist.asp?order=<%= Server.URLEncode("c_accesos") %>">control 
              </a><a href="Edificioslist.asp?order=<%= Server.URLEncode("c_accesos") %>">de 
              accesos&nbsp;</a> </p>
          </td>
          <td width="103"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_c_accesos") %>">descripci&oacute;n 
            de c accesos&nbsp;(*)</a> </td>
          <td width="75"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("seguridad") %>">seguridad&nbsp;</a> 
          </td>
          <td width="119"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_seguridad") %>">descripci&oacute;n 
            de seguridad&nbsp;(*)</a> </td>
          <td width="84"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("pisotecnico") %>">pisotecnico&nbsp;</a> 
          </td>
          <td width="73"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("pisoducto") %>">pisoducto&nbsp;</a> 
          </td>
          <td width="42"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("grupo_elec") %>">grupo 
            electr&oacute;geno&nbsp;</a> </td>
          <td width="62"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("cochera") %>">cochera&nbsp;</a> 
          </td>
          <td width="85"> <a href="Edificioslist.asp?order=<%= Server.URLEncode("desc_cochera") %>">descripci&oacute;n 
            cochera&nbsp;(*)</a> </td>
          <td width="33">&nbsp;</td>
          <td width="25">&nbsp;</td>
          <td width="47">&nbsp;</td>
        </tr>
        <%
recCount = 0
recActual = 0
Do While (NOT rs.EOF) AND (recCount < stopRec)
	recCount = recCount + 1
	If Clng(recCount) >= Clng(startRec) Then 
		recActual = recActual + 1 %>
        <%	' Display alternate color for rows
	If recCount mod 2 = 0 Then
		bgcolor="#FFFFFF"
	Else
		bgcolor="#F5F5F5"
	End If

	x_ID_no = rs("ID_no")
	x_Nombre = rs("Nombre")
	x_Direccion = rs("Direccion")
	x_Descripcion = rs("Descripcion")
	x_Superficie = rs("Superficie")
	x_sup_busqueda = rs("sup_busqueda")
	x_Imagen = rs("Imagen")
	x_Plano = rs("Plano")
	x_Tile = rs("Tile")
	x_sup_propia = rs("sup_propia")
	x_sup_util = rs("sup_util")
	x_sup_servicios = rs("sup_servicios")
	x_sup_comun = rs("sup_comun")
	x_ascensores = rs("ascensores")
	x_desc_ascensores = rs("desc_ascensores")
	x_aire_ac = rs("aire_ac")
	x_desc_aire_ac = rs("desc_aire_ac")
	x_det_incendio = rs("det_incendio")
	x_desc_det_incendio = rs("desc_det_incendio")
	x_ext_incendio = rs("ext_incendio")
	x_desc_ext_incendio = rs("desc_ext_incendio")
	x_c_accesos = rs("c_accesos")
	x_desc_c_accesos = rs("desc_c_accesos")
	x_seguridad = rs("seguridad")
	x_desc_seguridad = rs("desc_seguridad")
	x_pisotecnico = rs("pisotecnico")
	x_pisoducto = rs("pisoducto")
	x_grupo_elec = rs("grupo_elec")
	x_cochera = rs("cochera")
	x_desc_cochera = rs("desc_cochera")
%>
        <tr bgcolor="<%= bgcolor %>"> 
          <td class="textselect" width="26"> 
            <% response.write x_ID_no %>
            &nbsp; </td>
          <td class="textselect" width="85"> 
            <% response.write x_Nombre %>
            &nbsp; </td>
          <td class="textselect" width="95"> 
            <% response.write x_Direccion %>
            &nbsp; </td>
          <td class="textselect" width="110"> 
            <% response.write x_Descripcion %>
            &nbsp; </td>
          <td class="textselect" width="100"> 
            <% response.write x_Superficie %>
            &nbsp; </td>
          <td class="textselect" width="83">
            <% response.write x_sup_busqueda %>
          </td>
          <td class="textselect" width="83"> 
            <% response.write x_Imagen %>
            &nbsp; </td>
          <td class="textselect" width="70"> 
            <% response.write x_Plano %>
            &nbsp; </td>
          <td class="textselect" width="75"> 
            <% response.write x_Tile %>
            &nbsp;</td>
          <td class="textselect" width="75"> 
            <% response.write x_sup_propia %>
            &nbsp; </td>
          <td class="textselect" width="69"> 
            <% response.write x_sup_util %>
            &nbsp; </td>
          <td class="textselect" width="84"> 
            <% response.write x_sup_servicios %>
            &nbsp;</td>
          <td class="textselect" width="84"> 
            <% response.write x_sup_comun %>
            &nbsp;</td>
          <td class="textselect" width="84"> 
            <% If x_ascensores = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="107"> 
            <% response.write x_desc_ascensores %>
            &nbsp; </td>
          <td class="textselect" width="104"> 
            <% If x_aire_ac = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="79"> 
            <% response.write x_desc_aire_ac %>
            &nbsp; </td>
          <td class="textselect" width="67"> 
            <% If x_det_incendio = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="88"> 
            <% response.write x_desc_det_incendio %>
            &nbsp; </td>
          <td class="textselect" width="65"> 
            <% If x_ext_incendio = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="96"> 
            <% response.write x_desc_ext_incendio %>
            &nbsp; </td>
          <td class="textselect" width="71"> 
            <% If x_c_accesos = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="103"> 
            <% response.write x_desc_c_accesos %>
            &nbsp; </td>
          <td class="textselect" width="75"> 
            <% If x_seguridad = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="119"> 
            <% response.write x_desc_seguridad %>
            &nbsp; </td>
          <td class="textselect" width="84"> 
            <% If x_pisotecnico = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="73"> 
            <% If x_pisoducto = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="42"> 
            <% If x_grupo_elec = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="62"> 
            <% If x_cochera = True Then %>
            <%= "Yes" %> 
            <% Else %>
            <%= "No" %> 
            <% End If %>
            &nbsp; </td>
          <td class="textselect" width="85"> 
            <% response.write x_desc_cochera %>
            &nbsp; </td>
          <td class="textselect" width="33"><a href="Edificiosview.asp?key=<%=Server.URLEncode(rs("ID_no")&"")%>">Ver</a></td>
          <td class="textselect" width="25"><a href="Edificiosedit.asp?key=<%=Server.URLEncode(rs("ID_no")&"")%>">Editar</a></td>
          <td class="textselect" width="47"><a href="Edificiosdelete.asp?key=<%=Server.URLEncode(rs("ID_no")&"")%>">Borrar</a></td>
        </tr>
        <%
	end if

	rs.MoveNext
Loop 
%>
      </table>



<%
if totalRecs > 0 then

	' Find out if there should be Backward or Forward Buttons on the table.
	If 	startRec = 1 Then
		isPrev = False
	Else
		isPrev = True
		PrevStart = startRec - displayRecs
		If PrevStart < 1 Then PrevStart = 1 %>
	<hr size="1">
      <strong><a href="Edificioslist.asp?start=<%=PrevStart%>">[&lt;&lt;&nbsp;Prev]</a></strong> 
      <%
	End If
	
	' Display Page numbers
	If (isPrev OR (NOT rs.EOF)) Then
		If (NOT isPrev) Then Response.Write "<HR SIZE=1>"
		x = 1
		y = 1
	
		dx1 = ((startRec-1)\(displayRecs*recRange))*displayRecs*recRange+1
		dy1 = ((startRec-1)\(displayRecs*recRange))*recRange+1
		If (dx1+displayRecs*recRange-1) > intTotalRecs then
			dx2 = (totalRecs\displayRecs)*displayRecs+1
			dy2 = (totalRecs\displayRecs)+1
		Else
			dx2 = dx1+displayRecs*recRange-1
			dy2 = dy2+recRange-1
		End If
	
		While x < totalrecs
			If x >= dx1 and x <= dx2 Then
				If Clng(startRec) = Clng(x) Then %>
      <strong><%=y%></strong> 
      <% 			Else %>
      <strong><a href="Edificioslist.asp?start=<%=x%>"><%=y%></A></strong> 
      <%			End If
				x = x + displayRecs
				y = y + 1
			elseif x >= (dx1-displayRecs*recRange) and x <= (dx2+displayRecs*recRange) then
				if x+recRange*displayRecs < totalRecs then %>
      <a href="Edificioslist.asp?start=<%=x%>"><%=y%>-<%=y+recRange-1%></a> 
      <%			else
					ny=(totalRecs-1)\displayRecs+1
						if ny = y then %>
      <a href="Edificioslist.asp?start=<%=x%>"><%=y%></a> 
      <%					else %>
      <a href="Edificioslist.asp?start=<%=x%>"><%=y%>-<%=ny%></a> 
      <%					end if
				end if
				x=x+recRange*displayRecs
				y=y+recRange
			else
				x=x+recRange*displayRecs
				y=y+recRange
			End If
		Wend
	End If
	
	' Next link
	If NOT rs.EOF Then
		NextStart = startRec + displayRecs
		isMore = True %>
      <strong><a href="Edificioslist.asp?start=<%=NextStart%>">[Next&nbsp;&gt;&gt;]</a></strong> 
      <% Else
		isMore = False
	End If %>
      <hr size="1">
      <% If stopRec > recCount Then stopRec = recCount %>
      <span class="textselect">Registro<%= startRec %> al 
      <%= stopRec %> de <%= totalRecs %></span> <span class="textselect"> 
      <% Else %>
      </span> <br>
      <br>
      <font color="#FF0000"><span class="textselect">No se han encontrado registros 
      </span></font><span class="textselect"></span><br>
      <br>
<% End If %>

<%
' Close recordset and connection
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing %>


<!--#include file="footer.asp"-->
