action.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_iframe_auth_page':
  69. var_dump($_REQUEST);
  70. echo 'en construction :p';
  71. break;
  72. case 'rocketchat_iframe_auth':
  73. global $myUser;
  74. /*
  75. Necessite d'ajouter dans le htaccess :
  76. Header Set Access-Control-Allow-Origin "https://chat.sys1.fr"
  77. Header Set X-Frame-Options "ALLOWALL"
  78. Header add Access-Control-Allow-Credentials "true"
  79. Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
  80. Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
  81. */
  82. $response = array();
  83. file_put_contents(__DIR__.SLASH.'request.json', json_encode($_REQUEST, JSON_PRETTY_PRINT),FILE_APPEND);
  84. file_put_contents(__DIR__.SLASH.'request.json', json_encode($_FILES, JSON_PRETTY_PRINT),FILE_APPEND);
  85. file_put_contents(__DIR__.SLASH.'request.json', json_encode($_POST, JSON_PRETTY_PRINT),FILE_APPEND);
  86. file_put_contents(__DIR__.SLASH.'request.json', json_encode($_GET, JSON_PRETTY_PRINT),FILE_APPEND);
  87. file_put_contents(__DIR__.SLASH.'request.json', json_encode($_, JSON_PRETTY_PRINT),FILE_APPEND);
  88. //http_response_code(401);
  89. //exit();
  90. $response['token']= 1234;
  91. /*
  92. // otherwise create a rocket.chat session using rocket.chat's API
  93. axios.post('http://localhost:3000/api/v1/login', {
  94. username: 'username-set-previously',
  95. password: 'password-set-previously'
  96. }).then(function (response) {
  97. if (response.data.status === 'success') {
  98. res.json({
  99. loginToken: response.data.data.authToken
  100. });
  101. }
  102. }).catch(function() {
  103. res.sendStatus(401);
  104. });
  105. */
  106. header('application/json');
  107. echo json_encode($response);
  108. break;
  109. case 'rocketchat_widget_load':
  110. global $myUser;
  111. require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
  112. $widget = DashboardWidget::current();
  113. $widget->title = 'Widget Rocketchat';
  114. ob_start();
  115. //Décommenter après avoir créé widget.php
  116. require_once(__DIR__.SLASH.'widget.php');
  117. $widget->content = ob_get_clean();
  118. echo json_encode($widget);
  119. break;
  120. case 'rocketchat_widget_rocketchat_configure':
  121. global $myUser;
  122. require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
  123. $widget = DashboardWidget::current();
  124. ob_start();
  125. require_once(__DIR__.SLASH.'widget.configure.php');
  126. $content = ob_get_clean();
  127. echo $content ;
  128. break;
  129. case 'rocketchat_widget_rocketchat_configure_save':
  130. Action::write(function(&$response){
  131. global $myUser,$_;
  132. require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
  133. $widget = DashboardWidget::getById($_['id']);
  134. $widget->data('chan',$_['widget-rocketchat-chan']);
  135. $widget->save();
  136. });
  137. break;
  138. }
  139. ?>