/
home
/
sjslayjy
/
public_html
/
ccbfsoution
/
resources
/
views
/
admin
/
Upload File
HOME
@extends('layouts.app') @section('content') <div class="containerr"> <div class="d-flex justify-content-between mb-3"> <button class="btn-add" data-bs-toggle="modal" data-bs-target="#addUserModal">Add User</button> <div class="w-25"> <form action="{{ route('users.index') }}" method="GET"> <input type="text" name="search" id="search" placeholder="Search by name or email" class="form-control" value="{{ request('search') }}"> </form> </div> </div> @if(session('success')) <div class="alert alert-success"> {{ session('success') }} </div> @endif @if($errors->any()) <div class="alert alert-danger"> <ul class="mb-0"> @foreach($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <table class="table table-bordered"> <thead class="table-success"> <tr> <th>Sr. No.</th> <th>User ID</th> <th>User Name</th> <th>User Type</th> <th>Block Name</th> <th>Plot Name</th> <th>Area (Acre)</th> <th>Location</th> <th>Login Date/Time</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> @foreach ($users as $index => $user) <tr> <td>{{ ($users->currentPage() - 1) * $users->perPage() + $index + 1 }}</td> <td>{{ $user->email }}</td> <td>{{ $user->name }}</td> <td>{{ $user->user_type }}</td> <td>{{ $user->block_name }}</td> <td>{{ $user->plot_name }}</td> <td>{{ $user->area }}</td> <td> @if($user->site_name) @php $siteIds = explode(',', $user->site_name); $siteNames = []; foreach($siteIds as $siteId) { $site = DB::table('master_sites')->where('id', $siteId)->first(); if($site) { $siteNames[] = $site->site_name; } } @endphp {{ implode(', ', $siteNames) }} @else - @endif </td> <td> {{ $user->last_login ? \Carbon\Carbon::parse($user->last_login)->format('d-m-y') : '-' }} </td> <td>{{ $user->status ?? 'Active' }}</td> <td> <form action="{{ route('users.destroy', $user->id) }}" method="POST" onsubmit="return confirm('Are you sure you want to delete this user?');"> @csrf @method('DELETE') <button type="submit" class="btn btn-sm delete-btn"> <i class="fas fa-trash-alt" style="color: #dc3545;"></i> </button> </form> </td> </tr> @endforeach </tbody> </table> {{ $users->links('pagination::bootstrap-5') }} </div> <!-- Add User Modal --> <div class="modal fade" id="addUserModal" tabindex="-1"> <div class="modal-dialog"> <form action="{{ route('users.store') }}" method="POST"> @csrf <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Add User</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> <div class="row g-3"> @if(Auth::user()->role == 1) <!-- Sites selection for superadmin - FIRST --> <div class="col-md-6"> <label>Sites</label> <select name="site_ids[]" class="form-control" multiple required> @isset($sites) @foreach($sites as $site) <option value="{{ $site->id }}">{{ $site->site_name }}</option> @endforeach @endisset </select> <small class="text-muted">Hold Ctrl to select multiple sites</small> </div> <!-- Role selection for superadmin --> <div class="col-md-6"> <label>Role</label> <select name="role" class="form-control" required> <option value="">Select Role</option> <option value="1">Super Admin</option> <option value="2">Site Manager</option> <option value="3">Site Manager</option> <option value="4">User</option> <option value="5">Site Manager</option> </select> </div> @else <!-- Single site selection for other roles - FIRST --> <div class="col-md-6"> <label>Site Location</label> <select id="site_name" name="site_name" class="form-control" required> <option value="">Select Site</option> @isset($sites) @foreach($sites as $site) <option value="{{ $site->id }}">{{ $site->site_name }}</option> @endforeach @endisset </select> </div> <div class="col-md-6"></div> <!-- Empty column for spacing --> @endif <!-- User details - SECOND --> <div class="col-md-6"> <label>User Name</label> <input type="text" name="name" class="form-control" required> </div> <div class="col-md-6"> <label>User ID (Email)</label> <input type="email" name="email" class="form-control" required> </div> <div class="col-md-6"> <label>Password</label> <input type="password" name="password" class="form-control" required> </div> <div class="col-md-6"> <label>User Type</label> <select name="user_type" class="form-control"> <option value="">Select User Type</option> <option value="Field Office">Fodder Crop Officer</option> <option value="Supervisor">Supervisor</option> </select> </div> <!-- Location details - THIRD --> <div class="col-md-6"> <label>Block</label> <select id="add_block" name="block_name" class="form-control" required> <option value="">Select Block</option> @foreach ($blocks as $block) <option value="{{ $block->block_name }}">{{ $block->block_name }}</option> @endforeach </select> </div> <div class="col-md-6"> <label>Plot</label> <select id="add_plot" name="plot_name" class="form-control" required> <option value="">Select Plot</option> </select> </div> <div class="col-md-6"> <label>Area</label> <input type="text" id="add_area" name="area" class="form-control" readonly> </div> </div> </div> <div class="modal-footer"> <button type="submit" class="btn btn-success">Save</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> </div> </div> </form> </div> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function () { $('#search').on('keyup', function(e) { if(e.key === 'Enter') { $(this).closest('form').submit(); } }); $('#add_block').on('change', function () { let block = $(this).val(); $('#add_plot').html('<option value="">Loading...</option>'); $('#add_area').val(''); if (block) { $.ajax({ url: '/get-plots/' + block, type: 'GET', success: function(data) { let options = '<option value="">Select Plot</option>'; if (data && data.length > 0) { data.forEach(function(plot) { let plotValue = plot || 'N/A'; options += `<option value="${plotValue}">${plotValue}</option>`; }); } else { options += '<option value="N/A">No plots available</option>'; } $('#add_plot').html(options); }, error: function() { $('#add_plot').html('<option value="">Error loading plots</option>'); } }); } else { $('#add_plot').html('<option value="">Select Plot</option>'); } }); $('#add_plot').on('change', function () { let block = $('#add_block').val(); let plot = $(this).val(); if (block && plot) { $.ajax({ url: '/get-area', type: 'GET', data: { block_name: block, plot_name: plot }, success: function(data) { $('#add_area').val(data || '0.00'); }, error: function() { $('#add_area').val('0.00'); } }); } else { $('#add_area').val(''); } }); // Show/hide role and site fields based on user role @if(Auth::user()->role != 1) $('select[name="site_ids[]"]').hide(); $('select[name="role"]').hide(); @endif }); </script> @endsection