<?php 
    $person_id = $this->session->userdata('person_id');
?>

<div class="col-sm-12 gray text-left" style="border-bottom: 2px solid #8CC73F;font-weight: bold">
    <div class="col-sm-2" >Image</div>
    <div class="col-sm-3" >Name</div>
    <div class="col-sm-4" >Email</div>
    <!--<div class="col-sm-2" style="padding: 0">Mobile</div>-->
    <div class="col-sm-1" >Status</div>
    <div class="col-sm-2" >Action</div>
</div>

<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 + '.';
            }
        } else {
            for (i = 0; i < field.length; i++)
                field[i].checked = false;
            list = '';
        }
    }

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

    function setInstantUserIdList(userID) {
        list += userID + '.';
    }
</script>
<div class="col-sm-12">
    <br>
</div>
<div>
    <?php
    foreach ($resource_person as $v_resource_person) {
        if ($person_info[$v_resource_person->person_id]) {
            $person_url = $person_info[$v_resource_person->person_id]->url;
            ?>
            <div id="actions_for<?php echo $v_resource_person->person_id; ?>">
                <div class="col-sm-12 gray text-left">
                    <div class="col-sm-2" style="width:100px;" >
                        <a href="#">
                            <?php
                            if ($person_info[$v_resource_person->person_id]->person_image_thumb) {
                                ?>
                                <img class="img-responsive" style="margin: 0 auto; max-height: 60px; cursor: pointer;" 
                                     src="<?php echo base_url() . 'content-library/' . $person_url . '/' . $person_info[$v_resource_person->person_id]->person_image_thumb; ?>"  
                                     alt="image">
                                     <?php
                                 } else {
                                     ?>
                                <img class="img-responsive" style="margin: 0 auto; max-height: 80px; cursor: pointer;" 
                                     src="<?php echo base_url() ?>image/no_profile_picture.png"
                                     alt="image">

                            <?php } ?>
                        </a>
                    </div>

                    <div class="col-sm-3" >
                        <a href="<?php echo base_url() . $person_url . '/profile'; ?>" class="padding-zero" target="_blank">
                            <?php
                            //echo $person_info[$v_resource_person->person_id]->person_first_name . ' ' . $person_info[$v_resource_person->person_id]->person_last_name;
                            if (strlen($person_info[$v_resource_person->person_id]->person_first_name) && strlen($person_info[$v_resource_person->person_id]->person_last_name) < 20) {
                                echo $person_info[$v_resource_person->person_id]->person_first_name . ' ' . $person_info[$v_resource_person->person_id]->person_last_name;
                            } else {
                                echo substr($person_info[$v_resource_person->person_id]->person_first_name, 0, 30) . ' ' . substr($person_info[$v_resource_person->person_id]->person_last_name, 0, 20) . '...';
                            }
                            ?>
                        </a>
                    </div>
                    <div class="col-sm-4" >
                        <?php
                        //echo $person_info[$v_resource_person->person_id]->person_email 
                        if (strlen($person_info[$v_resource_person->person_id]->person_email) < 40) {
                            echo $person_info[$v_resource_person->person_id]->person_email;
                        } else {
                            echo substr($person_info[$v_resource_person->person_id]->person_email, 0, 35) . '...';
                        }
                        ?>
                    </div>

                    <div class="col-sm-1">
                        <?php
                        $status = $person_info[$v_resource_person->person_id]->person_status;
                        if ($status == 0) {
                            echo 'Inactive';
                        } else if ($status == 1) {
                            echo 'Active';
                        } else if ($status == 4) {
                            echo 'Inactive';
                        }
                        ?>



                    </div>
                    <div class="col-sm-2" style="text-align: center; float: left;">

                        <?php
                        $encrypted_url = $this->encrypt->encode($person_info[$v_resource_person->person_id]->url);
                        $encrypted_url = str_replace("/", "%F2", $encrypted_url);
                        if ($person_id != $person_info[$v_resource_person->person_id]->person_id) {
                            ?>

                            <a href="<?php echo base_url() . 'edit-teacher/' . $encrypted_url; ?>" > 
                                <i class="fa fa-edit"></i> 
                            </a>

                            <?php
                            $person_id = $person_info[$v_resource_person->person_id]->person_id;
                            $status = $person_info[$v_resource_person->person_id]->person_status;
                            $url = $person_info[$v_resource_person->person_id]->url;
                            if ($status == 0) {
                                ?>
                                <a href="javascript:;" onclick="return checkForAction('<?php echo base_url() . 'make-account-active/' . $encrypted_url; ?>', 'Active', '<?php echo $person_id; ?>')">
                                    <i class="fa  fa-user-plus" title="Active"></i>
                                </a>&nbsp;&nbsp;
                            <?php } else if ($status == 1) { ?>
                                <a href="javascript:;" onclick="return checkForAction('<?php echo base_url() . 'make-account-inactive/' . $encrypted_url; ?>', 'Inactive', '<?php echo $person_id; ?>')">
                                    <i class="fa  fa-user-times" title="Inactive"></i>
                                </a>&nbsp;&nbsp;
                            <?php } else if ($status == 4) { ?>
                                <a href="javascript:;" onclick="return checkForAction('<?php echo base_url() . 'make-account-active/' . $encrypted_url; ?>', 'Active', '<?php echo $person_id; ?>')">
                                    <i class="fa  fa-user-plus" title="Active"></i>
                                </a>&nbsp;&nbsp;
                            <?php } ?>

                        <?php } else { ?>
                            <a href="<?php echo base_url() . 'edit-teacher/' . $encrypted_url; ?>" > 
                                <i class="fa fa-edit"></i> 
                            </a>
                        <?php } ?>
                    </div>
                </div>
                <div class="col-sm-12">
                    <br>
                </div>
            </div>
            <?php
        }
    }
    ?>
</div>

<script>

    function checkForAction(url, action, personID) { // check for Active Inactives
        swal({
            title: "",
            text: "Are you sure you want to " + action + " this Teacher?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#8CC73F',
            confirmButtonText: 'Yes',
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
//                                document.location.href = url;
                        serverPage = url;
                        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("actions_for" + personID).innerHTML = xmlhttp.responseText;

                            }
                        }
                        xmlhttp.send(null);
                    }
                });
    }

    function changeUsersRole(userRoleId)
    {
        serverPage = '<?php echo base_url(); ?>super_admin/change_users_role/' + list + '/' + userRoleId;
        xmlhttp.open("GET", serverPage);
        xmlhttp.onreadystatechange = function ()
        {
            //                                        alert(xmlhttp.readyState);
            if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
            {
                document.getElementById('res').innerHTML = xmlhttp.responseText;
            }
            location.reload();
        };
        xmlhttp.send(null);
    }
</script>

<?php
echo $pagination_link; 
?>





