<?php
    // session_start();
    include "../db.php";
    require '../auth.php';
    restrictAccess(['Employee']);
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('M j, Y g:i a');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {
        header("Location: logout.php");
        exit();
    }

    $userDetails_sql = mysqli_query($con, "SELECT * FROM users WHERE uid = '$_SESSION[uid]' ");
    if($userDetails_row = mysqli_fetch_assoc($userDetails_sql)){
        $userName = $userDetails_row["uname"];
        $userState_id = $userDetails_row["state"];
        $userDist_id = $userDetails_row["dist"];
        $admin_ref = $userDetails_row["admin_ref"];
    }
?>

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

<head>
    <?php include "include/meta.php"; ?>
    <?php include "include/css.php"; ?>
    <?php include "include/php-functions.php"; ?>
</head>

<body>
    <!--  Header -->
    <?php 
    include "include/header.php"; 
    ?>
    <!-- #header -->

    <section id="inner-body">
        <div class="body-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-3 col-md-3 col-12 mb-2">
                        <a href="view-franchiee.php" class="text-dark" style="text-decoration:none;">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-md-9 col-8">
                                            <h5 class="card-title text-uppercase color-4b4be9">Associate</h5>
                                        </div>
                                        <div class="col-md-3 col-4">
                                            <div class="text-end">
                                                <h2 class="color-f25f00">
                                                    <i class="fa fa-handshake"></i>
                                                </h2>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>
                    <div class="col-lg-3 col-md-3 col-12 mb-2">
                        <a href="view-productList.php" class="text-dark" style="text-decoration:none;">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-md-9 col-8">
                                            <h5 class="card-title text-uppercase color-4b4be9">Assigned Works</h5>
                                        </div>
                                        <div class="col-md-3 col-4">
                                            <div class="text-end">
                                                <h2 class="color-f25f00">
                                                    <i class="fab fa-product-hunt"></i>
                                                </h2>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>
                    <div class="col-lg-3 col-md-3 col-12 mb-2">
                        <a href="service.php?show_list" class="text-dark" style="text-decoration:none;">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-md-9 col-6">
                                            <h5 class="card-title text-uppercase color-4b4be9">Courses</h5>
                                        </div>
                                        <div class="col-md-3 col-6">
                                            <div class="text-end">
                                                <h2 class="color-f25f00">
                                                    <i class="fa fa-chalkboard"></i>
                                                </h2>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>
                    <div class="col-lg-3 col-md-3 col-12 mb-2">
                        <a href="view-colleges.php" class="text-dark" style="text-decoration:none;">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row align-items-center">
                                        <div class="col-md-9 col-6">
                                            <h5 class="card-title text-uppercase color-4b4be9">Colleges</h5>
                                        </div>
                                        <div class="col-md-3 col-6">
                                            <div class="text-end">
                                                <h2 class="color-f25f00">
                                                    <i class="fa fa-school"></i>
                                                </h2>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>
                </div>
                <div class="row mt-2">
                    <div class="col-lg-6 col-md-6 col-12 mb-3">
                        <div class="card" id="organization-card">
                            <div class="card-body">
                                <div class="title-org">
                                    <h3 class="h-underline m-0">Notice List</h3>
                                    <span><a href="notice.php">View All</a></span>
                                </div>
                                <ul class="mt-3">
                                    <?php 
                                      $org_sql = mysqli_query($con, "SELECT * FROM notice WHERE admin_ref = '$admin_ref' AND notice_recycle = '1' AND notice_for = 'All' OR notice_for = 'Employee' ORDER BY notice_id DESC LIMIT 4");
                                      while($org_row = mysqli_fetch_assoc($org_sql)){
                                        if(($org_row["notice_state"] == "" OR $org_row["notice_state"] == $userState_id) && ($org_row["notice_dist"] == "" OR $org_row["notice_dist"] == $userDist_id) ){
                                    ?>
                                    <li class="mb-2">
                                        <div class="organization-preview ">
                                            <h5><i class="fa fa-bell"></i>
                                                &nbsp;<?php echo $org_row["notice_title"];?></h5>
                                        </div>
                                    </li>
                                    <?php } }?>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-12 mb-3">
                        <div class="card" id="blog-card">
                            <div class="card-body">
                                <div class="title-org">
                                    <h3 class="h-underline m-0">Recent News</h3>
                                    <span><a href="news.php?show_list">View All</a></span>
                                </div>
                                <ul class="mt-3">
                                    <?php
                                        $sql = "SELECT * FROM data WHERE data_catagory = 'news' AND data_recycle = '1' ORDER BY data_sl_no DESC LIMIT 4";
                                        $run = mysqli_query($con, $sql);

                                        $c = 1;
                                        while ( $rows = mysqli_fetch_assoc($run) ) {
                                    ?>
                                    <li class="mb-2">
                                        <a href="news.php?view_id=<?php echo $rows["data_sl_no"];?>"
                                            style="text-decoration:none;">
                                            <div class="blog-preview">
                                                <div class="row">
                                                    <div class="col-lg-3 col-md-3 col-3">
                                                        <img src="<?php echo $rows["data_img"];?>" class="img-fluid"
                                                            alt="<?php echo $rows['data_title']; ?>">
                                                    </div>
                                                    <div class="col-lg-9 col-md-9 col-9">
                                                        <h6 class="m-0"><?php echo $rows['data_title']; ?></h6>
                                                        <p class="m-0">
                                                            <?php echo substr($rows['data_short_des'], 0, 100); ?>...
                                                        </p>
                                                    </div>
                                                </div>
                                            </div>
                                        </a>
                                    </li>
                                    <?php $c++; }?>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <?php include "include/footer.php"; ?>
    </section>

    <!-- JavaScript Libraries -->

    <?php include "include/js.php"; ?>


</body>

</html>