start.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. require_once __DIR__.'/../../main/inc/global.inc.php';
  3. $course_plugin = 'mobidico'; //needed in order to load the plugin lang variables
  4. $plugin = Mobidico::create();
  5. if ($plugin->get('tool_enable') !== 'true') {
  6. api_not_allowed(true);
  7. }
  8. $url = $plugin->get('mobidico_url');
  9. $key = $plugin->get('api_key');
  10. $tool_name = get_lang('Videoconference');
  11. $params = [
  12. 'chamiloid' => api_get_user_id(),
  13. 'API_KEY' => $key,
  14. ];
  15. $redirect = '';
  16. try {
  17. $client = new GuzzleHttp\Client();
  18. $response = $client->request(
  19. 'POST',
  20. $url.'/app/desktop/php/authenticate.php',
  21. [
  22. 'form_params' => $params,
  23. 'verify' => false,
  24. ]
  25. );
  26. $status = $response->getStatusCode();
  27. if ($status === 200) {
  28. $result = json_decode($response->getBody());
  29. if ($result && isset($result->status)) {
  30. if ($result->status == 'OK') {
  31. $redirect = $url.'/app/index.html?session='.$result->session;
  32. } else {
  33. api_not_allowed(true);
  34. }
  35. }
  36. }
  37. } catch (Exception $e) {
  38. echo $e->getMessage();
  39. }
  40. $htmlHeadXtra[] = '<script>
  41. $(document).ready(function() {
  42. var url = "'.$redirect.'";
  43. var win = window.open(url, "_blank");
  44. win.focus();
  45. });
  46. </script>';
  47. $tpl = new Template('Mobidico');
  48. $content = '';
  49. $tpl->assign('content', $content);
  50. $tpl->display_one_col_template();