Location: PHPKode > projects > Stuffed Tracker - Web Traffic Monitoring & Analysis > stuffed-tracker-web-traffic-monitoring-analysis/actions/admin.misc_config.php
<?
if (!defined("NS_TRACKER_INDEX")) exit;
/////////////////////////////////////////////
///////// permission check here
if (!$nsUser->Logged()) $nsProduct->Redir("login", "", "admin");

if ($nsProduct->LICENSE==3&&!$nsUser->ADMIN) $nsProduct->Redir("default", "", "admin");
if ($nsProduct->LICENSE!=3&&!$nsUser->SUPER_USER) $nsProduct->Redir("default", "", "admin");

/////////////////////////////////////////////
///////// require libraries here

require_once SELF."/lib/store.func.php";
require_once SYS."/system/lib/validate.func.php";

/////////////////////////////////////////////
///////// prepare any variables

$EditArr=(ValidArr($_GP['EditArr']))? $_GP['EditArr']:false;
$ChangeTracking=ValidVar($_GP['ChangeTracking']);

$PageTitle=$Lang['Title'];
$nsLang->TplInc("inc/top_panel.inc");
$ProgPath[0]['Name']=$Lang['Administr'];
$ProgPath[0]['Url']=getURL("admin", "", "admin");
$ProgPath[1]['Name']=$Lang['Title'];
$ProgPath[1]['Url']=getURL("misc_config", "", "admin");
$MenuSection="admin";

if (!$nsUser->DEMO&&$ChangeTracking&&($nsUser->ADMIN||$nsUser->SUPER_USER)) ChangeTracking($ChangeTracking);

$Query = "SELECT * FROM ?_config WHERE COMPANY_ID=0 AND SITE_ID=0";
$Settings=$Db->Select($Query);
$P3P=GetParam("P3P", "STRVAL");
$P3P_REF=GetParam("P3P_REF", "STRVAL");

$nsLang->TplInc('constructor/periods');

/////////////////////////////////////////////
///////// call any process functions

if (!$nsUser->DEMO) {
	if (ValidArr($EditArr)) SaveSettings($EditArr);
}

/////////////////////////////////////////////
///////// display section here


$SkinsArr=array();
$Path=SELF."/skins";
clearstatcache();
$Dir=@opendir($Path);
    while ($Row = readdir($Dir)) {
        if ($Row == "." || $Row == ".." || $Row=="CVS") continue;
        if (is_file($Row)) continue;
        $Name = strtoupper(substr($Row,0,1)).substr($Row,1);
        $SkinsArr[$Row]=$Name;
    }

$LangsArr=array();
$LangsArr=$nsLang->GetList();

$Periods=array();
$Query = "SELECT * FROM ?_periods WHERE COMPANY_ID=0";
$Sql = new Query($Query);
while ($Row=$Sql->Row()) {
    $Row->NAME=V($Row->NAME,V($Lang[$Row->TEMPLATE],$Row->TEMPLATE));
    $Periods[$Row->TEMPLATE]=$Row->NAME;
}

$EditArr['P3P']=htmlspecialchars(stripslashes(V($EditArr['P3P'],$P3P)));
$EditArr['P3P_REF']=htmlspecialchars(stripslashes(V($EditArr['P3P_REF'],$P3P_REF)));
$EditArr['SSLink']=htmlspecialchars(stripslashes(V($EditArr['SSLink'],$Settings->SSL_LINK)));
$EditArr['DefSkin']=V($EditArr['DefSkin'],$nsProduct->DEFAULT_SKIN);
$EditArr['DefLang']=V($EditArr['DefLang'],$nsProduct->DEFAULT_LANG);
$EditArr['WhiteLogo']=V($EditArr['WhiteLogo'],$nsProduct->WHITE_LOGO);
$EditArr['UseStore']=V($EditArr['UseStore'],$Settings->USE_STORE);
$EditArr['FromEmail']=V($EditArr['FromEmail'],$Settings->FROM_EMAIL);
$EditArr['OnlinePeriod']=V($EditArr['OnlinePeriod'],$Settings->ONLINE_PERIOD);
$EditArr['UseIp']=V($EditArr['UseIp'],$Settings->IP_TRACKING);
$EditArr['IpPeriod']=V($EditArr['IpPeriod'],$Settings->IP_PERIOD);
$EditArr['IpNoCookie']=V($EditArr['IpNoCookie'],$Settings->IP_NO_COOKIE);
$EditArr['EnableFraud']=V($EditArr['EnableFraud'],$Settings->FRAUD_ENABLE);
$EditArr['FraudPeriod']=V($EditArr['FraudPeriod'],$Settings->FRAUD_PERIOD);
$EditArr['FraudCount']=V($EditArr['FraudCount'],$Settings->FRAUD_COUNT);
$EditArr['UseWhiteLogo']=V($EditArr['UseWhiteLogo'],$Settings->WHITE_NO_LOGO);
$EditArr['UseWhiteCopy']=V($EditArr['UseWhiteCopy'],$Settings->WHITE_NO_COPY);
$EditArr['VarCamp']=V($EditArr['VarCamp'],$Settings->VAR_CAMPAIGN);
$EditArr['VarCampSource']=V($EditArr['VarCampSource'],$Settings->VAR_CAMPAIGN_SOURCE);
$EditArr['VarKw']=V($EditArr['VarKw'],$Settings->VAR_KW);
$EditArr['VarKeyword']=V($EditArr['VarKeyword'],$Settings->VAR_KEYWORD);
$EditArr['CatchCharset']=V($EditArr['CatchCharset'],$Settings->CATCH_CHARSET);
$EditArr['SessionTime']=V($EditArr['SessionTime'],$Settings->SESSION_BREAK_TIME);
$EditArr['SaleOnlyExisting']=V($EditArr['SaleOnlyExisting'],$Settings->SALE_ONLY_EXISTING);
$EditArr['IgnoreAllBots']=V($EditArr['IgnoreAllBots'],$Settings->IGNORE_ALL_BOTS);
$EditArr['FormatDate']=V($EditArr['FormatDate'],$Settings->FORMAT_DATE);
$EditArr['FormatTime']=V($EditArr['FormatTime'],$Settings->FORMAT_TIME);
$EditArr['CacheRowsCnt']=V($EditArr['CacheRowsCnt'],$Settings->CACHE_ROWS_CNT);
$EditArr['Delayed']=V($EditArr['Delayed'],$Settings->DELAYED_TRACKING);
$EditArr['DefPeriod']=V($EditArr['DefPeriod'],$Settings->DEFAULT_PERIOD);
$EditArr['AuthKey']=V($EditArr['AuthKey'],$Settings->AUTH_KEY);
$EditArr['RssRows']=V($EditArr['RssRows'],$Settings->RSS_ROWS);

	$PriorArr=explode("|", $Settings->TRACKING_MODE);
	$EditArr['TrafficPrior']=ValidVar($PriorArr[0], "NONE");
	if (ValidVar($PriorArr[1])) {
		$EntryArr=explode(";", $PriorArr[1]);
		for($i=0;$i<count($EntryArr);$i++) {
			$TmpArr=explode(":", $EntryArr[$i]);
			if ($TmpArr[0]=="NONE") $EditArr['NoneEntryPrior']=$TmpArr[1];
			if ($TmpArr[0]=="PAID") $EditArr['PaidEntryPrior']=$TmpArr[1];
			if ($TmpArr[0]=="NATURAL") $EditArr['NaturalEntryPrior']=$TmpArr[1];
		}
	}
	$EditArr['NoneEntryPrior']=ValidVar($EditArr['NoneEntryPrior'], "LAST");
	$EditArr['PaidEntryPrior']=ValidVar($EditArr['PaidEntryPrior'], "LAST");
	$EditArr['NaturalEntryPrior']=ValidVar($EditArr['NaturalEntryPrior'], "LAST");



include $nsTemplate->Inc();

/////////////////////////////////////////////
///////// process functions here

function SaveSettings($EditArr)
{
	global $Db, $nsProduct, $Lang, $Logs, $Settings;
	$DoRedir=true;
	extract($EditArr);
	if (!isset($UseIp)) $UseIp=0;
	if (!isset($EnableFraud)) $EnableFraud=0;
    if (!isset($SessionTime)) $SessionTime=0;
	if (!isset($IpNoCookie)) $IpNoCookie=0;
	if (!isset($UseWhiteLogo)) $UseWhiteLogo=0;
	if (!isset($UseWhiteCopy)) $UseWhiteCopy=0;
	if (!isset($TrafficPrior)) $TrafficPrior="NONE";
	if (!isset($NoneEntryPrior)) $NoneEntryPrior="LAST";
	if (!isset($PaidEntryPrior)) $PaidEntryPrior="LAST";
	if (!isset($NaturalEntryPrior)) $NaturalEntryPrior="LAST";
    $CacheRowsCnt=V($CacheRowsCnt,20);
    $Delayed=V($Delayed,0);
    $DefPeriod=V($DefPeriod,'');
    $AuthKey =V($AuthKey,'');
    $RssRows = V($RssRows, 200);

    if ($CacheRowsCnt>100) $Logs->Alert($Lang['ConstRowsAlert']);

	$TrackingMode=$TrafficPrior."|NONE:$NoneEntryPrior;PAID:$PaidEntryPrior;NATURAL:$NaturalEntryPrior";
	$VarCamp=RemoveMiscSymb($VarCamp, "_");
	$VarCampSource=RemoveMiscSymb($VarCampSource, "_");
	$VarKw=RemoveMiscSymb($VarKw, "_,");
	$VarKeyword=RemoveMiscSymb($VarKeyword, "_");
	if (!V($FraudPeriod)) $FraudPeriod=1;
	if (!V($FraudCount)) $FraudCount=5;
	SetParam("P3P", "STRVAL", $P3P);
	SetParam("P3P_REF", "STRVAL", $P3P_REF);
	if (!V($DefSkin)) $DefSkin=$nsProduct->DEFAULT_SKIN;
	if (!V($DefLang)) $DefLang=$nsProduct->DEFAULT_LANG;
	if (!$nsProduct->WHITE||!ValidVar($WhiteLogo)) $WhiteLogo="";
	if (!V($UseStore)) $UseStore=0;
    $CatchCharset=V($CatchCharset,0);
    $SaleOnlyExisting=V($SaleOnlyExisting,0);
    $IgnoreAllBots=V($IgnoreAllBots,0);
    $FormatDate=V($FormatDate,'');
    $FormatTime=V($FormatTime,'');

	if ($UseStore&&!CheckStore()) {
		$Logs->Err($Lang['WriteErr']);
		$UseStore=0;
		$GLOBALS['EditArr']['UseStore']=0;
		$DoRedir=false;
	}
	if ($UseStore&&$UseStore!=$Settings->USE_STORE) {
		RebuildStoreFiles();
	}

	$Query = "UPDATE ".PFX."_system_product SET
        DEFAULT_SKIN = ?, DEFAULT_LANG=?, WHITE_LOGO=? WHERE ID = ?";
	$Db->Query($Query, $DefSkin, $DefLang, $WhiteLogo, $nsProduct->ID);


	$Query = "
		UPDATE ?_config SET
			SSL_LINK = ?,
			USE_STORE=?,
			CATCH_CHARSET=?,
			FROM_EMAIL = ?,
			ONLINE_PERIOD = ?,
			IP_TRACKING=?,
			IP_NO_COOKIE=?,
			IP_PERIOD=?,
			FRAUD_ENABLE=?,
			FRAUD_COUNT=?,
			FRAUD_PERIOD=?,
			VAR_CAMPAIGN=?,
			VAR_CAMPAIGN_SOURCE=?,
			VAR_KW=?,
			VAR_KEYWORD=?,
			WHITE_NO_LOGO=?,
			WHITE_NO_COPY=?,
			TRACKING_MODE=?,
            SESSION_BREAK_TIME=?,
            SALE_ONLY_EXISTING=?,
            FORMAT_DATE=?,
            FORMAT_TIME=?,
            CACHE_ROWS_CNT=?,
            DELAYED_TRACKING=?,
            DEFAULT_PERIOD=?,
            IGNORE_ALL_BOTS=?,
            AUTH_KEY=?,
            RSS_ROWS=?
		WHERE COMPANY_ID=0 AND SITE_ID=0";
	$Db->Query($Query,
                    $SSLink, $UseStore,$CatchCharset,
					$FromEmail, abs(intval($OnlinePeriod)), $UseIp,$IpNoCookie,
					abs(intval($IpPeriod)), $EnableFraud, abs(intval($FraudCount)),abs(intval($FraudPeriod)),
					$VarCamp,$VarCampSource,$VarKw,$VarKeyword,
                    $UseWhiteLogo, $UseWhiteCopy, $TrackingMode, $SessionTime,$SaleOnlyExisting,
                    $FormatDate,$FormatTime,$CacheRowsCnt,$Delayed,$DefPeriod, $IgnoreAllBots, $AuthKey, $RssRows);

	if ($DoRedir) $nsProduct->Redir("misc_config", "RUpd=1", "admin");

}

function CheckStore() {
	if (!is_dir(SELF."/store")) return false;
	$Filename="test.txt";
	$f=@fopen(SELF."/store/$Filename", "a+");
	if (!$f) return false;
    @fclose($f);
	if (!@is_writable(SELF."/store/$Filename")) return false;
	@unlink(SELF."/store/$Filename");
	return true;
}


function ChangeTracking($Mode)
{
	global $Db;
	if ($Mode==-1) $Mode=0;
	$Query = "UPDATE ?_config SET STOP_TRACKING = ? WHERE COMPANY_ID=0 AND SITE_ID=0";
	$Db->Query($Query,$Mode);
}


/////////////////////////////////////////////
///////// library section


function RebuildStoreFiles()
{
	$ActionFile="redir_action.nodb";
	$f=@fopen(SELF."/store/$ActionFile", "a+");
	@flock($f, LOCK_EX);
	@ftruncate($f, 0);
	@flock($f, LOCK_UN);
	@fclose($f);

	$SplitFile="split_test.nodb";
	$f=@fopen(SELF."/store/$SplitFile", "a+");
	@flock($f, LOCK_EX);
	@ftruncate($f, 0);
	@flock($f, LOCK_UN);
	@fclose($f);

	$Query = "SELECT * FROM ?_visitor_action WHERE REDIRECT_CATCH='1' ";
	$Sql = new Query($Query);
	while ($Row=$Sql->Row()) {
		$ActionArr['ID']=$Row->ID;
		$ActionArr['PAGE_ID']=$Row->PAGE_ID;
		$ActionArr['SITE_ID']=$Row->SITE_ID;
		$ActionArr['REDIRECT_URL']=$Row->REDIRECT_URL;
		$ActionArr['PATH']=$Row->PATH;
		SaveActionToFile($ActionArr, $ActionFile);
	}

	$Query = "SELECT ID FROM ?_split_test";
	$Sql = new Query($Query);
	while ($Row=$Sql->Row()) SaveSplitToFile(false, $SplitFile, $Row->ID);
}


?>
Return current item: Stuffed Tracker - Web Traffic Monitoring & Analysis