<?php
/*
 * pages/administration.php
 * PHP logic: 100% INTACT din CMS original
 * HTML: design Nostalgia2 (adaptat din userpanel.blade.php)
 */
?>

<!-- Header -->
<nav class="navbar navbar-dark bg-news-header">
    <div class="container-fluid">
        <h4 class="h4 small m-0 text-uppercase"><?php echo strtoupper($lang['user-panel']); ?></h4>
        <div class="d-flex d-none d-md-block">
            <ul class="navbar-nav list-group-horizontal small">
                <li class="nav-item px-2">
                    <span class="text-bluevioletmutted small">
                        Check your information and manage your data!
                    </span>
                </li>
            </ul>
        </div>
    </div>
</nav>

<?php
// ---- LOGICA PHP 100% INTACT ----
if(isset($_POST['delete-code'])) {
    $alt_message = $lang['delete-chars'];
    $subject     = $lang['delete-chars'];
    $sendName    = $account_name;
    $sendEmail   = $myEmail;
    $code        = getAccountSocialID($_SESSION['id']);
    $html_mail   = sendCode($account_name, $code);
    include 'include/functions/sendEmail.php';
    echo '<div class="alert alert-success alert-dismissible fade show m-3">
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        '.$lang['sended-code'].'</div>';

} else if(isset($_POST['storekeeper-code'])) {
    $code = getPlayerSafeBoxPassword($_SESSION['id']);
    if($code != '' && $code != '000000') {
        $alt_message = $lang['storekeeper'];
        $subject     = $lang['storekeeper'];
        $sendName    = $account_name;
        $sendEmail   = $myEmail;
        $html_mail   = sendCode($account_name, $code, 2);
        include 'include/functions/sendEmail.php';
        echo '<div class="alert alert-success alert-dismissible fade show m-3">
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            '.$lang['sended-code'].'</div>';
    } else {
        echo '<div class="alert alert-danger alert-dismissible fade show m-3">
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            '.$lang['no-storekeeper'].'</div>';
    }

} else if(!$delete_account && isset($_POST['delete-account'])) {
    $code = generateSocialID(32);
    update_deletion_token($_SESSION['id'], $code);
    $code_link = '<br><br><a href="'.$site_url.'user/delete/'.$code.'" target="_blank" style="display:inline-block;color:#fff;background:#3498db;border:1px solid #3498db;border-radius:5px;padding:12px 25px;text-decoration:none;font-weight:bold;">'.$lang['delete-account'].'</a>';
    $alt_message = $lang['delete-account'];
    $subject     = $lang['delete-account'];
    $sendName    = $account_name;
    $sendEmail   = $myEmail;
    $html_mail   = sendCode($account_name, $code_link, 3);
    include 'include/functions/sendEmail.php';
    echo '<div class="alert alert-success alert-dismissible fade show m-3">
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        '.$lang['sended-code'].'</div>';

} else if(isset($_POST['cancel-delete-account'])) {
    // cancelation handled by CMS router

} else if(isset($_POST['change-password'])) {
    $code = generateSocialID(32);
    update_passlost_token_by_email($myEmail, $code);
    $code_link = '<br><br><a href="'.$site_url.'user/password/'.$code.'" target="_blank" style="display:inline-block;color:#fff;background:#3498db;border:1px solid #3498db;border-radius:5px;padding:12px 25px;text-decoration:none;font-weight:bold;">'.$lang['change-password'].'</a>';
    $alt_message = $lang['password'];
    $subject     = $lang['password'];
    $sendName    = $account_name;
    $sendEmail   = $myEmail;
    $html_mail   = sendCode($account_name, $code_link, 4);
    include 'include/functions/sendEmail.php';
    echo '<div class="alert alert-success alert-dismissible fade show m-3">
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        '.$lang['sended-code'].'</div>';
}
?>

<div class="account_settings_main_board_darker_background">

    <!-- Info cont -->
    <table class="text-center table table-borderless" id="account_details">
        <tr class="account_details_row">
            <td class="account_details_category"><?php echo $lang['user-name']; ?></td>
            <td class="account_details_value"><?php echo htmlspecialchars($account_name); ?></td>
        </tr>
        <tr class="account_details_row">
            <td class="account_details_category"><?php echo $lang['md']; ?></td>
            <td class="account_details_value text-gold"><?php echo getAccountMD($_SESSION['id']); ?></td>
        </tr>
        <tr class="account_details_row">
            <td class="account_details_category"><?php echo $lang['jd']; ?></td>
            <td class="account_details_value text-gold"><?php echo getAccountJD($_SESSION['id']); ?></td>
        </tr>
        <tr class="account_details_row">
            <td class="account_details_category"><?php echo $lang['email-address']; ?></td>
            <td class="account_details_value"><?php echo htmlspecialchars($myEmail); ?></td>
        </tr>
    </table>

    <!-- Actiuni cont -->
    <div class="col-11 p-4 bg-news-title small mx-auto mt-3">
        <p class="col text-white w-100 small m-0 news-title-text text-uppercase"><?php echo $lang['account-data']; ?></p>
    </div>

    <div class="p-3">

        <!-- Caractere -->
        <div class="sider-btn mb-2">
            <a href="<?php echo $site_url; ?>user/characters">
                <button class="mx-auto sign-in-button btn bg-button small fw-bold" style="display:block;width:278px;">
                    <?php echo strtoupper($lang['chars']); ?> &raquo;
                </button>
            </a>
        </div>

        <!-- Email -->
        <div class="sider-btn mb-2">
            <a href="<?php echo $site_url; ?>user/email">
                <button class="mx-auto sign-in-button btn bg-button small fw-bold" style="display:block;width:278px;">
                    <?php echo strtoupper($lang['change-email']); ?> &raquo;
                </button>
            </a>
        </div>

        <!-- Schimba parola (trimite email) -->
        <div class="sider-btn mb-2">
            <form action="" method="post">
                <button type="submit" name="change-password"
                    onclick="return confirm('<?php echo addslashes($lang['sure_send?']); ?>')"
                    class="mx-auto sign-in-button btn bg-button small fw-bold" style="display:block;width:278px;">
                    <?php echo strtoupper($lang['change-password']); ?> &raquo;
                </button>
            </form>
        </div>

        <!-- Parola depozit -->
        <div class="sider-btn mb-2">
            <form action="" method="post">
                <button type="submit" name="storekeeper-code"
                    onclick="return confirm('<?php echo addslashes($lang['sure_send?']); ?>')"
                    class="mx-auto sign-in-button btn bg-button small fw-bold" style="display:block;width:278px;">
                    <?php echo strtoupper($lang['storekeeper']); ?> &raquo;
                </button>
            </form>
        </div>

        <!-- Cod stergere caractere -->
        <div class="sider-btn mb-2">
            <form action="" method="post">
                <button type="submit" name="delete-code"
                    onclick="return confirm('<?php echo addslashes($lang['sure_send?']); ?>')"
                    class="mx-auto sign-in-button btn bg-button small fw-bold" style="display:block;width:278px;">
                    <?php echo strtoupper($lang['send']); ?> <?php echo strtoupper($lang['delete-chars']); ?> &raquo;
                </button>
            </form>
        </div>

        <!-- Stergere cont -->
        <?php if(!$delete_account) { ?>
        <div class="sider-btn mb-2">
            <form action="" method="post">
                <button type="submit" name="delete-account"
                    onclick="return confirm('<?php echo addslashes($lang['sure_send?']); ?>')"
                    class="mx-auto sign-in-button btn bg-button small fw-bold text-danger" style="display:block;width:278px;border-color:darkred;">
                    <?php echo strtoupper($lang['delete-account']); ?> &raquo;
                </button>
            </form>
        </div>
        <?php } else {
            $date1 = date_create($delete_account['date']);
            $date2 = date_create(date('Y-m-d'));
            $diff  = date_diff($date1, $date2);
            $time_delete = intval($diff->format("%R%a"));
        ?>
        <div class="alert alert-warning m-3">
            <?php if($time_delete < 0)
                echo $lang['time-until-deletion'].' '.($time_delete*(-1)).' '.$lang['days'];
            else
                echo $lang['time-to-deletion'];
            ?>
        </div>
        <div class="sider-btn mb-2">
            <form action="" method="post">
                <button type="submit" name="cancel-delete-account"
                    class="mx-auto sign-in-button btn bg-button small fw-bold" style="display:block;width:278px;">
                    <?php echo strtoupper($lang['cancel-delete-account']); ?> &raquo;
                </button>
            </form>
        </div>
        <?php } ?>

    </div>
</div>
