add edit employee file upload

This commit is contained in:
vadivel J 2024-10-23 18:28:47 +05:30
parent 877db92512
commit 0c00f37cb9
3 changed files with 359 additions and 250 deletions

View File

@ -338,11 +338,25 @@ class Employeedetails extends BaseController
if ($result) {
// Get the uploaded files
$files = $this->request->getFiles();
$fileNames = $this->request->getPost('file_name'); // Get user-entered file names
if (isset($files['emp_file'])) {
foreach ($files['emp_file'] as $index => $file) {
if ($file->isValid() && !$file->hasMoved()) {
$files1 = $this->request->getFile('emp_file1');
$files2 = $this->request->getFile('emp_file2');
$files3 = $this->request->getFile('emp_file3');
$files4 = $this->request->getFile('emp_file4');
$files5 = $this->request->getFile('emp_file5');
$files=[$files1,$files2,$files3,$files4,$files5];
$fileName1 = $this->request->getPost('file_name1');
$fileName2 = $this->request->getPost('file_name2');
$fileName3 = $this->request->getPost('file_name3');
$fileName4 = $this->request->getPost('file_name4');
$fileName5 = $this->request->getPost('file_name5');
$fileNames=[$fileName1,$fileName2,$fileName3,$fileName4,$fileName5];
if (!empty($files)) {
foreach ($files as $index => $file) {
if ($ffile && $file->isValid() && !$file->hasMoved()) {
// Move the file to the desired directory
$newName = $file->getRandomName();
$file->move(ROOTPATH . 'public/uploads/images/emp_files', $newName);
@ -619,12 +633,6 @@ class Employeedetails extends BaseController
$EmpId = $this->request->getPost('employeeid');
$EmpId = $this->request->getPost('employeeid');
$PictureName = $this->request->getPost('Image');
$ModifyPictureName = $this->request->getPost('ModifyImage');
@ -816,27 +824,42 @@ class Employeedetails extends BaseController
//print_r($Employee);die();
$result = $this->employeedetails_model->UpdateEmployee($Employee, $EmpId);
// Get the uploaded files
$files = $this->request->getFiles();
$fileNames = $this->request->getPost('file_name'); // Get user-entered file names
if (isset($files['emp_file'])) {
foreach ($files['emp_file'] as $index => $file) {
if ($file->isValid() && !$file->hasMoved()) {
// Move the file to the desired directory
$newName = $file->getRandomName();
$file->move(ROOTPATH . 'public/uploads/images/emp_files', $newName);
$path = ROOTPATH . 'public/uploads/images/emp_files/' . $newName;
// Store the file information in the database
$this->empFiles->save([
'file_name' => $fileNames[$index], // User-entered file name
'emp_file' => $newName, // New file name
'emp_id' => $EmpId,
'path' => $path
]);
}
}
}
// Get the uploaded files
$files1 = $this->request->getFile('emp_file1');
$files2 = $this->request->getFile('emp_file2');
$files3 = $this->request->getFile('emp_file3');
$files4 = $this->request->getFile('emp_file4');
$files5 = $this->request->getFile('emp_file5');
$files=[$files1,$files2,$files3,$files4,$files5];
$fileName1 = $this->request->getPost('file_name1');
$fileName2 = $this->request->getPost('file_name2');
$fileName3 = $this->request->getPost('file_name3');
$fileName4 = $this->request->getPost('file_name4');
$fileName5 = $this->request->getPost('file_name5');
$fileNames=[$fileName1,$fileName2,$fileName3,$fileName4,$fileName5];
if (!empty($files)) {
foreach ($files as $index => $file) {
if ($file && $file->isValid() && !$file->hasMoved()) {
// Move the file to the desired directory
$newName = $file->getRandomName();
$file->move(ROOTPATH . 'public/uploads/images/emp_files', $newName);
$path = ROOTPATH . 'public/uploads/images/emp_files/' . $newName;
// Store the file information in the database
$this->empFiles->save([
'file_name' => $fileNames[$index], // User-entered file name
'emp_file' => $newName, // New file name
'emp_id' => $result,
'path' => $path
]);
}
}
}

View File

@ -423,13 +423,7 @@
<span class="d-none d-sm-inline">Proof</span>
</a>
</li>
<li class="nav-item" data-target-form="#fileForm">
<a href="#fivth" data-toggle="tab" class="nav-link">
<!-- <a data-toggle="tab" class="nav-link"> -->
<span class="number">5</span>
<span class="d-none d-sm-inline">File Upload</span>
</a>
</li>
</ul>
<div class="tab-content mb-0 b-0">
@ -1004,7 +998,7 @@
</div>
<div class="tab-pane fade" id="fourth">
<form id="proofForm" method="post" action="#" class="form-horizontal">
<form id="proofForm" method="post" action="#" class="form-horizontal" enctype="multipart/form-data">
<div class="row">
<div class="col-md-1">
</div>
@ -1016,6 +1010,24 @@
onchange="ValidateAadhar();" class="form-control"
onkeypress="return isNumberKey(event)" required>
</div>
<div class="col-md-3">
<label>File Name</label>
<input type="text" id="file_name" name="file_name1" maxlength="255"
class="form-control" value="Aadhar">
</div>
<div class="col-md-3">
<label>Select Aadhar File</label>
<input type="file" name="emp_file1" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"><label>PAN Number</label>
<input type="text" id="panno" maxlength="10"
style="text-transform:uppercase" name="panno"
@ -1024,6 +1036,26 @@
title=" 5 character,4 Digit Numbers,1 character (ex:ABCDE1234A) "
onkeypress="return alpha(event);">
</div>
<div class="col-md-3">
<label>PAN File Name</label>
<input type="text" id="file_name" name="file_name2" maxlength="255"
class="form-control" value="PAN">
</div>
<div class="col-md-3">
<label>Select PAN File</label>
<input type="file" name="emp_file2" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"><label>Passport Number</label>
<input type="text" id="passportno" maxlength="9"
onchange="ValidatePassport();" name="passportno"
@ -1031,11 +1063,50 @@
pattern="[aA-prPR-wyWY]{1}[1-9]{1}\d{1}\s\d{4}[1-9]{1}" title="The first digit or the last digit will never be 0
The first character cannot be Q, X or Z. (eg:A12 34567)" onkeypress="return alpha(event);">
</div>
<div class="col-md-3">
<label>Passport File Name</label>
<input type="text" id="file_name" name="file_name3" maxlength="255"
class="form-control" value="Passport">
</div>
<div class="col-md-3">
<label>Select Passport File</label>
<input type="file" name="emp_file3" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<label>Bank PassBok Name</label>
<input type="text" id="file_name" name="file_name4" maxlength="255"
class="form-control" value="Bank Passbook">
</div>
<div class="col-md-3">
<label>Bank PassBok File</label>
<input type="file" name="emp_file4" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<label>Other Document File Name</label>
<input type="text" id="file_name" name="file_name5" maxlength="255"
class="form-control" value="Other Document">
</div>
<div class="col-md-3">
<label>Other Document File </label>
<input type="file" name="emp_file5" class="">
</div>
</div>
</div>
</div>
@ -1043,48 +1114,11 @@
<ul class="list-inline wizard mb-0">
<li class="previous list-inline-item"><a href="javascript: void(0);" class="btn btn-secondary">Previous</a>
</li>
<li class="next list-inline-item float-right"><a href="javascript: void(0);" class="btn btn-secondary">Next</a></li>
</ul>
</div>
<div class="tab-pane fade" id="fivth">
<form id="fileForm" method="post" action="#" class="form-horizontal" enctype="multipart/form-data" style="height: 250px;">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-11">
<div class="row">
<!-- <div class="files"> -->
<div class="col-md-4">
<label>File Name</label>
<input type="text" id="file_name" name="file_name[]" maxlength="255"
class="form-control">
</div>
<div class="col-md-4">
<label>File</label>
<input type="file" name="emp_file[]" class="form-control">
</div>
<div class="col-md-4" style="margin-top: 32px;">
<button type="button" class="btn btn-primary btn-sm a1"
onclick="appendFilesFileds()" id="day">
Add
</button>
</div>
<div id="filesContainer" class="col-12"></div>
<!-- </div> -->
</div>
</div>
</div>
</form>
<ul class="list-inline wizard mb-0">
<li class="previous list-inline-item"><a href="javascript: void(0);" class="btn btn-secondary">Previous</a>
</li>
<!-- <li class="next list-inline-item float-right"> -->
<button type="submit" class="btn btn-primary submit float-right">Submit</button>
<!-- </li> -->
</ul>
</div>
</div>
</div> <!-- tab-content -->
</div> <!-- end #rootwizard-->
@ -1123,28 +1157,6 @@
}
}
function appendFilesFileds(data) {
var newRowHtml = `
<div class="pad row">
<div class="col-md-4">
<span for="file_name">File name</span>
<input type="text" id="file_name" name="file_name[]" maxlength="255" class="form-control" value="${data != null && data != '' ? data.file_name : ''}">
</div>
<div class="col-md-4">
<span for="emp_file">File</span>
<input type="file" name="emp_file[]" class="form-control">
</div>
<div class="col-md-4" style="margin-top: 23px;">
<button type="button" class="btn btn-danger btn-sm" id="" onclick="removeContact(this)">Remove</button>
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()">Add</button>
</div>
</div>`;
$('#filesContainer').append(newRowHtml);
$('.a1').hide();
$('#filesContainer .pad:last .a1').show();
}
function removeContact(button) {
$(button).closest('.pad').remove();
$('#filesContainer .a1').hide();
@ -1458,7 +1470,7 @@
var combinedFormData = new FormData(); // Use FormData to handle files
// List of form IDs you want to combine
var formIds = ['#accountForm', '#profileForm', '#bankForm', '#proofForm', '#fileForm']; // Add all your form IDs here
var formIds = ['#accountForm', '#profileForm', '#bankForm', '#proofForm',]; // Add all your form IDs here
formIds.forEach(function(formId) {
var $form = $(formId);

View File

@ -191,13 +191,7 @@ if (!empty($EmpDetails)) {
<span class="d-none d-sm-inline">Proof</span>
</a>
</li>
<li class="nav-item" data-target-form="#fileForm">
<a href="#fivth" data-toggle="tab" class="nav-link">
<!-- <a data-toggle="tab" class="nav-link"> -->
<span class="number">5</span>
<span class="d-none d-sm-inline">File Upload</span>
</a>
</li>
</ul>
<div class="tab-content mb-0 b-0">
@ -913,44 +907,228 @@ if (!empty($EmpDetails)) {
</div>
<div class="tab-pane fade" id="fourth">
<form id="proofForm" method="post" action="#" class="form-horizontal">
<form id="proofForm" method="post" enctype="multipart/form-data" action="#" class="form-horizontal">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-11">
<div class="row">
<div class="col-md-3">
<label>Aadhar Number</label> <span class="badge">*</span>
<input type="text" id="aadharno" name="aadharno" required
maxlength="14" placeholder="Aadhar Number"
onchange="ValidateAadhar();" class="form-control num"
value="<?php echo $AadharNo; ?>" title=" : 12 digit number">
</div>
<div class="col-md-3">
<label>PAN Number</label>
<input type="text" id="panno" style="text-transform: uppercase"
maxlength="10" name="panno" placeholder="PAN Number"
onchange="validatePAN();" class="form-control"
value="<?php echo $PANNo; ?>"
onkeypress="return alpha(event);"
pattern="([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}"
title=" 5 character,4 Digit Numbers,1 character (ex:ABCDE1234A) ">
</div>
<div class="col-md-3">
<label>Passport Number</label>
<input type="text" id="passportno" name="passportno"
maxlength="9" placeholder="Passport Number"
onkeypress="return alpha(event);"
onchange="ValidatePassport();" class="form-control"
value="<?php echo $PassportNo; ?>"
pattern="[Aa-PpRr-WwYy]{1}[1-9]{1}\d{1}\s\d{4}[1-9]{1}"
title="The first digit or the last digit will never be 0
The first character cannot be Q, X or Z. (eg:A12 34567)"
style="text-transform: uppercase">
</div>
<?php if (count($emp_data) > 0) {
?>
</div>
<!-- previous code -->
<!-- <div class="row">
<div class="col-md-4">
<label>File Name</label>
<input type="text" maxlength="255" class="form-control"
value="<?php echo $value['file_name']; ?>" readonly>
</div>
<div class="col-md-1" style="margin-top: 32px;">
<a href="<?php echo base_url() . 'public/uploads/images/emp_files/' . $value['emp_file']; ?>"
download>
<i class="fa fa-download" aria-hidden="true"
style="font-size: 25px;"></i>
</a>
</div>
<div class="col-md-4" align="left" style="margin-top: 32px;">
<button type="button" class="btn btn-danger btn-sm"
id="<?= $value['id']; ?>"
onclick="removeContact(this)">Delete
</button>
</div>
</div> -->
<!-- new code -->
<div class="row">
<div class="col-md-3"><label>Aadhar Number</label> <span
class="badge">*</span>
<input type="text" id="aadharno" name="aadharno" maxlength="14"
onchange="ValidateAadhar();" class="form-control"
onkeypress="return isNumberKey(event)" required>
</div>
<div class="col-md-3">
<label>File Name</label>
<input type="text" id="file_name" name="file_name1" maxlength="255"
class="form-control" value="<?= $value['emp_file']?>">
</div>
<div class="col-md-3">
<label>Select Aadhar File</label>
<input type="file" name="emp_file1" class="" value="">
</div>
</div>
<div class="row">
<div class="col-md-3"><label>PAN Number</label>
<input type="text" id="panno" maxlength="10"
style="text-transform:uppercase" name="panno"
onchange="validatePAN();" class="form-control"
pattern="([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}"
title=" 5 character,4 Digit Numbers,1 character (ex:ABCDE1234A) "
onkeypress="return alpha(event);">
</div>
<div class="col-md-3">
<label>PAN File Name</label>
<input type="text" id="file_name" name="file_name2" maxlength="255"
class="form-control" value="PAN">
</div>
<div class="col-md-3">
<label>Select PAN File</label>
<input type="file" name="emp_file2" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"><label>Passport Number</label>
<input type="text" id="passportno" maxlength="9"
onchange="ValidatePassport();" name="passportno"
style="text-transform:uppercase" class="form-control"
pattern="[aA-prPR-wyWY]{1}[1-9]{1}\d{1}\s\d{4}[1-9]{1}" title="The first digit or the last digit will never be 0
The first character cannot be Q, X or Z. (eg:A12 34567)" onkeypress="return alpha(event);">
</div>
<div class="col-md-3">
<label>Passport File Name</label>
<input type="text" id="file_name" name="file_name3" maxlength="255"
class="form-control" value="Passport">
</div>
<div class="col-md-3">
<label>Select Passport File</label>
<input type="file" name="emp_file3" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<label>Bank PassBok Name</label>
<input type="text" id="file_name" name="file_name4" maxlength="255"
class="form-control" value="Bank Passbook">
</div>
<div class="col-md-3">
<label>Bank PassBok File</label>
<input type="file" name="emp_file4" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<label>Other Document File Name</label>
<input type="text" id="file_name" name="file_name5" maxlength="255"
class="form-control" value="Other Document">
</div>
<div class="col-md-3">
<label>Other Document File </label>
<input type="file" name="emp_file5" class="">
</div>
</div>
<?php } else { ?>
<div class="row">
<div class="col-md-3"><label>Aadhar Number</label> <span
class="badge">*</span>
<input type="text" id="aadharno" name="aadharno" maxlength="14"
onchange="ValidateAadhar();" class="form-control"
onkeypress="return isNumberKey(event)" required>
</div>
<div class="col-md-3">
<label>File Name</label>
<input type="text" id="file_name" name="file_name1" maxlength="255"
class="form-control" value="Aadhar">
</div>
<div class="col-md-3">
<label>Select Aadhar File</label>
<input type="file" name="emp_file1" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"><label>PAN Number</label>
<input type="text" id="panno" maxlength="10"
style="text-transform:uppercase" name="panno"
onchange="validatePAN();" class="form-control"
pattern="([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}"
title=" 5 character,4 Digit Numbers,1 character (ex:ABCDE1234A) "
onkeypress="return alpha(event);">
</div>
<div class="col-md-3">
<label>PAN File Name</label>
<input type="text" id="file_name" name="file_name2" maxlength="255"
class="form-control" value="PAN">
</div>
<div class="col-md-3">
<label>Select PAN File</label>
<input type="file" name="emp_file2" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"><label>Passport Number</label>
<input type="text" id="passportno" maxlength="9"
onchange="ValidatePassport();" name="passportno"
style="text-transform:uppercase" class="form-control"
pattern="[aA-prPR-wyWY]{1}[1-9]{1}\d{1}\s\d{4}[1-9]{1}" title="The first digit or the last digit will never be 0
The first character cannot be Q, X or Z. (eg:A12 34567)" onkeypress="return alpha(event);">
</div>
<div class="col-md-3">
<label>Passport File Name</label>
<input type="text" id="file_name" name="file_name3" maxlength="255"
class="form-control" value="Passport">
</div>
<div class="col-md-3">
<label>Select Passport File</label>
<input type="file" name="emp_file3" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<label>Bank PassBok Name</label>
<input type="text" id="file_name" name="file_name4" maxlength="255"
class="form-control" value="Bank Passbook">
</div>
<div class="col-md-3">
<label>Bank PassBok File</label>
<input type="file" name="emp_file4" class="">
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<label>Other Document File Name</label>
<input type="text" id="file_name" name="file_name5" maxlength="255"
class="form-control" value="Other Document">
</div>
<div class="col-md-3">
<label>Other Document File </label>
<input type="file" name="emp_file5" class="">
</div>
</div>
<?php } ?>
</div>
</div>
@ -960,96 +1138,14 @@ if (!empty($EmpDetails)) {
<li class="previous list-inline-item"><a href="javascript: void(0);"
class="btn btn-secondary">Previous</a>
</li>
<li class="next list-inline-item float-right"><a href="javascript: void(0);"
class="btn btn-secondary">Next</a></li>
</ul>
</div>
<div class="tab-pane fade" id="fivth">
<form id="fileForm" method="post" action="#" class="form-horizontal">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-11">
<!-- <div class="row"> -->
<!-- <div class="files"> -->
<?php if (count($emp_data) > 0) { ?>
<?php foreach ($emp_data as $key => $value) { ?>
<div class="row">
<div class="col-md-4">
<label>File Name</label>
<input type="text" maxlength="255" class="form-control"
value="<?php echo $value['file_name']; ?>" readonly>
</div>
<div class="col-md-1" style="margin-top: 32px;">
<a href="<?php echo base_url() . 'public/uploads/images/emp_files/' . $value['emp_file']; ?>"
download>
<i class="fa fa-download" aria-hidden="true"
style="font-size: 25px;"></i>
</a>
</div>
<div class="col-md-4" align="left" style="margin-top: 32px;">
<button type="button" class="btn btn-danger btn-sm"
id="<?= $value['id']; ?>"
onclick="removeContact(this)">Delete
</button>
<button type="button" class="btn btn-primary btn-sm a1"
onclick="appendFilesFileds()" id="day"
style="display: inline-block;">
Add New File
</button>
</div>
</div>
<?php }
} else { ?>
<div class="row">
<div class="col-md-4">
<label>File Name</label>
<input type="text" id="file_name" name="file_name[]"
maxlength="255" class="form-control">
</div>
<div class="col-md-4">
<label>File</label>
<input type="file" name="emp_file[]" class="form-control">
</div>
<div class="col-md-4" style="margin-top: 32px;">
<button type="button" class="btn btn-primary btn-sm a1"
onclick="appendFilesFileds()" id="day">
Add
</button>
</div>
</div>
<?php } ?>
<div id="filesContainer" class="col-12"></div>
<!-- </div> -->
<!-- </div> -->
</div>
</div>
</form>
<ul class="list-inline wizard mb-0">
<li class="previous list-inline-item"><a href="javascript: void(0);"
class="btn btn-secondary">Previous</a>
<li class="next list-inline-item float-right">
<button type="submit" class="btn btn-primary submit float-right">Submit</button>
</li>
<!-- <li class="next list-inline-item float-right"> -->
<button type="submit" class="btn btn-primary submit float-right">Submit</button>
<!-- </li> -->
</ul>
</div>
</div>
</div> <!-- tab-content -->
</div> <!-- end #rootwizard-->
@ -1534,28 +1630,6 @@ if (!empty($EmpDetails)) {
}
}
function appendFilesFileds(data) {
var newRowHtml = `
<div class="pad row">
<div class="col-md-4">
<span for="file_name">File name</span>
<input type="text" id="file_name" name="file_name[]" maxlength="255" class="form-control" value="${data != null && data != '' ? data.file_name : ''}">
</div>
<div class="col-md-4">
<span for="emp_file">File</span>
<input type="file" name="emp_file[]" class="form-control">
</div>
<div class="col-md-4" style="margin-top: 23px;">
<button type="button" class="btn btn-danger btn-sm" id="" onclick="removeContact(this)">Remove</button>
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()">Add</button>
</div>
</div>`;
$('#filesContainer').append(newRowHtml);
$('.a1').hide();
$('#filesContainer .pad:last .a1').show();
}
function removeContact(button) {
if (button.id != '') {
$('#loader').show();
@ -1773,7 +1847,7 @@ if (!empty($EmpDetails)) {
var isValid = true;
var combinedFormData = new FormData();
var formIds = ['#accountForm', '#profileForm', '#bankForm', '#proofForm', '#fileForm']; // Add all your form IDs here
var formIds = ['#accountForm', '#profileForm', '#bankForm', '#proofForm']; // Add all your form IDs here
formIds.forEach(function(formId) {
var $form = $(formId);