dashboard.plugin.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. //Cette fonction va generer une page quand on clique sur dashboard dans menu
  3. function dashboard_page(){
  4. global $_,$myUser,$conf;
  5. if(isset($_['module'])) return;
  6. $page = !isset($_['page']) ? 'home' : $_['page'];
  7. $file = __DIR__.SLASH.'page.'.$page.'.php';
  8. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  9. require_once($file);
  10. }
  11. //Fonction executée lors de l'activation du plugin
  12. function dashboard_install($id){
  13. if($id != 'fr.idleman.dashboard') return;
  14. global $conf;
  15. Entity::install(__DIR__);
  16. $conf->put('dashboard_enable_sidebar',1);
  17. }
  18. //Fonction executée lors de la désactivation du plugin
  19. function dashboard_uninstall($id){
  20. if($id != 'fr.idleman.dashboard') return;
  21. Entity::uninstall(__DIR__);
  22. }
  23. //Déclaration des sections de droits du plugin
  24. function dashboard_section(&$sections){
  25. $sections['dashboard'] = "Gestion des droits sur le plugin dashboard";
  26. }
  27. //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
  28. function dashboard_action(){
  29. require_once(__DIR__.SLASH.'action.php');
  30. }
  31. //Déclaration du menu de réglages
  32. function dashboard_menu_setting(&$settingMenu){
  33. global $_, $myUser;
  34. if(!$myUser->can('dashboard','configure')) return;
  35. $settingMenu[]= array(
  36. 'sort' =>1,
  37. 'url' => 'setting.php?section=dashboard',
  38. 'icon' => 'fas fa-angle-right',
  39. 'label' => 'Dashboard'
  40. );
  41. }
  42. //Déclaration des pages de réglages
  43. function dashboard_content_setting(){
  44. global $_;
  45. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  46. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  47. }
  48. //Déclaration des settings de base
  49. //Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
  50. // Configuration::setting('dashboard',array(
  51. // "Général",
  52. // ));
  53. function dashboard_default_widget(&$widgets){
  54. global $myUser;
  55. require_once('DashboardWidget.class.php');
  56. $modelWidget = new DashboardWidget();
  57. $modelWidget->model = 'clock';
  58. $modelWidget->title = 'Horloge';
  59. $modelWidget->icon = 'far fa-clock';
  60. $modelWidget->background = '#212529';
  61. $modelWidget->load = 'action.php?action=dashboard_widget_clock_load';
  62. $modelWidget->js = [Plugin::url().'/js/progressbar.js',Plugin::url().'/js/widget.js?v=2'];
  63. $modelWidget->css = [Plugin::url().'/css/widget.css?v=2'];
  64. $modelWidget->description = "Affiche l'heure en temps réel";
  65. $widgets[] = $modelWidget;
  66. $modelWidget = new DashboardWidget();
  67. $modelWidget->model = 'profile';
  68. $modelWidget->title = 'Profile';
  69. $modelWidget->icon = 'far fa-user';
  70. $modelWidget->background = '#007bff';
  71. $modelWidget->load = 'action.php?action=dashboard_widget_profile_load';
  72. $modelWidget->js = [Plugin::url().'/js/widget.js'];
  73. $modelWidget->css = [Plugin::url().'/css/widget.css?v=2'];
  74. $modelWidget->description = "Affiche les informations de profil";
  75. $widgets[] = $modelWidget;
  76. $modelWidget = new DashboardWidget();
  77. $modelWidget->model = 'log';
  78. $modelWidget->title = 'Logs';
  79. $modelWidget->width = 8;
  80. $modelWidget->options[] = array('function'=>'window.location = \'setting.php?section=log\';','icon'=>'fa-eye','label'=>'Voir tous les logs');
  81. $modelWidget->icon = 'far fa-comment-dots';
  82. $modelWidget->background = '#28a745';
  83. $modelWidget->load = 'action.php?action=dashboard_widget_log_load';
  84. $modelWidget->js = [Plugin::url().'/js/widget.js'];
  85. $modelWidget->css = [Plugin::url().'/css/widget.css?v=2'];
  86. $modelWidget->description = "Affiche les informations des 30 derniers logs";
  87. if($myUser->can('log','read'))
  88. $widgets[] = $modelWidget;
  89. }
  90. //Déclation des assets
  91. Plugin::addCss("/css/main.css?v=1");
  92. Plugin::addJs("/js/main.js?v=1");
  93. //Mapping hook / fonctions
  94. Plugin::addHook("install", "dashboard_install");
  95. Plugin::addHook("uninstall", "dashboard_uninstall");
  96. Plugin::addHook("section", "dashboard_section");
  97. Plugin::addHook("page", "dashboard_page");
  98. Plugin::addHook("action", "dashboard_action");
  99. Plugin::addHook("menu_setting", "dashboard_menu_setting");
  100. Plugin::addHook("content_setting", "dashboard_content_setting");
  101. Plugin::addHook("widget", "dashboard_default_widget");
  102. ?>