Page 1 of 1

Automatic running and emailing of reports

Posted: Mon Jul 19, 2021 10:50 am
by stevedb
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

Re: Automatic running and emailing of reports

Posted: Mon Jul 19, 2021 8:33 pm
by kev1n
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.

Re: Automatic running and emailing of reports

Posted: Tue Jul 20, 2021 10:19 am
by stevedb
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

Re: Automatic running and emailing of reports

Posted: Tue Jul 20, 2021 4:53 pm
by kev1n
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.

Re: Automatic running and emailing of reports

Posted: Wed Jul 21, 2021 8:34 pm
by stevedb
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

Re: Automatic running and emailing of reports

Posted: Mon Jul 26, 2021 3:59 pm
by stevedb
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

Re: Automatic running and emailing of reports

Posted: Mon Jul 26, 2021 5:07 pm
by stevedb
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"}

Re: Automatic running and emailing of reports

Posted: Thu Jul 29, 2021 7:14 pm
by stevedb
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

Re: Automatic running and emailing of reports

Posted: Fri Sep 17, 2021 2:24 pm
by kev1n
Hi Steve,

Unfortunately, I haven't had time to look into it yet.

Re: Automatic running and emailing of reports

Posted: Fri Jan 20, 2023 9:14 pm
by treed
Any progress on this? I would like the same functionality for a daily email generated by the system. If it's a low priority I'll figure out another way to do it.