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; } ?>