dynamicform.plugin.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function dynamicform_menu(&$menuItems){
  4. global $myUser;
  5. if(!$myUser->can('dynamicform','read')) return;
  6. $menuItems[] = array(
  7. 'sort'=>3,
  8. 'url'=>'index.php?module=dynamicform',
  9. 'label'=>'Formulaires',
  10. 'icon'=> 'fas fa-text-height',
  11. 'color'=> '#273c75'
  12. );
  13. }
  14. //Cette fonction va generer une page quand on clique sur dynamicform dans menu
  15. function dynamicform_page(){
  16. global $_;
  17. if(!isset($_['module']) || $_['module'] !='dynamicform') return;
  18. $page = !isset($_['page']) ? 'list.dynamic.form' : $_['page'];
  19. $page = str_replace('..','',$page);
  20. $file = __DIR__.SLASH.'page.'.$page.'.php';
  21. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  22. require_once($file);
  23. }
  24. //Fonction executée lors de l'activation du plugin
  25. function dynamicform_install($id){
  26. if($id != 'fr.core.dynamicform') return;
  27. Entity::install(__DIR__);
  28. }
  29. //Fonction executée lors de la désactivation du plugin
  30. function dynamicform_uninstall($id){
  31. if($id != 'fr.core.dynamicform') return;
  32. Entity::uninstall(__DIR__);
  33. }
  34. //Déclaration des sections de droits du plugin
  35. //Déclaration des sections de droits du plugin
  36. Right::register('dynamicform',array('label'=>'Gestion des droits sur les formulaires dynamiques'));
  37. function dynamic_types_filter($field,&$filterType,&$filterOptions){
  38. switch($field['type']->slug){
  39. case 'user':
  40. case 'firm':
  41. case 'rank':
  42. case 'date':
  43. case 'hour':
  44. case 'boolean':
  45. $filterType = $field['type']->slug;
  46. break;
  47. case 'price':
  48. case 'integer':
  49. case 'float':
  50. $filterType = 'number';
  51. break;
  52. case 'list':
  53. $filterType = $field['type']->slug;
  54. $filterOptions = ' data-filter-type="list" data-source="'.(isset($field['meta']) ? $field['meta'] : '').'" data-depth="1" data-disable-label ';
  55. break;
  56. case 'dictionary':
  57. $filterType = $field['type']->slug;
  58. $meta = isset($field['meta']) ? json_decode(base64_decode($field['meta']), true) : array();
  59. $filterOptions = ' data-filter-type="dictionary" data-slug="'.(isset($meta['slug']) ? $meta['slug'] : '').'" data-depth="1" data-disable-label ';
  60. break;
  61. case 'checkbox-list':
  62. $filterType = $field['type']->slug;
  63. $meta = isset($field['meta']) ? json_decode(base64_decode($field['meta']), true) : array();
  64. $filterOptions = ' data-filter-type="checkbox-list" data-slug="'.(isset($meta['slug']) ? $meta['slug'] : '').'" data-depth="1" data-disable-label ';
  65. break;
  66. }
  67. }
  68. require_once(__DIR__.SLASH.'action.php');
  69. //Déclation des assets
  70. Plugin::addCss("/css/main.css");
  71. Plugin::addJs("/js/main.js");
  72. //Mapping hook / fonctions
  73. Plugin::addHook("install", "dynamicform_install");
  74. Plugin::addHook("uninstall", "dynamicform_uninstall");
  75. Plugin::addHook("menu_main", "dynamicform_menu");
  76. Plugin::addHook("page", "dynamicform_page");
  77. ?>