<?php
session_start();

if (isset($_SESSION['error'])) {
    $unsupported = '<div class="error-message">'. '<br>'. htmlspecialchars($_SESSION['error']) . '</div>';
    unset($_SESSION['error']);
}

$successCount = isset($_SESSION['successCount']) ? $_SESSION['successCount'] : 0;
$errorCount = isset($_SESSION['errorCount']) ? $_SESSION['errorCount'] : 0;
$passwordCount = isset($_SESSION['passwordCount']) ? $_SESSION['passwordCount'] : 0;
$csvFile = isset($_SESSION['csvFile']) ? $_SESSION['csvFile'] : '';
$delete_csv = isset($_SESSION['deleteFile'])? $_SESSION['deleteFile'] : '';
$password_csv = isset($_SESSION['passwordFile'])? $_SESSION['passwordFile'] : '';

unset($_SESSION['successCount']);
unset($_SESSION['errorCount']);
unset($_SESSION['passwordCount']);
unset($_SESSION['csvFile']);
unset($_SESSION['deleteFile']);
unset($_SESSION['passwordFile']);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="3;url=userlist.php">
    <title>Upload Summary</title>
    <link rel="stylesheet" href="../css/upload_summary.css">
</head>
<body>
    <div class="overlay">
        <div class="popup">
            <div class="wrap">
            <h3>Upload Summary</h3>
            <p><?php echo $unsupported;?></p>
            
            <p>Successfully Created Users: <?php echo $successCount; ?></p>

            <?php if ($passwordCount): ?>
            <p>Password Missing Users: <?php echo $passwordCount; ?></p>
            <?php endif; ?>

            <?php if ($csvFile):?>
                <p class="message">Some users already existed.</p>
                <a href="../downloads/<?php echo $csvFile; ?>" download>Download Existing Users List</a>
            <?php endif; ?>

            <?php if($password_csv):?>
                <p class="message">Some users doesnt have password.</p>
                <a href="../downloads/<?php echo $password_csv; ?>" download>Download Users With No Password</a>
            <?php else:?>
                <p>No existing users found.</p>
            <?php endif; ?>

            </div>
        </div>
    </div>
</body>
</html>
