143 lines
4.8 KiB
PHP
143 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use App\Utilities\ApiCalls;
|
|
use Session;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class AdminController extends Controller
|
|
{
|
|
public function index(){
|
|
$users_url = "user_mgt/get_all_users.php";
|
|
$data = ['api_token' => env('LUPMISAPIKEY')];
|
|
$result = ApiCalls::CurlPost(json_encode($data), $users_url);
|
|
$users_arr = json_decode($result, true);
|
|
if ($users_arr['success'] == false) {
|
|
return redirect->back();
|
|
}
|
|
|
|
$regions_url = "user_mgt/get_all_regions.php";
|
|
$data = ['api_token' => env('LUPMISAPIKEY')];
|
|
$result = ApiCalls::CurlPost(json_encode($data), $regions_url);
|
|
$regions_arr = json_decode($result, true);
|
|
if ($regions_arr['success'] == false) {
|
|
return redirect->back();
|
|
}
|
|
|
|
|
|
// 2. Define pagination parameters
|
|
$perPage = 10;
|
|
$currentPage = LengthAwarePaginator::resolveCurrentPage() ?: 1;
|
|
$offset = ($currentPage - 1) * $perPage;
|
|
|
|
// 3. Slice the array to get the items for the current page
|
|
$currentPageItems = array_slice($users_arr['data'], $offset, $perPage);
|
|
|
|
// 4. Create the LengthAwarePaginator instance
|
|
$paginatedItems = new LengthAwarePaginator(
|
|
$currentPageItems, // Items for the current page
|
|
count($users_arr['data']), // Total number of items
|
|
$perPage, // Items per page
|
|
$currentPage, // Current page number
|
|
['path' => request()->url(), 'query' => request()->query()] // Options to preserve query strings and path
|
|
);
|
|
$user_type_arr = [
|
|
'district_user' => 'District User',
|
|
'regional_user' => 'Regional User',
|
|
'national_user' => 'National User'
|
|
];
|
|
$data = [
|
|
'page_title' => 'User Admin',
|
|
'users_arr' => $users_arr['data'],
|
|
'regions_arr' => $regions_arr['data'],
|
|
'user_type_arr' => $user_type_arr,
|
|
'items' => $paginatedItems
|
|
];
|
|
// dump($data);
|
|
// 5. Pass the paginator instance to your view
|
|
return view('admin.paginated', $data);
|
|
// return view('admin.home', $data);
|
|
|
|
}
|
|
public function indexOld(){
|
|
$users_url = "user_mgt/get_all_users.php";
|
|
$data = ['api_token' => env('LUPMISAPIKEY')];
|
|
$result = ApiCalls::CurlPost(json_encode($data), $users_url);
|
|
$users_arr = json_decode($result, true);
|
|
if ($users_arr['success'] == false) {
|
|
return redirect->back();
|
|
}
|
|
|
|
$regions_url = "user_mgt/get_all_regions.php";
|
|
$data = ['api_token' => env('LUPMISAPIKEY')];
|
|
$result = ApiCalls::CurlPost(json_encode($data), $regions_url);
|
|
$regions_arr = json_decode($result, true);
|
|
if ($regions_arr['success'] == false) {
|
|
return redirect->back();
|
|
}
|
|
|
|
$user_type_arr = [
|
|
'district_user' => 'District User',
|
|
'regional_user' => 'Regional User',
|
|
'national_user' => 'National User'
|
|
];
|
|
|
|
$data = [
|
|
'page_title' => 'User Admin',
|
|
'users_arr' => $users_arr['data'],
|
|
'regions_arr' => $regions_arr['data'],
|
|
'user_type_arr' => $user_type_arr
|
|
];
|
|
return view('admin.home', $data);
|
|
}
|
|
public function districtparams(){
|
|
|
|
$url = "user_mgt/get_district_parameters.php";
|
|
$data = json_encode([
|
|
'district_id' => 171,
|
|
'api_token' => env('LUPMISAPIKEY')
|
|
]);
|
|
$result = ApiCalls::CurlPost($data, $url);
|
|
$result = json_decode($result, true);
|
|
// dd($result);
|
|
$data = [
|
|
'page_title' => "Page Under Development"
|
|
];
|
|
return view('common.notready', $data);
|
|
}
|
|
public function luspaparams(){
|
|
$data = [
|
|
'page_title' => "Page Under Development"
|
|
];
|
|
return view('common.notready', $data);
|
|
}
|
|
public function districts($reqion_id){
|
|
// return response()->json(['request' => $reqion_id]);
|
|
$url = "user_mgt/get_district_by_region_id.php";
|
|
$data = json_encode([
|
|
'region_id' => $reqion_id,
|
|
'api_token' => env('LUPMISAPIKEY')
|
|
]);
|
|
$result = ApiCalls::CurlPost($data, $url);
|
|
$results = json_decode($result, true);
|
|
|
|
$result = ['code' => 1, 'districts' => $results['data']];
|
|
if (request()->expectsJson()) {
|
|
return response()->json($result);
|
|
}
|
|
$data = [
|
|
'page_title' => 'Not Ready'
|
|
];
|
|
return view('common.notready', $data);
|
|
}
|
|
|
|
public function reports(){
|
|
$data = [
|
|
'page_title' => "Page Under Development"
|
|
];
|
|
return view('common.notready', $data);
|
|
}
|
|
}
|