<?php

defined('_IN_JOHNCMS') or die('Error: restricted access');

$headmod = 'premium';
$textl = 'Account Premium';
require('../system/head.php');

/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

/** @var PDO $db */
$db = $container->get(PDO::class);

/** @var Johncms\Api\UserInterface $systemUser */
$systemUser = $container->get(Johncms\Api\UserInterface::class);

/** @var Johncms\Api\ToolsInterface $tools */
$tools = $container->get(Johncms\Api\ToolsInterface::class);


if  ($systemUser->rights != 9) {
    header ('Location: ../?err');
    exit;
}

$id_user = intval($_GET['user']);
//$sql = $db->query("SELECT * FROM `users` WHERE `id`='".$id_user."'")->fetchColumn();

switch ($_GET['mod']) {
      case 'apply':
      echo '<div class="mainblok">' .
          '<div class="phdr">' .
          '<b>Request Premium Account</b>' .
          '</div>';
      if (isset($_POST['submit'])) {
         $db->exec("UPDATE `users` SET `premium`= '1' WHERE `id`='".$id_user."'");
      echo '<div class="rmenu">' .
             'Request succes<br/>' .
             'This user wass premium account' .
             '</div>';
     echo '<div class="phdr">' .
             '<b>' .
             '<a href="index.php?user='.$id_user.'">Back</a>' .
             '</b></div>';
     } else {
     echo '<div class="gmenu">Request Premium<br><form act="?act=premium&amp;mod=apply" method="post"><input type="submit" name="submit" value="Apply" />&#160;&#160;&#160;<a href="index.php?user='.$id_user.'"><b>Back</b></a></form>';
echo '</div>';
     }
     echo '</div>';
    break;
    case 'remove':
    echo '<div class="mainblok">' .
          '<div class="phdr">' .
          '<b>Removing Premium Account</b>' .
          '</div>';
          if (isset($_POST['submit'])) {
             $db->exec("UPDATE `users` SET `premium`= '0' WHERE `id`='".$id_user."'");
             echo '<div class="rmenu">Premium Removed Succes</div>';
             echo '<div class="phdr"><b><a href="index.php?user='.$id_user.'">Back</a></b></div>';
             } else {
             echo '<div class="gmenu">Removed premium account for this user ?<br><form act="?act=premium&amp;mod=remove" method="post"><input type="submit" name="submit" value="Yes" />&#160;&#160;&#160;<a href="index.php?user='.$id_user.'"><b>No</b></a></form></div>';
           }
   echo '</div>';
   break;
   default:
      header('Location ../?err');
      exit;
   break;
} 

?>
