setup.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. define('PLUGIN_SINGLESIGNON_VERSION', '1.0.0');
  3. // Init the hooks of the plugins -Needed
  4. function plugin_init_singlesignon() {
  5. global $PLUGIN_HOOKS, $CFG_GLPI, $CFG_SSO;
  6. $autoload = __DIR__ . '/vendor/autoload.php';
  7. if (file_exists($autoload)) {
  8. include_once $autoload;
  9. }
  10. $PLUGIN_HOOKS['csrf_compliant']['singlesignon'] = true;
  11. $CFG_SSO = Config::getConfigurationValues('singlesignon');
  12. $PLUGIN_HOOKS['display_login']['singlesignon'] = "plugin_singlesignon_display_login";
  13. $PLUGIN_HOOKS['menu_toadd']['singlesignon'] = array(
  14. 'plugins' => 'PluginSinglesignonProvider',
  15. 'config' => 'PluginSinglesignonProvider',
  16. );
  17. }
  18. // Get the name and the version of the plugin - Needed
  19. function plugin_version_singlesignon() {
  20. return array(
  21. 'name' => __sso('Single Sign-on'),
  22. 'version' => PLUGIN_SINGLESIGNON_VERSION,
  23. 'author' => 'Edgard Lorraine Messias',
  24. 'homepage' => 'https://github.com/edgardmessias/glpi-singlesignon',
  25. 'minGlpiVersion' => '0.85'
  26. );
  27. }
  28. // Optional : check prerequisites before install : may print errors or add to message after redirect
  29. function plugin_singlesignon_check_prerequisites() {
  30. $autoload = __DIR__ . '/vendor/autoload.php';
  31. if (!file_exists($autoload)) {
  32. echo __sso("Run first: composer install");
  33. return false;
  34. }
  35. if (version_compare(GLPI_VERSION, '0.85', 'lt')) {
  36. echo __sso("This plugin requires GLPI >= 0.85");
  37. return false;
  38. } else {
  39. return true;
  40. }
  41. }
  42. function plugin_singlesignon_check_config() {
  43. return true;
  44. }
  45. function __sso($str) {
  46. return __($str, 'singlesignon');
  47. }
  48. function sso_TableExists($table) {
  49. if (function_exists("TableExists")) {
  50. return TableExists($table);
  51. }
  52. global $DB;
  53. return $DB->TableExists($table);
  54. }
  55. function sso_FieldExists($table, $field, $usecache = true) {
  56. if (function_exists("FieldExists")) {
  57. return FieldExists($table);
  58. }
  59. global $DB;
  60. return $DB->FieldExists($table, $field, $usecache);
  61. }