<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
    $my_email = $_SESSION['login_user'];

// Include the database configuration file
include 'config.php';
// Initialize message variable
$msg = "";
  // If upload button is clicked ...
if (isset($_POST['upload'])) {
        $sql_author = mysqli_query($db, "SELECT * FROM members WHERE `Email`='$my_email'");
    while($DB_ROW = mysqli_fetch_array($sql_author)) {
        $pro_pic = $DB_ROW['Profile_Picture'];
        $fn = $DB_ROW['First_Name'];
        $mi = $DB_ROW['Middle_Initial'];
        $ln = $DB_ROW['Last_Name'];
        $full_name = "".$fn." ".$mi." ".$ln."";
    }
    
    $image_id= mysqli_real_escape_string($db, $_POST['image_id']);
    // Get image name
    $image = $_FILES['image']['name'];
    // Get text
    $image_text = mysqli_real_escape_string($db, $_POST['image_text']);
// image file directory
    $target = "uploads/".basename($image);
    
    // Set the new timezone
    date_default_timezone_set('Asia/Manila');
    $date_pos = date('m-d-y h:i:s A');

    $sql = "INSERT INTO image_upload (image, image_text, date_posted, `profile_pic`, `full_name`) VALUES ('$image', '$image_text', '$date_pos', '$pro_pic', '$full_name')";
    // execute query
    mysqli_query($db, $sql);

    if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
        $msg = "Image uploaded successfully";

        header("Location: profile.php");
    }else{
        $msg = "Failed to upload image";
    }
    //get date
    $date_posted=mysqli_real_escape_string($db, $_POST['date_posted']);

    
}


$gallery="SELECT * FROM image_upload ORDER BY id DESC  ";
$gallery_retrieve= mysqli_query($db,$gallery);


$index_portfolio="SELECT * FROM image_upload ORDER BY id DESC  ";
$port_index= mysqli_query($db,$index_portfolio);


$announce="SELECT * FROM image_upload ORDER BY id DESC LIMIT 1";
$announcements= mysqli_query($db,$announce);

$posts="SELECT * FROM image_upload ORDER BY id DESC LIMIT 10";
$retrieve_posts= mysqli_query($db,$posts);

$profile="SELECT * FROM members ORDER BY id ASC LIMIT 1";
$profile_pic= mysqli_query($db,$profile);


$read_full="SELECT * FROM announcements WHERE announcement_id='image_id'";
$read_post=mysqli_query($db,$read_full);


?>
