start.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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();