<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "membership";

$connection = new mysqli($servername, $username, $password, $database);

$id = "";
$nama_peserta = "";
$dribbling = "";
$passing = "";
$shooting = "";
$rebounding = "";
$defense = "";
$pivot = "";
$blocking = "";
$layup = "";
$crossover = "";
$tripleth = "";
$leadership = "";
$kejujuran = "";
$kerjasama = "";
$disiplin = "";
$sportivitas = "";
$catatan = "";

$errorMessage = "";
$successMessage = "";

if ($_SERVER['REQUEST_METHOD'] == 'GET') {

    if (!isset($_GET["id"])) {
        header("location: dataraportcch.php");
        exit;
    }

    $id = $_GET["id"];

    $sql = "SELECT * FROM raport WHERE id=$id";
    $result = $connection->query($sql);
    $row = $result->fetch_assoc();

    if (!$row) {
        header("location: dataraportcch.php");
        exit;
    }

    $nama_peserta = $row["nama_peserta"];
    $dribbling = $row["dribbling"];
    $passing = $row["passing"];
    $shooting = $row["shooting"];
    $rebounding = $row["rebounding"];
    $defense = $row["defense"];
    $pivot = $row["pivot"];
    $blocking = $row["blocking"];
    $layup = $row["layup"];
    $crossover = $row["crossover"];
    $tripleth = $row["tripleth"];
    $leadership = $row["leadership"];
    $kerjasama = $row["kerjasama"];
    $kejujuran = $row["kejujuran"];
    $disiplin = $row["disiplin"];
    $sportivitas = $row["sportivitas"];
    $catatan = $row["catatan"];

} else {

    $id = $_POST["id"];
    $nama_peserta = $_POST["nama_peserta"];
    $dribbling = $_POST["dribbling"];
    $passing = $_POST["passing"];
    $shooting = $_POST["shooting"];
    $rebounding = $_POST["rebounding"];
    $defense = $_POST["defense"];
    $pivot = $_POST["pivot"];
    $blocking = $_POST["blocking"];
    $layup = $_POST["layup"];
    $crossover = $_POST["crossover"];
    $tripleth = $_POST["tripleth"];
    $leadership = $_POST["leadership"];
    $kerjasama = $_POST["kerjasama"];
    $kejujuran = $_POST["kejujuran"];
    $disiplin = $_POST["disiplin"];
    $sportivitas = $_POST["sportivitas"];
    $catatan = $_POST["catatan"];

    do {
        $sql = "UPDATE raport
        SET nama_peserta = '$nama_peserta',
        dribbling = '$dribbling',
        passing = '$passing',
        shooting = '$shooting',
        rebounding = '$rebounding',
        defense = '$defense',
        pivot = '$pivot',
        blocking = '$blocking',
        layup = '$layup',
        crossover = '$crossover',
        tripleth = '$tripleth',
        leadership = '$leadership',
        kerjasama = '$kerjasama',
        kejujuran = '$kejujuran',
        disiplin = '$disiplin',
        sportivitas = '$sportivitas',
        catatan = '$catatan'
        WHERE id=$id";

        $result = $connection->query($sql);

        if (!$result) {
            $errorMessage = "Invalid Query" . $connection->error;
            break;
        }

        $successMessage = "Data berhasil diupdate";

        header("location:dataraportcch.php");
        exit;

    } while (false);
}
?>

<DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
    </head>

    <body>
        <div class="container">
            <h3>Form Penilaian Peserta</h3> <br>

            <form method="post">
                <input type="hidden" name="id" value="<?php echo $id; ?>">
                <div class="row mb-3">
                    <label class="col-sm-2 col-form-label">Nama Peserta</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="nama_peserta" value="<?php echo $nama_peserta; ?>"
                            readonly>
                    </div>
                </div>
                <h3><b>HARD SKILL</b></h3>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Dribbling</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="dribbling" value="<?php echo $dribbling; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Passing</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="passing" value="<?php echo $passing; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Shooting</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="shooting" value="<?php echo $shooting; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Rebounding</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="rebounding" value="<?php echo $rebounding; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Defense</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="defense" value="<?php echo $defense; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Pivot</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="pivot" value="<?php echo $pivot; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Blocking</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="blocking" value="<?php echo $blocking; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Lay Up</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="layup" value="<?php echo $layup; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Crossover</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="crossover" value="<?php echo $crossover; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Triple Threat</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="tripleth" value="<?php echo $tripleth; ?>">
                    </div>
                </div>
                <h3><b>SOFT SKILL</b></h3>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Leadership</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="leadership" value="<?php echo $leadership; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Kerjasama</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="kerjasama" value="<?php echo $kerjasama; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Kejujuran</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="kejujuran" value="<?php echo $kejujuran; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Disiplin</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="disiplin" value="<?php echo $disiplin; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label">Sportivitas</label>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" name="sportivitas" value="<?php echo $sportivitas; ?>">
                    </div>
                </div>
                <div class="row mb-2">
                    <label class="col-sm-2 col-form-label"><b>Catatan</b></label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="catatan" value="<?php echo $catatan; ?>">
                    </div>
                </div>


        </div>
        <div class="row mb-3">
            <div class="offset-sm-3 col-sm-3 d-grid">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
            <div class="col-sm-3 d-grid">
                <a class="btn btn-outline-primary" href=" dataraportcch.php" role="button">Batal</a>
            </div>
        </div>
        </form>

        </div>
    </body>

    </html>