<div class="col-sm-8">

    <div class="row ">
        <div class="col-sm-12 ">


            <div class="col-sm-5 col-sm-offset-7 ">
                <input type="text" 
                       class="form-control " 
                       oninput="searchLearnerGroup(this.value,'<?php echo base_url() . 'search-learner-group' ?>')"
                       placeholder="Search Group Here..." 
                       aria-describedby="basic-addon1">
                       <?php
//                $message = $this->session->userdata('message');
//                if ($message) {
//                    echo $message;
//                    $this->session->unset_userdata('message');
//                }
                       ?>
            </div>
            <div class="col-sm-12" style="padding: 0">

                <div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;padding: 10px 0 10px 0;font-weight: bold">
                    <div class="col-sm-2" style="padding: 0">Group name</div>
                    <div class="col-sm-2" style="padding: 0">Type</div>
                    <div class="col-sm-2" style="padding: 0">Permission</div>
                    <div class="col-sm-2" style="padding: 0">Member</div>
                    <div class="col-sm-2" style="padding: 0">Request</div>
                    <div class="col-sm-2" style="padding: 0">Action</div>
                </div>
                <div class="col-sm-12"><br></div>
                <input type="hidden" name="search_value" id="search_value" value="">
                <div id="requested_member_list">
                    <?php
                    if ($member_group_list) {
                        foreach ($member_group_list as $v_group_list) {
                            ?>
                            <div class="col-sm-12 gray text-center" >
                                <?php
                                foreach (($selected_group[$v_group_list->group_id]) as $v_selected_group) {
                                    ?>

                                    <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                        <a href="<?php echo base_url() . 'group/' . $v_selected_group->url; ?>">
                                            <?php
                                            if (strlen($v_selected_group->group_name) > 20) {
                                                echo mb_substr($v_selected_group->group_name, 0, 20) . '...';
                                            } else {
                                                echo $v_selected_group->group_name;
                                            }
                                            ?>
                                        </a>
                                    </div>

                                    <div class="col-sm-2" style="padding: 10px 0 0 0  "><?php echo $v_selected_group->group_type_name ?></div>

                                    <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                        <?php
                                        $group_permission = $v_selected_group->group_permission;
                                        if ($group_permission == 1) {
                                            echo 'Public';
                                        } else if ($group_permission == 2) {
                                            echo 'Talhatraining User';
                                        } else if ($group_permission == 3) {
                                            echo 'My Link';
                                        } else if ($group_permission == 4) {
                                            echo 'Only Group Member';
                                        }
                                        ?>
                                    </div>

                                    <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                        <!--<a href="">-->
                                        <?php echo $total_member[$v_selected_group->group_id]->total; ?>
                                        <!--</a>-->
                                    </div>

                                    <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                        <!--<a href="">-->
                                        <?php echo count($group_requested_members[$v_group_list->group_id]); ?>
                                        <!--</a>-->
                                    </div>

                                    <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                        <?php
                                        $status = $v_group_list->group_member_status;
                                        if ($v_selected_group->group_created_by == $this->session->userdata('person_id')) {
                                            echo 'Group Author';
                                        } else {
                                            if ($status == 1) {
                                                ?>
                                                <a href="<?php echo base_url() . 'group/leave_group/' . $v_selected_group->group_public_id; ?>">
                                                    <span class="btn btn-success" title="Leave Group"> <i class="fa fa-times"></i> </span>
                                                </a>
                                            <?php } else if ($status == 2) { ?>
                                                <a href="<?php echo base_url() . 'join-group/' . $v_selected_group->group_public_id; ?>">
                                                    <span class="btn btn-success" title="Join Request"><i class="fa fa-plus"></i>  </span>
                                                </a>
                                            <?php } else if ($status == 3) { ?>
                                                <a href="<?php echo base_url() . 'group/cancel_group_request/' . $v_selected_group->group_public_id; ?>">
                                                    <span class="btn btn-success"  title="Cancel Request"><i class="fa fa-remove"></i></span>
                                                </a>
                                            <?php } else if ($status == 4) { ?>
                                                <a href="<?php echo base_url() . 'join-group/' . $v_selected_group->group_public_id; ?>">
                                                    <span class="btn btn-success" title="Join Request"><i class="fa fa-plus"></i>  </span>
                                                </a>
                                            <?php } else {
                                                ?>
                                                <a href="<?php echo base_url() . 'join-group/' . $v_selected_group->group_public_id; ?>">
                                                    <span class="btn btn-success" title="Join Request"><i class="fa fa-plus"></i>  </span>
                                                </a>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </div>

                                <?php } ?>
                            </div>
                            <div class="col-sm-12">
                                <br>
                            </div>
                        <?php } ?>




                        <?php
                        // echo $total_limit_value->total_type;
                        $totall_count = count($count_member_group_list);
                        $total_page = ceil($totall_count / 10);
                        if ($total_page > 1) {
                            ?>
                            <nav class="course-pagination">
                                <ul class="pagination">
                                    <?php
                                    if ($page > 2) {
                                        ?>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups/learner' ?>" aria-label="Previous">
                                                <span aria-hidden="true" title="First Page">&laquo;&laquo;</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups/learner' . '/' . ($page - 1); ?>" aria-label="Previous">
                                                <span aria-hidden="true" title="Previous Page">&laquo;</span>
                                            </a>
                                        </li>
                                    <?php } elseif ($page > 1) { ?>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups/learner/' . ($page - 1); ?>" aria-label="Previous">
                                                <span aria-hidden="true" title="Previous Page">&laquo;</span>
                                            </a>
                                        </li>
                                        <?php
                                    }
                                    for ($i = 0; $total_page > $i; $i++) {
                                        echo '<li><a href="' . base_url() . 'groups/learner/' . ($i + 1) . '">' . ($i + 1) . '</a></li>';
                                    }
                                    if ($total_page != $page) {
                                        ?>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups/learner/' . ($page + 1); ?>" aria-label="Next">
                                                <span aria-hidden="true" title="Next Page">&raquo;</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups/learner/' . $total_page; ?>" aria-label="Next">
                                                <span aria-hidden="true" title="Last Page">&raquo;&raquo;</span>
                                            </a>
                                        </li>
                                    <?php } ?>
                                </ul>
                            </nav>
                        <?php
                        }
                    }
                    ?>
                </div>

            </div>


        </div>
    </div>

</div>
<script>
    function AjaxInitialization(xmlhttp4) {
        xmlhttp4 = false;
        try {
            xmlhttp4 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp4 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp4 = false;
            }
        }
        if (!xmlhttp4 && typeof XMLHttpRequest != 'undefined') {
            xmlhttp4 = new XMLHttpRequest();
        }
        return xmlhttp4;
    }

    function searchLearnerGroup(Value, Url) {
        var xmlhttp3;
        xmlhttp3 = AjaxInitialization(xmlhttp3);

        var formdata = new FormData();
        formdata.append("value", Value);

        xmlhttp3.addEventListener("load", function () {
            document.getElementById('search_value').value = Value;
            document.getElementById("requested_member_list").innerHTML = xmlhttp3.responseText;
            //xmlhttp3.responseText;

        }, false);

        xmlhttp3.open("POST", Url);
        xmlhttp3.send(formdata);
    }
    function checkForAction(url, action) { // check for Active Inactives
        swal({
            title: "",
            text: "Are you sure you want to " + action + " this Group?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#DD6B55',
            confirmButtonText: 'Yes',
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        document.location.href = url;
                    }
                });
    }

    function checkForDelete(url) {
        swal({
            title: "",
            text: "Are you sure you want to Delete The Group?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#DD6B55',
            confirmButtonText: 'Yes, delete it!',
            cancelButtonText: "No, cancel!",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        document.location.href = url;
                    }
                });
    }
    function searchPaginationlearnerGroup(url) {
        var Value = document.getElementById('search_value').value;
        var xmlhttp3;
        xmlhttp3 = AjaxInitialization(xmlhttp3);

        var formdata = new FormData();
        formdata.append("value", Value);

        xmlhttp3.addEventListener("load", function () {

            document.getElementById("requested_member_list").innerHTML = xmlhttp3.responseText;
            //xmlhttp3.responseText;

        }, false);

        xmlhttp3.open("POST", Url);
        xmlhttp3.send(formdata);
    }
</script>