<?php include('include/headscript.php');
$idyogaschool = 1;

?>
<?php
// Assuming you have an existing connection to the database
$conn = new mysqli($servername, $username, $password, $database);
// Fetch current values from the database
$query = $conn->prepare("SELECT * FROM yogaschool WHERE idyogaschool = ?");
$query->bind_param("i", $idyogaschool);
$query->execute();
$result = $query->get_result();
$schoolData = $result->fetch_assoc();

$schoolnamedb = $schoolData['nameschool'];
$addressdb = $schoolData['address'];
$countrydb = $schoolData['country'];
$referencemeailschooldb = $schoolData['referenceemailschool'];
$schooldescriptiondb = $schoolData['schooldescription'];
$shortschooldescription = $schoolData['shortschooldescription'];
$citydb = $schoolData['city'];
$zipdb = $schoolData['zip'];
$emailschooldb = $schoolData['emailschool'];
$referencenameschooldb = $schoolData['referencenameschool'];
$latitudedb = $schoolData['latitude'];
$longitudedb = $schoolData['longitude'];
?>
<!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, user-scalable=0, minimal-ui">
    <?php include('include/seo.php'); ?>

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <link rel="shortcut icon" href="assets/images/favicon.ico">

    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css">
    <link href="assets/css/style.css" rel="stylesheet" type="text/css">






</head>
<style>
    #descriptionyogaclass {
        min-height: 300px;
        /* 300px è circa 10 righe di altezza */
    }
</style>


<body class="fixed-left">

    <!-- Loader -->
    <div id="preloader">
        <div id="status">
            <div class="spinner"></div>
        </div>
    </div>

    <!-- Begin page -->
    <div id="wrapper">

        <?php include('include/navigationbar.php'); ?>

        <!-- Start right Content here -->

        <div class="content-page">
            <!-- Start content -->
            <div class="content">

                <?php include('include/topbar.php'); ?>

                <div class="page-content-wrapper ">

                    <div class="container-fluid">

                        <div class="row">
                            <div class="col-sm-12">
                                <div class="page-title-box">
                                    <div class="btn-group float-right">
                                        <ol class="breadcrumb hide-phone p-0 m-0">
                                            <li class="breadcrumb-item"><a href="#">YogiWhere</a></li>
                                            <li class="breadcrumb-item active">Dashboard</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title"><?php echo $myschool; ?></h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title end breadcrumb -->

                        <?php
                        $conn = new mysqli($servername, $username, $password, $database);
                        // Recupera le classi già create per questa scuola
                        $query_classes = $conn->prepare("SELECT yogaclass.idyogaclass, yogaclass.nameyogaclass, yogaclass.descriptionyogaclass, classcategory.namecategory, yogaclass.imgyogaclass 
                        FROM yogaclass 
                        LEFT JOIN classcategory ON yogaclass.idclasscategory = classcategory.idclasscategory 
                        WHERE yogaclass.idyogaschool = ?");
                        $query_classes->bind_param("i", $idyogaschool);
                        $query_classes->execute();
                        $result_classes = $query_classes->get_result();
                        ?>

                        <!-- Tabella per visualizzare le classi esistenti -->
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="card card-body">
                                    <h4 class="card-title font-20 mt-0">Classi già create</h4>
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>Nome Classe</th>
                                                <th>Categoria</th>
                                                <th>Descrizione</th>
                                                <th>Immagine</th> <!-- Aggiunta colonna per l'immagine -->
                                                <th>Azioni</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php if ($result_classes->num_rows > 0): ?>
                                                <?php while ($row = $result_classes->fetch_assoc()): ?>
                                                    <tr>
                                                        <td><?php echo $row['idyogaclass']; ?></td>
                                                        <td><?php echo $row['nameyogaclass']; ?></td>
                                                        <td><?php echo $row['namecategory']; ?></td>
                                                        <td><?php echo $row['descriptionyogaclass']; ?></td>
                                                        <td>
                                                            <?php if (!empty($row['imgyogaclass'])): ?>
                                                                <img src="uploadphotoclass/<?php echo $row['imgyogaclass']; ?>" alt="Immagine Classe" width="100">
                                                            <?php else: ?>
                                                                <span>Nessuna immagine</span>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td>
                                                            <a href="edit_class.php?idyogaclass=<?php echo $row['idyogaclass']; ?>" class="btn btn-primary btn-sm">Modifica</a>
                                                            <a href="delete_class.php?idyogaclass=<?php echo $row['idyogaclass']; ?>" class="btn btn-danger btn-sm">Cancella</a>
                                                        </td>
                                                    </tr>
                                                <?php endwhile; ?>
                                            <?php else: ?>
                                                <tr>
                                                    <td colspan="6">Nessuna classe trovata.</td>
                                                </tr>
                                            <?php endif; ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>


                        <!-- Form per la creazione di una nuova classe -->
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="card card-body">
                                    <h4 class="card-title font-20 mt-0">Crea Nuova Classe</h4>
                                    <form method="POST" action="create_class.php" enctype="multipart/form-data">
                                        <div class="form-group">
                                            <label for="nameyogaclass">Nome Classe</label>
                                            <input type="text" class="form-control" id="nameyogaclass" name="nameyogaclass" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="idclasscategory">Categoria Classe</label>
                                            <select class="form-control" id="idclasscategory" name="idclasscategory" required>
                                                <?php
                                                $query_categories = $conn->query("SELECT * FROM classcategory");
                                                while ($row = $query_categories->fetch_assoc()) {
                                                    echo '<option value="' . $row['idclasscategory'] . '">' . $row['namecategory'] . '</option>';
                                                }
                                                ?>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="descriptionyogaclass">Descrizione Classe</label>
                                            <textarea class="form-control" id="descriptionyogaclass" name="descriptionyogaclass" rows="10"></textarea>
                                        </div>
                                        <div class="form-group">
                                            <label for="imgyogaclass">Immagine Classe (Opzionale)</label>
                                            <input type="file" class="form-control" id="imgyogaclass" name="imgyogaclass" accept="image/*">
                                        </div>
                                        <div class="form-group">
                                            <label for="productcode">Codice Prodotto (Opzionale)</label>
                                            <input type="text" class="form-control" id="productcode" name="productcode" placeholder="Codice Prodotto">
                                        </div>
                                        <button type="submit" class="btn btn-primary">Crea Classe</button>
                                    </form>

                                </div>
                            </div>
                        </div>

                        <!-- Includi CKEditor -->
                        <script src="https://cdn.ckeditor.com/ckeditor5/35.0.1/classic/ckeditor.js"></script>
                        <script>
                            ClassicEditor
                                .create(document.querySelector('#descriptionyogaclass'))
                                .catch(error => {
                                    console.error(error);
                                });
                        </script>






                    </div>

                    <!-- end row -->


                </div><!-- container -->

            </div> <!-- Page content Wrapper -->

        </div> <!-- content -->

        <?php include('include/footer.php'); ?>

    </div>
    <!-- End Right content here -->

    </div>
    <!-- END wrapper -->





    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/popper.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/modernizr.min.js"></script>
    <script src="assets/js/detect.js"></script>
    <script src="assets/js/fastclick.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>
    <script src="assets/js/jquery.blockUI.js"></script>
    <script src="assets/js/waves.js"></script>
    <script src="assets/js/jquery.nicescroll.js"></script>
    <script src="assets/js/jquery.scrollTo.min.js"></script>

    <script src="assets/plugins/chart.js/chart.min.js"></script>
    <script src="assets/pages/dashboard.js"></script>

    <!-- App js -->
    <script src="assets/js/app.js"></script>


</body>

</html>