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

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

                </div>

                <div class="col-sm-4 ">
                    <input type="text" 
                           class="form-control " 
                           oninput="searchDetailGroup(this.value,'search','<?php echo base_url() . 'search-detail-group'; ?>')"
                           placeholder="Search Group Here..." 
                           aria-describedby="basic-addon1">
                </div>
                <input type="hidden" name="search_group_detail" id="search_group_detail" value="">
                <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>


            </div>

            <div class="col-sm-12"><hr></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
                        <div id="asc" style="display: inline;"><a onclick="AscdingOrderdetailGroup('a_group', '<?php echo base_url() . 'search-detail-group'; ?>')" style="cursor: pointer;"><i class="fa fa-angle-up"></i></a></div>
                        <div id="desc" style="display: none;"><a onclick="AscdingOrderdetailGroup('d_group', '<?php echo base_url() . 'search-detail-group'; ?>')" style="cursor: pointer;"><i class="fa fa-angle-down"></i></a></div></div>
                    <div class="col-sm-1" style="padding: 0">Member</div>

                    <div class="col-sm-5" style="padding: 0">Note / Alert / Assignment / Quiz / Photo / Video</div>

                    <div class="col-sm-2" style="padding: 0">Course / Video Course</div>

                    <div class="col-sm-2" style="padding: 0">Action</div>
                </div>
                <input type="hidden" name="order_value" id="order_value" value="">
                <div class="col-sm-12"><br></div> 
                <div id='group_detail_order'>
                    <?php
                    $i = 0;
                    if ($member_group_list) {
                        foreach ($member_group_list as $v_group) {
                            if((!empty($v_group->group_status)) && ($v_group->group_status == 2)){
                                continue;
                            }
                            ?>
                            <div class="col-sm-12 <?php
                            if ($i % 2) {
                                echo 'gray';
                            } else {
                                echo 'white';
                            }
                            $i++
                            ?> text-center" >

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

                                <div class="col-sm-1" style="padding: 10px 0 0 0  ">
                                    <a href="<?php echo base_url() . 'group/' . $v_group->url . '/members'; ?>">
                                        <?php echo count($group_member_list[$v_group->group_id]); ?>
                                    </a>
                                </div>



                                <div class="col-sm-5" style="padding: 10px 0 0 0  ">
                                    <a href="<?php echo base_url() . 'group/' . $v_group->url . '/note'; ?>">
                                        <?php echo count($group_note_post[$v_group->group_id]); ?>
                                    </a>/   

                                    <a href="<?php echo base_url() . 'group/' . $v_group->url . '/alert'; ?>">
                                        <?php echo count($group_alert_post[$v_group->group_id]); ?>
                                    </a>/

                                    <a href="<?php echo base_url() . 'group/' . $v_group->url . '/assignment'; ?>">
                                        <?php echo count($group_assignment_post[$v_group->group_id]); ?>
                                    </a>/

                                    <a href="<?php //echo base_url() . 'group/quizes/' . $v_group->url; ?>">
                                        0<?php //echo count($group_quiz[$v_group->group_id]); ?>
                                    </a>/

                                    <a href="<?php echo base_url() . 'group/' . $v_group->url . '/photo'; ?>">
                                        <?php echo count($group_photo_post[$v_group->group_id]); ?>
                                    </a>/

                                    <a href="<?php echo base_url() . 'group/' . $v_group->url . '/video'; ?>">
                                        <?php echo count($group_video_post[$v_group->group_id]); ?>
                                    </a>

                                </div>



                                <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                    <a href="<?php echo base_url() . 'fornt-end-group-course-list/' . $v_group->url ?>">
                                        <?php //echo count($group_courses[$v_group->group_id]) ?>
                                    </a>/

                                    <a href="<?php echo base_url() . 'fornt-end-group-video-course-list/' . $v_group->url ?>">
                                        <?php //echo count($group_video_courses[$v_group->group_id]) ?>

                                    </a>
                                </div>
                                <?php
                                $user_id = $this->session->userdata('user_id');
                                if ($group_creator[$v_group->group_id] == $user_id) {
                                    ?>
                                    <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                        <a href="<?php echo base_url() . 'group/' . $v_group->url . '/edit-group'; ?>"><i class="fa fa-edit" title="Edit"></i></a>&nbsp;&nbsp;

                                        <?php
                                        $group_status = $v_group->group_status;
                                        if ($group_status == 0) {
                                            ?>
                                            <a href="#" onclick="return checkForAction('<?php echo base_url() . 'unpublish-group/' . $v_group->url; ?>', 'Unpublish')">
                                                <i class="fa  fa-user-plus" title="Publish"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } else if ($group_status == 1) { ?>
                                            <a href="#" onclick="return checkForAction('<?php echo base_url() . 'unpublish-group/' . $v_group->url; ?>', 'Unpublish')">
                                                <i class="fa  fa-user-times" title="Unpublish"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } else if ($group_status == 2) { ?>
                                            <a href="#" onclick="return checkForAction('<?php echo base_url() . 'publish-group/' . $v_group->url; ?>', 'Publish')">
                                                <i class="fa  fa-user-plus" title="Publish"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } ?>

                                        <?php if ($group_status != 2) { ?>
                                            <a href="#" onclick="return checkForDelete('<?php echo base_url() . 'archive-group/' . $v_group->url; ?>')">
                                                <i class="fa fa-trash-o" title="Delete"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } ?>

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

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


                        <?php
                      //echo $total_limit_value->total_type;
                        $totall_count = count($count_group_list);
//                       echo $totall_count;
//                       exit();
                        $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-detail' ?>" aria-label="Previous">
                                                <span aria-hidden="true" title="First Page">&laquo;&laquo;</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups-detail' . '/' . ($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-detail/' . ($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-detail/' . ($i + 1) . '">' . ($i + 1) . '</a></li>';
                                    }
                                    if ($total_page != $page) {
                                        ?>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups-detail/' . ($page + 1); ?>" aria-label="Next">
                                                <span aria-hidden="true" title="Next Page">&raquo;</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="<?php echo base_url() . 'groups-detail/' . $total_page; ?>" aria-label="Next">
                                                <span aria-hidden="true" title="Last Page">&raquo;&raquo;</span>
                                            </a>
                                        </li>
                                    <?php } ?>
                                </ul>
                            </nav>
                        <?php } ?>
                    <?php } ?>
                </div>
                <script>
                    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: '#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>


            </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 searchDetailGroup(givenText,value, url) {
        //alert(givenText);
        var xmlhttp6;
        xmlhttp6 = AjaxInitialization(xmlhttp6);
        var formdata = new FormData();
        formdata.append("given_text", givenText);
        formdata.append("value", value);
        xmlhttp6.addEventListener("load", function (event) {
            document.getElementById("order_value").value = 'search';
            document.getElementById("search_group_detail").value = givenText;
            document.getElementById("group_detail_order").innerHTML = xmlhttp6.responseText;
        }, false);
        xmlhttp6.open("POST", url);
        xmlhttp6.send(formdata);
    }
    function searchDetailGrouppagination(url) {
        var xmlhttp2;
        xmlhttp2 = AjaxInitialization(xmlhttp2);
        var given_text = document.getElementById("search_group_detail").value;
        var value= document.getElementById("order_value").value;
        var formdata = new FormData();
        formdata.append("given_text", given_text);
        formdata.append("value", value);
        xmlhttp2.addEventListener("load", function (event) {
            document.getElementById("group_detail_order").innerHTML = xmlhttp2.responseText;
        }, false);
        xmlhttp2.open("POST", url);
        xmlhttp2.send(formdata);
    }
    function AscdingOrderdetailGroup(value, url) {
        var xmlhttp1;
        xmlhttp1 = AjaxInitialization(xmlhttp1);
        var formdata = new FormData();
        formdata.append("value", value);
        xmlhttp1.addEventListener("load", function (event) {

            if (value == 'a_group') {
                document.getElementById("group_detail_order").innerHTML = xmlhttp1.responseText;
                document.getElementById("desc").setAttribute("style", "display:inline");
                document.getElementById("asc").setAttribute("style", "display:none");
                document.getElementById("order_value").value = 'a_group';
            } else if (value == 'd_group') {
                document.getElementById("group_detail_order").innerHTML = xmlhttp1.responseText;
                document.getElementById("desc").setAttribute("style", "display:none");
                document.getElementById("asc").setAttribute("style", "display:inline");
                document.getElementById("order_value").value = 'd_group';
            }
        }, false);
        xmlhttp1.open("POST", url);
        xmlhttp1.send(formdata);


    }

</script>
