<div class="col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <!--START Relative Path-->
    <div class="">
        <a href="<?php echo base_url(); ?>super_admin">Dashboard <?php // echo $person_role;                                                                  ?></a>->>
        <a href="<?php echo base_url(); ?>super_admin/user_list/Organization/<?php echo $this->session->userdata('role_id'); ?>"><?php echo $person_role; ?> List</a>->>
        <a href="<?php echo base_url(); ?>super_admin/view_detail/Organization/<?php echo $org_info->person_id; ?>"><?php echo $person_role; ?> Detail</a>->>
        <span> <?php echo $person_role; ?> Detail</span>
        <div>
            <?php
            $message = $this->session->userdata('message');
            if ($message) {
                echo $message;
            }
            ?>
        </div>
    </div>
    <!--END Relative Path-->

    <?php echo $top_button; ?>

    <div class="col-lg-2">
        <select for="classroom_status" class="form-control"
                name="classroom_status" id="user_status" 
                onchange="selectCourseByStatus(category_id2.value, this.value, 'classroom_list');">
            <option value=''> Select Course Status</option>
            <option value='1'> Active</option>
            <option value='2'> End ClassRoom</option>
            <option value='3'> Unexpectedly END </option>
        </select>
    </div>
    <div class="col-lg-6">
        <div class="col-lg-6">Running Classes: <?php
            echo count($current_classroom_list);
            if (count($current_classroom_list) > 0) {
                ?> 
                <a href="<?php echo base_url() . $this->uri->segment(1); ?>/current_classroom/<?php echo $org_info->organization_id; ?>">(View)</a> 
            <?php } ?>
        </div>
        <div class="col-lg-6">Total Available Classroom: <?php echo $feature_info->virtual_classroom_number; ?></div>
    </div>

    <div class="container col-sm-8 col-sm-offset-2 col-md-offset-0 col-md-12" id="res">
        <div class="table-responsive col-lg-11 col-md-8 col-sm-7" id="user_list">
            <form name="myform" action=""  method="post">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th><input type="checkbox" name="all_category" id="all_category" onchange="toggleAllCategorySelection(document.myform.category_id)"/></th>
                            <th>ClassRoom</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $i = 1;
                        foreach ($classroom as $v_classroom) {
                            ?>
                            <tr>
                                <td>
                                    <input name="category_id" id="category_id<?php echo $v_classroom->classroom_id; ?>" type="checkbox"  value="<?php echo $v_classroom->classroom_id; ?>" onchange="setUserIdList(this.value);"/>
                                </td>

                                <td><img src="<?php echo base_url() . $v_classroom->course_image_thumb; ?>" width="50" height="50"> </td>
                                <td>
                                    <?php echo $v_classroom->course_name; ?>
                                    <br>
                                    <?php echo 'Start Time: ' . $v_classroom->class_start_time ?>
                                    <br>
                                    <?php echo 'Possible End Time: ' . $v_classroom->class_start_time ?>
                                    <br>
                                    <?php echo 'Total Student : ' . $total_student[$v_classroom->classroom_id]; ?>
                                    <br>
                                    <?php echo 'Total Attended Student: ' . $total_active_student[$v_classroom->classroom_id]; ?>
                                    <br>
                                    <?php echo 'Total Unexpectedly Leave Student: ' . $total_unexpectedly_leave_student[$v_classroom->classroom_id]; ?>
                                </td>
                                <td>
                                    <?php echo $v_classroom->person_first_name; //Resource Person Name   ?>
                                </td>
                                <td><?php
                                    if ($v_classroom->classroom_status == '1') {
                                        echo "<p style='color:Green;'>Active";
                                        ?>
                                        <a href="<?php echo base_url() . $this->uri->segment(1); ?>/end_classroom/<?php echo $v_classroom->classroom_id; ?>">
                                            <i class="fa fa-user-times" title="Inactive"></i></a>
                                        <?php
                                    } else if ($v_classroom->classroom_status == '2') {
                                        echo "<p style='color:blue;'>Class End";
                                        ?>
                                        <a href="<?php echo base_url() . $this->uri->segment(1); ?>/start_classroom_again/<?php echo $v_classroom->classroom_id; ?>">
                                            <i class="fa fa-user-plus" title="Active"></i></a>
                                        <?php
                                    } else if ($v_classroom->classroom_status == '3') {
                                        echo "<p style='color:red;'>Unexpectedly End";
                                        ?>
                                        <br>
                                        <a href="<?php echo base_url() . $this->uri->segment(1); ?>/end_classroom/<?php echo $v_classroom->classroom_id; ?>">
                                            <i class="fa fa-close" title="End Classroom"></i></a>
                                        <?php
                                    }
                                    ?>
                                </td>

                                <td>
                                    <?php if ($v_classroom->organization_id) { ?>
                                        <a href="<?php echo base_url() . $this->uri->segment(1) . '/view_organization_classroom/' . $v_classroom->organization_id . '/' . $v_classroom->classroom_id; ?>">
                                            <div class="span1"><i class="fa fa-edit">View Classroom</i></div>
                                        </a>
                                    <?php } else { ?>
                                        <a href="<?php echo base_url() . $this->uri->segment(1) . '/view_individual_teature_classroom/' . $v_classroom->person_id . '/' . $v_classroom->classroom_id; ?>">
                                            <div class="span1"><i class="fa fa-edit">View Classroom</i></div>
                                        </a>
                                    <?php } ?>
                                    <?php if ($v_classroom->classroom_status != 3) { ?>
                                        <a href="<?php echo base_url() . $this->uri->segment(1); ?>/make_classroom_archived/<?php echo $v_classroom->classroom_id; ?>" onclick="checkAction('Delete')">
                                            <i class="fa fa-remove">Delete</i>
                                        </a>
                                    <?php } ?>
                                </td>

                        <script>

                            function checkAction(action) {
                                message = 'do you want to ' + action + '!!';
                                chk = confirm(message);
                                if (chk) {
                                    return true;
                                } else {
                                    return false;
                                }
                            }

                        </script>

                        </tr>
                    <?php } ?>
                    </tbody>
                </table>
                <br>
            </form>

            <!-- Start Pagination -->

            <div class="col-lg-12 col-md-12 col-sm-12" >
                <hr>
                <form name="pagination">
                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <label for="per_page_user">Per Page: </label>
                        <select name="per_page" onchange="setPerPage(this.value);">
                            <option value=''>select</option>
                            <option value='10'>10</option>
                            <option value='25'>25</option>
                            <option value='50'>50</option>
                            <option value='100'>100</option>
                            <option value='200'>200</option>
                            <option value='250'>250</option>
                            <option value='500'>500</option>
                            <!--<option value='all'>All</option>-->
                        </select>
                        <p>This Page :<?php echo $this_page . '/' . $total_classroom; ?></p>
                    </div>

                    <?php
                    $limit = $this->session->userdata('per_page');
                    if ($limit == NULL) {
                        $limit = 10;
                    }

                    if ($limit == 'all') {
                        
                    } else {
                        $number_of_pages = ceil($total_classroom / $limit);
                        ?>
                    <?php }
                    ?>
                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <?php if (($start - $limit) >= 0) { ?>
                            <a href="<?php echo base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3); ?>" class='btn btn-sm btn-success'>First</a>
                            <a href="<?php echo base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . ($start - $limit); ?>" class='btn btn-sm btn-success'>Prev</a>
                        <?php } ?>
                    </div>

                    <div class='col-lg-5 col-md-5 col-sm-5'>
                        <?php for ($i = 0; $i < $number_of_pages; $i++) { ?>
                            <a <?php
                            if ($start / $limit == $i) {
                                echo 'disabled';
                            }
                            ?> class="btn btn-default" href="<?php echo base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . ($i * $limit); ?>" class='btn btn-sm btn-default'><?php echo $i + 1; ?></a>
                            <?php } ?>
                    </div>

                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <?php if ($start + $limit < $total_classroom) { ?>
                            <a href="<?php echo base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . ($start + $limit); ?>" class='btn btn-sm btn-default'>Next</a>
                            <a href="<?php echo base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . (($number_of_pages - 1) * $limit); ?>" class='btn btn-sm btn-success'>Last</a>
                        <?php } ?>
                    </div>
                    <script type="text/javascript">
                        document.forms['pagination'].elements['per_page'].value = '<?php echo $limit ?>';
                    </script>
                </form>
                <br>
                <hr>
            </div>

            <!-- End Pagination -->
        </div>


    </div>  
</div>  



<SCRIPT LANGUAGE="JavaScript">

    userList = '';
    function toggleAllUserSelection(field) {
        allUser = document.getElementById("all_user").checked;
        if (allUser) {
            for (i = 0; i < field.length; i++) {
                field[i].checked = true;
                userList += field[i].value + '.';
            }
            document.getElementById('change_role_button').disabled = false;
            document.getElementById('change_status_button').disabled = false;
        } else {
            for (i = 0; i < field.length; i++)
                field[i].checked = false;
            userList = '';
            document.getElementById('change_role_button').disabled = true;
            document.getElementById('change_status_button').disabled = true;
        }
        alert(field);
    }



    function setUserIdList(userID)
    {
        if ($("#user_id" + userID).is(":checked")) {
            userList += userID + '.';
        } else {
            userList = userList.replace(userID + ".", "");
        }
        if (userList) {
            document.getElementById('change_role_button').disabled = false;
            document.getElementById('change_status_button').disabled = false;
        } else {
            document.getElementById('change_role_button').disabled = true;
            document.getElementById('change_status_button').disabled = true;
        }
    }

    function checkAction(action) {
        message = 'do you want to ' + action + '!!';
        chk = confirm(message);
        if (chk) {
            return true;
        } else {
            return false;
        }
    }

    function changeUsersRole()
    {
        userRoleId = document.getElementById("user_role_id").value;
        serverPage = '<?php echo base_url(); ?>super_admin/change_users_role/' + userList + '/' + userRoleId;
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function ()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                document.getElementById('res').innerHTML = xmlhttp.responseText;
                localtion.reload();
            }
        }
        xmlhttp.send(null);
    }

    function changeUsersStatus()
    {
        userStatus = document.getElementById("change_status").value;
        serverPage = '<?php echo base_url(); ?>super_admin/change_users_status/' + userList + '/' + userStatus;
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function ()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                document.getElementById(objID).innerHTML = xmlhttp.responseText;
                localtion.reload();
            }
        }
        xmlhttp.send(null);
    }


    function selectUserByRole(roleName, userRole, userStatus, objID) {
        userStatus = document.getElementById('user_status').value;
        if (userStatus == '') {
            serverPage = '<?php echo base_url(); ?>super_admin/user_list_table_by_role/' + roleName + '/' + userRole + '/' + userStatus + '/' + 0;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                //                    alert(xmlhttp.readyState);
                //                    alert(xmlhttp.status);
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    document.getElementById(objID).innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.send(null);

        } else {
            selectUserByRoleAndStatus(roleName, userRole, userStatus, objID);
        }
    }

    function selectUserByRoleAndStatus(roleName, userRole, userStatus, objID) {
        //alert(roleName +'/'+ userRole +'/'+ userStatus +'/'+ objID);
        if (userRole == '') {

        } else {
            serverPage = '<?php echo base_url(); ?>super_admin/user_list_table_by_role_and_status/' + roleName + '/' + userRole + '/' + userStatus + '/' + 0;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    document.getElementById(objID).innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.send(null);
        }
    }

    function sendMailToUser() {
        window.location = '<?php echo base_url(); ?>super_admin/send_mail_to_user/' + userList;
    }


</script>