From 95285dd602438260720aeff0b9c2a127392fbc87 Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Wed, 18 Mar 2026 12:11:21 +0530 Subject: [PATCH] FIX_user_team --- app/Controllers/UserController.php | 101 +++++++++++++++-------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 09b458dc..0e29438a 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -202,52 +202,53 @@ class UserController extends AdminController // ]; // $this->bookStack->createEditUser($bookStackData); - // if ($insert) { - // $teamData['user_id'] = $insert; - // foreach ($teams as $value) { - // $teamData['team_id'] = $value; - // $teamData['created_by'] = get_session_userid(); - // $this->userTeamsModel->insert($teamData); - // } + if ($insert) { - // $db = \Config\Database::connect(); - // $tableName = 'hdz_staff'; + $teamData['user_id'] = $insert; + foreach ($teams as $value) { + $teamData['team_id'] = $value; + $teamData['created_by'] = get_session_userid(); + $this->userTeamsModel->insert($teamData); + } + + // $db = \Config\Database::connect(); + // $tableName = 'hdz_staff'; - // // Set default values - // $admin = 0; - // $acm = 0; - // $acm_id = null; + // // Set default values + // $admin = 0; + // $acm = 0; + // $acm_id = null; - // if ($userData['role'] == 3) { - // $admin = 0; - // $acm = 1; - // $acm_id = $insert; - // } else if (in_array($userData['role'], [1, 5])) { - // $admin = 1; - // $acm = 0; - // $acm_id = null; - // } + // if ($userData['role'] == 3) { + // $admin = 0; + // $acm = 1; + // $acm_id = $insert; + // } else if (in_array($userData['role'], [1, 5])) { + // $admin = 1; + // $acm = 0; + // $acm_id = null; + // } - // $password = '12345678'; // Default password - // $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + // $password = '12345678'; // Default password + // $hashedPassword = password_hash($password, PASSWORD_DEFAULT); - // $hdz_staff = [ - // 'emp_code' => $userData['emp_code'], - // 'fullname' => $userData['first_name'], - // 'username' => strtolower($userData['first_name']), - // 'email' => $userData['email'], - // 'admin' => $admin, - // 'acm' => $acm, - // 'acm_id' => $acm_id, - // 'registration' => time(), - // 'password' => $hashedPassword, - // 'active' => 1, - // 'department' => 'a:7:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"5";i:3;s:1:"3";i:4;s:1:"9";i:5;s:1:"4";i:6;s:2:"10";}', - // ]; + // $hdz_staff = [ + // 'emp_code' => $userData['emp_code'], + // 'fullname' => $userData['first_name'], + // 'username' => strtolower($userData['first_name']), + // 'email' => $userData['email'], + // 'admin' => $admin, + // 'acm' => $acm, + // 'acm_id' => $acm_id, + // 'registration' => time(), + // 'password' => $hashedPassword, + // 'active' => 1, + // 'department' => 'a:7:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"5";i:3;s:1:"3";i:4;s:1:"9";i:5;s:1:"4";i:6;s:2:"10";}', + // ]; - // $db->table($tableName)->insert($hdz_staff); + // $db->table($tableName)->insert($hdz_staff); - // } + } } $this->myLogger->logme('error', 'User create Successfully created by id {data}', ['data' => get_session_userid()]); return redirect()->to(base_url('/user/list')); @@ -400,17 +401,17 @@ class UserController extends AdminController // $this->bookStack->createEditUser($bookStackData,$existingData); - // if ($update) { + if ($update) { - // if ($teams) { - // $this->userTeamsModel->where('user_id', $id)->delete(); - // $teamData['user_id'] = $id; - // foreach ($teams as $value) { - // $teamData['team_id'] = $value; - // $teamData['created_by'] = get_session_userid(); - // $this->userTeamsModel->insert($teamData); - // } - // } + if ($teams) { + $this->userTeamsModel->where('user_id', $id)->delete(); + $teamData['user_id'] = $id; + foreach ($teams as $value) { + $teamData['team_id'] = $value; + $teamData['created_by'] = get_session_userid(); + $this->userTeamsModel->insert($teamData); + } + } // $db = \Config\Database::connect(); // $tableName = 'hdz_staff'; @@ -461,7 +462,7 @@ class UserController extends AdminController // $db->table($tableName)->insert($hdz_staff); // } - // } + } return redirect()->to(base_url('/user/list')); }