PageRenderTime 90ms CodeModel.GetById 73ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/jf/web/reports/TKTrinhdoctb.php

http://tinkerportal.googlecode.com/
PHP | 1865 lines | 1366 code | 239 blank | 260 comment | 349 complexity | 25ff3ef192b56f5fab7fbe429b60ebbc MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2if (session_id() == "") session_start(); // Initialize Session data
   3ob_start();
   4?>
   5<?php include_once "phprptinc/ewrcfg5.php"; ?>
   6<?php include_once "phprptinc/ewmysql.php"; ?>
   7<?php include_once "phprptinc/ewrfn5.php"; ?>
   8<?php include_once "phprptinc/ewrusrfn.php"; ?>
   9<?php
  10
  11// Global variable for table object
  12$TKTrinhdo = NULL;
  13
  14//
  15// Table class for TKTrinhdo
  16//
  17class crTKTrinhdo {
  18	var $TableVar = 'TKTrinhdo';
  19	var $TableName = 'TKTrinhdo';
  20	var $TableType = 'REPORT';
  21	var $ShowCurrentFilter = EWRPT_SHOW_CURRENT_FILTER;
  22	var $FilterPanelOption = EWRPT_FILTER_PANEL_OPTION;
  23	var $CurrentOrder; // Current order
  24	var $CurrentOrderType; // Current order type
  25
  26	// Table caption
  27	function TableCaption() {
  28		global $ReportLanguage;
  29		return $ReportLanguage->TablePhrase($this->TableVar, "TblCaption");
  30	}
  31
  32	// Session Group Per Page
  33	function getGroupPerPage() {
  34		return @$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TableVar . "_grpperpage"];
  35	}
  36
  37	function setGroupPerPage($v) {
  38		@$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TableVar . "_grpperpage"] = $v;
  39	}
  40
  41	// Session Start Group
  42	function getStartGroup() {
  43		return @$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TableVar . "_start"];
  44	}
  45
  46	function setStartGroup($v) {
  47		@$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TableVar . "_start"] = $v;
  48	}
  49
  50	// Session Order By
  51	function getOrderBy() {
  52		return @$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TableVar . "_orderby"];
  53	}
  54
  55	function setOrderBy($v) {
  56		@$_SESSION[EWRPT_PROJECT_VAR . "_" . $this->TableVar . "_orderby"] = $v;
  57	}
  58
  59//	var $SelectLimit = TRUE;
  60	var $id;
  61	var $name;
  62	var $qlf_name;
  63	var $count;
  64	var $pqlf_name;
  65	var $fields = array();
  66	var $Export; // Export
  67	var $ExportAll = TRUE;
  68	var $UseTokenInUrl = EWRPT_USE_TOKEN_IN_URL;
  69	var $RowType; // Row type
  70	var $RowTotalType; // Row total type
  71	var $RowTotalSubType; // Row total subtype
  72	var $RowGroupLevel; // Row group level
  73	var $RowAttrs = array(); // Row attributes
  74
  75	// Reset CSS styles for table object
  76	function ResetCSS() {
  77    	$this->RowAttrs["style"] = "";
  78		$this->RowAttrs["class"] = "";
  79		foreach ($this->fields as $fld) {
  80			$fld->ResetCSS();
  81		}
  82	}
  83
  84	// Summary cells
  85	var $SummaryCellAttrs;
  86	var $SummaryViewAttrs;
  87	var $SummaryCurrentValue;
  88	var $SummaryViewValue;
  89
  90	// Summary cell attributes
  91	function SummaryCellAttributes($i) {
  92		$sAtt = "";
  93		if (is_array($this->SummaryCellAttrs)) {
  94			if ($i >= 0 && $i < count($this->SummaryCellAttrs)) {
  95				$Attrs = $this->SummaryCellAttrs[$i];
  96				if (is_array($Attrs)) {
  97					foreach ($Attrs as $k => $v) {
  98						if (trim($v) <> "")
  99							$sAtt .= " " . $k . "=\"" . trim($v) . "\"";
 100					}
 101				}
 102			}
 103		}
 104		return $sAtt;
 105	}
 106
 107	// Summary view attributes
 108	function SummaryViewAttributes($i) {
 109		$sAtt = "";
 110		if (is_array($this->SummaryViewAttrs)) {
 111			if ($i >= 0 && $i < count($this->SummaryViewAttrs)) {
 112				$Attrs = $this->SummaryViewAttrs[$i];
 113				if (is_array($Attrs)) {
 114					foreach ($Attrs as $k => $v) {
 115						if (trim($v) <> "")
 116							$sAtt .= " " . $k . "=\"" . trim($v) . "\"";
 117					}
 118				}
 119			}
 120		}
 121		return $sAtt;
 122	}
 123
 124	//
 125	// Table class constructor
 126	//
 127	function crTKTrinhdo() {
 128		global $ReportLanguage;
 129
 130		// id
 131		$this->id = new crField('TKTrinhdo', 'TKTrinhdo', 'x_id', 'id', '`id`', 19, EWRPT_DATATYPE_NUMBER, -1);
 132		$this->id->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
 133		$this->fields['id'] =& $this->id;
 134		$this->id->DateFilter = "";
 135		$this->id->SqlSelect = "";
 136		$this->id->SqlOrderBy = "";
 137
 138		// name
 139		$this->name = new crField('TKTrinhdo', 'TKTrinhdo', 'x_name', 'name', '`name`', 200, EWRPT_DATATYPE_STRING, -1);
 140		$this->fields['name'] =& $this->name;
 141		$this->name->DateFilter = "";
 142		$this->name->SqlSelect = "";
 143		$this->name->SqlOrderBy = "";
 144
 145		// qlf_name
 146		$this->qlf_name = new crField('TKTrinhdo', 'TKTrinhdo', 'x_qlf_name', 'qlf_name', '`qlf_name`', 200, EWRPT_DATATYPE_STRING, -1);
 147		$this->qlf_name->GroupingFieldId = 2;
 148		$this->fields['qlf_name'] =& $this->qlf_name;
 149		$this->qlf_name->DateFilter = "";
 150		$this->qlf_name->SqlSelect = "";
 151		$this->qlf_name->SqlOrderBy = "";
 152
 153		// count
 154		$this->count = new crField('TKTrinhdo', 'TKTrinhdo', 'x_count', 'count', '`count`', 20, EWRPT_DATATYPE_NUMBER, -1);
 155		$this->count->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
 156		$this->fields['count'] =& $this->count;
 157		$this->count->DateFilter = "";
 158		$this->count->SqlSelect = "";
 159		$this->count->SqlOrderBy = "";
 160
 161		// pqlf_name
 162		$this->pqlf_name = new crField('TKTrinhdo', 'TKTrinhdo', 'x_pqlf_name', 'pqlf_name', '`pqlf_name`', 200, EWRPT_DATATYPE_STRING, -1);
 163		$this->pqlf_name->GroupingFieldId = 1;
 164		$this->fields['pqlf_name'] =& $this->pqlf_name;
 165		$this->pqlf_name->DateFilter = "";
 166		$this->pqlf_name->SqlSelect = "SELECT DISTINCT `pqlf_name` FROM " . $this->SqlFrom();
 167		$this->pqlf_name->SqlOrderBy = "`pqlf_name`";
 168	}
 169
 170	// Multiple column sort
 171	function UpdateSort(&$ofld, $ctrl) {
 172		if ($this->CurrentOrder == $ofld->FldName) {
 173			$sLastSort = $ofld->getSort();
 174			if ($this->CurrentOrderType == "ASC" || $this->CurrentOrderType == "DESC") {
 175				$sThisSort = $this->CurrentOrderType;
 176			} else {
 177				$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
 178			}
 179			$ofld->setSort($sThisSort);
 180		} else {
 181			if ($ofld->GroupingFieldId == 0 && !$ctrl) $ofld->setSort("");
 182		}
 183	}
 184
 185	// Get Sort SQL
 186	function SortSql() {
 187		$sDtlSortSql = "";
 188		$argrps = array();
 189		foreach ($this->fields as $fld) {
 190			if ($fld->getSort() <> "") {
 191				if ($fld->GroupingFieldId > 0) {
 192					if ($fld->FldGroupSql <> "")
 193						$argrps[$fld->GroupingFieldId] = str_replace("%s", $fld->FldExpression, $fld->FldGroupSql) . " " . $fld->getSort();
 194					else
 195						$argrps[$fld->GroupingFieldId] = $fld->FldExpression . " " . $fld->getSort();
 196				} else {
 197					if ($sDtlSortSql <> "") $sDtlSortSql .= ", ";
 198					$sDtlSortSql .= $fld->FldExpression . " " . $fld->getSort();
 199				}
 200			}
 201		}
 202		$sSortSql = "";
 203		foreach ($argrps as $grp) {
 204			if ($sSortSql <> "") $sSortSql .= ", ";
 205			$sSortSql .= $grp;
 206		}
 207		if ($sDtlSortSql <> "") {
 208			if ($sSortSql <> "") $sSortSql .= ",";
 209			$sSortSql .= $sDtlSortSql;
 210		}
 211		return $sSortSql;
 212	}
 213
 214	// Table level SQL
 215	function ColumnField() { // Column field
 216		return "`name`";
 217	}
 218
 219	function ColumnDateType() { // Column date type
 220		return "";
 221	}
 222
 223	function SummaryField() { // Summary field
 224		return "`count`";
 225	}
 226
 227	function SummaryType() { // Summary type
 228		return "SUM";
 229	}
 230
 231	function ColumnCaptions() { // Column captions
 232		global $ReportLanguage;
 233		return "";
 234	}
 235
 236	function ColumnNames() { // Column names
 237		return "";
 238	}
 239
 240	function ColumnValues() { // Column values
 241		return "";
 242	}
 243
 244	function SqlFrom() { // From
 245		return "`vw__official_reports_by_qlf`";
 246	}
 247
 248	function SqlSelect() { // Select
 249		return "SELECT `pqlf_name`, `qlf_name`, <DistinctColumnFields> FROM " . $this->SqlFrom();
 250	}
 251
 252	function SqlWhere() { // Where
 253		return "";
 254	}
 255
 256	function SqlGroupBy() { // Group By
 257		return "`pqlf_name`, `qlf_name`";
 258	}
 259
 260	function SqlHaving() { // Having
 261		return "";
 262	}
 263
 264	function SqlOrderBy() { // Order By
 265		return "`pqlf_name` ASC, `qlf_name` ASC";
 266	}
 267
 268	function SqlDistinctSelect() {
 269		return "SELECT DISTINCT `name` FROM `vw__official_reports_by_qlf`";
 270	}
 271
 272	function SqlDistinctWhere() {
 273		return "";
 274	}
 275
 276	function SqlDistinctOrderBy() {
 277		return "`name` ASC";
 278	}
 279
 280	// Table Level Group SQL
 281	function SqlFirstGroupField() {
 282		return "`pqlf_name`";
 283	}
 284
 285	function SqlSelectGroup() {
 286		return "SELECT DISTINCT " . $this->SqlFirstGroupField() . " FROM " . $this->SqlFrom();
 287	}
 288
 289	function SqlOrderByGroup() {
 290		return "`pqlf_name` ASC";
 291	}
 292
 293	function SqlSelectAgg() {
 294		return "SELECT <DistinctColumnFields> FROM " . $this->SqlFrom();
 295	}
 296
 297	function SqlGroupByAgg() {
 298		return "";
 299	}
 300
 301	// Sort URL
 302	function SortUrl(&$fld) {
 303		if ($this->Export <> "" ||
 304			in_array($fld->FldType, array(128, 204, 205))) { // Unsortable data type
 305				return "";
 306		} elseif ($fld->Sortable) {
 307			$sUrlParm = "order=" . urlencode($fld->FldName) . "&ordertype=" . $fld->ReverseSort();
 308			return ewrpt_CurrentPage() . "?" . $sUrlParm;
 309		} else {
 310			return "";
 311		}
 312	}
 313
 314	// Row attributes
 315	function RowAttributes() {
 316		$sAtt = "";
 317		foreach ($this->RowAttrs as $k => $v) {
 318			if (trim($v) <> "")
 319				$sAtt .= " " . $k . "=\"" . trim($v) . "\"";
 320		}
 321		return $sAtt;
 322	}
 323
 324	// Field object by fldvar
 325	function &fields($fldvar) {
 326		return $this->fields[$fldvar];
 327	}
 328
 329	// Table level events
 330	// Row Rendering event
 331	function Row_Rendering() {
 332
 333		// Enter your code here	
 334	}
 335
 336	// Cell Rendered event
 337	function Cell_Rendered(&$Field, $CurrentValue, &$ViewValue, &$ViewAttrs, &$CellAttrs, &$HrefValue) {
 338
 339		//$ViewValue = "xxx";
 340		//$ViewAttrs["style"] = "xxx";
 341
 342	}
 343
 344	// Row Rendered event
 345	function Row_Rendered() {
 346
 347		// To view properties of field class, use:
 348		//var_dump($this-><FieldName>); 
 349
 350	}
 351
 352	// Load Filters event
 353	function Filters_Load() {
 354
 355		// Enter your code here	
 356		// Example: Register/Unregister Custom Extended Filter
 357		//ewrpt_RegisterFilter($this-><Field>, 'StartsWithA', 'Starts With A', 'GetStartsWithAFilter');
 358		//ewrpt_UnregisterFilter($this-><Field>, 'StartsWithA');
 359
 360	}
 361
 362	// Page Filter Validated event
 363	function Page_FilterValidated() {
 364
 365		// Example:
 366		//global $MyTable;
 367		//$MyTable->MyField1->SearchValue = "your search criteria"; // Search value
 368
 369	}
 370
 371	// Chart Rendering event
 372	function Chart_Rendering(&$chart) {
 373
 374		// var_dump($chart);
 375	}
 376
 377	// Chart Rendered event
 378	function Chart_Rendered($chart, &$chartxml) {
 379
 380		// Example:	
 381		//$doc = $chart->XmlDoc; // Get the DOMDocument object
 382		// Enter your code to manipulate the DOMDocument object here
 383		//$chartxml = $doc->saveXML(); // Output the XML
 384
 385	}
 386
 387	// Email Sending event
 388	function Email_Sending(&$Email, &$Args) {
 389
 390		//var_dump($Email); var_dump($Args); exit();
 391		return TRUE;
 392	}
 393}
 394?>
 395<?php ewrpt_Header(FALSE) ?>
 396<?php
 397
 398// Create page object
 399$TKTrinhdo_crosstab = new crTKTrinhdo_crosstab();
 400$Page =& $TKTrinhdo_crosstab;
 401
 402// Page init
 403$TKTrinhdo_crosstab->Page_Init();
 404
 405// Page main
 406$TKTrinhdo_crosstab->Page_Main();
 407?>
 408<?php include_once "phprptinc/header.php"; ?>
 409<?php if ($TKTrinhdo->Export == "" || $TKTrinhdo->Export == "print" || $TKTrinhdo->Export == "email") { ?>
 410<script type="text/javascript">
 411
 412// Create page object
 413var TKTrinhdo_crosstab = new ewrpt_Page("TKTrinhdo_crosstab");
 414
 415// page properties
 416TKTrinhdo_crosstab.PageID = "crosstab"; // page ID
 417TKTrinhdo_crosstab.FormID = "fTKTrinhdocrosstabfilter"; // form ID
 418var EWRPT_PAGE_ID = TKTrinhdo_crosstab.PageID;
 419
 420// extend page with Chart_Rendering function
 421TKTrinhdo_crosstab.Chart_Rendering =  
 422 function(chart, chartid) { // DO NOT CHANGE THIS LINE!
 423
 424 	//alert(chartid);
 425 }
 426
 427// extend page with Chart_Rendered function
 428TKTrinhdo_crosstab.Chart_Rendered =  
 429 function(chart, chartid) { // DO NOT CHANGE THIS LINE!
 430
 431 	//alert(chartid);
 432 }
 433</script>
 434<?php } ?>
 435<?php if ($TKTrinhdo->Export == "") { ?>
 436<script language="JavaScript" type="text/javascript">
 437<!--
 438
 439// Write your client script here, no need to add script tags.
 440//-->
 441
 442</script>
 443<?php } ?>
 444<?php if ($TKTrinhdo->Export == "" || $TKTrinhdo->Export == "print" || $TKTrinhdo->Export == "email") { ?>
 445<script src="<?php echo EWRPT_FUSIONCHARTS_FREE_JSCLASS_FILE; ?>" type="text/javascript"></script>
 446<?php } ?>
 447<?php if ($TKTrinhdo->Export == "") { ?>
 448<div id="ewrpt_PopupFilter"><div class="bd"></div></div>
 449<script src="phprptjs/ewrptpop.js" type="text/javascript"></script>
 450<script type="text/javascript">
 451
 452// popup fields
 453<?php $jsdata = ewrpt_GetJsData($TKTrinhdo->pqlf_name, $TKTrinhdo->pqlf_name->FldType); ?>
 454ewrpt_CreatePopup("TKTrinhdo_pqlf_name", [<?php echo $jsdata ?>]);
 455</script>
 456<?php } ?>
 457<?php if ($TKTrinhdo->Export == "" || $TKTrinhdo->Export == "print" || $TKTrinhdo->Export == "email") { ?>
 458<!-- Table container (begin) -->
 459<table id="ewContainer" cellspacing="0" cellpadding="0" border="0">
 460<!-- Top container (begin) -->
 461<tr><td colspan="3"><div id="ewTop" class="phpreportmaker">
 462<!-- top slot -->
 463<a name="top"></a>
 464<?php } ?>
 465<p class="phpreportmaker ewTitle"><?php echo $TKTrinhdo->TableCaption() ?>
 466&nbsp;&nbsp;<?php $TKTrinhdo_crosstab->ExportOptions->Render("body"); ?></p>
 467<?php $TKTrinhdo_crosstab->ShowPageHeader(); ?>
 468<?php $TKTrinhdo_crosstab->ShowMessage(); ?>
 469<br><br>
 470<?php if ($TKTrinhdo->Export == "" || $TKTrinhdo->Export == "print" || $TKTrinhdo->Export == "email") { ?>
 471</div></td></tr>
 472<!-- Top container (end) -->
 473<tr>
 474	<!-- Left container (begin) -->
 475	<td style="vertical-align: top;"><div id="ewLeft" class="phpreportmaker">
 476	<!-- left slot -->
 477	</div></td>
 478	<!-- Left container (end) -->
 479	<!-- Center container (report) (begin) -->
 480	<td style="vertical-align: top;" class="ewPadding"><div id="ewCenter" class="phpreportmaker">
 481	<!-- center slot -->
 482<?php } ?>
 483<!-- crosstab report starts -->
 484<div id="report_crosstab">
 485<?php if ($TKTrinhdo->ShowCurrentFilter) { ?>
 486<div id="ewrptFilterList">
 487<?php $TKTrinhdo_crosstab->ShowFilterList() ?>
 488</div>
 489<br>
 490<?php } ?>
 491<table class="ewGrid" cellspacing="0"><tr>
 492	<td class="ewGridContent">
 493<?php if ($TKTrinhdo->Export == "") { ?>
 494<div class="ewGridUpperPanel">
 495<form action="<?php echo ewrpt_CurrentPage() ?>" name="ewpagerform" id="ewpagerform" class="ewForm">
 496<table border="0" cellspacing="0" cellpadding="0">
 497	<tr>
 498		<td style="white-space: nowrap;">
 499<?php if (!isset($Pager)) $Pager = new crPrevNextPager($TKTrinhdo_crosstab->StartGrp, $TKTrinhdo_crosstab->DisplayGrps, $TKTrinhdo_crosstab->TotalGrps) ?>
 500<?php if ($Pager->RecordCount > 0) { ?>
 501	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("Page") ?>&nbsp;</span></td>
 502<!--first page button-->
 503	<?php if ($Pager->FirstButton->Enabled) { ?>
 504	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->FirstButton->Start ?>"><img src="phprptimages/first.gif" alt="<?php echo $ReportLanguage->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></a></td>
 505	<?php } else { ?>
 506	<td><img src="phprptimages/firstdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></td>
 507	<?php } ?>
 508<!--previous page button-->
 509	<?php if ($Pager->PrevButton->Enabled) { ?>
 510	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->PrevButton->Start ?>"><img src="phprptimages/prev.gif" alt="<?php echo $ReportLanguage->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></a></td>
 511	<?php } else { ?>
 512	<td><img src="phprptimages/prevdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></td>
 513	<?php } ?>
 514<!--current page number-->
 515	<td><input type="text" name="pageno" id="pageno" value="<?php echo $Pager->CurrentPage ?>" size="4"></td>
 516<!--next page button-->
 517	<?php if ($Pager->NextButton->Enabled) { ?>
 518	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->NextButton->Start ?>"><img src="phprptimages/next.gif" alt="<?php echo $ReportLanguage->Phrase("PagerNext") ?>" width="16" height="16" border="0"></a></td>	
 519	<?php } else { ?>
 520	<td><img src="phprptimages/nextdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerNext") ?>" width="16" height="16" border="0"></td>
 521	<?php } ?>
 522<!--last page button-->
 523	<?php if ($Pager->LastButton->Enabled) { ?>
 524	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->LastButton->Start ?>"><img src="phprptimages/last.gif" alt="<?php echo $ReportLanguage->Phrase("PagerLast") ?>" width="16" height="16" border="0"></a></td>	
 525	<?php } else { ?>
 526	<td><img src="phprptimages/lastdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerLast") ?>" width="16" height="16" border="0"></td>
 527	<?php } ?>
 528	<td><span class="phpreportmaker">&nbsp;<?php echo $ReportLanguage->Phrase("of") ?> <?php echo $Pager->PageCount ?></span></td>
 529	</tr></table>
 530	</td>	
 531	<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
 532	<td>
 533	<span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("Record") ?> <?php echo $Pager->FromIndex ?> <?php echo $ReportLanguage->Phrase("To") ?> <?php echo $Pager->ToIndex ?> <?php echo $ReportLanguage->Phrase("Of") ?> <?php echo $Pager->RecordCount ?></span>
 534<?php } else { ?>
 535	<?php if ($TKTrinhdo_crosstab->Filter == "0=101") { ?>
 536	<span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("EnterSearchCriteria") ?></span>
 537	<?php } else { ?>
 538	<span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("NoRecord") ?></span>
 539	<?php } ?>
 540<?php } ?>
 541		</td>
 542<?php if ($TKTrinhdo_crosstab->TotalGrps > 0) { ?>
 543		<td style="white-space: nowrap;">&nbsp;&nbsp;&nbsp;&nbsp;</td>
 544		<td align="right" style="vertical-align: top; white-space: nowrap;"><span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("GroupsPerPage"); ?>&nbsp;
 545<select name="<?php echo EWRPT_TABLE_GROUP_PER_PAGE; ?>" onchange="this.form.submit();">
 546<option value="1"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 1) echo " selected=\"selected\"" ?>>1</option>
 547<option value="2"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 2) echo " selected=\"selected\"" ?>>2</option>
 548<option value="3"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 3) echo " selected=\"selected\"" ?>>3</option>
 549<option value="4"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 4) echo " selected=\"selected\"" ?>>4</option>
 550<option value="5"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 5) echo " selected=\"selected\"" ?>>5</option>
 551<option value="10"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 10) echo " selected=\"selected\"" ?>>10</option>
 552<option value="20"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 20) echo " selected=\"selected\"" ?>>20</option>
 553<option value="50"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 50) echo " selected=\"selected\"" ?>>50</option>
 554<option value="ALL"<?php if ($TKTrinhdo->getGroupPerPage() == -1) echo " selected=\"selected\"" ?>><?php echo $ReportLanguage->Phrase("AllRecords") ?></option>
 555</select>
 556		</span></td>
 557<?php } ?>
 558	</tr>
 559</table>
 560</form>
 561</div>
 562<?php } ?>
 563<!-- Report grid (begin) -->
 564<div class="ewGridMiddlePanel">
 565<table class="<?php echo $TKTrinhdo_crosstab->ReportTableClass ?>" cellspacing="0">
 566<?php if ($TKTrinhdo_crosstab->ShowFirstHeader) { // Show header ?>
 567	<thead>
 568	<!-- Table header -->
 569	<tr>
 570		<td class="ewRptColSummary" colspan="2" style="white-space: nowrap;"><div class="phpreportmaker"><?php echo $TKTrinhdo->count->FldCaption() ?>&nbsp;(<?php echo $ReportLanguage->Phrase("RptSum") ?>)&nbsp;</div></td>
 571		<td class="ewRptColHeader" colspan="<?php echo @$TKTrinhdo_crosstab->ColSpan; ?>" style="white-space: nowrap;">
 572			<?php echo $TKTrinhdo->name->FldCaption() ?>
 573		</td>
 574	</tr>
 575	<tr>
 576<td class="ewTableHeader">
 577<?php if ($TKTrinhdo->Export <> "") { ?>
 578<?php echo $TKTrinhdo->pqlf_name->FldCaption() ?>
 579<?php } else { ?>
 580	<table cellspacing="0" class="ewTableHeaderBtn" style="white-space: nowrap;"><tr>
 581<?php if ($TKTrinhdo->SortUrl($TKTrinhdo->pqlf_name) == "") { ?>
 582		<td style="vertical-align: bottom;"><?php echo $TKTrinhdo->pqlf_name->FldCaption() ?></td>
 583<?php } else { ?>
 584		<td class="ewPointer" onmousedown="ewrpt_Sort(event,'<?php echo $TKTrinhdo->SortUrl($TKTrinhdo->pqlf_name) ?>',2);"><?php echo $TKTrinhdo->pqlf_name->FldCaption() ?></td><td style="width: 10px;">
 585		<?php if ($TKTrinhdo->pqlf_name->getSort() == "ASC") { ?><img src="phprptimages/sortup.gif" width="10" height="9" border="0"><?php } elseif ($TKTrinhdo->pqlf_name->getSort() == "DESC") { ?><img src="phprptimages/sortdown.gif" width="10" height="9" border="0"><?php } ?></td>
 586<?php } ?>
 587		<td style="width: 20px;" align="right"><a href="#" onclick="ewrpt_ShowPopup(this.name, 'TKTrinhdo_pqlf_name', false, '<?php echo $TKTrinhdo->pqlf_name->RangeFrom; ?>', '<?php echo $TKTrinhdo->pqlf_name->RangeTo; ?>');return false;" name="x_pqlf_name" id="x_pqlf_name"><img src="phprptimages/popup.gif" width="15" height="14" border="0" alt="<?php echo $ReportLanguage->Phrase("Filter") ?>"></a></td>
 588	</tr></table>
 589<?php } ?>
 590</td>
 591<td class="ewTableHeader">
 592<?php if ($TKTrinhdo->Export <> "") { ?>
 593<?php echo $TKTrinhdo->qlf_name->FldCaption() ?>
 594<?php } else { ?>
 595	<table cellspacing="0" class="ewTableHeaderBtn" style="white-space: nowrap;"><tr>
 596<?php if ($TKTrinhdo->SortUrl($TKTrinhdo->qlf_name) == "") { ?>
 597		<td style="vertical-align: bottom;"><?php echo $TKTrinhdo->qlf_name->FldCaption() ?></td>
 598<?php } else { ?>
 599		<td class="ewPointer" onmousedown="ewrpt_Sort(event,'<?php echo $TKTrinhdo->SortUrl($TKTrinhdo->qlf_name) ?>',2);"><?php echo $TKTrinhdo->qlf_name->FldCaption() ?></td><td style="width: 10px;">
 600		<?php if ($TKTrinhdo->qlf_name->getSort() == "ASC") { ?><img src="phprptimages/sortup.gif" width="10" height="9" border="0"><?php } elseif ($TKTrinhdo->qlf_name->getSort() == "DESC") { ?><img src="phprptimages/sortdown.gif" width="10" height="9" border="0"><?php } ?></td>
 601<?php } ?>
 602	</tr></table>
 603<?php } ?>
 604</td>
 605<!-- Dynamic columns begin -->
 606	<?php
 607	$cntval = count($TKTrinhdo_crosstab->Val);
 608	for ($iy = 1; $iy < $cntval; $iy++) {
 609		if ($TKTrinhdo_crosstab->Col[$iy]->Visible) {
 610			$TKTrinhdo->SummaryCurrentValue[$iy-1] = $TKTrinhdo_crosstab->Col[$iy]->Caption;
 611			$TKTrinhdo->SummaryViewValue[$iy-1] = $TKTrinhdo->SummaryCurrentValue[$iy-1];
 612	?>
 613		<td class="ewTableHeader"<?php echo $TKTrinhdo->name->CellAttributes() ?>><span<?php echo $TKTrinhdo->name->ViewAttributes() ?>><?php echo $TKTrinhdo->SummaryViewValue[$iy-1]; ?></span></td>
 614	<?php
 615		}
 616	}
 617	?>
 618<!-- Dynamic columns end -->
 619	</tr>
 620	</thead>
 621<?php } // End show header ?>
 622	<tbody>
 623<?php
 624if ($TKTrinhdo_crosstab->TotalGrps > 0) {
 625
 626// Set the last group to display if not export all
 627if ($TKTrinhdo->ExportAll && $TKTrinhdo->Export <> "") {
 628	$TKTrinhdo_crosstab->StopGrp = $TKTrinhdo_crosstab->TotalGrps;
 629} else {
 630	$TKTrinhdo_crosstab->StopGrp = $TKTrinhdo_crosstab->StartGrp + $TKTrinhdo_crosstab->DisplayGrps - 1;
 631}
 632
 633// Stop group <= total number of groups
 634if (intval($TKTrinhdo_crosstab->StopGrp) > intval($TKTrinhdo_crosstab->TotalGrps)) {
 635	$TKTrinhdo_crosstab->StopGrp = $TKTrinhdo_crosstab->TotalGrps;
 636}
 637
 638// Navigate
 639$TKTrinhdo_crosstab->RecCount = 0;
 640
 641// Get first row
 642if ($TKTrinhdo_crosstab->TotalGrps > 0) {
 643	$TKTrinhdo_crosstab->GetGrpRow(1);
 644	$TKTrinhdo_crosstab->GrpCount = 1;
 645}
 646while ($rsgrp && !$rsgrp->EOF && $TKTrinhdo_crosstab->GrpCount <= $TKTrinhdo_crosstab->DisplayGrps) {
 647
 648	// Build detail SQL
 649	$sWhere = ewrpt_DetailFilterSQL($TKTrinhdo->pqlf_name, $TKTrinhdo->SqlFirstGroupField(), $TKTrinhdo->pqlf_name->GroupValue());
 650	if ($TKTrinhdo_crosstab->Filter != "")
 651		$sWhere = "($TKTrinhdo_crosstab->Filter) AND ($sWhere)";
 652	$sSql = ewrpt_BuildReportSql($TKTrinhdo_crosstab->SqlSelectWork, $TKTrinhdo->SqlWhere(), $TKTrinhdo->SqlGroupBy(), "", $TKTrinhdo->SqlOrderBy(), $sWhere, $TKTrinhdo_crosstab->Sort);
 653	$rs = $conn->Execute($sSql);
 654	$rsdtlcnt = ($rs) ? $rs->RecordCount() : 0;
 655	if ($rsdtlcnt > 0)
 656		$TKTrinhdo_crosstab->GetRow(1);
 657	while ($rs && !$rs->EOF) {
 658		$TKTrinhdo_crosstab->RecCount++;
 659
 660		// Render row
 661		$TKTrinhdo->ResetCSS();
 662		$TKTrinhdo->RowType = EWRPT_ROWTYPE_DETAIL;
 663		$TKTrinhdo_crosstab->RenderRow();
 664?>
 665	<!-- Data -->
 666	<tr<?php echo $TKTrinhdo->RowAttributes(); ?>>
 667		<!-- Trinh do -->
 668		<td<?php echo $TKTrinhdo->pqlf_name->CellAttributes(); ?>>
 669<span<?php echo $TKTrinhdo->pqlf_name->ViewAttributes(); ?>><?php echo $TKTrinhdo->pqlf_name->GroupViewValue; ?></span></td>
 670		<!-- Chi tiet -->
 671		<td<?php echo $TKTrinhdo->qlf_name->CellAttributes(); ?>>
 672<span<?php echo $TKTrinhdo->qlf_name->ViewAttributes(); ?>><?php echo $TKTrinhdo->qlf_name->GroupViewValue; ?></span></td>
 673<!-- Dynamic columns begin -->
 674	<?php
 675		$cntcol = count($TKTrinhdo->SummaryViewValue);
 676		for ($iy = 1; $iy <= $cntcol; $iy++) {
 677			$bColShow = ($iy <= $TKTrinhdo_crosstab->ColCount) ? $TKTrinhdo_crosstab->Col[$iy]->Visible : TRUE;
 678			$sColDesc = ($iy <= $TKTrinhdo_crosstab->ColCount) ? $TKTrinhdo_crosstab->Col[$iy]->Caption : $ReportLanguage->Phrase("Summary");
 679			if ($bColShow) {
 680	?>
 681		<!-- <?php //echo $TKTrinhdo_crosstab->Col[$iy]->Caption; ?> -->
 682		<!-- <?php echo $sColDesc; ?> -->
 683		<td<?php echo $TKTrinhdo->SummaryCellAttributes($iy-1) ?>><span<?php echo $TKTrinhdo->SummaryViewAttributes($iy-1); ?>><?php echo $TKTrinhdo->SummaryViewValue[$iy-1]; ?></span></td>
 684	<?php
 685			}
 686		}
 687	?>
 688<!-- Dynamic columns end -->
 689	</tr>
 690<?php
 691
 692		// Accumulate page summary
 693		$TKTrinhdo_crosstab->AccumulateSummary();
 694
 695		// Get next record
 696		$TKTrinhdo_crosstab->GetRow(2);
 697?>
 698<?php
 699	} // End detail records loop
 700?>
 701<?php
 702
 703		// Process summary level 1
 704		if ($TKTrinhdo_crosstab->ChkLvlBreak(1)) {
 705			$TKTrinhdo->ResetCSS();
 706			$TKTrinhdo->RowType = EWRPT_ROWTYPE_TOTAL;
 707			$TKTrinhdo->RowTotalType = EWRPT_ROWTOTAL_GROUP;
 708			$TKTrinhdo->RowTotalSubType = EWRPT_ROWTOTAL_FOOTER;
 709			$TKTrinhdo->RowGroupLevel = 1;
 710			$TKTrinhdo_crosstab->RenderRow();
 711?>
 712	<!-- Summary Trinh do (level 1) -->
 713	<tr<?php echo $TKTrinhdo->RowAttributes(); ?>>
 714		<td colspan="2"<?php echo $TKTrinhdo->pqlf_name->CellAttributes() ?>><?php echo $ReportLanguage->Phrase("RptSumHead") ?> <?php echo $TKTrinhdo->pqlf_name->FldCaption() ?>: <?php echo $TKTrinhdo->pqlf_name->GroupViewValue; ?></td>
 715<!-- Dynamic columns begin -->
 716	<?php
 717	$cntcol = count($TKTrinhdo->SummaryViewValue);
 718	for ($iy = 1; $iy <= $cntcol; $iy++) {
 719		$bColShow = ($iy <= $TKTrinhdo_crosstab->ColCount) ? $TKTrinhdo_crosstab->Col[$iy]->Visible : TRUE;
 720		$sColDesc = ($iy <= $TKTrinhdo_crosstab->ColCount) ? $TKTrinhdo_crosstab->Col[$iy]->Caption : $ReportLanguage->Phrase("Summary");
 721		if ($bColShow) {
 722	?>
 723		<!-- <?php //echo $TKTrinhdo_crosstab->Col[$iy]->Caption; ?> -->
 724		<!-- <?php echo $sColDesc; ?> -->
 725		<td<?php echo $TKTrinhdo->SummaryCellAttributes($iy-1) ?>><span<?php echo $TKTrinhdo->SummaryViewAttributes($iy-1); ?>><?php echo $TKTrinhdo->SummaryViewValue[$iy-1]; ?></span></td>
 726	<?php
 727		}
 728	}
 729	?>
 730<!-- Dynamic columns end -->
 731	</tr>
 732<?php
 733
 734			// Reset level 1 summary
 735			$TKTrinhdo_crosstab->ResetLevelSummary(1);
 736		}
 737?>
 738<?php
 739	$TKTrinhdo_crosstab->GetGrpRow(2);
 740	$TKTrinhdo_crosstab->GrpCount++;
 741}
 742?>
 743	</tbody>
 744	<tfoot>
 745<?php } ?>
 746	</tfoot>
 747</table>
 748</div>
 749<?php if ($TKTrinhdo_crosstab->TotalGrps > 0) { ?>
 750<?php if ($TKTrinhdo->Export == "") { ?>
 751<div class="ewGridLowerPanel">
 752<form action="<?php echo ewrpt_CurrentPage() ?>" name="ewpagerform" id="ewpagerform" class="ewForm">
 753<table border="0" cellspacing="0" cellpadding="0">
 754	<tr>
 755		<td style="white-space: nowrap;">
 756<?php if (!isset($Pager)) $Pager = new crPrevNextPager($TKTrinhdo_crosstab->StartGrp, $TKTrinhdo_crosstab->DisplayGrps, $TKTrinhdo_crosstab->TotalGrps) ?>
 757<?php if ($Pager->RecordCount > 0) { ?>
 758	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("Page") ?>&nbsp;</span></td>
 759<!--first page button-->
 760	<?php if ($Pager->FirstButton->Enabled) { ?>
 761	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->FirstButton->Start ?>"><img src="phprptimages/first.gif" alt="<?php echo $ReportLanguage->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></a></td>
 762	<?php } else { ?>
 763	<td><img src="phprptimages/firstdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></td>
 764	<?php } ?>
 765<!--previous page button-->
 766	<?php if ($Pager->PrevButton->Enabled) { ?>
 767	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->PrevButton->Start ?>"><img src="phprptimages/prev.gif" alt="<?php echo $ReportLanguage->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></a></td>
 768	<?php } else { ?>
 769	<td><img src="phprptimages/prevdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></td>
 770	<?php } ?>
 771<!--current page number-->
 772	<td><input type="text" name="pageno" id="pageno" value="<?php echo $Pager->CurrentPage ?>" size="4"></td>
 773<!--next page button-->
 774	<?php if ($Pager->NextButton->Enabled) { ?>
 775	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->NextButton->Start ?>"><img src="phprptimages/next.gif" alt="<?php echo $ReportLanguage->Phrase("PagerNext") ?>" width="16" height="16" border="0"></a></td>	
 776	<?php } else { ?>
 777	<td><img src="phprptimages/nextdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerNext") ?>" width="16" height="16" border="0"></td>
 778	<?php } ?>
 779<!--last page button-->
 780	<?php if ($Pager->LastButton->Enabled) { ?>
 781	<td><a href="<?php echo ewrpt_CurrentPage() ?>?start=<?php echo $Pager->LastButton->Start ?>"><img src="phprptimages/last.gif" alt="<?php echo $ReportLanguage->Phrase("PagerLast") ?>" width="16" height="16" border="0"></a></td>	
 782	<?php } else { ?>
 783	<td><img src="phprptimages/lastdisab.gif" alt="<?php echo $ReportLanguage->Phrase("PagerLast") ?>" width="16" height="16" border="0"></td>
 784	<?php } ?>
 785	<td><span class="phpreportmaker">&nbsp;<?php echo $ReportLanguage->Phrase("of") ?> <?php echo $Pager->PageCount ?></span></td>
 786	</tr></table>
 787	</td>	
 788	<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
 789	<td>
 790	<span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("Record") ?> <?php echo $Pager->FromIndex ?> <?php echo $ReportLanguage->Phrase("To") ?> <?php echo $Pager->ToIndex ?> <?php echo $ReportLanguage->Phrase("Of") ?> <?php echo $Pager->RecordCount ?></span>
 791<?php } else { ?>
 792	<?php if ($TKTrinhdo_crosstab->Filter == "0=101") { ?>
 793	<span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("EnterSearchCriteria") ?></span>
 794	<?php } else { ?>
 795	<span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("NoRecord") ?></span>
 796	<?php } ?>
 797<?php } ?>
 798		</td>
 799<?php if ($TKTrinhdo_crosstab->TotalGrps > 0) { ?>
 800		<td style="white-space: nowrap;">&nbsp;&nbsp;&nbsp;&nbsp;</td>
 801		<td align="right" style="vertical-align: top; white-space: nowrap;"><span class="phpreportmaker"><?php echo $ReportLanguage->Phrase("GroupsPerPage"); ?>&nbsp;
 802<select name="<?php echo EWRPT_TABLE_GROUP_PER_PAGE; ?>" onchange="this.form.submit();">
 803<option value="1"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 1) echo " selected=\"selected\"" ?>>1</option>
 804<option value="2"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 2) echo " selected=\"selected\"" ?>>2</option>
 805<option value="3"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 3) echo " selected=\"selected\"" ?>>3</option>
 806<option value="4"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 4) echo " selected=\"selected\"" ?>>4</option>
 807<option value="5"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 5) echo " selected=\"selected\"" ?>>5</option>
 808<option value="10"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 10) echo " selected=\"selected\"" ?>>10</option>
 809<option value="20"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 20) echo " selected=\"selected\"" ?>>20</option>
 810<option value="50"<?php if ($TKTrinhdo_crosstab->DisplayGrps == 50) echo " selected=\"selected\"" ?>>50</option>
 811<option value="ALL"<?php if ($TKTrinhdo->getGroupPerPage() == -1) echo " selected=\"selected\"" ?>><?php echo $ReportLanguage->Phrase("AllRecords") ?></option>
 812</select>
 813		</span></td>
 814<?php } ?>
 815	</tr>
 816</table>
 817</form>
 818</div>
 819<?php } ?>
 820<?php } ?>
 821</td></tr></table>
 822</div>
 823<!-- Crosstab report ends -->
 824<?php if ($TKTrinhdo->Export == "" || $TKTrinhdo->Export == "print" || $TKTrinhdo->Export == "email") { ?>
 825	</div><br></td>
 826	<!-- Center container (report) (end) -->
 827	<!-- Right container (begin) -->
 828	<td style="vertical-align: top;"><div id="ewRight" class="phpreportmaker">
 829	<!-- Right slot -->
 830	</div></td>
 831	<!-- Right container (end) -->
 832</tr>
 833<!-- Bottom container (begin) -->
 834<tr><td colspan="3"><div id="ewBottom" class="phpreportmaker">
 835	<!-- Bottom slot -->
 836	</div><br></td></tr>
 837<!-- Bottom container (end) -->
 838</table>
 839<!-- Table container (end) -->
 840<?php } ?>
 841<?php $TKTrinhdo_crosstab->ShowPageFooter(); ?>
 842<?php if (EWRPT_DEBUG_ENABLED) echo ewrpt_DebugMsg(); ?>
 843<?php
 844
 845// Close recordsets
 846if ($rsgrp) $rsgrp->Close();
 847if ($rs) $rs->Close();
 848?>
 849<?php if ($TKTrinhdo->Export == "") { ?>
 850<script language="JavaScript" type="text/javascript">
 851<!--
 852
 853// Write your table-specific startup script here
 854// document.write("page loaded");
 855//-->
 856
 857</script>
 858<?php } ?>
 859<?php include_once "phprptinc/footer.php"; ?>
 860<?php
 861$TKTrinhdo_crosstab->Page_Terminate();
 862?>
 863<?php
 864
 865//
 866// Page class
 867//
 868class crTKTrinhdo_crosstab {
 869
 870	// Page ID
 871	var $PageID = 'crosstab';
 872
 873	// Table name
 874	var $TableName = 'TKTrinhdo';
 875
 876	// Page object name
 877	var $PageObjName = 'TKTrinhdo_crosstab';
 878
 879	// Page name
 880	function PageName() {
 881		return ewrpt_CurrentPage();
 882	}
 883
 884	// Page URL
 885	function PageUrl() {
 886		$PageUrl = ewrpt_CurrentPage() . "?";
 887		global $TKTrinhdo;
 888		if ($TKTrinhdo->UseTokenInUrl) $PageUrl .= "t=" . $TKTrinhdo->TableVar . "&"; // Add page token
 889		return $PageUrl;
 890	}
 891
 892	// Export URLs
 893	var $ExportPrintUrl;
 894	var $ExportExcelUrl;
 895	var $ExportWordUrl;
 896	var $ExportPdfUrl;
 897	var $ReportTableClass;
 898
 899	// Message
 900	function getMessage() {
 901		return @$_SESSION[EWRPT_SESSION_MESSAGE];
 902	}
 903
 904	function setMessage($v) {
 905		if (@$_SESSION[EWRPT_SESSION_MESSAGE] <> "") { // Append
 906			$_SESSION[EWRPT_SESSION_MESSAGE] .= "<br>" . $v;
 907		} else {
 908			$_SESSION[EWRPT_SESSION_MESSAGE] = $v;
 909		}
 910	}
 911
 912	// Show message
 913	function ShowMessage() {
 914		$sMessage = $this->getMessage();
 915		$this->Message_Showing($sMessage);
 916		if ($sMessage <> "") { // Message in Session, display
 917			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
 918			$_SESSION[EWRPT_SESSION_MESSAGE] = ""; // Clear message in Session
 919		}
 920	}
 921	var $PageHeader;
 922	var $PageFooter;
 923
 924	// Show Page Header
 925	function ShowPageHeader() {
 926		$sHeader = $this->PageHeader;
 927		$this->Page_DataRendering($sHeader);
 928		if ($sHeader <> "") { // Header exists, display
 929			echo "<p><span class=\"phpreportmaker\">" . $sHeader . "</span></p>";
 930		}
 931	}
 932
 933	// Show Page Footer
 934	function ShowPageFooter() {
 935		$sFooter = $this->PageFooter;
 936		$this->Page_DataRendered($sFooter);
 937		if ($sFooter <> "") { // Fotoer exists, display
 938			echo "<p><span class=\"phpreportmaker\">" . $sFooter . "</span></p>";
 939		}
 940	}
 941
 942	// Validate page request
 943	function IsPageRequest() {
 944		global $TKTrinhdo;
 945		if ($TKTrinhdo->UseTokenInUrl) {
 946			if (ewrpt_IsHttpPost())
 947				return ($TKTrinhdo->TableVar == @$_POST("t"));
 948			if (@$_GET["t"] <> "")
 949				return ($TKTrinhdo->TableVar == @$_GET["t"]);
 950		} else {
 951			return TRUE;
 952		}
 953	}
 954
 955	//
 956	// Page class constructor
 957	//
 958	function crTKTrinhdo_crosstab() {
 959		global $conn, $ReportLanguage;
 960
 961		// Language object
 962		$ReportLanguage = new crLanguage();
 963
 964		// Table object (TKTrinhdo)
 965		$GLOBALS["TKTrinhdo"] = new crTKTrinhdo();
 966		$GLOBALS["Table"] =& $GLOBALS["TKTrinhdo"];
 967
 968		// Initialize URLs
 969		$this->ExportPrintUrl = $this->PageUrl() . "export=print";
 970		$this->ExportExcelUrl = $this->PageUrl() . "export=excel";
 971		$this->ExportWordUrl = $this->PageUrl() . "export=word";
 972		$this->ExportPdfUrl = $this->PageUrl() . "export=pdf";
 973
 974		// Page ID
 975		if (!defined("EWRPT_PAGE_ID"))
 976			define("EWRPT_PAGE_ID", 'crosstab', TRUE);
 977
 978		// Table name (for backward compatibility)
 979		if (!defined("EWRPT_TABLE_NAME"))
 980			define("EWRPT_TABLE_NAME", 'TKTrinhdo', TRUE);
 981
 982		// Start timer
 983		$GLOBALS["gsTimer"] = new crTimer();
 984
 985		// Open connection
 986		$conn = ewrpt_Connect();
 987
 988		// Export options
 989		$this->ExportOptions = new crListOptions();
 990		$this->ExportOptions->Tag = "span";
 991		$this->ExportOptions->Separator = "&nbsp;&nbsp;";
 992	}
 993
 994	// 
 995	//  Page_Init
 996	//
 997	function Page_Init() {
 998		global $gsExport, $gsExportFile, $ReportLanguage, $Security;
 999		global $TKTrinhdo;
1000
1001		// Get export parameters
1002		if (@$_GET["export"] <> "") {
1003			$TKTrinhdo->Export = $_GET["export"];
1004		}
1005		$gsExport = $TKTrinhdo->Export; // Get export parameter, used in header
1006		$gsExportFile = $TKTrinhdo->TableVar; // Get export file, used in header
1007		if ($TKTrinhdo->Export == "excel") {
1008			header('Content-Type: application/vnd.ms-excel;charset=utf-8');
1009			header('Content-Disposition: attachment; filename=' . $gsExportFile .'.xls');
1010		}
1011		if ($TKTrinhdo->Export == "word") {
1012			header('Content-Type: application/vnd.ms-word;charset=utf-8');
1013			header('Content-Disposition: attachment; filename=' . $gsExportFile .'.doc');
1014		}
1015
1016		// Setup export options
1017		$this->SetupExportOptions();
1018
1019		// Global Page Loading event (in userfn*.php)
1020		Page_Loading();
1021
1022		// Page Load event
1023		$this->Page_Load();
1024	}
1025
1026	// Set up export options
1027	function SetupExportOptions() {
1028		global $ReportLanguage, $TKTrinhdo;
1029
1030		// Printer friendly
1031		$item =& $this->ExportOptions->Add("print");
1032		$item->Body = "<a href=\"" . $this->ExportPrintUrl . "\">" . $ReportLanguage->Phrase("PrinterFriendly") . "</a>";
1033		$item->Visible = TRUE;
1034
1035		// Export to Excel
1036		$item =& $this->ExportOptions->Add("excel");
1037		$item->Body = "<a href=\"" . $this->ExportExcelUrl . "\">" . $ReportLanguage->Phrase("ExportToExcel") . "</a>";
1038		$item->Visible = TRUE;
1039
1040		// Export to Word
1041		$item =& $this->ExportOptions->Add("word");
1042		$item->Body = "<a href=\"" . $this->ExportWordUrl . "\">" . $ReportLanguage->Phrase("ExportToWord") . "</a>";
1043		$item->Visible = TRUE;
1044
1045		// Export to Pdf
1046		$item =& $this->ExportOptions->Add("pdf");
1047		$item->Body = "<a href=\"" . $this->ExportPdfUrl . "\">" . $ReportLanguage->Phrase("ExportToPDF") . "</a>";
1048		$item->Visible = FALSE;
1049
1050		// Uncomment codes below to show export to Pdf link
1051//		$item->Visible = FALSE;
1052		// Export to Email
1053
1054		$item =& $this->ExportOptions->Add("email");
1055		$item->Body = "<a name=\"emf_TKTrinhdo\" id=\"emf_TKTrinhdo\" href=\"javascript:void(0);\" onclick=\"ewrpt_EmailDialogShow({lnk:'emf_TKTrinhdo',hdr:ewLanguage.Phrase('ExportToEmail')});\">" . $ReportLanguage->Phrase("ExportToEmail") . "</a>";
1056		$item->Visible = FALSE;
1057
1058		// Reset filter
1059		$item =& $this->ExportOptions->Add("resetfilter");
1060		$item->Body = "<a href=\"" . ewrpt_CurrentPage() . "?cmd=reset\">" . $ReportLanguage->Phrase("ResetAllFilter") . "</a>";
1061		$item->Visible = TRUE;
1062		$this->SetupExportOptionsExt();
1063
1064		// Hide options for export
1065		if ($TKTrinhdo->Export <> "")
1066			$this->ExportOptions->HideAllOptions();
1067
1068		// Set up table class
1069		if ($TKTrinhdo->Export == "word" || $TKTrinhdo->Export == "excel" || $TKTrinhdo->Export == "pdf")
1070			$this->ReportTableClass = "ewTable";
1071		else
1072			$this->ReportTableClass = "ewTable ewTableSeparate";
1073	}
1074
1075	//
1076	// Page_Terminate
1077	//
1078	function Page_Terminate($url = "") {
1079		global $conn;
1080		global $ReportLanguage;
1081		global $TKTrinhdo;
1082
1083		// Page Unload event
1084		$this->Page_Unload();
1085
1086		// Global Page Unloaded event (in userfn*.php)
1087		Page_Unloaded();
1088
1089		// Export to Email (use ob_file_contents for PHP)
1090		if ($TKTrinhdo->Export == "email") {
1091			$sContent = ob_get_contents();
1092			$this->ExportEmail($sContent);
1093			ob_end_clean();
1094
1095			 // Close connection
1096			$conn->Close();
1097			header("Location: " . ewrpt_CurrentPage());
1098			exit();
1099		}
1100
1101		// Export to PDF (use ob_file_contents for PHP)
1102		if ($TKTrinhdo->Export == "pdf") {
1103			$sContent = ob_get_contents();
1104			$this->ExportPDF($sContent);
1105			ob_end_clean();
1106
1107			 // Close connection
1108			$conn->Close();
1109		}
1110
1111		 // Close connection
1112		$conn->Close();
1113
1114		// Go to URL if specified
1115		if ($url <> "") {
1116			if (!EWRPT_DEBUG_ENABLED && ob_get_length())
1117				ob_end_clean();
1118			header("Location: " . $url);
1119		}
1120		exit();
1121	}
1122
1123	// Initialize common variables
1124	var $ExportOptions; // Export options
1125
1126	// Paging variables
1127	var $RecCount = 0; // Record count
1128	var $StartGrp = 0; // Start group
1129	var $StopGrp = 0; // Stop group
1130	var $TotalGrps = 0; // Total groups
1131	var $GrpCount = 0; // Group count
1132	var $DisplayGrps = 20; // Groups per page
1133	var $GrpRange = 10;
1134	var $Sort = "";
1135	var $Filter = "";
1136	var $UserIDFilter = "";
1137
1138	// Clear field for ext filter
1139	var $ClearExtFilter = "";
1140	var $FilterApplied;
1141	var $ShowFirstHeader;
1142	var $Cnt, $Col, $Val, $Smry;
1143	var $ColCount, $ColSpan;
1144	var $SqlSelectWork, $SqlSelectAggWork;
1145	var $SqlChartWork;
1146
1147	//
1148	// Page main
1149	//
1150	function Page_Main() {
1151		global $TKTrinhdo;
1152		global $rs;
1153		global $rsgrp;
1154		global $gsFormError;
1155
1156		// Get sort
1157		$this->Sort = $this->GetSort();
1158
1159		// Set up groups per page dynamically
1160		$this->SetUpDisplayGrps();
1161
1162		// Popup values and selections
1163		$TKTrinhdo->pqlf_name->SelectionList = "";
1164		$TKTrinhdo->pqlf_name->DefaultSelectionList = "";
1165		$TKTrinhdo->pqlf_name->ValueList = "";
1166
1167		// Load default filter values
1168		$this->LoadDefaultFilters();
1169
1170		// Load custom filters
1171		$TKTrinhdo->Filters_Load();
1172
1173		// Set up popup filter
1174		$this->SetupPopup();
1175
1176		// Extended filter
1177		$sExtendedFilter = "";
1178
1179		// Load columns to array
1180		$this->GetColumns();
1181
1182		// Build popup filter
1183		$sPopupFilter = $this->GetPopupFilter();
1184
1185		//ewrpt_SetDebugMsg("popup filter: " . $sPopupFilter);
1186		if ($sPopupFilter <> "") {
1187			if ($this->Filter <> "")
1188  				$this->Filter = "($this->Filter) AND ($sPopupFilter)";
1189			else
1190				$this->Filter = $sPopupFilter;
1191		}
1192
1193		// Check if filter applied
1194		$this->FilterApplied = $this->CheckFilter();
1195		$this->ExportOptions->GetItem("resetfilter")->Visible = $this->FilterApplied;
1196
1197		// Get total group count
1198		$sGrpSort = ewrpt_UpdateSortFields($TKTrinhdo->SqlOrderByGroup(), $this->Sort, 2); // Get grouping field only
1199		$sSql = ewrpt_BuildReportSql($TKTrinhdo->SqlSelectGroup(), $TKTrinhdo->SqlWhere(), $TKTrinhdo->SqlGroupBy(), "", $TKTrinhdo->SqlOrderByGroup(), $this->Filter, $sGrpSort);
1200		$this->TotalGrps = $this->GetGrpCnt($sSql);
1201		if ($this->DisplayGrps <= 0) // Display all groups
1202			$this->DisplayGrps = $this->TotalGrps;
1203		$this->StartGrp = 1;
1204
1205		// Show header
1206		$this->ShowFirstHeader = ($this->TotalGrps > 0);
1207
1208		//$this->ShowFirstHeader = TRUE; // Uncomment to always show header
1209		// Set up start position if not export all
1210
1211		if ($TKTrinhdo->ExportAll && $TKTrinhdo->Export <> "")
1212			$this->DisplayGrps = $this->TotalGrps;
1213		else
1214			$this->SetUpStartGroup();
1215
1216		// Hide all options if export
1217		if ($TKTrinhdo->Export <> "") {
1218			$this->ExportOptions->HideAllOptions();
1219		}
1220
1221		// Get total groups
1222		$rsgrp = $this->GetGrpRs($sSql, $this->StartGrp, $this->DisplayGrps);
1223
1224		// Init detail recordset
1225		$rs = NULL;
1226
1227		// Set up column attributes
1228		$TKTrinhdo->name->ViewAttrs["style"] = "";
1229		$TKTrinhdo->name->CellAttrs["style"] = "white-space: nowrap; vertical-align: top;";
1230	}
1231
1232	// Get column values
1233	function GetColumns() {
1234		global $conn;
1235		global $TKTrinhdo;
1236		global $ReportLanguage;
1237
1238		// Build SQL
1239		$sSql = ewrpt_BuildReportSql($TKTrinhdo->SqlDistinctSelect(), $TKTrinhdo->SqlDistinctWhere(), "", "", $TKTrinhdo->SqlDistinctOrderBy(), $this->Filter, "");
1240
1241		// Load recordset
1242		$rscol = $conn->Execute($sSql);
1243
1244		// Get distinct column count
1245		$this->ColCount = ($rscol) ? $rscol->RecordCount() : 0;
1246
1247/* Uncomment to show phrase
1248		if ($this->ColCount == 0) {
1249			if ($rscol) $rscol->Close();
1250			echo $ReportLanguage->Phrase("NoDistinctColVals") . $sSql . "<br>";
1251			exit();
1252		}
1253*/
1254
1255		// 1st dimension = no of groups (level 0 used for grand total)
1256		// 2nd dimension = no of distinct values
1257
1258		$nGrps = 2;
1259		$this->Col =& ewrpt_InitArray($this->ColCount+1, NULL);
1260		$this->Val =& ewrpt_InitArray($this->ColCount+1, NULL);
1261		$this->ValCnt =& ewrpt_InitArray($this->ColCount+1, NULL);
1262		$this->Cnt =& ewrpt_Init2DArray($this->ColCount+1, $nGrps+1, NULL);
1263		$this->Smry =& ewrpt_Init2DArray($this->ColCount+1, $nGrps+1, NULL);
1264		$this->SmryCnt =& ewrpt_Init2DArray($this->ColCount+1, $nGrps+1, NULL);
1265
1266		// Reset summary values
1267		$this->ResetLevelSummary(0);
1268		$colcnt = 0;
1269		while (!$rscol->EOF) {
1270			if (is_null($rscol->fields[0])) {
1271				$wrkValue = EWRPT_NULL_VALUE;
1272				$wrkCaption = $ReportLanguage->Phrase("NullLabel");
1273			} elseif ($rscol->fields[0] == "") {
1274				$wrkValue = EWRPT_EMPTY_VALUE;
1275				$wrkCaption = $ReportLanguage->Phrase("EmptyLabel");
1276			} else {
1277				$wrkValue = $rscol->fields[0];
1278				$wrkCaption = $rscol->fields[0];
1279			}
1280			$colcnt++;
1281			$this->Col[$colcnt] = new crCrosstabColumn($wrkValue, $wrkCaption, TRUE);
1282			$rscol->MoveNext();
1283		}
1284		$rscol->Close();
1285
1286		// Get active columns
1287		if (!is_array($TKTrinhdo->name->SelectionList)) {
1288			$this->ColSpan = $this->ColCount;
1289		} else {
1290			$this->ColSpan = 0;
1291			for ($i = 1; $i <= $this->ColCount; $i++) {
1292				$bSelected = FALSE;
1293				$cntsel = count($TKTrinhdo->name->SelectionList);
1294				for ($j = 0; $j < $cntsel; $j++) {
1295					if (ewrpt_CompareValue($TKTrinhdo->name->SelectionList[$j], $this->Col[$i]->Value, $TKTrinhdo->name->FldType)) {
1296						$this->ColSpan++;
1297						$bSelected = TRUE;
1298						break;
1299					}
1300				}
1301				$this->Col[$i]->Visible = $bSelected;
1302			}
1303		}
1304
1305		// Update crosstab sql
1306		$sSqlFlds = "";
1307		for ($colcnt = 1; $colcnt <= $this->ColCount; $colcnt++) {
1308			$sFld = ewrpt_CrossTabField($TKTrinhdo->SummaryType(), $TKTrinhdo->SummaryField(), $TKTrinhdo->ColumnField(), $TKTrinhdo->ColumnDateType(), $this->Col[$colcnt]->Value, "'", "C" . $colcnt);
1309			if ($sSqlFlds <> "")
1310				$sSqlFlds .= ", ";
1311			$sSqlFlds .= $sFld;
1312		}
1313		$this->SqlSelectWork = str_replace("<DistinctColumnFields>", $sSqlFlds, $TKTrinhdo->SqlSelect());
1314		$this->SqlSelectAggWork = str_replace("<DistinctColumnFields>", $sSqlFlds, $TKTrinhdo->SqlSelectAgg());
1315
1316		// Update chart sql if Y Axis = Column Field
1317		$this->SqlChartWork = "";
1318		for ($i = 0; $i < $this->ColCount; $i++) {
1319			if ($this->Col[$i+1]->Visible) {
1320				$sChtFld = ewrpt_CrossTabField("SUM", $TKTrinhdo->SummaryField(), $TKTrinhdo->ColumnField(), $TKTrinhdo->ColumnDateType(), $this->Col[$i+1]->Value, "'");
1321				if ($this->SqlChartWork != "") $this->SqlChartWork .= "+";
1322				$this->SqlChartWork .= $sChtFld;
1323			}
1324		}
1325	}
1326
1327	// Get group count
1328	function GetGrpCnt($sql) {
1329		global $conn;
1330		$rsgrpcnt = $conn->Execute($sql);
1331		$grpcnt = ($rsgrpcnt) ? $rsgrpcnt->RecordCount() : 0;
1332		if ($rsgrpcnt) $rsgrpcnt->Close();
1333		return $grpcnt;
1334	}
1335
1336	// Get group rs
1337	function GetGrpRs($sql, $start, $grps) {
1338		global $conn;
1339		$wrksql = $sql;
1340		if ($start > 0 && $grps > -1)
1341			$wrksql .= " LIMIT " . ($start-1) . ", " . ($grps);
1342		$rswrk = $conn->Execute($wrksql);
1343		return $rswrk;
1344	}
1345
1346	// Get group row values
1347	function GetGrpRow($opt) {
1348		global $rsgrp;
1349		global $TKTrinhdo;
1350		if (!$rsgrp)
1351			return;
1352		if ($opt == 1) { // Get first group
1353
1354	//		$rsgrp->MoveFirst(); // NOTE: no need to move position
1355			$TKTrinhdo->pqlf_name->setDbValue(""); // Init first value
1356		} else { // Get next group
1357			$rsgrp->MoveNext();
1358		}
1359		if (!$rsgrp->EOF) {
1360			$TKTrinhdo->pqlf_name->setDbValue($rsgrp->fields[0]);
1361		} else {
1362			$TKTrinhdo->pqlf_name->setDbValue("");
1363		}
1364	}
1365
1366	// Get row values
1367	function GetRow($opt) {
1368		global $rs;
1369		global $TKTrinhdo;
1370		if (!$rs)
1371			return;
1372		if ($opt == 1) { // Get first row
1373
1374	//		$rs->MoveFirst(); // NOTE: no need to move position
1375		} else { // Get next row
1376			$rs->MoveNext();
1377		}
1378		if (!$rs->EOF) {
1379			if ($opt <> 1)
1380				$TKTrinhdo->pqlf_name->setDbValue($rs->fields('pqlf_name'));
1381			$TKTrinhdo->qlf_name->setDbValue($rs->fields('qlf_name'));
1382			$cntval = count($this->Val);
1383			for ($ix = 1; $ix < $cntval; $ix++)
1384				$this->Val[$ix] = $rs->fields[$ix+2-1];
1385		} else {
1386			$TKTrinhdo->pqlf_name->setDbValue("");
1387			$TKTrinhdo->qlf_name->setDbValue("");
1388		}
1389	}
1390
1391	// Check level break
1392	function ChkLvlBreak($lvl) {
1393		global $TKTrinhdo;
1394		switch ($lvl) {
1395			case 1:
1396				return (is_null($TKTrinhdo->pqlf_name->CurrentValue) && !is_null($TKTrinhdo->pqlf_name->OldValue)) ||
1397					(!is_null($TKTrinhdo->pqlf_name->CurrentValue) && is_null($TKTrinhdo->pqlf_name->OldValue)) ||
1398					($TKTrinhdo->pqlf_name->GroupValue() <> $TKTrinhdo->pqlf_name->GroupOldValue());
1399			case 2:
1400				return (is_null($TKTrinhdo->qlf_name->CurrentValue) && !is_null($TKTrinhdo->qlf_name->OldValue)) ||
1401					(!is_null($TKTrinhdo->qlf_name->CurrentValue) && is_null($TKTrinhdo->qlf_name->OldValue)) ||
1402					($TKTrinhdo->qlf_name->GroupValue() <> $TKTrinhdo->qlf_name->GroupOldValue()) || $this->ChkLvlBreak(1); // Recurse upper level
1403		}
1404	}
1405
1406	// Accummulate summary
1407	function AccumulateSummary() {
1408		global $TKTrinhdo;
1409		$cntx = count($this->Smry);
1410		for ($ix = 1; $ix < $cntx; $ix++) {
1411			$cnty = count($this->Smry[$ix]);
1412			for ($iy = 0; $iy < $cnty; $iy++) {
1413				$valwrk = $this->Val[$ix];
1414				$this->Cnt[$ix][$iy]++;
1415				$this->Smry[$ix][$iy] = ewrpt_SummaryValue($this->Smry[$ix][$iy], $valwrk, $TKTrinhdo->SummaryType());
1416			}
1417		}
1418	}
1419
1420	// Reset level summary
1421	function ResetLevelSummary($lvl) {
1422
1423		// Clear summary values
1424		$cntx = count($this->Smry);
1425		for ($ix = 1; $ix < $cntx; $ix++) {
1426			$cnty = count($this->Smry[$ix]);
1427			for ($iy = $lvl; $iy < $cnty; $iy++) {
1428				$this->Cnt[$ix][$iy] = 0;
1429				$this->Smry[$ix][$iy] = 0;
1430			}
1431		}
1432
1433		// Reset record count
1434		$this->RecCount = 0;
1435	}
1436
1437	// Set up starting group
1438	function SetUpStartGroup() {
1439		global $TKTrinhdo;
1440
1441		// Exit if no groups
1442		if ($this->DisplayGrps == 0)
1443			return;
1444
1445		// Check for a 'start' parameter
1446		if (@$_GET[EWRPT_TABLE_START_GROUP] != "") {
1447			$this->StartGrp = $_GET[EWRPT_TABLE_START_GROUP];
1448			$TKTā€¦

Large files files are truncated, but you can click here to view the full file