Fill the form to add a New Employee
home/abhiramc/public_html/acts.service/dashboard.employee.reg.php 0000644 00000274055 15021151573 0021204 0 ustar 00 getConnection(); // Check admin permission $usr = new user($db); $adminpermission = $usr->check_admin_permission($_SESSION["user"]); $off = new office($db); $stmtoff = $off->off_read(); $numoff = $stmtoff->rowCount(); $emp = new employee($db); $totalEmp = $emp->count_all_empid(); if (isset($_POST['submit'])) { // Sanitize and validate the form inputsy $emp->empadharnumber = str_replace(' ', '', htmlspecialchars(strip_tags($_POST['empadhar_number_raw']))); $emp->empname = htmlspecialchars(strip_tags($_POST['emp_name'])); $emp->empfathername = htmlspecialchars(strip_tags($_POST['emp_father_name'])); $emp->empdob = htmlspecialchars(strip_tags($_POST['emp_dob'])); $emp->empqualification = htmlspecialchars(strip_tags($_POST['emp_qualification'])); $emp->empemail = htmlspecialchars(strip_tags($_POST['emp_email'])); $emp->empphone = htmlspecialchars(strip_tags($_POST['emp_phone'])); $emp->empaddress = htmlspecialchars(strip_tags($_POST['emp_add'])); $emp->dgname = htmlspecialchars(strip_tags($_POST['dgname'])); $emp->empbg = htmlspecialchars(strip_tags($_POST['empbg'])); $uploadDir = 'uploads/images/'; if (!is_dir($uploadDir)) { mkdir($uploadDir, 0777, true); // Create if not exists } if (!empty($_POST['emp_pic_input'])) { $empPicBase64 = $_POST['emp_pic_input']; $empPicData = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $empPicBase64)); if ($empPicData !== false) { // Generate a unique name for the image $empPicFilename = 'pic_' . uniqid() . '.png'; // Save the image to the 'uploads/images/' directory $empPicPath = $uploadDir . $empPicFilename; if (file_put_contents($empPicPath, $empPicData) !== false) { // Save only the filename in the database (not the full path) $emp->emppic = $empPicFilename; // Save filename, not path } else { die("Failed to save image."); } } else { die("Invalid image data."); } } else { // If no image data is received, set a default image from the 'images' directory $empPicFilename = 'default-picture.png'; // Assuming your default image is named 'default_image.png' // Save the default image filename in the database (not the full path) $emp->emppic = $empPicFilename; // Save filename, not path } $emp->empstatus = "active"; $emp->emppass = htmlspecialchars(strip_tags($_POST['emp_pass'])); $brcname = trim($_POST['selected_text']); $folder_brname = preg_replace("/\s+/", "", $brcname); // Attempt to create or update the employee record if ($emp->emp_create_or_update()) { // Get the URL you want to redirect to $url = 'dashboard.employee.qr.php?empid=' . $emp->lastempid . '&foldername=' . $folder_brname; // Create a form and submit it to open in a new tab echo "
"; exit; // Ensure no further PHP code is executed } else { // Handle failed submission echo "Failed Submission."; exit; } } function getLatestEmpid($db) { $query = "SELECT empid FROM acts_emp ORDER BY empid DESC LIMIT 1"; // Query to get the most recent empid $stmt = $db->prepare($query); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result ? $result['empid'] : null; } $latestEmpid = getLatestEmpid($db); $empaid = $_GET['emplid'] ?? ''; if ($empaid !== '') { // Prepare and execute the query to fetch employee details $query = "SELECT * FROM acts_emp WHERE empid = :empaid"; $stmt = $db->prepare($query); $stmt->bindParam(':empaid', $empaid, PDO::PARAM_INT); $stmt->execute(); // Fetch the employee record $employee = $stmt->fetch(PDO::FETCH_ASSOC); // Assign values if record is found if ($employee) { $empLoname = $employee['loname'] ?? ''; // Fetch Aadhaar number $empNumber = $employee['empadharnumber'] ?? ''; // Fetch Aadhaar number $empName = $employee['empname'] ?? ''; // Fetch Name $empFatherName = $employee['empfathername'] ?? ''; // Fetch Father Name $empDob = $employee['empdob'] ?? ''; // Fetch Date of Birth $empQualification = $employee['empqualification'] ?? ''; // Fetch qualification $empEmail = $employee['empemail'] ?? ''; // Fetch Email $empPhone = $employee['empphone'] ?? ''; // Fetch Phone $empAddress = $employee['empaddress'] ?? ''; // Fetch Address $empDgname = $employee['dgname'] ?? ''; // Fetch Address $empBlood = $employee['empbg'] ?? ''; // Fetch Address $empPass = $employee['emppass'] ?? ''; // Fetch Password $docAdhar = $employee['doc_adhar'] ?? ''; // Fetch doc_adhar $docPolveri = $employee['doc_polveri'] ?? ''; // Fetch doc_adhar $docOther = $employee['doc_other'] ?? ''; // Fetch doc_adhar } else { $empNumber = ''; $docAdhar = ''; $docPolveri = ''; $docOther = ''; } $showSaveButton = true; } else { $empNumber = ''; $docAdhar = ''; $docPolveri = ''; $docOther = ''; $showSaveButton = false; } // Conditionally set the value attribute // If 'emplid' is present, show both forms; else show only the second form $firstFormDisplay = ($empaid !== '') ? 'flex' : 'flex'; // Show first form if empid is present $secondFormDisplay = ($empaid !== '') ? 'flex' : 'none'; // Show second form if empid is present $valueAttribute = ($empaid !== '') ? 'value="' . htmlspecialchars($empNumber, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeName = ($empaid !== '') ? 'value="' . htmlspecialchars($empName, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeFatherName = ($empaid !== '') ? 'value="' . htmlspecialchars($empFatherName, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeDob = ($empaid !== '') ? 'value="' . htmlspecialchars($empDob, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeQualification = ($empaid !== '') ? 'value="' . htmlspecialchars($empQualification, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeEmail = ($empaid !== '') ? 'value="' . htmlspecialchars($empEmail, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributePhone = ($empaid !== '') ? 'value="' . htmlspecialchars($empPhone, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeAddress = ($empaid !== '') ? 'value="' . htmlspecialchars($empAddress, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeLoname = ($empaid !== '') ? 'value="' . htmlspecialchars($empLoname, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeDgname = ($empaid !== '') ? 'value="' . htmlspecialchars($empDgname, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributeBlood = ($empaid !== '') ? 'value="' . htmlspecialchars($empBlood, ENT_QUOTES, 'UTF-8') . '"' : ''; $valueAttributePassword = ($empaid !== '') ? 'value="' . htmlspecialchars($empPass, ENT_QUOTES, 'UTF-8') . '"' : ''; $docAdharAttribute = ($empaid !== '') ? 'value="' . htmlspecialchars($docAdhar, ENT_QUOTES, 'UTF-8') . '"' : ''; $docPolveriAttribute = ($empaid !== '') ? 'value="' . htmlspecialchars($docPolveri, ENT_QUOTES, 'UTF-8') . '"' : ''; $docOtherAttribute = ($empaid !== '') ? 'value="' . htmlspecialchars($docOther, ENT_QUOTES, 'UTF-8') . '"' : ''; if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Get the Aadhar number from the POST data $adn = $_POST['adn'] ?? ''; // Prepare the value attribute $valueA = 'value="' . htmlspecialchars($adn, ENT_QUOTES, 'UTF-8') . '"'; } else { $valueA = ''; } ?> prepare($query); $stmt->bindParam(':empid', $empid); $stmt->execute(); // Fetch the empbranchcode $empbranchcode = $stmt->fetch(PDO::FETCH_ASSOC)['empbranchcode'] ?? ''; // Fetch the branch name based on empbranchcode from the `acts_branch` table $queryBranch = "SELECT brch_id, brch_name FROM acts_branch WHERE brch_id = :brch_id"; $stmtBranch = $db->prepare($queryBranch); $stmtBranch->bindParam(':brch_id', $empbranchcode); $stmtBranch->execute(); // Fetch the branch name $branch = $stmtBranch->fetch(PDO::FETCH_ASSOC); $selectedBranch = $branch['brch_name'] ?? ''; // Fallback to empty string if not found } ?> fetch_bank_details_by_empid($empid); } ?>Fill the form to add a New Employee