navigation.plugin.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function navigation_menu(){
  4. global $_,$myUser,$conf;
  5. // if(!$myUser->can('navigation','read')) return;
  6. $page = basename($_SERVER['REQUEST_URI']);
  7. $menuItems = array();
  8. $menuItems[] = array(
  9. 'sort'=>299,
  10. 'id'=>'{{id}}',
  11. 'url'=>'{{url}}',
  12. 'title'=>'{{title}}',
  13. 'target'=>'{{target}}',
  14. 'label'=>'{{{label}}}',
  15. 'icon'=> '{{icon}}',
  16. 'classes' =>'navigation-template-item hide',
  17. 'html' =>'<span class="navigation-edit-item-button hide" data-id="{{id}}" onclick="navigation_menuitem_edit(this,event)"><i class="fas fa-pencil-alt"></i></span>'
  18. );
  19. $menuItems[] = array(
  20. 'sort'=>400,
  21. 'label'=>'Affaires',
  22. 'slug'=>'case',
  23. 'icon'=> 'fas fa-suitcase',
  24. 'classes' =>'pointer'
  25. );
  26. $menuItems[] = array(
  27. 'sort'=>401,
  28. 'label'=>'Organisation',
  29. 'slug'=>'organization',
  30. 'icon'=> 'far fa-calendar-alt',
  31. 'classes' =>'pointer'
  32. );
  33. $menuItems[] = array(
  34. 'sort'=>402,
  35. 'label'=>'Statistiques',
  36. 'slug'=>'statistics',
  37. 'icon'=> 'fas fa-chart-line',
  38. 'classes' =>'pointer',
  39. );
  40. $menuItems[] = array(
  41. 'sort'=>403,
  42. 'label'=>'Exploitation',
  43. 'slug'=>'exploitation',
  44. 'icon'=> 'fas fa-cubes',
  45. 'classes' =>'pointer'
  46. );
  47. uasort($menuItems , function($a,$b){return $a['sort']>$b['sort']?1:-1;});
  48. //Menus ajoutés par les plugins
  49. $mainMenu = array();
  50. Plugin::callHook("menu_main", array(&$mainMenu));
  51. uasort ($mainMenu , function($a,$b){return $a['sort']>$b['sort']?1:-1;});
  52. foreach ($mainMenu as $item) {
  53. foreach ($menuItems as $key=>$existingitem) {
  54. if(!isset($item['parent'])) continue;
  55. if(!isset($existingitem['slug']) || $item['parent'] != $existingitem['slug']) continue;
  56. if(!isset($existingitem['childs']))
  57. $existingitem['childs'] = array();
  58. $existingitem['childs'][] = $item;
  59. $menuItems[$key] = $existingitem;
  60. }
  61. }
  62. if($conf->get('navigation_show_uncategorized')){
  63. foreach ($mainMenu as $item)
  64. if(!isset($item['parent'])) $menuItems[] = $item;
  65. }
  66. if($myUser->can('navigation','edit')){
  67. $menuItems[] = array(
  68. 'sort'=>300,
  69. 'onclick'=>'navigation_navigation_edit()',
  70. 'title'=>'Modifier le menu',
  71. 'icon'=> 'fas fa-edit',
  72. 'classes' =>'navigation-edit-button pointer'
  73. );
  74. $menuItems[] = array(
  75. 'sort'=>300,
  76. 'onclick'=>'navigation_navigation_save()',
  77. 'title'=>'Arrêter les modifications',
  78. 'icon'=> 'fas fa-check',
  79. 'classes' =>'navigation-validate-button pointer'
  80. );
  81. $menuItems[] = array(
  82. 'sort'=>300,
  83. 'onclick'=>'navigation_menuitem_edit()',
  84. 'title'=>'Ajouter un item',
  85. 'icon'=> 'fas fa-plus',
  86. 'classes' =>'navigation-plus-button pointer'
  87. );
  88. }
  89. ?>
  90. <ul class="navbar-nav navigation-menu">
  91. <?php if ($myUser->connected()): ?>
  92. <?php foreach($menuItems as $item): ?>
  93. <?php if (isset($item['label']) && $item['label'] == 'Réglages') $page = basename($_SERVER['PHP_SELF']);
  94. $classes = isset($item['classes'])? $item['classes']: '';
  95. if( isset($item['url']) && (
  96. (!empty($item['url'])
  97. && strpos($page, $item['url']) !== false
  98. && $item['url'] != 'index.php')
  99. || $page == $item['url'])
  100. ){
  101. $classes .= ' active';
  102. }
  103. if(!isset($item['childs']) && empty($item['url']) && empty($item['onclick'])) continue;
  104. ?>
  105. <li data-id="<?php echo isset($item['id'])?$item['id']:''; ?>" class="nav-item <?php echo $classes; ?> <?php echo isset($item['childs'])? 'dropdown':''; ?>">
  106. <a class="nav-link<?php echo isset($item['childs'])? ' dropdown-toggle':''?>"
  107. <?php echo isset($item['childs'])? 'data-toggle="dropdown"':''; ?>
  108. title="<?php echo isset($item['title'])?$item['title']:''; ?>"
  109. target="<?php echo isset($item['target'])?$item['target']:''; ?>"
  110. onclick="<?php echo isset($item['onclick'])?$item['onclick']:''; ?>"
  111. <?php echo isset($item['url'])? 'href="'.$item['url'].'"':''; ?>>
  112. <?php echo (isset($item['icon'])?'<i class="'.$item['icon'].'"></i> ':'').'<span>'.(isset($item['label'])?$item['label']:'').'</span>'; ?>
  113. <?php echo isset($item['html'])? $item['html']:''; ?>
  114. </a>
  115. <?php if(isset($item['childs'])): ?>
  116. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  117. <?php foreach($item['childs'] as $child): ?>
  118. <a class="dropdown-item" href="<?php echo $child['url']; ?>">
  119. <?php echo (isset($child['icon'])?'<i class="'.$child['icon'].'"></i> ':'') ?>
  120. <?php echo $child['label']; ?></a>
  121. <?php endforeach; ?>
  122. </div>
  123. <?php endif; ?>
  124. </li>
  125. <?php endforeach; ?>
  126. <?php endif; ?>
  127. </ul>
  128. <?php
  129. }
  130. //Cette fonction va generer une page quand on clique sur navigation dans menu
  131. function navigation_page(){
  132. global $_,$myUser;
  133. if(!isset($_['module']) || $_['module'] !='navigation') return;
  134. $page = !isset($_['page']) ? 'list' : $_['page'];
  135. $file = __DIR__.SLASH.'page.'.$page.'.php';
  136. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  137. require_once($file);
  138. }
  139. //Fonction executée lors de l'activation du plugin
  140. function navigation_install($id){
  141. if($id != 'fr.idleman.navigation') return;
  142. Entity::install(__DIR__);
  143. }
  144. //Fonction executée lors de la désactivation du plugin
  145. function navigation_uninstall($id){
  146. if($id != 'fr.idleman.navigation') return;
  147. Entity::uninstall(__DIR__);
  148. }
  149. //Déclaration des sections de droits du plugin
  150. function navigation_section(&$sections){
  151. $sections['navigation'] = "Gestion des droits sur le plugin navigation";
  152. }
  153. //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
  154. function navigation_action(){
  155. require_once(__DIR__.SLASH.'action.php');
  156. }
  157. //Déclaration du menu de réglages
  158. function navigation_menu_setting(&$settingMenu){
  159. global $_, $myUser;
  160. if(!$myUser->can('navigation','configure')) return;
  161. $settingMenu[]= array(
  162. 'sort' =>1,
  163. 'url' => 'setting.php?section=global.navigation',
  164. 'icon' => 'fas fa-angle-right',
  165. 'label' => 'Menu & Navigation'
  166. );
  167. }
  168. //Déclaration des pages de réglages
  169. function navigation_content_setting(){
  170. global $_;
  171. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  172. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  173. }
  174. //Déclaration des settings de base
  175. //Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
  176. Configuration::setting('navigation',array(
  177. "Général",
  178. 'navigation_show_uncategorized' => array("label"=>"Afficher les menus natifs non catégorisés","legend"=>"Affiche les menus de plugins qui n'ont pas de catégorie parente","type"=>"checkbox"),
  179. 'navigation_allow_custom_menu' => array("label"=>"Autoriser la création de menu personnalisés","legend"=>"Autorise aux utilisateurs la création de menu custom dans la navbar","type"=>"checkbox"),
  180. ));
  181. //Déclation des assets
  182. Plugin::addCss("/css/main.css?v=1");
  183. Plugin::addJs("/js/main.js?v=1");
  184. //Mapping hook / fonctions
  185. Plugin::addHook("install", "navigation_install");
  186. Plugin::addHook("uninstall", "navigation_uninstall");
  187. Plugin::addHook("section", "navigation_section");
  188. Plugin::addHook("header", "navigation_menu");
  189. Plugin::addHook("page", "navigation_page");
  190. Plugin::addHook("action", "navigation_action");
  191. Plugin::addHook("menu_setting", "navigation_menu_setting");
  192. Plugin::addHook("content_setting", "navigation_content_setting");
  193. ?>