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



/////////////////////////////////////////////
///////// require libraries here
require_once SYS."/system/lib/validate.func.php";
require_once SELF."/class/customreport.class.php";
require_once SELF."/lib/reports/misc.func.php";
$nsLang->TplInc("inc/menu");
$nsLang->TplInc("admin.reports");
$nsLang->TplInc("constructor/constructor_form");
$nsLang->IncFile("inc/cache.php");


/////////////////////////////////////////////
///////// prepare any variables
$SiteId=V($_REQUEST['SiteId']);
$CpId=V($_REQUEST['CpId']);
$StartDate=(ValidDate($_GP['StartDate']))? $_GP['StartDate']:false;
$EndDate=(ValidDate($_GP['EndDate']))? $_GP['EndDate']:false;
$ViewDate=(ValidDate($_GP['ViewDate']))? $_GP['ViewDate']:false;
$FormClicked=V($_REQUEST['FormClicked']);
$DynamicPeriod=V($_REQUEST['DynamicPeriod'],"-1");
$Depth=intval(V($_REQUEST['Depth'],"3"));
if($DynamicPeriod=='0-a-0') $DynamicPeriod="-1";
$Limit=V($_REQUEST['Limit'],10);

$StartDay=false;
$EndDay=false;
$SitesArr=array();

$nsLang->TplInc("constructor/periods");
// Ñïèñîê ïåðèîäîâ èç áàçû
$FormPeriodsArr=array();
$Query = "SELECT * FROM ?_periods WHERE COMPANY_ID IN (0, $CpId) AND DELETED != '1' ORDER BY TEMPLATE";
$Sql = new Query($Query);
while ($Row=$Sql->Row()) {
    if (!$Row->NAME && isset($Lang[$Row->TEMPLATE])) $Row->NAME=$Lang[$Row->TEMPLATE];
    $FormPeriodsArr[$Row->TEMPLATE]=$Row;
}
$PArr=array_keys($FormPeriodsArr);
usort($PArr,"SortPeriods");
$FormPeriodsArr=SyncKeysWValues($FormPeriodsArr,$PArr);    

$ShowPageTitles=array();

if (!ValidId($SiteId)&&!ValidId($CpId)) $nsProduct->Redir("default");
if (ValidId($CpId)) {
    $Query = "SELECT * FROM ?_client WHERE ID = ?";
    $Comp=$Db->Select($Query, false, $CpId);
    $PageTitle=$Comp->NAME;
    $Query = "
        SELECT S.ID, S.HOST, C.SHOW_PAGE_TITLE
        FROM ?_site S
            INNER JOIN ?_config C
                ON C.SITE_ID=S.ID
        WHERE S.COMPANY_ID=$CpId
    ";
    $Sql = new Query($Query, false, $CpId);
    while ($Row=$Sql->Row()) {
        $SitesArr[]=$Row;
        $ShowPageTitles[$Row->ID]=$Row->SHOW_PAGE_TITLE;
        $IdArr[]=$Row->ID;
    }
    $SiteList=implode(",", $IdArr);
}
if (ValidId($SiteId)) {
    $Query = "SELECT * FROM ?_site WHERE ID = ?";
    $Site=$Db->Select($Query, false, $SiteId);
    $PageTitle=$Site->HOST;
    $SiteList=$SiteId;
}
$PageTitle.=" : ".$Lang['Title'];

$ProgPath[0]['Name']=$Lang['MReports'];
$ProgPath[0]['Url']=getUrl("reports", "CpId=$CpId&SiteId=$SiteId", "admin");
$ProgPath[1]['Name']=$Lang['OtherReports'];
$ProgPath[1]['Url']=getUrl("reports", "Tab=Custom&CpId=$CpId&SiteId=$SiteId", "admin");
$ProgPath[2]['Name']=$Lang['PopularPath'];
$ProgPath[2]['Url']=getUrl("popular_path", "CpId=$CpId&SiteId=$SiteId", "report");

if (!$StartDate&&!$EndDate&&!$ViewDate&&!$FormClicked) $ViewDate=UserDate();
$MenuSection="logs";




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

$WhereArr=array();
$WhereStr="";
$DynamicDate="";
if ($DynamicPeriod!="-1" && $DynamicPeriod!==""  && $DynamicPeriod!=="0-a-0") {
    $DynamicDate=GetDateFromPeriod($DynamicPeriod,true);
    $StartDay=$StartDate=$DynamicDate['StartDate'];
    $EndDay=$EndDate=$DynamicDate['EndDate'];
    $ViewDate="";
} else {
    if ($StartDate) $StartDay=$StartDate." 00:00:00";
    if ($EndDate) $EndDay=$EndDate." 00:00:00";
}
if ($ViewDate) {
    $EndDay=$Db->ReturnValue("SELECT DATE_ADD('$ViewDate', INTERVAL 1 DAY)")." 00:00:00";
    $StartDay=$ViewDate." 00:00:00";
}
if ($StartDay&&!$EndDay) $WhereArr[]="S_LOG.STAMP >= DATE_ADD('$StartDay', INTERVAL '$nsUser->_SQL_TZ' HOUR_MINUTE)";
if (!$StartDay&&$EndDay) $WhereArr[]="S_LOG.STAMP <= DATE_ADD('$EndDay', INTERVAL '$nsUser->_SQL_TZ' HOUR_MINUTE)";
if ($StartDay&&$EndDay) $WhereArr[]="S_LOG.STAMP BETWEEN DATE_ADD('$StartDay', INTERVAL '$nsUser->_SQL_TZ' HOUR_MINUTE) AND DATE_ADD('$EndDay', INTERVAL '$nsUser->_SQL_TZ' HOUR_MINUTE)";
$WhereArr[]="S_LOG.SITE_ID IN ($SiteList)";
if ($Depth>1) $WhereArr[]="SESS.VISIT_DEPTH >= '$Depth' ";
if (Count($WhereArr)>0)     $WhereStr=implode(" AND ", $WhereArr);


$Query = "
    SELECT 
    SPATH.PATH,
    COUNT(SESS.ID) AS CNT,
    S_LOG.SITE_ID
    
    FROM ?_{$CpId}_stat_session SESS
    INNER JOIN ?_{$CpId}_stat_session_path SPATH
        ON SPATH.SESSION_ID=SESS.ID
    INNER JOIN ?_{$CpId}_stat_log S_LOG
        ON S_LOG.ID=SESS.START_LOG_ID

    WHERE $WhereStr
    GROUP BY SESS.VISIT_PATH
    ORDER BY 2 DESC
    LIMIT $Limit
";


$QueryArr=array('Paths'=>$Query);
$Cache=new CustomReport($CpId);
$Cache->CustomId=2;
$Cache->CacheJob($QueryArr,1);
$CustomReportId=2;


$Pages='';
$PqArr=array();
$TitleArr=array();
if (isset($Cache->Data['Paths']) && !empty($Cache->Data['Paths'])) $Paths = $Cache->Data['Paths'];
else $Paths= array();

if (!empty($Paths)) {
    if (!is_array($Paths)) {
        $Arr[0]=$Paths;
        $Paths=$Arr;
    }
    foreach ($Paths as $i=>$Row) {
         $Paths[$i]->PQ_ID=explode(",",$Row->PATH);
         if ($i>0) $Pages.=',';
         $Pages.=$Row->PATH;
    }
    $Query = "
        SELECT
        PQ.ID, SH.HOST, SP.PATH, Q.QUERY_STRING, PT.TITLE AS NAME, SH.SITE_ID
        FROM ?_page_query PQ
        INNER JOIN ?_site_host SH
            ON SH.ID=PQ.SITE_HOST_ID
        INNER JOIN ?_site_page SP
            ON SP.ID=PQ.PAGE_ID
        LEFT JOIN ?_query Q
            ON Q.ID=PQ.QUERY_ID
        LEFT JOIN ?_page_title PT
            ON PT.ID=PQ.TITLE_ID
        WHERE PQ.ID IN ($Pages)
    ";
    $Sql = new Query($Query);
    while ($Row=$Sql->Row()) {
        $Addr=$Row->HOST.$Row->PATH;
        if ($Row->QUERY_STRING) $Addr.='?'.$Row->QUERY_STRING;
        $TitleArr[$Row->ID]=$Row->NAME;
        $PqArr[$Row->ID]=$Addr;
    }
}


include $nsTemplate->Inc();

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





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





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