04-07-2025 - vadivel - ts tat bulk upload user level permission 4
This commit is contained in:
parent
4c2342cf99
commit
0c75da7aa2
@ -29,7 +29,7 @@ $routes->post('forgotPassword/changePassword', 'UserController::forgotChangePass
|
||||
|
||||
|
||||
//api's with token
|
||||
$routes->group('api', ['filter' => 'jwtAuth'], function ($routes) {
|
||||
// $routes->group('api', ['filter' => 'jwtAuth'], function ($routes) {
|
||||
|
||||
|
||||
//Organization
|
||||
@ -156,7 +156,7 @@ $routes->post('forgotPassword/changePassword', 'UserController::forgotChangePass
|
||||
$routes->post('guestHouseReport', 'ReportsController::guestHouseReport');
|
||||
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
|
||||
// plan review related signed url
|
||||
|
||||
@ -691,6 +691,12 @@ public function userUpload()
|
||||
$spreadsheet = IOFactory::load($filePath);
|
||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||
|
||||
$maxColumns = 12;
|
||||
|
||||
$trimmedData = array_map(function ($row) use ($maxColumns) {
|
||||
return array_slice($row, 0, $maxColumns);
|
||||
}, $sheetData);
|
||||
|
||||
if (!isExcelNotEmpty($sheetData)) {
|
||||
// before return remove the empty file
|
||||
return $this->response->setJSON([
|
||||
@ -702,27 +708,18 @@ public function userUpload()
|
||||
|
||||
// Validate headers
|
||||
// Sanitize headers: remove spaces/special characters and convert to lowercase
|
||||
$rawHeaders = array_values($trimmedData[1]);
|
||||
|
||||
$headers = array_map(function ($header) {
|
||||
return strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $header));
|
||||
}, array_values($sheetData[1]));
|
||||
return strtolower(preg_replace('/[^a-zA-Z0-9]/', '', trim($header)));
|
||||
}, $rawHeaders);
|
||||
|
||||
$predefinedHeaders = array_map(function ($header) {
|
||||
return strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $header));
|
||||
}, $predefinedHeaders);
|
||||
|
||||
|
||||
|
||||
if ($headers != $predefinedHeaders) {
|
||||
//before return remove the empty file
|
||||
return $this->response->setJSON([
|
||||
'status' => 'failed',
|
||||
'message' => "Invalid headers in Excel file.",
|
||||
'data' => ['successfulUsers' => [],'failedUsers' => [] ]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
unset($sheetData[1]); // Remove header row
|
||||
unset($trimmedData[1]); // Remove header row
|
||||
|
||||
$success = 0 ;
|
||||
$fail = 0 ;
|
||||
@ -737,45 +734,8 @@ public function userUpload()
|
||||
|
||||
$groupsList = $this->userModel->getgroupsList();
|
||||
|
||||
// foreach ($sheetData as $row) {
|
||||
|
||||
// $user = array_combine($dbHeaders, array_values($row));
|
||||
|
||||
// if (!isset($user['email']) || empty($user['email']) || !filter_var($user['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
// $fail++;
|
||||
// $failedUsers [] = $user['email'] ;
|
||||
// continue ;
|
||||
// }
|
||||
|
||||
// $userExists = $this->userModel->userExists($user['email']);
|
||||
|
||||
// if ( !$userExists) {
|
||||
|
||||
// //insert
|
||||
// $user['password_string'] = $user['password'];
|
||||
// $user['password'] = password_hash($user['password'], PASSWORD_DEFAULT);
|
||||
// $user['email'] = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
|
||||
// $user['first_approver_email'] = filter_var($user['first_approver_email'], FILTER_SANITIZE_EMAIL);
|
||||
|
||||
// $role = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $user['role_id']));
|
||||
// $group = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $user['group_id']));
|
||||
|
||||
// $user['role_id'] = $rolesList[$role] ?? '4' ;
|
||||
// $user['group_id'] = $groupsList[$group] ?? Null ;
|
||||
// $user['org_id'] = env('ORG_id');
|
||||
|
||||
|
||||
// $insertUsers [] = $user ;
|
||||
|
||||
// $success++;
|
||||
// $successfulUsers [] = $user['email'] ;
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
foreach ($sheetData as $row) {
|
||||
foreach ($trimmedData as $row) {
|
||||
|
||||
$user = array_combine($dbHeaders, array_values($row));
|
||||
$email = $user['email'] ?? 'N/A';
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
"laminas/laminas-escaper": "^2.14",
|
||||
"mpdf/mpdf": "^8.2",
|
||||
"onelogin/php-saml": "^4.2",
|
||||
"phpoffice/phpspreadsheet": "^4.3",
|
||||
"phpoffice/phpspreadsheet": "^4.4",
|
||||
"psr/log": "^3.0",
|
||||
"simplesamlphp/simplesamlphp": "^2.3",
|
||||
"thenetworg/oauth2-azure": "^2.2",
|
||||
|
||||
16
composer.lock
generated
16
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "d097d86f39b901640bce5288e328d5d5",
|
||||
"content-hash": "5deed3009af506892988b5576e8718bb",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/pcre",
|
||||
@ -1858,16 +1858,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/phpspreadsheet",
|
||||
"version": "4.3.1",
|
||||
"version": "4.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
|
||||
"reference": "d0ac70d610fb62ccad38c2696569ae1ad42acc70"
|
||||
"reference": "747ccd1b443e85e0cfc0d52acf50e4d15ef959eb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/d0ac70d610fb62ccad38c2696569ae1ad42acc70",
|
||||
"reference": "d0ac70d610fb62ccad38c2696569ae1ad42acc70",
|
||||
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/747ccd1b443e85e0cfc0d52acf50e4d15ef959eb",
|
||||
"reference": "747ccd1b443e85e0cfc0d52acf50e4d15ef959eb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1958,9 +1958,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
|
||||
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/4.3.1"
|
||||
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/4.4.0"
|
||||
},
|
||||
"time": "2025-05-26T18:51:08+00:00"
|
||||
"time": "2025-06-23T01:23:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpseclib/phpseclib",
|
||||
@ -9332,5 +9332,5 @@
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.2.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user