<?php

require "includes/mysql_database_connection.php";
require "includes/projects_management_function.php";
include "includes/cv_management_function.php";
include "includes/profile_management_function.php";
include "includes/session.php";
include "includes/util.php";
redirectToHTTPS();
if (isset($_GET['selectedSearchedUsername'])) {
    $searchedUsername = urldecode($_GET['selectedSearchedUsername']);
    if (hasProfileDetailsByUsername($searchedUsername)) {
        $userProfilePicturePath = getProfilePicturePathByUsername($searchedUsername);
        $selectedUserProfileDetails = getProfileDetailsByUsername($searchedUsername);
        $selectedUserEmail = $selectedUserProfileDetails["email"];
        $selectedUserFirstName = $selectedUserProfileDetails["first_name"];
        $selectedUserLastName = $selectedUserProfileDetails["last_name"];
        $selectedUserGender = $selectedUserProfileDetails["gender"];
        $selectedUserAddress1 = $selectedUserProfileDetails["address_line1"];
        if (isset($userProfileDetails["address_line2"])) {
            $selectedUserAddress2 = $userProfileDetails["address_line2"];
        } else {
            $selectedUserAddress2 = "";
        }
        $selectedUserCountry = $selectedUserProfileDetails["country"];
        if (isset($userProfileDetails["contact_number"])) {
            $selectedUserContactNumber = $userProfileDetails["contact_number"];
        } else {
            $selectedUserContactNumber = "";
        }
        $cvFilePath = getCVPathByUsername($searchedUsername);
require "includes/util.php";
require "includes/country_list.php";
redirectToHTTPS();
if (isset($_SESSION['username'])) {
    $username = $_SESSION['username'];
    if (isset($_POST['profileSubmit'])) {
        $firstname = $_POST['firstname'];
        $lastname = $_POST['lastname'];
        $gender = $_POST['gender'];
        $address1 = $_POST['address1'];
        $address2 = $_POST['address2'];
        $country = $_POST['country'];
        $contactnumber = $_POST['contactnumber'];
        $updateProfileResponse = updateProdileDetails($username, $firstname, $lastname, $gender, $address1, $address2, $country, $contactnumber);
    }
    $userProfileDetails = getProfileDetailsByUsername($username);
    if (isset($userProfileDetails)) {
        $userFirstName = $userProfileDetails["first_name"];
        $userLastName = $userProfileDetails["last_name"];
        $gender = $userProfileDetails["gender"];
        $userEmail = $userProfileDetails["email"];
        if (isset($userProfileDetails["contact_number"])) {
            $userContactNumber = $userProfileDetails["contact_number"];
        } else {
            $userContactNumber = "";
        }
        $address1 = $userProfileDetails["address_line1"];
        if (isset($userProfileDetails["address_line2"])) {
            $address2 = $userProfileDetails["address_line2"];
        } else {
            $address2 = "";