<?php 
session_start(); // Ensure session is started
if (!isset($_SESSION['email'])) {
    // Redirect to login if no session is found
    header("Location: login.php");
    exit();
}

include 'header_guru.php';
include 'koneksi.php';

// Get the logged-in user's email
$loggedInEmail = $_SESSION['email'];

// Query to get `id_pengguna` based on the logged-in email
$userQuery = "SELECT id_pengguna FROM pengguna WHERE email = '$loggedInEmail'";
$userResult = mysqli_query($koneksi, $userQuery);
$userData = mysqli_fetch_assoc($userResult);

// If the query failed or no data found, exit
if (!$userData) {
    die("Error: Unable to find user information.");
}

$id_pengguna = $userData['id_pengguna'];

// Query to join 'guru' with 'pengguna' to fetch only the current user's data
$query = "SELECT g.nip, g.nama_guru, g.alamat, g.no_telepon, p.email 
          FROM guru g 
          LEFT JOIN pengguna p ON g.id_pengguna = p.id_pengguna
          WHERE g.id_pengguna = '$id_pengguna'";

$data = mysqli_query($koneksi, $query);

// Check if the query failed
if (!$data) {
    die("Error: " . mysqli_error($koneksi)); // Show the MySQL error message
}
?>
<style>
    .android-btn {
        display: inline-block;
        padding: 15px 30px;
        font-size: 18px;
        color: #fff;
        background-color: #6200ea; /* Use Android Material color (deep purple) */
        border: none;
        border-radius: 25px; /* Rounded button */
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
        text-align: center;
        transition: background-color 0.3s ease;
        text-decoration: none;
    }

    .android-btn:hover {
        background-color: #3700b3; /* Darker shade on hover */
    }
</style>

    
    <div class="row">
        <?php while ($d = mysqli_fetch_array($data)) { ?>
            <div class="col-md-6 col-lg-4 mb-4">
                <div class="card shadow-sm">
                    <div class="card-body">
                        <h5 class="card-title">Nama Mata pelajaran: <?php echo $d['nama_mapel']; ?></h5>
                        <p class="card-text">
                            <strong>Nama:</strong> <?php echo $d['nama_guru']; ?><br>
                            <strong>Alamat:</strong> <?php echo $d['hari']; ?><br>
                            <strong>Telepon:</strong> <?php echo $d['nama_kelas']; ?><br>
                         
                        </p>
                    </div>
                </div>
            </div>
        <?php } ?>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>




