action.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. global $_,$conf;
  3. switch($_['action']){
  4. /** MENUITEM **/
  5. //Récuperation d'une liste de menuitem
  6. case 'navigation_menuitem_search':
  7. Action::write(function(&$response){
  8. global $myUser,$_;
  9. if (!$myUser->connected()) return;
  10. if(!$myUser->can('navigation','read')) return;
  11. require_once(__DIR__.SLASH.'MenuItem.class.php');
  12. $items = MenuItem::staticQuery('SELECT * FROM {{table}} WHERE user="" OR user=? ORDER BY sort',array($myUser->login),true);
  13. $mainMenu = array();
  14. Plugin::callHook("menu_main", array(&$mainMenu));
  15. foreach ($mainMenu as $item) {
  16. foreach ($items as $key=>$existingitem) {
  17. if(isset($item['parent'])){
  18. if(isset($existingitem->slug) && $item['parent'] == $existingitem->slug){
  19. if(!isset($existingitem->childs)) $existingitem->childs = array();
  20. $existingitem->childs[] = $item;
  21. $items[$key] = $existingitem;
  22. }
  23. }
  24. }
  25. }
  26. foreach($items as $menuitem){
  27. $response['rows'][] = $menuitem;
  28. }
  29. });
  30. break;
  31. case 'navigation_menuitem_move':
  32. Action::write(function(&$response){
  33. global $myUser,$_;
  34. if(!$myUser->can('navigation','edit')) throw new Exception("Permissions insuffisantes",403);
  35. require_once(__DIR__.SLASH.'MenuItem.class.php');
  36. if(isset($_['sort']) && !empty($_['sort'])){
  37. foreach ($_['sort'] as $sort => $id) {
  38. $item = MenuItem::getById($id);
  39. $item->sort = $sort;
  40. $item->save();
  41. }
  42. }
  43. });
  44. break;
  45. //Ajout ou modification d'élément menuitem
  46. case 'navigation_menuitem_save':
  47. Action::write(function(&$response){
  48. global $myUser,$_,$conf;
  49. if(!$myUser->can('navigation','edit')) throw new Exception("Permissions insuffisantes",403);
  50. require_once(__DIR__.SLASH.'MenuItem.class.php');
  51. if(!isset($_['url']) || empty($_['url'])) throw new Exception("Adresse web obligatoire");
  52. if(!$conf->get('navigation_allow_custom_menu') && !$myUser->superadmin) throw new Exception("La configuration du plugin n'autorise pas l'ajout de menu custom");
  53. $item = MenuItem::provide();
  54. if(!$item->editable && !$myUser->superadmin) throw new Exception("Ce menu n'est pas éditable");
  55. $item->icon = $_['icon'];
  56. $item->label = $_['label'];
  57. $item->url = str_replace(ROOT_URL.'/','',$_['url']);
  58. $item->target = $_['target'];
  59. $item->user = $myUser->login;
  60. if(isset($_['public']) && $_['public']=='1' && $myUser->can('navigation','configure'))
  61. $item->user = '';
  62. if($item->id==0){
  63. $item->slug = slugify($item->label);
  64. if(MenuItem::rowCount(array('slug'=>$item->slug)) <0 )
  65. $item->slug .='_'.time();
  66. }
  67. //$item->parent = $_['parent'];
  68. $item->save();
  69. });
  70. break;
  71. //Récuperation ou edition d'élément menuitem
  72. case 'navigation_menuitem_edit':
  73. Action::write(function(&$response){
  74. global $myUser,$_;
  75. if(!$myUser->can('navigation','edit')) throw new Exception("Permissions insuffisantes",403);
  76. require_once(__DIR__.SLASH.'MenuItem.class.php');
  77. $response = MenuItem::getById($_['id']);
  78. });
  79. break;
  80. //Suppression d'élement menuitem
  81. case 'navigation_menuitem_delete':
  82. Action::write(function(&$response){
  83. global $myUser,$_;
  84. if(!$myUser->can('navigation','delete')) throw new Exception("Permissions insuffisantes",403);
  85. require_once(__DIR__.SLASH.'MenuItem.class.php');
  86. MenuItem::deleteById($_['id']);
  87. // Décommenter pour une suppression logique
  88. // $item = MenuItem::getById($_['id']);
  89. // $item->state = MenuItem::INACTIVE;
  90. // $item->save();
  91. });
  92. break;
  93. //Sauvegarde des configurations de navigation
  94. case 'navigation_setting_save':
  95. Action::write(function(&$response){
  96. global $myUser,$_,$conf;
  97. if(!$myUser->can('navigation','configure')) throw new Exception("Permissions insuffisantes",403);
  98. foreach(Configuration::setting('navigation') as $key=>$value){
  99. if(!is_array($value)) continue;
  100. $allowed[] = $key;
  101. }
  102. foreach ($_['fields'] as $key => $value)
  103. if(in_array($key, $allowed)) $conf->put($key,$value);
  104. });
  105. break;
  106. }
  107. ?>