<?php
$table = 'users';

if (is_post() && post('needle')) {
    $where = "";
    $where .= "LOWER(login) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(email) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(phone) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(ip) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(payeer) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(perfectmoney) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(qiwi) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(yandexmoney) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(advcash) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(card) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(bitcoin) LIKE '%".strtolower(post('needle'))."%'";
    $where .= " OR LOWER(okpay) LIKE '%".strtolower(post('needle'))."%'";
    //$where .= " OR LOWER(card) LIKE '%".strtolower(post('needle'))."%'";
    $list = get_list($table, $where, 'id desc');
} else {
    $list = [];
}
?>

<div id="page-wrapper">



    <div class="container-fluid">
        <!-- Flot Charts -->
        <div class="row">
            <div class="col-lg-12">
                <h2 class="page-header"><?php echo T('Поиск пользователей'); ?></h2>
            </div>
        </div>
        <!-- /.row -->

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-bar-chart-o"></i> <?php echo T('Список'); ?></h3>
                    </div>
                    <div class="panel-body">
                        <div class="flot-chart">
                            <div class="flot-chart-content" id="flot-line-chart">
                                <div>
                                    <form enctype="multipart/form-data" action = "" method = "POST">
                                        <div class="input-group" style="max-width: 400px;">
                                            <input name="needle" class="form-control" placeholder="<?php echo T('Логин'); ?>">
                                            <span class="input-group-btn">
                                                <button class="btn btn-default" type="submit" name="find"><?php echo T('Искать'); ?></button>
                                            </span>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="flot-chart">
                            <div class="flot-chart-content" id="flot-line-chart">
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <th><?php echo T('ID'); ?></th>
                                            <th><?php echo T('Логин'); ?></th>
                                            <th><?php echo T('Реферовод'); ?></th>
                                            <th><?php echo T('IP'); ?></th>
                                            <th><?php echo T('Информация'); ?></th>
                                            <th><?php echo T('Изменить');?></th>
                                            <th><?php echo T('Забанить'); ?></th>
                                            <th><?php echo T('Удалить'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php foreach ($list as $item) { ?>
                                            <tr>
                                                <td>
                                                    <?php echo escape($item['id']); ?>
                                                </td>
                                                <td>
                                                    <?php echo escape($item['login']); ?>
                                                </td>
                                                <td>
                                                    <?php echo escape($item['refer']); ?>
                                                </td>
                                                <td>
                                                    <?php echo escape($item['ip']); ?>
                                                </td>
                                                <td><?php echo adg_gen_link_item_users($item['login'], 'Информация'); ?></td>
                                                <td>
                                                    <form action="?page=<?php echo $table; ?>" method="get">
                                                        <input type = "hidden" name = "page" value = "<?php echo $table; ?>">
                                                        <input type = "hidden" name = "id" value = "<?php echo $item['id']; ?>">
                                                        <button type="submit" class="btn btn-default">Изменить</button>
                                                    </form>
                                                </td>
                                                <td>
                                                    <?php echo $item['groups'] === "ban" ? adg_button_ban($item['id'], $item['groups'] === "ban" ? false : true) : adg_button_ban($item['id'], $item['groups'] === "ban" ? false : true); ?>
                                                </td>
                                                <td>
                                                    <?php if (!DEMO) {  button_delete($item['id']); } else { echo $class_error;} ?>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<style>
    .adg_gen_link_item_users {
        display: block;
        border: 1px solid #ccc;
        border-radius: 6px;
        padding: 7px;
        width: 106px;
    }
</style>
