<?php $__env->startSection('meta-content'); ?>
<title><?php echo Lang::get('words.admin_alt').' - '.Lang::get('words.users'); ?></title>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<?php
    $pl_counts = DB::table('playlists')->whereIn('user_id', $users->lists('id'))->select(DB::raw('user_id, count(id) as count'))->groupBy('user_id')->get();
    $pl_array = array();
    foreach($pl_counts as $pl_count) {
        $pl_array[$pl_count->user_id] = $pl_count->count;
    }
?>
<div class="row">
	<div class="col-xs-12">
		<ol class="breadcrumb">
			<li><a href="<?php echo URL::to('admin'); ?>"><i class="fa fa-dashboard"></i> <?php echo Lang::get('words.admin'); ?></a></li>
            <li class="active"><?php echo Lang::get('words.users'); ?> (<b><?php echo DB::table("users")->count(); ?></b>)</li>
		</ol>
	</div>
</div>
<div class="row">
    <form method="get">
        <div class="col-xs-12">
            <div class="form-group input-group">
                <input type="text" class="form-control" name="q" value="<?php if(Input::get('q')): ?><?php echo Input::get('q'); ?><?php endif; ?>" placeholder="<?php echo Lang::get('words.search'); ?>" aria-describedby="basic-addon2">
                <div class="input-group-btn">
                    <button type="submit" class="btn btn-primary"><span class="fa fa-search"></span> <?php echo Lang::get('words.search'); ?></button>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </form>
</div>
<div class="row">
	<div class="col-xs-12">
        <div class="table-responsive">
            <table class="table">
                <tr>
                   <th><?php echo Lang::get('words.username'); ?></th>
                   <th><?php echo Lang::get('words.email'); ?></th>
                   <th><?php echo Lang::get('words.playlists'); ?></th>
                   <th><?php echo Lang::get('words.created'); ?></th>
                   <th><?php echo Lang::get('words.active'); ?></th>
                   <th><?php echo Lang::get('words.actions'); ?></th>
                </tr>
                <?php foreach($users as $user): ?>
                    <?php 
                        $playlists_count = isset($pl_array[$user->id]) ? $pl_array[$user->id] : 0;
                    ?>
                    <tr>
                        <td><?php echo $user->username; ?></td>
                        <td><?php echo $user->email; ?></td>
                        <td><?php echo $playlists_count; ?></td>
                        <td><?php echo $user->created_at->toFormattedDateString(); ?></td>
                        <td>
                            <?php if($user->active): ?>
                                <label class="label label-success"><?php echo Lang::get('words.yes'); ?></label>
                            <?php else: ?>
                                <label class="label label-warning"><?php echo Lang::get('words.no'); ?></label>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php if($user->admin): ?> 
                                <a data-target="#user-mode-modal" data-toggle="modal" data-user="<?php echo $user->id; ?>" title="<?php echo Lang::get('words.make'); ?> <?php echo Lang::get('words.user'); ?>" class="btn btn-xs btn-success"><span class="fa fa-user-secret"></span> <?php echo Lang::get('words.admin'); ?></a>
                            <?php else: ?>
                                <a data-target="#user-mode-modal" data-toggle="modal" data-user="<?php echo $user->id; ?>" title="<?php echo Lang::get('words.make'); ?> <?php echo Lang::get('words.admin'); ?>" class="btn btn-xs btn-warning"><span class="fa fa-user"></span> <?php echo Lang::get('words.user'); ?></a>
                            <?php endif; ?>
                            
                            <a data-target="#edit-user-modal" data-toggle="modal" data-user="<?php echo $user->id; ?>" data-username="<?php echo $user->username; ?>" data-email="<?php echo $user->email; ?>" title="<?php echo Lang::get('words.edit-user'); ?>" class="btn btn-xs btn-danger"><span class="fa fa-edit"></span> <?php echo Lang::get('words.edit'); ?></a>
                            
                            <?php if($user->banned): ?> 
                                <a data-target="#user-status-modal" data-toggle="modal" data-user="<?php echo $user->id; ?>" title="Unban User" class="btn btn-xs btn-danger"><span class="fa fa-ban"></span> <?php echo Lang::get('words.unban'); ?></a>
                            <?php else: ?>
                                <a data-target="#user-status-modal" data-toggle="modal" data-user="<?php echo $user->id; ?>" title="Ban User" class="btn btn-xs btn-success"><span class="fa fa-check"></span> <?php echo Lang::get('words.ban'); ?></a>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-xs-12 text-center">
        <?php echo $users->links(); ?>

    </div>
</div>

<div class="modal fade" id="edit-user-modal" tabindex="-1" role="dialog" aria-labelledby="deleteProductModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><?php echo Lang::get('words.edit-user'); ?></h4>
            </div>
            <form id="edit-user-form" role="form" method="post" action="<?php echo URL::to('user/admin/user/edit'); ?>">
                <div class="modal-body">
                    <input type="hidden" name="user" value="">
                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                    <div class="form-group">
                        <label><?php echo Lang::get('words.username'); ?>:</label>
                        <input type="text" class="form-control" name="username" placeholder="<?php echo Lang::get('words.username'); ?>">
                    </div>
                    <div class="form-group">
                        <label><?php echo Lang::get('words.email'); ?>:</label>
                        <input type="text" class="form-control" name="email" placeholder="<?php echo Lang::get('words.email'); ?>">
                    </div>
                    <div class="form-group">
                        <label><?php echo Lang::get('words.new-password'); ?>:</label>
                        <input type="password" name="password" autocomplete="off" class="form-control" placeholder="<?php echo Lang::get('words.new-password'); ?>">
                    </div>
                    <div class="form-group">
                        <label><?php echo Lang::get('words.confirm-password'); ?>:</label>
                        <input type="password" name="password_confirmation" autocomplete="off" class="form-control" placeholder="<?php echo Lang::get('words.confirm-password'); ?>">
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="submit" class="btn btn-danger btn-block" value="<?php echo Lang::get('words.save-user'); ?>">
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="user-mode-modal" tabindex="-1" role="dialog" aria-labelledby="deleteProductModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><?php echo Lang::get('words.change-user-mode'); ?></h4>
            </div>
            <form id="user-mode-form" role="form" method="post" action="<?php echo URL::to('user/admin/user/mode'); ?>">
                <div class="modal-body">
                    <input type="hidden" name="user" value="">
                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                    <h5><?php echo Lang::get('words.change-user-mode-msg'); ?></h5>
                </div>
                <div class="modal-footer">
                    <input type="submit" class="btn btn-danger btn-block" value="<?php echo Lang::get('words.change-mode'); ?>">
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="user-status-modal" tabindex="-1" role="dialog" aria-labelledby="deleteProductModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><?php echo Lang::get('words.change-user-status'); ?></h4>
            </div>
            <form id="user-status-form" role="form" method="post" action="<?php echo URL::to('user/admin/user/status'); ?>">
                <div class="modal-body">
                    <input type="hidden" name="user" value="">
                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                    <h5><?php echo Lang::get('words.change-user-status-msg'); ?></h5>
                </div>
                <div class="modal-footer">
                    <input type="submit" class="btn btn-danger btn-block" value="<?php echo Lang::get('words.change-status'); ?>">
                </div>
            </form>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.index', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>