Is it possible to add/include a PHP file that can be load on every page/screen

how we can add/include a PHP file that can be load on every page/screen?
somewhere in the header. what is the best location where I can add my PHP file?

can anyone help?

Have a look at themes/SuiteP/tpls/_headerModuleList.tpl

it depends on what goals this file has…

For example, if I need to add some logic triggering when loading a page or embed a js script, then the ideal option is:

logic hoock - after_ui_frame

In file: custom/modules/logic_hooks.php i register the hook, and then create the methods I need in the hook file (the file name and address are described in logic_hooks.php) as an example:

custom/modules/logic_hooks.php

<?php
$hook_version = 1; 
$hook_array = Array();
$hook_array['after_ui_frame'][] = Array(15, 'add JS on view', 'custom/ODS_Util/global_hooks.php', 'ODS_Global_Hooks', 'echoJS'); 

custom/ODS_Util/global_hooks.php

<?php
if(!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}

class ODS_Global_Hooks
{
	public function echoJS($event, $arguments)
    {
        if ($_REQUEST['action']=='EditView') {
			echo '<script type="text/javascript" src="custom/ODS_Util/js_script/jquery.maskedinput.js"></script>';
			echo '<script type="text/javascript">$(".date_input").mask("99.99.9999")</script>';
		}

		if (in_array($_REQUEST['action'], array('DetailView', 'EditView', 'ListView'))) {
            echo '<script type="text/javascript" src="custom/ODS_Util/js_script/common.itfb.js"></script>';
        }
	}
}
2 Likes

Thank you Eldraft for your input.

but I think this will work only for one module, I need my PHP file to work/load on whatever page user visiting, not only for a specific module.

This work for all system and all page.
Even on administration pages =),

after_ui_frame is application hooks, not a module

Take a closer look at my example - I even have to limit the output.

See developer guide:
Logic Hooks/ Application Hooks

after_ui_frame
Fired after the UI has been displayed but before the footer has been displayed.

2 Likes

Hi,
Please use the hook @Eldraft suggested, this will work on all pages. But please note do such kind of coding in this module which may not effect any CORE JS or PHP files,headers And Admin Tools.

Thanks

Thank you .

This works perfectly. :star_struck:

Thank you for your help.
This is working fine, but I have facing an issue.

here is my global webhook simple code, I have placed this file in custom/modules/globalhooks.php

class Globalhooks
{
public function globalphp($event, $arguments)
{
	global $db;
	global $current_user;
	if($current_user->extension == 'test')
	{
		?>
        <script type="text/javascript">
			var a = 2;
		</script>
        <?php
	}
}
}

this hook is calling successfully, but when I tried to edit a filed (using inline edit) it alerts with this error popup because of javascript added in the above code (when I removed the javascript, I can successfully do inline edit)

can someone enlighten me what’s wrong.
Thanks