Location: PHPKode > projects > Stuffed Tracker - Web Traffic Monitoring & Analysis > stuffed-tracker-web-traffic-monitoring-analysis/actions/admin.user_cache.php
<?
if (!defined("NS_TRACKER_INDEX")) exit;
require_once SELF."/lib/reports/misc.func.php";
require_once SELF."/lib/reports/cache_path.func.php";

$RemoveReport=V($_REQUEST['RemoveReport'],array());

$nsLang->TplInc("constructor/periods");
$nsLang->TplInc("inc/reports");

$ProgPath[1]['Name']=$Lang['ReportsLog'];
$ProgPath[1]['Url']=$nsProduct->SelfAction("Mode=$Mode");

$Consult->CurrentHelp="hint";

if (!$nsUser->DEMO) {
    if (!empty($RemoveReport)) RemoveReports($RemoveReport);
}

$Query = "UPDATE ?_user_cache SET DONE=2 WHERE USER_ID=? AND DONE=1";
$Db->Query($Query, $nsUser->UserId());
$ToDone=$nsUser->REPORTS_DONE;
$nsUser->REPORTS_DONE=0;

$NeedsRefresh=false;

$Query = "
    SELECT 
    UC.*,
    DATE_FORMAT(DATE_ADD(UC.STAMP, INTERVAL '$nsUser->SQL_TZ' HOUR_MINUTE), '%d.%m.%Y %H:%i') AS DT
    FROM ?_user_cache UC
    WHERE UC.USER_ID=".$nsUser->UserId()."
    ORDER BY UC.STAMP DESC
    LIMIT 50
";
$Sql = new Query($Query);
$CacheLog=array();
while ($Row=$Sql->Row()) $CacheLog[]=$Row;

$PrevArr=array();
foreach ($CacheLog as $i=>$Row) {
    if (!$Row->DONE) $NeedsRefresh=true;
    $Row->NAME="";
    $Row->URL="";
    if ($Row->REPORT_ID) {
        $Query = "SELECT R.NAME,R.MODE,G.NAME AS GNAME 
                FROM ?_static_report R
                    INNER JOIN ?_static_report_group G
                        ON G.ID=R.GROUP_ID 
                WHERE R.ID = $Row->REPORT_ID";
        $Report=$Db->Select($Query);
        if (!$Report) {
            unset($CacheLog[$i]);
            continue;
        }
        if (isset($Lang[$Report->NAME])) $Report->NAME=$Lang[$Report->NAME];
        if (isset($Lang[$Report->GNAME])) $Report->GNAME=$Lang[$Report->GNAME];
        $Row->NAME=$Report->GNAME." &raquo; ".$Report->NAME;
        $Query = "
            SELECT RP.PERIOD
                FROM ?_{$Row->COMPANY_ID}_static_report_cache RC
                    INNER JOIN ?_static_report_periods RP
                        ON RP.ID=RC.PERIOD_ID
                WHERE RC.REPORT_ID=? AND RC.CACHE_ID=?
        ";
        $Report->PERIOD=$Db->ReturnValue($Query, $Row->REPORT_ID, $Row->CACHE_ID);
        $Row->URL=getURL((($Report->MODE=="NATURAL")?"natural_constructor":"paid_constructor"),"ReportId=".$Row->REPORT_ID."&CpId=".$Row->COMPANY_ID."&DynamicPeriod=".$Report->PERIOD, "report");
    }
    elseif ($Row->FUNNEL_ID) {
        $Row->NAME=$Db->ReturnValue("SELECT NAME FROM ?_path WHERE ID=?",$Row->FUNNEL_ID);
        $Row->URL=getURL("funnel","FId=".$Row->FUNNEL_ID,"report");
    }
    elseif ($Row->CUSTOM_REPORT) {
        
        if ($Row->CUSTOM_REPORT==1) {
            $Row->NAME=$Lang['CompareReport'];
            $Row->URL=getURL("compare","CpId=".$Row->COMPANY_ID,"report");
        }
        if ($Row->CUSTOM_REPORT==2) {
            $Row->NAME=$Lang['PopularPath'];
            $Row->URL=getURL("popular_path","CpId=".$Row->COMPANY_ID,"report");
        }        
        if ($Row->CUSTOM_REPORT==3) {
            $Row->NAME=$Lang['BotStat'];
            $Row->URL=getURL("bot_stat","CpId=".$Row->COMPANY_ID,"report");
        }
    }
    else {
        if (in_array($Row->CACHE_ID,$PrevArr)) {
            unset($CacheLog[$i]);
            continue;
        }
        $Query = "
            SELECT C.*, QS.PARAMS_SET
            FROM ?_{$Row->COMPANY_ID}_cache C
                INNER JOIN ?_{$Row->COMPANY_ID}_cache_query_set QS
                    ON QS.ID=C.QUERY_SET_ID 
            WHERE C.ID=?";
        $Cache=$Db->Select($Query, false, $Row->CACHE_ID);
        if (!$Cache) continue;
        $Row->Cache=$Cache;
        if ($Cache->MODE=="SPLIT") {
            $Arr=unserialize($Cache->PARAMS_SET);
            $SplitId=$Arr['SplitId'];
            $Query = "SELECT NAME FROM ?_camp_piece WHERE ID=$SplitId";
            $Row->NAME=$Db->ReturnValue($Query);
            $Row->URL=getURL("split_test", "SplitId=$SplitId", "report");
        }
        if ($Cache->MODE=="CUSTOM") continue;
        if ($Cache->MODE=="NATURAL"||$Cache->MODE=="PAID") {
            $Arr=unserialize($Cache->PARAMS_SET);
            $PathArr=CachePath($Arr['WhereArr'], $Row->COMPANY_ID);
            foreach ($Arr as $k=>$v) {
                if ($k=="WhereArr") continue;
                $PathArr['Path'].="&$k=$v";
            }
            $Row->NAME=$PathArr['Name'];
            if ($Cache->MODE=="NATURAL") {
                $Row->URL=getURL("natural_constructor",$PathArr['Path']."&CpId=".$Row->COMPANY_ID,"report");
            }
            if ($Cache->MODE=="PAID") {
                $Row->URL=getURL("paid_constructor",$PathArr['Path']."&CpId=".$Row->COMPANY_ID,"report");
            }            
        }
        $PrevArr[]=$Row->CACHE_ID;
    }
    if (!$Row->NAME) {
        unset($CacheLog[$i]);
        continue;
    }
    
    $CacheLog[$i]=$Row;
}



include $nsTemplate->Inc("admin.user_cache");





function RemoveReports($Arr)
{
    global $Db, $nsProduct, $nsUser;
    
    // ñîáèðàåì ìàññèâ ðàçíûõ çàïèñåé êåøà
    // îäèíàêîâûå çàïèñè â ëèñòå íå ïîêàçûâàþòñÿ, ïîýòîìó íàäî óäàëèòü òàê æå âñå çàïèñè
    // ó êîòîðûõ òàêîé æå CACHE_ID
    $CacheArr = array();
    $Query = "SELECT DISTINCT CACHE_ID FROM ?_user_cache WHERE ID IN (?) AND USER_ID=? AND CACHE_ID>0";
    $Sql = new Query($Query, false, $Arr, $nsUser->UserId());
    while ($Row=$Sql->Row()) $CacheArr[]=$Row->CACHE_ID;

    $Query = "DELETE FROM ?_user_cache WHERE ID IN (?) AND USER_ID=? AND DONE>0";
    $Db->Query($Query,$Arr,$nsUser->UserId());
    
    // çàîäíî íàäî îòìåíèòü ïîäãîòîâêó îò÷åòîâ, åñëè îíè åùå íå áûëè ïîäãîòîâëåíû, à èç ëèñòà èõ óäàëèëè
    $Query = "SELECT * FROM ?_user_cache WHERE ID IN (?) AND USER_ID=? AND DONE=0";
    $Sql = new Query($Query,false,$Arr,$nsUser->UserId());
    while ($Row=$Sql->Row()) {
        $Query = "SELECT ID FROM ?_user_cache WHERE CACHE_ID=? AND USER_ID!=? AND DONE=0";
        $CheckId=$Db->ReturnValue($Query,$Row->CACHE_ID,$nsUser->UserId());
        if (!$CheckId) {
            $Query = "UPDATE ?_{$Row->COMPANY_ID}_cache SET TO_CACHE='0' WHERE ID=?";
            $Db->Query($Query,$Row->CACHE_ID);
        }
    }
    $Query = "DELETE FROM ?_user_cache WHERE ID IN (?) AND USER_ID=?";
    $Db->Query($Query,$Arr,$nsUser->UserId());
    if (!empty($CacheArr)) {
        $Query = "DELETE FROM ?_user_cache WHERE CACHE_ID IN (?) AND USER_ID=?";
        $Db->Query($Query,$CacheArr,$nsUser->UserId());
    }
    $nsProduct->Redir("my_tracker","Mode=reports","admin");
}

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