dashboard.plugin.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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']) || !$myUser->connected()) 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.core.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.core.dashboard') return;
  21. Entity::uninstall(__DIR__);
  22. }
  23. //Déclaration des sections de droits du plugin
  24. //Déclaration des sections de droits du plugin
  25. Right::register('dashboard',array('label'=>'Gestion des droits sur le plugin dashboard'));
  26. //Comprends toutes les actions du plugin qui ne nécessitent pas de vue html
  27. require_once(__DIR__.SLASH.'action.php');
  28. //Déclaration du menu de réglages
  29. function dashboard_menu_setting(&$settingMenu){
  30. global $myUser;
  31. if(!$myUser->can('dashboard','configure')) return;
  32. $settingMenu[] = array(
  33. 'sort' =>1,
  34. 'url' => 'setting.php?section=dashboard',
  35. 'icon' => 'fas fa-angle-right',
  36. 'label' => 'Dashboard'
  37. );
  38. }
  39. //Déclaration des pages de réglages
  40. function dashboard_content_setting(){
  41. global $_;
  42. $_['section'] = str_replace('..', '', $_['section']);
  43. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  44. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  45. }
  46. function dashboard_default_widget(&$widgets){
  47. global $myUser;
  48. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  49. $modelWidget = new DashboardWidget();
  50. $modelWidget->model = 'clock';
  51. $modelWidget->title = 'Horloge';
  52. $modelWidget->icon = 'far fa-clock';
  53. $modelWidget->background = '#212529';
  54. $modelWidget->load = 'action.php?action=dashboard_widget_clock_load';
  55. $modelWidget->js = [Plugin::url().'/js/progressbar.min.js?v=2',Plugin::url().'/js/widget.js?v=2'];
  56. $modelWidget->css = [Plugin::url().'/css/widget.css?v='.time()];
  57. $modelWidget->description = "Affiche l'heure en temps réel";
  58. $widgets[] = $modelWidget;
  59. $modelWidget = new DashboardWidget();
  60. $modelWidget->model = 'profile';
  61. $modelWidget->title = 'Profil';
  62. $modelWidget->minWidth = 2;
  63. $modelWidget->maxWidth = 4;
  64. $modelWidget->icon = 'far fa-user';
  65. $modelWidget->background = '#007bff';
  66. $modelWidget->load = 'action.php?action=dashboard_widget_profile_load';
  67. $modelWidget->js = [Plugin::url().'/js/widget.js?v='.time()];
  68. $modelWidget->css = [Plugin::url().'/css/widget.css?v='.time()];
  69. $modelWidget->configure = 'action.php?action=dashboard_widget_profile_configure';
  70. $modelWidget->configure_callback = 'dashboard_widget_profile_configure_save';
  71. $modelWidget->description = "Affiche les informations de profil";
  72. $widgets[] = $modelWidget;
  73. $modelWidget = new DashboardWidget();
  74. $modelWidget->model = 'html';
  75. $modelWidget->title = 'Texte / Code HTML';
  76. $modelWidget->icon = 'fas fa-code';
  77. $modelWidget->background = '#686de0';
  78. $modelWidget->load = 'action.php?action=dashboard_widget_html_load';
  79. $modelWidget->js = [Plugin::url().'/js/widget.js?v='.time()];
  80. $modelWidget->css = [Plugin::url().'/css/widget.css?v='.time()];
  81. $modelWidget->configure = 'action.php?action=dashboard_widget_html_configure';
  82. $modelWidget->configure_callback = 'dashboard_widget_html_configure_save';
  83. $modelWidget->description = "Affiche un texte ou un morceau de code html intégré";
  84. $widgets[] = $modelWidget;
  85. $modelWidget = new DashboardWidget();
  86. $modelWidget->model = 'log';
  87. $modelWidget->title = 'Logs';
  88. $modelWidget->defaultWidth = 8;
  89. $modelWidget->options[] = array('function'=>'window.location = \'setting.php?section=log\';','icon'=>'fa-eye','title'=>'Voir tous les logs');
  90. $modelWidget->icon = 'far fa-comment-dots';
  91. $modelWidget->background = '#28a745';
  92. $modelWidget->load = 'action.php?action=dashboard_widget_log_load';
  93. $modelWidget->js = [Plugin::url().'/js/widget.js?v='.time()];
  94. $modelWidget->css = [Plugin::url().'/css/widget.css?v='.time()];
  95. $modelWidget->description = "Affiche les informations des 30 derniers logs";
  96. if($myUser->can('log','read'))
  97. $widgets[] = $modelWidget;
  98. }
  99. //Déclation des assets
  100. Plugin::addCss("/css/main.css");
  101. Plugin::addJs("/js/main.js");
  102. //Mapping hook / fonctions
  103. Plugin::addHook("install", "dashboard_install");
  104. Plugin::addHook("uninstall", "dashboard_uninstall");
  105. Plugin::addHook("page", "dashboard_page");
  106. Plugin::addHook("menu_setting", "dashboard_menu_setting");
  107. Plugin::addHook("content_setting", "dashboard_content_setting");
  108. Plugin::addHook("widget", "dashboard_default_widget");
  109. ?>