form.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\UserBundle\Entity\User;
  4. use Chamilo\CoreBundle\Entity\Course;
  5. require_once __DIR__.'/../../main/inc/global.inc.php';
  6. require './OAuthSimple.php';
  7. api_protect_course_script();
  8. $toolId = isset($_GET['id']) ? intval($_GET['id']) : 0;
  9. $em = Database::getManager();
  10. /** @var ImsLtiPlugin $imsLtiPlugin */
  11. $imsLtiPlugin = ImsLtiPlugin::create();
  12. /** @var ImsLtiTool $tool */
  13. $tool = ImsLtiTool::fetch($toolId);
  14. /** @var Course $course */
  15. $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
  16. /** @var User $user */
  17. $user = $em->find('ChamiloUserBundle:User', api_get_user_id());
  18. $siteName = api_get_setting('siteName');
  19. $institution = api_get_setting('Institution');
  20. $toolUserId = "$siteName - $institution - {$user->getId()}";
  21. $toolUserId = api_replace_dangerous_char($toolUserId);
  22. $params = [
  23. 'lti_message_type' => 'basic-lti-launch-request',
  24. 'lti_version' => 'LTI-1p0',
  25. 'resource_link_id' => $tool->getId(),
  26. 'resource_link_title' => $tool->getName(),
  27. 'user_id' => $toolUserId,
  28. 'roles' => api_is_teacher() ? 'Instructor' : 'Student',
  29. 'lis_person_name_given' => $user->getFirstname(),
  30. 'lis_person_name_family' => $user->getLastname(),
  31. 'lis_person_name_full' => $user->getCompleteName(),
  32. 'lis_person_contact_email_primary' => $user->getEmail(),
  33. 'context_id' => $course->getId(),
  34. 'context_label' => $course->getCode(),
  35. 'context_title' => $course->getTitle(),
  36. 'launch_presentation_locale' => api_get_language_isocode(),
  37. 'launch_presentation_document_target' => 'embed',
  38. 'tool_consumer_info_product_family_code' => 'Chamilo LMS',
  39. 'tool_consumer_info_version' => api_get_version(),
  40. 'tool_consumer_instance_guid' => api_get_setting('InstitutionUrl'),
  41. 'tool_consumer_instance_name' => $siteName,
  42. 'tool_consumer_instance_url' => api_get_path(WEB_PATH),
  43. 'tool_consumer_instance_contact_email' => api_get_setting('emailAdministrator'),
  44. 'resource_link_description' => 'A quick revision PowerPoint about the Water cycle. Make sure you\'re clear about it!',
  45. ];
  46. $oauth = new OAuthSimple(
  47. $tool->getConsumerKey(),
  48. $tool->getSharedSecret()
  49. );
  50. $oauth->setAction('post');
  51. $oauth->setSignatureMethod('HMAC-SHA1');
  52. $oauth->setParameters($params);
  53. $result = $oauth->sign(array(
  54. 'path' => $tool->getLaunchUrl(),
  55. 'parameters' => array(
  56. 'oauth_callback' => 'about:blank'
  57. )
  58. ));
  59. ?>
  60. <!DOCTYPE html>
  61. <html>
  62. <head>
  63. <title>title</title>
  64. </head>
  65. <body>
  66. <form action="<?php echo $result['signed_url'] ?>" name="ltiLaunchForm" method="post" encType="application/x-www-form-urlencoded">
  67. <input type="submit" value="Press to continue to external tool"/>
  68. </form>
  69. <script language="javascript">
  70. document.ltiLaunchForm.submit();
  71. </script>
  72. </body>
  73. </html>