Your IP : 216.73.216.79


Current Path : /var/www/html/dyna-project/views/user/
Upload File :
Current File : /var/www/html/dyna-project/views/user/index.php.20210225

<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\ParamList;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel app\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<div class="kt-subheader   kt-grid__item" id="kt_subheader">
    <div class="kt-container ">
        <div class="kt-subheader__main">
            <h3 class="kt-subheader__title">Manage Staff</h3>
            <div class="kt-subheader__breadcrumbs">
                <span class="kt-subheader__breadcrumbs-separator"></span>
                <span class="kt-subheader__breadcrumbs-link">Settings </span>
                <span class="kt-subheader__breadcrumbs-separator"></span>
                <span class="kt-subheader__breadcrumbs-link"> Manage Staff</span>
                <span class="kt-subheader__breadcrumbs-separator"></span>
                <span class="kt-subheader__breadcrumbs-link"> Staff List</span>
            </div>
        </div>
    </div>
</div>
<div class="user-index">
    <div class="kt-container kt-grid__item kt-grid__item--fluid">
        <div class="kt-portlet kt-portlet--mobile">
            <div class="kt-portlet__head"><?php echo $this->render('_search', ['model' => $searchModel]); ?></div>
            <div class="kt-portlet__body p-0">
                <?=
                GridView::widget([
                    'dataProvider' => $dataProvider,
                    'tableOptions' => ['class' => 'table mb-0 table-borderless table-striped table-hover table-custom'],
                    'pager' => [
                        'firstPageLabel' => '<i class="fa fa-angle-double-left kt-font-brand"></i>',
                        'lastPageLabel' => '<i class="fa fa-angle-double-right kt-font-brand"></i>',
                        'prevPageLabel' => '<i class="fa fa-angle-left kt-font-brand"></i>',
                        'nextPageLabel' => '<i class="fa fa-angle-right kt-font-brand"></i>',
                        'maxButtonCount' => 3,
                        'options' => ['tag' => 'ul', 'class' => 'p-4 kt-pagination--brand kt-pagination__links',],
                        'activePageCssClass' => 'kt-pagination__link--active',
                        'prevPageCssClass' => 'kt-pagination__link--prev',
                        'nextPageCssClass' => 'kt-pagination__link--next',
                        'firstPageCssClass' => 'kt-pagination__link--first',
                        'lastPageCssClass' => 'kt-pagination__link--last',
                    ],
                    'columns' => [
                        [
                            'class' => 'yii\grid\SerialColumn',
                            'headerOptions' => ['class' => 'text-center', 'width' => '4%'],
                            'contentOptions' => ['class' => 'text-center'],
                        ],
                        [
                            'attribute' => 'name',
                            'headerOptions' => ['class' => 'head-sort'],
                        ], [
                            'attribute' => 'dept',
                            'value' => function ($model) {
                                $ParamList = new ParamList();
                                return $ParamList->getlabel(34, $model->dept);
                            },
                        ],
                        [
                            'attribute' => 'role',
                            'value' => function ($model) {
                                $ParamList = new ParamList();
                                return $ParamList->getlabel(2, $model->role);
                            },
                        ], [
                            'attribute' => 'email',
                            'headerOptions' => ['class' => 'head-sort'],
                        ],
                        [
                            'header' => 'Mobile Number',
                            'format' => 'raw',
                            'value' => function ($model) {
                                if (!empty($model->phone))
                                    return '+601' . $model->phone;
                                else
                                    return '';
                            },
                        ],
                        [
                            'class' => 'yii\grid\ActionColumn',
                            'header' => 'Action',
                            'headerOptions' => ['class' => 'text-center', 'width' => '10%'],
                            'contentOptions' => ['class' => 'text-center'],
                            'template' => '{update}&nbsp;&nbsp;{pwd}&nbsp;&nbsp;{delete}',
                            'buttons' => [
                                'update' => function ($url, $model) {
                                    $url = Url::to(['user/update', 'uuid' => $model->uuid]);
                                    return Html::a('<span class="kt-font-success icon-custom"><i class="far fa-edit fa-lg"></i></span>', $url, ['title' => 'Update',]);
                                }, 'pwd' => function ($url, $model) {
                                    return '<span class="kt-font-warning icon-custom" title="Reset Password" onclick="changepwd(' . $model->id . ')"><i class="fas fa-key fa-lg"></i></span>';
                                }, 'delete' => function ($url, $model) {
                                    return '<span class="kt-font-danger" title="Delete"><i class="far fa-trash-alt fa-lg" style="cursor:pointer;" onclick="deletedata(' . $model->id . ')"></i></span>';
                                },],
                        ],
                    ],
                ]);
                ?>
            </div>
        </div>
    </div>
</div>

<script>
    function changepwd(id) {
        Swal.fire({
            title: 'Are you sure to reset this user password?',
            text: "Reset process will take a few minutes. Please wait until success message appear",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, reset it!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: "index.php?r=user/adminresetpwd",
                    method: "POST",
                    data: {"id": id},
                    success: function (response) {
                        if (response === 'success') {
                            swal.fire({
                                position: 'center-center',
                                type: 'success',
                                title: 'Password successfully reset<br> New password has been send to user email',
                                showConfirmButton: false,
                                timer: 2000,
                            }).then(function (result) {
                                location.reload();
                            });
                        }
                    },
                });
            }
        }
        );
    }

    function deletedata(id) {
        Swal.fire({
            title: 'Are you sure to delete this data?',
            text: "You won't be able to revert this!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: "index.php?r=user/delete",
                    method: "POST",
                    data: {"id": id},
                    success: function (response) {
                        if (response === 'success') {
                            swal.fire({
                                position: 'center-center',
                                type: 'success',
                                title: 'Data has been deleted',
                                showConfirmButton: false,
                                timer: 1500, }).then(function (result) {
                                location.reload();
                            });
                        }
                    },
                });
            }
        });
    }
</script>