From fd3a3c25e7b6ecd1ba6edffa105a9e91133fac19 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Mon, 6 Nov 2023 12:24:54 +0000
Subject: [PATCH] fixes #3428

Closes #3428

Merge request studip/studip!2330
---
 app/controllers/course/lti.php  | 11 +++++++----
 app/views/course/lti/iframe.php |  7 +++++++
 app/views/course/lti/index.php  | 29 +++++++++++++++--------------
 lib/models/LtiData.php          |  2 ++
 4 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/app/controllers/course/lti.php b/app/controllers/course/lti.php
index 28bf218b848..7f182922ed1 100644
--- a/app/controllers/course/lti.php
+++ b/app/controllers/course/lti.php
@@ -78,11 +78,14 @@ class Course_LtiController extends StudipController
     /**
      * Display the launch form for a tool as an iframe.
      */
-    public function iframe_action()
+    public function iframe_action(string $position)
     {
-        $this->launch_url  = Request::get('launch_url');
-        $this->launch_data = Request::getArray('launch_data');
-        $this->signature   = Request::get('signature');
+        $lti_data = LtiData::findByCourseAndPosition($this->course_id, $position);
+        $lti_link = $this->getLtiLink($lti_data);
+
+        $this->launch_url = $lti_data->getLaunchURL();
+        $this->launch_data = $lti_link->getBasicLaunchData();
+        $this->signature = $lti_link->getLaunchSignature($this->launch_data);
 
         $this->set_layout(null);
     }
diff --git a/app/views/course/lti/iframe.php b/app/views/course/lti/iframe.php
index cd73efda47f..1cd0d2c53c7 100644
--- a/app/views/course/lti/iframe.php
+++ b/app/views/course/lti/iframe.php
@@ -1,3 +1,10 @@
+<?php
+/**
+ * @var string $launch_url
+ * @var array $launch_data
+ * @var string $signature
+ */
+?>
 <!DOCTYPE html>
 <html>
 <head>
diff --git a/app/views/course/lti/index.php b/app/views/course/lti/index.php
index e04e3bf3349..df1696bee4f 100644
--- a/app/views/course/lti/index.php
+++ b/app/views/course/lti/index.php
@@ -1,14 +1,16 @@
+<?php
+/**
+ * @var Course_LtiController $controller
+ * @var LtiData[] $lti_data_array
+ * @var bool $edit_perm
+ */
+?>
 <? if (empty($lti_data_array)): ?>
     <?= MessageBox::info(_('Es wurden noch keine Inhalte angelegt.')) ?>
 <? endif ?>
 
 <? foreach ($lti_data_array as $lti_data): ?>
     <? $launch_url = $lti_data->getLaunchURL() ?>
-    <? if ($launch_url): ?>
-        <? $lti_link = $controller->getLtiLink($lti_data) ?>
-        <? $launch_data = $lti_link->getBasicLaunchData() ?>
-        <? $signature = $lti_link->getLaunchSignature($launch_data) ?>
-    <? endif ?>
 
     <article class="studip">
         <header>
@@ -47,20 +49,19 @@
         <section>
             <?= formatReady($lti_data->description) ?>
 
-            <? if ($launch_url && $lti_data->options['document_target'] == 'iframe'): ?>
+            <? if ($launch_url && $lti_data->options['document_target'] === 'iframe'): ?>
                 <iframe style="border: none; height: 640px; width: 100%;"
-                        src="<?= $controller->link_for('course/lti/iframe', compact('launch_url', 'launch_data', 'signature')) ?>"></iframe>
+                        src="<?= $controller->link_for('course/lti/iframe', $lti_data->position) ?>"></iframe>
             <? endif ?>
         </section>
 
-        <? if ($launch_url && $lti_data->options['document_target'] != 'iframe'): ?>
+        <? if ($launch_url && $lti_data->options['document_target'] !== 'iframe'): ?>
             <footer>
-                <form class="default" action="<?= htmlReady($launch_url) ?>" method="post" target="_blank">
-                    <? foreach ($launch_data as $key => $value): ?>
-                        <input type="hidden" name="<?= htmlReady($key) ?>" value="<?= htmlReady($value, false) ?>">
-                    <? endforeach ?>
-                    <?= Studip\Button::create(_('Anwendung starten'), 'oauth_signature', ['value' => $signature]) ?>
-                </form>
+                <?= Studip\LinkButton::create(
+                    _('Anwendung starten'),
+                    $controller->link_for('course/lti/iframe', $lti_data->position),
+                    ['target' => '_blank']
+                ) ?>
             </footer>
         <? endif ?>
     </article>
diff --git a/lib/models/LtiData.php b/lib/models/LtiData.php
index 2f0a08d41a1..e991b6aab8f 100644
--- a/lib/models/LtiData.php
+++ b/lib/models/LtiData.php
@@ -42,6 +42,8 @@ class LtiData extends SimpleORMap
 
     /**
      * Find a single entry by course_id and position.
+     *
+     * @return static|null
      */
     public static function findByCourseAndPosition($course_id, $position)
     {
-- 
GitLab