File "product.php"

Full Path: /home/sasslijg/public_html/nc_assets/product/product.php
File size: 16.52 KB
MIME-type: text/x-php
Charset: utf-8

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

$query = "SELECT * from product";
$products =db::getRecords($query);

?>


<section id="breadcrumb-alignment">
    <div class="row">
        <div class="col-sm-12">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex justify-content-between breadcrumb-wrapper">
                        <nav aria-label="breadcrumb ">
                            <ol class="breadcrumb mt-2">
                                <li class="breadcrumb-item"><a href="javascript:void(0)"><i class='bx bx-home-alt mx-1'></i>Dashboard</a></li>
                                <li class="breadcrumb-item"><a href="javascript:void(0)">Products</a></li>
                            </ol>
                        </nav>
                        <?php
                        if($user_role=='1'){


                        ?>

                        <nav aria-label="breadcrumb ">
                            <div class="ml-auto">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-success bg-success bg-darken-2 m-1 px-5" data-toggle="modal" data-target="#add"><i class="bx bx-image-add mr-1"></i>Add Product</button>
                                </div>
                            </div>
                        </nav>
                        <?php
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- Breadcrumb Alignment Ends -->
<h2 class="mb-0 text-center h1 text-primary uppercase">Products</h2>
<hr>
<div class="row">
    <?php
    if($products!=NULL)
    {
        foreach($products as $product)
        {

            $product_id          = $product['id'];
            $query               = "SELECT * from product_image where product_id='$product_id' ";
            $product_image      = db::getRecord($query);


    ?>
    <div class="col-12 col-lg-4 col-xl-4">
        <div class="card">
            <img src="<?php echo "images/".$product_image['image_name']; ?>" height="300" width="300" class="card-img-top" alt="">
            <div class="card-body" style="height:250px;">
                <h3 class="text-primary text-center my-2">
                    <?php echo $product['name'];  ?></h3>
                <hr>
                <div class="profile-social mt-3 text-center justify-content-between d-flex">


                    <?php
            if($user_role=='1'){


                    ?>
                    <button type="button" class="btn btn-linkedin text-center bg-info bg-darken-2  text-white  float-left" data-toggle="modal" data-target="#view-product<?php echo $product['id']; ?>"><i class="fa fa-eye "></i></button>
                    <button type="button" class="btn btn-linkedin text-center bg-success bg-darken-2  text-white  float-left" data-toggle="modal" data-target="#edit_modal<?php echo $product['id']; ?>"><i class="fa fa-edit "></i></button>

                    <span onclick="delete_modal('<?php echo $product['id']; ?>')">
                        <a data-toggle="popover" data-trigger="hover" data-original-title="Delete Category" class="btn btn-pinterest "><i class="bx bx-trash"></i></a>
                    </span>
                    <?php
            }
                    ?>
                </div>
            </div>

            <div class="modal-size-lg d-inline-block">
                <!-- Modal -->
                <div class="modal fade text-left" id="view-product<?php echo $product['id']; ?>" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
                        <div class="modal-content">
                            <div class="modal-header bg-info">
                                <h4 class="modal-title my-1 text-white">Product Details</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="row justify-content-center">

                                    <?php

            $product_id= $product['id'];
            $query               = "SELECT * from product_image where product_id='$product_id' ";
            $product_images      = db::getRecords($query);
                                    ?>
                                    <div class="col-xl-6 col-lg-6 col-md-6 py-4 px-2">
                                        <div class="row justify-content-center">

                                            <div id="slide<?php echo $product['id']; ?>" class="carousel slide" data-ride="carousel">
                                                <ol class="carousel-indicators" style="background-color:#04040457;border-radius:50px;">
                                                    <?php

            if($product_images!=null){

                $count=0;


                foreach($product_images as $product_image)
                {
                    if($count==0)
                    {
                                                    ?>
                                                    <li data-target="#slide<?php echo $product['id']; ?>" data-slide-to="<?php echo $count;?>" class="active"></li>
                                                    <?php

                    }
                    else{

                                                    ?>

                                                    <li data-target="#slide<?php echo $product['id']; ?>" data-slide-to="<?php echo $count;?>"></li>
                                                    <?php
                    }
                    $count++;
                }

            }
                                                    ?>
                                                </ol>

                                                <div class="carousel-inner" role="listbox">
                                                    <?php

            if($product_images!=null){

                $count=0;


                foreach($product_images as $product_image)
                {

                    if($count == 0){
                                                    ?>
                                                    <div class="carousel-item active">
                                                        <img class="img-fluid w-100" src="<?php echo "images/".$product_image['image_name']; ?>" alt="slide" style="height:400px" />
                                                        <div class="carousel-caption">

                                                        </div>
                                                    </div>
                                                    <?php

                    }
                    else{

                                                    ?>

                                                    <div class="carousel-item">
                                                        <img class="img-fluid w-100" src="<?php echo "images/".$product_image['image_name']; ?>" alt="slide" style="height:400px" />
                                                        <div class="carousel-caption">

                                                        </div>
                                                    </div>
                                                    <?php
                    }

                    $count++;
                }

            }
                                                    ?>




                                                </div>

                                                <a class="carousel-control-prev" href="#slide<?php echo $product['id']; ?>" role="button" data-slide="prev">
                                                    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                                                    <span class="sr-only">Previous</span>
                                                </a>
                                                <a class="carousel-control-next" href="#slide<?php echo $product['id']; ?>" role="button" data-slide="next">
                                                    <span class="carousel-control-next-icon" aria-hidden="true"></span>
                                                    <span class="sr-only">Next</span>
                                                </a>

                                            </div>
                                        </div>

                                    </div>

                                    <div class="col-md-6">
                                        <h2 class="text-primary ">Name: </h2>
                                        <h5 class="card-title "><?php echo $product['name']; ?></h5>
                                       
                                        <h2 class="text-primary "> Price: </h2>
                                        <h5 class="card-title ">$<?php echo $product['price']; ?></h5>

                                        <h2 class="text-primary ">Description:</h2>
                                        <?php echo $product['description']; ?>

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

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


            <!-- Modal -->
            <div id="edit_modal<?php echo $product['id']; ?>" class="modal fade" data-backdrop="false" tabindex="-1" role="dialog" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered" role="document">
                    <div class="modal-content radius-30">
                        <div class="modal-header bg-success border-bottom-0">
                            <h4 class="modal-title my-1 text-white">Edit Products</h4>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body p-5">

                            <form action="../action.php" method="post" enctype="multipart/form-data">
                                <div class="form-group">
                                    <label class="h4">Upload Image</label>
                                    <div class="file-upload-wrapper">
                                        <input type="file" name="file[]" multiple class="form-control form-control-lg file-upload" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="h4">Name</label>
                                    <input type="text" id="edit_c_name" value="<?php echo $product['name']; ?>" name="name" class="form-control form-control-lg radius-30" required />
                                </div>
                                <div class="form-group">
                                    <label class="h4"> Price</label>
                                    <input type="text" id="pprice" name="price" value="<?php echo $product['price']; ?>" class="form-control form-control-lg radius-30" required />
                                </div>
                            
                                <div class="form-group">
                                    <label class="h4">Description</label>
                                    <textarea class="ckeditor form-control form-control-lg radius-30" name="description" rows="5"><?php echo $product['description']; ?></textarea>
                                </div>

                                <input type="text" id="edit_id" value="<?php echo $product['id']; ?>" name="edit_id" hidden>
                                <hr />
                                <div class="form-group">
                                    <button type="submit" class="btn btn-success float-right  btn-lg " name="edit_products">Update </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>
    <?php
        }
    }
    else{
        echo "Data is not Found!!";
    }
    ?>
</div>

<!-- Modal -->
<div class="modal fade" id="add" data-backdrop="false" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content radius-30">
            <div class="modal-header bg-success bg-darken-2 border-bottom-0">
                <h3 class="text-white m-1">Add Product</h3>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body p-5">

                <form action="../action.php" method="post" enctype="multipart/form-data">


                    <div class="row">
                        <div class="col-lg-12 col-md-12">
                            <div class="form-group">
                                <label class="h4">Upload Images</label>
                                <div class="file-upload-wrapper">
                                    <input type="file" name="file[]" multiple class="form-control form-control-lg file-upload" required />
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="h4">Name</label>
                        <input type="text" name="name" class="form-control form-control-lg radius-30" required />
                    </div>
                    <div class="form-group">
                        <label class="h4"> Price</label>
                        <input type="text" name="price" class="form-control form-control-lg radius-30" required />
                    </div>
                    
                    <div class="form-group">
                        <label class="h4">Description</label>
                        <textarea type="text" name="description" rows="5" class="ckeditor form-control form-control-lg radius-30" required> </textarea>
                    </div>

                    <hr />

                    <div class="form-group mt-3">

                        <button type="submit" class="btn btn-success float-right radius-30 btn-lg" name="add_new_product">Submit</button>

                    </div>

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


<!-- Modal -->
<div class="modal fade" id="delete_modal" data-backdrop="false" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content  border-0">
            <div class="modal-header bg-danger bg-darken-2 border-bottom-0">
                <h5 class="modal-title" style="color:white;">Delete Products</h5>

                <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form action="../action.php" method="POST">
                    <div class="modal-body">
                        <p class="text-danger">Are You Sure to Delete This</p>
                    </div>
                    <input type="text" id="delete_id" name="delete_id" hidden>
                    <div class="modal-footer border-top-0">
                        <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
                        <button type="submit" name="delete_products" class="btn btn-outline-danger">Delete</button>
                    </div>
                </form>
            </div>

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


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

?>

<script>


    function delete_modal(id) {

        document.getElementById("delete_id").value = id;


        $("#delete_modal").modal('show');
    }
    
</script>