<?php

if (!headers_sent())
{
	if (isset($_GET['session_id']) && !empty($_GET['session_id']))
    {
        $session_id = trim($_GET['session_id']);
        $pattern = '/[a-zA-Z0-9]+/';
        if (version_compare(PHP_VERSION, '5.0.0', '>='))
        {
            $pattern = '/[a-zA-Z0-9,-]+/';
        }
        if (preg_match($pattern, $session_id))
        {
            session_id($session_id);
        }
    }
	session_name('ShoppingCart50');
	// Set SameSite=Lax to mitigate CSRF attacks
	session_set_cookie_params(array(
		'lifetime' => 0,
		'path'     => '/',
		'secure'   => isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on',
		'httponly' => true,
		'samesite' => 'Lax',
	));
	@session_start();
}
$_SERVER['PHP_SELF']=htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES);
if (isset($_GET["reporting"]) && $_GET["reporting"] == '0') 
{
	$_SESSION["error_reporting"] = '0';
} else if (isset($_GET["reporting"]) && $_GET["reporting"]== '1') {
	$_SESSION["error_reporting"] = '1';
}
if (isset($_SESSION["error_reporting"]) && $_SESSION["error_reporting"]=='1')
{
	ini_set("display_errors", "On");
	ini_set("display_startup_errors", "On");
	error_reporting(E_ALL|E_STRICT);
} else {
	ini_set("display_errors", "Off");
	ini_set("display_startup_errors", "Off");
	error_reporting(0);
}
header("Content-type: text/html; charset=utf-8");
if (!defined("ROOT_PATH"))
{
	define("ROOT_PATH", dirname(__FILE__) . '/');
}

require ROOT_PATH . 'app/config/options.inc.php';

require_once PJ_FRAMEWORK_PATH . 'pjAutoloader.class.php';
pjAutoloader::register();

if (!isset($_GET['controller']) || empty($_GET['controller']))
{
	header("HTTP/1.1 301 Moved Permanently");
	pjUtil::redirect(PJ_INSTALL_URL . basename($_SERVER['PHP_SELF'])."?controller=pjBase&action=pjActionIndex");
}

if (isset($_GET['controller']))
{
	$pjObserver = pjObserver::factory();
	$pjObserver->init();
}
?>
