ok

Mini Shell

Direktori : /home2/selectio/www/wedding-info-new/admin/
Upload File :
Current File : /home2/selectio/www/wedding-info-new/admin/plans_new.php

<?php
include 'header.php';

// Assuming $pdo is initialized somewhere in your code
$query = "SELECT id, name FROM categories";
$stmt = $pdo->query($query);
$categories = $stmt->fetchAll(PDO::FETCH_ASSOC);
 
$query1 = "SELECT plan_id, plan_name FROM plan_name";
$stmtq = $pdo->query($query1);
$plans = $stmtq->fetchAll(PDO::FETCH_ASSOC);



$is_edit_mode = false;
$edit_plan_id = null;

if (isset($_GET['e_id'])) {
    $is_edit_mode = true;
    $edit_plan_id = $_GET['e_id'];
    
    
    
    $statementss = $pdo->prepare("SELECT a.status as status, c.name AS category_name, b.plan_name AS plans, a.* FROM tbl_plans AS a 
        LEFT JOIN plan_name AS b ON b.plan_id = a.plan_name
        LEFT JOIN categories AS c ON c.id = a.category 
        WHERE a.id=?");
    $statementss->execute([$_GET['e_id']]);

    $plan_edit = $statementss->fetchAll(PDO::FETCH_ASSOC);

    // Fetch existing plan details for editing
    $stmt_plan = $pdo->prepare("SELECT * FROM tbl_plans WHERE id = ?");
    $stmt_plan->execute([$edit_plan_id]);
    $existing_plan = $stmt_plan->fetch(PDO::FETCH_ASSOC);
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $category = $_POST['category'];
    $plan_name = $_POST['plan_name'];
    $plan_duration = $_POST['plan_duration'];
    $leads = $_POST['leads'];
    $price = $_POST['price'];
    $content = $_POST['content'];
    $bg_color = $_POST['bg_color']; // Added background color
    $max_price = $_POST['max_price']; // Added maximum price

    if ($is_edit_mode) {
        // Update existing plan
        $statement = $pdo->prepare("UPDATE `tbl_plans` SET max_price=?, category=?, plan_name=?, plan_duration=?, price=?, content=?, bg_color=?, leads=? WHERE id = ?");
        $result = $statement->execute([$max_price, $category, $plan_name, $plan_duration, $price, $content, $bg_color, $leads, $edit_plan_id]);
    } else {
        // Insert new plan
        $statement = $pdo->prepare("INSERT INTO `tbl_plans` (max_price, category, plan_name, plan_duration, price, content, bg_color, leads) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
        $result = $statement->execute([$max_price, $category, $plan_name, $plan_duration, $price, $content, $bg_color, $leads]);
    }

    if ($result) {
        echo "Plan " . ($is_edit_mode ? "updated" : "created") . " successfully.";
    } else {
        echo "Error " . ($is_edit_mode ? "updating" : "creating") . " plan.";
    }
}
?>

<div class="page-wrapper">
    <div class="page-content">
        <form method='post' action=''>
            <?php if ($is_edit_mode): ?>
                <input type="hidden" name="edit_mode" value="true">
                <input type="hidden" name="plan_id" value="<?= $edit_plan_id ?>">
            <?php endif; ?>
            <div class="card">
                <div class="card-body p-4">
                    <center><h5 class="mb-4"><?= $is_edit_mode ? "Edit" : "Create" ?> Plan </h5></center> 
                   
                    <div class="row mb-3">
                        <label for="category" class="col-sm-3 col-form-label">Choose A Plan For</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <span class="input-group-text"><i class='bx bx-flag'></i></span>
                                <select class="form-select" id="category" name="category">
                                    <?php foreach ($categories as $cat) { ?>
                                        <option <?= ($cat['id'] == $plan_edit[0]['id'] ? "selected":"" ) ?>    value="<?= $cat['id'] ?>"><?= $cat['name'] ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <label for="plan_name" class="col-sm-3 col-form-label">Enter Plan Name</label>
                        <div class="col-sm-9">
                            <div class="input-group"> 
                                <select class="form-select" id="plan_name" name="plan_name">
                                    <option selected>Choose the Plan</option>
                                    <?php foreach ($plans as $plan) { ?>
                                        <option  <?= ($plan['plan_id'] == $plan_edit[0]['plan_name'] ? "selected":"" ) ?> value="<?= $plan['plan_id'] ?>"><?= $plan['plan_name'] ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <label for="plan_duration" class="col-sm-3 col-form-label">Plan Duration in Months</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <span class="input-group-text"><i class='bx bx-time'></i></span>
                                <input type="number" class="form-control" id="plan_duration" name='plan_duration' value='<?=$plan_edit[0]['plan_duration']?>' placeholder="Enter the months in number">
                            </div>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <label for="leads" class="col-sm-3 col-form-label">Leads</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <span class="input-group-text"><i class='bx bx-time'></i></span>
                                <input type="number" class="form-control" id="leads" name='leads' value='<?=$plan_edit[0]['leads']?>' placeholder="Enter the months in number">
                            </div>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <label for="max_price" class="col-sm-3 col-form-label">Original Price</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <span class="input-group-text"><i class='bx bx-dollar'></i></span>
                                <input type="number" class="form-control" id="max_price" name='max_price' value='<?=$plan_edit[0]['max_price']?>' placeholder="Price">
                            </div>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <label for="price" class="col-sm-3 col-form-label">Final Price</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <span class="input-group-text"><i class='bx bx-dollar'></i></span>
                                <input type="number" class="form-control" id="price" name='price' value='<?=$plan_edit[0]['price']?>' placeholder="Price">
                            </div>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <label for="content" class="col-sm-3 col-form-label">Content</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <span class="input-group-text"><i class='bx bx-envelope'></i></span>
                                <textarea name='content' id='content' class='form-control'><?=$plan_edit[0]['content']?></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <label for="bg_color" class="col-sm-3 col-form-label">Background-color</label> <!-- Corrected label -->
                        <div class="col-sm-9">
                            <div class="input-group">
                                <span class="input-group-text"><i class='bx bx-envelope'></i></span>
                                <input type="text" name="bg_color" id="bg_color" class="form-control" value='<?=$plan_edit[0]['bg_color']?>' placeholder="Enter background color" />
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <label class="col-sm-3 col-form-label"></label>
                        <div class="col-sm-9">
                            <div class="d-md-flex d-grid align-items-center gap-3">
                                 <button type="submit" class="btn btn-primary"><?= $is_edit_mode ? "Update" : "Submit" ?></button>
                        </div>
                    </div>
                </div>
            </div>  
        </form>
    </div>
</div>

<?php include 'footer.php'; ?>

Zerion Mini Shell 1.0