<?php include("auth.php");

require("conn.php");
$action = "Add";
$id = null;

if (isset($_GET['action'])) {
    $action = base64_decode($_GET['action']);
    $id = base64_decode($_GET['id']);

    $sql = "select * from tbl_post where id='$id'";
    $smt = mysqli_query($conn, $sql);
    $row = mysqli_fetch_assoc($smt);
}

?>

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

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title> Post </title>
    <meta content="" name="description">
    <meta content="" name="keywords">
    <link href="assets/img/favicon.png" rel="icon">
    <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
    <?php include("templates/inc.php"); ?>

    <script src="scripts/post.js" type="text/javascript" language="javascript"></script>


</head>

<body>

    <!-- ======= Header ======= -->
    <?php
    include("templates/header.php");
    ?>

    <!-- End Header -->

    <!-- ======= Sidebar ======= -->
    <?php
    include("templates/sidebar.php");

    ?>
    <!-- End Sidebar-->

    <main id="main" class="main">

        <div class="pagetitle">
            <h1>Post Upload</h1>
            <nav>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
                    <li class="breadcrumb-item">Post Uplod</li>

                </ol>
            </nav>
            <hr>
            <nav>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a href="post-list.php">
                            <button type="button" class="btn btn-sm btn-success"><i class="bi bi-arrow-left me-1"></i>View List</button>
                        </a>
                    </li>

                </ol>
            </nav>
        </div><!-- End Page Title -->

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

                    <div class="card">
                        <div class="card-body">
                            <div class="card-body">
                                <h5 class="card-title">Add New / Update</h5>

                                <!-- Custom Styled Validation -->
                                <form id="post" action="post-action.php" class="row g-3 needs-validation" novalidate="">

                                    <div class="col-md-6">
                                        <label for="validationCustom01" class="form-label"><b>Vendor ID</b></label>
                                        <input value="<?php echo $_SESSION['v_code']; ?>" type="text" class="form-control" id="v_code" name="v_code" readonly="readonly" style="background-color:#ccc">

                                    </div>



                                    <div class="col-md-6">
                                        <label for="validationCustom01" class="form-label"><b>State</b></label>
                                        <select class="form-select" id="state" name="state" required="">
                                            <option value="Jharkhand ">Jharkhand </option>

                                        </select>


                                    </div>

                                    <div class="col-md-6">
                                        <label for="validationCustom01" class="form-label"><b>District*</b></label>

                                        <select type="Select" class="form-select" id="district" name="district">
                                            <!-- <option selected="salacted" value="0">Choose...</option> -->
                                            <option value="Ranchi">Ranchi</option>
                                            <option value="Chatra">Chatra</option>
                                            <option value="Deoghar">Deoghar</option>
                                            <option value="Dhanbad">Dhanbad</option>
                                            <option value="Dumka">Dumka</option>
                                            <option value="East Singhbhum">East Singhbhum</option>
                                            <option value="Garhwa">Garhwa</option>
                                            <option value="Giridih">Giridih</option>
                                            <option value="Godda">Godda</option>
                                            <option value="Gumla">Gumla</option>
                                            <option value="Hazaribagh">Hazaribagh</option>
                                            <option value="Jamtara">Jamtara</option>
                                            <option value="Jamshedpur">Jamshedpur</option>
                                            <option value="Khunti">Khunti</option>
                                            <option value="Kodarma">Kodarma</option>
                                            <option value="Latehar">Latehar</option>
                                            <option value="Lohardaga">Lohardaga</option>
                                            <option value="Pakur">Pakur</option>
                                            <option value="Palamu">Palamu</option>
                                            <option value="Ramgarh">Ramgarh</option>
                                            <option value="Bokaro">Bokaro</option>
                                            <option value="Sahibganj">Sahibganj</option>
                                            <option value="Saraikela Kharsawan">Saraikela Kharsawan</option>
                                            <option value="Simdega">Simdega</option>
                                            <option value="West Singhbhum">West Singhbhum</option>
                                        </select>


                                    </div>



                                    <div class="col-md-6">
                                        <label for="validationCustom01" class="form-label"><b>Area</b></label>
                                        <input value="<?php if (isset($_GET['id'])) echo $row['area']; ?>" type="text" class="form-control" id="area" name="area" required="">
                                        <div class="invalid-feedback">
                                            Please provide a Area.
                                        </div>
                                    </div>



                                    <div class="col-md-6">
                                        <label for="validationDefault04" class="form-label">Category Type</label>
                                        <select class="form-select" id="category" name="category" required="">

                                            <?php
                                            include("conn.php");
                                            $sql = "select * from tbl_vendorcategory order by id asc";
                                            $smt = mysqli_query($conn, $sql);
                                            while ($rs = mysqli_fetch_assoc($smt)) {
                                                if ($rs['id'] == $row['id'])
                                                    echo '<option value="' . $rs['type'] . '" selected>' . $rs['type'] . '</option>';
                                                else
                                                    echo '<option value="' . $rs['type'] . '">' . $rs['type'] . '</option>';
                                            }
                                            ?>

                                        </select>
                                    </div>

                                    <div class="col-md-6">
                                        <label for="validationCustom01" class="form-label"><b>Title</b></label>
                                        <input value="<?php if (isset($_GET['id'])) echo $row['title']; ?>" type="text" class="form-control" id="title" name="title" required="">
                                        <div class="invalid-feedback">
                                            Please provide a Title.
                                        </div>
                                    </div>

                                  
                                    <div class="col-md-12">
                                        <label for="validationCustom01" class="form-label"><b>Post Desciption</b></label>
                                        <textarea type="text" class="form-control" id="des" name="des" required=""><?php if (isset($_GET['id'])) echo $row['des']; ?></textarea>
                                        <div class="invalid-feedback">
                                            Please provide Description.
                                        </div>
                                    </div>




                                  
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="formFileMultiple" class="form-label"><b> Event Picture</b></label>
                                            <input class="form-control" value="<?php if (isset($_GET['id'])) echo $row['event_url'] ?>" type="file" id="event_url" name="event_url" multiple />
                                            <span id="uploaded_event_url"></span><br>
                                        </div>
                                    </div>


                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="formFileMultiple" class="form-label"><b> Event Expire Date</b></label>
                                            <input class="form-control" value="<?php if (isset($_GET['id'])) echo $row['e_date'] ?>" type="date" id="e_date" name="e_date" multiple />
                                        </div>
                                    </div>



                                    <div class="col-12">
                                        <input type="hidden" name="id" id="id" value="<?php echo $id; ?>" />
                                        <input type="hidden" name="action" id="action" value="<?php echo $action; ?>" />
                                        <?php if (isset($_GET['id'])) {
                                        ?>
                                            <button class="btn btn-lg btn-primary btn-lg" type="submit">Update</button>
                                            <a href="post-list.php"><button class="btn btn-lg btn-danger btn-lg" type="button">Cancel</button></a>
                                        <?php
                                        } else {
                                        ?>

                                    <button class="btn btn-primary  btn-lg" type="submit">Add New</button>
                                    <a href="post-list.php"><button class="btn btn-danger  btn-lg" type="button">Cancel</button></a>
                                        <?php
                                        }
                                        ?>
                                        <br>
                                        <h4 id="msg"></h4>
                                    </div>
                                </form><!-- End Custom Styled Validation -->

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

                </div>
            </div>

        </section>

    </main><!-- End #main -->

    <!-- ======= Footer ======= -->
    <?php
    include("templates/footer.php");
    ?>
    <!-- End Footer -->


    <?php include("templates/vendors.php"); ?>

</body>

</html>