123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- global $_,$conf;
- switch($_['action']){
- /** CHAT **/
- //Récuperation d'une liste de chat
- case 'rocketchat_chat_search':
- Action::write(function(&$response){
- global $myUser,$_;
- User::check_access('rocketchat','read');
- require_once(__DIR__.SLASH.'Chat.class.php');
-
- // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
- $query = 'SELECT * FROM '.Chat::tableName().' WHERE 1';
- $data = array();
- //Recherche simple
- if(!empty($_['filters']['keyword'])){
- $query .= ' AND label LIKE ?';
- $data[] = '%'.$_['filters']['keyword'].'%';
- }
- //Recherche avancée
- if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('label'),$query,$data);
- //Tri des colonnes
- if(isset($_['sort'])) sort_secure_query($_['sort'],array('label'),$query,$data);
- //Pagination
- $response['pagination'] = Chat::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
- $chats = Chat::staticQuery($query,$data,true,0);
-
- foreach($chats as $chat){
- $row = $chat->toArray();
- $response['rows'][] = $row;
- }
-
- });
- break;
-
- //Ajout ou modification d'élément chat
- case 'rocketchat_chat_save':
- Action::write(function(&$response){
- global $myUser,$_;
- User::check_access('rocketchat','edit');
- require_once(__DIR__.SLASH.'Chat.class.php');
- $item = Chat::provide();
- $item->save();
- });
- break;
-
-
- //Suppression d'élement chat
- case 'rocketchat_chat_delete':
- Action::write(function(&$response){
- global $myUser,$_;
- User::check_access('rocketchat','delete');
- require_once(__DIR__.SLASH.'Chat.class.php');
- Chat::deleteById($_['id']);
-
- });
- break;
-
- //Sauvegarde des configurations de rocketchat
- case 'rocketchat_setting_save':
- Action::write(function(&$response){
- global $myUser,$_,$conf;
- User::check_access('rocketchat','configure');
- //Si input file "multiple", possibilité de normlaiser le
- //tableau $_FILES récupéré avec la fonction => normalize_php_files();
-
- foreach(Configuration::setting('rocketchat') as $key=>$value){
- if(!is_array($value)) continue;
- $allowed[] = $key;
- }
- foreach ($_['fields'] as $key => $value) {
- if(in_array($key, $allowed))
- $conf->put($key,$value);
- }
- });
- break;
- case 'rocketchat_iframe_auth_page':
- var_dump($_REQUEST);
- echo 'en construction :p';
- break;
- case 'rocketchat_iframe_auth':
- global $myUser;
- /*
- Necessite d'ajouter dans le htaccess :
- Header Set Access-Control-Allow-Origin "https://chat.sys1.fr"
- Header Set X-Frame-Options "ALLOWALL"
- Header add Access-Control-Allow-Credentials "true"
- Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
- Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
- */
- $response = array();
- file_put_contents(__DIR__.SLASH.'request.json', json_encode($_REQUEST, JSON_PRETTY_PRINT),FILE_APPEND);
- file_put_contents(__DIR__.SLASH.'request.json', json_encode($_FILES, JSON_PRETTY_PRINT),FILE_APPEND);
- file_put_contents(__DIR__.SLASH.'request.json', json_encode($_POST, JSON_PRETTY_PRINT),FILE_APPEND);
- file_put_contents(__DIR__.SLASH.'request.json', json_encode($_GET, JSON_PRETTY_PRINT),FILE_APPEND);
- file_put_contents(__DIR__.SLASH.'request.json', json_encode($_, JSON_PRETTY_PRINT),FILE_APPEND);
-
- //http_response_code(401);
- //exit();
- $response['token']= 1234;
- /*
- // otherwise create a rocket.chat session using rocket.chat's API
- axios.post('http://localhost:3000/api/v1/login', {
- username: 'username-set-previously',
- password: 'password-set-previously'
- }).then(function (response) {
- if (response.data.status === 'success') {
- res.json({
- loginToken: response.data.data.authToken
- });
- }
- }).catch(function() {
- res.sendStatus(401);
- });
- */
- header('application/json');
- echo json_encode($response);
- break;
-
- case 'rocketchat_widget_load':
- global $myUser;
- require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
- $widget = DashboardWidget::current();
- $widget->title = 'Widget Rocketchat';
- ob_start();
- //Décommenter après avoir créé widget.php
- require_once(__DIR__.SLASH.'widget.php');
- $widget->content = ob_get_clean();
-
- echo json_encode($widget);
- break;
-
- case 'rocketchat_widget_rocketchat_configure':
- global $myUser;
- require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
- $widget = DashboardWidget::current();
- ob_start();
- require_once(__DIR__.SLASH.'widget.configure.php');
- $content = ob_get_clean();
- echo $content ;
- break;
- case 'rocketchat_widget_rocketchat_configure_save':
- Action::write(function(&$response){
- global $myUser,$_;
- require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
- $widget = DashboardWidget::getById($_['id']);
- $widget->data('chan',$_['widget-rocketchat-chan']);
- $widget->save();
- });
- break;
- }
- ?>
|