Creating an interface to quickly generate HTML reports (in a single dynamic html page)

Post your working scripts, libraries and tools
nilsonrdg
Posts: 15
Joined: 16 Feb 2017, 16:05
Location: Brazil
Contact:

Creating an interface to quickly generate HTML reports (in a single dynamic html page)

01 Nov 2018, 08:56

This script creates an interface to quickly generate HTML reports (photo reports / photo gallery)

They are organized in a single page where you can click on the links to generate them (you don't need to create multiple html files).

It's needed to save an imagem named Default.jpg in the script folder or it will fail!

English version:

Code: Select all

#SingleInstance force

/*

This script creates an interface to quickly generate HTML reports (photografic reports)

They are organized in a single page where you can click on the links to generate them.

Default Image of the interface: Default.jpg (use your image in the script folder). Do this or the script will fail.

Default report image: https://4.bp.blogspot.com/-TDpuvUT3UPQ/V-HEQ86Z-JI/AAAAAAAAFnM/rbk1vTUeLf41ciJQA5hpzJOZRdZDtd2jwCK4B/s400/bird-animated-gif-30.gif

You can substitute for your images.

*/

Global Address
Global Applicant
Global ReportNumber
Global DatePic1
Global DatePic2
Global Image1
Global Image2
Global Caption1
Global Caption2
Global Page

ReportNumber := 0


; ------ Creating the interface ------

Gui,Add,Picture,w300 h-1 vMyPicture1, %A_ScriptDir%/Default.jpg
Gui, Add, Text, vc_Caption01Tag, Caption 1
Gui, Add, Edit, vc_Caption01 w300 h40, Caption 01
Gui, Add, Text, vc_PictureDate01Tag, Picture Date 01
Gui, Add, Edit, vc_PictureDate01 w300 h20, Picture Date 01
Gui, Add, Text, 
Gui,Add,Picture,w300 h-1 vMyPicture2, %A_ScriptDir%/Default.jpg
Gui, Add, Text, vc_Caption02Tag, Caption 2
Gui, Add, Edit, vc_Caption02 w300 h40, Caption 02
Gui, Add, Text, vc_PictureDate02Tag, Picture Date 02
Gui, Add, Edit, vc_PictureDate02 w300 h20, Picture Date 02

Gui, Add, Text, ym ,
Gui, Add, Text, ym ,

Gui, Add, Text, vc_ApplicantTag, Applicant (Opcional)
Gui, Add, Edit, vc_Applicant w300 h20,

Gui, Add, Text, vc_AddressTag, Address (Folder Number - Address)
Gui, Add, Edit, vc_Address w300 h20,

Gui, Add, Text, vc_PageTag, Page
Gui, Add, Edit, vc_Page w300 h20,  01 de ___

Gui, Add, Text,
Gui, Add, Button, vc_InsertImage01 gInsertImage01, Insert Image 01
Gui, Add, Button, vc_InsertImage02 gInsertImage02, Insert Image 02
Gui, Add, Text,
Gui, Add, Button, gGenerateReportHTML, Generate report
Gui, Add, Button, gReload, Reload

Gui, Add, Text,
Gui, Add, Button, gViewReports, View created reports
Gui, Add, Button, gDeleteEntry, Delete Entry

Gui, Add, Text,
Gui, Add, Text,
Gui, Add, Button, gExplore, Explore images
Gui, Add, Text,
Gui, Add, Button, gScriptFolder, Open folder do script

Gui, font, s12, Verdana
Gui, Add, Text, vc_Progress w400 h100,

Gui,Show

ControlsVisibility(0)

Return

;----------------- End - Creating the interface ---------------



; --------------- Selecting the images ----------------


InsertImage01:

; Selecting image 01

FileSelectFile, Pic1, 3, , Open a file, Text Documents (*.jpg; *.jpge;*.gif;*.png)
if Pic1 =
{
MsgBox, You need select a image.
}
else
{

; Getting information about the Image 1

SplitPath, Pic1,, dir

Address := RegExReplace(Dir, "^.*\\","") ; The folder must have the name of the property address

; Getting file name
FileName1 := RegExReplace(Pic1, "^.*\\","")

; Getting creation date
FileGetTime, FileTime, %Pic1%
FormatTime, FileTime, %FileTime%, dd/MM/yyyy   ; Since the last parameter is omitted, the long date and time are retrieved.
DatePic1 = %FileTime%.


; Showing image and fields related to image 01

GuiControl,, MyPicture1, %Pic1%

GuiControl, show, c_Caption01
GuiControl, show, c_Caption01Tag

GuiControl, show, c_PictureDate01
GuiControl, show, c_PictureDate01Tag

; Sugesting a date for the picture
GuiControl,, c_PictureDate01, %DatePic1%


; Getting image path
SplitPath, Pic1,, dir

Address := RegExReplace(Dir, "^.*\\","")



; Defining report name (the name of the folder to where images will be copied: Report Number - Address)

Loop, %A_ScriptDir%/*, 2, 0
{
ReportNumber = %A_index%
}

ReportNumber := ReportNumber

AddressCabecalho = %Address%
Address = %ReportNumber% - %Address%
}

return



InsertImage02:

FileSelectFile, Pic2, 3, , Open a file, Text Documents (*.jpg; *.jpge;*.gif;*.png)
if Pic2 =
{
MsgBox, You need to select an image.
}
else
{

; Getting information about the Image 02

; Getting file name
FileName2 := RegExReplace(Pic2, "^.*\\","")


; Getting image 02 creation date
FileGetTime, FileTime, %Pic2%
FormatTime, FileTime, %FileTime%, dd/MM/yyyy ; Since the last parameter is omitted, the long date and time are retrieved.
DatePic2 = %FileTime%.

; Showing image 02 and related fields
GuiControl,, MyPicture2, %Pic2%
Gui,Show

; Sugesting the date to the picture
GuiControl,, c_PictureDate02, %DatePic2%

}


ControlsVisibility(1)


; Sugesting the property address
GuiControl,, c_Address, %Address%


ShowMessage("`nVerify the fields and then`nclick the 'Generate report' button.")

return


; --------------- END - Selecting images ---------------




; ---------------------- Functions ------------------------------


ControlsVisibility(Mode)
{

if (Estado=0)
{

GuiControl, Hide, c_Applicant
GuiControl, Hide, c_ApplicantTag

GuiControl, Hide, c_Address
GuiControl, Hide, c_AddressTag

GuiControl, Hide, c_Caption01
GuiControl, Hide, c_Caption01Tag

GuiControl, Hide, c_Caption02
GuiControl, Hide, c_Caption02Tag

GuiControl, Hide, c_Page
GuiControl, Hide, c_PageTag

GuiControl, Hide, c_PictureDate01
GuiControl, Hide, c_PictureDate01Tag

GuiControl, Hide, c_PictureDate02
GuiControl, Hide, c_PictureDate02Tag
}
else
{

GuiControl, Show, c_Applicant
GuiControl, Show, c_ApplicantTag

GuiControl, Show, c_Address
GuiControl, Show, c_AddressTag

GuiControl, Show, c_Caption01
GuiControl, Show, c_Caption01Tag

GuiControl, Show, c_Caption02
GuiControl, Show, c_Caption02Tag

GuiControl, Show, c_Page
GuiControl, Show, c_PageTag

GuiControl, Show, c_PictureDate01
GuiControl, Show, c_PictureDate01Tag

GuiControl, Show, c_PictureDate02
GuiControl, Show, c_PictureDate02Tag
}
}



ShowMessage(Message)
{
GuiControl,, c_Progress, %Mensagem%
}




; ---- Hotkeys -----


; Pressing Control+ESC finish the script
^Esc::exitapp


; Writing the report name in saving pdf box
!^#n::
send, %Applicant% - %Address%
return




; ---------------- Button Actions -------------------


Reload:
reload
return



; Deleting a link
DeleteEntry:

InputBox, Entry, Delete a link, Insert the name of the link to delete.`nNote: The link isn't deleted`, it's just hidden!, , 400, 150, , , , , %Clipboard%
if ErrorLevel
    MsgBox, Action canceled.
else
{
FileRead, FileData, %A_ScriptDir%/Reports.htm

StringReplace, FileData, FileData, >%Entry%<,style="visibility:hidden">%Entry%<

FileCreateDir, %A_ScriptDir%/Backup

FileMove, %A_ScriptDir%/Reports.htm, %A_ScriptDir%/Backup, 1

FileAppend, %FileData%, %A_ScriptDir%/Reports.htm, UTF-8

msgbox, Now`, you must reload the report.
}

return




GenerateReportHTML:

; --- If "Reports.htm" doesn't exist, he will be created ------------


; -------------------- HTML Code of the Report ---------------------------
HTML=
(
<!-- Relatorio -->

<div id="divControl" style="position:absolute;left:700px;top:5px"><br>To delete a link, copy the text below and click 'Delete Entry' in the script window.<br><input readonly value="" onmouseover="select();" type=text id="inputCopiarAddress" size="40px"></input></div>

<div id="divPrint"><a href="javascript:EsconderControles();print();" style="position:absolute;left:500px;top:5px">Print</a><br></div>

<div id="divTitulo" style="position:absolute;left:20px;top:20px; font-size:20px;font-weight:bold">Report nº.</div>

<div id="divCabecalho" style="position:absolute;left:20px;top:50px;font-size:14px;font-weight:bold;">
<div id="divApplicant">Applicant:</div>
<div id="divAddress">Address:</div>
</div>

<div align="center" id="divCorpo" style="position:absolute;left:20px;top:85px;font-size:14px">
<img id="img1" src="https://4.bp.blogspot.com/-TDpuvUT3UPQ/V-HEQ86Z-JI/AAAAAAAAFnM/rbk1vTUeLf41ciJQA5hpzJOZRdZDtd2jwCK4B/s400/bird-animated-gif-30." width="500px">
<br>
<span id="spanCaption1">Caption 01</span> - <span id="spanDatePic1">Date: 00/00/0000</span>
<br><br>
<img id="img2" src="https://4.bp.blogspot.com/-TDpuvUT3UPQ/V-HEQ86Z-JI/AAAAAAAAFnM/rbk1vTUeLf41ciJQA5hpzJOZRdZDtd2jwCK4B/s400/bird-animated-gif-30." width="500px">
<br>
<span id="spanCaption2">Caption 02</span> - <span id="spanDatePic2">Date: 00/00/0000</span>
<br><br>
<div id="divPage">Pag. 01 de 01</div>
<br><br>
</div>

<script>

function GenerateReport(Address,Applicant,DatePic1,DatePic2,Image1,Image2,Caption1,Caption2,Page,textoLink)
{
topFunction();

document.getElementById("divAddress").innerHTML = "Address: " + Address;
if (Applicant!="") {
document.getElementById("divApplicant").innerHTML = "Applicant: " + Applicant;}
else {
document.getElementById("divApplicant").innerHTML = "";
}
document.getElementById("img1").src = Image1;
document.getElementById("img2").src= Image2;
document.getElementById("spanCaption1").innerHTML = Caption1;
document.getElementById("spanCaption2").innerHTML = Caption2;

document.getElementById("spanDatePic1").innerHTML = "Date: " + DatePic1;
document.getElementById("spanDatePic2").innerHTML = "Date: " + DatePic2;

document.getElementById("divPage").innerHTML = Page;

document.getElementById("inputCopiarAddress").value = textoLink;

}

function EsconderControles() {
alert("Alt+Win+Control+N can be used to insert the report name in save as pdf name field.")
document.getElementById('divListaDeReports').style.visibility='hidden';
document.getElementById('divControl').style.visibility='hidden';
document.getElementById('divPrint').style.visibility='hidden';
}

function topFunction() {
    document.body.scrollTop = 0; // For Safari
    document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}


</script>

<!-- Relatorio -->
<div id="divListaDeReports" style="position:absolute;left:600px;top:80px;font-size:14px">
</div><!-- Final Line -->
)

; -------------------- END - HTML Code of the Report ----------------------

ReportFile=%A_ScriptDir%/Reports.htm

if (!FileExist(ReportFile)){
FileAppend, %HTML%, %A_ScriptDir%/Reports.htm, UTF-8
}

; ------------ End - Creating Report File -----------------------


; Reading fields

GuiControlGet, PictureDate02,,c_PictureDate02
GuiControlGet, PictureDate01,,c_PictureDate01
GuiControlGet, Caption2,,c_Caption02
GuiControlGet, Caption1,,c_Caption01
GuiControlGet, Page,,c_Page
GuiControlGet, Applicant,,c_Applicant
GuiControlGet, Address,,c_Address


; Creating and Copying images to the report folder in script folder

ImagesFolder=%A_ScriptDir%/%Address%

if (!FileExist(ImagesFolder)){

FileCreateDir, %A_ScriptDir%/%Address%

FileCopy, %Pic1%, %A_ScriptDir%/%Address%/%FileName1%
FileCopy, %Pic2%, %A_ScriptDir%/%Address%/%FileName2%

; Creating the  link to GenerateReport function in javaScript

JavaScriptCode = <a href="javascript:GenerateReport('%AddressCabecalho%','%Applicant%','%PictureDate01%','%PictureDate02%','%Address%/%FileName1%','%Address%/%FileName2%','%Caption1%','%Caption2%','%Page%','%Address%');">%Address%</a><br>


; Writing in the reports file the links to visualize them

FileRead, FileData, %A_ScriptDir%/Reports.htm

FileDelete, %A_ScriptDir%/Reports.htm

StringReplace, FileData, FileData, </div><!-- Final Line -->, %JavaScriptCode%`n</div><!-- Final Line -->

FileAppend, %FileData%, %A_ScriptDir%/Reports.htm, UTF-8

run, %A_ScriptDir%/Reports.htm
}
else
{
msgbox, There is already a report with this name. Chose another.
}

return



Explore:
run, explorer
return



ScriptFolder:
msgbox, 0,, Access script folder to backup reports file manually.
run, %A_ScriptDir%
return



ViewReports:
run, %A_ScriptDir%/Reports.htm
return



guiClose:
MsgBox, 4,, Do you really want to exit? (press Yes or No)
IfMsgBox Yes
{
   exitapp
}
return


; Created by http://nilsonrdg-dicas-finais.blogspot.com

Nota: É necessário salvar uma imagem chamada Default.jpg no diretório do script ou ele falhará!

Versão em Português:

Code: Select all

#SingleInstance force

/*

Este script cria uma interface para agilizar a criação de relatórios fotográficos.

Os relatórios são organizados numa única página, onde por meio de links podem ser visualizados isoladamente.

Imagem Default da interface: Default.jpg (coloque sua imagem na pasta do script). Faça isso ou o script pode falhar!

Imagem default do relatório: https://4.bp.blogspot.com/-TDpuvUT3UPQ/V-HEQ86Z-JI/AAAAAAAAFnM/rbk1vTUeLf41ciJQA5hpzJOZRdZDtd2jwCK4B/s400/bird-animated-gif-30.gif

Você pode substituir por suas imagens.

By http://nilsonrdg-dicas-finais.blogspot.com

*/

Global Endereco
Global Requerente
Global NumeroDoRelatorio
Global DataPic1
Global DataPic2
Global Imagem1
Global Imagem2
Global Legenda1
Global Legenda2
Global Pagina

NumeroDoRelatorio := 0


; ------ Criando a interface ------

Gui,Add,Picture,w300 h-1 vMyPicture1, %A_ScriptDir%/Default.jpg
Gui, Add, Text, vc_Legenda01Tag, Legenda 1
Gui, Add, Edit, vc_Legenda01 w300 h40, Legenda 01
Gui, Add, Text, vc_DataFoto01Tag, Data da foto 01
Gui, Add, Edit, vc_DataFoto01 w300 h20, Data da foto 01
Gui, Add, Text, 
Gui,Add,Picture,w300 h-1 vMyPicture2, %A_ScriptDir%/Default.jpg
Gui, Add, Text, vc_Legenda02Tag, Legenda 2
Gui, Add, Edit, vc_Legenda02 w300 h40, Legenda 02
Gui, Add, Text, vc_DataFoto02Tag, Data da foto 02
Gui, Add, Edit, vc_DataFoto02 w300 h20, Data da foto 02

Gui, Add, Text, ym ,
Gui, Add, Text, ym ,

Gui, Add, Text, vc_RequerenteTag, Requerente (Opcional)
Gui, Add, Edit, vc_Requerente w300 h20,

Gui, Add, Text, vc_EnderecoTag, Endereço (Número da Pasta - Endereço)
Gui, Add, Edit, vc_Endereco w300 h20,

Gui, Add, Text, vc_PaginaTag, Página
Gui, Add, Edit, vc_Pagina w300 h20,  01 de ___

Gui, Add, Text,
Gui, Add, Button, vc_InserirImagem01 gInserirImagem01, Inserir imagem 01
Gui, Add, Button, vc_InserirImagem02 gInserirImagem02, Inserir imagem 02
Gui, Add, Text,
Gui, Add, Button, gGerarRelatorioHTML, Gerar Relatório
Gui, Add, Button, gReload, Recarregar

Gui, Add, Text,
Gui, Add, Button, gVerRelatorios, Ver relatórios prontos
Gui, Add, Button, gApagarEntrada, Apagar Entrada

Gui, Add, Text,
Gui, Add, Text,
Gui, Add, Button, gExplorar, Explorar Imagens
Gui, Add, Text,
Gui, Add, Button, gScriptFolder, Abrir pasta do script

Gui, font, s12, Verdana
Gui, Add, Text, vc_Progress w400 h100,

Gui,Show

VisibilidadeControles(0)

Return

;----------------- FIM - Criando interface ---------------



; --------------- Selecionando as imagens ----------------

InserirImagem01:

; Selecionando imagem 01

FileSelectFile, Pic1, 3, , Open a file, Text Documents (*.jpg; *.jpge;*.gif;*.png)
if Pic1 =
{
MsgBox, Você deve selecionar uma imagem.
}
else
{
; Obtendo dados da imagem 1

SplitPath, Pic1,, dir

Endereco := RegExReplace(Dir, "^.*\\","") ; No caso, a pasta onde estão as imagem deve ter o nome do endereço do local vistoriado

; Obtendo nome do arquivo
NomeDoArquivo1 := RegExReplace(Pic1, "^.*\\","")

; Obtendo a data de criação
FileGetTime, FileTime, %Pic1%
FormatTime, FileTime, %FileTime%, dd/MM/yyyy
DataPic1 = %FileTime%.


; Mostrando imagem e campos relacionados a imagem 01

GuiControl,, MyPicture1, %Pic1%

GuiControl, show, c_Legenda01
GuiControl, show, c_Legenda01Tag

GuiControl, show, c_DataFoto01
GuiControl, show, c_DataFoto01Tag


; Sugerindo a data para a criação da foto
GuiControl,, c_DataFoto01, %DataPic1%


; Obtendo caminho da imagem
SplitPath, Pic1,, dir

Endereco := RegExReplace(Dir, "^.*\\","") ; No caso, a pasta onde estão as imagem deve ter o nome do endereço do local vistoriado

; Estabelecendo número do relatório (para estabelecer nome da pasta onde serão copiadas as imagens)

Loop, %A_ScriptDir%/*, 2, 0
{
NumeroDoRelatorio = %A_index%
}

NumeroDoRelatorio := NumeroDoRelatorio

EnderecoCabecalho = %Endereco%
Endereco = %NumeroDoRelatorio% - %Endereco%
}

return



InserirImagem02:

FileSelectFile, Pic2, 3, , Open a file, Text Documents (*.jpg; *.jpge;*.gif;*.png)
if Pic2 =
{
MsgBox, Você deve selecionar uma imagem.
}
else
{

; Obtendo dados da imagem 2

; Obtendo nome do arquivo
NomeDoArquivo2 := RegExReplace(Pic2, "^.*\\","")


; Obtendo a data de criação
FileGetTime, FileTime, %Pic2%
FormatTime, FileTime, %FileTime%, dd/MM/yyyy ; Since the last parameter is omitted, the long date and time are retrieved.
DataPic2 = %FileTime%.

; Mostrando imagem 2 e campos relacionados
GuiControl,, MyPicture2, %Pic2%
Gui,Show

; Sugerindo a data para a criação da foto
GuiControl,, c_DataFoto02, %DataPic2%

}


VisibilidadeControles(1)


; Sugerindo endereço da vistoria
GuiControl,, c_Endereco, %Endereco%


ExibirMensagem("`nQuando terminar de verificar`nclique no botão 'Gerar Relatório'.")

return


; --------------- FIM - Selecionando as imagens ---------------



; ---------------------- Funções ------------------------------


VisibilidadeControles(Estado)
{

if (Estado=0)
{

GuiControl, Hide, c_Requerente
GuiControl, Hide, c_RequerenteTag

GuiControl, Hide, c_Endereco
GuiControl, Hide, c_EnderecoTag

GuiControl, Hide, c_Legenda01
GuiControl, Hide, c_Legenda01Tag

GuiControl, Hide, c_Legenda02
GuiControl, Hide, c_Legenda02Tag

GuiControl, Hide, c_Pagina
GuiControl, Hide, c_PaginaTag

GuiControl, Hide, c_DataFoto01
GuiControl, Hide, c_DataFoto01Tag

GuiControl, Hide, c_DataFoto02
GuiControl, Hide, c_DataFoto02Tag
}
else
{

GuiControl, Show, c_Requerente
GuiControl, Show, c_RequerenteTag

GuiControl, Show, c_Endereco
GuiControl, Show, c_EnderecoTag

GuiControl, Show, c_Legenda01
GuiControl, Show, c_Legenda01Tag

GuiControl, Show, c_Legenda02
GuiControl, Show, c_Legenda02Tag

GuiControl, Show, c_Pagina
GuiControl, Show, c_PaginaTag

GuiControl, Show, c_DataFoto01
GuiControl, Show, c_DataFoto01Tag

GuiControl, Show, c_DataFoto02
GuiControl, Show, c_DataFoto02Tag
}
}



ExibirMensagem(Mensagem)
{
GuiControl,, c_Progress, %Mensagem%
}




; ---- Atalhos -----


; Pressionando-se Control+ESC finaliza o script
^Esc::exitapp


; Escrever nome do relatório (útil para dar o nome ao arquivo quando imprimir/salvar como pdf)
!^#n::
send, %Requerente% - %Endereço%
return



; ---------------- Button Actions -------------------


Reload:
reload
return


ApagarEntrada:

InputBox, Entrada, Apagar entrada, Insira o endereço da entrada a apagar.`nNota: a entrada NÃO é apagada`, é apenas ocultada!, , 400, 150, , , , , %Clipboard%
if ErrorLevel
    MsgBox, Ação cancelada.
else
{
FileRead, DadosDoArquivo, %A_ScriptDir%/Relatorios.htm

StringReplace, DadosDoArquivo, DadosDoArquivo, >%Entrada%<,style="visibility:hidden">%Entrada%<

FileCreateDir, %A_ScriptDir%/Backup

FileMove, %A_ScriptDir%/Relatorios.htm, %A_ScriptDir%/Backup, 1

FileAppend, %DadosDoArquivo%, %A_ScriptDir%/Relatorios.htm, UTF-8

msgbox, Agora`, você deve atualizar a página no navegador.
}

return




GerarRelatorioHTML:

; --- Se o arquivo "Relatorios.htm" não existe, ele será criado ------------


; -------------------- Código HTML do relatório ---------------------------
HTML=
(
<!-- Relatorio -->

<div id="divControle" style="position:absolute;left:700px;top:5px"><br>Para excluir um link, copie o texto abaixo e click em 'Apagar Entrada' na janela do script<br><input readonly value="" onmouseover="select();" type=text id="inputCopiarEndereco" size="40px"></input></div>

<div id="divImprimir"><a href="javascript:EsconderControles();print();" style="position:absolute;left:500px;top:5px">Imprimir</a><br></div>

<div id="divTitulo" style="position:absolute;left:20px;top:20px; font-size:20px;font-weight:bold">LEVANTAMENTO FOTOGRÁFICO nº.</div>

<div id="divCabecalho" style="position:absolute;left:20px;top:50px;font-size:14px;font-weight:bold;">
<div id="divRequerente">Requerente:</div>
<div id="divEndereco">Endereço:</div>
</div>

<div align="center" id="divCorpo" style="position:absolute;left:20px;top:85px;font-size:14px">
<img id="img1" src="https://4.bp.blogspot.com/-TDpuvUT3UPQ/V-HEQ86Z-JI/AAAAAAAAFnM/rbk1vTUeLf41ciJQA5hpzJOZRdZDtd2jwCK4B/s400/bird-animated-gif-30." width="500px">
<br>
<span id="spanLegenda1">Legenda 01</span> - <span id="spanDataPic1">Data: 00/00/0000</span>
<br><br>
<img id="img2" src="https://4.bp.blogspot.com/-TDpuvUT3UPQ/V-HEQ86Z-JI/AAAAAAAAFnM/rbk1vTUeLf41ciJQA5hpzJOZRdZDtd2jwCK4B/s400/bird-animated-gif-30." width="500px">
<br>
<span id="spanLegenda2">Legenda 02</span> - <span id="spanDataPic2">Data: 00/00/0000</span>
<br><br>
<div id="divPagina">Pag. 01 de 01</div>
<br><br>
</div>

<script>

function GerarRelatorio(Endereco,Requerente,DataPic1,DataPic2,Imagem1,Imagem2,Legenda1,Legenda2,Pagina,textoLink)
{
topFunction();

document.getElementById("divEndereco").innerHTML = "Endereço: " + Endereco;
if (Requerente!="") {
document.getElementById("divRequerente").innerHTML = "Requerente: " + Requerente;}
else {
document.getElementById("divRequerente").innerHTML = "";
}
document.getElementById("img1").src = Imagem1;
document.getElementById("img2").src= Imagem2;
document.getElementById("spanLegenda1").innerHTML = Legenda1;
document.getElementById("spanLegenda2").innerHTML = Legenda2;

document.getElementById("spanDataPic1").innerHTML = "Data: " + DataPic1;
document.getElementById("spanDataPic2").innerHTML = "Data: " + DataPic2;

document.getElementById("divPagina").innerHTML = Pagina;

document.getElementById("inputCopiarEndereco").value = textoLink;

}

function EsconderControles() {
alert("Ao salvar/imprimir como PDF, use Alt+Win+Control+N para inserir o nome do relatório no campo 'nome do arquivo'.")
document.getElementById('divListaDeRelatorios').style.visibility='hidden';
document.getElementById('divControle').style.visibility='hidden';
document.getElementById('divImprimir').style.visibility='hidden';
}

function topFunction() {
    document.body.scrollTop = 0; // For Safari
    document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}


</script>

<!-- Relatorio -->
<div id="divListaDeRelatorios" style="position:absolute;left:600px;top:80px;font-size:14px">
</div><!-- Ultima Linha -->
)

; -------------------- Código HTML do relatório (fim) ----------------------

Arquivo=%A_ScriptDir%/Relatorios.htm

if (!FileExist(Arquivo)){
FileAppend, %HTML%, %A_ScriptDir%/Relatorios.htm, UTF-8
}

; ------------ Criando arquivo (fim) -----------------------


; ----- Lendo Entradas

GuiControlGet, DataFoto02,,c_DataFoto02
GuiControlGet, DataFoto01,,c_DataFoto01
GuiControlGet, Legenda2,,c_Legenda02
GuiControlGet, Legenda1,,c_Legenda01
GuiControlGet, Pagina,,c_Pagina
GuiControlGet, Requerente,,c_Requerente
GuiControlGet, Endereco,,c_Endereco


; ---------- Copiando imagens para pasta na pasta do script ---------------

; Criando diretório para as imagens

PastaImagens=%A_ScriptDir%/%Endereco%

if (!FileExist(PastaImagens)){

FileCreateDir, %A_ScriptDir%/%Endereco%

FileCopy, %Pic1%, %A_ScriptDir%/%Endereco%/%NomeDoArquivo1%
FileCopy, %Pic2%, %A_ScriptDir%/%Endereco%/%NomeDoArquivo2%

; Criando o link para a função GerarRelatório do javaScript

CodigoJavaScript = <a href="javascript:GerarRelatorio('%EnderecoCabecalho%','%Requerente%','%DataFoto01%','%DataFoto02%','%Endereco%/%NomeDoArquivo1%','%Endereco%/%NomeDoArquivo2%','%Legenda1%','%Legenda2%','%Pagina%','%Endereco%');">%Endereco%</a><br>


; Escrevendo na lista de relatórios os links para criar visualizá-los

FileRead, DadosDoArquivo, %A_ScriptDir%/Relatorios.htm

FileDelete, %A_ScriptDir%/Relatorios.htm

StringReplace, DadosDoArquivo, DadosDoArquivo, </div><!-- Ultima Linha -->, %CodigoJavaScript%`n</div><!-- Ultima Linha -->

FileAppend, %DadosDoArquivo%, %A_ScriptDir%/Relatorios.htm, UTF-8

run, %A_ScriptDir%/Relatorios.htm
}
else
{
msgbox, Já existe um relatório com esse nome. Escolha outro.
}

return



Explorar:
run, explorer
return



ScriptFolder:
msgbox, 0,, Acessar pasta do script para criar cópia de segurança manualmente.
run, %A_ScriptDir%
return



VerRelatorios:
run, %A_ScriptDir%/Relatorios.htm
return



guiClose:
MsgBox, 4,, Você realmente quer sair? (press Sim ou Não)
IfMsgBox Yes
{
   exitapp
}
return
Last edited by nilsonrdg on 08 Nov 2018, 21:14, edited 6 times in total.
DRocks
Posts: 475
Joined: 08 May 2018, 10:20

Re: Creating an interface to quickly generate HTML reports (in a single dynamic html page)

01 Nov 2018, 22:42

Thank you very much!
Exactly what i was looking for today. Ill try that as soon as possible
nilsonrdg
Posts: 15
Joined: 16 Feb 2017, 16:05
Location: Brazil
Contact:

Re: Creating an interface to quickly generate HTML reports (in a single dynamic html page)

08 Nov 2018, 20:44

DRocks,

I posted the script again, and finally the Code tag is working, so now it's easier to copy the code and test.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot] and 53 guests