<?php
// Include DB connection
include 'ominterior_db.php';

// Get ID from URL
$id = $_GET['id'] ?? 0;

// Fetch data for editing
$sql = "SELECT * FROM about_section WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$data = $result->fetch_assoc();

if (!$data) {
    die("No record found.");
}

// If form submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $section_title = $_POST['section_title'];
    $heading = $_POST['heading'];
    $content = $_POST['content'];
    $icon = $_POST['icon']; // New icon field

    $update = $conn->prepare("UPDATE about_section SET section_title=?, heading=?, content=?, icon=? WHERE id=?");
    $update->bind_param("ssssi", $section_title, $heading, $content, $icon, $id);

    if ($update->execute()) {
        echo "<div class='alert alert-success'>Record updated successfully.</div>";
        // Reload updated data
        $data = ['section_title' => $section_title, 'heading' => $heading, 'content' => $content, 'icon' => $icon];
        header("Location: texts.php");
        exit;
    } else {
        echo "<div class='alert alert-danger'>Update failed: " . $update->error . "</div>";
    }
}
?>



<!doctype html>
<html lang="en" dir="ltr">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<link rel="icon" href="assets/images/black-logo.png" type="image/x-icon"/>

<title>OM INTERIOR - Dashborad</title>

<!-- Bootstrap Core and vandor -->
<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css" />

<!-- Plugins css -->
<link rel="stylesheet" href="assets/plugins/charts-c3/c3.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- Core css -->
<link rel="stylesheet" href="assets/css/main2.css"/>
<link rel="stylesheet" href="assets/css/theme1.css"/>
</head>

<body class="font-montserrat">
<!-- Page Loader -->
<div class="page-loader-wrapper">
    <div class="loader">
    </div>
</div>

<div id="main_content">

<?php include 'haderTop_logo.php'?>
    
<?php include 'rightside_menu.php'?>

<?php include 'leftside_menu.php' ?>


    <div class="page">
        <div id="page_top" class="section-body top_dark">
            <div class="container-fluid">
                <div class="page-header">
                    <div class="left">
                        <a href="javascript:void(0)" class="icon menu_toggle mr-3"><i class="fa  fa-align-left"></i></a>
                        <h1 class="page-title">Project</h1>                        
                    </div>
                    <div class="right">
                        <?php include 'dropdown_flex_menu.php' ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="container mt-5">
            <h4>Edit About Section</h4>
            <form method="POST">
                <div class="mb-3">
                    <label class="form-label">Section Title</label>
                    <input type="text" name="section_title" class="form-control" value="<?= htmlspecialchars($data['section_title']) ?>" required>
                </div>

                 <div class="mb-3">
                    <label class="form-label">Icon</label>
                    <input type="text" name="icon" class="form-control" value="<?= htmlspecialchars($data['icon']) ?>" required>
                </div>

                <div class="mb-3">
                    <label class="form-label">Heading</label>
                    <input type="text" name="heading" class="form-control" value="<?= htmlspecialchars($data['heading']) ?>" required>
                </div>

                <div class="mb-3">
                    <label class="form-label">Content</label>
                    <textarea name="content" class="form-control" rows="6" required><?= htmlspecialchars($data['content']) ?></textarea>
                </div>

                <button type="submit" class="btn btn-primary">Update</button>
            </form>
        </div>
                
        <div class="section-body">
            <footer class="footer">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12 col-sm-12 text-md-right">
                            <ul class="list-inline mb-0">
                                <li class="list-inline-item"><a href="doc/index.html">OM INTERIOR</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </footer>
        </div>
    </div>    
</div>

<script src="assets/bundles/lib.vendor.bundle.js"></script>

<script src="assets/bundles/apexcharts.bundle.js"></script>
<script src="assets/bundles/counterup.bundle.js"></script>
<script src="assets/bundles/knobjs.bundle.js"></script>
<script src="assets/bundles/c3.bundle.js"></script>

<script src="assets/js/core.js"></script>
<script src="assets/js/page/project-index.js"></script>
</body>
</html>
