Fibinger Ádám
2019-11-27 c5946f44341c29594803c5b2ca64dcaf335fbca3
form.php
@@ -1,39 +1,49 @@
<?php
ini_set('display_errors', E_ALL);
include_once "common/base.php";
include "vendor/autoload.php";
$s = new \EOG\Models\Stripe();
define('IS_DEV', (!isset($_SERVER['HTTP_HOST'])));
define('SITE_ROOT', __DIR__);
if (!empty($_POST['stripe'])) {
    $s->loadFromArray($_POST['stripe']);
if (IS_DEV)
{
   define('OVERLAY_DIR', dirname(__DIR__) . '/esl-overlay/');
}
else
{
   define('OVERLAY_DIR', dirname(__DIR__) . '/overlays/');
    if (!empty($s->getState())) {
        file_put_contents(STRIPE_JSON, $s->getJson());
    }
    $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('overlays/stripe.twig', ['stripe' => $s]);
    file_put_contents(OVERLAY_DIR . 'team.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);
} else {
    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);
        }
    }
}
$twig = \EOG\Utils\TwigFactory::getEnvironment(SITE_ROOT);
$teams = new \EOG\Models\TeamList();
if (!empty($_POST))
{
   $s = new \EOG\Models\Stripe();
   $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
   file_put_contents(OVERLAY_DIR . 'generated.html', $html_content);
   echo OVERLAY_DIR . 'generated.html';
if (file_exists(TEAMS_JSON)) {
    $teams->fromJson(file_get_contents(TEAMS_JSON));
}
else
{
   $s = new \EOG\Models\Stripe();
   $var = [
      'stripe' => $s,
      'operators' => $s->getOperators()
   ];
   echo $twig->render('templates/admin/form.twig', $var);
}
$var = [
    'stripe' => $s,
    'teamNames' => $teams->getTeamNames(),
    'operators' => $s->getOperators(),
    'post' => !empty($_POST['stripe'])
];
echo $twig->render('admin/stripe-form.twig', $var);