<?
$config = array();

// Begin Configuration
$config['basedir']     =  '/home/username/public_html';
$config['baseurl']     =  'http://www.idocscript.com';

$DBTYPE = 'mysql';
$DBHOST = 'localhost';
$DBUSER = 'database_username';
$DBPASSWORD = 'database_password';
$DBNAME = 'database_name';

$default_language = "english"; //Valid choices are english, spanish or french
// End Configuration

session_start();
date_default_timezone_set('America/New_York');

$config['adminurl']      =  $config['baseurl'].'/administrator';
$config['cssurl']      =  $config['baseurl'].'/css';
$config['tmpimgpath']     =   $config['basedir'].'/uploads/temp';
$config['tmpimgpath2']     =   $config['basedir'].'/uploads/temp';
$config['imagedir']      =  $config['basedir'].'/images';
$config['imageurl']      =  $config['baseurl'].'/images';
$config['membersprofilepicdir']      =  $config['imagedir'].'/membersprofilepic';
$config['membersprofilepicurl']      =  $config['imageurl'].'/membersprofilepic';
$config['channelthumbdir']      =  $config['imagedir'].'/channelthumbs';
$config['channelthumburl']      =  $config['imageurl'].'/channelthumbs';
$config['originalvdir']      =  $config['basedir'].'/uploads/doc';
$config['originalvurl']      =  $config['baseurl'].'/uploads/doc';
$config['docdir']      =  $config['basedir'].'/ddata';
$config['docurl']      =  $config['baseurl'].'/ddata';
$config['thumbdir']      =  $config['imagedir'].'/docthumbs';
$config['thumburl']      =  $config['imageurl'].'/docthumbs';
require_once($config['basedir'].'/smarty/libs/Smarty.class.php');
require_once($config['basedir'].'/libraries/mysmarty.class.php');
require_once($config['basedir'].'/libraries/SConfig.php');
require_once($config['basedir'].'/libraries/SError.php');
require_once($config['basedir'].'/libraries/adodb/adodb.inc.php');
require_once($config['basedir'].'/libraries/phpmailer/class.phpmailer.php');
require_once($config['basedir'].'/libraries/SEmail.php');

function strip_mq_gpc($arg)
{
  if (get_magic_quotes_gpc())
  {
  	$arg = str_replace('"',"'",$arg);
  	$arg = stripslashes($arg);
    return $arg;
  } 
  else
  {
    $arg = str_replace('"',"'",$arg);
    return $arg;
  }
}

$conn = &ADONewConnection($DBTYPE);
$conn->PConnect($DBHOST, $DBUSER, $DBPASSWORD, $DBNAME);
@mysql_query("SET NAMES 'UTF8'");
$sql = "SELECT * from config";
$rsc = $conn->Execute($sql);

if($rsc){while(!$rsc->EOF)
{
$field = $rsc->fields['setting'];
$config[$field] = $rsc->fields['value'];
STemplate::assign($field, strip_mq_gpc($config[$field]));
@$rsc->MoveNext();
}}

if ($_REQUEST['language'] != "")
{
	if ($_REQUEST['language'] == "english")
	{
		$_SESSION['language'] = "english";
	}
	elseif ($_REQUEST['language'] == "spanish")
	{
		$_SESSION['language'] = "spanish";
	}
	elseif ($_REQUEST['language'] == "french")
	{
		$_SESSION['language'] = "french";
	}
}

if ($_SESSION['language'] == "")
{
	$_SESSION['language'] = $default_language;
}

if ($_SESSION['language'] == "english")
{
	include("lang/english.php");
}
elseif ($_SESSION['language'] == "spanish")
{
	include("lang/spanish.php");
}
elseif ($_SESSION['language'] == "french")
{
	include("lang/french.php");
}
else
{
	include("lang/".$default_language.".php");
}

for ($i=0; $i<count($lang); $i++)
{
	STemplate::assign('lang'.$i, $lang[$i]);
}

for ($i=0; $i<count($langev); $i++)
{
	STemplate::assign('langev'.$i, $langev[$i]);
}

STemplate::assign('baseurl',       $config['baseurl']);
STemplate::assign('basedir',       $config['basedir']);
STemplate::assign('adminurl',       $config['adminurl']);
STemplate::assign('cssurl',       $config['cssurl']);
STemplate::assign('tmpimgpath',       $config['tmpimgpath']);
STemplate::assign('tmpimgpath2',       $config['tmpimgpath2']);
STemplate::assign('imagedir',        $config['imagedir']);
STemplate::assign('imageurl',        $config['imageurl']);
STemplate::assign('imgpath',        $config['imgpath']);
STemplate::assign('membersprofilepicdir',        $config['membersprofilepicdir']);
STemplate::assign('membersprofilepicurl',        $config['membersprofilepicurl']);
STemplate::assign('channelthumbdir',        $config['channelthumbdir']);
STemplate::assign('channelthumburl',        $config['channelthumburl']);
STemplate::assign('originalvdir',        $config['originalvdir']);
STemplate::assign('originalvurl',        $config['originalvurl']);
STemplate::assign('docdir',        $config['docdir']);
STemplate::assign('docurl',        $config['docurl']);
STemplate::assign('thumbdir',        $config['thumbdir']);
STemplate::assign('thumburl',        $config['thumburl']);
STemplate::assign('vthumburl',        $config['thumburl']);
STemplate::setCompileDir($config['basedir']."/temporary");
STemplate::setTplDir($config['basedir']."/themes");
if($sban != "1")
{
	$bquery = "SELECT count(*) as total from bans_ips WHERE ip='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."'";
	$bresult = $conn->execute($bquery);
	$bcount = $bresult->fields['total'];
	if($bcount > "0")
	{
		$brdr = $config['baseurl']."/banned.php";
		header("Location:$brdr");
		exit;
	}
}
function create_slrememberme() {
        $key = md5(uniqid(rand(), true));
        global $conn;
        $sql="update members set remember_me_time='".date('Y-m-d H:i:s')."', remember_me_key='".$key."' WHERE username='".mysql_real_escape_string($_SESSION[USERNAME])."'";
        $conn->execute($sql);
        setcookie('slrememberme', gzcompress(serialize(array($_SESSION[USERNAME], $key)), 9), time()+60*60*24*30);
}

function destroy_slrememberme($username) {
        if (strlen($username) > 0) {
                global $conn;
                $sql="update members set remember_me_time=NULL, remember_me_key=NULL WHERE username='".mysql_real_escape_string($username)."'";
                $conn->execute($sql);
        }
        setcookie ("slrememberme", "", time() - 3600);
}

if (!isset($_SESSION["USERNAME"]) && isset($_COOKIE['slrememberme'])) 
{
        $sql="update members set remember_me_time=NULL and remember_me_key=NULL WHERE remember_me_time<'".date('Y-m-d H:i:s', mktime(0, 0, 0, date("m")-1, date("d"),   date("Y")))."'";
        $conn->execute($sql);
        list($username, $key) = @unserialize(gzuncompress(stripslashes($_COOKIE['slrememberme'])));
        if (strlen($username) > 0 && strlen($key) > 0)
		{
        	$sql="SELECT status,USERID,email,username,verified from members WHERE username='".mysql_real_escape_string($username)."' and remember_me_key='".mysql_real_escape_string($key)."'";
          	$rs=$conn->execute($sql);
          	if($rs->recordcount()<1)
			{
				$error = $lang['45'];
			}
		    elseif($rs->fields['status'] == "0")
			{
				$error = $lang['44'];
			}
    		if($error=="")
			{				
				$_SESSION['USERID']=$rs->fields['USERID'];
				$_SESSION['EMAIL']=$rs->fields['email'];
				$_SESSION['USERNAME']=$rs->fields['username'];
				$_SESSION['VERIFIED']=$rs->fields['verified'];
      			create_slrememberme();
        	}
			else
			{
                destroy_slrememberme($username);
        	}
        }
}

?>