From b89d854d9a64bda93b9b42a93ee1a6447f64cd4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= <jschneider@entrouvert.com>
Date: Wed, 22 Oct 2014 16:18:32 +0200
Subject: [PATCH 1/3] Factorise saml tabs in a function

---
 etc/inc/captiveportal_saml.inc                         | 18 ++++++++++++++++++
 .../www/services_captiveportal_saml_federation.php     | 12 ++----------
 usr/local/www/services_captiveportal_saml_sp.php       | 11 ++---------
 .../www/services_captiveportal_saml_whitelist.php      | 10 ++--------
 4 files changed, 24 insertions(+), 27 deletions(-)
 create mode 100644 etc/inc/captiveportal_saml.inc

diff --git a/etc/inc/captiveportal_saml.inc b/etc/inc/captiveportal_saml.inc
new file mode 100644
index 0000000..ad8b9f6
--- /dev/null
+++ b/etc/inc/captiveportal_saml.inc
@@ -0,0 +1,18 @@
+<?php
+
+function display_saml_tabs($file_name) {
+    $tab_array = array();
+    $tab_array[] = array(gettext("Service provider"), false, "services_captiveportal_saml_sp.php");
+    # $tab_array[] = array(gettext("Identity provider"), false, "services_captiveportal_saml_idp.php");
+    $tab_array[] = array(gettext("Federations"), false, "services_captiveportal_saml_federation.php");
+    $tab_array[] = array(gettext("Whitelists"), false, "services_captiveportal_saml_whitelist.php");
+    $tab_array[] = array(gettext("Blacklists"), false, "services_captiveportal_saml_blacklist.php");
+    for ($i = 0; $i < sizeof($tab_array); $i++) {
+        if ($tab_array[$i][2] == $file_name) {
+            $tab_array[$i][1] = true;
+        }
+    }
+    display_top_tabs($tab_array);
+}
+
+?>
diff --git a/usr/local/www/services_captiveportal_saml_federation.php b/usr/local/www/services_captiveportal_saml_federation.php
index 6b0ab94..d2ad602 100755
--- a/usr/local/www/services_captiveportal_saml_federation.php
+++ b/usr/local/www/services_captiveportal_saml_federation.php
@@ -38,6 +38,7 @@
 ##|-PRIV
 
 require("guiconfig.inc");
+require_once("captiveportal_saml.inc");
 require_once("certs.inc");
 
 $pgtitle = array(gettext("Service"), gettext("Captive portal"),"SAML 2.0 Federations");
@@ -197,16 +198,7 @@ include("head.inc");
 
 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="CA manager">
 	<tr>
-		<td>
-		<?php
-			$tab_array = array();
-			$tab_array[] = array(gettext("Service provider"), false, "services_captiveportal_saml_sp.php");
-			# $tab_array[] = array(gettext("Identity provider"), false, "services_captiveportal_saml_idp.php");
-			$tab_array[] = array(gettext("Federations"), true, "services_captiveportal_saml_federation.php");
-			$tab_array[] = array(gettext("Whitelists"), false, "services_captiveportal_saml_whitelist.php");
-			display_top_tabs($tab_array);
-		?>
-		</td>
+		<td><?php display_saml_tabs(basename(__FILE__));  ?></td>
 	</tr>
 	<tr>
 		<td id="mainarea">
diff --git a/usr/local/www/services_captiveportal_saml_sp.php b/usr/local/www/services_captiveportal_saml_sp.php
index 8537e53..4a255cb 100755
--- a/usr/local/www/services_captiveportal_saml_sp.php
+++ b/usr/local/www/services_captiveportal_saml_sp.php
@@ -44,6 +44,7 @@ require_once("functions.inc");
 require_once("filter.inc");
 require_once("shaper.inc");
 require_once("captiveportal.inc");
+require_once("captiveportal_saml.inc");
 
 if (!is_array($config['captiveportal']))
 	$config['captiveportal'] = array();
@@ -109,15 +110,7 @@ include("head.inc");
 <form action="services_captiveportal_saml_sp.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
 
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
-  <tr><td class="tabnavtbl">
-<?php
-	$tab_array = array();
-	$tab_array[] = array(gettext("Service provider"), true, "services_captiveportal_saml_sp.php");
-	# $tab_array[] = array(gettext("Identity provider"), false, "services_captiveportal_saml_idp.php");
-	$tab_array[] = array(gettext("Federations"), false, "services_captiveportal_saml_federation.php");
-	$tab_array[] = array(gettext("Whitelists"), false, "services_captiveportal_saml_whitelist.php");
-	display_top_tabs($tab_array, true);
-?>    </td></tr>
+  <tr><td class="tabnavtbl"><?php display_saml_tabs(basename(__FILE__)); ?></td></tr>
   <tr>
   <td class="tabcont">
   <table width="100%" border="0" cellpadding="6" cellspacing="0">
diff --git a/usr/local/www/services_captiveportal_saml_whitelist.php b/usr/local/www/services_captiveportal_saml_whitelist.php
index df1f45a..fe758fa 100755
--- a/usr/local/www/services_captiveportal_saml_whitelist.php
+++ b/usr/local/www/services_captiveportal_saml_whitelist.php
@@ -39,6 +39,7 @@
 
 require("guiconfig.inc");
 require_once("certs.inc");
+require_once("captiveportal_saml.inc");
 
 $pgtitle = array(gettext("Service"), gettext("Captive portal"),"SAML 2.0 Whitelists");
 $shortcut_section = "captiveportal";
@@ -189,14 +190,7 @@ include("head.inc");
 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="CA manager">
 	<tr>
 		<td>
-		<?php
-			$tab_array = array();
-			$tab_array[] = array(gettext("Service provider"), false, "services_captiveportal_saml_sp.php");
-			# $tab_array[] = array(gettext("Identity provider"), false, "services_captiveportal_saml_idp.php");
-			$tab_array[] = array(gettext("Federations"), false, "services_captiveportal_saml_federation.php");
-			$tab_array[] = array(gettext("Whitelists"), true, "services_captiveportal_saml_whitelist.php");
-			display_top_tabs($tab_array);
-		?>
+		<?php display_saml_tabs(basename(__FILE__)); ?>
 		</td>
 	</tr>
 	<tr>
-- 
2.1.1

