action.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /** CHAT **/
  3. //Récuperation d'une liste de chat
  4. Action::register('rocketchat_chat_search',function(&$response){
  5. global $myUser,$_;
  6. User::check_access('rocketchat','read');
  7. require_once(__DIR__.SLASH.'Chat.class.php');
  8. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  9. $query = 'SELECT * FROM '.Chat::tableName().' WHERE 1';
  10. $data = array();
  11. //Recherche simple
  12. if(!empty($_['filters']['keyword'])){
  13. $query .= ' AND label LIKE ?';
  14. $data[] = '%'.$_['filters']['keyword'].'%';
  15. }
  16. //Recherche avancée
  17. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('label'),$query,$data);
  18. //Tri des colonnes
  19. if(isset($_['sort'])) sort_secure_query($_['sort'],array('label'),$query,$data);
  20. //Pagination
  21. $response['pagination'] = Chat::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
  22. $chats = Chat::staticQuery($query,$data,true,0);
  23. foreach($chats as $chat){
  24. $row = $chat->toArray();
  25. $response['rows'][] = $row;
  26. }
  27. });
  28. //Ajout ou modification d'élément chat
  29. Action::register('rocketchat_chat_save',function(&$response){
  30. global $myUser,$_;
  31. User::check_access('rocketchat','edit');
  32. require_once(__DIR__.SLASH.'Chat.class.php');
  33. $item = Chat::provide();
  34. $item->save();
  35. });
  36. //Suppression d'élement chat
  37. Action::register('rocketchat_chat_delete',function(&$response){
  38. global $myUser,$_;
  39. User::check_access('rocketchat','delete');
  40. require_once(__DIR__.SLASH.'Chat.class.php');
  41. Chat::deleteById($_['id']);
  42. });
  43. //Sauvegarde des configurations de rocketchat
  44. Action::register('rocketchat_setting_save',function(&$response){
  45. global $myUser,$_,$conf;
  46. User::check_access('rocketchat','configure');
  47. //Si input file "multiple", possibilité de normlaiser le
  48. //tableau $_FILES récupéré avec la fonction => normalize_php_files();
  49. foreach(Configuration::setting('rocketchat') as $key=>$value){
  50. if(!is_array($value)) continue;
  51. $allowed[] = $key;
  52. }
  53. foreach ($_['fields'] as $key => $value) {
  54. if(in_array($key, $allowed))
  55. $conf->put($key,$value);
  56. }
  57. });
  58. Action::register('rocketchat_widget_load',function(&$response){
  59. global $myUser;
  60. User::check_access('rocketchat','read');
  61. require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
  62. $widget = DashboardWidget::current();
  63. $widget->title = 'Widget Rocketchat';
  64. ob_start();
  65. //Décommenter après avoir créé widget.php
  66. require_once(__DIR__.SLASH.'widget.php');
  67. $widget->content = ob_get_clean();
  68. echo json_encode($widget);
  69. exit();
  70. });
  71. Action::register('rocketchat_widget_rocketchat_configure',function(&$response){
  72. global $myUser;
  73. User::check_access('rocketchat','read');
  74. require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
  75. $widget = DashboardWidget::current();
  76. ob_start();
  77. require_once(__DIR__.SLASH.'widget.configure.php');
  78. $content = ob_get_clean();
  79. echo $content ;
  80. exit();
  81. });
  82. Action::register('rocketchat_widget_rocketchat_configure_save',function(&$response){
  83. global $myUser,$_;
  84. User::check_access('rocketchat','read');
  85. require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
  86. $widget = DashboardWidget::getById($_['id']);
  87. $widget->data('chan',$_['widget-rocketchat-chan']);
  88. $widget->save();
  89. });
  90. ?>