



<?= $this->element('user_management_nav', array('title' => __('User Management'), 'permissions' => $user_permission,
    'showNavigationButtons' => true)); ?>
<?php
echo $this->Html->script('bulk_select.js');
$menu_modules = unserialize($this->request->session()->read('modules'));
?>


<div class="row">
    <div class="col-md-12">
        <div class="box box-primary">
            <div class="box-header">

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

                                <div class="clearfix">&nbsp;</div>
                                <div class="row">
                                    <div class="col-md-6 ">
                                        <div class="row">

                                            <?= $this->Form->create(null, array('type' => 'get', 'id' => 'limitForm')); ?>
                                            <div class="col-md-3"><strong>Show</strong></div>
                                            <div class="col-md-6"><select name="page_limit"
                                                                          class="form-control input-sm"
                                                                          onchange="this.form.submit()">
                                                    <option value="10" <?php echo $page_limit == "10" ? 'selected="selected"' : '' ?>>
                                                        10
                                                    </option>
                                                    <option value="25" <?php echo $page_limit == "25" ? 'selected="selected"' : '' ?>>
                                                        25
                                                    </option>
                                                    <option value="50" <?php echo $page_limit == "50" ? 'selected="selected"' : '' ?>>
                                                        50
                                                    </option>
                                                    <option value="100" <?php echo $page_limit == "100" ? 'selected="selected"' : '' ?>>
                                                        100
                                                    </option>
                                                </select>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- /col-md-6 -->
                            <div class="col-md-8">


                                <div class="row">

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

                                        <div class="row">


                                            <div class="col-md-6 pull-right" style="margin-top: 25px;">

                                                <div class="box-tools">
                                                    <div class="input-group input-group-sm">
                                                        <?= $this->Form->input('', ['placeholder' => __('SEARCH'), 'class' => 'form-control', 'type' => 'text', 'name' => 'search', 'value' => $searchText, 'id' => 'search']); ?>
                                                        <div class="input-group-btn">
                                                            <?= $this->Form->submit(__('User Search'), ['class' => 'btn btn-success btn-flat']); ?>
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>


                                    </div>
                                    <div class="col-md-12">
                                        &nbsp;
                                    </div>

                                    <!-- /row -->
                                </div>
                                <?= $this->Form->end(); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- /.box-header -->
            <div class="box-body table-responsive ">
                <table class="table table-striped table-bordered table-hover">

                    <thead>
                    <tr>
                        <th>
                            <div> <!-- <div class="checkbox"> -->
                                <input type="checkbox" id="ContentSelect">
                                <label class="image-checkbox-label" for="ContentSelect"></label>
                            </div>
                        </th>
                        <th>
                            <?= $this->Paginator->sort('username') ?>
                        </th>

                        <th>
                            <?= $this->Paginator->sort('email') ?>
                        </th>
                        <th class="text-center">
                            <?= $this->Paginator->sort('is_allow_defult_pass', 'Default Password') ?>
                        </th>

                        <th>
                            <?= $this->Paginator->sort('created_on') ?>
                        </th>


                        <th class="text-left"><?= __('Action') ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($cmsusers as $cmsuser):
                        $isMember = "No";
                        $is_member_status = 0;
                        $menu_text = 'Pause Membership';
                        $operation_type = 'pause';

                        if (isset($cmsUserUsergroupAssoc[$cmsuser->id]) && in_array(CUSTOMER_USER_GROUP_ID, $cmsUserUsergroupAssoc[$cmsuser->id])) {
                            $isMember = "Yes";
                            $is_member_status = 1;
                        } else if (isset($cmsuser->CU['usergroup_id']) && $cmsuser->CU['usergroup_id'] == CUSTOMER_USER_GROUP_ID) {
                            $isMember = "Yes";
                            $is_member_status = 1;
                        }

                        $icon_class = 'fa fa-pause-circle-o';
                        if ($cmsuser->is_active == STATUS_PAUSE_MEMBERSHIP) {
                            $isMember = "Yes/Pause";
                            $menu_text = 'Assign Membership';
                            $icon_class = 'fa fa-user-circle';
                            $operation_type = 'assign';
                        }

                        $default_pass = "No";
                        if ($cmsuser->is_allow_defult_pass == 1) {
                            $default_pass = "Yes";
                        }

                        ?>
                        <tr>
                            <td>
                                <div> <!-- <div class="checkbox"> -->
                                    <input type="checkbox"
                                           id="content_<?= $cmsuser->id ?>">
                                    <label class="image-checkbox-label"
                                           for="content_<?= $cmsuser->id ?>"></label>
                                </div>
                            </td>

                            <td><?= h($cmsuser->username) ?></td>
                            <td>  <?= h($cmsuser->email) ?></td>
                            <td class="text-center">  <?= h($default_pass) ?></td>

                            <td> <?= h($cmsuser->created_on) ?></td>

                            <td class="text-left">

                                <div class="btn-group">

                                    <button type="button" class="btn btn-success dropdown-toggle"
                                            data-toggle="dropdown">
                                        <i class="fa fa-list"></i> <span class="caret"></span>
                                        <span class="sr-only">Toggle Dropdown</span>
                                    </button>
                                    <ul class="dropdown-menu" role="menu">

                                        <?php
                                        $added = [];

                                        foreach ($user_permission as $permission) {

                                            if ($permission['page_id'] == $page_list['edit'] && !in_array($page_list['edit'], $added)) {
                                                array_push($added, $page_list['edit']); ?>
                                                <li>

                                                    <?= $this->Html->link('<i class="fa fa-pencil"></i>' . __('Edit'), '/users/edit/' . $cmsuser->id, array('escape' => false)) ?>
                                                </li>
                                                <?php
                                            } elseif ($permission['page_id'] == $page_list['delete'] && !in_array($page_list['delete'], $added)) {
                                                array_push($added, $page_list['delete']); ?>
                                                <li>

                                                    <?= $this->Form->postLink(' <i class="fa fa-trash-o"></i>' . __('Delete'), ['action' => 'delete', $cmsuser->id], ['confirm' => __('Are you sure you want to delete {0}?', $cmsuser->username), 'escape' => false]) ?>
                                                </li>

                                                <?php
                                            } elseif ($permission['page_id'] == $page_list['allowaction'] && !in_array($page_list['allowaction'], $added)) {
                                                array_push($added, $page_list['allowaction']); ?>
                                                <?php if ($cmsuser->is_allow_defult_pass == 0) { ?>
                                                    <li>

                                                        <?= $this->Html->link('<i class="fa fa-tasks"></i>' . __('Allow Default Password'), '/users/allowaction/' . $cmsuser->id, array('escape' => false)) ?>
                                                    </li>
                                                <?php } ?>

                                                <?php
                                            } elseif ($permission['page_id'] == $page_list['revokeaction'] && !in_array($page_list['revokeaction'], $added)) {
                                                array_push($added, $page_list['revokeaction']); ?>

                                                <?php if ($cmsuser->is_allow_defult_pass == 1) { ?>
                                                    <li>

                                                        <?= $this->Html->link('<i class="fa fa-undo"></i>' . __('Revoke Default Password'), '/users/revokeaction/' . $cmsuser->id, array('escape' => false)) ?>
                                                    </li>
                                                <?php } ?>

                                                <?php
                                            }

                                        }
                                        ?>


                                    </ul>
                                </div>


                            </td>
                        </tr>

                    <?php

                    endforeach; ?>
                    </tbody>
                </table>


            </div>
            <!-- /.box-body -->
            <?php
            //debug($this->Paginator->params());
            if ($this->Paginator->params()['nextPage']) {
                $start_limit = (($this->Paginator->params()['page'] * $this->Paginator->params()['current']) - $this->Paginator->params()['perPage']) + 1;
                $end_limit = $this->Paginator->params()['page'] * $this->Paginator->params()['current'];
            } else {
                if ($this->Paginator->params()['count'] != 0) {
                    $start_limit = ($this->Paginator->params()['count'] - $this->Paginator->params()['current']) + 1;
                } else {
                    $start_limit = 0;
                }
                $end_limit = $this->Paginator->params()['count'];
            }
            ?>
            <div class="box-footer clearfix">
                <div class="row">
                    <div class="col-md-6"><p
                                style="padding-top:20px;"><?php echo 'Showing ' . $start_limit . ' to ' . $end_limit . ' of ' . $this->Paginator->params()['count'] . ' entries'; ?></p>
                    </div>
                    <div class="col-md-6">

                        <div class="paginator pull-right">
                            <ul class="pagination ">
                                <?= $this->Paginator->prev('< ' . __('previous')) ?>
                                <?= $this->Paginator->numbers() ?>
                                <?= $this->Paginator->next(__('next') . ' >') ?>
                            </ul>

                        </div>

                    </div>

                </div>
            </div>

        </div>
        <!-- /.box -->


    </div>


</div>


<script>
    $(document).ready(function () {
        $("#bulk_action_apply").click(function (e) {
            var selectedContent = $("input[name='selected_content']").val();
            if (selectedContent == null || selectedContent == "") {
                e.preventDefault();
                $('#status-area').flash_message({
                    text: 'Select atleast one item in the list!',
                    how: 'append'
                });
            }
        });
    });

    function exportMember(elem) {
        $('input[name=isExport]').val(1);
        document.getElementById('filter').submit();
    }
</script>
