Fibinger Ádám
2019-10-16 268b326d5a7d228ac991f15086b804db808535bf
commit | author | age
812087 1 <?php
2 ini_set('display_errors', E_ALL);
3
4 include "vendor/autoload.php";
5
6 define('IS_DEV', (!isset($_SERVER['HTTP_HOST'])));
7 define('SITE_ROOT', __DIR__);
8
9 if (IS_DEV)
10 {
11     define('OVERLAY_DIR', dirname(__DIR__) . '/esl-overlay/');
12 }
13 else
14 {
15     define('OVERLAY_DIR', dirname(__DIR__) . '/overlays/');
16 }
17
cc3ac8 18 $last_json = OVERLAY_DIR.'last.json';
19
812087 20 $twig = \EOG\Utils\TwigFactory::getEnvironment(SITE_ROOT);
21
cc3ac8 22 $s = new \EOG\Models\Stripe();
23
24 if (!empty($_POST['stripe']))
812087 25 {
cc3ac8 26     $s->loadFromArray($_POST['stripe']);
812087 27
268b32 28     if (!empty($s->getState())) {
cc3ac8 29         file_put_contents($last_json, $s->getJson());
30     }
812087 31
cc3ac8 32     switch ($s->stripe['class'])
33     {
34         case 'simple':
35             $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
36             file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
37             break;
38         case 'team':
39             $s->setClass('simple');
40             $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
41             file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
812087 42
cc3ac8 43             $s->setClass('team');
44             $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
45             file_put_contents(OVERLAY_DIR . 'team.html', $html_content);
46
47             break;
48         case 'team-ban':
49             $s->setClass('simple');
50             $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
51             file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
52
53             $s->setClass('team');
54             $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
55             file_put_contents(OVERLAY_DIR . 'team.html', $html_content);
56
57             $s->setClass('team-ban');
58             $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
59             file_put_contents(OVERLAY_DIR . 'team-ban.html', $html_content);
60             break;
61     }
62 } else {
63     if (file_exists($last_json)) {
64         $raw_json = file_get_contents($last_json);
65         $stateArray = json_decode($raw_json, true);
66         if (is_array($stateArray)) {
67             $s->loadFromArray($stateArray);
68         }
69     }
812087 70 }
cc3ac8 71
268b32 72 echo "<pre>State:".PHP_EOL;
73 var_dump($s->getState());
74 echo "</pre>";
75
cc3ac8 76 $var = [
77     'stripe'    => $s,
78     'operators' => $s->getOperators(),
79     'post'      => !empty($_POST['stripe'])
80 ];
81 echo $twig->render('templates/admin/form.twig', $var);
812087 82