You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2022-01-21 13:51:10

Albager
Member
Registered: 2021-03-16
Posts: 10

How to add custom pages like legal notice, privacy statement et cetera

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

#2 2022-01-21 16:28:29

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,287

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#3 2022-01-21 17:02:24

Albager
Member
Registered: 2021-03-16
Posts: 10

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#4 2022-01-22 20:26:57

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#5 2023-12-15 23:50:01

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#6 2023-12-16 00:45:33

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#7 2023-12-19 19:56:03

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#8 2023-12-19 20:30:57

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: How to add custom pages like legal notice, privacy statement et cetera

"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

#9 2023-12-19 23:44:57

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#10 2023-12-19 23:47:56

jhoux@zirrusone.com
Member
Registered: 2023-01-13
Posts: 14

Re: How to add custom pages like legal notice, privacy statement et cetera

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

#11 2023-12-20 03:24:37

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: How to add custom pages like legal notice, privacy statement et cetera

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

Board footer

Powered by FluxBB