<?php
session_start();
if($_SESSION['unohs'] == null){
    header("location:index.php?msg=unauthorized");
}

date_default_timezone_set("Asia/Kolkata");
include "conn.php";
include "../../functions2.php";

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $level1 = $_POST['level1'];
    $level2 = $_POST['level2'];
    $level3 = $_POST['level3'];
    $level4 = $_POST['level4'];
    $level5 = $_POST['level5'];
    $level6 = $_POST['level6'];

    $updateQuery = "UPDATE web_commission SET 
        level1 = ?, 
        level2 = ?, 
        level3 = ?, 
        level4 = ?, 
        level5 = ?, 
        level6 = ? 
        WHERE id = 1";

    $stmt = mysqli_prepare($conn, $updateQuery);
    mysqli_stmt_bind_param($stmt, "dddddd", $level1, $level2, $level3, $level4, $level5, $level6);
    
    if (mysqli_stmt_execute($stmt)) {
        $msg = "✅ Levels updated successfully!";
    } else {
        $msg = "❌ Error updating levels: " . mysqli_error($conn);
    }
}

// Fetch current settings
$query = "SELECT * FROM web_commission LIMIT 1";
$result = mysqli_query($conn, $query);
$settings = mysqli_fetch_assoc($result);
?>
<?php include 'header.php'; ?>



<div class="main-panel">
    <div class="content-wrapper">
        <div class="row justify-content-center">
            <div class="col-lg-6 col-md-8">
                <div class="card shadow-sm p-4">
                    <h4 class="font-weight-bold text-dark mb-3">Update Settings</h4>
          <?php if (isset($msg)) : ?>
            <div class="alert alert-info text-center"> <?php echo $msg; ?> </div>
          <?php endif; ?>
          <form action="" method="POST">
            <?php for ($i = 1; $i <= 6; $i++) : ?>
              <div class="mb-3">
                <label>Level <?php echo $i; ?> Commission:</label>
                <input type="text" name="level<?php echo $i; ?>" class="form-control" value="<?php echo $settings['level' . $i]; ?>" required>
              </div>
            <?php endfor; ?>
            <button type="submit" class="btn btn-primary w-100">Update Levels</button>
          </form>
        </div>
      </div>
    </div>
  </div>
  <style>
 
 
 
</style>

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