
<hr>
<div class="">
    <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>->>
    <span><?php echo $user_role; ?> User</span>
</div>
<hr>
<div class="span11 right">
    <div class="col-lg-6 col-md-4" >
        <h4><?php echo $user_role; ?> User Information</h4> 
    </div>
    <div class="col-lg-2 col-md-2">
    </div>
    <div class="col-lg-4 col-md-4">
        <a class="btn btn-sm btn-primary" href="<?php echo base_url(); ?>super_admin/export_user_list_csv">Export</a> 
        <a class="btn btn-sm btn-primary" href="#" data-toggle="modal" data-target="#importFile">Import</a> 
        <input type="submit" value="Print" id="change_role_button" class="btn btn-sm btn-primary  "  data-toggle="modal" data-target="" onclick="printPreview('user_list');"><!--#print-->
        <a class="btn btn-sm btn-primary" href="#" onclick="sendMailToUser();">Email</a>
        <a class="btn btn-sm btn-primary" href="#" onclick="sendMailToUser();">SMS</a>
    </div>
</div>

<!--User LIST-->

<div class="table-responsive col-lg-12 col-md-10 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_list" id="all_list" onchange="toggleAllUserSelection(document.myform.person_id)"/></th>
                    <!--<th>User ID</th>-->
                    <th>Profile Picture</th>
                    <th>User Name</th>
                    <th>User Email</th>
                    <th>Contact Number</th>
                    <th>Role</th>
                    <th>Status</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
            <script>

                function toggleAllUserSelection(field) {
                    allList = document.getElementById("all_list").checked;
                    if (allList) {
                        for (i = 0; i < field.length; i++) {
                            field[i].checked = true;
                            list += 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;
                        list = '';
//                                    document.getElementById('change_role_button').disabled = true;
//                                    document.getElementById('change_status_button').disabled = true;
                    }
                }

                function setUserIdList(userID)
                {
                    if ($("#person_id" + userID).is(":checked")) {
                        list += userID + '.';
                    } else {
                        list = list.replace(userID + ".", "");
                    }
                    if (list) {
//                                    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;
                    }
//                                alert(userID);
                }

                function setInstantUserIdList(userID) {
                    list += userID + '.';
                }
            </script>
            <?php
            foreach ($users as $v_user) {
                ?>
                <tr>
                    <td>
                        <input name="person_id" id="person_id<?php echo $v_user->person_id; ?>" type="checkbox"  value="<?php echo $v_user->person_id; ?>" onchange="setUserIdList(this.value);"/>
                    </td>

                                                                <!--<td><?php // echo $v_user->person_id         ?></td>-->
                    <td><img src="<?php echo base_url() . $v_user->person_image_thumb; ?>" width="50" height="50"> </td>
                    <td><?php echo $v_user->person_first_name . ' ' . $v_user->person_last_name; ?></td>
                    <td><?php echo $v_user->person_email ?></td>
                    <td><?php echo $v_user->person_contact_number ?></td>
                    <td>
                        <?php
                        if ($v_user->person_role == '1') {
                            echo 'Admin';
                        }
                        if ($v_user->person_role == '2') {
                            echo 'Account';
                        }
                        if ($v_user->person_role == '3') {
                            echo 'Resource';
                        }
                        if ($v_user->person_role == '4') {
                            echo 'Organization';
                        }
                        if ($v_user->person_role == '5') {
                            echo 'Student';
                        }
                        ?><br>
                        <?php if ($v_user->person_role != 5) { ?><a href="#" class="" data-toggle="modal" data-target="#changeRole" onclick="setInstantUserIdList(<?php echo $v_user->person_id; ?>);">Change Role</a><?php } ?>
                    </td>

                    <!--
                        Action: Active, Inactive, Archive, Edit
                    -->

                    <td><?php
                        if ($v_user->person_status == '1') {
                            echo '<p style="color:limegreen;">Active</p>';
                            ?>
                            <a href="<?php echo base_url(); ?>super_admin/make_user_inactive/<?php echo $v_user->person_id; ?>"><i class="fa fa-user-times" title="Inactive"></i></a>
                            <?php
                        } else if ($v_user->person_status == '0') {
                            echo '<p style="color:red;">Inactive</p>';
                            ?>
                            <a href="<?php echo base_url(); ?>super_admin/make_user_active/<?php echo $v_user->person_id; ?>">
                                <i class="fa fa-user-plus" title="Active"></i></a>
                            <?php
                        } else if ($v_user->person_status == '2') {
                            echo '<p style="color:blue;">Archived';
                            ?>
                            <a href="<?php echo base_url(); ?>super_admin/make_user_active/<?php echo $v_user->person_id; ?>"><i class="fa fa-user-plus" title="Active"></i> </a>
                        <?php } ?>
                    </td>

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

                <td style="width: 200px;">
                    <a href="<?php echo base_url(); ?>super_admin/edit_user_information/<?php echo $v_user->person_id; ?>"><div class="span1"><i class="fa fa-edit">Edit</i></div></a>
                    <a href="<?php echo base_url(); ?>super_admin/view_detail/<?php echo $this->uri->segment(3) . '/' . $v_user->person_id; ?>"><div class="span1"><i class="fa fa-edit">View detail</i></div></a>
                    <?php if ($v_user->person_status != 2) { ?><a href="<?php echo base_url(); ?>super_admin/delete_user/<?php echo $v_user->person_id; ?>" onclick="return checkAction('delete');"><i class="fa fa-remove">Delete</i></a><br><?php } ?>
                    <?php if ($v_user->person_role == 5) { ?><a href="<?php echo base_url() ?>super_admin_student/assign_course/<?php echo $v_user->person_id; ?>"><i class="fa fa-remove">Assign Course</i></a><br><?php } ?>
                </td>
                </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_user; ?></p>
            </div>

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

            if ($limit == 'all') {
                $number_of_pages = ceil($total_user / $total_user);
            } else {
                $number_of_pages = ceil($total_user / $limit);
            }
            ?>
            <div class="col-lg-2 col-md-2 col-sm-2">
                <?php if (($start - $limit) >= 0) { ?>
                    <a href="<?php echo base_url(); ?>super_admin/<?php echo $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/0'; ?>" class='btn btn-sm btn-success'>First</a>
                    <a href="<?php echo base_url(); ?>super_admin/<?php echo $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/' . ($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(); ?>super_admin/<?php echo $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/' . ($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_user) { ?>
                    <a href="<?php echo base_url(); ?>super_admin/<?php echo $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/' . ($start + $limit); ?>" class='btn btn-sm btn-default'>Next</a>
                    <a href="<?php echo base_url(); ?>super_admin/<?php echo $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/' . (($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>