<?php
$datetime = date("Y-m-d H:i:s");
$txt  = "\n$datetime - ".$_SERVER['PHP_SELF']."\n";
$txt .= print_r($user, true);
$txt .= print_r($_POST, true);

//make sure user is superAdmin
if ( !$user['superAdmin'] ) {
$txt .= "403 not superAdmin\n";

    http_response_code(403);
    echo json_encode('You do not have permission to delete this attachment');
    exit;
}

//validate plan id
if ( !$publicProjectAttachment = $db->row("SELECT * FROM public_project_attachment WHERE id = ?", $_POST['id']) ) {
$txt .= "400 invalid public project attachment ID\n";

    http_response_code(400);
    echo json_encode('Invalid public project attachment ID');
    exit;
} 
$txt .= print_r($publicProjectAttachment, true);

$db->delete('public_project_attachment', ['id' => $_POST['id']]);

$txt .= "done\n\n\n\n";
$file = fopen(PATH_LOGS.'/btb.delete-public-project-image.log', "a");
fwrite($file, $txt);
fclose($file);

http_response_code(200);
echo json_encode('Public project attachment deleted');