function SaveReport($SaveArr, $WhereArr) { global $Db, $Logs, $nsUser, $nsProduct, $NaturalConstPath, $PaidConstPath, $Lang; if (ValidVar($SaveArr['SaveMode']) == "NATURAL") { $OrderConstPath = $NaturalConstPath; $ConstPath = "natural_constructor"; } if (ValidVar($SaveArr['SaveMode']) == "PAID") { $OrderConstPath = $PaidConstPath; $ConstPath = "paid_constructor"; } if (!ValidVar($SaveArr['Name'])) { $Logs->Err($Lang['NameMustFill']); return; } if (ValidVar($SaveArr['SaveMode']) != "NATURAL" && ValidVar($SaveArr['SaveMode']) != "PAID") { $Logs->Err($Lang['SaveErr1']); return; } if (!ValidVar($SaveArr['GroupBy'])) { $Logs->Err($Lang['SaveErr1']); return; } foreach ($WhereArr as $i => $Row) { if (!isset($OrderConstPath[$Row['Mode']])) { $Logs->Err($Lang['SaveErr1']); return; } } if (ValidVar($SaveArr['ViewDate']) && !ValidDate($SaveArr['ViewDate']) || ValidVar($SaveArr['StartDate']) && !ValidDate($SaveArr['StartDate']) || ValidVar($SaveArr['EndDate']) && !ValidDate($SaveArr['EndDate'])) { $Logs->Err($Lang['ValidDates']); return; } $WhereArrStr = serialize($WhereArr); $CurrentDate = ValidVar($SaveArr['CurrentDate']) ? $SaveArr['CurrentDate'] : 0; $SaveMode = ValidVar($SaveArr['SaveMode']) ? $SaveArr['SaveMode'] : 0; $CpId = ValidVar($SaveArr['CpId']) ? $SaveArr['CpId'] : 0; $GroupBy = ValidVar($SaveArr['GroupBy']) ? $SaveArr['GroupBy'] : false; $DatesUsed = ValidVar($SaveArr['DatesUsed']) ? $SaveArr['DatesUsed'] : false; $ViewDate = ValidVar($SaveArr['ViewDate']) ? $SaveArr['ViewDate'] : false; $StartDate = ValidVar($SaveArr['StartDate']) ? $SaveArr['StartDate'] : false; $EndDate = ValidVar($SaveArr['EndDate']) ? $SaveArr['EndDate'] : false; $Filter = ValidVar($SaveArr['Filter']) ? $SaveArr['Filter'] : false; $Limit = ValidId($SaveArr['Limit']) ? $SaveArr['Limit'] : 0; $ShowAll = ValidVar($SaveArr['ShowAll']) ? $SaveArr['ShowAll'] : 0; $OrderBy = ValidVar($SaveArr['OrderBy']) ? $SaveArr['OrderBy'] : false; $OrderTo = ValidVar($SaveArr['OrderTo']) ? $SaveArr['OrderTo'] : "ASC"; $Name = ValidVar($SaveArr['Name']) ? addslashes($SaveArr['Name']) : false; $UserId = $nsUser->UserId(); $AddToMy = ValidVar($SaveArr['AddToMy']) ? $SaveArr['AddToMy'] : false; $Query = "\n\t\tINSERT INTO " . PFX . "_tracker_user_report \n\t\t\t(CONST_TYPE, COMPANY_ID, NAME, VIEW_DATE, START_DATE, END_DATE, FILTER, PAGE_LIMIT, SHOW_NO_REF, SORT_BY, SORT_ORDER, USE_CURRENT_DATE, GROUP_BY, WHERE_ARR)\n\t\t\tVALUES \n\t\t\t('{$SaveMode}', {$CpId}, '{$Name}', '{$ViewDate}', '{$StartDate}', '{$EndDate}', '{$Filter}', {$Limit}, '{$ShowAll}', '{$OrderBy}', '{$OrderTo}', '{$CurrentDate}', '{$GroupBy}', '{$WhereArrStr}')\n\t\t"; $Db->Query($Query); $NewId = $Db->LastInsertId; if ($AddToMy) { $Query = "INSERT INTO " . PFX . "_tracker_watch (USER_ID, REPORT_ID) VALUES ({$UserId}, {$NewId})"; $Db->Query($Query); } $nsProduct->Redir($ConstPath, "RUpd=1&ConstId={$NewId}&CpId=" . ValidVar($SaveArr['CpId']), "report"); }
///////////////////////////////////////////// ///////// require libraries here require_once SELF . "/lib/delete.func.php"; require_once SYS . "/system/lib/validate.func.php"; require_once SELF . "/class/graph.class.php"; ///////////////////////////////////////////// ///////// prepare any variables $PageTitle = $Lang['Title']; $nsLang->TplInc("inc/user_welcome"); $ProgPath[0]['Name'] = $Lang['Administr']; $ProgPath[0]['Url'] = getURL("admin", "", "admin"); $ProgPath[1]['Name'] = $PageTitle; $ProgPath[1]['Url'] = getURL("base_stat", "", "admin"); $MenuSection = "admin"; $DoOptimize = ValidVar($_GP['DoOptimize']) ? true : false; $EndDate = ValidDate($_GP['EndDate']) ? $_GP['EndDate'] : false; $DoClear = ValidVar($_GP['DoClear']) ? true : false; $ForClient = ValidId($_GP['ForClient']) ? $_GP['ForClient'] : false; $SiteId = ValidId($_GP['SiteId']) ? $_GP['SiteId'] : false; $EndTime = false; if ($EndDate) { $EndTime = $EndDate . " 23:59:59"; } if (!$ForClient && ValidVar($_GP['ForClient']) != "all" && ValidId($CurrentCompany->ID)) { $ForClient = $CurrentCompany->ID; } $ClientsArr = array(); $StatLogArr = array(); $ActionLogArr = array(); $SaleLogArr = array(); $SplitLogArr = array();
function Where() { global $nsUser; $StartStamp = false; $EndStamp = false; if (ValidDate($this->ViewDate)) { $StartStamp = $this->ViewDate . " 00:00:00"; $EndStamp = $this->ViewDate . " 23:59:59"; } if (ValidDate($this->StartDate)) { $StartStamp = $this->StartDate . " 00:00:00"; } if (ValidDate($this->EndDate)) { $EndStamp = $this->EndDate . " 23:59:59"; } if ($StartStamp && $EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) BETWEEN '{$StartStamp}' AND '{$EndStamp}'"; } if ($StartStamp && !$EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) >= '{$StartStamp}'"; } if (!$StartStamp && $EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) <= '{$EndStamp}'"; } if (ValidId($this->SplitId)) { $this->WhereArr[] = "S_SPLIT.SPLIT_ID = " . $this->SplitId; } }
///////////////////////////////////////////// ///////// prepare any variables $CpId = ValidVar($_GP['CpId']) ? $_GP['CpId'] : false; $GroupBy = ValidVar($_GP['GroupBy']) ? $_GP['GroupBy'] : false; $CurrentGroupBy = ValidVar($_GP['CurrentGroupBy']) ? $_GP['CurrentGroupBy'] : false; $WhereArr = ValidArr($_GP['WhereArr']) ? $_GP['WhereArr'] : false; if (!ValidArr($WhereArr)) { $WhereArr = array(); } $CurrentId = ValidArr($_GP['CurrentId']) ? $_GP['CurrentId'] : false; if (!ValidArr($CurrentId)) { $CurrentId = array(); } $StartDate = ValidDate($_GP['StartDate']) ? $_GP['StartDate'] : false; $EndDate = ValidDate($_GP['EndDate']) ? $_GP['EndDate'] : false; $ViewDate = ValidDate($_GP['ViewDate']) ? $_GP['ViewDate'] : false; $Month = ValidVar($_GP['Month']) ? $_GP['Month'] : false; $CampId = ValidVar($_GP['CampId']) ? $_GP['CampId'] : false; $GrpId = ValidVar($_GP['GrpId']) ? $_GP['GrpId'] : false; $Filter = ValidVar($_GP['Filter']) ? trim($_GP['Filter']) : false; $Limit = ValidVar($_GP['Limit']) ? intval($_GP['Limit']) : 100; $OrderTo = ValidVar($_GP['OrderTo']) ? $_GP['OrderTo'] : false; $OrderBy = ValidVar($_GP['OrderBy']) ? $_GP['OrderBy'] : false; $ConstId = ValidId($_GP['ConstId']) ? $_GP['ConstId'] : false; $General = ValidVar($_GP['General']) ? $_GP['General'] : false; $ExportReport = ValidArr($_GP['ExportReport']) ? $_GP['ExportReport'] : false; $FormUsed = ValidVar($_GP['FormUsed']) == 1 ? true : false; $Redir = ValidVar($_GP['Redir']) == 1 ? true : false; $Print = ValidVar($_GP['Print']) ? $_GP['Print'] : false; $ShowFilter = $nsUser->ADVANCED_MODE ? 1 : 0; if (isset($_GP['ShowFilter'])) {
function ImportReport($Id = false) { if (!$Id) { return false; } global $Db, $nsUser, $CpId, $nsProduct; $Where = ""; if (!$nsUser->ADMIN) { $Where = "AND COMPANY_ID=" . $nsUser->COMPANY_ID; } $Query = "SELECT * FROM " . PFX . "_tracker_user_report WHERE ID = {$Id} {$Where}"; $Import = $Db->Select($Query); if (!ValidId($Import->ID)) { return false; } if ($Import->COMPANY_ID > 0 && $Import->COMPANY_ID != $CpId) { Redir($nsProduct->SelfAction("CpId=" . $Import->COMPANY_ID . "&ConstId=" . $Import->ID)); } $WhereArr = unserialize($Import->WHERE_ARR); if (!ValidArr($WhereArr)) { return false; } for ($i = 0; $i < count($WhereArr); $i++) { if (!ValidVar($WhereArr[$i]['OrderBy'])) { $WhereArr[$i]['OrderBy'] = "CNT"; } if (!ValidVar($WhereArr[$i]['OrderTo'])) { $WhereArr[$i]['OrderTo'] = "DESC"; } } $GLOBALS['WhereArr'] = $WhereArr; $DatesUsed = false; for ($i = 0; $i < count($WhereArr); $i++) { if ($WhereArr[$i]['Mode'] == "Month" || $WhereArr[$i]['Mode'] == "Date") { $DatesUsed = true; break; } } if (!$DatesUsed) { $ViewDate = $Import->VIEW_DATE != "0000-00-00" && ValidDate($Import->VIEW_DATE) ? $Import->VIEW_DATE : false; $StartDate = $Import->START_DATE != "0000-00-00" && ValidDate($Import->START_DATE) ? $Import->START_DATE : false; $EndDate = $Import->END_DATE != "0000-00-00" && ValidDate($Import->END_DATE) ? $Import->END_DATE : false; if ($ViewDate && $Import->USE_CURRENT_DATE) { $ViewDate = date("Y-m-d"); } if ($EndDate && $Import->USE_CURRENT_DATE) { $EndDate = date("Y-m-d"); } if ($Import->USE_CURRENT_DATE && !$ViewDate && !$EndDate) { $ViewDate = date("Y-m-d"); } $GLOBALS['ViewDate'] = $ViewDate; $GLOBALS['StartDate'] = $StartDate; $GLOBALS['EndDate'] = $EndDate; } $GLOBALS['Limit'] = ValidVar($Import->PAGE_LIMIT) > 0 ? $Import->PAGE_LIMIT : false; $GLOBALS['Filter'] = ValidVar($Import->FILTER); $GLOBALS['ShowAll'] = $Import->SHOW_NO_REF == 1 ? 1 : false; $GLOBALS['OrderBy'] = ValidVar($Import->SORT_BY); $GLOBALS['OrderTo'] = $Import->SORT_ORDER; $GLOBALS['GroupBy'] = ValidVar($Import->GROUP_BY); return true; }
function Where() { global $nsUser; if (!$this->SiteId && $this->CpId) { $this->SiteIds = $this->GetSiteIds($this->CpId); } if ($this->SiteId) { $this->SiteIds = $this->SiteId; } if ($this->SiteIds) { $this->WhereArr[] = "S_LOG.SITE_ID IN (" . $this->SiteIds . ")"; } $StartStamp = false; $EndStamp = false; if (ValidDate($this->ViewDate)) { $StartStamp = $this->ViewDate . " 00:00:00"; $EndStamp = $this->ViewDate . " 23:59:59"; } if (ValidDate($this->StartDate)) { $StartStamp = $this->StartDate . " 00:00:00"; } if (ValidDate($this->EndDate)) { $EndStamp = $this->EndDate . " 23:59:59"; } if ($StartStamp && $EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) BETWEEN '{$StartStamp}' AND '{$EndStamp}'"; } if ($StartStamp && !$EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) >= '{$StartStamp}'"; } if (!$StartStamp && $EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) <= '{$EndStamp}'"; } if (!$this->NoRef && !$this->KeyId && !$this->HostId && !$this->HostGrp && !$this->RsNeeded && !$this->OnlyNoRef) { $this->WhereArr[] = "S_LOG.REFERER_SET>0"; } if ($this->OnlyNoRef) { $this->WhereArr[] = "S_LOG.REFERER_SET=0"; } if (ValidDate($this->ViewDate)) { $this->UseStraight = true; } if (ValidId($this->KeyId)) { $this->WhereArr[] = "RS.NATURAL_KEY=" . $this->KeyId; } if (ValidId($this->HostId)) { $this->WhereArr[] = "RS.HOST_ID=" . $this->HostId; } if (ValidId($this->HostGrp) && !ValidId($this->HostId)) { $this->JoinArr[] = "INNER JOIN " . PFX . "_tracker_host TH ON TH.ID=RS.HOST_ID"; $this->WhereArr[] = "TH.GRP_ID=" . $this->HostGrp; } if ($this->RsNeeded !== false || $this->KeyId !== false || $this->HostId !== false || $this->HostGrp !== false) { array_unshift($this->JoinArr, "INNER JOIN " . PFX . "_tracker_referer_set RS ON RS.ID=S_LOG.REFERER_SET"); } }
function Where() { global $nsUser; if (!ValidId($this->SiteId) && $this->CpId) { $this->SiteIds = $this->GetSiteIds($this->CpId); } if (ValidId($this->SiteId)) { $this->SiteIds = $this->SiteId; } if ($this->SiteIds) { $this->WhereArr[] = "S_LOG.SITE_ID IN (" . $this->SiteIds . ")"; } $StartStamp = false; $EndStamp = false; if (ValidDate($this->ViewDate)) { $StartStamp = $this->ViewDate . " 00:00:00"; $EndStamp = $this->ViewDate . " 23:59:59"; //$EndStamp=$this->Db->ReturnValue("SELECT DATE_ADD('".$this->ViewDate."', INTERVAL 1 DAY)")." 00:00:00"; } if (ValidDate($this->StartDate)) { $StartStamp = $this->StartDate . " 00:00:00"; } if (ValidDate($this->EndDate)) { $EndStamp = $this->EndDate . " 23:59:59"; } if ($StartStamp && $EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) BETWEEN '{$StartStamp}' AND '{$EndStamp}'"; } if ($StartStamp && !$EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) >= '{$StartStamp}'"; } if (!$StartStamp && $EndStamp) { $this->WhereArr[] = "DATE_ADD(S_LOG.STAMP, INTERVAL '" . $nsUser->TZ . "' HOUR) <= '{$EndStamp}'"; } if ((ValidId($this->GrpId) || ValidId($this->CpId)) && !ValidId($this->CampId)) { $this->CampIds = $this->GetCampIds(); $this->WhereArr[] = "S_CLICK.CAMP_ID IN (" . implode(",", $this->CampIds) . ")"; } if (ValidId($this->CampId)) { $this->WhereArr[] = "S_CLICK.CAMP_ID = " . $this->CampId; $this->CampIds[] = $this->CampId; } if (ValidId($this->KeyId)) { $this->WhereArr[] = "S_CLICK.KEYWORD_ID = " . $this->KeyId; } if (ValidId($this->HostId)) { $this->WhereArr[] = "S_CLICK.SOURCE_HOST_ID = " . $this->HostId; } }