<SCRIPT LANGUAGE="JavaScript">

    studentList = '';
    function toggleAllStudentSelection(field) {
        allStudent = document.getElementById("all_student").checked;
        if (allStudent) {
            for (i = 0; i < field.length; i++) {
                field[i].checked = true;
                studentList += 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;
            studentList = '';
            document.getElementById('change_role_button').disabled = true;
            document.getElementById('change_status_button').disabled = true;
        }
    }



    function setStudentIdList(studentID)
    {
        if ($("#student_id" + studentID).is(":checked")) {
            studentList += studentID + '.';
        } else {
            studentList = studentList.replace(studentID + ".", "");
        }
        if (studentList) {
            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()
    {
        studentRoleId = document.getElementById("type_id").value;
        serverPage = '<?php echo base_url(); ?>super_admin/change_students_role/' + studentList + '/' + studentRoleId;
        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_students_status/' + studentList + '/' + studentStatus;
        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;
//        alert(userStatus);
        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>

<div class="col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <a href="<?php echo base_url(); ?>smis/add_Student/<?php echo $student_type ?>" class="btn btn-sm btn-success">Add Student</a>
    <input type="submit" value="Change Role" id="change_role_button" class="btn btn-sm btn-success"  data-toggle="modal" data-target="#changeRole" disabled="true">
    <input type="submit" value="Assign Course" id="assign_course" class="btn btn-sm btn-success"  data-toggle="modal" data-target="#assignCourse" >
    <input type="submit" value="Change Status" id="change_status_button" class="btn btn-sm btn-success"  data-toggle="modal" data-target="#changeStatus" disabled="true">
    <a href="<?php echo base_url(); ?>super_admin/shorted_students_list/<?php echo $student_type . '/' . $this->session->userdata('role_id'); ?>" class="btn btn-sm btn-success" >Short Student by name</a> ||
    
    
    
    <select for="type_id" name="type_id2" id="type_id2" onchange="selectUserByRole('<?php echo $student_type; ?>', this.value, user_status.value, 'user_list');">
        <option value=''> Select Role</option>
        <?php foreach ($student_types as $v_student_type) { ?>
            <option value="<?php echo $v_student_type->type_id; ?>" <?php
            if ($v_student_type->type_name == $student_type) {
                echo 'Selected';
            }
            ?>> <?php echo $v_student_type->type_name ?></option>
                <?php } ?>
    </select>

    <select for="user_status" name="user_status" id="user_status" onchange="selectUserByRoleAndStatus('<?php echo $student_type; ?>', type_id2.value, this.value, 'user_list');">
        <option value=''> Select Status</option>
        <option value='1'> Active</option>
        <option value='2'> Inactive</option>
        <option value='3'> Archive</option>
    </select>

    <div class="dropdown">
        <button class="btn btn-sm btn-round dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
            Dropdown
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
        </ul>
    </div>

    <div class="container" id="res">
        <div class="row">

        </div>

        <hr>
        <div class="">
            <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>->>
            <span><?php echo $student_type; ?> Student</span>
        </div>
        <hr>
        <div class="span11 right">
            <div class="col-lg-6 col-md-4" >
                <h4><?php echo $student_type; ?> Student Information</h4> </div>
            <div class="col-lg-2 col-md-2">
            </div>
            <div class="col-lg-3 col-md-3">
                <a href="<?php echo base_url(); ?>super_admin/export_student_list_csv">Export</a> ||
                <a href="#" data-toggle="modal" data-target="#importFile">Import</a> ||
                <a href="">Print</a> ||
                <a href="#" onclick="sendMailToUser();">Email</a>
            </div>
        </div>

        <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_student" id="all_student" onchange="toggleAllStudentSelection(document.myform.student_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>
                        <?php
                        $i = 1;
                        foreach ($students as $v_student) {
                            ?>
                            <tr>
                                <td><input name="student_id" id="student_id<?php echo $v_student->student_id; ?>" type="checkbox"  value="<?php echo $v_student->student_id; ?>" onchange="setStudentIdList(this.value);"/></td>
                                <td><?php echo $v_student->student_id ?></td>
                                <td><img src="<?php echo base_url() . $v_student->image_thumb; ?>" width="50" height="50"> </td>
                                <td><?php echo $v_student->first_name . ' ' . $v_student->last_name; ?></td>
                                <td><?php echo $v_student->email ?></td>
                                <td><?php echo $v_student->contact_number ?></td>
                                <td>
                                    <?php echo $v_student->type_name ?><br>
                                    <a href="#" class="" data-toggle="modal" data-target="#changeRole">Change Role</a>
                                </td>
                                <td><?php
                                    if ($v_student->status == '1') {
                                        echo 'Active';
                                        ?>
                                        <a href="<?php echo base_url(); ?>smis/make_student_inactive/<?php echo $v_student->student_id; ?>"><i class="fa fa-user-times" title="Inactive"></i></a>
                                        <?php
                                    } else if ($v_student->status == '2') {
                                        echo 'Inactive';
                                        ?>

                                        <a href="<?php echo base_url(); ?>smis/make_student_active/<?php echo $v_student->student_id; ?>">
                                            <i class="fa fa-user-plus" title="Active"></i></a>
                                        <?php
                                    } else {
                                        echo 'Archived';
                                        ?>
                                        <a href="<?php echo base_url(); ?>smis/make_student_active/<?php echo $v_student->student_id; ?>"><i class="fa fa-user-plus" title="Active"></i> </a>
                                    <?php } ?>
                                </td>

                                <td>
                                    <a href="<?php echo base_url(); ?>smis/edit_student/<?php echo $v_student->student_id; ?>"><div class="span1"><i class="fa fa-edit">Edit</i></div></a>
                                    <?php if ($v_student->status != 3) { ?><a href="<?php echo base_url(); ?>smis/make_student_archived/<?php echo $v_student->student_id; ?>" onclick="return checkAction('delete');"><i class="fa fa-remove">Delete</i></a><?php } ?>
                                </td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
                <br>

            </form>

            <div class="col-lg-12 col-md-12 col-sm-12" >
                <hr>
                <form>
                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <label for="per_page_user">Per Page: </label>
                        <select>
                            <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>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <a href="<?php echo base_url(); ?>super_admin/user_list/<?php echo $student_type . '/' . '1'; ?>" class='btn btn-sm btn-success'>Start</a>
                        <a href="<?php echo base_url(); ?>super_admin/user_list/<?php echo $student_type . '/' . '1'; ?>" class='btn btn-sm btn-success'>Prev</a>
                    </div>
                    <div class='col-lg-5 col-md-5 col-sm-5'>
                        <?php $number_of_pages = $total_student / 10 ?>
                        <?php for ($i = 0; $i < $number_of_pages; $i++) { ?>
                            <a href="<?php echo base_url(); ?>super_admin/<?php echo $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/' . $this->uri->segment(4) . '/' . $i * 10; ?>" class='btn btn-sm btn-default'><?php echo $i; ?></a>
                        <?php } ?>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <a href="<?php echo base_url(); ?>super_admin/user_list/<?php echo $student_type . '/' . '1'; ?>" class='btn btn-sm btn-success'>Next</a>
                        <a href="<?php echo base_url(); ?>super_admin/user_list/<?php echo $student_type . '/' . '1'; ?>" class='btn btn-sm btn-success'>Last</a>
                    </div>
                </form>
                <br>
                <hr>
            </div>
        </div>


    </div>  
</div>  

<!-- Modal Start For Change Role and Status-->
<div class="modal fade" id="changeRole" tabindex="-1" role="dialog" aria-labelledby="changeRole" 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">Change Role</h4>
            </div>
            <form name="changeRole">
                <div class="modal-body">

                    <label for="type_id">User role:</label><span>*</span>
                    <select class="form-control" name="type_id" id="type_id" required>
                        <option value="">--Select User Role--</option>
                        <?php foreach ($student_types as $v_student_type) { ?>
                            <option value="<?php echo $v_student_type->type_id; ?>" <?php
                            if ($v_student_type->type_name == $student_type) {
                                echo 'selected';
                            }
                            ?>> <?php echo $v_student_type->type_name ?></option>
                                <?php } ?>
                    </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary" onclick="changeUsersRole();">Save changes</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal fade" id="assignCourse" tabindex="-1" role="dialog" aria-labelledby="assignCourse" 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">Change Role</h4>
            </div>
            <form name="assignCourse">
                <div class="modal-body">
                    <label for="category_id">Select Course Category:</label><span>*</span>
                    <select class="form-control" name="category_id" id="category_id" required>
                        <option value="">--Select Category--</option>
                        <?php foreach ($course_categories as $v_category) { ?>
                            <option value="<?php echo $v_category->category_id; ?>" <?php
                            if ($v_category->category_name == $student_type) {
                                echo 'selected';
                            }
                            ?>> <?php echo $v_category->category_name; ?></option>
                                <?php } ?>
                    </select>

                    <label for="type_id">Select Course:</label><span>*</span>                    
                    <div id="course_list"></div>
                    <select class="form-control" name="course_id" id="type_id" required>
                        <option value="">--Select Course --</option>
                        <?php foreach ($courses as $v_course) { ?>
                            <option value="<?php echo $v_course->course_id; ?>" <?php echo $v_course->course_name ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary" onclick="changeUsersRole();">Save changes</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="selectRole" tabindex="-1" role="dialog" aria-labelledby="selectRole" 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">Select User By Role</h4>
            </div>
            <form name="selectRole" action="<?php echo base_url(); ?>super_admin/view_user_list" method="post">
                <div class="modal-body">
                    <label for="type_id">User role:</label><span>*</span>
                    <select class="form-control" name="type_id"  required>
                        <option value="">--Select User Role--</option>
                        <?php foreach ($student_types as $v_student_type) { ?>
                            <option value="<?php echo $v_student_type->type_id; ?>" > <?php echo $v_student_type->type_name ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">View User</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="changeStatus" tabindex="-1" role="dialog" aria-labelledby="changeStatus" 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">Change User Status</h4>
            </div>
            <form>
                <div class="modal-body">
                    <h3>Select Status</h3>
                    <select class="form-control" name="change_status" id="change_status" required>
                        <option value="">--Select User Status--</option>
                        <option value="1">Active</option>
                        <option value="2">Inactive</option>
                        <option value="3">Archive</option>
                    </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" onclick="changeUsersStatus();">Save changes</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="selectStatus" tabindex="-1" role="dialog" aria-labelledby="selectStatus" 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">Select User By Status</h4>
            </div>
            <form name="selectStatus" action="<?php echo base_url(); ?>super_admin/view_user_list" method="post">
                <div class="modal-body">
                    <h3>Select Status</h3>
                    <select class="form-control" name="status" required>
                        <option value="">--Select User Status--</option>
                        <option value="1">Active</option>
                        <option value="2">Inactive</option>
                        <option value="0">Archive</option>
                    </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">View User</button>
                </div>
            </form>
        </div>
    </div>
</div>

<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_csv_file" method="post" name="import_csv" enctype="multipart/form-data" >
                        <div class="form-group col-sm-8" >
                            <label for="import_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="import_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>

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