<SCRIPT LANGUAGE="JavaScript">

    var userList = [];
    function checkAll(field)
    {
        for (i = 0; i < field.length; i++) {
            field[i].checked = true;
            userList += field[i].value + '.';
        }
    }

    function uncheckAll(field)
    {
        for (i = 0; i < field.length; i++)
            field[i].checked = false;
        userList = '';
    }

    function setUserIdList(userID)
    {
        if ($("#user_id" + userID).is(":checked")) {
            userList += userID + '.';
        } else {
            userList = userList.replace(userID + ".", "");
        }
    }

    //Create a boolean variable to check for a valid Internet Explorer instance.
    var xmlhttp = false;
    //Check if we are using IE.
    try {
        //If the Javascript version is greater than 5.
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

        //alert ("You are using Microsoft Internet Explorer.");
    } catch (e) {

        //If not, then use the older active x object.
        try {
            //If we are using Internet Explorer.
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            //alert ("You are using Microsoft Internet Explorer");
        } catch (E) {
            //Else we must be using a non-IE browser.
            xmlhttp = false;
        }
    }
    //If we are using a non-IE browser, create a javascript instance of the object.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
        //alert ("You are not using Microsoft Internet Explorer");
    }

    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(objID).innerHTML = xmlhttp.responseText;
                window.localtion.href = '<?php echo base_url(); ?>super_admin';
                window.open();
            }
        }
        xmlhttp.send(null);
    }

    function changeUsersStatus()
    {
//        alert('changeUserStatus');
        userStatus = document.getElementById("change_status").value;
        serverPage = '<?php echo base_url(); ?>super_admin/change_users_status/' + userList + '/' + userStatus;
        alert(serverPage);
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function ()
        {
            alert(xmlhttp.readyState);
            alert(xmlhttp.status);
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                alert(xmlhttp.responseText);
                document.getElementById(objID).innerHTML = xmlhttp.responseText;
                window.localtion.href = '<?php echo base_url(); ?>super_admin';
                window.open();
            }
        }
        xmlhttp.send(null);
    }

</script>
<br>
<div class="col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 ">
    <a href="<?php echo base_url(); ?>super_admin/create" class="btn btn-sm btn-success">Add User</a>
    <a href="#" data-toggle="modal" data-target="#importFile" class="btn btn-sm btn-success">Import CSV File</a>
    <div class="container" id="res">
        <div class="row"></div>
        <hr>
        <div class="">
            <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>->>
        </div>
        <hr>
        <div class="span11 right">
            <div class="col-lg-6 col-md-4" > </div>
            <div class="col-lg-2 col-md-2" > </div>
            <div class="col-lg-3 col-md-3">
                <!--<a href="#" data-toggle="modal" data-target="#importFile" class="btn btn-sm btn-success">Import</a> ||-->
            </div>
        </div>

        <div class="table-responsive col-lg-10 col-md-7 col-sm-5">
            <form name="myform" action=""  method="post">
                <h4>Exported Files</h4>

                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>
                                <input type="checkbox" name="all_user" value="all"/>
                            </th>
                            <th>File ID</th>
                            <th>CSV File Path</th>
                            <th>File Type</th>
                            <th>Date & Time</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $i = 1;
                        foreach ($files as $v_file) {
                            ?>
                            <tr>
                                <td><input name="user_id" id="user_id<?php echo $v_file->file_id; ?>" type="checkbox"  value="<?php echo $v_file->file_id; ?>" onchange="setUserIdList(this.value);"/></td>
                                <td><?php echo $v_file->file_id ?></td>
                                <td><a href="<?php echo base_url() . $v_file->file_path; ?>"><?php echo $v_file->file_path; ?></a></td>
                                <td><?php echo $v_file->file_type; ?></a></td>
                                <td><?php echo $v_file->file_create_date.' - '.$v_file->file_create_time; ?></td>
                                
                                <td><?php
                                    if ($v_file->file_status == '1') {
                                        echo '<p style="color:limegreen;">Active</p>';
                                        ?>
                                        <a href="<?php echo base_url(); ?>super_admin/make_user_inactive/<?php echo $v_file->file_id; ?>"><i class="fa fa-user-times" title="Archive"></i></a>
                                        <?php
                                    } else if ($v_file->file_status == '2'){
                                        echo '<p style="color:blue;">Archived';
                                        ?>
                                        <a href="<?php echo base_url(); ?>super_admin/make_user_active/<?php echo $v_file->file_id; ?>"><i class="fa fa-user-plus" title="Active"></i> </a>
                                    <?php } ?>
                                </td>
                                <td>
                                    <a href="<?php echo base_url() . $v_file->file_status; ?>"><div class="span1"><i class="fa fa-edit">Download User File</i></div></a>
                                </td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
                <br>
            </form>
        </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_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 User Info 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="form-group col-sm-8" >
                                <label for="user_person_info_file" style="float:left;">Select User Person Info 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_person_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>

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