	<?php
	$currentUri = $_SERVER['REQUEST_URI'];
	$phpSelf = basename($_SERVER['PHP_SELF']);
	$queryString = $_SERVER['QUERY_STRING'];

	// Determine if we are on the homepage: index.php (or "/") with no query string.
	$isHomepage = ($phpSelf === "index.php" || $currentUri === "/") && empty($queryString);
	
	
	// For Popup 1:
	if (defined('POPUP1_ENABLED') && POPUP1_ENABLED && defined('POPUP1_TARGET')) {
		if (POPUP1_TARGET === "HOME" && $isHomepage) {
			// Retrieve the static page content using the stored page ID for Popup 1
		if (defined('POPUP1_PAGE_ID') && !empty(POPUP1_PAGE_ID)) {
			$popup1_query = tep_db_query("SELECT description FROM main_page_description WHERE page_id = '" . tep_db_input(POPUP1_PAGE_ID) . "' AND language_id = '1'");
			$popup1_page  = tep_db_fetch_array($popup1_query);
			define('POPUP1_CONTENT', $popup1_page['description']);
		} else {
			define('POPUP1_CONTENT', '');
		}
			include 'templates/marketing_modal.php';
			echo "<script>
			  document.addEventListener('DOMContentLoaded', function () {
				setTimeout(function () {
				  var popup1 = new bootstrap.Modal(document.getElementById('marketingModal'));
				  popup1.show();
				}, 5000);
			  });
			</script>";
		} else if (POPUP1_TARGET !== "HOME" && strpos($currentUri, POPUP1_TARGET) !== false) {
			// Retrieve the static page content using the stored page ID for Popup 1
		if (defined('POPUP1_PAGE_ID') && !empty(POPUP1_PAGE_ID)) {
			$popup1_query = tep_db_query("SELECT description FROM main_page_description WHERE page_id = '" . tep_db_input(POPUP1_PAGE_ID) . "' AND language_id = '1'");
			$popup1_page  = tep_db_fetch_array($popup1_query);
			define('POPUP1_CONTENT', $popup1_page['description']);
		} else {
			define('POPUP1_CONTENT', '');
		}
			include 'templates/marketing_modal.php';
			echo "<script>
			  document.addEventListener('DOMContentLoaded', function () {
				setTimeout(function () {
				  var popup1 = new bootstrap.Modal(document.getElementById('marketingModal'));
				  popup1.show();
				}, 5000);
			  });
			</script>";
		}
	}

	// Similar logic for Popup 2:
	// For Popup 2:
if (defined('POPUP2_ENABLED') && POPUP2_ENABLED && defined('POPUP2_TARGET')) {
    $popup2_content = '';  // initialize variable for the popup content
    if (defined('POPUP2_PAGE_ID') && !empty(POPUP2_PAGE_ID)) {
        $popup2_query = tep_db_query("SELECT description FROM main_page_description WHERE page_id = '" . tep_db_input(POPUP2_PAGE_ID) . "' AND language_id = '1'");
        $popup2_page  = tep_db_fetch_array($popup2_query);
		//error_log("Popup2 content: " . print_r($popup2_page, true));
        $popup2_content = $popup2_page['description'];
    }
    // Check target conditions for Popup 2:
    if ((POPUP2_TARGET === "HOME" && $isHomepage) || (POPUP2_TARGET !== "HOME" && strpos($currentUri, POPUP2_TARGET) !== false)) {
        // Pass the content to the template by defining a constant or by other means.
        // Here we use a constant for consistency with Popup 1:
        define('POPUP2_CONTENT', $popup2_content);
        include 'templates/marketing_modal2.php';
        echo "<script>
          document.addEventListener('DOMContentLoaded', function () {
            setTimeout(function () {
              var popup2 = new bootstrap.Modal(document.getElementById('marketingModal2'));
              popup2.show();
            }, 5000);
          });
        </script>";
    }
}

	?>