<?php

//include 'encdec.php';
//include 'bcrypt.php';

$usehttps=0; //enforcing HTTPS on production server, enable this on production server

$enableudf=0; //allow UDF editing, disable this on production server
$enablelivechat=0;
$chatkey='5BjFWzJY4yRiXVg7j5pDcHVJvtn1HLjN'; //default to Developer Support

$forceajxjs=0; //set to 1 to enable live reloading of JS during switch-over deployment, remember to set it back to 0

date_default_timezone_set('America/Toronto');

define ('TABLENAME_USERS','users');
define ('TABLENAME_ACTIONLOG','actionlog');
define ('TABLENAME_REPORTS','reports');

$_SERVER['RAW_IP']=$_SERVER['REMOTE_ADDR'];
$_SERVER['O_IP']=$_SERVER['REMOTE_ADDR'];

if (isset($_SERVER['HTTP_X_REAL_IP'])) $_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_REAL_IP'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_FORWARDED_FOR'];

if ($_SERVER['REMOTE_ADDR']==='::1') {
	$_SERVER['REMOTE_ADDR6']=$_SERVER['REMOTE_ADDR'];
	$_SERVER['REMOTE_ADDR']='127.0.0.1';
}

if (isset($_SERVER['HTTP_X_REAL_IP'])) {
	$_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_REAL_IP'];
	$_SERVER['RAW_IP']=$_SERVER['HTTP_X_REAL_IP'];
}
if (isset($_SERVER['HTTP_X_FORWARDED_SSL'])&&$_SERVER['HTTP_X_FORWARDED_SSL']==='on') $_SERVER['HTTPS']='on';
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
	$fparts=explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
	$_SERVER['REMOTE_ADDR']=$fparts[0];	
}

if (strpos($_SERVER['O_IP'],':')!==false&&$_SERVER['O_IP']!=='::1'){
	$ipparts=explode(':',$_SERVER['O_IP']);
	$nipparts=array();
	$ipmax=4; $ipidx=0;
	while ($ipidx<$ipmax){
		array_push($nipparts,$ipparts[$ipidx]);
		$ipidx++;
	}
	$_SERVER['O_IP']=implode(':',$nipparts);	
}

if (isset($_SERVER['REMOTE_ADDR6'])&&($_SERVER['REMOTE_ADDR6']===$_SERVER['REMOTE_ADDR']||strpos($_SERVER['REMOTE_ADDR'],':')!==false)){
	$ipparts=explode(':',$_SERVER['REMOTE_ADDR']);
	$nipparts=array();
	$ipmax=4; $ipidx=0;
	while ($ipidx<$ipmax){
		array_push($nipparts,$ipparts[$ipidx]);
		$ipidx++;
	}
	$_SERVER['REMOTE_ADDR6']=$_SERVER['REMOTE_ADDR'];
	$_SERVER['REMOTE_ADDR']=implode(':',$nipparts);
}

if (trim($_SERVER['PHP_SELF'])=='') $_SERVER['PHP_SELF']=$_SERVER['SCRIPT_NAME'];

//replace the following with memcache.php in production
include 'memcache_stub.php'; 
cache_init();

function _jsflag($flag){
	global $forceajxjs;
	
	if ($forceajxjs) return 'null';
	
	return $flag;	
}

function jsflag($flag){
	global $forceajxjs;
	
	if ($forceajxjs) echo 'null';
	else echo 'self.'.$flag;
}
