2024-10-16 19:18:52 +05:30
< ? php
error_reporting ( E_ERROR | E_PARSE );
include ( 'includes/config/config.php' );
include ( 'includes/functions.php' );
include ( 'log_entry.php' );
error_log ( " Start Printing Request Attributes " );
$requestStr = " " ;
foreach ( $_REQUEST as $key => $value ) {
$requestStr .= $key . " : " . $value . " \n " ;
error_log ( $key . " : " . $value . " <br /> \r \n " );
}
error_log ( " End Printing Request Attributes " );
save_log ( $requestStr , 'Patient' , 'SAVE' , 'save_employee.php' );
// print_r($_POST);
$id = $_POST [ 'employee_id' ];
$fname = $_POST [ 'fname' ];
$lname = $_POST [ 'lname' ];
$father_name = $_POST [ 'father_name' ];
$dob = $_POST [ 'dob' ];
$doj = $_POST [ 'doj' ];
$designation_id = $_POST [ 'designation_id' ];
$emp_code = $_POST [ 'emp_code' ];
$emp_type_id = $_POST [ 'emp_type_id' ];
$bu_id = $_POST [ 'bu_id' ];
$sbu_id = $_POST [ 'sbu_id' ];
$section_id = $_POST [ 'section_id' ];
$sub_section_id = $_POST [ 'sub_section_id' ];
$mgr_emp_id = $_POST [ 'mgr_emp_id' ];
$gender = $_POST [ 'gender' ];
$address = $_POST [ 'address' ];
$primary_phone = $_POST [ 'primary_phone' ];
$email = $_POST [ 'email' ];
$aadhar_no = $_POST [ 'aadhar_no' ];
$blood_group = $_POST [ 'blood_group' ];
$has_first_aid = $_POST [ 'has_first_aid' ];
if ( $known_health_advices != '' ) {
$known_health_advices = implode ( ',' , $known_health_advices );
$known_health_advices = $known_health_advices . " , " ;
$known_health_advices = addslashes ( $known_health_advices );
// $known_health_advices='ifNull(known_health_advices,)'addslashes($known_health_advices);
} else {
$known_health_advices = " concat(known_health_advices,'') " ;
// /echo $known_health_advices;
}
if ( $known_health_risks != '' ) {
$known_health_risks = implode ( ',' , $known_health_risks );
$known_health_risks = $known_health_risks . " , " ;
$known_health_risks = addslashes ( $known_health_risks );
} else {
$known_health_risks = " concat(known_health_risks,'') " ;
}
// echo $known_health_risks;
// echo $known_health_advices;
$imgData = null ;
$photoQuery = " " ;
if ( count ( $_FILES ) > 0 ) {
$_FILES [ 'photo' ][ 'tmp_name' ];
if ( is_uploaded_file ( $_FILES [ 'photo' ][ 'tmp_name' ])) {
$info = pathinfo ( $_FILES [ 'photo' ][ 'name' ]);
$ext = pathinfo ( $info , PATHINFO_EXTENSION );
$imgData = addslashes ( file_get_contents ( $_FILES [ 'photo' ][ 'tmp_name' ]));
$imageProperties = getimageSize ( $_FILES [ 'photo' ][ 'tmp_name' ]);
$photoQuery = " ,photo=' { $imgData } ' ,image_type=' { $imageProperties [ 'mime' ] } ' " ;
}
}
$data = array ();
$query = " " ;
$emp_id = " " ;
if ( ! empty ( $id )) {
$query = " update employee set fname = ' " . addslashes ( $fname ) . " ', lname = ' " . addslashes ( $lname ) . " ', father_name = ' " . addslashes ( $father_name ) . " ',
dob = STR_TO_DATE ( '" . $_POST[' dob '] . "' , '%d/%m/%Y' ), doj = STR_TO_DATE ( '" . $_POST[' doj '] . "' , '%d/%m/%Y' ), designation_id = '" . addslashes($designation_id) . "' , emp_code = '" . addslashes($emp_code) . "' , employment_type_id = '" . addslashes($emp_type_id) . "' ,
bu_id = '$bu_id' , sbu_id = '$sbu_id' , section_id = '$section_id' , sub_section_id = '$sub_section_id' , mgr_emp_id = '$mgr_emp_id' ,
gender = '$gender' , address = '" . addslashes($address) . "' , primary_phone = '" . addslashes($primary_phone) . "' ,
primary_contact_person = '" . addslashes($primary_contact_person) . "' , primary_contact_no = '" . addslashes($primary_contact_no) . "' ,
known_health_advices = '" . $known_health_advices . "' , known_health_risks = '" . $known_health_risks . "' ,
secondary_contact_person = '" . addslashes($secondary_contact_person) . "' , secondary_contact_no = '" . addslashes($secondary_contact_no) . "' ,
email_id = '" . addslashes($email) . "' , aadhar_no = '" . addslashes($aadhar_no) . "' , is_first_aid = '" . addslashes($has_first_aid) . "' ,
blood_group = '" . addslashes($blood_group) . "' " . $photoQuery . " , modified_by = '" . $_SESSION[' user_id '] . "' where id = " . $id . " " ;
} else {
$query = " insert into employee set fname = ' " . addslashes ( $fname ) . " ', lname = ' " . addslashes ( $lname ) . " ', father_name = ' " . addslashes ( $father_name ) . " '
, dob = STR_TO_DATE ( '" . $_POST[' dob '] . "' , '%d/%m/%Y' ), doj = STR_TO_DATE ( '" . $_POST[' doj '] . "' , '%d/%m/%Y' ),
designation_id = '" . addslashes($designation_id) . "' , emp_code = '" . addslashes($emp_code) . "' , employment_type_id = '" . addslashes($emp_type_id) . "' ,
bu_id = '$bu_id' , sbu_id = '$sbu_id' , section_id = '$section_id' , sub_section_id = '$sub_section_id' , mgr_emp_id = '$mgr_emp_id' ,
gender = '$gender' , address = '" . addslashes($address) . "' , primary_phone = '" . addslashes($primary_phone) . "' , known_health_advices = '" . $known_health_advices . "'
, known_health_risks = '" . $known_health_risks . "' , email_id = '" . addslashes($email) . "' , primary_contact_person = '" . addslashes($primary_contact_person) . "' ,
primary_contact_no = '" . addslashes($primary_contact_no) . "' , secondary_contact_person = '" . addslashes($secondary_contact_person) . "' ,
secondary_contact_no = '" . addslashes($secondary_contact_no) . "' , aadhar_no = '" . addslashes($aadhar_no) . "' , blood_group = '" . addslashes($blood_group) . "' ,
is_first_aid = '" . addslashes($has_first_aid) . "' , " . $photoQuery . "
modified_by = '" . $_SESSION[' user_id '] . "' " ;
}
// echo $query;
// $data['query']=$query;
if ( ! $result = @ mysqli_query ( $conn , $query )) {
$data [ 'status' ] = 500 ;
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
} else {
if ( ! empty ( $id )) {
$emp_id = $id ;
}
else {
$emp_id = @ mysqli_insert_id ();
}
}
if ( ! empty ( $id )) {
$rowCount = $_POST [ 'rowCount' ];
// echo $rowCount;
$select_query_family_members = " select id from emp_family_members where emp_id= $id " ;
// echo $select_query_family_members;
$result_family_members = @ mysqli_query ( $conn , $select_query_family_members );
$rows_family_members = @ mysqli_num_rows ( $result_family_members );
$members_id = array ();
$count = 0 ;
while ( $row_members = @ mysqli_fetch_assoc ( $result_family_members )) {
$members_id [ $count ] = $row_members [ 'id' ];
$count ++ ;
}
$query_initial = " " ;
$query_end = " " ;
for ( $i = 0 ; $i < $rowCount ; $i ++ ) {
if ( $rows_family_members > 0 ) {
if ( $rows_family_members == $rowCount ) {
$query_initial = " update emp_family_members " ;
$query_end = " where id=' $members_id[$i] ' " ;
} elseif ( $rows_family_members < $rowCount ) {
if ( $i < $rows_family_members ) {
$query_initial = " update emp_family_members " ;
$query_end = " where id=' $members_id[$i] ' " ;
} else {
$query_initial = " insert into emp_family_members " ;
$query_end = " " ;
}
}
// $query_family_members=$query_initial." set name='".addslashes($_POST['name'.$i])."' ,age='".addslashes($_POST['age'.$i])."', gender='".addslashes($_POST['gender'.$i])."', relation_type='".addslashes($_POST['relation_type'.$i])."',emp_id='$emp_id' ".$query_end;
// echo $query_family_members;
// @mysqli_query($conn,$query_family_members);
} else {
$query_initial = " insert into emp_family_members " ;
// echo $query_initial;
}
// echo $i;
$query_family_members = $query_initial . " set name=' " . addslashes ( $_POST [ 'name' . $i ]) . " ' ,age=' " . addslashes ( $_POST [ 'age' . $i ]) . " ', gender=' " . addslashes ( $_POST [ 'gender' . $i ]) . " ', relation_type=' " . addslashes ( $_POST [ 'relation_type' . $i ]) . " ',emp_id= $emp_id " . $query_end ;
// echo $query_family_members;
@ mysqli_query ( $conn , $query_family_members );
}
$checkup_header_val = explode ( ',' , $_POST [ 'checkup_header_val' ]);
// echo $_POST['checkup_header_val'];
//echo count($checkup_header_val);
for ( $h = 0 ; $h < count ( $checkup_header_val ); $h ++ ) {
$querowCount = $_POST [ 'querowCount' ];
// echo $querowCount;
$select_query_que = " select ans_id from questionnaire_ans where emp_id= $id AND section_id= $checkup_header_val[$h] " ;
// echo $select_query_que;
$result_que = @ mysqli_query ( $conn , $select_query_que );
$rows_que = @ mysqli_num_rows ( $result_que );
$ans_id = array ();
$count = 0 ;
while ( $row_questions = @ mysqli_fetch_assoc ( $result_que )) {
$ans_id [ $count ] = $row_questions [ 'ans_id' ];
$count ++ ;
}
$select_query_child_que = " select ans_id from questionnaire_ans where emp_id= $id AND section_id is null " ;
//echo $select_query_child_que;
$result_child_que = @ mysqli_query ( $conn , $select_query_child_que );
$rows_child_que = @ mysqli_num_rows ( $result_child_que );
$child_ans_id = array ();
$count_child = 0 ;
while ( $row_child_questions = @ mysqli_fetch_assoc ( $result_child_que )) {
$child_ans_id [ $count_child ] = $row_child_questions [ 'ans_id' ];
$count_child ++ ;
}
// print_r($child_ans_id);
$query_initial = " " ;
$query_end = " " ;
for ( $i = 0 ; $i < $querowCount ; $i ++ ) {
$que_id = $_POST [ 'que_id' . $i ];
$childQuesQuery = " select * from questionnaire where parentId = ' $que_id ' " ;
// echo $i." ".$childQuesQuery."<br>";
$childQueResult = @ mysqli_query ( $conn , $childQuesQuery );
$numQuesRows = @ mysqli_num_rows ( $childQueResult );
// echo $childQuesQuery." ".$numQuesRows."<br>";
if ( $numQuesRows != 0 ) {
while ( $rowChildQue = @ mysqli_fetch_array ( $childQueResult )) {
$childQueId = $rowChildQue [ 'question_id' ];
// echo $childQueId."<br>";
if ( $rows_child_que > 0 ) {
// echo $rows_child_que;
if ( $_POST [ $childQueId . 'ans' . $i ] == null or $_POST [ $childQueId . 'ans' . $i ] == " " ) {
$query_child_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $child_ans_id[0] '; " ;
// echo $query_child_delete;
@ mysqli_query ( $conn , $query_child_delete );
} else {
$query_child_initial = " update questionnaire_ans " ;
$query_child_end = " where ans_id=' $child_ans_id[$i] ' " ;
}
if ( $i < $rows_que ) {
if ( $_POST [ $childQueId . 'ans' . $i ] == null or $_POST [ $childQueId . 'ans' . $i ] == " " ) {
$query_child_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $child_ans_id[$i] '; " ;
// echo "<br>".$query_child_delete;
@ mysqli_query ( $conn , $query_child_delete );
} else {
$query_child_initial = " update questionnaire_ans " ;
$query_child_end = " where ans_id=' $child_ans_id[$i] ' " ;
}
} else {
if ( $_POST [ $childQueId . 'ans' . $i ] != null or $_POST [ $childQueId . 'ans' . $i ] != " " ) {
$query_child_initial = " insert into questionnaire_ans " ;
$query_child_end = " " ;
}
}
// $query_family_members=$query_initial." set name='".addslashes($_POST['name'.$i])."' ,age='".addslashes($_POST['age'.$i])."', gender='".addslashes($_POST['gender'.$i])."', relation_type='".addslashes($_POST['relation_type'.$i])."',emp_id='$emp_id' ".$query_end;
// echo $query_family_members;
// @mysqli_query($conn,$query_family_members);
} else {
$query_child_initial = " insert into questionnaire_ans " ;
}
// echo $i;
if ( $_POST [ $childQueId . 'ans' . $i ] != null or $_POST [ $childQueId . 'ans' . $i ] != " " ) {
$ans = $_POST [ $childQueId . 'ans' . $i ];
$query_child_que = $query_child_initial . " set answer=' $ans ' ,que_id=' " . addslashes ( $_POST [ $childQueId . 'que_id' . $i ]) . " ' ,emp_id= $emp_id , modified_by = ' " . $_SESSION [ 'user_id' ] . " ' " . $query_child_end ;
//echo $query_child_que . "<br>";
@ mysqli_query ( $conn , $query_child_que );
}
}
}
$que_id = $_POST [ 'que_id' . $i ];
$QuesQuery = " select requiredDetailsIds from questionnaire where question_id = ' $que_id ' " ;
// echo $i." ".$childQuesQuery."<br>";
$QueResult = @ mysqli_query ( $conn , $QuesQuery );
$quesRows = @ mysqli_fetch_array ( $QueResult );
$ans = " " ;
if ( $_POST [ 'ans' . $i ] != null or $_POST [ 'ans' . $i ] != " " ) {
$requiredDetails = $quesRows [ 'requiredDetailsIds' ];
//echo $requiredDetails;
$requiredDetailsArr = explode ( " , " , $requiredDetails );
$ans = $_POST [ 'ans' . $i ] . " : " ;
foreach ( $requiredDetailsArr as $requiredDetailsIdsArrval ) {
$requiredDetailsArrval = getTableFieldValue ( 'question_sub_details' , 'sub_detail_name' , 'sub_detail_id' , $requiredDetailsIdsArrval );
$ans = $ans . " , " . $requiredDetailsArrval . " : " . $_POST [ $requiredDetailsArrval . $i ];
}
}
// echo "que row".$rows_que;
if ( $rows_que > 0 ) {
if ( $rows_que == $querowCount ) {
if ( $_POST [ 'ans' . $i ] == null or $_POST [ 'ans' . $i ] == " " ) {
$query_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $ans_id[$i] ' AND section_id= $checkup_header_val[$h] ; " ;
// echo $query_delete;
@ mysqli_query ( $conn , $query_delete );
}
else {
$query_initial = " update questionnaire_ans " ;
// echo $query_initial;
$query_end = " where ans_id=' $ans_id[$i] ' " ;
}
} elseif ( $rows_que < $querowCount ) {
if ( $i < $rows_que ) {
if ( $_POST [ 'ans' . $i ] == null or $_POST [ 'ans' . $i ] == " " ) {
$query_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $ans_id[$i] ' AND section_id= $checkup_header_val[$h] ; " ;
// echo $query_delete;
@ mysqli_query ( $conn , $query_delete );
}
else {
$query_initial = " update questionnaire_ans " ;
$query_end = " where ans_id=' $ans_id[$i] ' AND section_id= $checkup_header_val[$h] " ;
}
} else {
if ( $_POST [ 'ans' . $i ] != null or $_POST [ 'ans' . $i ] != " " ) {
$query_initial = " insert into questionnaire_ans " ;
$query_initial ;
$query_end = " " ;
}
}
}
// $query_family_members=$query_initial." set name='".addslashes($_POST['name'.$i])."' ,age='".addslashes($_POST['age'.$i])."', gender='".addslashes($_POST['gender'.$i])."', relation_type='".addslashes($_POST['relation_type'.$i])."',emp_id='$emp_id' ".$query_end;
// echo $query_family_members;
// @mysqli_query($conn,$query_family_members);
} else {
$query_initial = " insert into questionnaire_ans " ;
$query_initial ;
}
// echo $i;
if ( $_POST [ 'ans' . $i ] != null or $_POST [ 'ans' . $i ] != " " ) {
// $query_initial = "update questionnaire_ans ";
// $query_end = "";
$query_que = $query_initial . " set answer=' $ans ' ,que_id=' " . addslashes ( $_POST [ 'que_id' . $i ]) . " ' ,emp_id= $emp_id , modified_by = ' " . $_SESSION [ 'user_id' ] . " ',section_id=' " . $checkup_header_val [ $h ] . " ' " . $query_end ;
//echo $query_que;
@ mysqli_query ( $conn , $query_que );
}
}
$docsData = null ;
$docsQuery = " " ;
if ( count ( $_FILES ) > 0 ) {
$FileType = [
'application/vnd.ms-excel' ,
'text/xls' ,
'text/xlsx' ,
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
];
$_FILES [ 'userfile' ][ 'tmp_name' ];
if ( is_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ])) {
$info = pathinfo ( $_FILES [ 'userfile' ][ 'name' ]);
$fileName = $_FILES [ 'userfile' ][ 'name' ];
2024-11-19 09:59:09 +05:30
if ( is_string ( $fileName )) {
if ( is_string ( $fileName )) {
2024-10-16 19:18:52 +05:30
$position = strpos ( $fileName , " . " );
2024-11-19 09:59:09 +05:30
}
}
2024-10-16 19:18:52 +05:30
$fileextension = substr ( $fileName , $position + 1 );
$fileextension = strtolower ( $fileextension );
/*
* $targetDir = " files/ " ;
* $targetFilePath = $targetDir . $fileName ;
*/
$ext = pathinfo ( $info , PATHINFO_EXTENSION );
$docsData = addslashes ( file_get_contents ( $_FILES [ 'userfile' ][ 'tmp_name' ]));
$docsProperties = getimageSize ( $_FILES [ 'userfile' ][ 'tmp_name' ]);
// if(move_uploaded_file($_FILES["userfile"]["tmp_name"], $targetFilePath)){
$docsQuery = " insert into employee_docs set document=' $docsData ', doc_type=' $fileextension ', doc_name=' $fileName ', emp_id= $id ,modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
@ mysqli_query ( $conn , $docsQuery );
// echo $docsQuery;
// }
}
if ( in_array ( $_FILES [ " userfile " ][ " type " ], $FileType )) {
$targetPath = 'excel/uploads/' . $_FILES [ 'userfile' ][ 'name' ];
move_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ], $targetPath );
$Reader = new SpreadsheetReader ( $targetPath );
$sheetCount = count ( $Reader -> sheets ());
for ( $i = 0 ; $i < $sheetCount ; $i ++ ) {
$Reader -> ChangeSheet ( $i );
foreach ( $Reader as $Row ) {
$question_name = " " ;
if ( isset ( $Row [ 0 ])) {
$question_name = mysqli_real_escape_string ( $conn , $Row [ 0 ]);
}
$question_type = " " ;
if ( isset ( $Row [ 1 ])) {
$question_type = mysqli_real_escape_string ( $conn , $Row [ 1 ]);
}
$question_section_id = " " ;
if ( isset ( $Row [ 2 ])) {
$question_section_id = mysqli_real_escape_string ( $conn , $Row [ 2 ]);
}
if ( ! empty ( $question_name ) || ! empty ( $question_type ) || ! empty ( $question_section_id )) {
$query = " insert into questionnaire(question_name,question_type,question_section_id) values(' " . $question_name . " ',' " . $question_type . " ',' " . $question_section_id . " ') " ;
$result = mysqli_query ( $conn , $query );
if ( ! empty ( $result )) {
$type = " success " ;
$message = " Excel Data Imported into the Database " ;
} else {
$type = " error " ;
$message = " Problem in Importing Excel Data " ;
}
}
}
}
}
$_FILES [ 'userfile' ][ 'tmp_name' ];
if ( is_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ])) {
$info = pathinfo ( $_FILES [ 'userfile' ][ 'name' ]);
$fileName = $_FILES [ 'userfile' ][ 'name' ];
2024-11-19 09:59:09 +05:30
if ( is_string ( $fileName )) {
2024-10-16 19:18:52 +05:30
$position = strpos ( $fileName , " . " );
2024-11-19 09:59:09 +05:30
}
2024-10-16 19:18:52 +05:30
$fileextension = substr ( $fileName , $position + 1 );
$fileextension = strtolower ( $fileextension );
/*
* $targetDir = " files/ " ;
*
* $targetFilePath = $targetDir . $fileName ;
*/
$ext = pathinfo ( $info , PATHINFO_EXTENSION );
$docsData = addslashes ( file_get_contents ( $_FILES [ 'userfile' ][ 'tmp_name' ]));
$docsProperties = getimageSize ( $_FILES [ 'userfile' ][ 'tmp_name' ]);
// if(move_uploaded_file($_FILES["userfile"]["tmp_name"], $targetFilePath)){
$docsQuery = " insert into employee_docs set document=' $docsData ', doc_type=' $fileextension ', doc_name=' $fileName ', emp_id= $id ,modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
@ mysqli_query ( $conn , $docsQuery );
// echo $docsQuery;
// }
}
}
}
}
if ( $data == null ) {
$data [ 'status' ] = 200 ;
// $data['message'] = "Data not found!";
}
echo json_encode ( $emp_id );
?>
< ? php
error_reporting ( E_ERROR | E_PARSE );
include ( 'includes/config/config.php' );
include ( 'includes/functions.php' );
// print_r($_POST);
$id = $_POST [ 'employee_id' ];
$fname = $_POST [ 'fname' ];
$lname = $_POST [ 'lname' ];
$father_name = $_POST [ 'father_name' ];
$dob = $_POST [ 'dob' ];
$doj = $_POST [ 'doj' ];
$designation_id = $_POST [ 'designation_id' ];
$emp_code = $_POST [ 'emp_code' ];
$emp_type_id = $_POST [ 'emp_type_id' ];
$bu_id = $_POST [ 'bu_id' ];
$sbu_id = $_POST [ 'sbu_id' ];
$section_id = $_POST [ 'section_id' ];
$sub_section_id = $_POST [ 'sub_section_id' ];
$mgr_emp_id = $_POST [ 'mgr_emp_id' ];
$gender = $_POST [ 'gender' ];
$address = $_POST [ 'address' ];
$primary_phone = $_POST [ 'primary_phone' ];
$email = $_POST [ 'email' ];
$aadhar_no = $_POST [ 'aadhar_no' ];
$blood_group = $_POST [ 'blood_group' ];
$has_first_aid = $_POST [ 'has_first_aid' ];
if ( $known_health_advices != '' ) {
$known_health_advices = implode ( ',' , $known_health_advices );
$known_health_advices = $known_health_advices . " , " ;
$known_health_advices = addslashes ( $known_health_advices );
// $known_health_advices='ifNull(known_health_advices,)'addslashes($known_health_advices);
} else {
$known_health_advices = " concat(known_health_advices,'') " ;
// /echo $known_health_advices;
}
if ( $known_health_risks != '' ) {
$known_health_risks = implode ( ',' , $known_health_risks );
$known_health_risks = $known_health_risks . " , " ;
$known_health_risks = addslashes ( $known_health_risks );
} else {
$known_health_risks = " concat(known_health_risks,'') " ;
}
// echo $known_health_risks;
// echo $known_health_advices;
$imgData = null ;
$photoQuery = " " ;
if ( count ( $_FILES ) > 0 ) {
$_FILES [ 'photo' ][ 'tmp_name' ];
if ( is_uploaded_file ( $_FILES [ 'photo' ][ 'tmp_name' ])) {
$info = pathinfo ( $_FILES [ 'photo' ][ 'name' ]);
$ext = pathinfo ( $info , PATHINFO_EXTENSION );
$imgData = addslashes ( file_get_contents ( $_FILES [ 'photo' ][ 'tmp_name' ]));
$imageProperties = getimageSize ( $_FILES [ 'photo' ][ 'tmp_name' ]);
$photoQuery = " ,photo=' { $imgData } ' ,image_type=' { $imageProperties [ 'mime' ] } ' " ;
}
}
$data = array ();
$query = " " ;
$emp_id = " " ;
if ( ! empty ( $id )) {
$query = " update employee set fname = ' " . addslashes ( $fname ) . " ', lname = ' " . addslashes ( $lname ) . " ', father_name = ' " . addslashes ( $father_name ) . " ',
dob = STR_TO_DATE ( '" . $_POST[' dob '] . "' , '%d/%m/%Y' ), doj = STR_TO_DATE ( '" . $_POST[' doj '] . "' , '%d/%m/%Y' ), designation_id = '" . addslashes($designation_id) . "' , emp_code = '" . addslashes($emp_code) . "' , employment_type_id = '" . addslashes($emp_type_id) . "' ,
bu_id = '$bu_id' , sbu_id = '$sbu_id' , section_id = '$section_id' , sub_section_id = '$sub_section_id' , mgr_emp_id = '$mgr_emp_id' ,
gender = '$gender' , address = '" . addslashes($address) . "' , primary_phone = '" . addslashes($primary_phone) . "' ,
primary_contact_person = '" . addslashes($primary_contact_person) . "' , primary_contact_no = '" . addslashes($primary_contact_no) . "' ,
known_health_advices = '" . $known_health_advices . "' , known_health_risks = '" . $known_health_risks . "' ,
secondary_contact_person = '" . addslashes($secondary_contact_person) . "' , secondary_contact_no = '" . addslashes($secondary_contact_no) . "' ,
email_id = '" . addslashes($email) . "' , aadhar_no = '" . addslashes($aadhar_no) . "' , is_first_aid = '" . addslashes($has_first_aid) . "' ,
blood_group = '" . addslashes($blood_group) . "' " . $photoQuery . " , modified_by = '" . $_SESSION[' user_id '] . "' where id = " . $id . " " ;
} else {
$query = " insert into employee set fname = ' " . addslashes ( $fname ) . " ', lname = ' " . addslashes ( $lname ) . " ', father_name = ' " . addslashes ( $father_name ) . " '
, dob = STR_TO_DATE ( '" . $_POST[' dob '] . "' , '%d/%m/%Y' ), doj = STR_TO_DATE ( '" . $_POST[' doj '] . "' , '%d/%m/%Y' ),
designation_id = '" . addslashes($designation_id) . "' , emp_code = '" . addslashes($emp_code) . "' , employment_type_id = '" . addslashes($emp_type_id) . "' ,
bu_id = '$bu_id' , sbu_id = '$sbu_id' , section_id = '$section_id' , sub_section_id = '$sub_section_id' , mgr_emp_id = '$mgr_emp_id' ,
gender = '$gender' , address = '" . addslashes($address) . "' , primary_phone = '" . addslashes($primary_phone) . "' , known_health_advices = '" . $known_health_advices . "'
, known_health_risks = '" . $known_health_risks . "' , email_id = '" . addslashes($email) . "' , primary_contact_person = '" . addslashes($primary_contact_person) . "' ,
primary_contact_no = '" . addslashes($primary_contact_no) . "' , secondary_contact_person = '" . addslashes($secondary_contact_person) . "' ,
secondary_contact_no = '" . addslashes($secondary_contact_no) . "' , aadhar_no = '" . addslashes($aadhar_no) . "' , blood_group = '" . addslashes($blood_group) . "' ,
is_first_aid = '" . addslashes($has_first_aid) . "' , " . $photoQuery . "
modified_by = '" . $_SESSION[' user_id '] . "' " ;
}
// echo $query;
// $data['query']=$query;
if ( ! $result = @ mysqli_query ( $conn , $query )) {
$data [ 'status' ] = 500 ;
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
} else {
if ( ! empty ( $id )) {
$emp_id = $id ;
}
else {
$emp_id = @ mysqli_insert_id ();
}
}
if ( ! empty ( $id )) {
$rowCount = $_POST [ 'rowCount' ];
// echo $rowCount;
$select_query_family_members = " select id from emp_family_members where emp_id= $id " ;
// echo $select_query_family_members;
$result_family_members = @ mysqli_query ( $conn , $select_query_family_members );
$rows_family_members = @ mysqli_num_rows ( $result_family_members );
$members_id = array ();
$count = 0 ;
while ( $row_members = @ mysqli_fetch_assoc ( $result_family_members )) {
$members_id [ $count ] = $row_members [ 'id' ];
$count ++ ;
}
$query_initial = " " ;
$query_end = " " ;
for ( $i = 0 ; $i < $rowCount ; $i ++ ) {
if ( $rows_family_members > 0 ) {
if ( $rows_family_members == $rowCount ) {
$query_initial = " update emp_family_members " ;
$query_end = " where id=' $members_id[$i] ' " ;
} elseif ( $rows_family_members < $rowCount ) {
if ( $i < $rows_family_members ) {
$query_initial = " update emp_family_members " ;
$query_end = " where id=' $members_id[$i] ' " ;
} else {
$query_initial = " insert into emp_family_members " ;
$query_end = " " ;
}
}
// $query_family_members=$query_initial." set name='".addslashes($_POST['name'.$i])."' ,age='".addslashes($_POST['age'.$i])."', gender='".addslashes($_POST['gender'.$i])."', relation_type='".addslashes($_POST['relation_type'.$i])."',emp_id='$emp_id' ".$query_end;
// echo $query_family_members;
// @mysqli_query($conn,$query_family_members);
} else {
$query_initial = " insert into emp_family_members " ;
// echo $query_initial;
}
// echo $i;
$query_family_members = $query_initial . " set name=' " . addslashes ( $_POST [ 'name' . $i ]) . " ' ,age=' " . addslashes ( $_POST [ 'age' . $i ]) . " ', gender=' " . addslashes ( $_POST [ 'gender' . $i ]) . " ', relation_type=' " . addslashes ( $_POST [ 'relation_type' . $i ]) . " ',emp_id= $emp_id " . $query_end ;
// echo $query_family_members;
@ mysqli_query ( $conn , $query_family_members );
}
$checkup_header_val = explode ( ',' , $_POST [ 'checkup_header_val' ]);
// echo $_POST['checkup_header_val'];
//echo count($checkup_header_val);
for ( $h = 0 ; $h < count ( $checkup_header_val ); $h ++ ) {
$querowCount = $_POST [ 'querowCount' ];
// echo $querowCount;
$select_query_que = " select ans_id from questionnaire_ans where emp_id= $id AND section_id= $checkup_header_val[$h] " ;
// echo $select_query_que;
$result_que = @ mysqli_query ( $conn , $select_query_que );
$rows_que = @ mysqli_num_rows ( $result_que );
$ans_id = array ();
$count = 0 ;
while ( $row_questions = @ mysqli_fetch_assoc ( $result_que )) {
$ans_id [ $count ] = $row_questions [ 'ans_id' ];
$count ++ ;
}
$select_query_child_que = " select ans_id from questionnaire_ans where emp_id= $id AND section_id is null " ;
//echo $select_query_child_que;
$result_child_que = @ mysqli_query ( $conn , $select_query_child_que );
$rows_child_que = @ mysqli_num_rows ( $result_child_que );
$child_ans_id = array ();
$count_child = 0 ;
while ( $row_child_questions = @ mysqli_fetch_assoc ( $result_child_que )) {
$child_ans_id [ $count_child ] = $row_child_questions [ 'ans_id' ];
$count_child ++ ;
}
// print_r($child_ans_id);
$query_initial = " " ;
$query_end = " " ;
for ( $i = 0 ; $i < $querowCount ; $i ++ ) {
$que_id = $_POST [ 'que_id' . $i ];
$childQuesQuery = " select * from questionnaire where parentId = ' $que_id ' " ;
// echo $i." ".$childQuesQuery."<br>";
$childQueResult = @ mysqli_query ( $conn , $childQuesQuery );
$numQuesRows = @ mysqli_num_rows ( $childQueResult );
// echo $childQuesQuery." ".$numQuesRows."<br>";
if ( $numQuesRows != 0 ) {
while ( $rowChildQue = @ mysqli_fetch_array ( $childQueResult )) {
$childQueId = $rowChildQue [ 'question_id' ];
// echo $childQueId."<br>";
if ( $rows_child_que > 0 ) {
// echo $rows_child_que;
if ( $_POST [ $childQueId . 'ans' . $i ] == null or $_POST [ $childQueId . 'ans' . $i ] == " " ) {
$query_child_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $child_ans_id[0] '; " ;
// echo $query_child_delete;
@ mysqli_query ( $conn , $query_child_delete );
} else {
$query_child_initial = " update questionnaire_ans " ;
$query_child_end = " where ans_id=' $child_ans_id[$i] ' " ;
}
if ( $i < $rows_que ) {
if ( $_POST [ $childQueId . 'ans' . $i ] == null or $_POST [ $childQueId . 'ans' . $i ] == " " ) {
$query_child_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $child_ans_id[$i] '; " ;
// echo "<br>".$query_child_delete;
@ mysqli_query ( $conn , $query_child_delete );
} else {
$query_child_initial = " update questionnaire_ans " ;
$query_child_end = " where ans_id=' $child_ans_id[$i] ' " ;
}
} else {
if ( $_POST [ $childQueId . 'ans' . $i ] != null or $_POST [ $childQueId . 'ans' . $i ] != " " ) {
$query_child_initial = " insert into questionnaire_ans " ;
$query_child_end = " " ;
}
}
// $query_family_members=$query_initial." set name='".addslashes($_POST['name'.$i])."' ,age='".addslashes($_POST['age'.$i])."', gender='".addslashes($_POST['gender'.$i])."', relation_type='".addslashes($_POST['relation_type'.$i])."',emp_id='$emp_id' ".$query_end;
// echo $query_family_members;
// @mysqli_query($conn,$query_family_members);
} else {
$query_child_initial = " insert into questionnaire_ans " ;
}
// echo $i;
if ( $_POST [ $childQueId . 'ans' . $i ] != null or $_POST [ $childQueId . 'ans' . $i ] != " " ) {
$ans = $_POST [ $childQueId . 'ans' . $i ];
$query_child_que = $query_child_initial . " set answer=' $ans ' ,que_id=' " . addslashes ( $_POST [ $childQueId . 'que_id' . $i ]) . " ' ,emp_id= $emp_id , modified_by = ' " . $_SESSION [ 'user_id' ] . " ' " . $query_child_end ;
//echo $query_child_que . "<br>";
@ mysqli_query ( $conn , $query_child_que );
}
}
}
$que_id = $_POST [ 'que_id' . $i ];
$QuesQuery = " select requiredDetailsIds from questionnaire where question_id = ' $que_id ' " ;
// echo $i." ".$childQuesQuery."<br>";
$QueResult = @ mysqli_query ( $conn , $QuesQuery );
$quesRows = @ mysqli_fetch_array ( $QueResult );
$ans = " " ;
if ( $_POST [ 'ans' . $i ] != null or $_POST [ 'ans' . $i ] != " " ) {
$requiredDetails = $quesRows [ 'requiredDetailsIds' ];
//echo $requiredDetails;
$requiredDetailsArr = explode ( " , " , $requiredDetails );
$ans = $_POST [ 'ans' . $i ] . " : " ;
foreach ( $requiredDetailsArr as $requiredDetailsIdsArrval ) {
$requiredDetailsArrval = getTableFieldValue ( 'question_sub_details' , 'sub_detail_name' , 'sub_detail_id' , $requiredDetailsIdsArrval );
$ans = $ans . " , " . $requiredDetailsArrval . " : " . $_POST [ $requiredDetailsArrval . $i ];
}
}
// echo "que row".$rows_que;
if ( $rows_que > 0 ) {
if ( $rows_que == $querowCount ) {
if ( $_POST [ 'ans' . $i ] == null or $_POST [ 'ans' . $i ] == " " ) {
$query_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $ans_id[$i] ' AND section_id= $checkup_header_val[$h] ; " ;
// echo $query_delete;
@ mysqli_query ( $conn , $query_delete );
}
else {
$query_initial = " update questionnaire_ans " ;
// echo $query_initial;
$query_end = " where ans_id=' $ans_id[$i] ' " ;
}
} elseif ( $rows_que < $querowCount ) {
if ( $i < $rows_que ) {
if ( $_POST [ 'ans' . $i ] == null or $_POST [ 'ans' . $i ] == " " ) {
$query_delete = " DELETE FROM questionnaire_ans WHERE ans_id=' $ans_id[$i] ' AND section_id= $checkup_header_val[$h] ; " ;
// echo $query_delete;
@ mysqli_query ( $conn , $query_delete );
}
else {
$query_initial = " update questionnaire_ans " ;
$query_end = " where ans_id=' $ans_id[$i] ' AND section_id= $checkup_header_val[$h] " ;
}
} else {
if ( $_POST [ 'ans' . $i ] != null or $_POST [ 'ans' . $i ] != " " ) {
$query_initial = " insert into questionnaire_ans " ;
$query_initial ;
$query_end = " " ;
}
}
}
// $query_family_members=$query_initial." set name='".addslashes($_POST['name'.$i])."' ,age='".addslashes($_POST['age'.$i])."', gender='".addslashes($_POST['gender'.$i])."', relation_type='".addslashes($_POST['relation_type'.$i])."',emp_id='$emp_id' ".$query_end;
// echo $query_family_members;
// @mysqli_query($conn,$query_family_members);
} else {
$query_initial = " insert into questionnaire_ans " ;
$query_initial ;
}
// echo $i;
if ( $_POST [ 'ans' . $i ] != null or $_POST [ 'ans' . $i ] != " " ) {
// $query_initial = "update questionnaire_ans ";
// $query_end = "";
$query_que = $query_initial . " set answer=' $ans ' ,que_id=' " . addslashes ( $_POST [ 'que_id' . $i ]) . " ' ,emp_id= $emp_id , modified_by = ' " . $_SESSION [ 'user_id' ] . " ',section_id=' " . $checkup_header_val [ $h ] . " ' " . $query_end ;
//echo $query_que;
@ mysqli_query ( $conn , $query_que );
}
}
$docsData = null ;
$docsQuery = " " ;
if ( count ( $_FILES ) > 0 ) {
$FileType = [
'application/vnd.ms-excel' ,
'text/xls' ,
'text/xlsx' ,
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
];
$_FILES [ 'userfile' ][ 'tmp_name' ];
if ( is_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ])) {
$info = pathinfo ( $_FILES [ 'userfile' ][ 'name' ]);
$fileName = $_FILES [ 'userfile' ][ 'name' ];
2024-11-19 09:59:09 +05:30
if ( is_string ( $fileName )) {
2024-10-16 19:18:52 +05:30
$position = strpos ( $fileName , " . " );
2024-11-19 09:59:09 +05:30
}
2024-10-16 19:18:52 +05:30
$fileextension = substr ( $fileName , $position + 1 );
$fileextension = strtolower ( $fileextension );
/*
* $targetDir = " files/ " ;
* $targetFilePath = $targetDir . $fileName ;
*/
$ext = pathinfo ( $info , PATHINFO_EXTENSION );
$docsData = addslashes ( file_get_contents ( $_FILES [ 'userfile' ][ 'tmp_name' ]));
$docsProperties = getimageSize ( $_FILES [ 'userfile' ][ 'tmp_name' ]);
// if(move_uploaded_file($_FILES["userfile"]["tmp_name"], $targetFilePath)){
$docsQuery = " insert into employee_docs set document=' $docsData ', doc_type=' $fileextension ', doc_name=' $fileName ', emp_id= $id ,modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
@ mysqli_query ( $conn , $docsQuery );
// echo $docsQuery;
// }
}
if ( in_array ( $_FILES [ " userfile " ][ " type " ], $FileType )) {
$targetPath = 'excel/uploads/' . $_FILES [ 'userfile' ][ 'name' ];
move_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ], $targetPath );
$Reader = new SpreadsheetReader ( $targetPath );
$sheetCount = count ( $Reader -> sheets ());
for ( $i = 0 ; $i < $sheetCount ; $i ++ ) {
$Reader -> ChangeSheet ( $i );
foreach ( $Reader as $Row ) {
$question_name = " " ;
if ( isset ( $Row [ 0 ])) {
$question_name = mysqli_real_escape_string ( $conn , $Row [ 0 ]);
}
$question_type = " " ;
if ( isset ( $Row [ 1 ])) {
$question_type = mysqli_real_escape_string ( $conn , $Row [ 1 ]);
}
$question_section_id = " " ;
if ( isset ( $Row [ 2 ])) {
$question_section_id = mysqli_real_escape_string ( $conn , $Row [ 2 ]);
}
if ( ! empty ( $question_name ) || ! empty ( $question_type ) || ! empty ( $question_section_id )) {
$query = " insert into questionnaire(question_name,question_type,question_section_id) values(' " . $question_name . " ',' " . $question_type . " ',' " . $question_section_id . " ') " ;
$result = mysqli_query ( $conn , $query );
if ( ! empty ( $result )) {
$type = " success " ;
$message = " Excel Data Imported into the Database " ;
} else {
$type = " error " ;
$message = " Problem in Importing Excel Data " ;
}
}
}
}
}
$_FILES [ 'userfile' ][ 'tmp_name' ];
if ( is_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ])) {
$info = pathinfo ( $_FILES [ 'userfile' ][ 'name' ]);
$fileName = $_FILES [ 'userfile' ][ 'name' ];
2024-11-19 09:59:09 +05:30
if ( is_string ( $fileName )) {
2024-10-16 19:18:52 +05:30
$position = strpos ( $fileName , " . " );
2024-11-19 09:59:09 +05:30
}
2024-10-16 19:18:52 +05:30
$fileextension = substr ( $fileName , $position + 1 );
$fileextension = strtolower ( $fileextension );
/*
* $targetDir = " files/ " ;
*
* $targetFilePath = $targetDir . $fileName ;
*/
$ext = pathinfo ( $info , PATHINFO_EXTENSION );
$docsData = addslashes ( file_get_contents ( $_FILES [ 'userfile' ][ 'tmp_name' ]));
$docsProperties = getimageSize ( $_FILES [ 'userfile' ][ 'tmp_name' ]);
// if(move_uploaded_file($_FILES["userfile"]["tmp_name"], $targetFilePath)){
$docsQuery = " insert into employee_docs set document=' $docsData ', doc_type=' $fileextension ', doc_name=' $fileName ', emp_id= $id ,modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
@ mysqli_query ( $conn , $docsQuery );
// echo $docsQuery;
// }
}
}
}
}
if ( $data == null ) {
$data [ 'status' ] = 200 ;
// $data['message'] = "Data not found!";
}
echo json_encode ( $emp_id );
?>