form.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Session;
  4. use Chamilo\UserBundle\Entity\User;
  5. use Chamilo\CoreBundle\Entity\Course;
  6. use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
  7. require_once __DIR__.'/../../main/inc/global.inc.php';
  8. require './OAuthSimple.php';
  9. api_protect_course_script(false);
  10. api_block_anonymous_users(false);
  11. $em = Database::getManager();
  12. /** @var ImsLtiTool $tool */
  13. $tool = isset($_GET['id']) ? $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', intval($_GET['id'])) : 0;
  14. if (!$tool) {
  15. api_not_allowed(true);
  16. }
  17. /** @var ImsLtiPlugin $imsLtiPlugin */
  18. $imsLtiPlugin = ImsLtiPlugin::create();
  19. /** @var Session $session */
  20. $session = $em->find('ChamiloCoreBundle:Session', api_get_session_id());
  21. /** @var Course $course */
  22. $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
  23. /** @var User $user */
  24. $user = $em->find('ChamiloUserBundle:User', api_get_user_id());
  25. $siteName = api_get_setting('siteName');
  26. $toolUserId = ImsLtiPlugin::generateToolUserId($user);
  27. $params = [];
  28. $params['lti_version'] = 'LTI-1p0';
  29. if ($tool->isActiveDeepLinking()) {
  30. $params['lti_message_type'] = 'ContentItemSelectionRequest';
  31. $params['content_item_return_url'] = api_get_path(WEB_PLUGIN_PATH).'ims_lti/item_return.php';
  32. $params['accept_media_types'] = '*/*';
  33. $params['accept_presentation_document_targets'] = 'iframe';
  34. //$params['accept_unsigned'];
  35. //$params['accept_multiple'];
  36. //$params['accept_copy_advice'];
  37. //$params['auto_create']';
  38. $params['title'] = $tool->getName();
  39. $params['text'] = $tool->getDescription();
  40. $params['data'] = 'tool:'.$tool->getId();
  41. } else {
  42. $params['lti_message_type'] = 'basic-lti-launch-request';
  43. $params['resource_link_id'] = $tool->getId();
  44. $params['resource_link_title'] = $tool->getName();
  45. $params['resource_link_description'] = $tool->getDescription();
  46. }
  47. $params['user_id'] = ImsLtiPlugin::generateToolUserId($user->getId());
  48. $params['user_image'] = UserManager::getUserPicture($user->getId());
  49. $params['roles'] = ImsLtiPlugin::getUserRoles($user);
  50. $params['lis_person_name_given'] = $user->getFirstname();
  51. $params['lis_person_name_family'] = $user->getLastname();
  52. $params['lis_person_name_full'] = $user->getCompleteName();
  53. $params['lis_person_contact_email_primary'] = $user->getEmail();
  54. if (api_is_allowed_to_edit(false, true)) {
  55. $params['role_scope_mentor'] = ImsLtiPlugin::getRoleScopeMentor($course, $session);
  56. }
  57. $params['context_id'] = $course->getId();
  58. $params['context_type'] = 'CourseSection';
  59. $params['context_label'] = $course->getCode();
  60. $params['context_title'] = $course->getTitle();
  61. $params['launch_presentation_locale'] = api_get_language_isocode();
  62. $params['launch_presentation_document_target'] = 'iframe';
  63. $params['tool_consumer_info_product_family_code'] = 'Chamilo LMS';
  64. $params['tool_consumer_info_version'] = api_get_version();
  65. $params['tool_consumer_instance_guid'] = str_replace(['https://', 'http://'], '', api_get_setting('InstitutionUrl'));
  66. $params['tool_consumer_instance_name'] = $siteName;
  67. $params['tool_consumer_instance_url'] = api_get_path(WEB_PATH);
  68. $params['tool_consumer_instance_contact_email'] = api_get_setting('emailAdministrator');
  69. $oauth = new OAuthSimple(
  70. $tool->getConsumerKey(),
  71. $tool->getSharedSecret()
  72. );
  73. $oauth->setAction('post');
  74. $oauth->setSignatureMethod('HMAC-SHA1');
  75. $oauth->setParameters($params);
  76. $result = $oauth->sign(array(
  77. 'path' => $tool->getLaunchUrl(),
  78. 'parameters' => array(
  79. 'oauth_callback' => 'about:blank'
  80. )
  81. ));
  82. ?>
  83. <!DOCTYPE html>
  84. <html>
  85. <head>
  86. <title>title</title>
  87. </head>
  88. <body>
  89. <form action="<?php echo $tool->getLaunchUrl() ?>" name="ltiLaunchForm" method="post"
  90. encType="application/x-www-form-urlencoded">
  91. <?php
  92. foreach ($result["parameters"] as $key => $values) { //Dump parameters
  93. echo '<input type="hidden" name="'.$key.'" value="'.$values.'" />';
  94. }
  95. ?>
  96. <button type="submit">
  97. <?php echo $imsLtiPlugin->get_lang('PressToContinue') ?>
  98. </button>
  99. </form>
  100. <script language="javascript">
  101. document.querySelector('form [type="submit"]').style.display = "none";
  102. document.ltiLaunchForm.submit();
  103. </script>
  104. </body>
  105. </html>