<!DOCTYPE html>
<html lang="en">

<?php
include('include/head.php');
include("loginCheck.php");
include('include/header.php');
include('include/menu.php');
requireLogin();
?>

<div id="main-content">
    <div class="container-fluid">

        <div class="block-header">
            <div class="row">
                <div class="col-lg-5 col-md-8 col-sm-12">

                    <h2>
                        <a href="javascript:void(0);" onclick="window.history.back();"
                            class="btn btn-xs btn-link btn-toggle-fullwidth">
                            <i class="fa fa-arrow-left"></i>
                        </a>

                        Search Member
                    </h2>

                    <ul class="breadcrumb">
                        <li class="breadcrumb-item"><a href="dashboard"><i class="icon-home"></i></a></li>
                        <li class="breadcrumb-item">Member</li>
                        <li class="breadcrumb-item active">Search Member</li>
                    </ul>

                </div>
            </div>
        </div>

        <div class="row clearfix">
            <div class="col-md-12">

                <div class="card">
                    <div class="body">

                        <form onsubmit="return false;">
                            <div class="row">

                                <div class="col-lg-4 col-md-12">
                                    <div class="input-group">

                                        <input type="text" id="searchValue" class="form-control"
                                            placeholder="Search User ID / Name / Phone"
                                            onkeypress="return catchEnter(event)">

                                    </div>
                                </div>

                                <div class="col-lg-2 col-md-12">

                                    <button type="button" class="btn btn-primary" onclick="mySearch()"
                                        id="SubmitSearch">

                                        Search

                                    </button>

                                </div>

                            </div>
                        </form>

                    </div>
                </div>

            </div>
        </div>

        <div id="showResult"></div>

    </div>
</div>

<?php include('include/footer.php'); ?>

<script>

    /* ENTER KEY SEARCH */
    function catchEnter(e) {

        if (e.key === "Enter") {
            e.preventDefault();
            mySearch();
        }

    }

    /* MEMBER SEARCH */
    function mySearch() {

        let search_value = $('#searchValue').val().trim();

        if (search_value === "") {
            alert("Please enter search value");
            return;
        }

        $("#showResult").html(
            '<div class="text-center p-4">Searching...</div>'
        );

        $.ajax({

            url: "ajaxCalls/searchAllAjax.php",

            method: "GET",

            data: { search_value: search_value },

            success: function (result) {

                $("#showResult").html(result);

            },

            error: function () {

                $("#showResult").html(
                    '<div class="text-danger p-4">Error loading data</div>'
                );

            }

        });

    }

    /* OPEN USER DASHBOARD */
    function memberDashboard(userId, password, memberId) {

        let url = '../User/setSessionAdvice.php?userId=' + userId +
            '&mID=' + password +
            '&codeGenerate=' + memberId;

        window.open(url, '_blank');

    }

    /* BLOCK USER */
    function blockUser(memberId, blockStatus) {

        if (confirm('Are you sure to Block this Member?')) {

            $.ajax({

                type: "POST",

                url: 'ajaxCalls/blockUnBlockUserAjax',

                data: { memberId: memberId, blockStatus: blockStatus },

                success: function (data) {

                    alert('User Block Successfully');

                    mySearch();

                }

            });

        }

    }

    /* UNBLOCK USER */
    function unBlockUser(memberId, blockStatus) {

        if (confirm('Are you sure to Un-Block this Member?')) {

            $.ajax({

                type: "POST",

                url: 'ajaxCalls/blockUnBlockUserAjax',

                data: { memberId: memberId, blockStatus: blockStatus },

                success: function (data) {

                    alert('User Un-Block Successfully');

                    mySearch();

                }

            });

        }

    }

    /* MENU ACTIVE */
    document.getElementById("Members").classList.add("active");
    document.getElementById("searchMember").classList.add("active");

</script>

</body>

</html>