Location: PHPKode > projects > Stuffed Tracker - Web Traffic Monitoring & Analysis > stuffed-tracker-web-traffic-monitoring-analysis/actions/admin.visit_length.php
<?
$PageTitle=$Lang['Title'];
$nsLang->TplInc("inc/menu");

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

$FromArr=V($_REQUEST['FromArr'],array());
$ToArr=V($_REQUEST['ToArr'],array());
$FromType=V($_REQUEST['FromType'],array());
$ToType=V($_REQUEST['ToType'],array());

$Consult->CurrentHelp="hint";

if (!empty($FromArr)) SavePeriods();


$Table = array();
$Query = "SELECT * FROM ?_visit_length ORDER BY LEN1 ASC";
$Sql = new Query($Query);
while ($Row=$Sql->Row()) {
    if ($Row->LEN2==1000000000) {$Row->LEN2='';$Row->LEN2_TYPE='s';}    
    $Row->LEN1_TYPE='s';
    if ($Row->LEN1>=60) {
        if (!($Row->LEN1%3600)) {$Row->LEN1=$Row->LEN1/3600; $Row->LEN1_TYPE='h';}
        elseif (!($Row->LEN1%60)) {$Row->LEN1=$Row->LEN1/60; $Row->LEN1_TYPE='m';}
    }
    $Row->LEN2_TYPE='s';
    if ($Row->LEN2>=60) {
        if (!($Row->LEN2%3600)) {$Row->LEN2=$Row->LEN2/3600; $Row->LEN2_TYPE='h';}
        elseif (!($Row->LEN2%60)) {$Row->LEN2=$Row->LEN2/60; $Row->LEN2_TYPE='m';}
    }
    if ($Row->LEN2==0) $Row->LEN2='';    
    $Table[]=$Row;
}



include $nsTemplate->Inc("inc/header");
include $nsTemplate->Inc();
include $nsTemplate->Inc("inc/footer");



function SavePeriods()
{
    global $FromArr,$ToArr,$FromType,$ToType,$Db,$nsProduct,$Logs;
    $DoNotDelete=array();
    foreach ($FromArr as $i=>$From) {
        if (strlen($From)==0) continue;
        if (!isset($FromType[$i])) continue;
        if (!V($ToArr[$i])) {$ToArr[$i]=1000000000;$ToType[$i]='s';}
        if (V($ToArr[$i])>1000000000) {$ToArr[$i]=1000000000;$ToType[$i]='s';}
        $NewId=SaveOnePeriod($From, $ToArr[$i],$FromType[$i],$ToType[$i]);
        if ($NewId>0) $DoNotDelete[]=$NewId;
        if ($Logs->HaveErr()) return false;
    }
    $Query = "DELETE FROM ?_visit_length";
    if (!empty($DoNotDelete)) $Query.=" WHERE ID NOT IN (?)";
    $Db->Query($Query,$DoNotDelete);
    $nsProduct->Redir("visit_length","","admin");
}

function SaveOnePeriod($From,$To,$FromType,$ToType)
{
    global $Db,$Lang,$Logs;
    if (!in_array($FromType,array('s','m','h'))) return false;
    if (!in_array($ToType,array('s','m','h'))) return false;
    if (strval(intval($From))!=$From) return false;
    if (strval(intval($To))!=$To) return false;
    $From=($FromType=='s')?$From:($FromType=='m'?$From*60:$From*3600);
    $To=($ToType=='s')?$To:($ToType=='m'?$To*60:$To*3600);
    $Query = "SELECT ID FROM ?_visit_length WHERE LEN1=? AND LEN2=?";
    $CheckId=$Db->ReturnValue($Query,$From,$To);
    if ($CheckId) return $CheckId;
    
    $Query = "INSERT INTO ?_visit_length (LEN1, LEN2) VALUES (?,?)";
    $Db->Query($Query,$From,$To);
    return $Db->LastInsertId;
}


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