require 'admin/connection.php';
$request_uri = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'templates/';
$load_assets = str_replace('index.php', '', $request_uri);
$uri = $_SERVER['PATH_INFO'];
$slug = str_replace('/', '', $uri);
$sql = "SELECT * FROM projects WHERE slug = '$slug' LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$title = $row['p_title'];
$heading = $row['heading'];
$catgory = $row['category'];
$load_urls = json_decode($row['urls'], true);
$form_fields = json_decode($row['form'], true);
$gtm_code = $row['gtm_id'];
$fbp_code = $row['fb_id'];
$json_gtm_decode = json_decode($gtm_code,true);
$json_fbp_decode = json_decode($fbp_code,true);
$json_content = $row['content'];
$content = str_replace('"', '', $json_content);
$phone = json_decode($row['phone'],true);
$phoneNumbers = explode(',', $phone['phone']);
$keyItems_array = json_decode($row['key_items'],true);
$icon_code = $keyItems_array['icon_code'];
$icon_color = $keyItems_array['icon_color'];
$text_color = $keyItems_array['text_color'];
$items_key = explode(',', $keyItems_array['items']);
$items = explode(",", $keyItems_array['items']);
$list_items = "";
foreach ($items as $item) {
if(!empty($item)):
$list_items .= '
' . trim($item) . '';
endif;
}
$list = '';
$links = array_map(function($phoneNumber) {
return '' . $phoneNumber . '
';
}, $phoneNumbers);
$output = implode(' ', $links);
if($row['templete'] == 'template_1'):
include "templates/temp1.php";
elseif($row['templete'] == 'template_2'):
$links = array_map(function($phoneNumber) {
return '' . $phoneNumber . '';
}, $phoneNumbers);
$output = implode(' - ', $links);
include "templates/temp2.php";
elseif($row['templete'] == 'template_3'):
include "templates/temp3.php";
endif;
} else {
$uri = $_SERVER['PATH_INFO'];
$find_thank_you = "/thank-you";
if (strpos($uri, $find_thank_you) !== false) {
$ORIG_PATH_INFO = $_SERVER['ORIG_PATH_INFO'];
$checked = "/thank-you";
$checking = str_replace($checked, "", $ORIG_PATH_INFO);
$slug = str_replace('/', "", $checking);
$thanks_query = "SELECT * FROM projects WHERE slug = '$slug' LIMIT 1";
$result_thankyou = $conn->query($thanks_query);
if ($result_thankyou->num_rows > 0) {
$data = $result_thankyou->fetch_assoc();
$title = $data['p_title'];
$heading = $data['heading'];
$catgory = $data['category'];
$load_urls = json_decode($data['urls'] ,true);
$form_fields = json_decode($data['form'] ,true);
$json_content = $data['content'];
$content = str_replace('"', '', $json_content);
$gtm_code = $data['gtm_id'];
$fbp_code = $data['fb_id'];
$json_gtm_decode = json_decode($gtm_code,true);
$json_fbp_decode = json_decode($fbp_code,true);
$json_thanks_details = json_decode($data['thanks_info'],true);
$json_thanks_details_sub = str_replace('"', '', $data['thanks_desc']);
$phone = json_decode($data['phone'],true);
$phoneNumbers = explode(',', $phone['phone']);
// Format phone numbers as HTML links
$links = array_map(function($phoneNumber) {
return '' . $phoneNumber . '
';
}, $phoneNumbers);
$output = implode(' ', $links);
if($data['templete'] == 'template_1'):
include "templates/temp-1-thank-you.php";
elseif($data['templete'] == 'template_2'):
include "templates/temp-2-thank-you.php";
elseif($data['templete'] == 'template_3'):
include "templates/temp-3-thank-you.php";
endif;
}
} else {
// echo "test slug";
// Page not found, display 404 error
header("HTTP/1.0 404 Not Found");
// header('location: https://markproperties.pk/404');
}
}
// Close connection
$conn->close();
?>