Topic: The Header option from module itself

There is a small change in the core of pdf_report.inc will  give us a good way to add template form from the module itself.

from the reporting/includes/pdf_report.inc:

function NewPage() 
    {
        global $installed_extensions, $path_to_root;
    
    
        if ($this->pageNumber==0)
        {
            // check if there is pdf header template for this report
            // and set if it is found
            $tmpl_pdf = find_custom_file("/reporting/forms/".$this->headerTmpl.".pdf");
            if ($tmpl_pdf) {
                $this->tmplSize = $this->setSourceFile($tmpl_pdf);
            } else {
                // include reports installed inside extension modules
                if (count($installed_extensions) > 0)
                {
                    $extensions = $installed_extensions;
                    foreach ($extensions as $ext)
                        if (($ext['active'] && $ext['type'] == 'extension')) {
                            $tmpl_pdf = find_custom_file($path_to_root.'/'.$ext['path']."/reporting/forms/".$this->headerTmpl.".pdf");
                            if ($tmpl_pdf) {
                                $this->tmplSize = $this->setSourceFile($tmpl_pdf);
                            }
                        }
                }
            }
        }

        $this->pageNumber++;
        parent::newPage();

        if ($this->tmplSize) {
            $this->row = $this->pageHeight - $this->topMargin; // reset row
            $id = $this->importPage(min($this->pageNumber, $this->tmplSize));
            $this->useTemplate($id);
        }

        // include related php file if any
        $tmpl_php = find_custom_file("/reporting/forms/".$this->headerTmpl.".php");
        if ($tmpl_php) {
            include($tmpl_php);
        }  else {
                // include reports installed inside extension modules
                if (count($installed_extensions) > 0)
                {
                    $extensions = $installed_extensions;
                    foreach ($extensions as $ext)
                        if (($ext['active'] && $ext['type'] == 'extension')) {
                            $tmpl_php = find_custom_file($path_to_root.'/'.$ext['path']."/reporting/forms/".$this->headerTmpl.".php");
                            if ($tmpl_php) {
                                $this->tmplSize = $this->setSourceFile($tmpl_php);
                            }
                        }
                }
            }

        if (method_exists($this, $this->headerTmpl))    // draw predefined page layout if any
            $this->{$this->headerTmpl}();
    }

This would help us to hook from the modules template to work on.

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

When code is pasted into FA, it can cause security concerns.

Re: The Header option from module itself

We are allowing to connect custom reports. If it's giving security issues. That will also give security problems

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

As long as it is a file that is uploaded in the core it should be okay. If code is pasted into a field in a FA form, it will cause security issues.

Re: The Header option from module itself

@apmuthu -  For custom header changes, we are allowing to collect from forms directory. And i am trying to bring the same feature to modules directory. I can't understand your point, How it will cause security issues.

@joe - If you think its not good practice, than lets takeout the forms directory and form files support in pdf_report.inc

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

The pdf forms folder is okay and so is @kvvaradha's suggestion as long as the sysadmin allows it to be uploaded after vetting. Only that it should not be uploadable by the end user into the FA system especially through a normal web interface or user input form..

Re: The Header option from module itself

No. My suggestion is to get the file from module. Not allowing end users to input into it. Or upload into the system. 

And also I just figured out. The find_custom_file function get the module files too. So we can ignore the  changes what I suggested.

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

Then it should be okay if the sysadmin trusts the module's author.

Re: The Header option from module itself

can u provide a sample template to test?

www.boxygen.pk

10 (edited by kvvaradha 03/23/2020 03:16:55 am)

Re: The Header option from module itself

Here I have added the details of my templates to test it as well as change the templates. We have 4 templates now. And still we are adding 3 more soon.

https://www.kvcodes.com/module/premium-pdf-templates-frontaccounting/

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

Wonder how dark backgrounds would go with printing. Pre-printed stationery may do it well too. They look good though! Did you have to
1, create a new header file itself or
2. just a PDF template like you described earlier or
3. make an extension with specific settings much like themes?

Re: The Header option from module itself

@apmuthu, we created separate header file for each templates and made some changes inside the rep107, rep111, rep109 as well. and also all of these files we put it inside our module to take up here. Nothing touched in the core.

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

The changed rep###.php files can be placed in the company/#/reporting folder to substitute the standard ones in the core reporting folder.

@joe: any hooks for replacement header files?

Re: The Header option from module itself

No, I don't have any suggestions at present. Please continue experimenting. Maybe some good ideas will show up.

Joe

15 (edited by kvvaradha 03/25/2020 02:46:50 pm)

Re: The Header option from module itself

There is no need to create new functionality for handling functions from modules. The existing program already checks the modules directory like this

/modules/module_name/reporting/repXXX.php and if anything is there and it was linked in reports_custom.php. that will be replacing with existing core reports.

With that it's good to change the rep files.  And regarding the headers also it's connecting from modules directory and works properly.
Hope nothing to research more about it.

Actually I was trying to make few things.

*login files from themes directory
*hooks for custom fields in different area
*smtp for emails
* nicedit for textareas with on and off option
* bring salesman column in sales orders and debtor trans tables and alter queries to work on
* my batch functionality which I have done already.


And I will make an unofficial version for users to get it.

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

@kvvaradha
Actually I was doing some trial on login.inc file from the themes. The normal login.php checks if there is a login.inc file in the theme directory and if, this is called instead of the default login. It is prepared, but I thought it could wait to 2.5. To implement it in 2.5, I am waiting for some changing that Janusz want to do before we start implementing the 2.5 things. Unfortunately he is very occupied with his normal work at present.
In the example I did, I changed the login.php, and all the other helpers timeout etc. so it was easier to implement a theme login.
The trials works perfectly and it is safe.
The custom fields is also interesting for at least 2.5. And more.

/Joe

Re: The Header option from module itself

@Joe I tired in another way. From config.php we will save the default theme in a constant  and then from sessions.inc we will check whether the theme login.php exist or not. If it exist, we can require that file. Otherwise it will require the access/login.php. it's good alternative i feel. And you can try yourself whether it works or not.

Subscription service based on FA
HRM CRM POS batch Themes

Re: The Header option from module itself

@kvvaradha.
Sure, I also thought about a global config.php flag if the login was from theme, however for safety I think it is better going from existing login.php where all the tests code is executed here and only the layout would be called from theme if a login.inc file exists.

Joe

Re: The Header option from module itself

kvvaradha wrote:

There is a small change in the core of pdf_report.inc will  give us a good way to add template form from the module itself.

from the reporting/includes/pdf_report.inc:

function NewPage() 
    {
        global $installed_extensions, $path_to_root;
    
    
        if ($this->pageNumber==0)
        {
            // check if there is pdf header template for this report
            // and set if it is found
            $tmpl_pdf = find_custom_file("/reporting/forms/".$this->headerTmpl.".pdf");
            if ($tmpl_pdf) {
                $this->tmplSize = $this->setSourceFile($tmpl_pdf);
            } else {
                // include reports installed inside extension modules
                if (count($installed_extensions) > 0)
                {
                    $extensions = $installed_extensions;
                    foreach ($extensions as $ext)
                        if (($ext['active'] && $ext['type'] == 'extension')) {
                            $tmpl_pdf = find_custom_file($path_to_root.'/'.$ext['path']."/reporting/forms/".$this->headerTmpl.".pdf");
                            if ($tmpl_pdf) {
                                $this->tmplSize = $this->setSourceFile($tmpl_pdf);
                            }
                        }
                }
            }
        }

        $this->pageNumber++;
        parent::newPage();

        if ($this->tmplSize) {
            $this->row = $this->pageHeight - $this->topMargin; // reset row
            $id = $this->importPage(min($this->pageNumber, $this->tmplSize));
            $this->useTemplate($id);
        }

        // include related php file if any
        $tmpl_php = find_custom_file("/reporting/forms/".$this->headerTmpl.".php");
        if ($tmpl_php) {
            include($tmpl_php);
        }  else {
                // include reports installed inside extension modules
                if (count($installed_extensions) > 0)
                {
                    $extensions = $installed_extensions;
                    foreach ($extensions as $ext)
                        if (($ext['active'] && $ext['type'] == 'extension')) {
                            $tmpl_php = find_custom_file($path_to_root.'/'.$ext['path']."/reporting/forms/".$this->headerTmpl.".php");
                            if ($tmpl_php) {
                                $this->tmplSize = $this->setSourceFile($tmpl_php);
                            }
                        }
                }
            }

        if (method_exists($this, $this->headerTmpl))    // draw predefined page layout if any
            $this->{$this->headerTmpl}();
    }

This would help us to hook from the modules template to work on.

howto use this header template ?

Re: The Header option from module itself

Just find this function  and compare my code. You can update the change in it.

Subscription service based on FA
HRM CRM POS batch Themes