<div class="col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <a href="<?php echo base_url(); ?>super_admin_course/add_course_category" class="btn btn-sm btn-success">Add Category</a>
    <a href="<?php echo base_url(); ?>super_admin_course/add_course" class="btn btn-sm btn-success">Add Course</a>
    <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_course/shorted_category_list/" class="btn btn-sm btn-success" >Short category by name</a> ||

    <select for="category_id" name="category_id2" id="category_id2" onchange="selectCourseByCategory(this.value, course_status.value, 'course_list');">
        <option value=''> Select Category</option>
        <?php foreach ($course_categories as $v_category) { ?>
            <option value="<?php echo $v_category->course_category_id; ?>"> <?php echo $v_category->course_category_name ?></option>
        <?php } ?>
    </select>
    <select for="course_status" name="course_status" id="user_status" onchange="selectCourseByStatus(category_id2.value, this.value, 'course_list');">
        <option value=''> Select Course Status</option>
        <option value='1'> Active</option>
        <option value='2'> Inactive</option>
        <option value='3'> Archive</option>
    </select>

    <div class="container col-sm-8 col-sm-offset-2 col-md-offset-0 col-md-12" id="res">
        <div class="row">

        </div>

        <hr>
        <div class="">
            <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>
            <span><?php ?> Courses</span>
        </div>
        <hr>
        <div class="span11 right">
            <div class="col-lg-6 col-md-4" >
                <h4><?php // echo $user_role;  ?>Course List</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_course/export_course_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_category" id="all_category" onchange="toggleAllCategorySelection(document.myform.category_id)"/></th>
                            <th>Course Name</th>
                            <th>Resource Person</th>
                            <th>Category Name</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $i = 1;
                        foreach ($courses as $v_course) {
                            ?>
                            <tr>
                                <td>
                                    <input name="category_id" id="category_id<?php echo $v_course->course_id; ?>" type="checkbox"  value="<?php echo $v_course->course_id; ?>" onchange="setUserIdList(this.value);"/>
                                </td>
                                <!--<td><?php // echo $v_course->course_id ?></td>-->
                                <!--<td><img src="<?php // echo base_url() . $v_course->course_image_thumb; ?>" width="50" height="50"> </td>-->
                                <td><?php echo $v_course->course_name; ?></td>
                                <td><?php echo ''; ?></td>
                                <td><?php echo $v_course->course_category_name; ?></td>
                                <td><?php
                                    if ($v_course->course_status == '1') {
                                        echo "<p style='color:Green;'>Active";
                                        ?>
                                        <a href="<?php echo base_url(); ?>super_admin_course/make_course_inactive/<?php echo $v_course->course_id; ?>">
                                            <i class="fa fa-user-times" title="Inactive"></i></a>
                                        <?php
                                    } else if ($v_course->course_status == '2') {
                                        echo "<p style='color:red;'>Inactive";
                                        ?>

                                        <a href="<?php echo base_url(); ?>super_admin_course/make_course_active/<?php echo $v_course->course_id; ?>">
                                            <i class="fa fa-user-plus" title="Active"></i></a>
                                        <?php
                                    } else {
                                        echo "<p style='color:red;'>Archived";
                                        ?>
                                        <a href="<?php echo base_url(); ?>super_admin_course/make_course_active/<?php echo $v_course->course_id; ?>">
                                            <i class="fa fa-user-plus" title="Active"></i> </a>
                                    <?php } ?>
                                </td>

                                <td>
                                    <a href="<?php echo base_url(); ?>super_admin_course/edit_course/<?php echo $v_course->course_id; ?>"><div class="span1"><i class="fa fa-edit">Edit</i></div></a>
                                    <a href="<?php echo base_url(); ?>super_admin_course/view_course_information/<?php echo $v_course->course_id; ?>">
                                        <div class="span1"><i class="fa fa-edit">View</i></div></a>
                                    <?php if ($v_course->course_status != 3) { ?>
                                        <a href="<?php echo base_url(); ?>super_admin_course/make_course_archived/<?php echo $v_course->course_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>

            <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_category">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_course/manage_course_category" class='btn btn-sm btn-success'>Start</a>
                        <a href="<?php echo base_url(); ?>super_admin_course/manage_course_category" 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_user / 10 ?>
                        <?php // for ($i = 0; $i < $number_of_pages; $i++) { ?>
                        <a href="<?php echo base_url(); ?>cmis/manage_course_category" 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_course/manage_course_category" class='btn btn-sm btn-success'>Next</a>
                        <a href="<?php echo base_url(); ?>super_admin_course/manage_course_category" 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="user_role_id">User role:</label><span>*</span>
                    <select class="form-control" name="user_role_id" id="user_role_id" required>
                        <option value="">--Select User Role--</option>
                        <?php foreach ($user_roles as $v_category_role) { ?>
                            <option value="<?php echo $v_category_role->user_role_id; ?>" <?php
                            if ($v_category_role->role_name == $user_role) {
                                echo 'selected';
                            }
                            ?>> <?php echo $v_category_role->role_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="user_role_id">User role:</label><span>*</span>
                    <select class="form-control" name="user_role_id"  required>
                        <option value="">--Select User Role--</option>
                        <?php foreach ($user_roles as $v_category_role) { ?>
                            <option value="<?php echo $v_category_role->user_role_id; ?>" > <?php echo $v_category_role->role_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_course/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-->


<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>