Option Strict On

Imports System.Data
Imports System.Data.SqlClient
Imports System.IO

Imports System.Text
Imports System.Web.UI.WebControls
Imports System.Web.UI.Control

'Imports System.Linq

Imports System.Security.Permissions

Public Class func

    Inherits System.Web.UI.Page


    'Private Const acen As String = "&#180;"
    'Private Const a_acen As String = "&#225;"
    'Private Const e_acen As String = "&#233;"
    'Private Const i_acen As String = "&#237;"
    'Private Const o_acen As String = "&#243;"
    'Private Const u_acen As String = "&#250;"
    'Private Const a_may As String = "&#193;"
    'Private Const e_may As String = "&#201;"
    'Private Const i_may As String = "&#205;"
    'Private Const o_may As String = "&#211;"
    'Private Const u_may As String = "&#218;"
    'Private Const enie As String = "&#241;"
    'Private Const enie_may As String = "&#209;"
    'Private Const u_dier As String = "&#252;"
    'Private Const s_preg As String = "&#191;"
    'Private Const s_admir As String = "&#161;"
    'Private Const com_abrir As String = "&#171;"   '' «
    'Private Const com_cerrar As String = "&#187;"  '' »
    'Private Const cerito As String = "&#176;"      '' ° 
    Private Const com_abrir1 As String = "&#8220;"
    Private Const com_abrir2 As String = "&#8221;"
    'Private Const cedilla As String = "&#231;"       '' ç
    'Private Const achiquita As String = "&#170;"  '' ª
    ''Private Const ampersand As String = "&amp;"  “
    Public Shared limite_bajada As Integer = CInt(System.Configuration.ConfigurationManager.AppSettings("limite_bajada"))
    Public Shared admin_errores As String = System.Configuration.ConfigurationManager.AppSettings("admin_errores")
    '' Esto viene de BASE_3 y es para IMPERSONAR

    Public Shared LOGON32_LOGON_INTERACTIVE As Integer = 2
    Public Shared LOGON32_PROVIDER_DEFAULT As Integer = 0

    Public Shared impersonationContext As System.Security.Principal.WindowsImpersonationContext

    Declare Function LogonUserA Lib "advapi32.dll" (ByVal lpszUsername As String, _
                            ByVal lpszDomain As String, _
                            ByVal lpszPassword As String, _
                            ByVal dwLogonType As Integer, _
                            ByVal dwLogonProvider As Integer, _
                            ByRef phToken As IntPtr) As Integer

    Declare Auto Function DuplicateToken Lib "advapi32.dll" ( _
                            ByVal ExistingTokenHandle As IntPtr, _
                            ByVal ImpersonationLevel As Integer, _
                            ByRef DuplicateTokenHandle As IntPtr) As Integer

    Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long
    Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Long

    <PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
    Public Shared Function impersonateValidUser(ByVal userName As String, ByVal domain As String, ByVal password As String) As Boolean

        Dim tempWindowsIdentity As System.Security.Principal.WindowsIdentity
        Dim token As IntPtr = IntPtr.Zero
        Dim tokenDuplicate As IntPtr = IntPtr.Zero
        impersonateValidUser = False

        If CBool(RevertToSelf()) Then
            If LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
                If DuplicateToken(token, 2, tokenDuplicate) <> 0 Then
                    tempWindowsIdentity = New System.Security.Principal.WindowsIdentity(tokenDuplicate)
                    impersonationContext = tempWindowsIdentity.Impersonate()
                    If Not impersonationContext Is Nothing Then
                        impersonateValidUser = True
                    End If
                End If
            End If
        End If
        If Not tokenDuplicate.Equals(IntPtr.Zero) Then
            CloseHandle(tokenDuplicate)
        End If
        If Not token.Equals(IntPtr.Zero) Then
            CloseHandle(token)
        End If
    End Function

    Public Shared Sub undoImpersonation()
        impersonationContext.Undo()
    End Sub

    Public Shared Function RetornaImagen(ByVal str_archivo As String) As Drawing.Image
        Dim imagen As System.Drawing.Image
        Dim fs As System.IO.FileStream
        fs = New System.IO.FileStream(str_archivo, IO.FileMode.Open, IO.FileAccess.Read)
        imagen = System.Drawing.Image.FromStream(fs)
        fs.Close()
        Return imagen
    End Function

    Public Shared Function LeeIndicadores(ByVal fecha As String, ByVal n_seccion As Integer) As SqlDataReader
        LeeIndicadores = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_lee_indicadores", New SqlParameter() {db.MakeParameter("@fecha", fecha), db.MakeParameter("@n_seccion", n_seccion)}, LeeIndicadores)
    End Function

    Public Shared Function LeeHace(ByVal fecha As String) As SqlDataReader
        LeeHace = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_lee_hace", New SqlParameter() {db.MakeParameter("@fecha", fecha)}, LeeHace)
    End Function


    Public Shared Function MuestraOpiniones(ByVal idNoticia As Long, ByVal origen As Integer, ByVal cant As Integer) As SqlDataReader
        MuestraOpiniones = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_muestra_opiniones", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia), _
                        db.MakeParameter("@origen", origen), db.MakeParameter("@cant", cant)}, MuestraOpiniones)
    End Function

    Public Shared Function MuestraOpinionesRelacionadas(ByVal idNoticia As Long, ByVal orden As Integer) As SqlDataReader
        MuestraOpinionesRelacionadas = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_muestra_opiniones_rel", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia), _
                        db.MakeParameter("@orden", orden)}, MuestraOpinionesRelacionadas)
    End Function

    Public Shared Function CuentaOpiniones(ByVal idNoticia As Long, ByVal origen As Integer) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        Return db.RunProcedure("sp_cuenta_opiniones", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia), db.MakeParameter("@origen", origen)})
    End Function

    Public Shared Function CuentaReportadas(ByVal id_usuario As Long) As String
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        Return db.RunProcstring("sp_cuenta_reportadas", New SqlParameter() {db.MakeParameter("@id_usuario", id_usuario)})
    End Function

    '    Public Shared Sub EditaUsu(ByVal id_usu As Integer, ByVal clave As String, ByVal Direccion As String, _
    'ByVal telefono As String, ByVal documento As String, ByVal fecha_edicion As Date, ByVal titulares As Integer, ByVal foto As Boolean)
    '        Dim db As New Database
    '        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
    '        db.RunProcedure("sp_EditaUsu", New SqlParameter() {db.MakeParameter("@id_usu", id_usu), _
    '        db.MakeParameter("@clave", clave), db.MakeParameter("@direccion", Direccion), _
    '        db.MakeParameter("@telefono ", telefono), db.MakeParameter("@documento", documento), db.MakeParameter("@fecha_edicion", fecha_edicion), db.MakeParameter("@titulares", titulares), db.MakeParameter("@foto", foto)})
    '    End Sub

    Public Shared Sub EditaUsu(ByVal id_usu As Integer, ByVal clave As String, ByVal Direccion As String, _
    ByVal telefono As String, ByVal documento As String, ByVal ocupacion As String, ByVal provincia As Integer, ByVal localidad As Integer, _
    ByVal CodPostal As String, ByVal fecha_edicion As Date, ByVal titulares As Integer, ByVal foto As Boolean, ByVal autorizo As Boolean)
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_EditaUsu", New SqlParameter() {db.MakeParameter("@id_usu", id_usu), _
        db.MakeParameter("@clave", clave), db.MakeParameter("@direccion", Direccion), db.MakeParameter("@telefono ", telefono), _
        db.MakeParameter("@documento", documento), db.MakeParameter("@ocupacion", ocupacion), db.MakeParameter("@provincia", provincia), _
        db.MakeParameter("@localidad", localidad), db.MakeParameter("@CodPostal", CodPostal), _
        db.MakeParameter("@fecha_edicion", fecha_edicion), db.MakeParameter("@titulares", titulares), db.MakeParameter("@foto", foto), db.MakeParameter("@autorizo", autorizo)})
    End Sub

    Public Shared Sub BorraUsu(ByVal id As Integer)
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_borrausu", New SqlParameter() {db.MakeParameter("@id", id)})
    End Sub

    Public Shared Function LoginUsu(ByVal usuario As String, ByVal clave As String) As SqlDataReader
        LoginUsu = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_usulogin", New SqlParameter() {db.MakeParameter("@usuario", usuario), db.MakeParameter("@clave", clave)}, LoginUsu)
    End Function

    Public Shared Function LoginUsuSuscripcion(id_cliente As Int64) As SqlDataReader
        LoginUsuSuscripcion = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_HaySuscripcion", New SqlParameter() {db.MakeParameter("@id_cliente", id_cliente)}, LoginUsuSuscripcion)
    End Function

    Public Shared Sub HabilitaCuenta(ByVal usuario As String, ByVal titulares As Integer)

        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_habilita_cuenta", New SqlParameter() {db.MakeParameter("@usuario", usuario), db.MakeParameter("@titulares", titulares)})
    End Sub

    Public Shared Sub ActualizaCuenta(ByVal id As Integer, ByVal estado As Integer)

        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_actualiza_cuenta", New SqlParameter() {db.MakeParameter("@id", id), db.MakeParameter("@estado", estado)})
    End Sub

    Public Shared Sub HabilitaAmigo(ByVal n_origen As Int64, ByVal n_dest As Int64)

        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_habilita_amigo", New SqlParameter() {db.MakeParameter("@n_origen", n_origen), db.MakeParameter("@n_dest", n_dest)})
    End Sub

    Public Shared Function ver_UsuClave(ByVal email As String, ByVal usuario As String) As SqlDataReader
        ver_UsuClave = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_usuclave", New SqlParameter() {db.MakeParameter("@email", email), db.MakeParameter("@usuario", usuario)}, ver_UsuClave)
    End Function

    Public Shared Function ver_UsuDatos(ByVal email As String) As SqlDataReader
        ver_UsuDatos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_usudatos", New SqlParameter() {db.MakeParameter("@email", email)}, ver_UsuDatos)
    End Function

    Public Shared Function NuevoUsuario(ByVal nombre As String, ByVal apellido As String, ByVal usuario As String, _
    ByVal clave As String, ByVal email As String, ByVal fecha_nac As Date, ByVal telefono As String, ByVal direccion As String, _
    ByVal documento As String, ByVal foto As Boolean, ByVal estado As Integer, ByVal ultimo_login As Date, ByVal Fecha_alta As Date, _
    ByVal Fecha_edicion As Date, ByVal observaciones As String, ByVal n_comentarios As Integer, ByVal n_denreal As Integer, ByVal n_denrec As Integer, _
    ByVal n_denconc As Integer, ByVal n_titulares As Integer) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")

        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), _
        db.MakeParameter("@nombre", nombre), db.MakeParameter("@apellido", apellido), db.MakeParameter("@usuario", usuario), _
        db.MakeParameter("@clave", clave), db.MakeParameter("@email", email), db.MakeParameter("@fecha_nac", fecha_nac), _
        db.MakeParameter("@telefono", telefono), db.MakeParameter("@direccion", direccion), db.MakeParameter("@documento", documento), _
        db.MakeParameter("@foto", foto), db.MakeParameter("@estado", estado), db.MakeParameter("@ultimo_login", ultimo_login), _
        db.MakeParameter("@fecha_alta", Fecha_alta), db.MakeParameter("@fecha_edicion", Fecha_edicion), db.MakeParameter("@observaciones", observaciones), _
        db.MakeParameter("@n_comentarios", n_comentarios), db.MakeParameter("@n_denreal", n_denreal), db.MakeParameter("@n_denrec", n_denrec), _
        db.MakeParameter("@n_denconc", n_denconc), db.MakeParameter("@n_titulares", n_titulares)}

        db.RunProcedure("sp_nuevousuario", parameters)

        NuevoUsuario = CInt(parameters(0).Value)
    End Function

    Public Shared Function GuardaBuscado(ByVal str_nombre As String, ByVal int_edad As Integer, ByVal str_lugar As String, ByVal str_buscador As String, _
                                    ByVal bool_foto As Boolean, ByVal str_contacto As String) As Integer

        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), _
        db.MakeParameter("@str_nombre", str_nombre), db.MakeParameter("@int_edad", int_edad), _
        db.MakeParameter("@str_lugar", str_lugar), db.MakeParameter("@str_buscador", str_buscador), db.MakeParameter("@bool_foto", bool_foto), db.MakeParameter("@str_contacto", str_contacto)}

        db.RunProcedure("sp_guarda_buscado", parameters)
        GuardaBuscado = CInt(parameters(0).Value)
    End Function

    Public Shared Function GuardaMascota(ByVal str_tipo As String, ByVal str_desc As String, ByVal str_nombre As String, ByVal str_lugar As String, ByVal str_buscador As String, _
                                    ByVal bool_foto As Boolean, ByVal str_contacto As String) As Integer

        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), _
        db.MakeParameter("@str_tipo", str_tipo), db.MakeParameter("@str_desc", str_desc), db.MakeParameter("@str_nombre", str_nombre), _
        db.MakeParameter("@str_lugar", str_lugar), db.MakeParameter("@str_buscador", str_buscador), db.MakeParameter("@bool_foto", bool_foto), db.MakeParameter("@str_contacto", str_contacto)}

        db.RunProcedure("sp_guarda_mascota", parameters)
        GuardaMascota = CInt(parameters(0).Value)
    End Function

    ' se agregó Autorizo
    Public Shared Function NuevoUsuario(ByVal nombre As String, ByVal apellido As String, ByVal usuario As String, _
    ByVal clave As String, ByVal email As String, ByVal fecha_nac As Date, ByVal telefono As String, ByVal direccion As String, _
    ByVal provincia As Int32, ByVal localidad As Int32, ByVal CodPostal As String, _
    ByVal documento As String, ByVal ocupacion As String, ByVal foto As Boolean, ByVal estado As Integer, ByVal ultimo_login As Date, ByVal Fecha_alta As Date, _
    ByVal Fecha_edicion As Date, ByVal observaciones As String, ByVal n_comentarios As Integer, ByVal n_denreal As Integer, ByVal n_denrec As Integer, _
    ByVal n_denconc As Integer, ByVal n_titulares As Integer, ByVal Autorizo As Boolean) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")

        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), _
        db.MakeParameter("@nombre", nombre), db.MakeParameter("@apellido", apellido), db.MakeParameter("@usuario", usuario), _
        db.MakeParameter("@clave", clave), db.MakeParameter("@email", email), db.MakeParameter("@fecha_nac", fecha_nac), _
        db.MakeParameter("@telefono", telefono), db.MakeParameter("@direccion", direccion), _
        db.MakeParameter("@provincia", provincia), db.MakeParameter("@localidad", localidad), db.MakeParameter("@CodPostal", CodPostal), _
        db.MakeParameter("@documento", documento), db.MakeParameter("@ocupacion", ocupacion), _
        db.MakeParameter("@foto", foto), db.MakeParameter("@estado", estado), db.MakeParameter("@ultimo_login", ultimo_login), _
        db.MakeParameter("@fecha_alta", Fecha_alta), db.MakeParameter("@fecha_edicion", Fecha_edicion), db.MakeParameter("@observaciones", observaciones), _
        db.MakeParameter("@n_comentarios", n_comentarios), db.MakeParameter("@n_denreal", n_denreal), db.MakeParameter("@n_denrec", n_denrec), _
        db.MakeParameter("@n_denconc", n_denconc), db.MakeParameter("@n_titulares", n_titulares), db.MakeParameter("@Autorizo", Autorizo)}

        db.RunProcedure("sp_nuevousuario", parameters)

        NuevoUsuario = CInt(parameters(0).Value)
    End Function

    ' se agregó n_Sitio
    Public Shared Function NuevoUsuario(ByVal nombre As String, ByVal apellido As String, ByVal usuario As String, _
    ByVal clave As String, ByVal email As String, ByVal fecha_nac As Date, ByVal telefono As String, ByVal direccion As String, _
    ByVal provincia As Int32, ByVal localidad As Int32, ByVal CodPostal As String, _
    ByVal documento As String, ByVal ocupacion As String, ByVal foto As Boolean, ByVal estado As Integer, ByVal ultimo_login As Date, ByVal Fecha_alta As Date, _
    ByVal Fecha_edicion As Date, ByVal observaciones As String, ByVal n_comentarios As Integer, ByVal n_denreal As Integer, ByVal n_denrec As Integer, _
    ByVal n_denconc As Integer, ByVal n_titulares As Integer, ByVal Autorizo As Boolean, ByVal n_Sitio As Integer) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")

        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), _
        db.MakeParameter("@nombre", nombre), db.MakeParameter("@apellido", apellido), db.MakeParameter("@usuario", usuario), _
        db.MakeParameter("@clave", clave), db.MakeParameter("@email", email), db.MakeParameter("@fecha_nac", fecha_nac), _
        db.MakeParameter("@telefono", telefono), db.MakeParameter("@direccion", direccion), _
        db.MakeParameter("@provincia", provincia), db.MakeParameter("@localidad", localidad), db.MakeParameter("@CodPostal", CodPostal), _
        db.MakeParameter("@documento", documento), db.MakeParameter("@ocupacion", ocupacion), _
        db.MakeParameter("@foto", foto), db.MakeParameter("@estado", estado), db.MakeParameter("@ultimo_login", ultimo_login), _
        db.MakeParameter("@fecha_alta", Fecha_alta), db.MakeParameter("@fecha_edicion", Fecha_edicion), db.MakeParameter("@observaciones", observaciones), _
        db.MakeParameter("@n_comentarios", n_comentarios), db.MakeParameter("@n_denreal", n_denreal), db.MakeParameter("@n_denrec", n_denrec), _
        db.MakeParameter("@n_denconc", n_denconc), db.MakeParameter("@n_titulares", n_titulares), db.MakeParameter("@Autorizo", Autorizo), _
        db.MakeParameter("@n_Sitio", n_Sitio)}

        db.RunProcedure("sp_nuevousuario", parameters)

        NuevoUsuario = CInt(parameters(0).Value)
    End Function

    Public Shared Function ver_usumail(ByVal email As String) As SqlDataReader
        ver_usumail = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_usumail", New SqlParameter() {db.MakeParameter("@email", email)}, ver_usumail)
    End Function

    Public Shared Function ver_datosusu(ByVal usuario As String) As SqlDataReader
        ver_datosusu = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_datosusu", New SqlParameter() {db.MakeParameter("@usuario", usuario)}, ver_datosusu)
    End Function

    Public Shared Function ver_datosusu(ByVal id_usu As Int64) As SqlDataReader
        ver_datosusu = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_datosusu_id", New SqlParameter() {db.MakeParameter("@id_usu", id_usu)}, ver_datosusu)
    End Function

    Public Shared Function Puntos_suspensivos(ByVal str_bajada As String, ByVal int_limite As Integer) As String
        'str_bajada = "<div>la vaca</div><p>El intendente Pablo Bruera present&#243; ayer junto a pasteleros la torta solidaria por el 130&#186; aniversario de la Ciudad. Como se inform&#243;, se trata de una r&#233;plica a escala, de chocolate, del Palacio Municipal. Este a&#241;o es a beneficio del Hospital de Ni&#241;os, C&#225;ritas y la fundaci&#243;n &#8220;Volver a empezar&#8221; <br /> <br /><div class=""Video""><strong>Video de YouTube</strong><br /><br /><object width=""425"" height=""350""><param name=""movie"" value=""http://www.youtube.com/v/nTeqviVRu2Y""></param><param name=""wmode"" value=""transparent""></param><embed src=""http://www.youtube.com/v/nTeqviVRu2Y""  type=""application/x-shockwave-flash"" wmode=""transparent"" width=""425"" height=""350""></embed></object></div><div style=""clear:left""><script></script></div><br /></p>"
        'str_bajada = "<div class=""Galeria""><script src=""/galeria_nueva.ashx?galeria=237&amp;por=Calle_13_en_La_Plata_(Twitter)"" type=""text/javascript""></script></div><p>El intendente Pablo Bruera present&#243; ayer junto a pasteleros la torta solidaria por el 130&#186; aniversario de la Ciudad. Como se inform&#243;, se trata de una r&#233;plica a escala, de chocolate, del Palacio Municipal. Este a&#241;o es a beneficio del Hospital de Ni&#241;os, C&#225;ritas y la fundaci&#243;n &#8220;Volver a empezar&#8221; <br /> <br /></p>"
        'str_bajada = "<div class=""Audio""><embed src=""/reproductor.swf?mp3=/ediciones/20121120/20121120090329_1.mp3&amp;titulo=El m&#243;vil de La Redonda"" type=""application/x-shockwave-flash"" width=""260"" height=""87"" /></div>"
        'While str_bajada.IndexOf("<div") >= 0
        '    str_bajada = str_bajada.Remove(str_bajada.IndexOf("<div"), str_bajada.IndexOf("/div>") + 5 - str_bajada.IndexOf("<div"))
        'End While


        str_bajada = str_bajada.Replace("<", "!")
        str_bajada = str_bajada.Replace("!div", "<div")
        str_bajada = str_bajada.Replace("!/div", "</div")
        Dim options As RegexOptions = RegexOptions.IgnoreCase Or RegexOptions.Multiline
        Dim pattern As String = "<div[A-Za-zñáéíóú\s0-9=""-/:]*>[^<]+"
        Dim rgx1 As New RegularExpressions.Regex(pattern, options)
        str_bajada = rgx1.Replace(str_bajada, "")
        '' vuelve a el original
        str_bajada = str_bajada.Replace("!", "<")
        str_bajada = str_bajada.Replace("</div>", "")


        ''''''No sirve para galerías y audios
        'Dim options As RegexOptions = RegexOptions.IgnoreCase Or RegexOptions.Multiline
        ' '' videos con tags internos, primero remueve los tags:
        'Dim pattern As String = "<strong[A-Za-zñáéíóú\s0-9=""-/]*>[^<]+<\/strong>" ' "(<div[^>]+>)[^<]+(<\/div>)"  ' '
        'Dim rgx1 As New Regex(pattern, options)
        'str_bajada = rgx1.Replace(str_bajada, "")
        'pattern = "<param[A-Za-zñáéíóú\s0-9=""-/\.:]*><\/param>"
        'Dim rgx2 As New Regex(pattern, options)
        'str_bajada = rgx2.Replace(str_bajada, "")
        'pattern = "<embed[A-Za-zñáéíóú\s0-9=""-/\.:]*><\/embed>"
        'Dim rgx3 As New Regex(pattern, options)
        'str_bajada = rgx3.Replace(str_bajada, "")
        'pattern = "<object[A-Za-zñáéíóú\s0-9=""-/\.:]*><\/object>"
        'Dim rgx4 As New Regex(pattern, options)
        'str_bajada = rgx4.Replace(str_bajada, "")
        '' saca los br
        'str_bajada = str_bajada.Replace("<br />", "&nbsp;")
       
        Dim n_pos As Integer

        '' str_bajada = "<p class=""Firma_nota"">Por <b>ALEJANDRO CASTAÑEDA</b></p><br><br><br><br><p><b><a href=""mailto:afcastab@gmail.com?subject=Referencia de EL DIA"">afcastab@gmail.com </a></b></p>"

        If str_bajada.Length > int_limite Then
            n_pos = str_bajada.IndexOf(" ", int_limite)
            If n_pos > 0 Then
                str_bajada = str_bajada.Substring(0, n_pos) + " ..."
                ''Primero saco los <a> que no tengan el cierre antes del punto suspensivo
                If str_bajada.LastIndexOf("<a") > str_bajada.LastIndexOf("</a>") Then
                    str_bajada = str_bajada.Remove(str_bajada.IndexOf("<a"), str_bajada.Length - str_bajada.IndexOf("<a"))
                End If
                ''Después cierro las etiquetas que puedan quedar abiertas
                If str_bajada.LastIndexOf("<b>") > str_bajada.LastIndexOf("</b>") Then
                    str_bajada += "</b>"
                End If
                If str_bajada.LastIndexOf("<strong>") > str_bajada.LastIndexOf("</strong>") Then
                    str_bajada += "</strong>"
                End If
                If str_bajada.LastIndexOf("<span") > str_bajada.LastIndexOf("</span") Then
                    str_bajada += "</span>"
                End If
                If str_bajada.LastIndexOf("<i>") > str_bajada.LastIndexOf("</i>") Then
                    str_bajada += "</i>"
                End If
                If str_bajada.LastIndexOf("<div") > str_bajada.LastIndexOf("</div>") Then
                    str_bajada += "</div>"
                End If
                If str_bajada.LastIndexOf("<script") > str_bajada.LastIndexOf("</script>") Then
                    str_bajada += "</script>"
                End If
                If str_bajada.LastIndexOf("<p") > str_bajada.LastIndexOf("</p>") Then
                    str_bajada += "</p>"
                End If
     
            End If
        End If
        Return func.ConvertUTF(str_bajada)
    End Function

    Public Shared Function Puntos_suspensivos(ByVal str_bajada As String) As String
        Dim n_pos As Integer
        If str_bajada.Length > limite_bajada Then
            n_pos = str_bajada.IndexOf(" ", limite_bajada)
            If n_pos > 0 Then
                str_bajada = str_bajada.Substring(0, n_pos) + " ..."
            End If
        End If
        Return func.ConvertUTF(str_bajada)
    End Function


    Public Shared Sub CuentaEncuesta(ByVal id_opcion As Long)
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_cuenta_encuesta", New SqlParameter() {db.MakeParameter("@id", id_opcion)})
    End Sub

    Public Shared Function LeeOpciones(ByVal id_encuesta As Long) As SqlDataReader
        LeeOpciones = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_lee_opciones", New SqlParameter() {db.MakeParameter("@id", id_encuesta)}, LeeOpciones)
    End Function

    Public Shared Function CuentaOpcionesEncuesta(ByVal id_encuesta As Long) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        Return db.RunProcedure("sp_cuenta_opciones", New SqlParameter() {db.MakeParameter("@id", id_encuesta)})
    End Function

    Public Shared Function LeeEncuesta(ByVal idNoticia As Long) As SqlDataReader
        LeeEncuesta = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_existe_encuesta", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia)}, LeeEncuesta)
    End Function

    Public Shared Sub GraboOpinion(ByVal idn As Int64, ByVal origen As Integer, ByVal remote_ip As String, ByVal opinion As String, ByVal id_usu As Int64)
        Dim db As New Database
        db.RunProcedure("sp_GraboOpinion", New SqlParameter() {db.MakeParameter("@idn", idn), _
        db.MakeParameter("@origen", origen), db.MakeParameter("@remote_ip", remote_ip), db.MakeParameter("@opinion", opinion), _
        db.MakeParameter("@id_usu", id_usu)})
    End Sub

    Public Shared Sub AgregoExitosos(ByVal id_usu As Int64)
        Dim db As New Database
        db.RunProcedure("sp_AgregoExitosos", New SqlParameter() {db.MakeParameter("@id_usu", id_usu)})
    End Sub

    Public Shared Function BuscoDenunciantes(ByVal idc As Int64) As SqlDataReader
        BuscoDenunciantes = Nothing
        Dim db As New Database
        db.RunProcedure("sp_BuscoDenunciantes", New SqlParameter() {db.MakeParameter("@idc", idc)}, BuscoDenunciantes)
    End Function

    Public Shared Sub AceptaDenuncia(ByVal idc As Int64, ByVal id_denunciado As Int64)
        Dim db As New Database
        db.RunProcedure("sp_AceptaDenuncia", New SqlParameter() {db.MakeParameter("@idc", idc), db.MakeParameter("@id_denunciado", id_denunciado)})
    End Sub

    Public Shared Sub SumaUnoDenuncias(ByVal id_usu As Int64, ByVal id_denunciado As Int64)
        Dim db As New Database
        db.RunProcedure("sp_sumaUnoDenuncia", New SqlParameter() {db.MakeParameter("@id_usu", id_usu), db.MakeParameter("@id_denunciado", id_denunciado)})
    End Sub

    Public Shared Function sumaDenuncia(ByVal idc As Int64, ByVal cantidad As Integer) As SqlDataReader
        sumaDenuncia = Nothing
        Dim db As New Database
        db.RunProcedure("sp_sumaDenuncia", New SqlParameter() {db.MakeParameter("@idc", idc), db.MakeParameter("@cantidad", cantidad)}, sumaDenuncia)
    End Function

    Public Shared Sub agregaDenuncia(ByVal idc As Int64, ByVal id_usu As Int64, ByVal ip_origen As String)
        Dim db As New Database
        db.RunProcedure("sp_agregaDenuncia", New SqlParameter() {db.MakeParameter("@idc", idc), db.MakeParameter("@id_usu", id_usu), db.MakeParameter("@ip", ip_origen)})
    End Sub

    Public Shared Function verDenuncias(ByVal idc As Int64, ByVal id_usu As Int64) As Boolean
        Dim db As New Database
        Return db.RunProcBool("sp_verDenuncias", New SqlParameter() {db.MakeParameter("@idc", idc), db.MakeParameter("@id_usu", id_usu)})
    End Function

    Public Shared Function LeeOpiniones(ByVal idNoticia As Long, ByVal origen As Integer) As SqlDataReader
        LeeOpiniones = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_lee_opiniones", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia), _
                        db.MakeParameter("@origen", origen)}, LeeOpiniones)
    End Function

    Public Shared Function LeeVotos(ByVal idNoticia As Long) As SqlDataReader
        LeeVotos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_lee_votos", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia)}, LeeVotos)
    End Function

    Public Shared Sub cuenta_votos(ByVal idNoticia As Long, ByVal origen As Integer)
        '' cada vez que alguien vota, agrega uno
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_cuenta_votos", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia), db.MakeParameter("@origen", origen)})
    End Sub

    Public Shared Function LeeNota(ByVal categoria As Integer) As SqlDataReader
        LeeNota = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("spcu_leenota", New SqlParameter() {db.MakeParameter("@categoria", categoria)}, LeeNota)
    End Function

    Public Shared Function LeeNotax(ByVal categoria As Integer, ByVal suple As Integer, ByVal fecha_limite As String) As SqlDataReader
        LeeNotax = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("spx_leenota", New SqlParameter() {db.MakeParameter("@categoria", categoria), db.MakeParameter("@suple", suple), db.MakeParameter("@fecha_limite", fecha_limite)}, LeeNotax)
    End Function

    Public Shared Function LeeNotaCu(ByVal categoria As Integer, ByVal fecha_limite As String) As SqlDataReader
        LeeNotaCu = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("spcu_leenota", New SqlParameter() {db.MakeParameter("@categoria", categoria), db.MakeParameter("@fecha_limite", fecha_limite)}, LeeNotaCu)
    End Function

    Public Shared Function LeeCol(ByVal fecha As String, ByVal col As Integer, ByVal n_secc As Integer, ByVal mos As Boolean) As SqlDataReader
        LeeCol = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_lee_columnas", New SqlParameter() {db.MakeParameter("@fecha", fecha), _
        db.MakeParameter("@col", col), db.MakeParameter("@n_secc", n_secc), db.MakeParameter("@mos", mos)}, LeeCol)
    End Function

    Public Shared Function LeeSaludos(ByVal Identificador As Integer) As SqlDataReader
        LeeSaludos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_leesaludos", New SqlParameter() {db.MakeParameter("@Identificador", Identificador)}, LeeSaludos)
    End Function

    Public Shared Function InsertaSaludo(ByVal Remitente As String, ByVal Mensaje As String, _
   ByVal Epigrafe As String, ByVal foto As Boolean, ByVal aprobado As Boolean, ByVal Identificador As Integer) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")

        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), _
        db.MakeParameter("@Remitente", Remitente), db.MakeParameter("@Mensaje", Mensaje), _
        db.MakeParameter("@epigrafe", Epigrafe), db.MakeParameter("@foto", foto), db.MakeParameter("@aprobado", aprobado), _
        db.MakeParameter("@Identificador", Identificador)}

        db.RunProcedure("sp_insertasaludo", parameters)

        InsertaSaludo = CInt(parameters(0).Value)
    End Function

    Public Shared Function InsertaMensaje(ByVal Hijos As String, ByVal Madre As String, ByVal Mensaje As String, _
   ByVal email As String, ByVal foto As Boolean, ByVal aprobado As Boolean) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")

        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), _
        db.MakeParameter("@Hijos", Hijos), db.MakeParameter("@Madre", Madre), db.MakeParameter("@Mensaje", Mensaje), _
        db.MakeParameter("@email", email), db.MakeParameter("@foto", foto), db.MakeParameter("@aprobado", True)}

        db.RunProcedure("sp_insertamensaje", parameters)

        InsertaMensaje = CInt(parameters(0).Value)
    End Function

    Public Shared Function leemensaje(ByVal Id As Integer) As SqlDataReader
        leemensaje = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_leemensaje", New SqlParameter() {db.MakeParameter("@Id", Id)}, leemensaje)
    End Function

    'Public Shared Sub EditaPerfil(ByVal id_usu As Integer, ByVal email As String, ByVal Direccion As String, _
    'ByVal telefono As String, ByVal dni As String, ByVal titulares As Integer, ByVal imagen As Integer)

    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    db.RunProcedure("sp_EditaPerfil", New SqlParameter() {db.MakeParameter("@id_usu", id_usu), _
    '    db.MakeParameter("@email", email), db.MakeParameter("@direccion", Direccion), _
    '    db.MakeParameter("@telefono ", telefono), db.MakeParameter("@dni", dni), db.MakeParameter("@titulares", titulares), db.MakeParameter("@imagen", imagen)})

    'End Sub

    Public Shared Function extrae_hora_vinc(ByVal hora As String) As String
        If hora.Length >= 18 Then
            If IsNumeric(hora.Replace(".htm", "")) Then
                Dim str_hora As String
                str_hora = hora.Substring(14, 4)
                Return "<span class=""Small"">&nbsp;&nbsp;|&nbsp;&nbsp;" + _
                        str_hora.Chars(0) + str_hora.Chars(1) + ":" + str_hora.Chars(2) + str_hora.Chars(3) + _
                        "</span>"
            Else
                Return ""
            End If
        Else
            Return ""
        End If
    End Function

    Public Shared Function especiales() As SqlDataReader
        especiales = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_especiales", especiales)

    End Function

    '' para ver si se publica el vínculo de agregar comentarios:
    Public Shared Function ver_comentario(ByVal IdNoticia As Long) As SqlDataReader
        ver_comentario = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_pub_comentario", New SqlParameter() {db.MakeParameter("@IdNoticia", IdNoticia)}, ver_comentario)
    End Function

    Public Shared Function ver_signo(ByVal fechahoy As String) As SqlDataReader
        ver_signo = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_versigno", New SqlParameter() {db.MakeParameter("@fechahoy", fechahoy)}, ver_signo)
    End Function

    Public Shared Function lee_horos(ByVal f1 As String, ByVal f2 As String) As SqlDataReader
        lee_horos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_leehoros", New SqlParameter() {db.MakeParameter("@f1", f1), db.MakeParameter("@f2", f2)}, lee_horos)

    End Function

    Public Shared Function lee_signos(ByVal id As Integer) As SqlDataReader
        lee_signos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_leesignos", New SqlParameter() {db.MakeParameter("@id", id)}, lee_signos)

    End Function

    Public Shared Function ver_signochino(ByVal añohoy As String) As SqlDataReader
        ver_signochino = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_versignochino", New SqlParameter() {db.MakeParameter("@añohoy", añohoy)}, ver_signochino)

    End Function

    Public Shared Function lee_chino(ByVal f1 As String, ByVal f2 As String) As SqlDataReader
        lee_chino = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_leechino", New SqlParameter() {db.MakeParameter("@f1", f1), db.MakeParameter("@f2", f2)}, lee_chino)

    End Function

    Public Shared Function lee_suerte(ByVal f1 As String, ByVal f2 As String) As SqlDataReader
        lee_suerte = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_leesuerte", New SqlParameter() {db.MakeParameter("@f1", f1), db.MakeParameter("@f2", f2)}, lee_suerte)

    End Function


    Public Shared Sub InsertaTemasEnForos(ByVal titulo As String, ByVal desarrollo As String, ByVal autor As String, ByVal seccion As String)
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("Foro_insertar_nuevo", New SqlParameter() {db.MakeParameter("@titulo", titulo), db.MakeParameter("@desarrollo", desarrollo), _
        db.MakeParameter("@autor", autor), db.MakeParameter("@seccion", seccion)})
    End Sub



    Public Shared Function lee_signoschinos(ByVal id As Integer) As SqlDataReader
        lee_signoschinos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_leesignoschinos", New SqlParameter() {db.MakeParameter("@id", id)}, lee_signoschinos)

    End Function

    Public Shared Function fecha1(ByVal fecha As String, ByVal incremento As Integer) As Date
        If fecha Is Nothing Then
            Return Date.Now
        Else
            Try
                Return (DateTime.Parse(fecha.Substring(0, 4) + "/" + fecha.Substring(4, 2) + "/" + fecha.Substring(6, 2))).AddDays(incremento) ' fecha siguiente

            Catch ex As Exception
                admin.errores(func.admin_errores + "func.fecha1: " + fecha)
                Return Date.Now
            End Try
        End If
    End Function

    'Public Shared Function auth_copia(ByVal str_usuario As String, ByVal str_passw As String) As SqlDataReader

    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    auth_copia = Nothing
    '    db.RunProcedure("sp_autoriza_copia", New SqlParameter() {db.MakeParameter("@usuario", str_usuario), _
    '    db.MakeParameter("@passw", str_passw)}, auth_copia)

    'End Function
    'Public Shared Function auth(ByVal str_usuario As String, ByVal str_passw As String) As SqlDataReader

    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    auth = Nothing
    '    db.RunProcedure("sp_autoriza", New SqlParameter() {db.MakeParameter("@usuario", str_usuario), _
    '    db.MakeParameter("@passw", str_passw)}, auth)

    'End Function

    'Public Shared Sub cuenta_visitas(ByVal id As Integer, ByVal fecha As Date)
    '    '' cada vez que alguien se registra, agrega uno
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    Dim DReader As SqlDataReader = Nothing
    '    db.RunProcedure("sp_visitas", New SqlParameter() {db.MakeParameter("@id", id), _
    '    db.MakeParameter("@fecha", fecha)}, DReader)
    'End Sub

    'Public Shared Function DatosPlanilla(ByVal id1 As Integer, ByVal id2 As Integer) As SqlDataReader
    '    'para armar la planilla de datos del posible usuario
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    DatosPlanilla = Nothing
    '    db.RunProcedure("sp_regdatos", New SqlParameter() {db.MakeParameter("@id1", id1), db.MakeParameter("@id2", id2)}, _
    '    DatosPlanilla)
    'End Function


    'Public Shared Function ver_mail(ByVal email As String) As SqlDataReader
    '    ver_mail = Nothing
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    Dim DReader As SqlDataReader = Nothing
    '    db.RunProcedure("sp_vermail", New SqlParameter() {db.MakeParameter("@email", email)}, ver_mail)

    'End Function

    'Public Shared Sub olvido(ByVal id As Integer)
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    db.RunProcedure("sp_olvido", New SqlParameter() {db.MakeParameter("@id", id)})
    'End Sub


    'Public Shared Function ver_usu(ByVal usuario As String) As SqlDataReader
    '    ver_usu = Nothing
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    db.RunProcedure("sp_usuario", New SqlParameter() {db.MakeParameter("@usuario", usuario)}, ver_usu)
    'End Function

    'Public Shared Sub borrar(ByVal id As Integer, ByVal usuario As String)
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    db.RunProcedure("sp_borrar", New SqlParameter() {db.MakeParameter("@id", id), _
    '    db.MakeParameter("@usuario", usuario)})
    'End Sub

    'Public Shared Sub AddUsu(ByVal apellido As String, ByVal nombre As String, ByVal f_nac As Date, _
    'ByVal direccion As String, ByVal localidad As String, ByVal provincia As String, ByVal pais As String, _
    'ByVal postal As String, ByVal e_mail As String, ByVal usuario As String, ByVal comen As String, _
    'ByVal n_visitas As Integer, ByVal fecha_ini As Date, ByVal fecha_ult As Date, _
    'ByVal fecha_alta As Date, ByVal autorizo As Int16, ByVal nivel As Int16, ByVal sec_origen As Int16, _
    'ByVal ocupacion As Int16, ByVal cargo As Int16, ByVal conexion As Int16, ByVal passw As String)
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    db.RunProcedure("sp_addusu", New SqlParameter() {db.MakeParameter("@apellido", apellido), _
    '    db.MakeParameter("@nombre", nombre), db.MakeParameter("@f_nac", f_nac), db.MakeParameter("@direccion", direccion), _
    '    db.MakeParameter("@localidad", localidad), db.MakeParameter("@provincia", provincia), db.MakeParameter("@pais", pais), _
    '    db.MakeParameter("@postal", postal), db.MakeParameter("@e_mail", e_mail), db.MakeParameter("@usuario", usuario), _
    '    db.MakeParameter("@comen", comen), db.MakeParameter("@n_visitas", n_visitas), db.MakeParameter("@fecha_ini", fecha_ini), _
    '    db.MakeParameter("@fecha_ult", fecha_ult), db.MakeParameter("@fecha_alta", fecha_alta), db.MakeParameter("@autorizo", autorizo), _
    '    db.MakeParameter("@nivel", nivel), db.MakeParameter("@sec_origen", sec_origen), db.MakeParameter("@ocupacion", ocupacion), _
    '    db.MakeParameter("@cargo", cargo), db.MakeParameter("@conexion", conexion), db.MakeParameter("@passw", passw)})
    'End Sub

    ' Public Shared Sub HabilitaTitulares(ByVal usuario As String)

    '     Dim db As New Database
    '     db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '     db.RunProcedure("sp_habilita_titulares", New SqlParameter() {db.MakeParameter("@usuario", usuario)})
    ' End Sub

    ' Public Shared Sub DardebajaTitulares(ByVal usuario As String)

    '     Dim db As New Database
    '     db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '     db.RunProcedure("sp_baja_titulares", New SqlParameter() {db.MakeParameter("@usuario", usuario)})
    ' End Sub


    ' Public Shared Function AddUsu1(ByVal apellido As String, ByVal nombre As String, ByVal f_nac As Date, _
    'ByVal direccion As String, ByVal localidad As String, ByVal provincia As String, ByVal pais As String, _
    'ByVal postal As String, ByVal e_mail As String, ByVal usuario As String, ByVal comen As String, _
    'ByVal n_visitas As Integer, ByVal fecha_ini As Date, ByVal fecha_ult As Date, _
    'ByVal fecha_alta As Date, ByVal autorizo As Int16, ByVal nivel As Int16, ByVal sec_origen As Int16, _
    'ByVal ocupacion As Int16, ByVal cargo As Int16, ByVal conexion As Int16, ByVal passw As String, _
    ' ByVal titulares As Integer) As Integer
    '     Dim db As New Database
    '     db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")

    '     Dim parameters() As SqlParameter = {db.MakeParameter("@ItemID", ParameterDirection.Output, 0), _
    '     db.MakeParameter("@apellido", apellido), _
    '     db.MakeParameter("@nombre", nombre), db.MakeParameter("@f_nac", f_nac), db.MakeParameter("@direccion", direccion), _
    '     db.MakeParameter("@localidad", localidad), db.MakeParameter("@provincia", provincia), db.MakeParameter("@pais", pais), _
    '     db.MakeParameter("@postal", postal), db.MakeParameter("@e_mail", e_mail), db.MakeParameter("@usuario", usuario), _
    '     db.MakeParameter("@comen", comen), db.MakeParameter("@n_visitas", n_visitas), db.MakeParameter("@fecha_ini", fecha_ini), _
    '     db.MakeParameter("@fecha_ult", fecha_ult), db.MakeParameter("@fecha_alta", fecha_alta), db.MakeParameter("@autorizo", autorizo), _
    '     db.MakeParameter("@nivel", nivel), db.MakeParameter("@sec_origen", sec_origen), db.MakeParameter("@ocupacion", ocupacion), _
    '     db.MakeParameter("@cargo", cargo), db.MakeParameter("@conexion", conexion), db.MakeParameter("@passw", passw), _
    '     db.MakeParameter("@titulares", titulares)}

    '     db.RunProcedure("sp_addusu1", parameters)

    '     AddUsu1 = CInt(parameters(0).Value)
    ' End Function

    'Public Shared Sub InsertaValores(ByVal valor As Integer)
    '    Dim db As New Database
    '    db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clasi3")
    '    db.RunProcedure("sp_valores", New SqlParameter() {db.MakeParameter("@valor", valor)})
    'End Sub

    Public Shared Function ConvertUTF(ByVal texto As String) As String
        If texto.Length > 3 Then
            texto = texto.Trim
            If texto.Length > 0 Then
                If StrReverse(texto).Chars(0) = "_" Then
                    If StrReverse(texto).Chars(1) = "_" Then
                        If StrReverse(texto).Chars(2) = "_" Then
                            texto = texto.Remove(texto.LastIndexOf("___"), 3)
                        Else
                            texto = texto.Remove(texto.LastIndexOf("__"), 2)
                        End If
                    Else
                        texto = texto.Remove(texto.LastIndexOf("_"), 1)
                    End If
                End If
            End If
            If texto.Length > 0 Then
                If StrReverse(texto).Chars(0) = "." And Not StrReverse(texto).Chars(1) = "." Then       '' saco el punto final, si lo hay
                    texto = texto.Remove(texto.LastIndexOf("."), 1)
                End If
            End If
        Else
            texto = texto
        End If
        ''
        texto = ExtendedHtmlUtility.HtmlEntityEncode(texto, True)  '' función agregada en C#
        Return texto
    
    End Function

    Public Shared Function Extrae_bold(ByVal tex As String) As String
        'tengo que devolver lo que está dentro de <b> y </b>, separado por <br />
        Dim n_posi1, n_posi2 As Integer
        'Dim str_aux As String
        Dim str_b As New StringBuilder

        'str_aux = ""
        n_posi2 = 0

        While tex.IndexOf("<b>", n_posi2) >= 0
            n_posi1 = tex.IndexOf("<b>", n_posi2)
            ''n_posi1 = tex.IndexOf("<b>", n_posi2)
            If n_posi2 >= 0 Then                            'hay bold
                n_posi2 = tex.IndexOf("</b>", n_posi1 + 3)
                If n_posi2 < 0 Then
                    Exit While
                End If
            End If
            If n_posi2 > n_posi1 Then
                str_b.Append("- " + tex.Substring(n_posi1 + 3, n_posi2 - n_posi1 - 3) + "<br />")
            End If
            n_posi2 += 4  'largo de <b/>
        End While
        Return str_b.ToString
    End Function

    Public Shared Function LeoAviso(ByVal id As Int64) As SqlDataReader
        LeoAviso = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leoaviso", New SqlParameter() {db.MakeParameter("@id", id)}, LeoAviso)
    End Function

    Public Shared Function LeoUltimosAvisos(ByVal rubro As Integer) As SqlDataReader
        LeoUltimosAvisos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leoultimosavisos", New SqlParameter() {db.MakeParameter("@rubro", rubro)}, LeoUltimosAvisos)
    End Function

    Public Shared Function LeoRubros(ByVal rubro As Integer) As SqlDataReader
        LeoRubros = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leourubros", New SqlParameter() {db.MakeParameter("@rubro", rubro)}, LeoRubros)
    End Function
    Public Shared Function LeoRubros() As SqlDataReader
        LeoRubros = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leourubros", LeoRubros)
    End Function

    Public Shared Function LeoUltimosAvisos() As SqlDataReader
        LeoUltimosAvisos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leoultimosavisos", LeoUltimosAvisos)
    End Function
    Public Shared Function LeoAvisosInt(ByVal rubro As Integer, ByVal tipoav As Integer) As SqlDataReader
        LeoAvisosInt = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leoavisosint", New SqlParameter() {db.MakeParameter("@rubro", rubro), db.MakeParameter("@tipoav", tipoav)}, LeoAvisosInt)
    End Function
    Public Shared Function LeoAvisosInt(ByVal tipoav As Integer) As SqlDataReader
        LeoAvisosInt = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leoavisosint", New SqlParameter() {db.MakeParameter("@tipoav", tipoav)}, LeoAvisosInt)
    End Function
    Public Shared Function LeoRubrosInt(ByVal rubro As Integer, ByVal tipoav As Integer) As SqlDataReader
        LeoRubrosInt = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leourubrosint", New SqlParameter() {db.MakeParameter("@rubro", rubro), db.MakeParameter("@tipoav", tipoav)}, LeoRubrosInt)
    End Function
    Public Shared Function LeoRubrosInt(ByVal tipoav As Integer) As SqlDataReader
        LeoRubrosInt = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_clientes")
        db.RunProcedure("sp_leourubrosint", New SqlParameter() {db.MakeParameter("@tipoav", tipoav)}, LeoRubrosInt)
    End Function

    Public Shared Function LeoUsuariosVip() As SqlDataReader
        LeoUsuariosVip = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_usuarios_vip", LeoUsuariosVip)
    End Function

    Public Shared Function LeoUsuariosIp() As SqlDataReader
        LeoUsuariosIp = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_usuarios_ip", LeoUsuariosIp)
    End Function


    Public Shared Function ver_seccion(ByVal ids As Integer) As SqlDataReader
        ver_seccion = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_ver_seccion", New SqlParameter() {db.MakeParameter("@ids", ids)}, ver_seccion)
    End Function


    Public Shared Function LeeSeccionesForos() As SqlDataReader
        LeeSeccionesForos = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_lee_secciones_foros", LeeSeccionesForos)
    End Function

    Public Shared Sub InsertaEstado(ByVal texto As String, ByVal id_origen As Int64)
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_insertar_estado", New SqlParameter() {db.MakeParameter("@texto", texto), db.MakeParameter("@id_origen", id_origen)})
    End Sub

    Public Shared Function LeeStatusAmigo(ByVal id_amigo As Int64) As SqlDataReader
        LeeStatusAmigo = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_amigos_lee_status", New SqlParameter() {db.MakeParameter("@id_amigo", id_amigo)}, LeeStatusAmigo)
    End Function

    Public Shared Function LeeDefensor() As SqlDataReader
        LeeDefensor = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_lee_defensor", LeeDefensor)
    End Function

    Public Shared Function LeeDefensorAmpliada(ByVal id As Integer) As SqlDataReader
        LeeDefensorAmpliada = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_lee_defensor_ampliada", New SqlParameter() {db.MakeParameter("@id", id)}, LeeDefensorAmpliada)
    End Function

    Public Shared Sub InsertaDenuncia(ByVal comentario As String, ByVal remitente As String)
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_ins_denuncia", New SqlParameter() {db.MakeParameter("@comentario", comentario), db.MakeParameter("@remitente", remitente)})
    End Sub

    Public Shared Sub InsertaInvitacionAmigo(ByVal id_origen As Int64, ByVal id_amigo As Int64)
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_ins_invita_amigo", New SqlParameter() {db.MakeParameter("@id_origen", id_origen), db.MakeParameter("@id_amigo", id_amigo)})
    End Sub

    Public Shared Function FechaHoraSql() As SqlDataReader
        FechaHoraSql = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        db.RunProcedure("sp_fechahora", FechaHoraSql)
    End Function

    Public Shared Function GetSearchWords(ByVal text As String) As String
        text = text.Replace(",", " ").Replace("""", "")
        Dim re As Regex = New Regex("[A-za-záéíóú&#0-9;,\.]{4,}")
        ''Dim re As Regex = New Regex("\b(\w+)\b\s*\1\b")  '' para buscar palabras repetidas
        Dim matches As MatchCollection = re.Matches(text)
        Dim words() As String = New String((matches.Count) - 1) {}

        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim int_cuenta As Integer = matches.Count
        Do While (i < int_cuenta)
            Dim str_match1 As String = matches(i).Value.TrimEnd.TrimStart.Replace(",", "").Replace(".", "")
            i += 1
        Loop
        i = 0
        Do While (i < int_cuenta)
            Dim str_match As String = matches(j).Value.TrimEnd.TrimStart.Replace(",", "").Replace(".", "")
            Array.Sort(words)
            If Array.BinarySearch(words, str_match) >= 0 Then
                int_cuenta -= 1
            Else
                words(0) = str_match  '' el sort siempre coloca arriba a nothing
                i += 1
            End If
            j += 1
        Loop
        Dim str_palabra_clave, str_retorno As String
        str_retorno = ""
        For Each str_palabra_clave In words
            If Not str_palabra_clave Is Nothing Then
                str_retorno += str_palabra_clave + ","
            End If
        Next       
        Return str_retorno
    End Function

    Public Shared Function resumen(ByVal texto As String, ByVal id As Integer, ByVal mayusculas As Boolean, ByVal str_vinculo As String, ByVal str_ancho As String, _
    ByVal str_alto As String, ByVal int_limite As Integer, ByVal str_yes_no As String) As String
        Dim n_pos As Integer
        If texto <> "" Then
            'me fijo si está todo en mayúsculas:
            If mayusculas Then
                If texto.Substring(0, 3) = texto.Substring(0, 3).ToUpper Then
                    texto = texto.ToLower
                    texto = texto.Chars(0).ToString.ToUpper + texto.Remove(0, 1)  '' la primera con mayúscula
                End If
            End If

            If texto.Length > int_limite Then
                texto = texto.Substring(0, int_limite)
                n_pos = texto.LastIndexOf(" ")
                If n_pos > 0 Then
                    Return texto.Substring(0, n_pos) + "...&nbsp;<a href=""Javascript:NuevaVentana('" + str_vinculo + "?id=" + id.ToString + "'" + "," + str_ancho + "," + str_alto + ",'" + str_yes_no + "')"">(ampliar)</a>"
                Else
                    Return texto
                End If
            Else
                Return texto
            End If
        Else
            Return texto
        End If

    End Function

    Public Shared Function InsertaAgenda(ByVal genero As Int32, ByVal evento As String, ByVal fecha As Date, ByVal horario As String, ByVal lugar As String, _
    ByVal direccion As String, ByVal detalles As String, ByVal gratuito As Boolean, ByVal telefono As String, ByVal n_id As String) As Int64
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")

        Dim parameters() As SqlParameter = {db.MakeParameter("@id", ParameterDirection.Output, 0), db.MakeParameter("@genero", genero), db.MakeParameter("@evento", evento), _
        db.MakeParameter("@fecha", fecha), db.MakeParameter("@horario", horario), db.MakeParameter("@lugar", lugar), db.MakeParameter("@direccion", direccion), _
        db.MakeParameter("@detalles", detalles), db.MakeParameter("@gratuito", gratuito), db.MakeParameter("@telefono", telefono), db.MakeParameter("@n_id", n_id)}

        db.RunProcedure("sp_insertaagenda", parameters)

        InsertaAgenda = CInt(parameters(0).Value)

    End Function

    Public Shared Function veridevento(ByVal idtablero As Integer) As SqlDataReader
        veridevento = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_tablero")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_veridevento", New SqlParameter() {db.MakeParameter("@idtablero", idtablero)}, veridevento)
    End Function

    Public Shared Function muestrafutbol(ByVal eventid As Integer) As SqlDataReader
        muestrafutbol = Nothing
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_tablero")
        Dim DReader As SqlDataReader = Nothing
        db.RunProcedure("sp_futbol_muestra", New SqlParameter() {db.MakeParameter("@eventid", eventid)}, muestrafutbol)
    End Function


    Public Shared Function HabilitaOpiniones(ByVal idNoticia As Int64, ByVal ori As Integer) As Boolean
        Dim db As New Database
        Return db.RunProcBool("sp_HabilitaOpiniones", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia), db.MakeParameter("@ori", ori)})
    End Function

    Public Shared Function ChequeaFotosExtras(ByVal idNoticia As Int64) As Boolean
        Dim db As New Database
        Return db.RunProcBool("sp_ChequeaFotosExtras", New SqlParameter() {db.MakeParameter("@idNoticia", idNoticia)})
    End Function

    Public Shared Function BuscaTitulosExternos(ByVal id_seccion As Integer) As String
        Dim db As New Database
        Return db.RunProcstring("sp_BuscaTitulosExternos", New SqlParameter() {db.MakeParameter("@id_seccion", id_seccion)})
    End Function

    Public Shared Function DevuelveIdTexto(ByVal idnoticia As Long) As Integer
        Dim db As New Database
        db.ConString = System.Configuration.ConfigurationManager.AppSettings("con_ed1")
        Dim DReader As SqlDataReader = Nothing
        Return db.RunProcedure("sp_DevuelveIdTexto", New SqlParameter() {db.MakeParameter("@idnoticia", idnoticia)})
    End Function
End Class
