From c5946f44341c29594803c5b2ca64dcaf335fbca3 Mon Sep 17 00:00:00 2001
From: Fibinger Ádám <adam.fibinger@wup.hu>
Date: Wed, 27 Nov 2019 21:03:23 +0100
Subject: [PATCH] Némi refaktor és új overlay

---
 form.php |   85 ++++++++++++++----------------------------
 1 files changed, 28 insertions(+), 57 deletions(-)

diff --git a/form.php b/form.php
index e928767..f2bf36e 100644
--- a/form.php
+++ b/form.php
@@ -1,67 +1,30 @@
 <?php
-ini_set('display_errors', E_ALL);
-
-include "vendor/autoload.php";
-
-define('IS_DEV', (!isset($_SERVER['HTTP_HOST'])));
-define('SITE_ROOT', __DIR__);
-
-if (IS_DEV)
-{
-	define('OVERLAY_DIR', dirname(__DIR__) . '/esl-overlay/');
-}
-else
-{
-	define('OVERLAY_DIR', dirname(__DIR__) . '/overlays/');
-}
-
-$last_json = OVERLAY_DIR.'last.json';
-
-$twig = \EOG\Utils\TwigFactory::getEnvironment(SITE_ROOT);
+include_once "common/base.php";
 
 $s = new \EOG\Models\Stripe();
 
-if (!empty($_POST['stripe']))
-{
-	$s->loadFromArray($_POST['stripe']);
+if (!empty($_POST['stripe'])) {
+    $s->loadFromArray($_POST['stripe']);
 
-    if (!empty($s->stripe['class'])) {
-        file_put_contents($last_json, $s->getJson());
+    if (!empty($s->getState())) {
+        file_put_contents(STRIPE_JSON, $s->getJson());
     }
 
-	switch ($s->stripe['class'])
-	{
-		case 'simple':
-			$html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
-			file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
-			break;
-		case 'team':
-			$s->setClass('simple');
-			$html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
-			file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
+    $s->setClass('simple');
+    $html_content = $twig->render('overlays/stripe.twig', ['stripe' => $s]);
+    file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
 
-			$s->setClass('team');
-			$html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
-			file_put_contents(OVERLAY_DIR . 'team.html', $html_content);
+    $s->setClass('team');
+    $html_content = $twig->render('overlays/stripe.twig', ['stripe' => $s]);
+    file_put_contents(OVERLAY_DIR . 'team.html', $html_content);
 
-			break;
-		case 'team-ban':
-			$s->setClass('simple');
-			$html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
-			file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
+    $s->setClass('team-ban');
+    $html_content = $twig->render('overlays/stripe.twig', ['stripe' => $s]);
+    file_put_contents(OVERLAY_DIR . 'team-ban.html', $html_content);
 
-			$s->setClass('team');
-			$html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
-			file_put_contents(OVERLAY_DIR . 'team.html', $html_content);
-
-			$s->setClass('team-ban');
-			$html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
-			file_put_contents(OVERLAY_DIR . 'team-ban.html', $html_content);
-			break;
-	}
 } else {
-    if (file_exists($last_json)) {
-        $raw_json = file_get_contents($last_json);
+    if (file_exists(STRIPE_JSON)) {
+        $raw_json = file_get_contents(STRIPE_JSON);
         $stateArray = json_decode($raw_json, true);
         if (is_array($stateArray)) {
             $s->loadFromArray($stateArray);
@@ -69,10 +32,18 @@
     }
 }
 
+$teams = new \EOG\Models\TeamList();
+
+if (file_exists(TEAMS_JSON)) {
+    $teams->fromJson(file_get_contents(TEAMS_JSON));
+}
+
 $var = [
-	'stripe'    => $s,
-	'operators' => $s->getOperators(),
-	'post'      => !empty($_POST['stripe'])
+    'stripe' => $s,
+    'teamNames' => $teams->getTeamNames(),
+    'operators' => $s->getOperators(),
+    'post' => !empty($_POST['stripe'])
 ];
-echo $twig->render('templates/admin/form.twig', $var);
+
+echo $twig->render('admin/stripe-form.twig', $var);
 

--
Gitblit v1.8.0