<?php
include "config.php";
header('Content-Type: application/json');
$valid_passwords = array("LifeLCT" => "LifLinCnslt");
$valid_users = array_keys($valid_passwords);

$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);

if (!$validated) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    $responsefull = array('error_message' => 'Unathorized: please provide a valid password!', 'data' => []);
} else {


    $datas = json_decode(file_get_contents('php://input'), true);
    $post_id = $datas['id'];

        if(!empty($post_id)){

            $lifeline_clinics_details = array();

            $query_menu = "SELECT * FROM `wp_posts` WHERE `ID`='$post_id'";
            $res_menu = mysqli_query($con, $query_menu);
            while ($row_menu = mysqli_fetch_array($res_menu)) {
                $post_content = str_replace("\n"," ",$row_menu['post_content']);
                // $post_content2 = str_replace("<!-- wp:html -->"," ",$post_content);
                // $post_content3 = str_replace(" <!-- /wp:html -->"," ",$post_content2);
                $post_contents1 =  stripslashes($post_content);
                $post_contents2 =  strip_tags($post_contents1);
                $post_contents3 = str_replace("\t","",$post_contents2);
                $post_contents4 = str_replace("“",'"',$post_contents3);
                $post_contents5 = str_replace('[ngg src=\"galleries\" ids=\"28\" display=\"basic_thumbnail\"] "',"",$post_contents4);

                // $contentsssss.= '<html><head></head><body style="font-size:20px;"><center>';
                $contentsssss.= '<html><head></head><body style="font-size:20px;" align="justify">';
                $contentsssss.= $post_contents5;
                $contentsssss.='</body></html>';

                $lifeline_clinics_details[] = array(
                    'id' => $row_menu['ID'],
                    'name' => $row_menu['post_title'],
                    'content' => $contentsssss
                );
            }

            $data = array("lifeline_clinics_details" => $lifeline_clinics_details );
            $response = array("status" => "true","message" => "Success", "data" => $data);

        }else{

            $lifeline_clinics_details[] = array(
                'id' => '',
                'name' => '',
                'content' => ''
            );

            $data = array("lifeline_clinics_details" => $lifeline_clinics_details );
            $response = array("status" => "false","message" => "parameter missing", "data" => $data);

        }




}
if(isset($response))
{
	echo json_encode($response, JSON_UNESCAPED_SLASHES);
}
?>