directory.plugin.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. require_once(__DIR__.SLASH.'QRCode.class.php');
  3. function directory_plugin_menu(&$accountMenu){
  4. global $_, $myUser;
  5. if(!$myUser->connected()) throw new Exception('Vous devez être connecté pour accéder à cette fonctionnalité',401);
  6. $accountMenu[]= array(
  7. 'sort' =>1,
  8. 'url' => 'account.php?section=directory',
  9. 'icon' => 'fas fa-angle-right',
  10. 'label' => 'Annuaire',
  11. );
  12. }
  13. function directory_get_contacts(){
  14. $users = User::getAll();
  15. $userMapping = array();
  16. foreach ($users as $user) {
  17. $userMapping[$user->login] = array(
  18. 'object'=>$user,
  19. 'values' => array(
  20. 'Nom' => strtoupper($user->name).' '.$user->firstname,
  21. 'Email' => '<a href="mailto:'.$user->mail.'">'.$user->mail.'</a>',
  22. 'Fixe' => '<a href="tel: '.$user->phone.'">'.$user->phone.'</a>',
  23. 'Portable (pro)' => '<a href="tel: '.$user->mobile.'">'.$user->mobile.'</a>'
  24. )
  25. );
  26. }
  27. Plugin::callHook('directory_list',array(&$userMapping));
  28. $columns = array();
  29. $reference = array();
  30. foreach ($userMapping as $infos) {
  31. if(isset($infos['values']) && count($infos['values']) > count($reference)) $reference = $infos['values'];
  32. }
  33. if(!empty($reference)) $columns = array_keys($reference);
  34. //Tri par ordre alphabétique
  35. uasort($userMapping, function($a, $b){
  36. return strcmp($a['object']->name, $b['object']->name);
  37. });
  38. return array($columns,$userMapping);
  39. }
  40. //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
  41. require_once(__DIR__.SLASH.'action.php');
  42. function directory_plugin_page(){
  43. global $myUser,$_;
  44. if(!isset($_['section']) || $_['section']!='directory') return;
  45. if($myUser!=false){
  46. list($columns,$userMapping) = directory_get_contacts();
  47. ?>
  48. <div class="tab-pane fade show active">
  49. <h3>Annuaire</h3>
  50. <p>Annuaire de la société</p>
  51. <hr>
  52. <a type="btn" href="action.php?action=directory_get_excel" class="btn btn-primary" title="Excel"><i class="far fa-file-excel"></i> Exporter l'annuaire (.csv)</a>
  53. <br/><br/>
  54. <table class="table table-striped table-bordered table-hover">
  55. <thead>
  56. <tr>
  57. <?php foreach($columns as $column): ?>
  58. <th><?php echo $column; ?></th>
  59. <?php endforeach; ?>
  60. <th>Action</th>
  61. </tr>
  62. </thead>
  63. <?php foreach($userMapping as $infos){
  64. $user = $infos['object'];
  65. if($user->origin != ''){
  66. ?>
  67. <tr data-user="<?php echo $user->login; ?>">
  68. <?php foreach($columns as $column): ?>
  69. <td><?php echo isset($infos['values'][$column])?$infos['values'][$column]:''; ?></td>
  70. <?php endforeach; ?>
  71. <td>
  72. <a type="btn" target="_blank" href="action.php?action=directory_get_qr&amp;user=<?php echo $user->login; ?>" class="btn btn-primary btn-sm" title="QR Code"><i class="fas fa-qrcode"></i></a>
  73. <a type="btn" href="action.php?action=directory_get_cardav&amp;user=<?php echo $user->login; ?>" class="btn btn-primary btn-sm" title="Cardav"><i class="far fa-address-card"></i></a>
  74. <?php if(Plugin::is_active('fr.core.sms')): ?>
  75. <div onclick="directory_send_sms(this)" class="btn btn-primary btn-sm" title="Me l'envoyer par sms"><i class="fas fa-sms"></i></div>
  76. <?php endif; ?>
  77. </td>
  78. </tr>
  79. <?php
  80. }
  81. } ?>
  82. </table>
  83. </div>
  84. <?php } else { ?>
  85. <div id="main" class="wrapper clearfix">
  86. <article>
  87. <h3>Vous devez être connecté</h3>
  88. </article>
  89. </div>
  90. <?php }
  91. }
  92. Plugin::addJs("/js/main.js");
  93. Plugin::addHook("menu_account", "directory_plugin_menu");
  94. Plugin::addHook("content_account", "directory_plugin_page");
  95. ?>