Automatic running and emailing of reports

Questions related to customising nuBuilder Forte with JavaScript or PHP.

Automatic running and emailing of reports

Unread postby stevedb » Mon Jul 19, 2021 6:20 pm

Hi - I wonder if someone could give me some pointers as to the best way to tackle this:

I would like to create some reports and have them run automatically every month.
The results will get emailed ... again automatically to a mailing list.

I guess I would trigger the process from cron.
I could then just interact with my DB directly and send an email, but it would be nice to use the report features of nuBuilder and have as much of it as possible integrated there.

Any pointers gratefully received.
Steve
stevedb
 
Posts: 21
Joined: Tue Oct 16, 2018 7:51 am

Re: Automatic running and emailing of reports

Unread postby kev1n » Tue Jul 20, 2021 4:03 am

Hi Steve,

I am not aware of any possibility to run & create a report from a crun job.
There is a file nucall_ext.php that allows you to execute code from outside nuBuilder .
However, I still have to adjust nurunpdf.php a bit to make it work. It shouldn't be too difficult, I'll get back to you.
kev1n
nuBuilder Team
 
Posts: 2053
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Automatic running and emailing of reports

Unread postby stevedb » Tue Jul 20, 2021 5:49 pm

Thanks kev1n,
This is exactly what I need.
I'm using v4 not v4.5, but as far as I can see that's OK isn't it?

I don't need hash cookies for this but those should work too? If I add them in my script, using something like wget or curl?
This also allows me to do other things I've been pushing back on because it seemed too hard :D

Cheers,
Steve
stevedb
 
Posts: 21
Joined: Tue Oct 16, 2018 7:51 am

Re: Automatic running and emailing of reports

Unread postby kev1n » Wed Jul 21, 2021 12:23 am

This is how it works for me.

Follow the steps from this article to create an

1) Aceess Level (For this example, I used the Code accsendreport)
2) A Procedure with Code sendreport and Run "Hidden" and PHP (change the from address, recpient etc.)

Code: Select all
require_once('nurunpdf.php');

$id = nuRunReport('testreport');
$result = nuRunReportId($id, "", false);

if ($result !== false) {

    $file = $result['filename'];
    $body = "Hello, <br><br> here's your report";
    $subject = "Report from nuBuilder";
    $recipient = "send_to_email@something.com";
    $cc = "";
    $bcc = "";
    nuSendEmail($recipient, "from_address@something.com", "From Name", $body, $subject, [basename($file) => $file], true, $cc, $bcc);
}


3. You will need nucall_ext.php. (Which is already included in 4.5)
4. Update nurunpdf.php (/core directory) with the one in the attachment.

To test it, run the URL which is of the following format in your browser (change it accordingly)

Code: Select all
https://localhost/nubuilder4/core/nucall_ext.php?p=sendreport&acc=accsendreport


In a short test, however, the execution via cron job did not work. Maybe you can get it to work.

Last but not least, and I didn't test it with v.4.0 and will probably not do so since it won't run with PHP 8.0.
Attachments
nurunpdf.zip
(7.93 KiB) Downloaded 24 times
kev1n
nuBuilder Team
 
Posts: 2053
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Automatic running and emailing of reports

Unread postby stevedb » Thu Jul 22, 2021 4:04 am

Hi kev1n,
I'm still on v4 and have implemented what you have given me.
I can do the https request and send an email - cool!
I believe I am now just battling linux permissions so the pdf can get written to the temp directory.
I'm away for a few days so will let you know how this goes and if I manage to the cron job working.
Many thanks,
Steve
stevedb
 
Posts: 21
Joined: Tue Oct 16, 2018 7:51 am

Re: Automatic running and emailing of reports

Unread postby stevedb » Mon Jul 26, 2021 11:29 pm

Hi Kev1n,
As I said, I'm running on v4. I'm now able to run this as you descried perfectly fine.
If useful for others ... the only additional changes I had to make were:
1) In nucommon.php func nuAddToHashList - Had to include the isset check on slp_has as per nubuilder v4.5
2) PHP was unable to write the file to the temp directory even after setting up the permissions. This was down to SELinux booleans. I had to run 'setsebool -P httpd_unified 1' for it to work. Probably down to the specifics of my setup.

Now onto setting up the cron job

Steve
stevedb
 
Posts: 21
Joined: Tue Oct 16, 2018 7:51 am

Re: Automatic running and emailing of reports

Unread postby stevedb » Tue Jul 27, 2021 12:37 am

Hi Kev1n,
Actually I may need some more help.
It only works if I am logged into nuBuilder on another browser window.
If I logout and run the https request I get:
Code: Select all
Notice: Trying to get property of non-object in /var/www/html/eng/nucommon.php on line 405
Notice: Trying to get property of non-object in /var/www/html/eng/nucommon.php on line 424
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 32
Warning: Invalid argument supplied for foreach() in /var/www/html/eng/nucommon.php on line 679
Notice: Trying to get property of non-object in /var/www/html/eng/nucommon.php on line 700
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 38
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 38
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 862
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 62
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 64
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 196
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 999
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 1007
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 356
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 461
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 461
Warning: First parameter must either be an object or the name of an existing class in /var/www/html/eng/nurunpdf.php on line 461
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 356
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 461
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 461
Warning: First parameter must either be an object or the name of an existing class in /var/www/html/eng/nurunpdf.php on line 461
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 355
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 356
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 358
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 461
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 461
Warning: First parameter must either be an object or the name of an existing class in /var/www/html/eng/nurunpdf.php on line 461
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 575
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 575
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 576
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 587
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 587
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 165
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 165
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 165
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 86
Notice: Trying to get property of non-object in /var/www/html/eng/nurunpdf.php on line 87
{"filename":"\/var\/www\/html\/eng\/temp\/nupdf_60fec88251beb88.pdf","id":"60fec8825304cd1"}
stevedb
 
Posts: 21
Joined: Tue Oct 16, 2018 7:51 am

Re: Automatic running and emailing of reports

Unread postby stevedb » Fri Jul 30, 2021 2:44 am

Hi kev1n,
This doesn't work in nubuilder v4 or v4.5.
As soon as I add 'require_once('nurunpdf.php')' to my procedure it just results in 'You must be logged into nuBuilder 4'.

It only works if I happen to be logged into nubuilder on another browser tab or it picks up on a past login session.

As far as I can tell it's hitting nusession.php included from nurunpdf.php and dieing.
Does nurunpdf.php need to include nusession.php?
I think it does otherwise nuRunReportId fails.

Cheers,
Steve
stevedb
 
Posts: 21
Joined: Tue Oct 16, 2018 7:51 am

Re: Automatic running and emailing of reports

Unread postby kev1n » Fri Sep 17, 2021 9:54 pm

Hi Steve,

Unfortunately, I haven't had time to look into it yet.
kev1n
nuBuilder Team
 
Posts: 2053
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 3 guests

cron