function Page_Main()
 {
     global $Report13;
     global $rs;
     global $rsgrp;
     global $gsFormError;
     // Aggregate variables
     // 1st dimension = no of groups (level 0 used for grand total)
     // 2nd dimension = no of fields
     $nDtls = 1;
     $nGrps = 6;
     $this->Val = ewrpt_InitArray($nDtls, 0);
     $this->Cnt = ewrpt_Init2DArray($nGrps, $nDtls, 0);
     $this->Smry = ewrpt_Init2DArray($nGrps, $nDtls, 0);
     $this->Mn = ewrpt_Init2DArray($nGrps, $nDtls, NULL);
     $this->Mx = ewrpt_Init2DArray($nGrps, $nDtls, NULL);
     $this->GrandSmry = ewrpt_InitArray($nDtls, 0);
     $this->GrandMn = ewrpt_InitArray($nDtls, NULL);
     $this->GrandMx = ewrpt_InitArray($nDtls, NULL);
     // Set up if accumulation required
     $this->Col = array(FALSE);
     // Set up groups per page dynamically
     $this->SetUpDisplayGrps();
     $Report13->First_Name->SelectionList = "";
     $Report13->First_Name->DefaultSelectionList = "";
     $Report13->First_Name->ValueList = "";
     $Report13->Paper_Name->SelectionList = "";
     $Report13->Paper_Name->DefaultSelectionList = "";
     $Report13->Paper_Name->ValueList = "";
     // Load default filter values
     $this->LoadDefaultFilters();
     // Set up popup filter
     $this->SetupPopup();
     // Extended filter
     $sExtendedFilter = "";
     // Build popup filter
     $sPopupFilter = $this->GetPopupFilter();
     //ewrpt_SetDebugMsg("popup filter: " . $sPopupFilter);
     if ($sPopupFilter != "") {
         if ($this->Filter != "") {
             $this->Filter = "({$this->Filter}) AND ({$sPopupFilter})";
         } else {
             $this->Filter = $sPopupFilter;
         }
     }
     // Check if filter applied
     $this->FilterApplied = $this->CheckFilter();
     // Get sort
     $this->Sort = $this->GetSort();
     // Get total group count
     $sGrpSort = ewrpt_UpdateSortFields($Report13->SqlOrderByGroup(), $this->Sort, 2);
     // Get grouping field only
     $sSql = ewrpt_BuildReportSql($Report13->SqlSelectGroup(), $Report13->SqlWhere(), $Report13->SqlGroupBy(), $Report13->SqlHaving(), $Report13->SqlOrderByGroup(), $this->Filter, $sGrpSort);
     $this->TotalGrps = $this->GetGrpCnt($sSql);
     if ($this->DisplayGrps <= 0) {
         // Display all groups
         $this->DisplayGrps = $this->TotalGrps;
     }
     $this->StartGrp = 1;
     // Show header
     $this->ShowFirstHeader = $this->TotalGrps > 0;
     //$this->ShowFirstHeader = TRUE; // Uncomment to always show header
     // Set up start position if not export all
     if ($Report13->ExportAll && $Report13->Export != "") {
         $this->DisplayGrps = $this->TotalGrps;
     } else {
         $this->SetUpStartGroup();
     }
     // Get current page groups
     $rsgrp = $this->GetGrpRs($sSql, $this->StartGrp, $this->DisplayGrps);
     // Init detail recordset
     $rs = NULL;
 }
 function Page_Main()
 {
     global $CustomView2;
     global $rs;
     global $rsgrp;
     global $gsFormError;
     // Aggregate variables
     // 1st dimension = no of groups (level 0 used for grand total)
     // 2nd dimension = no of fields
     $nDtls = 2;
     $nGrps = 1;
     $this->Val = ewrpt_InitArray($nDtls, 0);
     $this->Cnt = ewrpt_Init2DArray($nGrps, $nDtls, 0);
     $this->Smry = ewrpt_Init2DArray($nGrps, $nDtls, 0);
     $this->Mn = ewrpt_Init2DArray($nGrps, $nDtls, NULL);
     $this->Mx = ewrpt_Init2DArray($nGrps, $nDtls, NULL);
     $this->GrandSmry = ewrpt_InitArray($nDtls, 0);
     $this->GrandMn = ewrpt_InitArray($nDtls, NULL);
     $this->GrandMx = ewrpt_InitArray($nDtls, NULL);
     // Set up if accumulation required
     $this->Col = array(FALSE, FALSE);
     // Set up groups per page dynamically
     $this->SetUpDisplayGrps();
     // Set up popup filter
     $this->SetupPopup();
     // Extended filter
     $sExtendedFilter = "";
     // Build popup filter
     $sPopupFilter = $this->GetPopupFilter();
     //ewrpt_SetDebugMsg("popup filter: " . $sPopupFilter);
     if ($sPopupFilter != "") {
         if ($this->Filter != "") {
             $this->Filter = "({$this->Filter}) AND ({$sPopupFilter})";
         } else {
             $this->Filter = $sPopupFilter;
         }
     }
     // No filter
     $this->FilterApplied = FALSE;
     // Get sort
     $this->Sort = $this->GetSort();
     // Get total count
     $sSql = ewrpt_BuildReportSql($CustomView2->SqlSelect(), $CustomView2->SqlWhere(), $CustomView2->SqlGroupBy(), $CustomView2->SqlHaving(), $CustomView2->SqlOrderBy(), $this->Filter, $this->Sort);
     $this->TotalGrps = $this->GetCnt($sSql);
     if ($this->DisplayGrps <= 0) {
         // Display all groups
         $this->DisplayGrps = $this->TotalGrps;
     }
     $this->StartGrp = 1;
     // Show header
     $this->ShowFirstHeader = $this->TotalGrps > 0;
     //$this->ShowFirstHeader = TRUE; // Uncomment to always show header
     // Set up start position if not export all
     if ($CustomView2->ExportAll && $CustomView2->Export != "") {
         $this->DisplayGrps = $this->TotalGrps;
     } else {
         $this->SetUpStartGroup();
     }
     // Get current page records
     $rs = $this->GetRs($sSql, $this->StartGrp, $this->DisplayGrps);
 }
 function GetColumns()
 {
     global $conn;
     global $Crosstab1;
     global $ReportLanguage;
     // Build SQL
     $sSql = ewrpt_BuildReportSql($Crosstab1->SqlDistinctSelect(), $Crosstab1->SqlDistinctWhere(), "", "", $Crosstab1->SqlDistinctOrderBy(), $this->Filter, "");
     // Load recordset
     $rscol = $conn->Execute($sSql);
     // Get distinct column count
     $this->ColCount = $rscol ? $rscol->RecordCount() : 0;
     if ($this->ColCount == 0) {
         if ($rscol) {
             $rscol->Close();
         }
         echo $ReportLanguage->Phrase("NoDistinctColVals") . $sSql . "<br />";
         exit;
     }
     // 1st dimension = no of groups (level 0 used for grand total)
     // 2nd dimension = no of distinct values
     $nGrps = 2;
     $this->Col = ewrpt_InitArray($this->ColCount + 1, NULL);
     $this->Val = ewrpt_InitArray($this->ColCount + 1, NULL);
     $this->ValCnt = ewrpt_InitArray($this->ColCount + 1, NULL);
     $this->Cnt = ewrpt_Init2DArray($this->ColCount + 1, $nGrps + 1, NULL);
     $this->Smry = ewrpt_Init2DArray($this->ColCount + 1, $nGrps + 1, NULL);
     $this->SmryCnt = ewrpt_Init2DArray($this->ColCount + 1, $nGrps + 1, NULL);
     // Reset summary values
     $this->ResetLevelSummary(0);
     $colcnt = 0;
     while (!$rscol->EOF) {
         if (is_null($rscol->fields[0])) {
             $wrkValue = EWRPT_NULL_VALUE;
             $wrkCaption = $ReportLanguage->Phrase("NullLabel");
         } elseif ($rscol->fields[0] == "") {
             $wrkValue = EWRPT_EMPTY_VALUE;
             $wrkCaption = $ReportLanguage->Phrase("EmptyLabel");
         } else {
             $wrkValue = $rscol->fields[0];
             $wrkCaption = $rscol->fields[0];
         }
         $colcnt++;
         $this->Col[$colcnt] = new crCrosstabColumn($wrkValue, $wrkCaption, TRUE);
         $rscol->MoveNext();
     }
     $rscol->Close();
     // Get active columns
     if (!is_array($Crosstab1->Total_Marks->SelectionList)) {
         $this->ColSpan = $this->ColCount;
     } else {
         $this->ColSpan = 0;
         for ($i = 1; $i <= $this->ColCount; $i++) {
             $bSelected = FALSE;
             $cntsel = count($Crosstab1->Total_Marks->SelectionList);
             for ($j = 0; $j < $cntsel; $j++) {
                 if (ewrpt_CompareValue($Crosstab1->Total_Marks->SelectionList[$j], $this->Col[$i]->Value, $Crosstab1->Total_Marks->FldType)) {
                     $this->ColSpan++;
                     $bSelected = TRUE;
                     break;
                 }
             }
             $this->Col[$i]->Visible = $bSelected;
         }
     }
     // Update crosstab sql
     $sSqlFlds = "";
     for ($colcnt = 1; $colcnt <= $this->ColCount; $colcnt++) {
         $sFld = ewrpt_CrossTabField($Crosstab1->SummaryType(), $Crosstab1->SummaryField(), $Crosstab1->ColumnField(), $Crosstab1->ColumnDateType(), $this->Col[$colcnt]->Value, "", "C" . $colcnt);
         if ($sSqlFlds != "") {
             $sSqlFlds .= ", ";
         }
         $sSqlFlds .= $sFld;
     }
     $this->SqlSelectWork = str_replace("<DistinctColumnFields>", $sSqlFlds, $Crosstab1->SqlSelect());
     $this->SqlSelectAggWork = str_replace("<DistinctColumnFields>", $sSqlFlds, $Crosstab1->SqlSelectAgg());
     // Update chart sql if Y Axis = Column Field
     $this->SqlChartWork = "";
     for ($i = 0; $i < $this->ColCount; $i++) {
         if ($this->Col[$i + 1]->Visible) {
             $sChtFld = ewrpt_CrossTabField("SUM", $Crosstab1->SummaryField(), $Crosstab1->ColumnField(), $Crosstab1->ColumnDateType(), $this->Col[$i + 1]->Value, "");
             if ($this->SqlChartWork != "") {
                 $this->SqlChartWork .= "+";
             }
             $this->SqlChartWork .= $sChtFld;
         }
     }
 }