MMCT TEAM
Server IP : 103.53.40.154  /  Your IP : 3.147.47.177
Web Server : Apache
System : Linux md-in-35.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : ppcad7no ( 715)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home2/ppcad7no/sssktrust.com/../shsindia.com/crm/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/ppcad7no/sssktrust.com/../shsindia.com/crm/edit-empolyee.php
<?php
include_once('include/config.php');
if (!isLoggedIn()) {
    $_SESSION['msg'] = "You must log in first";
    header('location: login.php');
}
if (!isAdmin()) {
    $_SESSION['msg'] = "You are not Admin";
    header('location: login.php');
}
if(isset($_POST['update_employee'])) {
    date_default_timezone_set('Asia/Kolkata');
    
    $emp_id = $_POST['id'];

    $emp_name = $_POST['emp_name'];
    $emp_father = $_POST['emp_father'];
    $emp_dob = $_POST['emp_dob'];
    $emp_number = $_POST['emp_number'];
    $emp_alt_number = $_POST['emp_alt_number'];
    $emp_emergency_number = $_POST['emp_emergency_number'];
    $emp_email = $_POST['emp_email'];
    $emp_address = htmlspecialchars($_POST['emp_address'], ENT_QUOTES);
    $permanent_address = htmlspecialchars($_POST['permanent_address'], ENT_QUOTES);
    $emp_family_detail = htmlspecialchars($_POST['emp_family_detail'], ENT_QUOTES);
    $emp_nominee_name = $_POST['emp_nominee_name'];
    $emp_nominee_relation = $_POST['emp_nominee_relation'];
    $emp_nominee_phone = $_POST['emp_nominee_phone'];
    $emp_bank_name = $_POST['emp_bank_name'];
    $emp_account_no = $_POST['emp_account_no'];
    $emp_ifsc = $_POST['emp_ifsc'];
    $emp_branch = $_POST['emp_branch'];
    $maritul_status = $_POST['maritul_status'];
    $emp_code = $_POST['emp_code'];
    $emp_pf_no = $_POST['emp_pf_no'];
    $emp_esic_no = $_POST['emp_esic_no'];
    $emp_uan_no = $_POST['emp_uan_no'];
    $emp_doj = $_POST['emp_doj'];
    $emp_supervisor_id = $_POST['emp_supervisor_id'];
    $emp_status = 'Active';
    $sk_id = isset($_POST['sk_id']) ? implode(',', $_POST['sk_id']) : '';

    // Handle image uploads
    $allowed_extensions = ['jpg', 'jpeg', 'png'];

    // Check and upload emp_photo
    if($_FILES['emp_photo']['name'] != '') {
        $emp_photo_extension = pathinfo($_FILES['emp_photo']['name'], PATHINFO_EXTENSION);
        if (in_array($emp_photo_extension, $allowed_extensions)) {
            $emp_photo_new_name = 'emp_photo_' . date('YmdHis') . '.' . $emp_photo_extension;
            move_uploaded_file($_FILES['emp_photo']['tmp_name'], 'images/employee/' . $emp_photo_new_name);
        } else {
            die("Invalid emp_photo file format. Allowed formats are jpg, jpeg, png");
        }
    }

    // Check and upload emp_aadhar_front
    if($_FILES['emp_aadhar_front']['name'] != '') {
        $aadhar_front_extension = pathinfo($_FILES['emp_aadhar_front']['name'], PATHINFO_EXTENSION);
        if (in_array($aadhar_front_extension, $allowed_extensions)) {
            $aadhar_front_new_name = 'emp_aadhar_front_' . date('YmdHis') . '.' . $aadhar_front_extension;
            move_uploaded_file($_FILES['emp_aadhar_front']['tmp_name'], 'images/employee/' . $aadhar_front_new_name);
        } else {
            die("Invalid emp_aadhar_front file format. Allowed formats are jpg, jpeg, png");
        }
    }
    
    // Check and upload emp_aadhar_back
    if($_FILES['emp_aadhar_back']['name'] != '') {
        $aadhar_back_extension = pathinfo($_FILES['emp_aadhar_back']['name'], PATHINFO_EXTENSION);
        if (in_array($aadhar_back_extension, $allowed_extensions)) {
            $aadhar_back_new_name = 'emp_aadhar_back_' . date('YmdHis') . '.' . $aadhar_back_extension;
            move_uploaded_file($_FILES['emp_aadhar_back']['tmp_name'], 'images/employee/' . $aadhar_back_new_name);
        } else {
            die("Invalid emp_aadhar_back file format. Allowed formats are jpg, jpeg, png");
        }
    }
    
    // Check and upload emp_elec_card
    if($_FILES['emp_elec_card']['name']!='') {
        $emp_elec_card = pathinfo($_FILES['emp_elec_card']['name'], PATHINFO_EXTENSION);
        if (in_array($emp_elec_card, $allowed_extensions)) {
            $emp_elec_card_new_name = 'emp_elec_card_' . date('YmdHis') . '.' . $emp_elec_card;
            move_uploaded_file($_FILES['emp_elec_card']['tmp_name'], 'images/employee/' . $emp_elec_card_new_name);
        } else {
            die("Invalid emp_elec_card file format. Allowed formats are jpg, jpeg, png");
        }
    }
    
    // Check and upload emp_pancard
    if($_FILES['emp_pancard']['name'] != '') {
        $pancard_extension = pathinfo($_FILES['emp_pancard']['name'], PATHINFO_EXTENSION);
        if (in_array($pancard_extension, $allowed_extensions)) {
            $pancard_new_name = 'emp_pancard_' . date('YmdHis') . '.' . $pancard_extension;
            move_uploaded_file($_FILES['emp_pancard']['tmp_name'], 'images/employee/' . $pancard_new_name);
        } else {
            die("Invalid emp_pancard file format. Allowed formats are jpg, jpeg, png");
        }
    }

    // Construct the SQL update query
    $sql = "UPDATE `tbl_employee` SET 
            `emp_name`='$emp_name', 
            `emp_father`='$emp_father', 
            `emp_dob`='$emp_dob', 
            `emp_number`='$emp_number', 
            `emp_alt_number`='$emp_alt_number', 
            `emp_emergency_number`='$emp_emergency_number', 
            `emp_email`='$emp_email', 
            `emp_address`='$emp_address', 
            `permanent_address`='$permanent_address', 
            `emp_family_detail`='$emp_family_detail', 
            `maritul_status`='$maritul_status', 
            `emp_code`='$emp_code', 
            `emp_pf_no`='$emp_pf_no', 
            `emp_esic_no`='$emp_esic_no', 
            `emp_uan_no`='$emp_uan_no', 
            `emp_doj`='$emp_doj', 
            `skill_id`='$sk_id', 
            `emp_supervisor_id`='$emp_supervisor_id', 
            `emp_nominee_name`='$emp_nominee_name', 
            `emp_nominee_relation`='$emp_nominee_relation', 
            `emp_nominee_phone`='$emp_nominee_phone', 
            `emp_bank_name`='$emp_bank_name', 
            `emp_account_no`='$emp_account_no', 
            `emp_ifsc`='$emp_ifsc', 
            `emp_branch`='$emp_branch'";

    // Add image fields only if they are updated
    if(isset($emp_photo_new_name))
        $sql .= ", `emp_photo`='$emp_photo_new_name'";
    if(isset($aadhar_front_new_name))
        $sql .= ", `emp_aadhar_front`='$aadhar_front_new_name'";
    if(isset($aadhar_back_new_name))
        $sql .= ", `emp_aadhar_back`='$aadhar_back_new_name'";
    if(isset($pancard_new_name))
        $sql .= ", `emp_pancard`='$pancard_new_name'";
        
    if(isset($emp_elec_card_new_name))
        $sql .= ", `emp_elec_card`='$emp_elec_card_new_name'";

    // Close the SQL query with WHERE clause for the specific employee ID
    $sql .= " WHERE `emp_id`='$emp_id'";
    
    $result = mysqli_query($db, $sql) or die("Query unsuccessful");

    if($result){
        echo ("<script>
        window.alert('Successfully Updated');
        window.location.href='manage-employee.php';
        </script>");
        mysqli_close($db);
    } else {
        echo "Error";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
    
<head>
    <?php include "top-links.php";?>
</head>

    <body>
        <!-- Begin page -->
        <div class="wrapper">

            <?php include "header.php";?>

            <?php include "sidebar.php";?>
            
              <div class="content-page">
                <div class="content">

                    <!-- Start Content-->
                    
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h4 class="header-title mb-0"> Edit Empolyee</h4>
                                    </div>
                                    <div class="card-body">
                                        <?php
                                            $id=$_GET['id'];
                                            $sql = "SELECT * FROM `tbl_employee` WHERE emp_id =$id";
                                            $run = mysqli_query($db,$sql) or die("Query Not run");
                                            $data = mysqli_fetch_assoc($run);
                                        ?>
                                        <form action="<?php $_PHP_SELF?>" method="POST" enctype="multipart/form-data">
                                            <div id="basicwizard">
                                                <div class=" b-0 mb-0">
                                                    <div >
                                                        <div class="row">
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Empolyee Name</label>
                                                                <div>
                                                                    <input type="hidden" name="id" value="<?php echo $data['emp_id']?>">
                                                                    <input type="text" class="form-control" id="userName" name="emp_name" placeholder="Empolyee Name" value="<?php echo $data['emp_name']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Father/Husband Name</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_father" placeholder="Father name" value="<?php echo $data['emp_father']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">DOB</label>
                                                                <div>
                                                                    <input type="date" class="form-control" id="userName" name="emp_dob" value="<?php echo $data['emp_dob']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Phone Number</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_number" placeholder="Phone Number" value="<?php echo $data['emp_number']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Alt Phone</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_alt_number" value="<?php echo $data['emp_alt_number']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Emergency Number</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_emergency_number" value="<?php echo $data['emp_emergency_number']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Email</label>
                                                                <div>
                                                                    <input type="email" class="form-control" id="userName" name="emp_email" value="<?php echo $data['emp_email']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                                <label class="" for="maritul_status">Marital Status</label>
                                                                <select class="form-select" id="example-select" name="maritul_status">
                                                                    <option value="Un Married"<?php if ($data['maritul_status'] == "Un Married") echo " selected"; ?>>Un Married</option>
                                                                    <option value="Married"<?php if ($data['maritul_status'] == "Married") echo " selected"; ?>>Married</option>
                                                                </select>
                                                            </div>
                                                            
                                                            <div class="col-md-4 mb-3">
                                                                <label class="" for="emp_supervisor_id">Assign Supervisor</label>
                                                                <select class="form-select" id="example-select" name="emp_supervisor_id">
                                                                    <option value="0">Select Supervisor</option>
                                                                    <?php
                                                                       $selected_manager_id = $data['emp_supervisor_id'];
                                                                       $sqlsup = "SELECT * FROM `login_tbl` WHERE user_type='Supervisor' AND user_status='Active'";
                                                                       $runsup = mysqli_query($db, $sqlsup) or die("Query Not run");
                                                                       while($datasup = mysqli_fetch_assoc($runsup)){
                                                                           $selected = ($datasup['id'] == $selected_manager_id) ? 'selected="selected"' : '';
                                                                           echo "<option value='{$datasup['id']}' $selected>{$datasup['name']}</option>";
                                                                       }
                                                                    ?>
                                                                </select>
                                                            </div>
                                                            
                                                            <div class="col-md-6 mb-3">
                                                                <div>
                                                                    <label class="form-label" for="userName">Local Address</label>
                                                                    <textarea class="form-control" name="emp_address" id="example-textarea" rows="3"><?php echo $data['emp_address']; ?></textarea>
                                                                </div>
                                                            </div>
                                                            
                                                            <!-- Permanent Address -->
                                                            <div class="col-md-6 mb-3">
                                                                <div>
                                                                    <label for="example-textarea" class="form-label">Permanent Address</label>
                                                                    <textarea class="form-control" name="permanent_address" id="example-textarea" rows="3"><?php echo $data['permanent_address']; ?></textarea>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-12 mb-3">
                                                                <div>
                                                                    <label for="example-textarea" class="form-label">Family Details</label>
                                                                    <textarea class="form-control" name="emp_family_detail" id="example-textarea" rows="3"><?php echo $data['emp_family_detail']; ?></textarea>
                                                                </div>
                                                            </div>
                                                            <!-- Employment Skills -->
                                                            <div class="card-header">
                                                                <h4 class="header-title">Employment Skills</h4>
                                                            </div>
                                                            <div class="row pt-2 pb-2">
                                                                <div class="col">
                                                                    <label>Choose Employment Skills</label>
                                                                    <div style="display:flex;flex-wrap:wrap;">
                                                                        <?php
                                                                            $sqlsp = "SELECT * FROM `tbl_emp_skills` WHERE skill_status='Active'";
                                                                            $runsp = mysqli_query($db, $sqlsp) or die("Query Not run");
                                                                            $submitted_spots_ids = array();
                                                                            $service_id = $_GET['id'];
                                                                            $sql_check_submission = "SELECT skill_id FROM `tbl_employee` WHERE emp_id = $service_id";
                                                                            $run_check_submission = mysqli_query($db, $sql_check_submission) or die("Query Not run");
                                                                            while ($row_check_submission = mysqli_fetch_assoc($run_check_submission)) {
                                                                                $submitted_spots_ids = explode(',', $row_check_submission['skill_id']);
                                                                            }
                                                                            while ($datasp = mysqli_fetch_assoc($runsp)) {
                                                                                $spot_id = $datasp['sk_id'];
                                                                                $checked = (!empty($submitted_spots_ids) && in_array($spot_id, $submitted_spots_ids)) ? 'checked' : '';
                                                                        ?>
                                                                            <p style="padding-left:10px;"><input type="checkbox" name="sk_id[]" value='<?php echo $spot_id; ?>' <?php echo $checked; ?>> <?php echo $datasp['skill_name']; ?></p>
                                                                        <?php
                                                                        } 
                                                                        ?>
                                                            
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <!-- Employment Identification -->
                                                            <div class="card-header">
                                                                <h4 class="header-title">Employment Identification</h4>
                                                            </div>
                                                            
                                                            <!-- Employee Code Number -->
                                                            <div class="col-md-4 mb-3">
                                                                <label class="" for="userName">Employee Code Number</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_code" value="<?php echo $data['emp_code']; ?>">
                                                                </div>
                                                            </div>
                                                            
                                                            <!-- PF Number -->
                                                            <div class="col-md-4 mb-3">
                                                                <label class="" for="userName">PF Number</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_pf_no" value="<?php echo $data['emp_pf_no']; ?>">
                                                                </div>
                                                            </div>
                                                            
                                                            <!-- ESIC Number -->
                                                            <div class="col-md-4 mb-3">
                                                                <label class="" for="userName">ESIC Number</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_esic_no" value="<?php echo $data['emp_esic_no']; ?>">
                                                                </div>
                                                            </div>
                                                            
                                                            <!-- UAN Number -->
                                                            <div class="col-md-6 mb-3">
                                                                <label class="" for="userName">UAN Number</label>
                                                                <div>
                                                                    <input type="text" class="form-control" id="userName" name="emp_uan_no" value="<?php echo $data['emp_uan_no']; ?>">
                                                                </div>
                                                            </div>
                                                            
                                                            <!-- Date Of Joining (DOJ) -->
                                                            <div class="col-md-6 mb-3">
                                                                <label class="" for="userName">Date Of Joining (DOJ)</label>
                                                                <div>
                                                                    <input type="date" class="form-control" id="userName" name="emp_doj" value="<?php echo $data['emp_doj']; ?>">
                                                                </div>
                                                            </div>
                                                            
                                                            <div class="card-header">
                                                                <h4 class="header-title">Images</h4>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Profile Photo</label>
                                                                <div>
                                                                    <input type="file"  class="form-control" id="userName" name="emp_photo" placeholder="image">
                                                                    <img src="images/employee/<?php echo $data['emp_photo']; ?>" width="60px" alt="image">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Aadhar Card(Front)</label>
                                                                <div>
                                                                    <input type="file"  class="form-control" id="userName" name="emp_aadhar_front" placeholder="image">
                                                                    <img src="images/employee/<?php echo $data['emp_aadhar_front']; ?>" width="60px" alt="image">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Aadhar Card(Back)</label>
                                                                <div>
                                                                    <input type="file"  class="form-control" id="userName" name="emp_aadhar_back" placeholder="image">
                                                                    <img src="images/employee/<?php echo $data['emp_aadhar_back']; ?>" width="60px" alt="image">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Pan Card</label>
                                                                <div>
                                                                    <input type="file"  class="form-control" id="userName" name="emp_pancard" placeholder="image">
                                                                    <img src="images/employee/<?php echo $data['emp_pancard']; ?>" width="60px" alt="image">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Election Card</label>
                                                                <div>
                                                                    <input type="file"  class="form-control" id="userName" name="emp_elec_card" placeholder="image">
                                                                    <img src="images/employee/<?php echo $data['emp_elec_card']; ?>" width="60px" alt="image">
                                                                </div>
                                                            </div>
                                                            <div class="card-header">
                                                                <h4 class="header-title">Nominee Details</h4>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Nominee Name</label>
                                                                <div>
                                                                    <input type="text"  class="form-control" id="userName" name="emp_nominee_name" value="<?php echo $data['emp_nominee_name']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Nominee Relation</label>
                                                                <div>
                                                                    <input type="text"  class="form-control" id="userName" name="emp_nominee_relation" value="<?php echo $data['emp_nominee_relation']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Nominee Phone</label>
                                                                <div>
                                                                    <input type="text"  class="form-control" id="userName" name="emp_nominee_phone" value="<?php echo $data['emp_nominee_phone']?>">
                                                                </div>
                                                            </div>
                                                            <div class="card-header">
                                                                <h4 class="header-title">Bank Details</h4>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Bank Name</label>
                                                                <div>
                                                                    <input type="text"  class="form-control" id="userName" name="emp_bank_name" value="<?php echo $data['emp_bank_name']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Account Number</label>
                                                                <div>
                                                                    <input type="text"  class="form-control" id="userName" name="emp_account_no" value="<?php echo $data['emp_account_no']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">Branch Name</label>
                                                                <div>
                                                                    <input type="text"  class="form-control" id="userName" name="emp_branch" value="<?php echo $data['emp_branch']?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-4 mb-3">
                                                               <label class="" for="userName">IFSC Code</label>
                                                                <div>
                                                                    <input type="text"  class="form-control" id="userName" name="emp_ifsc" value="<?php echo $data['emp_ifsc']?>">
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <ul class="list-inline wizard mb-0">
                                                            <li class="next list-inline-item float-end">
                                                                <button class="btn btn-info" name="update_employee" type="submit">Update <i class="ri-arrow-right-line ms-1"></i></button>
                                                            </li>
                                                        </ul>
                                                    </div>
                                                </div> 
                                            </div> 
                                        </form>
                                    </div> 
                                </div> 
                            </div>
                        </div> 
                    </div>
                    </div>
                    </div>
        </div>
        
        <?php include "footer.php";?>
        
    </body>

</html> 

MMCT - 2023