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

    <div class="row ">
        <div class="col-sm-12 ">
            <div class="col-sm-12" style="padding: 0">
              
                     <div class="col-sm-4 col-sm-offset-8 form-group" > <input type="text" 
                      class="form-control " 
                      oninput="searchGroup(this.value,'<?php echo base_url().'search-group-by-text'?>')"
                       placeholder="Search Group Here..." 
                       aria-describedby="basic-addon1">
                     </div>
              
                <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 id="asc" style="display: inline;"><a onclick="AscdingOrderGroup('a_group','<?php echo base_url().'ascdscding-order-group';?>')" style="cursor: pointer;"><i class="fa fa-angle-up"></i></a></div>
                        <div id="desc" style="display: none;"><a onclick="AscdingOrderGroup('d_group','<?php echo base_url().'ascdscding-order-group';?>')" style="cursor: pointer;"><i class="fa fa-angle-down"></i></a></div>
                    </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 id="asc1" style="display: inline;"><a onclick="memberAscDscNumberwiseShow('a_member','<?php echo base_url().'ascdscding-order-group';?>')" style="cursor: pointer;"><i class="fa fa-angle-up"></i></a></div>
                        <div id="desc1" style="display: none;"><a  onclick="memberAscDscNumberwiseShow('d_member','<?php echo base_url().'ascdscding-order-group';?>')" style="cursor: pointer;"><i class="fa fa-angle-down"></i></a></div>
                    </div>
                    <div class="col-sm-2" style="padding: 0">Request
                    <div id="asc2" style="display: inline;"><a onclick="memrReqAscDscNumberwiseShow('a_request','<?php echo base_url().'ascdscding-order-group';?>')" style="cursor: pointer;"><i class="fa fa-angle-up"></i></a></div>
                    <div id="desc2" style="display: none;"><a  onclick="memrReqAscDscNumberwiseShow('d_request','<?php echo base_url().'ascdscding-order-group';?>')" style="cursor: pointer;"><i class="fa fa-angle-down"></i></a></div>
                    </div>
                    <div class="col-sm-2" style="padding: 0">Action</div>
                </div>
                <input type="hidden" name="asc_dsc_value" id="asc_dsc_value" value="">
                <input type="hidden" name="search_input_text" id="search_input_text" value="">
                <div class="col-sm-12"><br></div>
                <div id="group_order">
                   
                <?php
                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_group_list->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 base_url() . 'group/' . $v_group_list->url . '/members'; ?>">
                                    <?php echo $total_member[$v_group_list->group_id]->total; ?>
                                </a>
                            </div>

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

                            <div class="col-sm-2" style="padding: 10px 0 0 0  ">

                                <a href="<?php echo base_url() . 'group/' . $v_group_list->url . '/edit-group'; ?>"><i class="fa fa-edit" title="Edit"></i></a>&nbsp;&nbsp;

                                <?php
                                $group_status = $v_selected_group->group_status;
                                if ($group_status == 0) {
                                    ?>
                                    <a href="#" onclick="return checkForAction('<?php echo base_url() . 'publish-group/' . $v_group_list->url; ?>', 'Publish')">
                                        <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_list->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_list->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_list->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 } ?>

              
                <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 The Group?",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: '#8CC73F',
                            confirmButtonText: 'Yes',
                            cancelButtonText: "No",
                            closeOnConfirm: true,
                            closeOnCancel: true
                        },
                        function (isConfirm) {
                            if (isConfirm) {
                                document.location.href = url;
                            }
                        });
                    }
                </script>

              <?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/organization' ?>" aria-label="Previous">
                                        <span aria-hidden="true" title="First Page">&laquo;&laquo;</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo base_url() . 'groups/organization'.'/'. ($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/organization/'. ($page - 1); ?>" aria-label="Previous">
                                        <span aria-hidden="true" title="Previous Page">&laquo;</span>
                                    </a>
                                </li>
                                <?php
                            }
                            for ($i = 0; $total_page > $i; $i++) {?>
                            <li><a href="<?php echo base_url() . 'groups/organization/'. ($i + 1) ?>">  <?php echo ($i + 1) ?> </a></li>
                            <?php }
                            if ($total_page != $page) {
                                ?>
                                <li>
                                    <a href="<?php echo base_url() . 'groups/organization/'. ($page + 1); ?>" aria-label="Next">
                                        <span aria-hidden="true" title="Next Page">&raquo;</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo base_url() . 'groups/organization/'. $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  AscdingOrderGroup(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_order").innerHTML=xmlhttp1.responseText;
     document.getElementById("desc").setAttribute("style","display:inline");
     document.getElementById("asc").setAttribute("style","display:none");
     document.getElementById("asc_dsc_value").value='a_group';
    }
       else if(value=='d_group'){
       document.getElementById("group_order").innerHTML=xmlhttp1.responseText;
       document.getElementById("desc").setAttribute("style","display:none");
       document.getElementById("asc").setAttribute("style","display:inline");
      document.getElementById("asc_dsc_value").value='d_group';
       }
            }, false);
            xmlhttp1.open("POST", url);
            xmlhttp1.send(formdata);
     
      
       
   }
   
    function AscdscdingOrderGroupPagination(url) {
      //  alert(url);
        var xmlhttp2;
        xmlhttp2 = AjaxInitialization(xmlhttp2);
        var given_text=document.getElementById("search_input_text").value;
        var value=document.getElementById("asc_dsc_value").value;
        var formdata = new FormData();
        formdata.append("value", value);
        if(value=='search'){
        formdata.append("given_text", given_text);
         }
         xmlhttp2.addEventListener("load", function (event) {
            //alert(xmlhttp2.responseText);
        document.getElementById("group_order").innerHTML=xmlhttp2.responseText;
        }, false);
        xmlhttp2.open("POST", url);
        xmlhttp2.send(formdata);


    }
    function memberAscDscNumberwiseShow(value,url){
    var xmlhttp5;
    xmlhttp5 = AjaxInitialization(xmlhttp5);
    var formdata = new FormData();
    formdata.append("value", value);
    xmlhttp5.addEventListener("load", function (event) {
       //alert(xmlhttp5.responseText);      
  if(value==='a_member'){
     
     document.getElementById("group_order").innerHTML=xmlhttp5.responseText;
     document.getElementById("desc1").setAttribute("style","display:inline");
     document.getElementById("asc1").setAttribute("style","display:none");
     document.getElementById("asc_dsc_value").value='a_member';
    }
       else if(value==='d_member'){
         
       document.getElementById("group_order").innerHTML=xmlhttp5.responseText;
       document.getElementById("desc1").setAttribute("style","display:none");
       document.getElementById("asc1").setAttribute("style","display:inline");
       document.getElementById("asc_dsc_value").value='d_member';
       }
            }, false);
            xmlhttp5.open("POST", url);
            xmlhttp5.send(formdata);
      }
  
   function memrReqAscDscNumberwiseShow(value,url){
    var xmlhttp5;
    xmlhttp5 = AjaxInitialization(xmlhttp5);
    var formdata = new FormData();
    formdata.append("value", value);
    xmlhttp5.addEventListener("load", function (event) {
       //alert(xmlhttp5.responseText);      
  if(value=='a_request'){
     
     document.getElementById("group_order").innerHTML=xmlhttp5.responseText;
     document.getElementById("desc2").setAttribute("style","display:inline");
     document.getElementById("asc2").setAttribute("style","display:none");
     document.getElementById("asc_dsc_value").value='a_request';
    }
       else if(value=='d_request'){
         
       document.getElementById("group_order").innerHTML=xmlhttp5.responseText;
       document.getElementById("desc2").setAttribute("style","display:none");
       document.getElementById("asc2").setAttribute("style","display:inline");
       document.getElementById("asc_dsc_value").value='d_request';
       }
            }, false);
            xmlhttp5.open("POST", url);
            xmlhttp5.send(formdata);
      }
 function searchGroup(givenText,url){
     var xmlhttp6;
    xmlhttp6 = AjaxInitialization(xmlhttp6);
    var formdata = new FormData();
    formdata.append("given_text", givenText);
    xmlhttp6.addEventListener("load", function (event) {
      //   alert(xmlhttp6.responseText);   
            document.getElementById("asc_dsc_value").value='search';
            document.getElementById("search_input_text").value=givenText;
            document.getElementById("group_order").innerHTML=xmlhttp6.responseText;
           }, false);
            xmlhttp6.open("POST", url);
            xmlhttp6.send(formdata);
      }
    
 
    
    </script>