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

<div id="change">
    <div class="col-sm-10 col-sm-offset-3 main col-md-10 col-md-offset-2 main">

        <div class="col-sm-4 col-md-6">
            <a href="#" data-toggle="modal" data-target="#videoUploadModal">
                <span class="btn btn-success">Upload</span>
            </a>
        </div>

        <!-- Select User By Role and Status -->

        <div class="col-sm-4 col-md-4 main">
            <form name="control_form">
                <select for="user_status" name="user_status" id="user_status" onchange="selectUser(user_role_id2.value, this.value, 'change');">
                    <!--<option value=''> Select Status</option>-->
                    <option value='all'> All</option>
                    <option value='0'> Inactive</option>
                    <option value='1'> Active</option>
                    <option value='2'> Archive</option>
                </select>
            </form> 
        </div>

        <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>All Video List</span>
            </div>
            <hr>
            <div class="span11 right">
                <div class="col-lg-6 col-md-4" >
                    <h4> Video Information</h4> 
                </div>
                <div class="col-lg-2 col-md-2">
                </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.video_id)"/></th>
                                <th>Sl No</th>
                                <th>Title</th>
                                <th>Video Category</th>
                                <th>Resource Person Name</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 ($("#video_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 ($video_management_item as $v_video_management) {
                            ?>
                            <tr>
                                <td>
                                    <input name="video_management_id" id="video_management_id<?php echo $v_video_management->video_management_id; ?>" type="checkbox"  value="<?php echo $v_video_management->video_management_id; ?>" onchange="setUserIdList(this.value);"/>
                                </td>

                                <td><?php echo $v_video_management->video_management_id ?></td>

                                <td><?php echo $v_video_management->video_title; ?></td>
                                <td><?php echo $v_video_management->course_category_name; ?></td>
                                <td><?php echo $v_video_management->person_first_name; ?></td>
                                <!--
                                    Action: Active, Inactive, Archive, Edit
                                -->

                                <td><?php
                                    if ($v_video_management->video_management_status == '1') {
                                        echo '<p style="color:limegreen;">Published</p>';
                                        ?>
                                        <a href="<?php echo base_url(); ?>super_admin_video/make_video_management_inactive/<?php echo $v_video_management->video_management_id; ?>"><i class="fa fa-user-times" title="Inactive"></i></a>
                                        <?php
                                    } else if ($v_video_management->video_management_status == '0') {
                                        echo '<p style="color:red;">Unpublished</p>';
                                        ?>
                                        <a href="<?php echo base_url(); ?>super_admin_video/make_video_management_active/<?php echo $v_video_management->video_management_id; ?>">
                                            <i class="fa fa-user-plus" title="Active"></i></a>
                                        <?php
                                    } else if ($v_video_management->video_management_status == '2') {
                                        echo '<p style="color:blue;">Archived';
                                        ?>
                                        <a href="<?php echo base_url(); ?>super_admin_video/make_video_management_active/<?php echo $v_video_management->video_management_id; ?>"><i class="fa fa-user-plus" title="Active"></i> </a>
                                    <?php } ?>
                                </td>

                            <script>
                                function changeUsersRole(userRoleId)
                                {
                                    //                userRoleId = document.getElementById("video_role_modal_input").value;
                                    serverPage = '<?php echo base_url(); ?>super_admin_video/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_video/edit_upload_video_information/<?php echo $v_video_management->video_management_id; ?>"><div class="span1"><i class="fa fa-edit">Edit</i></div></a>
                                <a href="<?php echo base_url(); ?>super_admin_video/video_management_view/<?php echo $v_video_management->video_management_id; ?>" target="blank"><div class="span1"><i class="fa fa-edit">View video</i></div></a>
                                <?php if ($v_video_management->video_management_status != 2) { ?><a href="<?php echo base_url(); ?>super_admin_video/archive_video_management/<?php echo $v_video_management->video_management_id; ?>" onclick="return checkAction('delete');"><i class="fa fa-remove">Delete</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_video_management; ?></p>
                        </div>

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

                        if ($limit == 'all') {
                            $number_of_pages = ceil($total_video_management / $total_video_management);
                        } else {
                            $number_of_pages = ceil($total_video_management / $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 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; ?></a>
                            <?php } ?>
                        </div>

                        <div class="col-lg-2 col-md-2 col-sm-2">
                            <?php if ($start + $limit < $total_video_management) { ?>
                                <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>
        </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("video_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) {
        alert(perPage);
        serverPage = '<?php echo base_url(); ?>super_admin_video/set_per_page/' + perPage;
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function ()
        {
            alert(xmlhttp.readyState);
            alert(xmlhttp.status);
            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>