<?phpsession_start();ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);include ($_SERVER['DOCUMENT_ROOT'] . "/includes/server_pages.inc");include ($_SERVER['DOCUMENT_ROOT'] . "/includes/columns.inc");include ($_SERVER['DOCUMENT_ROOT'] . "/includes/simeya-constants.inc");include ($_SERVER['DOCUMENT_ROOT'] . "/admin/pdo.inc"); // <-- DB (PDO)include ($_SERVER['DOCUMENT_ROOT'] . "/includes/functions.inc");$pg = $_GET['pg']  ?? '';$fd	= explode('?', $pg);$pg	= $fd[0] . ".inc";foreach ($_GET as $key => $value) {    // Allow only alphanumeric keys    if (!preg_match('/^[a-zA-Z0-9_]+$/', $key)) {        continue;    }    // Trim and sanitize value    $value = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);    //echo "<li>$key : $value </li>";}$functionCalled = [];$SCRIPT_1 = $SCRIPT_2 = $SCRIPT_3 = '';if ($_SERVER['SCRIPT_URL'] == '/') {  	$SCRIPT_URL = "/";} else if (!empty($_SERVER['SCRIPT_URL'])) {  	$u 			= substr($_SERVER['SCRIPT_URL'], -1) == '/' ? substr($_SERVER['SCRIPT_URL'], 0, -1) : $_SERVER['SCRIPT_URL'];  	$parts    	= explode('/', $u);  	$SCRIPT_URL = $parts[1];  	$SCRIPT_1 	= !empty($parts[1]) ? $parts[1] : '';  	$SCRIPT_2 	= !empty($parts[2]) ? $parts[2] : '';  	$SCRIPT_3 	= !empty($parts[3]) ? $parts[3] : '';  	// join referral redirect  	if ($parts[1] == "join" && !empty($parts[2])) {    	if (intval($parts[2]) > 0) {      		if (isMember('cc', intval($parts[2]))) {        		DEFINE("REFERRER", $parts[2]);        		$SCRIPT_2 = "";        		$u        = $parts[1];        		$invited  = '/invited?cc=' . $parts[2] . '&nm=' . ($_GET['nm'] ?? '');        		header("Location: $invited");        		exit();      		}    	}  	}} else {  	$SCRIPT_URL = "/";}$HOST = $_SERVER['HTTP_HOST'];$ct   = 'US';DEFINE("HTTP_HOST", $HOST);DEFINE("SCRIPT_URL", $SCRIPT_URL);DEFINE("SCRIPT_2", $SCRIPT_2);DEFINE("SCRIPT_3", $SCRIPT_3);DEFINE("QUERY_STRING", $_SERVER['QUERY_STRING']);// Build $pgid (slug-ish) like beforeif ($SCRIPT_1 == 'dashboard') {  	if (!empty($SCRIPT_4))    	$pgid = $SCRIPT_2 . '-' . $SCRIPT_3 . '-' . $SCRIPT_4;  	else if (!empty($SCRIPT_3))    	$pgid = $SCRIPT_2 . '-' . $SCRIPT_3;  	else if (!empty($SCRIPT_2))    	$pgid = $SCRIPT_2;  	else    	$pgid = 'dashboard';} else {  	if (!empty($SCRIPT_3))    	$pgid = $SCRIPT_1 . '-' . $SCRIPT_2 . '-' . $SCRIPT_3;  	else if (!empty($SCRIPT_2))    	$pgid = $SCRIPT_1 . '-' . $SCRIPT_2;  	else if (!empty($SCRIPT_1))    	$pgid = $SCRIPT_1;  	else    	$pgid = 'home';}// Filesystem fallbacks (original behavior)if ($pgid == 'apps-sendgrid') {  	$xurl  = "/apps/sendgrid/sdg.php";  	$xhtml = $_SERVER['DOCUMENT_ROOT'] . "/apps/sendgrid/sdg.php";} else {  	$xurl  = "/includes/" . $pgid . ".inc";  	$xhtml = $_SERVER['DOCUMENT_ROOT'] . "/includes/" . $pgid . ".inc";}// ---------- OPTIONAL INVITER COOKIE ----------if (!empty($_GET['_UID'])) {  	setInviterCookie($_GET['_UID']);}// Prepare defaults (legacy)$head  = $pgid . '-' . 'head';$photo = $pgid . '-' . 'photo';$p     = !empty($server_pages[$photo]) ? $server_pages[$photo] : '';$h     = !empty($server_pages[$head]) ? $server_pages[$head] : '';$index = '';DEFINE("PGID", $pgid);DEFINE("PHOTO", $p);DEFINE("HEAD",  $h);// ---------- AUTH / LOGGING ----------if (!empty($_GET['language']) || !empty($_GET['currency'])) {  	include ($_SERVER['DOCUMENT_ROOT'] . "/admin/save_language.inc");}if ($pgid == 'logout') {  	$message = getLogout();}if (!empty($_COOKIE["SIM_id"])) {  	include ($_SERVER['DOCUMENT_ROOT'] . "/admin/decode.inc");  	$SIMinfo = decodeString($_COOKIE['SIM_id']);}include ($_SERVER['DOCUMENT_ROOT'] . "/admin/user-logs.php");// ======================================================================//                  DB PAGE LOOKUP (simeya_pages)// ======================================================================// Try to resolve the page from DB first; fallback to filesystem mapping.$page = null;try {  	$stm = $pdo->prepare("SELECT * FROM simeya_pages WHERE slug=? AND status='active' LIMIT 1");  	$stm->execute([$pgid]);  	$page = $stm->fetch(PDO::FETCH_ASSOC);} catch (Throwable $e) {  	// If DB not available for some reason, we just fall back silently  	$page = null;}if ($page) {  	// DB-based route  	$purl = $page['include_file']; // e.g. /includes/business.inc} else {  	// Filesystem fallback (original)  	if ($SCRIPT_1 == 'dashboard') {    	$purl = "/dashboard/includes/" . $pgid . ".inc";  	} else if (file_exists($xhtml) && !empty($pgid)) {    	$purl = $xurl;  	} else {    	$purl = $server_pages[404];  	}  	// Construct a synthetic $page with sensible defaults so templates can use it  	$page = [    'page_id'            => 0,    'slug'               => $pgid,    'url_path'           => '/' . $pgid,    'include_file'       => $purl,    'title'              => null,    'display_type'       => 1,                // default 1 column    'visibility'         => 'public',    'modal_enabled'      => 0,    'modal_include_file' => null,    'left_ads_mode'      => 'auto',    'left_ads_max'       => 2,    'left_ads_order'     => 'ordered',    'status'             => 'active'  ];}//if($pg == "shop") {	$purl = "/includes/" . $pg;//}DEFINE("PURL", $purl);//print "<h2>PURL $purl</h2>";// Make $page available to included templates$GLOBALS['page'] = $page;// ======================================================================//            ACCESS CONTROL (DB visibility + optional allow list)// ======================================================================$deny 		= false;$userType 	= $SIMinfo['user_type'] ?? null;if (!empty($page['visibility'])) {  	if ($page['visibility'] === 'admin') {    	// Adjust your admin roles as needed    	$deny = !in_array($userType, ['A','M'], true);  	} elseif ($page['visibility'] === 'restricted') {    	$deny = true; // default deny until allowed    	try {      		$qa = $pdo->prepare("SELECT 1 FROM simeya_page_access WHERE page_id=? AND user_type=? LIMIT 1");      		$qa->execute([$page['page_id'], $userType]);      		if ($qa->fetchColumn()) $deny = false;    	} catch (Throwable $e) {      		// If table not present yet, remain denied for restricted pages      		$deny = true;    	}  	}}if ($deny) {  	// Render a friendly denial page (same style as your block in 2-col template)  	$index .= '  	<div class="content-wrapper">    	<header class="wrapper bg-light">';  			include ($_SERVER['DOCUMENT_ROOT'] . "/includes/header-win.inc"); $index .= $header;  			$index .= '    	</header>    	<div class="container py-10">      		<div class="text-center mt-7">        		<img src="/assets/img/access-denied.jpg" class="img-fluid mb-4" alt="Access Denied">        		<h2 class="display-5 mb-2">🚫 Access Denied</h2>        		<p class="lead mb-4">You are not authorized to access this page.</p>        		<p>          			<a href="#" class="btn btn-sm btn-primary rounded-pill" data-bs-toggle="modal" data-bs-target="#authModal">Login</a>          			or          			<a href="/join" class="btn btn-sm btn-primary rounded-pill">Join the Simeya Network</a>        		</p>      		</div>    	</div>  	</div>';  	// Footer & close will be added later below as usual} else {  	// ====================================================================  	//   DISPATCH to main templates (original behavior preserved)  	// ====================================================================  	  	/*  	if ($SCRIPT_1 == 'dashboard') {    	include ($_SERVER['DOCUMENT_ROOT'] . "/dashboard/html/index.php");  	} else if (PGID == 'home') {    	include ($_SERVER['DOCUMENT_ROOT'] . "/includes/index-win-new.inc");  	} else if (in_array($pgid, $server_social)) {    	include ($_SERVER['DOCUMENT_ROOT'] . "/includes/index-win-new.inc");  	} else if (in_array($pgid, $server_includes)) {    	include ($_SERVER['DOCUMENT_ROOT'] . "/includes/index-includes.inc");  	} else {    	include ($_SERVER['DOCUMENT_ROOT'] . "/includes/index-win-new.inc");  	}  	*/  	include ($_SERVER['DOCUMENT_ROOT'] . "/includes/index-win-new.inc");}// Page composed by included template(s)$page_html = $index;echo $page_html;?><style>  	#authModal .modal-dialog { max-width: 95%; }  	@media (min-width: 768px) { #authModal .modal-dialog { max-width: 60%; } }</style><?php// Common listsinclude ($_SERVER['DOCUMENT_ROOT'] . "/includes/months.inc");include ($_SERVER['DOCUMENT_ROOT'] . "/includes/days.inc");include ($_SERVER['DOCUMENT_ROOT'] . "/includes/country_list.inc");?><!-- Auth Modal + JSON Frontend (CSRF + Remember Me) --><div class="modal fade" id="authModal" tabindex="-1">  	<div class="modal-dialog modal-dialog-centered">    	<div class="modal-content p-3">      		<div class="modal-header">        		<h5 class="modal-title">Simeya Account</h5>        		<button type="button" class="btn-close" data-bs-dismiss="modal"></button>      		</div>      		<div class="modal-body">        		<!-- Nav Tabs -->        		<ul class="nav nav-tabs mb-3" id="authTabs">          			<li class="nav-item"><a class="nav-link active" data-bs-toggle="tab" href="#loginTab">Login</a></li>          			<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#registerTab">Join</a></li>          			<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#forgotTab">Forgot Password</a></li>        		</ul>        		<div class="tab-content">          			<!-- Login -->          			<div class="tab-pane fade show active" id="loginTab">            			<form id="loginForm">              				<input type="email" class="form-control mb-2" name="email" placeholder="Email" required>              				<input type="password" class="form-control mb-2" name="password" placeholder="Password" required>              				<div class="form-check mb-2">                				<input class="form-check-input" type="checkbox" id="rememberMe" name="remember_me" value="1">                				<label class="form-check-label" for="rememberMe">Remember me</label>              				</div>              				<button class="btn btn-primary w-100">Login</button>            			</form>          			</div>          			<!-- Register -->          			<div class="tab-pane fade" id="registerTab">            			<form id="registerForm">              				<div class="row">                				<div class="col-md-6"><div class="mb-3"><label>First Name</label><input type="text" name="first_name" class="form-control" required></div></div>                				<div class="col-md-6"><div class="mb-3"><label>Last Name</label><input type="text" name="last_name" class="form-control" required></div></div>              				</div>              				<div class="row">                				<div class="col-md-6"><div class="mb-3"><label>Email</label><input type="email" name="email_address" class="form-control" required></div></div>                				<div class="col-md-6"><div class="mb-3"><label>Phone #</label><input type="tel" name="phone_number" class="form-control" required></div></div>              				</div>              				<div class="row">                				<div class="col-md-6">                  					<div class="mb-3">                    					<label>Birth Country</label>                    					<div class="form-select-wrapper mb-1 mt-3">                      						<select class="form-select" id="country_birth" name="country_birth" required>                        						<option value="" selected>Choose one *</option>                        						<?= function_country('') ?>                      						</select>                    					</div>                  					</div>                						</div>                					<div class="col-md-6">                  						<div class="mb-3">                    						<label>Residence Country</label>                    						<div class="form-select-wrapper mb-1 mt-3">                      							<select class="form-select" id="country_residence" name="country_residence" required>                        							<option value="" selected>Choose one *</option>                        							<?= function_country('') ?>                      							</select>                    						</div>                  						</div>                					</div>              					</div>              					<div class="row">                					<div class="col-md-4">                  						<div class="mb-3">                    						<label>Gender</label>                    						<div class="form-select-wrapper mb-1 mt-3">                      							<select class="form-select" id="gender" name="gender" required>                        							<option value="" selected>Gender *</option>                        							<option value="01">Male</option>                        							<option value="02">Female</option>                      							</select>                    						</div>                  						</div>                					</div>                					<div class="col-md-4">                  					<div class="mb-3">                    					<label>Birth Month</label>                    					<div class="form-select-wrapper mb-1 mt-3">                      						<select class="form-select" id="birth_month" name="birth_month" required>                        						<option value="" selected>Choose one</option>                        						<?= function_months('') ?>                      						</select>                    					</div>                  					</div>                				</div>                				<div class="col-md-4">                  					<div class="mb-3">                    					<label>Birth Day</label>                    					<div class="form-select-wrapper mb-1 mt-3">                      						<select class="form-select" id="birth_day" name="birth_day" required>                        						<option value="" selected>Choose one</option>                        						<?= function_days('') ?>                      						</select>                    					</div>                  					</div>                				</div>              				</div>              				<div class="mb-3">                				<label>Password</label>                				<input type="password" name="password_hash" class="form-control" required>                				<small class="text-muted">Min 10 chars, include upper, lower, digit, special.</small>              				</div>              				<button type="submit" class="btn btn-success w-100">Join</button>            			</form>          			</div>          			<!-- Forgot Password -->          			<div class="tab-pane fade" id="forgotTab">            			<form id="forgotForm">              				<input type="email" class="form-control mb-2" name="email" placeholder="Enter your email" required>              				<button class="btn btn-warning w-100">Send Reset Link</button>            			</form>          			</div>        		</div>        		<!-- Reset Password (hidden until link clicked) -->        		<div id="resetTab" style="display:none;">          			<form id="resetForm">            			<input type="hidden" name="token">            			<input type="password" class="form-control mb-2" name="password" placeholder="New Password" required>            			<button class="btn btn-success w-100">Reset Password</button>          			</form>        		</div>        		<div id="authMsg" class="mt-3 text-center text-danger"></div>      		</div>    	</div>  	</div></div><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><script>	// ===== CSRF: set header from XSRF-TOKEN cookie =====	function getCookie(name){  		const m = document.cookie.match(new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()\\[\\]\\\\/+^])/g,'\\\\$1') + '=([^;]*)'));  		return m ? decodeURIComponent(m[1]) : '';	}	$.ajaxSetup({  		beforeSend: function(xhr){    		const token = getCookie('XSRF-TOKEN');    		if (token) xhr.setRequestHeader('X-CSRF-Token', token);  		}	});		// Boot: ensure CSRF cookie is issued when modal opens	$('#authModal').on('shown.bs.modal', function(){  		$.getJSON('/login-app/auth/login.php?action=csrf');	});		function handleForm(formId, action, onSuccess){  		$(formId).on('submit', function(e){    		e.preventDefault();    		$.post('/login-app/auth/login.php?action='+action, $(this).serialize(), function(resp){      			$('#authMsg').text(resp.message)        		.removeClass('text-danger text-success')        		.addClass(resp.success ? 'text-success' : 'text-danger');      			if(resp.success && typeof onSuccess === 'function') onSuccess(resp);    		}, 'json').fail(function(xhr) {      			$('#authMsg').text('AJAX Error: ' + xhr.status);    		});  		});	}		handleForm('#loginForm', 'login', function(resp){  		if(resp.redirect) window.location = resp.redirect; else location.reload();	});	handleForm('#registerForm', 'register', function(){  		$('a[href="#loginTab"]').tab('show');	});	handleForm('#forgotForm', 'forgot');	handleForm('#resetForm', 'reset', function(){  		$('a[href="#loginTab"]').tab('show');	});	// ===== Modal autoload: once per session (gates any auto-show in plugins.js)	if (document.querySelector(".modal-popup") != null) {  		if (!localStorage.getItem('seenModal02')) {    		const myModalPopup = new bootstrap.Modal(document.querySelector('.modal-popup'));    		setTimeout(function() {      			myModalPopup.show();      			localStorage.setItem('seenModal02', 'true');    		}, 200);  		}	}</script><?php// ---------- FOOTER ----------echo '<footer class="bg-light">';	include ($_SERVER['DOCUMENT_ROOT'] . "/includes/footer-win.inc"); echo $footer;	echo '</footer><div class="progress-wrap">    <svg class="progress-circle svg-content" width="100%" height="100%" viewBox="-1 -1 102 102">      	<path d="M50,1 a49,49 0 0,1 0,98 a49,49 0 0,1 0,-98" />    </svg></div>';include ($_SERVER['DOCUMENT_ROOT'] . "/includes/foot-win.inc"); echo $foot;// include ($_SERVER['DOCUMENT_ROOT'] . "/includes/contrast2.inc"); echo $contrast2;?><?php// ======================================================================//          LEFT-RAIL ADS HELPERS (available to templates)// ======================================================================if (!function_exists('fetch_left_ads')) {  	function fetch_left_ads($pdo, $page, $now = null) {    	$dt = isset($page['display_type']) ? (int)$page['display_type'] : 1;    	if ($dt < 2) return [];    	$mode  = isset($page['left_ads_mode'])  ? $page['left_ads_mode']  : 'auto';    	if ($mode === 'none') return [];    	$limit = isset($page['left_ads_max']) ? (int)$page['left_ads_max'] : 2;    	if ($limit <= 0) return [];    	$order = isset($page['left_ads_order']) ? $page['left_ads_order'] : 'ordered';    	$now   = $now ?: date('Y-m-d H:i:00');    	$timeClause = "(a.start_at IS NULL OR a.start_at <= :now) AND (a.end_at IS NULL OR a.end_at >= :now) AND a.status='active'";    	if ($mode === 'manual' && !empty($page['page_id'])) {      		// ORDER BY for manual mode      		if ($order === 'random') {        		$orderSql = ' ORDER BY RAND() ';      		} elseif ($order === 'weighted') {        		$orderSql = ' ORDER BY spa.weight DESC, spa.slot_order ASC ';      		} else {        		$orderSql = ' ORDER BY spa.slot_order ASC ';      		}      		$sql = "        		SELECT a.*, COALESCE(spa.weight, a.weight) AS eff_weight        		FROM simeya_page_ads spa        		JOIN simeya_ads a ON a.ad_id = spa.ad_id        		WHERE spa.page_id = :pid AND $timeClause        		$orderSql        		LIMIT $limit";      		$st = $pdo->prepare($sql);      		$st->execute([':pid' => $page['page_id'], ':now' => $now]);      		return $st->fetchAll(PDO::FETCH_ASSOC);    	}    		if (!function_exists('render_ad')) {  			function render_ad($ad) {    			switch ($ad['ad_type']) {      				case 'image':        				if (!empty($ad['image_url'])) {          					$img  = htmlspecialchars($ad['image_url'], ENT_QUOTES);          					$href = !empty($ad['link_url']) ? htmlspecialchars($ad['link_url'], ENT_QUOTES) : '#';          					echo '<div class="card shadow-sm mb-3"><a href="'.$href.'" target="_blank" rel="nofollow noopener"><img class="img-fluid" src="'.$img.'" alt=""></a></div>';        				}        				break;      				case 'html':        				echo '<div class="card shadow-sm mb-3"><div class="card-body">'.$ad['html_snippet'].'</div></div>';        				break;      				case 'include':        				if (!empty($ad['include_file'])) {          					$file = $_SERVER['DOCUMENT_ROOT'].$ad['include_file'];          					if (is_file($file)) include $file;        				}        				break;    			}  			}		}    	// AUTO mode    	if ($order === 'random') {      		$orderSql = ' ORDER BY RAND() ';    	} elseif ($order === 'weighted') {      		$orderSql = ' ORDER BY a.weight DESC, a.ad_id DESC ';    	} else {      		$orderSql = ' ORDER BY a.ad_id DESC ';    	}    	$sql = "SELECT a.*, a.weight AS eff_weight            FROM simeya_ads a            WHERE $timeClause            $orderSql            LIMIT $limit";    		$st = $pdo->prepare($sql);    		$st->execute([':now' => $now]);    		return $st->fetchAll(PDO::FETCH_ASSOC);  	}}