example.plugin.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function example_menu(&$menuItems){
  4. global $_,$myUser;
  5. if(!$myUser->can('example','read')) return;
  6. $menuItems[] = array(
  7. 'sort'=>2,
  8. 'url'=>'index.php?module=example',
  9. 'label'=>'Example',
  10. 'icon'=> 'fas fa-users',
  11. 'color'=> '#3498db'
  12. );
  13. }
  14. //Cette fonction va generer une page quand on clique sur Modele dans menu
  15. function example_page(){
  16. global $_,$myUser;
  17. if(!isset($_['module']) || $_['module'] !='example') return;
  18. $page = !isset($_['page']) ? 'list' : $_['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 example_install($id){
  26. if($id != 'fr.sys1.example') return;
  27. Entity::install(__DIR__);
  28. }
  29. //Fonction executée lors de la désactivation du plugin
  30. function example_uninstall($id){
  31. if($id != 'fr.sys1.example') return;
  32. Entity::uninstall(__DIR__);
  33. }
  34. //Déclaration des sections de droits du plugin
  35. function example_section(&$sections){
  36. $sections['example'] = "Gestion des droits sur le plugin d'exemple";
  37. }
  38. //Cette fonction comprends toutes les actions
  39. //du plugin qui ne nécessitent pas de vue html
  40. function example_action(){
  41. require_once(__DIR__.SLASH.'action.php');
  42. }
  43. //Déclaration du menu de réglages
  44. function example_menu_setting(&$settingMenu){
  45. global $_, $myUser;
  46. if($myUser->can('example','configure')) {
  47. $settingMenu[]= array(
  48. 'sort' =>1,
  49. 'url' => 'setting.php?section=example',
  50. 'icon' => 'fas fa-angle-right',
  51. 'label' => 'Example'
  52. );
  53. }
  54. }
  55. //Déclaration des pages de réglages
  56. function example_content_setting(){
  57. global $_;
  58. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  59. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  60. }
  61. function example_menu_account(&$accountMenu){
  62. global $_, $myUser;
  63. if(!$myUser->can('example', 'read')) return;
  64. $accountMenu[]= array(
  65. 'sort' =>0,
  66. 'url' => 'account.php?section=example',
  67. 'icon' => 'fas fa-angle-right',
  68. 'label' => 'Example',
  69. );
  70. $accountMenu[]= array(
  71. 'sort' =>0,
  72. 'url' => 'account.php?section=example.contact',
  73. 'icon' => 'fas fa-angle-right',
  74. 'label' => 'Example Contact',
  75. );
  76. }
  77. //Déclaration des pages de réglages
  78. function example_content_account(){
  79. global $_;
  80. if(file_exists(__DIR__.SLASH.'account.'.$_['section'].'.php'))
  81. require_once(__DIR__.SLASH.'account.'.$_['section'].'.php');
  82. }
  83. function example_document_setting(){
  84. $documents = array();
  85. foreach(glob(__ROOT__.FILE_PATH.'contact'.SLASH.'documents'.SLASH.'settings'.SLASH.'*.*') as $file){
  86. if(get_OS() === 'WIN') $file = utf8_encode($file);
  87. $documents[] = array(
  88. 'path' => 'contact'.SLASH.'documents'.SLASH.'settings'.SLASH.basename($file),
  89. 'url' => 'action.php?action=contact_download_document&path=settings'.SLASH.rawurlencode(basename($file)),
  90. 'name' => basename($file),
  91. 'icon' => getExtIcon(getExt($file))
  92. );
  93. }
  94. return $documents;
  95. }
  96. Configuration::setting('example',array(
  97. "Général",
  98. 'example_dropzone' => array("label"=>"Dropzone de fichiers","type"=>"dropzone","legend"=>"la légende","parameters"=>array(
  99. "data-allowed" => "docx,pdf,txt,jpg,bmp,gif,xlsx,png,iso",
  100. "data-label" => "Faites glisser vos documents",
  101. "data-delete" => "contact_delete_document",
  102. "documents" => json_encode(example_document_setting())
  103. )),
  104. ));
  105. //Déclation des assets
  106. Plugin::addCss("/css/main.css");
  107. Plugin::addJs("/js/main.js");
  108. //Mapping hook / fonctions
  109. Plugin::addHook("install", "example_install");
  110. Plugin::addHook("uninstall", "example_uninstall");
  111. Plugin::addHook("section", "example_section");
  112. Plugin::addHook("menu_main", "example_menu");
  113. Plugin::addHook("page", "example_page");
  114. Plugin::addHook("action", "example_action");
  115. Plugin::addHook("menu_setting", "example_menu_setting");
  116. Plugin::addHook("content_setting", "example_content_setting");
  117. Plugin::addHook("menu_account", "example_menu_account");
  118. Plugin::addHook("content_account", "example_content_account");
  119. global $myFirm;
  120. if($myFirm->has_plugin('fr.sys1.export')){
  121. require_once(__ROOT__.PLUGIN_PATH.'export'.SLASH.'ExportModel.class.php');
  122. ExportModel::add('example','contact-sheet', 'Fiche contact', function($parameters){
  123. global $myUser;
  124. require_once(__DIR__.SLASH.'Contact.class.php');
  125. $contact = new Contact();
  126. if(isset($parameters['description']) && $parameters['description']!=true && !empty($parameters['id']))
  127. $contact = Contact::getById($parameters['id']);
  128. $data['contact'] = array('label'=>'Contact', 'type'=>'object','value' => array());
  129. $data['contact']['value']['libellé'] = array('label' => 'Libellé du contact','value' => $contact->label);
  130. $data['contact']['value']['téléphone'] = array('label' => 'N° de téléphone du contact','value' => $contact->phone);
  131. $data['contact']['value']['anniversaire'] = array('label' => 'Date de naissance/d\'anniversaire du contact','value' => date('d/m/Y',$contact->birth));
  132. $data['contact']['value']['identifiant'] = array('label' => 'Identifiant du contact','value'=>$contact->login);
  133. $data['contact']['value']['photo'] = array(
  134. 'label'=>'Image de profil du contact',
  135. 'type'=>'image',
  136. 'value' => file_get_contents($contact->get_image('path'))
  137. );
  138. return $data;
  139. });
  140. ExportModel::add('example','contact-list','Liste de contacts',function($parameters){
  141. global $myUser;
  142. require_once(__DIR__.SLASH.'Contact.class.php');
  143. $contacts = array(new Contact());
  144. if(isset($parameters['description']) && $parameters['description']!=true) $contacts = Contact::loadAll();
  145. $data['contacts'] = array('label'=>'Boucle sur les contacts', 'type'=>'list','value' => array());
  146. $data['contacts']['nombre'] = array('label' => 'Nombre de contacts au total', 'value' => count($contacts));
  147. foreach($contacts as $contact){
  148. $data['contacts']['value'][] = array(
  149. 'libellé' => array('label' => 'Libellé du contact' , 'value' => $contact->label ),
  150. 'téléphone' => array('label' => 'N° de téléphone du contact' , 'value' => $contact->phone ),
  151. 'anniversaire' => array('label' => 'Date de naissance/d\'anniversaire du contact' , 'value' => $contact->birth ),
  152. 'identifiant' => array('label' => 'Identifiant du contact' , 'value' => $contact->login ),
  153. 'photo' => array(
  154. 'label' => 'Image de profil du contact',
  155. 'type'=>'image' ,
  156. 'value' => file_get_contents($contact->get_image('path'))
  157. ),
  158. );
  159. }
  160. return $data;
  161. });
  162. }
  163. ?>