<?php
include('connection.php');

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
    $first_name = $_POST['first_name'];
    $marital_status = $_POST['marital_status'];
    $email = $_POST['email'];
    $number = $_POST['number'];
    $profile = $_POST['profile'];
    $experience = $_POST['experience'];
    $location = $_POST['location'];
    $salary_expectations = $_POST['salary_expectations'];
    $linkedin_username = $_POST['linkedin_username'];
    $whatsapp_username = $_POST['whatsapp_username'];
 
    $currentDate = date('Y-m-d');

    // File Upload
    $upload_directory = "uploads/";
    $resume_file_name = $_FILES['file']['name'];
    $resume_file_tmp = $_FILES['file']['tmp_name'];
    $resume_file_path = $upload_directory . uniqid() . "_" . $resume_file_name;

    if (move_uploaded_file($resume_file_tmp, $resume_file_path)) {
        // Database Insertion
        $linkedin_url = "https://www.linkedin.com/in/";
        $whatsapp_url = "https://wa.me/+";
        $sql = "INSERT INTO add_resume (full_name, marital_status, email, number, work_profile, work_experience, location, linkedin, whatsapp_username, resume, salary_expectations, date)
            VALUES ('$first_name', '$marital_status', '$email', '$number', '$profile', '$experience', '$location', '$linkedin_url$linkedin_username','$whatsapp_url$whatsapp_username', '$resume_file_path','$salary_expectations', '$currentDate')";
        $result = mysqli_query($conn, $sql);
        if ($result) {
            header("Location: resume-add-new.php?success=Resume Added Successfully!!!");
            exit(); 
        } else {
            header("Location: resume-add-new.php?error=Something Went Wrong!!!");
            exit(); 
        }
    } else {
        header("Location: resume-add-new.php?error=File Upload Failed!!!");
        exit(); 
    }
}
?>