Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ public function destroy(Request $request)
if ($user->submissions()->count() > 0){
$json_result = array('done' => 0, 'message' => "You must delete users' submission before you can delete user.");
}
elseif (Auth::user()->id == $user_id) {
$json_result = array('done' => 0, 'message' => 'You cannot delete yourself!');
}
elseif (User::destroy($user_id))
$json_result = array('done' => 1);
else
Expand All @@ -291,7 +294,7 @@ public function delete_submissions(User $user){
$i = 0;
$json_result = array('done'=>0 , 'count' => 0);
foreach ($subs as $sub) {
var_dump($sub->directory());
// var_dump($sub->directory());
shell_exec("rm -rf " . $sub->directory());
$sub->delete();
$i++;
Expand Down Expand Up @@ -361,8 +364,8 @@ public function add_user($username, $email, $password, $role, $display_name="",
'display_name' => $display_name
];
$validator = Validator::make($user, [
'username' => ['required', 'string', 'max:50', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'username' => ['required', 'string', 'max:50', 'unique:users', 'regex:/^\S*$/'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users', 'regex:/^\S*$/'],
'display_name' => ['nullable', 'string', 'max:255'],
'password' => ['required', 'string', 'min:8'],
]);
Expand Down Expand Up @@ -497,8 +500,6 @@ public function set_trial(Request $request){
$count = $where_clause->update(['trial_time' => DB::Raw(" TIMESTAMPDIFF(HOUR, `created_at`, '$end_time' )") ,'role_id' => 4 ] );
}
// dd($count);
return back()->with(['success' => $count ])->withInput()
;
return back()->with(['success' => $count ])->withInput();
}

}
}
99 changes: 96 additions & 3 deletions resources/views/users/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,21 @@
<a class="ms-4 fs-6 link-dark" href="{{ url('users/add_multiple') }}"><i class="fa fa-user-plus text-success"></i> Add Users</a>
<a class="ms-4 fs-6 link-dark" href="{{ 'mailto:' . App\User::pluck('email')->join(',') }}"><i class="fas fa-mail-bulk "></i> Email all users</a>
<a class="ms-4 fs-6 link-dark" href="{{route('users.set_trial') }}"><i class="fas fa-highlighter "></i>Update multiple users trial time</a>

{{-- <span class="ms-4 fs-6"><a href="{{ url('users/list_excel') }}"><i class="fa fa-download color9"></i> Excel</a></span> --}}
@endsection

@section('content')
<a name="" id="copy_user_list" class="btn btn-primary my-2" href="#" role="button"><i class="fas fa-copy "></i> copy user name list</a>
@if (Auth::user()->role->name == 'admin')
<button id="delete_selected" class="btn btn-danger my-2"><i class="fas fa-trash"></i> Delete selected users</button>
@endif
<div class="row">
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="thead-old table-dark">
<tr>
<th></th>
<th>#</th>
{{-- <th>User ID</th> --}}
<th>Username</th>
Expand All @@ -64,6 +69,9 @@
</thead>
@foreach ($users as $user)
<tr data-id="{{$user->id}}">
<td>
<i class="checkbox pointer far fa-circle fa-2x"></i>
</td>
<td> {{$loop->iteration}} </td>
{{-- <td> {{$user->id}} </td> --}}
<td id="un"> {{$user->username}} </td>
Expand Down Expand Up @@ -176,10 +184,95 @@
$("#user_delete").modal("show");
});

let selected_users = [];

$('.checkbox').click(function() {
let username = $(this).parents('tr').find('#un').text().trim();
let id = $(this).parents('tr').data('id');

if ($(this).hasClass('fa-check-circle')) {
$(this).removeClass('fa-check-circle').addClass('fa-circle');
this.classList.add('fa-circle');
selected_users = selected_users.filter(user => user.id !== id && user.username !== username);
} else {
$(this).removeClass('fa-circle').addClass('fa-check-circle');
selected_users.push({
id: id,
username: username,
});
}
console.log(selected_users)
});

$("#delete_selected").click(function(e) {
e.preventDefault();
console.log(selected_users)

if (selected_users.length === 0) return;

// Show popup
let row = $(this).parents('tr');
let user_ids = row.data('id');
let usernames = row.children('#un').html();

$(".modal-title").html("Are you sure you want to DELETE these users and their submissions?");
$(".modal-body").html('')
selected_users.forEach(user => {
$(".modal-body").append('User ID: <code>'+user.id+'</code><br>Username: <code>'+user.username+'</code><br><br>');
});
$("#user_delete").modal("show");

$(".confirm-user-delete").click(function() {
$("#user_delete").modal("hide");
selected_users.forEach(async user => {

// Delete submissions
await $.ajax({
url: 'users/delete_submissions/'+user.id,
type: 'POST',
data: {
user_id: user.id,
"_token": "{{ csrf_token() }}",
},
error: shj.loading_error,
success: function (response){
if (response.done) {
$.notify('All ' + parseInt(response.count) +' submission(s) ' + 'of User '+user.username +' has been deleted.', {position: 'bottom right', className: 'success', autoHideDelay: 5000});
}
else {
shj.loading_failed(response.message);
}
}
});

// Delete user
await $.ajax({
url: '{{ route('users.index') }}/'+user.id,
type: 'DELETE',
data: {
user_id: user.id,
"_token": "{{ csrf_token() }}",
},
error: shj.loading_error,
success: function (response){
if (response.done) {
row.animate({backgroundColor: '#FF7676'},100, function(){row.remove();});
$.notify('User '+user.username+' deleted.', {position: 'bottom right', className: 'success', autoHideDelay: 5000});
}
else {
shj.loading_failed(response.message);
}
}
});

});
});
});

$("table").DataTable({
"pageLength": 50,
"lengthMenu": [ [20, 50, 100, 200, -1], [20, 50, 100, 200, "All"] ]
});
"pageLength": 50,
"lengthMenu": [ [20, 50, 100, 200, -1], [20, 50, 100, 200, "All"] ]
});
});

</script>
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Route::view('users/set_trial', 'users.set_trial')->name('users.set_trial')->middleware('auth');
Route::post('users/set_trial', [App\Http\Controllers\UserController::class, 'set_trial'])->name('users.set_trial_post');


Route::get('/problems/downloadtestsdesc/{id}', [App\Http\Controllers\problem_controller::class, 'downloadtestsdesc'])->name('problems.downloadtestsdesc');
Route::get('/problems/downloadpdf/{id}', [App\Http\Controllers\problem_controller::class, 'pdf'])->name('problems.pdf');
Route::get('/problems/downloadtemplate/{problem_id}/{assignment_id}', [App\Http\Controllers\problem_controller::class, 'template'])->name('problems.template');
Expand Down