Imports Telerik.Web.UI

Public Class Aktuality_Upravit
	Inherits System.Web.UI.UserControl

	Public cTitle As Admin.Title
    Public sStrankaID As String = "100"
    Public sID As String  'ID zaznamu

	Public sAdresaSave As String = gadrAktuality_upravit
    Public sAdresaStorno As String = gadrAktuality
    Public sAdresaZaznam As String = gadrAktuality_upravit

    Public sAdresaUpravit As String = gadrAktuality_foto_upravit
    Public sAdresaOdstranit As String = gadrAktuality_foto_odstranit

    Public sTable As String = "[aktuality].[list]"
    Public sTableFoto As String = "[aktuality].[fotogalerie]"

    Public bShowLocalization As Boolean = True

	Private sFotoCestaRelativni As String = _PathFotoRelative & "/Aktuality"
	Private sFotoCestaAbsolutni As String = _PathFoto & "\Aktuality"
	Public bPovolitVerzeFotografii As Boolean = True

	''' <summary>
	''' Seznam zaznamu - upravit zaznam
	''' Verze: 1.0
	''' </summary>
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		cmdSave.Attributes.Add("onclick", "ShowPopInfo('" & gstrProbihaUkladaniZaznamu & "');")

		cTitle._Nadpis("Aktuality")

        '# Inicializace fotografie
        Dim l As New PCSolution.Localize

        l.RadAsyncUpload(cmdFoto)
        cmdFoto.OnClientFilesUploaded = "fUploaded"
        cmdFoto.AllowedFileExtensions = New String(1) {".jpg", ".png"}
        cmdFoto.Localization.Select = "Přidat fotografii"
        cmdFoto.Width = Unit.Pixel(50)

        l.RadAsyncUpload(cmdFoto1)
		cmdFoto1.OnClientFilesUploaded = "fUploaded"
		cmdFoto1.AllowedFileExtensions = New String(1) {".jpg", ".png"}
		cmdFoto1.Width = Unit.Pixel(50)
        'l.RadAsyncUpload(cmdFoto2)
        'cmdFoto2.OnClientFilesUploaded = "fUploaded"
        'cmdFoto2.AllowedFileExtensions = New String(1) {".jpg", ".png"}
        'cmdFoto2.Width = Unit.Pixel(50)
        'l.RadAsyncUpload(cmdFoto3)
        'cmdFoto3.OnClientFilesUploaded = "fUploaded"
        'cmdFoto3.AllowedFileExtensions = New String(1) {".jpg", ".png"}
        'cmdFoto3.Width = Unit.Pixel(50)
        l.RadAsyncUpload(cmdSoubor)
		cmdSoubor.OnClientFilesUploaded = "fUploaded"
		cmdSoubor.Width = Unit.Pixel(50)

		sID = Request.QueryString("id")

		lblBC.Text = "<a href=""" & gadrAktuality & """>Aktuality</a>"

		If sID = "" Then
			lblFoto1.Visible = False
			cmdFoto1Delete.Visible = False
            'lblFoto2.Visible = False
            'cmdFoto2Delete.Visible = False
            'lblFoto3.Visible = False
            'cmdFoto3Delete.Visible = False
            lblSoubor.Visible = False
			cmdSouborDelete.Visible = False
			chkZobrazit.Checked = True
			'ddDatum.SelectedDate = Now
		End If
		'@

		If sID = "0" Then sID = ""

		If sID <> "" Then
			sID = Request.QueryString("id")
			lblCaption.Text = "Aktuality"
			cTitle._Podnadpis("upravit")
		Else
			lblCaption.Text = "Aktuality"
			cTitle._Podnadpis("nová aktualita")
			lblBC.Text &= "➞ Nová aktualita"
		End If

        If IsPostBack = False Then
            Me.UmisteniFotografie()
            Me.NacistData()
        End If

        Me.NacistFotogalerii()

        Dim pSort As New PCSolution.SortItems
        pSort.InsertSorting(sTableFoto, PCSolution.SortItems.eRazeni.Seznam)

        txtNadpis.Focus()

    End Sub

#Region "  NACIST UMISTENI FOTOGRAFIE  "

    Sub UmisteniFotografie()

        Dim p As New PCSolution.Foto_umisteni
        p.NaplnitRozbalovaciSeznam(ddFoto_umisteni)

    End Sub

#End Region

#Region "  NACIST DATA  "

    Sub NacistData()

        If sID = "" Then
            ajax.ResponseScripts.Add("$('.label-localize').css('display','none');")
            Exit Sub
        End If

        Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT * FROM " & sTable & " WHERE id = '" & sID & "'")
        If DS.Rows.Count = 0 Then Exit Sub

        Dim cRow As DataRow = DS.Rows(0)

        txtNadpis.Text = cRow("nadpis" & _Language)
        'txtKratkyText.Text = cRow("kratkytext" & _Language)
        txtPopis.Text = cRow("text" & _Language)
        txtSouborPopis.Text = cRow("souborpopis" & _Language)

        ddFoto_umisteni.SelectedValue = cRow("foto_umisteni")

        Try
            ddDatum.SelectedDate = New Date(cRow("datum"))
        Catch ex As Exception
            ddDatum.SelectedDate = Nothing
        End Try

        chkZobrazit.Checked = cRow("zobrazit" & _Language)

        If txtNadpis.Text <> "" Then
            lblBC.Text &= "➞ " & txtNadpis.Text
        Else
            lblBC.Text &= "➞ " & cRow("nadpiscz")
        End If

        '# Lokalizace
        If _Language <> "cz" Then
            lblNadpis.Text = cRow("nadpiscz")
            'lblKratkytext.Text = cRow("kratkytextcz")
            lblText.Text = cRow("textcz")
            lblSouborpopis.Text = cRow("souborpopiscz")
        Else
            ajax.ResponseScripts.Add("$('.label-localize').css('display','none');")
        End If
        '@

        '# Nahled snimku
        If IO.File.Exists(sFotoCestaAbsolutni & "\" & sID & "\01\v" & cRow("foto1verze") & "\Nahled1\" & cRow("foto1nazev") & cRow("foto1pripona")) Then
            lblFoto1.Text = "<img src=""" & sFotoCestaRelativni & "/" & sID & "/01/v" & cRow("foto1verze") & "/Nahled2/" & cRow("foto1nazev") & cRow("foto1pripona") & """ alt=""" & cRow("foto1nazev") & """ />"
            cmdFoto1.Visible = False
            lblFoto1.Visible = True
            cmdFoto1Delete.Visible = True
        Else
            lblFoto1.Visible = False
            cmdFoto1Delete.Visible = False
        End If

        'If IO.File.Exists(sFotoCestaAbsolutni & "\" & sID & "\02\v" & cRow("foto2verze") & "\Nahled1\" & cRow("foto2nazev") & cRow("foto2pripona")) Then
        '	lblFoto2.Text = "<img src=""" & sFotoCestaRelativni & "/" & sID & "/02/v" & cRow("foto2verze") & "/Nahled2/" & cRow("foto2nazev") & cRow("foto2pripona") & """ alt=""" & cRow("foto2nazev") & """ />"
        '	cmdFoto2.Visible = False
        '	lblFoto2.Visible = True
        '	cmdFoto2Delete.Visible = True
        'Else
        '	lblFoto2.Visible = False
        '	cmdFoto2Delete.Visible = False
        'End If
        'If IO.File.Exists(sFotoCestaAbsolutni & "\" & sID & "\03\v" & cRow("foto3verze") & "\Nahled1\" & cRow("foto3nazev") & cRow("foto3pripona")) Then
        '	lblFoto3.Text = "<img src=""" & sFotoCestaRelativni & "/" & sID & "/03/v" & cRow("foto3verze") & "/Nahled2/" & cRow("foto3nazev") & cRow("foto3pripona") & """ alt=""" & cRow("foto3nazev") & """ />"
        '	cmdFoto3.Visible = False
        '	lblFoto3.Visible = True
        '	cmdFoto3Delete.Visible = True
        'Else
        '	lblFoto3.Visible = False
        '	cmdFoto3Delete.Visible = False
        'End If

        If IO.File.Exists(sFotoCestaAbsolutni & "\" & sID & "\Soubor\v" & cRow("souborverze") & "\" & cRow("soubornazev") & cRow("souborpripona")) Then
            lblSoubor.Text = cRow("soubornazev") & cRow("souborpripona")
            cmdSoubor.Visible = False
            lblSoubor.Visible = True
            cmdSouborDelete.Visible = True
        Else
            lblSoubor.Visible = False
            cmdSouborDelete.Visible = False
        End If
        '@

        LoadLink(sStrankaID, sID, txtTitle.Text, txtLink.Text)

    End Sub

#End Region

#Region "  NACIST FOTOGALERII  "

    Sub NacistFotogalerii()

        Dim s As String = ""

        Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT * FROM " & sTableFoto & " WHERE zaznamid = " & sID & " ORDER BY sort")
        If DS.Rows.Count > 0 Then
            s &= "<ul id=""sort"">"
        End If
        For Each cRow As DataRow In DS.Rows

            s &= "<li id=""sort" & cRow("id") & """>"
            s &= "<div class=""image"">" 'Fotografie 
            If IO.File.Exists(sFotoCestaAbsolutni & "\" & sID & "\" & cRow("id") & "\v" & cRow("fotoverze") & "\Nahled3\" & cRow("fotonazev") & cRow("fotopripona")) Then
                s &= "<img src=""" & sFotoCestaRelativni & "/" & sID & "/" & cRow("id") & "/v" & cRow("fotoverze") & "/Nahled3/" & cRow("fotonazev") & cRow("fotopripona") & """ alt=""" & cRow("fotonazev") & """ class=""thumb"" />"
            End If
            s &= "</div>"
            s &= "<div class=""cmdEditovat width-50"" onclick=""location.href='/zaznamid-" & sID & "-" & cRow("id") & sAdresaUpravit & "';"">" 'Tlacitko upravit
            s &= "Upravit"
            s &= "</div>"
            s &= "<div class=""cmdOdstranit width-50"" onclick=""ConfirmDelete('Odstranit fotografii', 'Opravdu chcete odstranit fotografii " & cRow("fotonazev") & cRow("fotopripona") & "?','/zaznamid-" &
                  sID & "-" & cRow("id") & sAdresaOdstranit & "','','');return false;"""">" 'Tlacitko odstranit
            s &= "Odstranit"
            s &= "</div>"
            s &= "</li>"

        Next
        If DS.Rows.Count > 0 Then
            s &= "</ul>"
        End If

        phItems.Controls.Add(New LiteralControl(s)) : s = ""

        If DS.Rows.Count = 0 Then
            phItems.Visible = False
            phNoItem.Controls.Add(New LiteralControl("<div class=""noitem"">Není nalezená žádná fotografie.</div>"))
        End If

    End Sub

#End Region

#Region "  ULOZIT FOTOGRAFII  "

    Private Sub cmdFoto_FileUploaded(sender As Object, e As FileUploadedEventArgs) Handles cmdFoto.FileUploaded

        UlozitZaznam()

        For n As Int16 = 0 To cmdFoto.UploadedFiles.Count - 1

            Dim pDoc As New PCSolution.Document

            Dim sFileName As String = pDoc.OdstranitDiakritiku(IO.Path.GetFileNameWithoutExtension(cmdFoto.UploadedFiles(n).FileName), "-")
            Dim sExt As String = IO.Path.GetExtension(cmdFoto.UploadedFiles(n).FileName)

            '# Vytvorit novou fotografii v databazi
            Dim iFotoID As Int16 = 0
            Dim iSort As Int16 = 0
            Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT max(sort) FROM " & sTableFoto)
            Try
                iSort = DS.Rows(0)(0) + 1
            Catch ex As Exception
                iSort = 1
            End Try

            DB.ExecuteCommand("INSERT INTO " & sTableFoto & " (zaznamid, sort) VALUES (" & sID & ", " & iSort & ")")
            DS = DB.ExecuteSelectCommand("SELECT max(id) FROM " & sTableFoto)
            iFotoID = DS.Rows(0)(0)
            '@

            '# Upravit cestu
            Dim sCesta As String = _PathFoto & "\Aktuality\" & sID & "\" & iFotoID
            '@

            '# Pokud je potreba vytvaret verze souboru, vytvorit novou cilovou slozku pro verzi
            DS = DB.ExecuteSelectCommand("SELECT fotoverze FROM " & sTableFoto & " WHERE id = '" & iFotoID & "'")
            If DS.Rows.Count > 0 Then
                Dim cRow As DataRow = DS.Rows(0)
                If cRow("fotoverze") = 0 Then
                    cRow("fotoverze") = 1
                Else
                    cRow("fotoverze") += 1
                End If
                sCesta &= "\v" & cRow("fotoverze")
                DB.ExecuteCommand("UPDATE " & sTableFoto & " SET fotoverze = " & cRow("fotoverze") & " WHERE id = '" & iFotoID & "'")
            End If
            '@

            IO.Directory.CreateDirectory(sCesta) 'Vytvorit slozku

            '# Nahrat fotografii a zmensit na pozadovany rozmer
            cmdFoto.UploadedFiles(n).SaveAs(sCesta & "\original" & sExt)

            Dim fil As New PCSolution.Images.Images
            fil.SaveFoto(sCesta, sCesta & "\Nahled1", "original" & sExt, sFileName, 1280, 0, 80, sExt)
            fil.SaveFoto(sCesta, sCesta & "\Nahled2", "original" & sExt, sFileName, 600, 0, 80, sExt)
            fil.SaveFoto(sCesta, sCesta & "\Nahled3", "original" & sExt, sFileName, 0, 150, 80, sExt)

            DB.ExecuteCommand("UPDATE " & sTableFoto & " SET fotonazev = '" & sFileName & "', fotopripona = '" & sExt & "' WHERE id = '" & iFotoID & "'")

        Next

        Response.Redirect("/id-" & sID & sAdresaZaznam)

    End Sub

#End Region

#Region "  NAHLED FOTOGRAFIE 1  "

    Private Sub cmdFoto1_FileUploaded(sender As Object, e As FileUploadedEventArgs) Handles cmdFoto1.FileUploaded

		Me.UlozitZaznam()

		For n As Int16 = 0 To cmdFoto1.UploadedFiles.Count - 1

			Dim pDoc As New PCSolution.Document

			Dim sFileName As String = pDoc.OdstranitDiakritiku(IO.Path.GetFileNameWithoutExtension(cmdFoto1.UploadedFiles(n).FileName), "-")
			Dim sExt As String = IO.Path.GetExtension(cmdFoto1.UploadedFiles(n).FileName)

			'# Pokud je potreba vytvaret verze souboru, vytvorit novou cilovou slozku pro verzi
			If bPovolitVerzeFotografii = True Then
				Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT foto1verze FROM " & sTable & " WHERE id = '" & sID & "'")
				If DS.Rows.Count > 0 Then
					Dim cRow As DataRow = DS.Rows(0)
					If cRow("foto1verze") = 0 Then
						cRow("foto1verze") = 1
					Else
						cRow("foto1verze") += 1
					End If
					sFotoCestaAbsolutni &= "\" & sID & "\01\v" & cRow("foto1verze")
					sFotoCestaRelativni &= "/" & sID & "/01/v" & cRow("foto1verze")
					DB.ExecuteCommand("UPDATE " & sTable & " SET foto1verze = " & cRow("foto1verze") & " WHERE id = '" & sID & "'")
				End If
			End If
			'@

			IO.Directory.CreateDirectory(sFotoCestaAbsolutni) 'Vytvorit slozku

			'# Nahrat fotografii a zmensit na pozadovany rozmer
			cmdFoto1.UploadedFiles(n).SaveAs(sFotoCestaAbsolutni & "\original" & sExt)

			Dim fil As New PCSolution.Images.Images
			fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled1", "original" & sExt, sFileName, 1300, 0, 80, sExt)
			fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled2", "original" & sExt, sFileName, 250, 0, 80, sExt)
			fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled3", "original" & sExt, sFileName, 600, 0, 80, sExt)

			DB.ExecuteCommand("UPDATE " & sTable & " SET foto1nazev = '" & sFileName & "', foto1pripona = '" & sExt & "' WHERE id = '" & sID & "'")

		Next

		Response.Redirect("/id-" & sID & sAdresaSave)

	End Sub

	Private Sub cmdFoto1Delete_Click(sender As Object, e As EventArgs) Handles cmdFoto1Delete.Click

		Me.UlozitZaznam()

		Try
			Dim p As New PCSolution.DirectoryDelete
			p.Delete(sFotoCestaAbsolutni & "\" & sID & "\01")
		Catch ex As Exception
		End Try

		DB.ExecuteCommand("UPDATE " & sTable & " SET foto1nazev = '', foto1pripona = '' WHERE id = '" & sID & "'")

		Response.Redirect("/id-" & sID & sAdresaSave)

	End Sub

#End Region

#Region "  NAHLED FOTOGRAFIE 2  "

    'Private Sub cmdFoto2_FileUploaded(sender As Object, e As FileUploadedEventArgs) Handles cmdFoto2.FileUploaded

    '	Me.UlozitZaznam()

    '	For n As Int16 = 0 To cmdFoto2.UploadedFiles.Count - 1

    '		Dim pDoc As New PCSolution.Document

    '		Dim sFileName As String = pDoc.OdstranitDiakritiku(IO.Path.GetFileNameWithoutExtension(cmdFoto2.UploadedFiles(n).FileName), "-")
    '		Dim sExt As String = IO.Path.GetExtension(cmdFoto2.UploadedFiles(n).FileName)

    '		'# Pokud je potreba vytvaret verze souboru, vytvorit novou cilovou slozku pro verzi
    '		If bPovolitVerzeFotografii = True Then
    '			Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT foto2verze FROM " & sTable & " WHERE id = '" & sID & "'")
    '			If DS.Rows.Count > 0 Then
    '				Dim cRow As DataRow = DS.Rows(0)
    '				If cRow("foto2verze") = 0 Then
    '					cRow("foto2verze") = 1
    '				Else
    '					cRow("foto2verze") += 1
    '				End If
    '				sFotoCestaAbsolutni &= "\" & sID & "\02\v" & cRow("foto2verze")
    '				sFotoCestaRelativni &= "/" & sID & "/02/v" & cRow("foto2verze")
    '				DB.ExecuteCommand("UPDATE " & sTable & " SET foto2verze = " & cRow("foto2verze") & " WHERE id = '" & sID & "'")
    '			End If
    '		End If
    '		'@

    '		IO.Directory.CreateDirectory(sFotoCestaAbsolutni) 'Vytvorit slozku

    '		'# Nahrat fotografii a zmensit na pozadovany rozmer
    '		cmdFoto2.UploadedFiles(n).SaveAs(sFotoCestaAbsolutni & "\original" & sExt)

    '		Dim fil As New PCSolution.Images.Images
    '		fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled1", "original" & sExt, sFileName, 1300, 0, 80, sExt)
    '		fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled2", "original" & sExt, sFileName, 250, 0, 80, sExt)
    '		fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled3", "original" & sExt, sFileName, 600, 0, 80, sExt)

    '		DB.ExecuteCommand("UPDATE " & sTable & " SET foto2nazev = '" & sFileName & "', foto2pripona = '" & sExt & "' WHERE id = '" & sID & "'")

    '	Next

    '	Response.Redirect("/id-" & sID & sAdresaSave)

    'End Sub

    'Private Sub cmdFoto2Delete_Click(sender As Object, e As EventArgs) Handles cmdFoto2Delete.Click

    '	Me.UlozitZaznam()

    '	Try
    '		Dim p As New PCSolution.DirectoryDelete
    '		p.Delete(sFotoCestaAbsolutni & "\" & sID & "\02")
    '	Catch ex As Exception
    '	End Try

    '	DB.ExecuteCommand("UPDATE " & sTable & " SET foto2nazev = '', foto2pripona = '' WHERE id = '" & sID & "'")

    '	Response.Redirect("/id-" & sID & sAdresaSave)

    'End Sub

#End Region

#Region "  NAHLED FOTOGRAFIE 3  "

    '   Private Sub cmdFoto3_FileUploaded(sender As Object, e As FileUploadedEventArgs) Handles cmdFoto3.FileUploaded

    '	Me.UlozitZaznam()

    '	For n As Int16 = 0 To cmdFoto3.UploadedFiles.Count - 1

    '		Dim pDoc As New PCSolution.Document

    '		Dim sFileName As String = pDoc.OdstranitDiakritiku(IO.Path.GetFileNameWithoutExtension(cmdFoto3.UploadedFiles(n).FileName), "-")
    '		Dim sExt As String = IO.Path.GetExtension(cmdFoto3.UploadedFiles(n).FileName)

    '		'# Pokud je potreba vytvaret verze souboru, vytvorit novou cilovou slozku pro verzi
    '		If bPovolitVerzeFotografii = True Then
    '			Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT foto3verze FROM " & sTable & " WHERE id = '" & sID & "'")
    '			If DS.Rows.Count > 0 Then
    '				Dim cRow As DataRow = DS.Rows(0)
    '				If cRow("foto3verze") = 0 Then
    '					cRow("foto3verze") = 1
    '				Else
    '					cRow("foto3verze") += 1
    '				End If
    '				sFotoCestaAbsolutni &= "\" & sID & "\03\v" & cRow("foto3verze")
    '				sFotoCestaRelativni &= "/" & sID & "/03/v" & cRow("foto3verze")
    '				DB.ExecuteCommand("UPDATE " & sTable & " SET foto3verze = " & cRow("foto3verze") & " WHERE id = '" & sID & "'")
    '			End If
    '		End If
    '		'@

    '		IO.Directory.CreateDirectory(sFotoCestaAbsolutni) 'Vytvorit slozku

    '		'# Nahrat fotografii a zmensit na pozadovany rozmer
    '		cmdFoto3.UploadedFiles(n).SaveAs(sFotoCestaAbsolutni & "\original" & sExt)

    '		Dim fil As New PCSolution.Images.Images
    '		fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled1", "original" & sExt, sFileName, 1300, 0, 80, sExt)
    '		fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled2", "original" & sExt, sFileName, 250, 0, 80, sExt)
    '		fil.SaveFoto(sFotoCestaAbsolutni, sFotoCestaAbsolutni & "\Nahled3", "original" & sExt, sFileName, 600, 0, 80, sExt)

    '		DB.ExecuteCommand("UPDATE " & sTable & " SET foto3nazev = '" & sFileName & "', foto3pripona = '" & sExt & "' WHERE id = '" & sID & "'")

    '	Next

    '	Response.Redirect("/id-" & sID & sAdresaSave)

    'End Sub

    'Private Sub cmdFoto3Delete_Click(sender As Object, e As EventArgs) Handles cmdFoto3Delete.Click

    '	Me.UlozitZaznam()

    '	Try
    '		Dim p As New PCSolution.DirectoryDelete
    '		p.Delete(sFotoCestaAbsolutni & "\" & sID & "\03")
    '	Catch ex As Exception
    '	End Try

    '	DB.ExecuteCommand("UPDATE " & sTable & " SET foto3nazev = '', foto3pripona = '' WHERE id = '" & sID & "'")

    '	Response.Redirect("/id-" & sID & sAdresaSave)

    'End Sub

#End Region

#Region "  SOUBOR KE STAZENI  "

    Private Sub cmdSoubor_FileUploaded(sender As Object, e As FileUploadedEventArgs) Handles cmdSoubor.FileUploaded

		Me.UlozitZaznam()

		For n As Int16 = 0 To cmdSoubor.UploadedFiles.Count - 1

			Dim pDoc As New PCSolution.Document

			Dim sFileName As String = pDoc.OdstranitDiakritiku(IO.Path.GetFileNameWithoutExtension(cmdSoubor.UploadedFiles(n).FileName), "-")
			Dim sExt As String = IO.Path.GetExtension(cmdSoubor.UploadedFiles(n).FileName)

			'# Pokud je potreba vytvaret verze souboru, vytvorit novou cilovou slozku pro verzi
			If bPovolitVerzeFotografii = True Then
				Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT souborverze FROM " & sTable & " WHERE id = '" & sID & "'")
				If DS.Rows.Count > 0 Then
					Dim cRow As DataRow = DS.Rows(0)
					If cRow("souborverze") = 0 Then
						cRow("souborverze") = 1
					Else
						cRow("souborverze") += 1
					End If
					sFotoCestaAbsolutni &= "\" & sID & "\Soubor\v" & cRow("souborverze")
					sFotoCestaRelativni &= "/" & sID & "/Soubor/v" & cRow("souborverze")
					DB.ExecuteCommand("UPDATE " & sTable & " SET souborverze = " & cRow("souborverze") & " WHERE id = '" & sID & "'")
				End If
			End If
			'@

			IO.Directory.CreateDirectory(sFotoCestaAbsolutni) 'Vytvorit slozku

			'# Nahrat fotografii a zmensit na pozadovany rozmer
			cmdSoubor.UploadedFiles(n).SaveAs(sFotoCestaAbsolutni & "\" & sFileName & sExt)

			DB.ExecuteCommand("UPDATE " & sTable & " SET soubornazev = '" & sFileName & "', souborpripona = '" & sExt & "', souborvelikost = " & cmdSoubor.UploadedFiles(n).ContentLength & " WHERE id = '" & sID & "'")

		Next

		Response.Redirect("/id-" & sID & sAdresaSave)

	End Sub

	Private Sub cmdSouborDelete_Click(sender As Object, e As EventArgs) Handles cmdSouborDelete.Click

		Me.UlozitZaznam()

		Try
			Dim p As New PCSolution.DirectoryDelete
			p.Delete(sFotoCestaAbsolutni & "\" & sID & "\Soubor")
		Catch ex As Exception
		End Try

		DB.ExecuteCommand("UPDATE " & sTable & " SET soubornazev = '', souborpripona = '' WHERE id = '" & sID & "'")

		Response.Redirect("/id-" & sID & sAdresaSave)

	End Sub

#End Region

#Region "  ULOZIT  "

	Sub UlozitZaznam()

		If sID = "" Then '# Vytvorit novy zaznam

			Dim iSort As Int16 = 1
			Dim DS As DataTable = DB.ExecuteSelectCommand("SELECT min(sort) FROM " & sTable)
			Try
				iSort = DS.Rows(0)(0) - 1
			Catch ex As Exception
			End Try
			DB.ExecuteCommand("INSERT INTO " & sTable & " (sort) VALUES (" & iSort & ")")

			'If ddDatum.SelectedDate Is Nothing Then
			'	ddDatum.SelectedDate = Now
			'End If
			'Dim iDatum As Int64
			'Try
			'	iDatum = ddDatum.SelectedDate.Value.Ticks
			'Catch ex As Exception
			'	iDatum = Now.Ticks
			'End Try

			'Dim DS As DataTable
			'DB.ExecuteCommand("INSERT INTO " & sTable & " (datum) VALUES (" & iDatum & ")")
			DS = DB.ExecuteSelectCommand("SELECT max(id) FROM " & sTable)
			sID = DS.Rows(0)(0)

		End If

		Dim iDatum As Int64

		Try
			iDatum = ddDatum.SelectedDate.Value.Ticks
		Catch ex As Exception
			iDatum = 0
		End Try

        DB.ExecuteCommand("UPDATE " & sTable & " SET " &
                           "nadpis" & _Language & " = '" & _PrevestTextNaBezpecny(txtNadpis.Text) & "', " &
                           "text" & _Language & " = '" & _PrevestTextNaBezpecny(txtPopis.Text) & "', " &
                           "souborpopis" & _Language & " = '" & _PrevestTextNaBezpecny(txtSouborPopis.Text) & "', " &
                           "datum = " & iDatum & ", " &
                           "foto_umisteni = " & ddFoto_umisteni.SelectedItem.Value & ", " &
                           "zobrazit" & _Language & " = '" & chkZobrazit.Checked & "' " &
                           "WHERE id = " & sID)

        '"kratkytext" & _Language & " = '" & _PrevestTextNaBezpecny(txtKratkyText.Text) & "', " &

        If txtTitle.Text = "" Then txtTitle.Text = txtNadpis.Text
		If txtLink.Text = "" Then txtLink.Text = txtNadpis.Text

		'# Ulozit informace o prohlizeci
		Dim sLink As String = SaveLink(sStrankaID, sID, txtTitle.Text, txtLink.Text)

	End Sub

	Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click

		Me.UlozitZaznam()
		Response.Redirect(sAdresaStorno)

	End Sub

	Private Sub cmdStorno_Click(sender As Object, e As EventArgs) Handles cmdStorno.Click

		Response.Redirect(sAdresaStorno)

	End Sub

#End Region

End Class