public static function addUser($data, $requestUserId) { try { $db = Database::getInstance(); $conn = $db->getConnection(); if (Config::isUserAvailable($data->userInfo->email)) { $conn->beginTransaction(); $password = ""; $userId = AppUtil::generateId(); $date = new DateTime($data->userInfo->dob); $dob = $date->format('Y-m-d'); $stmt = $conn->prepare("INSERT INTO `usermaster`(`userId`, `firstName`, `lastName`, `dateOfBirth`, `address`, `city`, `state`, `country`, `pincode`, `mobileNumber`, `emailId`, `createdBy`, `creationDate`, `lastModifiedBy`, `lastModificationDate`)\n VALUES (:userId,:firstName,:lastName,:dob,:address,:city,:state,:country,:pincode,:mobileNumber,:emailId,:createdBy,now(),:lastModifiedBy,now())"); $stmt->bindParam(':userId', $userId, PDO::PARAM_STR); $stmt->bindParam(':firstName', $data->userInfo->firstName, PDO::PARAM_STR); $stmt->bindParam(':lastName', $data->userInfo->lastName, PDO::PARAM_STR); $stmt->bindParam(':dob', $dob, PDO::PARAM_STR); $stmt->bindParam(':address', $data->userInfo->address, PDO::PARAM_STR); $stmt->bindParam(':city', $data->userInfo->city, PDO::PARAM_STR); $stmt->bindParam(':state', $data->userInfo->state, PDO::PARAM_STR); $stmt->bindParam(':country', $data->userInfo->country, PDO::PARAM_STR); $stmt->bindParam(':pincode', $data->userInfo->pincode, PDO::PARAM_STR); $stmt->bindParam(':mobileNumber', $data->userInfo->mobile, PDO::PARAM_STR); $stmt->bindParam(':emailId', $data->userInfo->email, PDO::PARAM_STR); $stmt->bindParam(':createdBy', $requestUserId, PDO::PARAM_STR); $stmt->bindParam(':lastModifiedBy', $requestUserId, PDO::PARAM_STR); $rollback = false; HicreteLogger::logDebug("Query:\n " . json_encode($stmt)); HicreteLogger::logDebug("Data:\n " . json_encode($data)); if ($stmt->execute()) { if (!Config::insertRoleInfo($conn, $userId, $data->userInfo->designation, $data->roleId, $data->userInfo->userType, $requestUserId)) { $rollback = true; } else { // foreach ($data->accessPermissions as $accessEntry) { // if ($accessEntry->read->ispresent) { // if (!Config::insertUserAccessPermission($conn, $userId, $requestUserId, $accessEntry->read->accessId)) { // $rollback = true; // // break; // } // // } // // if ($accessEntry->write->ispresent) { // if (!Config::insertUserAccessPermission($conn, $userId, $requestUserId, $accessEntry->write->accessId)) { // $rollback = true; // // break; // } // } // } //if (!$rollback) { $str = $data->userInfo->email . $userId; $stmt = $conn->prepare("INSERT INTO `logindetails`(`userId`, `userName`, `password`) \n VALUES (:userId,:userName,:password)"); $stmt->bindParam(':userId', $userId, PDO::PARAM_STR); $stmt->bindParam(':userName', $data->userInfo->email, PDO::PARAM_STR); $password = mt_rand(1000000, 9999999); $hash = sha1($password); $stmt->bindParam(':password', $hash, PDO::PARAM_STR); HicreteLogger::logDebug("Query:\n " . json_encode($stmt)); if (!$stmt->execute()) { $rollback = true; } //} } } else { HicreteLogger::logError("Unknown Database error occured "); echo AppUtil::getReturnStatus("Unsuccessful", "Unknown database error occurred"); } if ($rollback) { $conn->rollback(); HicreteLogger::logError("Unknown Database error occured "); echo AppUtil::getReturnStatus("Unsuccessful", "Unknown database error occurred"); } else { $conn->commit(); HicreteLogger::logInfo("User added successfully"); echo AppUtil::getReturnStatus("Successful", $password); AppUtil::sendMail($data->userInfo->email, $password, $data->userInfo->email, $data->userInfo->firstName); } } else { HicreteLogger::logError("user already available"); echo AppUtil::getReturnStatus("Unsuccessful", "User Already Available"); } } catch (Exception $e) { HicreteLogger::logFatal("Exception Occured Message:\n" . $e->getMessage()); echo AppUtil::getReturnStatus("Exception", "Exception Occurred while creating role"); } }