From 3d274cba87792b7ddbfa3c940f05ecd347327d52 Mon Sep 17 00:00:00 2001
From: Hanne Moa <hanne.moa@uninett.no>
Date: Tue, 4 Oct 2016 10:58:26 +0200
Subject: [PATCH] Move faventry-discovery to calling page

For #485
---
 modules/discopower/lib/PowerIdPDisco.php   |  7 +++++++
 modules/discopower/templates/disco.tpl.php | 24 ++++++----------------
 2 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/modules/discopower/lib/PowerIdPDisco.php b/modules/discopower/lib/PowerIdPDisco.php
index 7a1d8b592..0cfba1369 100644
--- a/modules/discopower/lib/PowerIdPDisco.php
+++ b/modules/discopower/lib/PowerIdPDisco.php
@@ -246,6 +246,12 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco
         $idpList = $this->getIdPList();
         $idpList = $this->idplistStructured($this->filterList($idpList));
         $preferredIdP = $this->getRecommendedIdP();
+        $faventry = NULL;
+        foreach ($idpList AS $tab => $slist) {
+            if (!empty($preferredIdP) && array_key_exists($preferredIdP, $slist)) {
+                $faventry = $slist[$preferredIdP]];
+            }
+        }
 
         $t = new SimpleSAML_XHTML_Template($this->config, 'discopower:disco.tpl.php', 'disco');
         $discoPowerTabs = array(
@@ -262,6 +268,7 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco
             'switzerland' => $t->noop('{discopower:tabs:switzerland}'),
             'ukacessfederation' => $t->noop('{discopower:tabs:ukacessfederation}'),
         );
+        $t->data['faventry'] = $faventry;
         $t->data['tabNames'] = $discoPowerTabs;
         $t->data['idplist'] = $idpList;
         $t->data['preferredidp'] = $preferredIdP;
diff --git a/modules/discopower/templates/disco.tpl.php b/modules/discopower/templates/disco.tpl.php
index 2e9afd681..4e1bf6c42 100644
--- a/modules/discopower/templates/disco.tpl.php
+++ b/modules/discopower/templates/disco.tpl.php
@@ -1,17 +1,5 @@
 <?php
 
-
-$faventry = NULL;
-foreach( $this->data['idplist'] AS $tab => $slist) {
-	if (!empty($this->data['preferredidp']) && array_key_exists($this->data['preferredidp'], $slist))
-		$faventry = $slist[$this->data['preferredidp']];
-}
-
-
-
-
-
-
 if(!array_key_exists('header', $this->data)) {
 	$this->data['header'] = 'selectidp';
 }
@@ -31,7 +19,7 @@ $(document).ready(function() {
 $i = 0;
 foreach ($this->data['idplist'] AS $tab => $slist) {
 	$this->data['head'] .= "\n" . '$("#query_' . $tab . '").liveUpdate("#list_' . $tab . '")' .
-		(($i++ == 0) && (empty($faventry)) ? '.focus()' : '') .
+		(($i++ == 0) && (empty($this->data['faventry'])) ? '.focus()' : '') .
 		';';
 
 
@@ -46,7 +34,7 @@ $this->data['head'] .= '
 
 
 
-if (!empty($faventry)) $this->data['autofocus'] = 'favouritesubmit';
+if (!empty($this->data['faventry'])) $this->data['autofocus'] = 'favouritesubmit';
 
 $this->includeAtTemplateBase('includes/header.php');
 
@@ -101,20 +89,20 @@ function getTranslatedName($t, $metadata) {
 
 
 
-if (!empty($faventry)) {
+if (!empty($this->data['faventry'])) {
 
 
 	echo('<div class="favourite">');
 	echo($this->t('previous_auth'));
-	echo(' <strong>' . htmlspecialchars(getTranslatedName($this, $faventry)) . '</strong>');
+	echo(' <strong>' . htmlspecialchars(getTranslatedName($this, $this->data['faventry'])) . '</strong>');
 	echo('
 	<form id="idpselectform" method="get" action="' . $this->data['urlpattern'] . '">
 		<input type="hidden" name="entityID" value="' . htmlspecialchars($this->data['entityID']) . '" />
 		<input type="hidden" name="return" value="' . htmlspecialchars($this->data['return']) . '" />
 		<input type="hidden" name="returnIDParam" value="' . htmlspecialchars($this->data['returnIDParam']) . '" />
-		<input type="hidden" name="idpentityid" value="' . htmlspecialchars($faventry['entityid']) . '" />
+		<input type="hidden" name="idpentityid" value="' . htmlspecialchars($this->data['faventry']['entityid']) . '" />
 
-		<input type="submit" name="formsubmit" id="favouritesubmit" value="' . $this->t('login_at') . ' ' . htmlspecialchars(getTranslatedName($this, $faventry)) . '" /> 
+		<input type="submit" name="formsubmit" id="favouritesubmit" value="' . $this->t('login_at') . ' ' . htmlspecialchars(getTranslatedName($this, $this->data['faventry'])) . '" /> 
 	</form>');
 
 	echo('</div>');
-- 
GitLab