From 20ef0ac88c0108072a6ed27ad5324d64a30b9277 Mon Sep 17 00:00:00 2001
From: Tomasz Wolniewicz <twoln@umk.pl>
Date: Wed, 28 Aug 2024 18:12:18 +0200
Subject: [PATCH] Status page for a single federation as requesed by ECCS

---
 page-logic/status.php | 75 +++++++++++++++++++++++++++++++------------
 1 file changed, 55 insertions(+), 20 deletions(-)

diff --git a/page-logic/status.php b/page-logic/status.php
index 75670e4..61bd9c3 100644
--- a/page-logic/status.php
+++ b/page-logic/status.php
@@ -143,29 +143,64 @@ function dateMissingCheck($federation, $fieldName) {
     return !isset($federation[$fieldName]) || $federation[$fieldName] == '0000-00-00 00:00:00';
 }
 
-foreach ($edugain->FEDS as $countryCode => $federation) {
-    $status = $federation['status'];
-    $processedFederation = processFederation($federation);
-    $processedFederation['status'] = $status;
-    if ($status) { // This will exclude federations with a status of 0 (lib/Status.php ln 124)
-        if ($status < 4 && $status != 2) {
-            $candidates[] = $processedFederation;
-        } else if ($status > 3 && $status < 5) {
-            $votingOnly[] = $processedFederation;
-        } else if ($status == 6 || $status == 5) {
-            $participants[] = $processedFederation;
-        }
+$data = [];
+$singleFed = false;
+$reg_auth_safe = '';
+if (!empty($_REQUEST['fed_id'])) {
+    $code = $_REQUEST['fed_id'];
+    if (!preg_match('/^:?([a-zA-Z]*-?[a-zA-Z]*)(:[a-aA-Z]*-?[a-zA-Z]*)*$/', $code)) {
+        exit;
     }
+    $singleFed = true;
 }
 
+if (!empty($_REQUEST['reg_auth'])) {
+    $reg_auth = $_REQUEST['reg_auth'];
+    $reg_auth_safe = $edugain->cleanInput($reg_auth);
+    $singleFed = true;
+//    print $reg_auth_safe;
+}
 
-$data = [];
-$data['participants'] = $participants;
-$data['votingOnly'] = $votingOnly;
-$data['candidates'] = $candidates;
-if (isset($_GET['issues'])) {
-    $data['problem_switch'] = 1;
+if ($singleFed) {
+    $my_federation = '';
+    foreach ($edugain->FEDS as $countryCode => $federation) {
+        if ($code !== $countryCode && ($reg_auth_safe === '' || $reg_auth_safe !== $federation['reg_auth'])) {
+            continue;
+        }
+        $status = $federation['status'];
+        if ($status === 0) {
+            exit;
+        }
+        $processedFederation['status'] = $status;
+        $my_federation = processFederation($federation);
+    }
+    if ($my_federation === '') {
+        exit;
+    }
+    $data['federation'] = $my_federation;
+    echo $twig->render('status/status-members-details.html', $data);
 } else {
-    $data['problem_switch'] = 0;
+    foreach ($edugain->FEDS as $countryCode => $federation) {
+        $status = $federation['status'];
+        $processedFederation = processFederation($federation);
+        $processedFederation['status'] = $status;
+        if ($status) { // This will exclude federations with a status of 0 (lib/Status.php ln 124)
+            if ($status < 4 && $status != 2) {
+                $candidates[] = $processedFederation;
+            } else if ($status > 3 && $status < 5) {
+                $votingOnly[] = $processedFederation;
+            } else if ($status == 6 || $status == 5) {
+                $participants[] = $processedFederation;
+            }
+        }
+    }
+    $data['participants'] = $participants;
+    $data['votingOnly'] = $votingOnly;
+    $data['candidates'] = $candidates;
+    if (isset($_GET['issues'])) {
+        $data['problem_switch'] = 1;
+    } else {
+        $data['problem_switch'] = 0;
+    }
+    echo $twig->render('status.html', $data);
 }
-echo $twig->render('status.html', $data);
-- 
GitLab