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

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

                    <div class="col-sm-2 ">
                        <!--                        <h3 style="margin-top: 15px;">Pending List</h3>-->
                    </div>
                    <div class="col-sm-3 col-sm-offset-7">
                        <a href="javascript:;" id="group_member_request_accept" class="btn btn-success" title="Accept all" onclick="acceptAll('<?php echo base_url() . 'accept-all-pending-member' ?>', '1')" style="display: none;"> <i class="fa fa-check" aria-hidden="true" ></i></a>
                        <a href="javascript:;" id="group_member_request_cancel" onclick="acceptAll('<?php echo base_url() . 'accept-all-pending-member' ?>', '2')" class="btn btn-success" title="Cancel all" style="display: none;"><i class="fa fa-times" aria-hidden="true" ></i></a>
                        <select id="pending_list_number" onchange="pendingListShow(this.value, '<?php echo base_url() . 'number-wise-pending-list'; ?>', '<?php echo $group_url; ?>')">
                            <option value="10">10</option>
                            <option value="20">20</option>
                            <option value="50">50</option>
                            <option value="100">100</option>
                            <option value="500">500</option>
                        </select>
                    </div>
                </div>
                <!--                <div id="join_group" class="modal fade" role="dialog">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                <h4 class="modal-title">Join Group</h4>
                                            </div>
                                            <div class="modal-body">
                
                                                <form action="my_group.html">
                
                                                    <div class="col-sm-6 col-sm-offset-3">
                                                        <br><br>
                
                
                                                        <div class="input-group">
                                                            <input type="text" class="form-control" placeholder="Please Type Group Code.." >
                                                            <span class="input-group-addon" ><i class="fa fa-group"></i></span>
                                                        </div>
                                                    </div>   
                
                                                    <div class="col-sm-12"><br> <br></div>
                
                                                    <div class="col-sm-3"></div>
                                                    <div class="col-sm-6">
                
                                                        <input type="submit" class="green-btn btn btn-default" value="Join Group !"><br/><br/>
                                                    </div>
                                                    <div class="col-sm-3"></div>
                                                </form>
                                            </div>
                                            <div class="col-sm-12"><hr></div>
                                            <div class="modal-footer">
                
                                                <button type="button" class="btn btn-danger pull-right" data-dismiss="modal">Close</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>-->
                <hr>

            </div>

            <div class="col-sm-12"><hr></div>

            <div class="col-sm-12 padding-zero">


                <div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;font-weight: bold">
                    <div class="col-sm-1 padding-zero" >
                        <div class="checkbox checkbox-success">
                            <input id="checkbox1" name="checkbox1" class="styled" type="checkbox"><label for="checkbox1"></label>
                        </div>
                    </div>
                    <div class="col-sm-2 padding-zero" >Name</div>
                    <div class="col-sm-4 padding-zero" >Email Address</div>
                    <div class="col-sm-2 padding-zero" >Join Date</div>
                    <div class="col-sm-1 padding-zero" >Status</div>
                    <div class="col-sm-2 padding-zero" >Action</div>
                </div>
                <div class="col-sm-12"><br></div> 
                <input type="hidden" name="value1" id="value1" value="">
                <input type="hidden" name="group_url" id="group_url" value="">
                <div id="pending_list">
                    <?php foreach ($group_requested_member_list as $v_requested_member) { ?>
                        <div class="col-sm-12 gray text-center" >
                            <div class="col-sm-1 padding-zero">
                                <div class="checkbox checkbox-success"   style="text-align: center;">
                                    <input  class="checkbox2" name="checkbox2[]" type="checkbox" value="<?php echo $v_requested_member->group_member_id; ?>"><label for="checkbox"></label>
                                </div>
                            </div>
                            <div class="col-sm-2 padding-zero" ><a href="<?php echo base_url() . $v_requested_member->url . '/profile' ?>">
                                <?php 
                                    //echo $v_requested_member->person_first_name; 
                                    if(strlen($v_requested_member->person_first_name)< 30){
                                        echo $v_requested_member->person_first_name;
                                        }
                                    else{
                                        echo substr($v_requested_member->person_first_name, 0, 30).'...';
                                        }
                                ?></a>
                            </div>
                            <div class="col-sm-4 padding-zero" >
                                <?php
                                    //echo $v_requested_member->person_email; 
                                    if(strlen($v_requested_member->person_email)< 30){
                                        echo $v_requested_member->person_email;
                                        }
                                    else{
                                        echo substr($v_requested_member->person_email, 0, 40).'...';
                                        }
                                ?>
                            </div>
                            <div class="col-sm-2 padding-zero" ><?php echo date('Y-m-d', strtotime($v_requested_member->group_join_date_time)); ?></div>

                            <div class="col-sm-1 padding-zero">
                                <?php
                                $group_member_status = $v_requested_member->group_member_status;
                                if ($group_member_status == 4) {
                                    echo 'Blocked';
                                } else {
                                    echo 'Pending';
                                }
                                ?>
                            </div>

                            <div class="col-sm-2 padding-zero">
                                <?php
                                if ($group_member_status == 4 || $group_member_status == 3) {
                                    ?>
                                    <a href="#" onclick="return checkForAction('<?php echo base_url() . 'make-active-group-member/' . $v_requested_member->group_member_id; ?>', 'Active')">
                                        <i class="fa fa-user-plus" title="Active"></i>
                                    </a>&nbsp;&nbsp;
                                <?php } ?>

                                <?php if ($group_member_status != 4) { ?>
                                    <a href="#" onclick="return checkForAction('<?php echo base_url() . 'make-block-group-member/' . $v_requested_member->group_member_id; ?>', 'Block')">
                                        <i class="fa fa-lock" title="Blocked"></i>
                                    </a>&nbsp;&nbsp;
                                <?php } ?>

                                <a href="#" onclick="return checkForDelete('<?php echo base_url() . 'make-archive-group-member/' . $v_requested_member->group_member_id; ?>')">
                                    <i class="fa fa-trash-o" title="Delete"></i>
                                </a>&nbsp;&nbsp;
                            </div>
                        </div>
                        <div class="col-sm-12"><br></div> 
                    <?php } ?>



                    <?php
                    // echo $total_limit_value->total_type;
                    $totall_count = count($totall_pending_member);
                    $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() . 'group/' . $group_url . '/requested-members' ?>" aria-label="Previous">
                                            <span aria-hidden="true" title="First Page">&laquo;&laquo;</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="<?php echo base_url() . 'group/' . $group_url . '/requested-members' . '/' . ($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() . 'group/' . $group_url . '/requested-members' . '/' . ($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() . 'group/' . $group_url . '/requested-members' . '/' . ($i + 1) . '">' . ($i + 1) . '</a></li>';
                                }
                                if ($total_page != $page) {
                                    ?>
                                    <li>
                                        <a href="<?php echo base_url() . 'group/' . $group_url . '/requested-members' . '/' . ($page + 1); ?>" aria-label="Next">
                                            <span aria-hidden="true" title="Next Page">&raquo;</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="<?php echo base_url() . 'group/' . $group_url . '/requested-members' . '/' . $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>

    $(document).ready(function () {
        $('input:checkbox').click(function () {
            if (this.checked) {
                $("#group_member_request_accept").show();
                $("#group_member_request_cancel").show();
            }
            else{
                $("#group_member_request_accept").hide();
                $("#group_member_request_cancel").hide();
            }
        });
    });
        
    $("#checkbox1").change(function () {
        $("input:checkbox").prop('checked', $(this).prop("checked"));
    });
    function AjaxInitialiazation(xmlhttp5) {
        xmlhttp5 = false;
        try {
            xmlhttp5 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp5 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp5 = false;
            }
        }
        if (!xmlhttp5 && typeof XMLHttpRequest != 'undefined') {
            xmlhttp5 = new XMLHttpRequest();
        }
        return xmlhttp5;
    }

    function acceptAll(url,value) {
        var xmlhttp1;
        xmlhttp1 = AjaxInitialiazation(xmlhttp1);

        var valMemberId = [];
        $(document).ready(function () {
            $('input:checkbox[name="checkbox2[]"]').each(function () {
                if (this.checked) {
                    valMemberId.push(this.value);
                }
            });
        });

        var GroupMemberId = valMemberId;
        var formdata = new FormData();
        formdata.append("group_member_id", GroupMemberId);
        formdata.append("value", value);
        xmlhttp1.addEventListener("load", function () {
            //alert(xmlhttp1.responseText);
            location.reload();
        }, false);

        xmlhttp1.open("POST", url);
        xmlhttp1.send(formdata);
    }
    function pendingListShow(value, url, groupUrl) {
        var xmlhttp2;
        xmlhttp2 = AjaxInitialiazation(xmlhttp2);

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

        xmlhttp2.addEventListener("load", function () {
            document.getElementById('value1').value = value;
            document.getElementById('group_url').value = groupUrl;
            document.getElementById('pending_list').innerHTML = xmlhttp2.responseText;

        }, false);

        xmlhttp2.open("POST", url);
        xmlhttp2.send(formdata);
    }
    function ajaxRequestedMemberPagination(url) {
        var xmlhttp3;
        xmlhttp3 = AjaxInitialiazation(xmlhttp3);


        var value = document.getElementById('value1').value;
        var groupUrl = document.getElementById('group_url').value;
        var formdata = new FormData();
        formdata.append("value", value);
        formdata.append("group_url", groupUrl);
        xmlhttp3.addEventListener("load", function () {
            document.getElementById('pending_list').innerHTML = 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 Member?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#8CC73F',
            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 this Group Member?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#8CC73F',
            confirmButtonText: 'Yes',
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        document.location.href = url;
                    }
                });
    }

</script>
