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j '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u403625155/domains/connecttogetherwith.com/public_html/admin/celebs.php

<?php
require "header.php";
?>
<style>
    th{
        color:#000 !important;
    }
</style>

<div class="row">
    <div class="col-12">
        <div class="card bg-white">
            <div class="card-header h3 text-dark">
                Celebrities
                <button class="float-end btn btn-primary" data-bs-toggle="modal" data-bs-target="#create-modal">
                   + Create Celebrity
                </button>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table" id="table">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Description</th>
                                <th>Category</th>
                                <th>Membership Fee</th>
                                <th>Edit</th>
                                <th>Delete</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                      $get_users = mysqli_query($conn, "SELECT c.*, cat.name AS category_name FROM celebrities c INNER JOIN categories cat ON c.category_id = cat.id ORDER BY c.id DESC");
                      if(mysqli_num_rows($get_users)>0){
                                    while($task=mysqli_fetch_assoc($get_users)){
                                       $id=$task['id'];
                                        $name=$task['name'];
                                        $desc=$task['description'];
                                        $fee=$task['fee'];
                                        $cat=$task['category_name'];
                                        ?>

                                        <tr>
                                            <td><?php echo $name; ?></td>
                                            <td><?php echo $desc; ?></td>
                                            
                                            <td><?php echo $cat; ?></td>
                                            <td>$<?php echo $fee; ?></td>
                                            <td><button value="<?php echo $id; ?>" class="btn btn-primary" ><i class="bx bx-pencil" data-bs-toggle="modal" data-bs-target="#package-<?php echo $id; ?> "></i></button></td>
              
<td>
    <button value="<?php echo $id; ?>" class="btn btn-danger delete-btn" onclick="confirmDelete(<?php echo $id; ?>)">
        <i class="bx bx-trash"></i>
    </button>
</td>

                                        </tr>
                                        <?php
                                    }
                                }
                                ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>



<?php
                        $get_users = mysqli_query($conn, "SELECT c.*, cat.name AS category_name FROM celebrities c INNER JOIN categories cat ON c.category_id = cat.id ORDER BY c.id DESC");
                        if(mysqli_num_rows($get_users)>0){
                                    while($task=mysqli_fetch_assoc($get_users)){
                                        $id=$task['id'];
                                        $name=$task['name'];
                                        $desc=$task['description'];
                                        $fee=$task['fee'];
                                        $cat=$task['category_name'];
                                        ?>


                                        <div class="modal fade" id="package-<?php echo $id; ?>">
                                            <div class="modal-dialog modal-dialog-centered">
                                                <div class="modal-content">
                                                    <div class="modal-header h3 text-dark">
                                                        Edit Celebrity
                                                        <button class="btn btn-close" data-bs-dismiss="modal"></button>
                                                    </div>
                                                    <div class="modal-body">
                                                        <form method="post" enctype="multipart/form-data">
                                                        <input type="hidden" name="id"  value="<?php echo $id; ?>"/>
                                                        
                                                        <div class="form-group my-2">
                                                            <label class="form-label">
                                                                Name
                                                            </label>
                                                            <input type="text" name="name" class="form-control" value="<?php echo $name; ?>"/>
                                                        </div>
                                                        <div class="form-group my-2">
                                                            <label class="form-label">
                                                               Celebrity Description / Bio
                                                            </label>
                                                           <textarea name="description"  cols="5" rows="5" class="form-control" ><?php echo $desc; ?></textarea>
                                                          
                                                        </div>

                                                        <div class="form-group my-2">
                                                            <label class="form-label">
                                                                Membership Fee
                                                            </label>
                                                            <input type="text" name="fee" class="form-control" value="<?php echo $fee; ?>"/>
                                                        </div>

                                                        <div class="form-group my-2">
                                                        <label class="form-label">
                                                               Select Category
                                                            </label>
                                                            <select name="category" id="" class="form-control">

    <?php
    $get_categories = mysqli_query($conn, "SELECT * FROM categories ORDER BY id DESC");
    if (mysqli_num_rows($get_categories) > 0) {
        while ($category = mysqli_fetch_assoc($get_categories)) {
            $category_name = $category['name'];
            $category_id = $category['id'];
            echo '<option value="' . $category_id . '">' . $category_name . '</option>';
        }
    }
    ?>
</select>

                                                        </div>



                                                        <div class="form-group my-2">
                                <label class="form-label">
                                    Celebrity Image
                                </label>
                                <input type="file" name="new_image1" class="form-control"/>
                            </div>
                               
                              

                                                    


                                                        <div class="form-group m-3">
                                                            <button name="edit" class="btn btn-primary">
                                                                Edit Celebrity
                                                            </button>
                                                        </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>


<?php
                                    }
                                }
                                ?>

<div class="modal fade" id="create-modal">
                                            <div class="modal-dialog modal-dialog-centered">
                                                <div class="modal-content">
                                                    <div class="modal-header h3 text-dark">
                                                        Create Celebrity
                                                        <button class="btn btn-close" data-bs-dismiss="modal"></button>
                                                    </div>
                                                    <div class="modal-body">
                                                        <form method="post" enctype="multipart/form-data">
                                                        <div class="form-group my-2">
                                                            <label class="form-label">
                                                                Celebrity Name
                                                            </label>
                                                            <input type="text" name="name" class="form-control" required/>
                                                        </div>
                                                       
                                                        <div class="form-group my-2">
                                                            <label class="form-label">
                                                               Celebrity Description / Bio
                                                            </label>
                                                           <textarea name="description"  cols="5" rows="5" class="form-control" required></textarea>
                                                          
                                                        </div>

                                                        <div class="form-group my-2">
                                                            <label class="form-label">
                                                                Membership Fee
                                                            </label>
                                                            <input type="text" name="fee" class="form-control" required/>
                                                        </div>

                                                       
                                                        <div class="form-group my-2">
                                                        <label class="form-label">
                                                               Select Category
                                                            </label>
                                                            <select name="category" id="" class="form-control" required>
    <option value="">Select Category</option>
    <?php
    $get_categories = mysqli_query($conn, "SELECT * FROM categories ORDER BY id DESC");
    if (mysqli_num_rows($get_categories) > 0) {
        while ($category = mysqli_fetch_assoc($get_categories)) {
            $category_name = $category['name'];
            $category_id = $category['id'];
            echo '<option value="' . $category_id . '">' . $category_name . '</option>';
        }
    }
    ?>
</select>

                                                        </div>

                                                      
                                            
                                                     
                                                        <div class="form-group my-2">
                                                            <label class="form-label">
                                                                Image
                                                            </label>
                                                            <input type="file" name="image" class="form-control" />
                                                        </div>
                                                       

                                                        <div class="form-group m-3">
                                                            <button name="create" class="btn btn-primary">
                                                                Create Celebrity
                                                            </button>
                                                        </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>






<?php
require "footer.php";


if(isset($_POST['edit'])) {
    $id = mysqli_real_escape_string($conn, $_POST['id']);
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $description = mysqli_real_escape_string($conn, $_POST['description']);
    $category = mysqli_real_escape_string($conn, $_POST['category']);
    $fee = mysqli_real_escape_string($conn, $_POST['fee']);


    if (!empty($_FILES['new_image1']['name'])) {
        $new_image_name = $_FILES['new_image1']['name'];
        $new_image_tmp = $_FILES['new_image1']['tmp_name'];
        
        $unique_filename = uniqid() . '_' . $new_image_name; 
        $target_file = "../celebs/" . basename($unique_filename); 

        if (move_uploaded_file($new_image_tmp, $target_file)) {
            $update_image = mysqli_query($conn, "UPDATE celebrities SET image_url='$unique_filename' WHERE id='$id'");
            if (!$update_image) {
           echo '<script>
            swal({
                title: "Error!",
                text: "An error occurred while updating the image.",
                icon: "error",
                button: "OK"
            });
          </script>';
            }
        } else {
                echo '<script>
            swal({
                title: "Error!",
                text: "Error Uploading Images.",
                icon: "error",
                button: "OK"
            });
          </script>';
        }
    }

    $update = mysqli_query($conn, "UPDATE celebrities SET name='$name', description='$description', fee='$fee', category_id='$category' WHERE id='$id'");

if ($update) {
    echo '<script>
            swal({
                title: "Success!",
                text: "Celebrity updated successfully.",
                icon: "success",
                button: "OK"
            }).then(function() {
                window.location.replace("celebs");
            });
          </script>';
    exit();
} else {
    echo '<script>
            swal({
                title: "Error!",
                text: "An error occurred while updating the celebrity.",
                icon: "error",
                button: "OK"
            });
          </script>';
}
}



if(isset($_POST['create'])) {
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $description = mysqli_real_escape_string($conn, $_POST['description']);
    $category = mysqli_real_escape_string($conn, $_POST['category']);
    $fee = mysqli_real_escape_string($conn, $_POST['fee']);

    $image_name = $_FILES['image']['name'];
    $image_tmp = $_FILES['image']['tmp_name'];
    $target_dir = "../celebs/";
    $unique_filename = uniqid() . '_' . $image_name;
    $target_file = $target_dir . basename($unique_filename);
    
    if(move_uploaded_file($image_tmp, $target_file)) {
        $insert_query = "INSERT INTO celebrities (name, description, fee, category_id, image_url) VALUES ('$name', '$description', '$fee', '$category', '$unique_filename')";
        $insert_result = mysqli_query($conn, $insert_query);

        if($insert_result) {
            echo '<script>
                    swal({
                        title: "Success!",
                        text: "Celebrity created successfully.",
                        icon: "success",
                        button: "OK"
                    }).then(function() {
                        window.location.replace("celebs");
                    });
                  </script>';
            exit();
        } else {
            echo '<script>
                    swal({
                        title: "Error!",
                        text: "An error occurred while creating the celebrity.",
                        icon: "error",
                        button: "OK"
                    });
                  </script>';
        }
    } else {
        echo '<script>
                swal({
                    title: "Error!",
                    text: "Error uploading image.",
                    icon: "error",
                    button: "OK"
                });
              </script>';
    }
}
?>



<script>
function confirmDelete(id) {
    swal({
        title: "Are you sure?",
        text: "Once deleted, you will not be able to recover this Celebrity!",
        icon: "warning",
        buttons: true,
        dangerMode: true,
    })
    .then((willDelete) => {
        if (willDelete) {
            deletePackage(id);
        }
    });
}

function deletePackage(id) {
    $.ajax({
        type: 'POST',
        url: 'delete.php', 
        data: {
            delete: true,
            id: id  
        },
        success: function (response) {
            swal('Great', 'Celebrity Deleted', 'success')
                .then(() => {
                    location.replace('celebs')
                });
        },
        error: function () {
            swal('Oops', 'An error occurred while deleting', 'error');
        }
    });
}
</script>
Back to Directory=ceiIENDB`