Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

How can I add a button for sending a report by email?

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: How can I add a button for sending a report by email?

Unread post by kev1n »

You must pass an associative array for the file.

Code: Select all

$file = "#filename#";           // get Filename
$filename = basename($file);  // file name only

if(file_exists($file)){
    nuSendEmail('form_email@something.com','to_email@something.com','From Name','Test E-Mail from ....','Your Order',[$filename => $file],true);    // Send E-Mail
}else{
    nuDebug('Cannot send ' . $file);
}
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

Re: How can I add a button for sending a report by email?

Unread post by oli »

Thank you! Now it works.
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: How can I add a button for sending a report by email?

Unread post by treed »

It works for me too! I wish I understood it better though. I now understand what an associative array is. One question is does the nuSendEmail() function loop through the array for multiple attachments? And since there are a lot of pieces that need to be put together from several threads, could a complete example be added to the code library for the next guy?

And finally, is there a way to change the name of the attached file to something more human friendly?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: How can I add a button for sending a report by email?

Unread post by kev1n »

treed wrote: Fri Feb 03, 2023 10:31 pm And finally, is there a way to change the name of the attached file to something more human friendly?
You can rename/change file to whatever you want.
ropaiva80
Posts: 1
Joined: Thu Feb 02, 2023 2:12 pm
Has thanked: 4 times

Re: How can I add a button for sending a report by email?

Unread post by ropaiva80 »

Some update about it?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: How can I add a button for sending a report by email?

Unread post by kev1n »

What exactly do you want to know?
pedromiceli
Posts: 5
Joined: Thu Mar 16, 2023 1:37 pm

Re: How can I add a button for sending a report by email?

Unread post by pedromiceli »

Hello Friends, Im in the same situation here, i have the file on temp folder, i want to change the name and send via e-mail. At this point its all working i can save the report, end send, the last thing a have to do is change the file name from nupdf_....pdf to something like, pdf_date.pdf, how can i do this?

My JS Onclick code:

nuRunReportSave('ReportPDF', null, reportCreated);

function reportCreated(filename, id) {
const to_coo =$("#email_to").val();
const conteudo =$("#Body_do_email").val();

nuSetProperty('conteudo', conteudo, true);
nuSetProperty('to',to_coo, true);
nuSetProperty('filename', filename);
nuRunPHPHidden('enviar_com_dados',0);
alert("Conteudo Enviado!");

My php procedure:

$file = "#filename#"; // get Filename
$filename = basename($file); // file name only

$to = "#to#";
$conteudo = "#conteudo#";


if(file_exists($file)){
if($conteudo){
nuSendEmail($to,$to,'Healthcheck',$conteudo,'Report Equipamentos',[$filename => $file],false); // Send E-Mail
}else{
nuSendEmail($to,$to,'Healthcheck','Report do estado do equipamento','Report Equipamentos',[$filename => $file],false); // Send E-Mail
}
}else{
nuDebug('Cannot send ' . $file);
}
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: How can I add a button for sending a report by email?

Unread post by kev1n »

Hi,

To rename a file in PHP, you can use the rename function. The rename function takes two arguments: the current filename and the new filename.

Here's how you can use it to rename the file in your example (untested!)

Code: Select all

$file = "#filename#"; // get Filename
$filename = basename($file); // file name only

// Create a new filename
$newFilename = 'new_' . $filename;

// Get the current directory
$currentDirectory = dirname($file);

// Rename the file
if (rename($file, $currentDirectory . DIRECTORY_SEPARATOR . $newFilename)) {
    $file = realpath($currentDirectory . DIRECTORY_SEPARATOR . $newFilename);
    $filename = basename($file); // file name only
}
pedromiceli
Posts: 5
Joined: Thu Mar 16, 2023 1:37 pm

Re: How can I add a button for sending a report by email?

Unread post by pedromiceli »

Kevin you are the man, thank you very much, i changed a little the code but what you send here saved me.
Post Reply