From 721fd4e523464047eae96f2d1702a25cc4ff3d5b Mon Sep 17 00:00:00 2001
From: Tomasz Wolniewicz <twoln@umk.pl>
Date: Mon, 23 May 2022 14:04:33 +0200
Subject: [PATCH] Moving all ECCS constants into Constants.php so this will be
 the only place to change things if new status arrives

---
 lib/API.php            | 10 ++++------
 lib/Constants.php      | 10 +++++-----
 lib/eduGAIN_entity.php | 16 +++-------------
 3 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/lib/API.php b/lib/API.php
index 045d177..34b03ac 100644
--- a/lib/API.php
+++ b/lib/API.php
@@ -134,15 +134,13 @@ class API {
                 }
                 break;
             case 'eccs_status':
-                switch ($optValue) {   // these values can be only 0,1,2,3
+                switch ($optValue) {   // these values can be only 0,1,2,3,4
                     case 'NOTSET':
                         $optValue = 0;
-                    case 0;
-                    case 1;
-                    case 2;
-                    case 3;
-                        break;
                     default:
+                        if (isset(Constants::ECCS_Colours[$optValue])) {
+                            break;
+                        }
                         $this->optionError($optName);
                         break;
                 }
diff --git a/lib/Constants.php b/lib/Constants.php
index 536c9cc..f831ee7 100644
--- a/lib/Constants.php
+++ b/lib/Constants.php
@@ -13,12 +13,12 @@ class Constants {
     const EC = 'http://macedir.org/entity-category';
 // entity category support
     const ECs = 'http://macedir.org/entity-category-support';
-// ECSS_colours
+// ECCS_colours
     const ECCS_Colours = [
-        1 => ['white', 'green'],
-        2 => ['black', '#D3D3D3'],
-        3 => ['white', 'red'],
-        4 => ['black', '#FFDB58'],
+        1 => ['white', 'green', 'OK'],
+        2 => ['black', '#D3D3D3', 'Disabled'],
+        3 => ['white', 'red', 'Error'],
+        4 => ['black', '#FFDB58', 'Unknown'],
    ];
 // Code of Conduct Support
     const COCO = 'http://www.geant.net/uri/dataprotection-code-of-conduct/v1';
diff --git a/lib/eduGAIN_entity.php b/lib/eduGAIN_entity.php
index 0ae466d..69ceee8 100644
--- a/lib/eduGAIN_entity.php
+++ b/lib/eduGAIN_entity.php
@@ -860,18 +860,8 @@ class eduGAIN_entity extends eduGAIN {
         $V = array_shift($TR);
         $row_class = 'CLASS_REPLACE';
         if ($V['type'] == 'IdP' && $entity['eccs_status'] != 0) {
-            if ($entity['eccs_status'] == 1) {
-                $td_s = "background:green; text-align:center";
-                $a_s = "color:white";
-            }
-            if ($entity['eccs_status'] == 2) {
-                $td_s = "background:#D3D3D3; text-align:center";
-                $a_s = "color:black";
-            }
-            if ($entity['eccs_status'] == 3) {
-                $td_s = "background:red; text-align:center";
-                $a_s = "color:white";
-            }
+            $td_s = "background:".Constants::ECCS_Colours[$entity['eccs_status']][1]."; text-align:center";
+            $a_s = "color:".Constants::ECCS_Colours[$entity['eccs_status']][0];
             $eccs = "<div class='status_box' style='$td_s'><a style='$a_s' href='javascript:show_eccs(\"" . urlencode($entity['entityid']) . "\")'>ECCS</a></div>";
         } else {
             $eccs = '';
@@ -1226,4 +1216,4 @@ class eduGAIN_entity extends eduGAIN {
     private $ec_filter;
     private $show_warnings;
 
-}
\ No newline at end of file
+}
-- 
GitLab