action.php 3.4 KB

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