<script>
    var list = '';
</script>

<div id="change">
    <?php
    $status = $this->session->userdata('status');
    $role_id = $this->session->userdata('role_id');
    ?>
    <div class="col-sm-10 col-sm-offset-3 main col-md-10 col-md-offset-2 main">
        <!-- Select User By Role and Status -->
        <script>


            function selectUser(roleID, userStatus, objID) {
                if (roleID === '') {
                    serverPage = '<?php echo base_url(); ?>super_admin/select_user_list/' + '' + '/' + userStatus + '/' + 0;
                } else {
                    serverPage = '<?php echo base_url(); ?>super_admin/select_user_list/' + roleID + '/' + 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;
//                        location.reload();
                    }
                };
                xmlhttp.send(null);
            }
        </script>

        <div class="container col-sm-8 col-sm-offset-2 col-md-offset-0 col-md-12" id="res">
            <hr>
            <div class="">
                <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>->>
                <span><?php echo $user_role; ?> User</span>
            </div>
            <hr>
            
            <!--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>Wish ID</th>
                                <th>Profile Picture</th>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Contact Number</th>
                                <th>Course</th>
                                <th>Category</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_person) {
                            ?>
                            <tr>
                                <td>
                                    <input name="person_id" id="person_id<?php echo $v_person->person_id; ?>" type="checkbox"  value="<?php echo $v_person->person_id; ?>" onchange="setUserIdList(this.value);"/>
                                </td>

                                <td><?php echo $v_person->wish_list_management_id ?></td>
                                <td><img src="<?php echo base_url() . $v_person->person_image_thumb; ?>" width="50" height="50"> </td>
                                <td><?php echo $v_person->person_first_name . ' ' . $v_person->person_last_name; ?></td>
                                <td><?php echo $v_person->person_email ?></td>
                                <td><?php echo $v_person->person_contact_number ?></td>
                                <td><?php echo $v_person->course_name; ?><br> </td>
                                <td><?php echo $v_person->course_category_name; ?><br> </td>

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

                                <td><?php
                                    if ($v_person->wish_list_management_status == '1') {
                                        echo '<p style="color:limegreen;">Active</p>';
                                    } else if ($v_person->wish_list_management_status == '0') {
                                        echo '<p style="color:red;">Inactive</p>';
                                    }
                                    ?>
                                </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_student/student_detail/<?php echo $v_person->person_id; ?>/0"><div class="span1"><i class="fa fa-edit">View detail</i></div></a>
                                <a href="<?php echo base_url(); ?>super_admin_student/delete_from_wish_list/<?php echo $v_person->wish_list_management_id; ?>/0"><div class="span1"><i class="fa fa-edit">Delete</i></div></a>
                            </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_wish_list; ?></p>
                        </div>

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

                        if ($limit == 'all') {
                            $number_of_pages = ceil($total_wish_list / $total_wish_list);
                        } else {
                            $number_of_pages = ceil($total_wish_list / $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_course/<?php echo $this->uri->segment(2) . '/0'; ?>" class='btn btn-sm btn-success'>First</a>
                                <a href="<?php echo base_url(); ?>super_admin_course/<?php echo $this->uri->segment(2) . '/' . ($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 href="<?php echo base_url(); ?>super_admin_course/<?php echo $this->uri->segment(2) . '/' . ($i * $limit); ?>" class='btn btn-sm btn-default'><?php echo $i; ?></a>
                            <?php } ?>
                        </div>

                        <div class="col-lg-2 col-md-2 col-sm-2">
                            <?php if ($start + $limit < $total_wish_list) { ?>
                                <a href="<?php echo base_url(); ?>super_admin_course/<?php echo $this->uri->segment(2) . '/' . ($start + $limit); ?>" class='btn btn-sm btn-default'>Next</a>
                                <a href="<?php echo base_url(); ?>super_admin_course/<?php echo $this->uri->segment(2) . '/' . (($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> 

    <!-- Modal Start For Change Role and Status-->
    <!--
    

    <?php include 'admin_modal_view/modal_change_role.php'; ?>
    <?php include 'admin_modal_view/modal_change_status.php'; ?>
    <?php include 'admin_modal_view/modal_for_print.php'; ?>
    
    <!--

Modal:: 
IMPORT FILE FORM

    -->

    <div class="modal fade" id="importFile" tabindex="-1" role="dialog" aria-labelledby="importFile" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Add User</h4>
                </div>
                <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                    <p>
                        <?php
                        $message = $this->session->userdata('message');
                        $this->session->unset_userdata('message');
                        if ($message) {
                            echo $message;
                        }
                        ?>
                    </p>
                    <div class="table-responsive col-sm-12">
                        <?php // echo validation_errors();   ?>
                        <form action="<?php echo base_url(); ?>super_admin/import_user_csv_file" method="post" name="import_csv" enctype="multipart/form-data" >
                            <div class="form-group col-sm-8" >
                                <label for="user_info_file" style="float:left;">Select CSV File</label><span class="required"> * <?php // echo form_error('user_image');                                                                           ?></span><br><br>
                                <input style="float:left;" type='file' onchange="readURL(this, 'file_0');" name="user_info_file" value="<?php // echo set_value('user_image');                                                                           ?>"/>
                                <div id="file" style="float:left;width: 50px; height: 50px;" ></div>
                            </div>
                            <div class="checkbox col-sm-8" >
                                <button type="submit" class="btn btn-default">Submit</button>
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <!--<button type="button" class="btn btn-primary">Save changes</button>-->
                </div>
            </div>
        </div>
    </div>
</div>


<SCRIPT LANGUAGE="JavaScript">

    document.forms['control_form'].elements['user_role_id2'].value = '<?php echo $role_id; ?>';
    document.forms['control_form'].elements['user_status'].value = '<?php echo $status; ?>';

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



    function changeUsersStatus()
    {
        userStatus = document.getElementById("person_status").value;
        serverPage = '<?php echo base_url(); ?>super_admin/change_users_status/' + list + '/' + userStatus;
        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);
    }

    function setPerPage(perPage) {

        serverPage = '<?php echo base_url(); ?>super_admin/set_per_page/' + perPage;
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function ()
        {
            if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
            {
                location.reload();
            }
        };
        xmlhttp.send(null);
    }

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


    function printPreview(divName) {
        serverPage = '<?php echo base_url(); ?>super_admin/make_print_data/' + list;
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function ()
        {
            if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
            {
                window = document.getElementById('change').innerHTML = xmlhttp.responseText;
                window.print();
            }
        };
        xmlhttp.send(null);
    }


    function printDiv(divName) {
        window.print();
    }
</script>