<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>

<!DOCTYPE html>
<html lang="en">
<?php include ("../Header/head.php"); ?>
<body class="skin-default fixed-layout">

<div id="main-wrapper">
<?php include ("../Header/header.php"); ?>
<?php include ("../Header/left_menu.php"); ?>
<?php include ("../Header/right_sidebar.php"); ?>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.js"></script>

<div class="page-wrapper">
<div class="container-fluid">
<br><br>

<div class="row">
<div class="col-12">

<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">

<?php
$id = $_GET['id'];

$q = "SELECT *
      FROM monthly_promotion
      WHERE id = '$id'
      ORDER BY id";
$result = $mysqli->query($q);

if ($result && $result->num_rows > 0)
{
    $record = $result->fetch_assoc();

    $promotion_id = $record['id'];
    $promotion_ref_code = $record['promotion_ref_code'];
    $promotion_month = $record['promotion_month'];
    $promotion_year = $record['promotion_year'];
    $promotion_title = $record['promotion_title'];
    $promotion_image = $record['promotion_image'];
    $promotion_content = $record['promotion_content'];
}
?>

<form id="postForm" method="post" action="../Controller/Database_sql.php" enctype="multipart/form-data" onsubmit="return confirm('Do you want to proceed?');">
    <div class="form-body">
        <h3 class="card-title">Update Promotion</h3>
        <hr>

        <div class="row p-t-20">
            <div class="col-md-6">
                <div class="form-group">
                    <label class="control-label">Promotion Month</label>
                    <select name="promotion_month" class="form-control" required>
                        <?php
                        $months = array("January","February","March","April","May","June","July","August","September","October","November","December");
                        echo "<option value=\"".$promotion_month."\">".$promotion_month."</option>";
                        foreach ($months as $m) {
                            if ($m != $promotion_month) {
                                echo "<option value=\"$m\">$m</option>";
                            }
                        }
                        ?>
                    </select>
                </div>
            </div>

            <div class="col-md-6">
                <div class="form-group">
                    <label class="control-label">Promotion Year</label>
                    <select name="promotion_year" class="form-control" required>
                        <?php
                        echo "<option value=\"".$promotion_year."\">".$promotion_year."</option>";
                        for ($y = 2026; $y <= 2040; $y++) {
                            if ((string)$y != (string)$promotion_year) {
                                echo "<option value=\"$y\">$y</option>";
                            }
                        }
                        ?>
                    </select>
                </div>
            </div>

            <div class="col-md-6">
                <div class="form-group">
                    <label class="control-label">Title</label>
                    <input type="text" class="form-control" name="promotion_title" value="<?php echo $promotion_title; ?>" required>
                </div>
            </div>

            <div class="col-md-6">
                <div class="form-group">
                    <label class="control-label">Image</label>
                    <?php if ($promotion_image != "") { ?>
                        | <a href="../Controller/uploads/<?php echo $promotion_image; ?>" download><font color="blue">Download</font></a><br>
                        <img src="../Controller/uploads/<?php echo $promotion_image; ?>" width="100" height="100"><br><br>
                    <?php } ?>
                    <input type="file" class="form-control" name="promotion_image">
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group">
                    <label class="control-label">Content</label>
                    <textarea id="summernote1" name="promotion_content" rows="10"><?php echo $promotion_content; ?></textarea>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group">
                    <input type="hidden" name="promotion_id" value="<?php echo $promotion_id; ?>" required>
                    <input type="hidden" name="promotion_ref_code" value="<?php echo $promotion_ref_code; ?>" required>
                    <button name="Update_Promotion" class="btn btn-success"><i class="fa fa-check"></i> Submit</button>
                    <a href="list_of_promotion_1.php" class="btn btn-success">Back</a>
                </div>
            </div>
        </div>

    </div>
</form>

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

</div>
</div>

</div>
</div>

<?php include ("../Footer/footer.php"); ?>
</div>

<?php include ("../Header/all_jquery.php"); ?>

<script type="text/javascript">
$(document).ready(function() {
    $('#summernote1').summernote({
      toolbar: [
          ['style', ['bold', 'italic', 'underline', 'clear']],
          ['font', ['strikethrough', 'superscript', 'subscript']],
          ['fontsize', ['fontsize']],
          ['color', ['color']],
          ['para', ['ul', 'ol', 'paragraph']],
          ['table', ['table']],
          ['insert', ['link', 'video']],
          ['view', ['fullscreen', 'codeview', 'help']]
      ]
    });
});
</script>

</body>
</html>