From cc3ac843ada92f513339d893c8da534e3c5b9ae7 Mon Sep 17 00:00:00 2001
From: Fibinger Ádám <adam.fibinger@wup.hu>
Date: Tue, 15 Oct 2019 16:47:12 +0200
Subject: [PATCH] Meccs történet alapok

---
 form.php |   67 ++++++++++++++++++++++++++-------
 1 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/form.php b/form.php
index a56ebfe..e928767 100644
--- a/form.php
+++ b/form.php
@@ -15,25 +15,64 @@
 	define('OVERLAY_DIR', dirname(__DIR__) . '/overlays/');
 }
 
+$last_json = OVERLAY_DIR.'last.json';
+
 $twig = \EOG\Utils\TwigFactory::getEnvironment(SITE_ROOT);
 
-if (!empty($_POST))
+$s = new \EOG\Models\Stripe();
+
+if (!empty($_POST['stripe']))
 {
-	$s = new \EOG\Models\Stripe();
+	$s->loadFromArray($_POST['stripe']);
 
-	$html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
+    if (!empty($s->stripe['class'])) {
+        file_put_contents($last_json, $s->getJson());
+    }
 
-	file_put_contents(OVERLAY_DIR . 'generated.html', $html_content);
+	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);
 
-	echo OVERLAY_DIR . 'generated.html';
+			$s->setClass('team');
+			$html_content = $twig->render('templates/overlay-base.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');
+			$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);
+        $stateArray = json_decode($raw_json, true);
+        if (is_array($stateArray)) {
+            $s->loadFromArray($stateArray);
+        }
+    }
 }
-else
-{
-	$s = new \EOG\Models\Stripe();
-	$var = [
-		'stripe' => $s,
-		'operators' => $s->getOperators()
-	];
-	echo $twig->render('templates/admin/form.twig', $var);
-}
+
+$var = [
+	'stripe'    => $s,
+	'operators' => $s->getOperators(),
+	'post'      => !empty($_POST['stripe'])
+];
+echo $twig->render('templates/admin/form.twig', $var);
 

--
Gitblit v1.8.0