<?php

if (!isset($_SESSION['admin_email'])) {

    echo "<script>window.open('login.php','_self')</script>";

} else {

?>

<div class="row"><!-- 1 row Starts -->
    <div class="col-lg-12">
        <ol class="breadcrumb">
            <li class="active">
                <i class="fa fa-dashboard"></i> Dashboard / View Product Categories
            </li>
        </ol>
    </div>
</div><!-- 1 row Ends -->

<div class="row"><!-- 2 row Starts -->
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <i class="fa fa-money fa-fw"></i> View Product Categories
                </h3>
            </div>

            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-striped">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Category Type</th> <!-- Hardware / Software -->
                                <th>Product Category</th>
                                <th>Delete</th>
                                <th>Edit</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $i = 0;

                            $get_p_cats = "
                                SELECT pc.p_cat_id, pc.p_cat_title, c.cat_type 
                                FROM product_categories pc
                                JOIN categories c ON pc.cat_id = c.cat_id
                            ";
                            $run_p_cats = mysqli_query($con, $get_p_cats);

                            while ($row_p_cats = mysqli_fetch_array($run_p_cats)) {
                                $p_cat_id = $row_p_cats['p_cat_id'];
                                $p_cat_title = $row_p_cats['p_cat_title'];
                                $cat_type = $row_p_cats['cat_type']; // Hardware or Software
                                $i++;
                            ?>
                                <tr>
                                    <td><?php echo $i; ?></td>
                                    <td><?php echo $cat_type; ?></td>
                                    <td><?php echo $p_cat_title; ?></td>
                                    <td>
                                        <a href="index.php?delete_p_cat=<?php echo $p_cat_id; ?>">
                                            <i class="fa fa-trash-o"></i> Delete
                                        </a>
                                    </td>
                                    <td>
                                        <a href="index.php?edit_p_cat=<?php echo $p_cat_id; ?>">
                                            <i class="fa fa-pencil"></i> Edit
                                        </a>
                                    </td>
                                </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div><!-- 2 row Ends -->

<?php } ?>
