diff --git a/app/modules_app/companies/index.php b/app/modules_app/companies/index.php index a6009cd..2076448 100644 --- a/app/modules_app/companies/index.php +++ b/app/modules_app/companies/index.php @@ -52,6 +52,12 @@ foreach ($companies as &$company) { unset($company['jofotara_client_id_encrypted']); unset($company['jofotara_secret_key_encrypted']); unset($company['certificate_password_encrypted']); + + // Decrypt Tenant Name (if exists) + if (isset($company['tenant_name'])) { + $decTenantName = Encryption::decrypt($company['tenant_name']); + $company['tenant_name'] = $decTenantName !== false ? $decTenantName : $company['tenant_name']; + } } json_success($companies); diff --git a/app/modules_app/tenants/create.php b/app/modules_app/tenants/create.php index de708e2..2824415 100644 --- a/app/modules_app/tenants/create.php +++ b/app/modules_app/tenants/create.php @@ -40,11 +40,14 @@ try { ); // 1. Create Tenant + $encryptedTenantName = \App\Core\Encryption::encrypt($data['name']); + $encryptedTenantEmail = \App\Core\Encryption::encrypt($data['email']); + $stmt = $db->prepare("INSERT INTO tenants (id, name, email, phone, status, created_at) VALUES (?, ?, ?, ?, 'active', NOW())"); $stmt->execute([ $tenantId, - $data['name'], - $data['email'], + $encryptedTenantName, + $encryptedTenantEmail, $data['phone'] ?? null ]); diff --git a/app/modules_app/tenants/index.php b/app/modules_app/tenants/index.php index 084f235..4c5a1ad 100644 --- a/app/modules_app/tenants/index.php +++ b/app/modules_app/tenants/index.php @@ -17,4 +17,12 @@ $db = Database::getInstance(); $stmt = $db->query("SELECT id, name, email, phone, status, created_at FROM tenants ORDER BY created_at DESC"); $tenants = $stmt->fetchAll(); +foreach ($tenants as &$t) { + $decName = \App\Core\Encryption::decrypt($t['name']); + $t['name'] = $decName !== false ? $decName : $t['name']; + + $decEmail = \App\Core\Encryption::decrypt($t['email']); + $t['email'] = $decEmail !== false ? $decEmail : $t['email']; +} + json_success($tenants); diff --git a/app/modules_app/users/index.php b/app/modules_app/users/index.php index 5d0db27..ebfd0ae 100644 --- a/app/modules_app/users/index.php +++ b/app/modules_app/users/index.php @@ -54,6 +54,12 @@ foreach ($users as &$user) { $decryptedCompanyName = Encryption::decrypt($user['company_name']); $user['company_name'] = $decryptedCompanyName !== false ? $decryptedCompanyName : $user['company_name']; } + + // Decrypt Tenant Name (if exists) + if ($user['tenant_name']) { + $decryptedTenantName = Encryption::decrypt($user['tenant_name']); + $user['tenant_name'] = $decryptedTenantName !== false ? $decryptedTenantName : $user['tenant_name']; + } } json_success($users); diff --git a/scripts/debug_data.php b/scripts/debug_data.php new file mode 100644 index 0000000..c3a234f --- /dev/null +++ b/scripts/debug_data.php @@ -0,0 +1,17 @@ +query("SELECT * FROM tenants"); +print_r($stmt->fetchAll(PDO::FETCH_ASSOC)); + +echo "\n--- USERS ---\n"; +$stmt = $db->query("SELECT u.id, u.name, u.role, u.tenant_id, t.name as tenant_name FROM users u LEFT JOIN tenants t ON u.tenant_id = t.id"); +print_r($stmt->fetchAll(PDO::FETCH_ASSOC)); + +echo "\n--- COMPANIES ---\n"; +$stmt = $db->query("SELECT * FROM companies"); +print_r($stmt->fetchAll(PDO::FETCH_ASSOC));