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

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin : View Task</title>
    <?php include("headerlink.php") ?>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
</head>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">

        <div class="preloader flex-column justify-content-center align-items-center">
            <img class="animation__shake" src="dist/img/AdminLTELogo.png" alt="AdminLTELogo" height="60" width="60">
        </div>

        <?php include("navbar.php") ?>


        <?php include("sidebar.php") ?>

        <div class="content-wrapper">

            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0 fw-bold text-uppercase">Task</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item active">Task</li>
                                <li class="breadcrumb-item active">View All</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>

            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-12">
                            <div class="card shadow">
                                <div class="card-header" style="background: #343a40; ">
                                    <h3 class="card-title text-white text-bold text-uppercase">Group View All task</h3>
                                </div>

                                <div class="card-body">
                                    <div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4">
                                        <div class="row">
                                            <div class="col-sm-12 col-md-6"></div>
                                            <div class="col-sm-12 col-md-6"></div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <table class="table-responsive">
                                                    <table id="example2" class="table table-bordered table-hover text-center">
                                                        <thead>
                                                            <tr>
                                                                <th>Sr No.</th>
                                                                <th>Date &amp; time</th>
                                                                <th>Task Title</th>
                                                                <th>Platform</th>
                                                                <th>Group Name</th>
                                                                <th>Total Assign</th>
                                                                <th>CTM</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php
                                                            include('connection.php');
                                                            $sql = "SELECT * FROM group_add_task";
                                                            $query = mysqli_query($conn, $sql);

                                                            $Sr = 1;
                                                            while ($row = mysqli_fetch_assoc($query)) {
                                                                $group = $row['group_id'];
                                                                $sel = "SELECT * FROM groups where group_name ='$group'";
                                                                $res = mysqli_query($conn, $sel);
                                                                $total_member_count = 0;

                                                                while ($fetch = mysqli_fetch_assoc($res)) {
                                                                    $membersList = $fetch['member'];
                                                                    $membersArray = explode(',', $membersList);
                                                                    $total_member_count = count($membersArray);
                                                                }
                                                            ?>
                                                                <tr>
                                                                    <td><?php echo $row['id'] ?></td>
                                                                    <td><?php echo $row['datetime']; ?></td>
                                                                    <td>
                                                                        <a type="button" class="btn-sm btn btn-danger text-uppercase" style="text-decoration: none;width:130px" data-toggle="modal" data-target="#detailsModal<?php echo $row['id']; ?>">
                                                                            <?php echo $row['title']; ?>
                                                                        </a>
                                                                    </td>
                                                                    <td><?php echo $row['platform']; ?></td>
                                                                    <td> <!-- Button trigger modal -->
                                                                        <a type="button" class="btn btn-primary btn-sm" style="width: 100px;" data-toggle="modal" data-target="#exampleModalCenter<?php echo $row['id']; ?>">
                                                                            <?php echo $row['group_id'] ?>
                                                                        </a>
                                                                    </td>
                                                                    <!-- Modal -->

                                                                    <?php
                                                                    $group = $row['group_id'];
                                                                    $sel = "SELECT * FROM groups where group_name ='$group'";
                                                                    $res = mysqli_query($conn, $sel);
                                                                    while ($fetch = mysqli_fetch_assoc($res)) {
                                                                    ?>
                                                                        <div class="modal fade" id="exampleModalCenter<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                                                            <div class="modal-dialog modal-dialog-centered" role="document">
                                                                                <div class="modal-content">
                                                                                    <div class="modal-header">
                                                                                        <h5 class="modal-title fw-bold" id="exampleModalLongTitle">Group Name : <?php echo $fetch['group_name'] ?></h5>
                                                                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                                            <span aria-hidden="true">&times;</span>
                                                                                        </button>
                                                                                    </div>
                                                                                    <div class="modal-body">
                                                                                        <?php echo $fetch['member']; ?>
                                                                                    </div>
                                                                                    <div class="modal-footer">
                                                                                        <button type="button" class="btn btn-dark" data-dismiss="modal">Close</button>

                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    <?php } ?>
                                                                    <td><?php echo $total_member_count; ?></td>
                                                                    <?php
                                                                    $group = $row['group_id'];
                                                                    $sql = "SELECT COUNT(*) as count FROM update_all_task WHERE `group` = '$group' AND `status` = 'complete'";
                                                                    $query2 = mysqli_query($conn, $sql);
                                                                    $row2 = mysqli_fetch_assoc($query2);
                                                                    $completeCount = $row2['count'];
                                                                    ?>

                                                                    <!-- <td><?php echo $completeCount; ?></td> -->
                                                                    <!-- Button trigger modal -->

                                                                    <td>
                                                                        <a type="button" class="btn btn-info btn-sm" style="width: 100px;" data-toggle="modal" data-target="#groupModal<?php echo $row['group_id']; ?>">
                                                                            <?php echo $completeCount; ?>
                                                                        </a>
                                                                    </td>

                                                                    <!-- Modal with a unique ID -->
                                                                    <div class="modal fade" id="groupModal<?php echo $row['group_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="groupModalTitle" aria-hidden="true">
                                                                        <div class="modal-dialog modal-dialog-centered" role="document">
                                                                            <div class="modal-content">
                                                                                <div class="modal-header">
                                                                                    <h5 class="modal-title" id="groupModalTitle">Complete Employee IDs for Group: <?php echo $row['group_id']; ?></h5>
                                                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                                        <span aria-hidden="true">&times;</span>
                                                                                    </button>
                                                                                </div>
                                                                                <div class="modal-body">
                                                                                    <?php
                                                                                    $group = $row['group_id'];
                                                                                    $sql = "SELECT employee_id FROM update_all_task WHERE status = 'complete' AND `group` = '$group'";
                                                                                    $result = mysqli_query($conn, $sql);
                                                                                    while ($row2 = mysqli_fetch_array($result)) {
                                                                                        echo '<p><strong>Employee ID:</strong> ' . $row2["employee_id"] . '</p>';
                                                                                    }
                                                                                    ?>
                                                                                </div>
                                                                                <div class="modal-footer">
                                                                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>





                                                                </tr>
                                                            <?php
                                                                $Sr++;
                                                            }
                                                            ?>
                                                        </tbody>
                                                    </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
                <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
                <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
                <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
                <!-- member view all task -->
                <section class="content py-5">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-12">
                                <div class="card shadow">
                                    <div class="card-header" style="background: #343a40; ">
                                        <h3 class="card-title text-white text-bold text-uppercase">Member View All Task</h3>
                                    </div>
                                    <!-- /.card-header -->
                                    <div class="card-body">
                                        <div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4">
                                            <div class="row">
                                                <div class="col-sm-12 col-md-6"></div>
                                                <div class="col-sm-12 col-md-6"></div>
                                            </div>
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <table class="table-responsive">
                                                        <table id="example3" class="table table-bordered table-hover text-center">
                                                            <thead>
                                                                <tr>
                                                                    <th>Sr No.</th>
                                                                    <th>Date &amp; time</th>
                                                                    <th>Task Title</th>
                                                                    <th>Platform</th>
                                                                    <th>Member</th>
                                                                    <th>Total Assign</th>
                                                                    <th>CTM</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php
                                                                include('connection.php');
                                                                $sql = "SELECT * FROM member_add_task";
                                                                $query = mysqli_query($conn, $sql);
                                                                  while($row = mysqli_fetch_assoc($query)){
                                                                 ?>
                                                                    <tr>
                                                                        <td><?php echo $row['id'] ?></td>
                                                                        <td><?php echo $row['datetime']; ?></td>
                                                                        <td>
                                                                            <a type="button" class="btn btn-sm btn-danger text-uppercase" style="text-decoration: none; width: 120px;" data-toggle="modal" data-target="#detailsModal<?php echo $row['id']; ?>">
                                                                                <?php echo $row['title'] ?>
                                                                            </a>
                                                                        </td>
                                                                        <td><?php echo $row['platform']; ?></td>

                                                                        <td>
                                                                            <a type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#memberModal<?php echo $row['id']; ?>">
                                                                                <?php echo $row['member'] ?>
                                                                            </a>
                                                                        </td>
                                                                        <?php
                                                                        $group = $row['member'];
                                                                        $res1 = "SELECT * FROM add_employee WHERE employee_id='$group'";
                                                                        $query1 = mysqli_query($conn, $res1);
                                                                        while ($fetch = mysqli_fetch_assoc($query1)) {
                                                                        ?>
                                                                            <!-- Modal -->
                                                                            <div class="modal fade" id="memberModal<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                                                <div class="modal-dialog" role="document">
                                                                                    <div class="modal-content">
                                                                                        <div class="modal-header">
                                                                                            <h5 class="modal-title" id="exampleModalLabel">Member Id : <?php echo $fetch['employee_id'] ?></h5>
                                                                                            <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">
                                                                                                <div class="col-2">
                                                                                                    Name :
                                                                                                </div>
                                                                                                <div class="col-10">
                                                                                                    <p><?php echo $fetch['name']; ?></p>
                                                                                                </div>
                                                                                            </div>
                                                                                            <div class="row">
                                                                                                <div class="col-2">
                                                                                                    Contact :
                                                                                                </div>
                                                                                                <div class="col-10">
                                                                                                    <p><?php echo $fetch['number1']; ?></p>
                                                                                                </div>
                                                                                            </div>
                                                                                            <div class="row">
                                                                                                <div class="col-2">
                                                                                                    Email :
                                                                                                </div>
                                                                                                <div class="col-10">
                                                                                                    <p><?php echo $fetch['email1']; ?></p>
                                                                                                </div>
                                                                                            </div>

                                                                                        </div>
                                                                                        <div class="modal-footer">
                                                                                            <button type="button" class="btn btn-dark" data-dismiss="modal">Close</button>

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

                                                                            <?php
                                                                            include('connection.php');

                                                                            // Define the 'id' you want to count, replace 'YOUR_ID' with the actual value

                                                                            $id = $row['member'];

                                                                            // Count how many times the specified member ID appears in the 'member' column
                                                                            $sel2 = "SELECT COUNT(*) AS member_count FROM member_add_task WHERE member='$id'";
                                                                            $query2 = mysqli_query($conn, $sel2);
                                                                            $row = mysqli_fetch_assoc($query2);
                                                                            $member_count = $row['member_count'];

                                                                            echo '<td>';
                                                                            echo "$member_count";
                                                                            echo '</td>';
                                                                            ?>

<?php
// Assuming you have a database connection established in $conn

$query3 = "SELECT COUNT(*) AS status_count FROM member_update_task";
$result3 = mysqli_query($conn, $query3);

if ($result3) {
    $row3 = mysqli_fetch_assoc($result3);
    $status_count = $row3['status_count'];
    echo '<td>' . $status_count . '</td>';
} else {
    echo '<td>Error fetching count</td>';
}
?>







                                                                        <!-- Modal with a unique ID -->






                                                                    </tr>
                                                                <?php
                                                                    $Sr++;
                                                                }
                                                                ?>
                                                            </tbody>
                                                        </table>
                                                </div>
                                            </div>

                                        </div>
                                    </div>

                                </div>

                            </div>

                        </div>

                    </div>

                </section>

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

    <!-- member task title model start here -->
    <?php
    include('connection.php');
    $sql = "SELECT * FROM member_add_task";
    $query = mysqli_query($conn, $sql);
    while ($row = mysqli_fetch_assoc($query)) {
    ?>
        <div class="modal fade" id="detailsModal<?php echo $row['id']; ?>">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header" style="background: #343a40; ">
                        <h4 class="modal-title fw-bold text-uppercase text-white">Member Id : <?php echo $row['member'] ?></h4>
                        <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form action="update_leads_code.php" method="POST">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-8">
                                        <video width="300" height="200" controls>
                                            <source src="../AdminLt/<?php echo $row['video']; ?>" type="video/mp4">
                                        </video>
                                    </div>

                                    <div class="col-4">
                                        <img src="../AdminLt/<?php echo $row['image']; ?>" alt="" style="height:200px;width:150px">
                                    </div>

                                </div>

                                <div class="row">
                                    <div class="col-6">
                                        <audio controls>
                                            <source src="../AdminLt/<?php echo $row['audio']; ?>" type="audio/mp3">
                                            Your browser does not support the audio element.
                                        </audio>
                                    </div>
                                    <div class="col-6">

                                        <div>
                                            <label>
                                                <a href="../AdminLt/<?php echo $row['pdf']; ?>" download>
                                                    <?php echo $row['pdf']; ?>
                                                </a>
                                            </label>
                                        </div>



                                    </div>
                                </div>



                            </div>

                        </form>


                    </div>

                </div>

            </div>

        </div>
    <?php } ?>
    <!-- member task title model close here -->

    <?php
    $sql = "SELECT * FROM group_add_task ";
    $query = mysqli_query($conn, $sql);
    while ($row = mysqli_fetch_assoc($query)) {
    ?>
        <div class="modal fade" id="detailsModal<?php echo $row['id']; ?>">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header" style="background: #343a40; ">
                        <h4 class="modal-title fw-bold text-white text-uppercase"><?php echo $row['group_id'] ?></h4>
                        <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form method="POST" action="update-taskcode.php" enctype="multipart/form-data">
                            <div class="card-body">
                                <input type="hidden" id="id" name="id" value="<?php echo $row['id'] ?>">
                                <div class="row">
                                    <div class="col-4">
                                        <div class="form-group">
                                            <label for="exampleInputName">Task Title</label>
                                            <input type="text" class="form-control" id="exampleInputName" value="<?php echo $row['title'] ?>" name="title">
                                        </div>
                                    </div>
                                    <div class="col-4">
                                        <div class="form-group">
                                            <label for="exampleInputName">Platform</label>
                                            <select class="form-control" name="platform">
                                                <option value="GMB Review" <?php if ($row['platform'] == 'GMB Review') echo 'selected'; ?>>GMB
                                                    Review</option>
                                                <option value="JD Review" <?php if ($row['platform'] == 'JD Review') echo 'selected'; ?>>JD Review
                                                </option>
                                                <option value="Amazon Order" <?php if ($row['platform'] == 'Amazon Order') echo 'selected'; ?>>Amazon
                                                    Order</option>
                                                <option value="Flipkart Order" <?php if ($row['platform'] == 'Flipkart Order') echo 'selected'; ?>>
                                                    Flipkart Order</option>
                                                <option value="Youtube Like" <?php if ($row['platform'] == 'Youtube Like') echo 'selected'; ?>>
                                                    Youtube Like</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-4">
                                        <div class="form-group">
                                            <label for="exampleInputPurpose">URL</label>
                                            <input type="text" name="url" class="form-control" id="exampleInputPurpose" placeholder="URL" value="<?php echo $row['url'] ?>">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-12">
                                        <div class="form-group">
                                            <label for="exampleInputContact1">Task Discription</label>
                                            <textarea id="" rows="5" class="form-control" name="discription"><?php echo $row['task_discription']; ?></textarea>
                                        </div>
                                    </div>
                                </div>


                                <div class="row">
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputFile">Video Upload</label>


                                            <div class="custom-file">
                                                <input type="file" class="custom-file-input" id="video_file" name="video_file" onchange="displayFileName()">
                                                <label class="custom-file-label" for="video_file"><?php echo $row['video']; ?></label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputFile">Image Upload</label>



                                            <div class="custom-file">
                                                <input type="file" class="custom-file-input" id="image_file" name="image_file" onchange="displayFileName()">
                                                <label class="custom-file-label" for="image_file"><?php echo $row['image']; ?></label>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputFile">Audio Upload</label>


                                            <div class="custom-file">
                                                <input type="file" class="custom-file-input" id="audio_file" name="audio_file" onchange="displayFileName()">
                                                <label class="custom-file-label" for="audio_file"><?php echo $row['audio']; ?></label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label for="exampleInputFile">Pdf Upload</label>

                                            <div class="custom-file">
                                                <input type="file" class="custom-file-input" id="pdf_file" name="pdf_file" onchange="displayFileName()">
                                                <label class="custom-file-label" for="pdf_file"><?php echo $row['pdf']; ?></label>
                                            </div>

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


                            </div>

                            <div class="card-footer">
                                <button type="submit" class="btn text-white fw-bold" style="background: #343a40;">Update
                                    Task</button>
                            </div>
                        </form>
                    </div>

                </div>

            </div>

        </div>
    <?php } ?>



    <?php include("footerlink.php") ?>






    <!-- Page specific script -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
    <script>
        // Use noConflict to avoid conflicts with other scripts
        var $j = jQuery.noConflict();
        $j(document).ready(function() {
            $j('#example2').DataTable();
        });
    </script>
    <script>
        // Use noConflict to avoid conflicts with other scripts
        var $j = jQuery.noConflict();
        $j(document).ready(function() {
            $j('#example3').DataTable();
        });
    </script>



</body>

</html>