You are not logged in.
Hello, after searching quite a while, I could not find a plugin or clear instructions on how to add custom pages to GLPI like eg. a custom legal notice and privacy statement, and desirably links to these custom pages should appear in the footer of all pages.
I'm just wondering if I'm searching for the wrong buzzwords or if this is not intended at all. I guess this question may have come up allready, as it is mandatory in many contexts to have these pages.
As far as I understand, I'd either need to write my own plugin to accomplish this task or hack my code into the existing GLPI-php files (which is not so nice, obviously). Am I maybe missing something here or what would be your suggestions?
Thank you. Best regards!
Last edited by Albager (2022-01-21 14:02:31)
Offline
Why don't you add items in FAQ / KB ?
Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1 Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9
Offline
Not sure if I understand correctly, but how would I create a link to this Knowledge Base / FAQ entry in all pages' footer?
I have now edited the html.class.php from lines 6446 and added some html to the getCopyrightMessage function... but of course, these changes will be lost after every update... But if this should be the (easiest) way to go, setting up server side git on the glpi folder could help manage or even automate that.
Last edited by Albager (2022-01-21 17:04:47)
Offline
The best solution for changes like this would be in a plugin so that you avoid having to make the changes every time you update GLPI and makes it easier to troubleshoot if you ever run into issues with GLPI.
The FusionInventory plugin loads a JavaScript to automatically add a message to the footer:
$(window).bind("load", function() {
$('#footer').css('height', 'auto');
$("#footer td.right").append(fifooter);
});
In the snippet, fifooter is the HTML content they inject.
It should be easy to implement your own plugin by starting with the empty plugin template:
https://github.com/pluginsGLPI/empty
Run "./plugin.sh YourPluginNameWithoutSpaces 1.0.0 /path/to/glpi/plugins" to initialize the plugin files in your GLPI instance.
Copy the above JavaScript into a new JS file within your plugin folder.
Use the 'add_javascript' hook in the init function for the plugin's setup.php file.
$PLUGIN_HOOKS['add_javascript']['yourpluginnamewithoutspaces'][] = 'relative/path/to/js/file.js';
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
Is it possible to get a complete working plugin example that does just the following one specific thing?
- Add a top-level menu item that links to a "blank" page -- e.g. a canvas for you to write any PHP on it that you want to.
I'm struggling to figure out how to do this.
Offline
There is no example plugin that only does that one thing.
There are plenty of smaller plugins you could look at and quickly get an idea of how it is done.
Take "https://github.com/cconard96/glpi-dev-plugin/" for example,
It adds an entry under the "Plugins" menu (normally hidden until there is something in the menu) for "GLPI Development Helper".
Starting in the setup.php file, you can see it uses the "menu_toadd" hook:
$PLUGIN_HOOKS['menu_toadd']['dev'] = ['plugins' => 'PluginDevMenu'];
This tells GLPI to add an entry for the "PluginDevMenu" class to the plugins entry.
You can find this class in "inc/menu.class.php". Then, for the actual display GLPI will look for a file under the "front" directory with a matching name for when the page is actually displayed. In this case, "front/menu.php".
This hook lets you add menu entries under the existing top-level options, but does not let you add any top-level sections.
The other method of modifying the menu is the "redefine_menus" hook.
You can see an example of its use in "https://github.com/cconard96/glpimenufix".
This time, "redefine_menus" is a "function" hook so the code in the setup.php file gives GLPI the name of a function to call after the menu is initially generated:
$PLUGIN_HOOKS['redefine_menus']['menufix'] = 'plugin_menufix_redefine_menus';
In the hook.php file, you can see the implementation of that function. When GLPI calls it, it will pass the entire menu array as a parameter. You have the ability to modify it as needed and then return the modified menu array.
This plugin hook would allow you to create entirely new top-level entries.
A top-level item that is an actual link can be defined like it is done for the "Create a ticket" option that shows for regular users:
$menu['create_ticket'] = [
'default' => '/front/helpdesk.public.php?create_ticket=1',
'title' => __('Create a ticket'),
'icon' => 'ti ti-plus',
];
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
Ok that is super helpful! Thank so much for the detailed answer!
Another question (hopefully the last):
I got the menu link to direct to /plugins/myplugin/mypage.php, but the webserver fails to serve it. I'm serving my DocumentRoot as glpi/public as recommended. Is the router going to be able to serve the PHP page out of my plugin folder?
Last edited by jhoux@zirrusone.com (2023-12-19 19:56:22)
Offline
"Is the router going to be able to serve the PHP page out of my plugin folder?"
I don't know, but I wouldn't recommend putting that file there. The only files directly in the plugin folder should be setup.php, hook.php and maybe a few other files like a readme, changelog, dependency configs, etc. Any PHP script served to users should be in subfolders named "ajax" or "front". "ajax" refers to scripts called through "Asynchronous JavaScript And XML" to get data from the server without reloading/redirecting the page. Scripts that represent the entry-point for pages should be in "front". For CSS and JavaScript, they should be in a "public" subfolder.
If you still cannot get the page to load after moving the script and changing the link, please indicate the error you are seeing in the browser and if there are any errors in your GLPI logs (files/_log folder by default).
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
So you're saying under the recommended installation practice, its not possible to serve custom pages without putting them in a core folder?
Does this mean either a) nobody makes custom pages in community plugins or b) if someone publishes a plugin with custom pages, there are instructions indicating to copy files into "glpi/front" ?
Last edited by jhoux@zirrusone.com (2023-12-19 23:45:06)
Offline
If custom file "mypage.php" has to be in "glpi/front", could it put it in a subfolder? For instance, could the file be located at "glpi/front/custom/mypage.php".
If that's acceptable forward practice, then it would be nice because "glpi/front/custom" could be symbolicly linked to an external folder. I'm just trying to avoid putting anything in core folders. I've even remapped "glpi/plugins" as a symbolic link to an external plugins folder.
Last edited by jhoux@zirrusone.com (2023-12-19 23:48:36)
Offline
The subfolders I was referring to would be inside your plugin's folder.
Your plugin folder structure would look something like:
/plugins/custom/ajax
/plugins/custom/front
/plugins/custom/inc
/plugins/custom/setup.php
/plugins/custom/hook.php
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline