<?php

// Global variable for table object
$luasview = NULL;

//
// Table class for luasview
//
class crluasview extends crTableBase {
	var $ShowGroupHeaderAsRow = FALSE;
	var $ShowCompactSummaryFooter = TRUE;
	var $Chart1;
	var $Chart2;
	var $Chart3;
	var $Pic;
	var $varietas;
	var $Provinsi;
	var $Kabupaten;
	var $Koordinator;
	var $Tahun;
	var $Bulan;
	var $Luas;
	var $Estimasi_Panen;
	var $Aktual_Panen;
	var $Rata_rata_Skor;

	//
	// Table class constructor
	//
	function __construct() {
		global $ReportLanguage, $gsLanguage;
		$this->TableVar = 'luasview';
		$this->TableName = 'luasview';
		$this->TableType = 'VIEW';
		$this->DBID = 'DB';
		$this->ExportAll = FALSE;
		$this->ExportPageBreakCount = 0;

		// Pic
		$this->Pic = new crField('luasview', 'luasview', 'x_Pic', 'Pic', '`Pic`', 200, EWR_DATATYPE_STRING, -1);
		$this->Pic->Sortable = TRUE; // Allow sort
		$this->fields['Pic'] = &$this->Pic;
		$this->Pic->DateFilter = "";
		$this->Pic->SqlSelect = "";
		$this->Pic->SqlOrderBy = "";

		// varietas
		$this->varietas = new crField('luasview', 'luasview', 'x_varietas', 'varietas', '`varietas`', 200, EWR_DATATYPE_STRING, -1);
		$this->varietas->Sortable = TRUE; // Allow sort
		$this->fields['varietas'] = &$this->varietas;
		$this->varietas->DateFilter = "";
		$this->varietas->SqlSelect = "";
		$this->varietas->SqlOrderBy = "";

		// Provinsi
		$this->Provinsi = new crField('luasview', 'luasview', 'x_Provinsi', 'Provinsi', '`Provinsi`', 200, EWR_DATATYPE_STRING, -1);
		$this->Provinsi->Sortable = TRUE; // Allow sort
		$this->fields['Provinsi'] = &$this->Provinsi;
		$this->Provinsi->DateFilter = "";
		$this->Provinsi->SqlSelect = "";
		$this->Provinsi->SqlOrderBy = "";

		// Kabupaten
		$this->Kabupaten = new crField('luasview', 'luasview', 'x_Kabupaten', 'Kabupaten', '`Kabupaten`', 200, EWR_DATATYPE_STRING, -1);
		$this->Kabupaten->Sortable = TRUE; // Allow sort
		$this->fields['Kabupaten'] = &$this->Kabupaten;
		$this->Kabupaten->DateFilter = "";
		$this->Kabupaten->SqlSelect = "";
		$this->Kabupaten->SqlOrderBy = "";

		// Koordinator
		$this->Koordinator = new crField('luasview', 'luasview', 'x_Koordinator', 'Koordinator', '`Koordinator`', 200, EWR_DATATYPE_STRING, -1);
		$this->Koordinator->Sortable = TRUE; // Allow sort
		$this->fields['Koordinator'] = &$this->Koordinator;
		$this->Koordinator->DateFilter = "";
		$this->Koordinator->SqlSelect = "";
		$this->Koordinator->SqlOrderBy = "";

		// Tahun
		$this->Tahun = new crField('luasview', 'luasview', 'x_Tahun', 'Tahun', '`Tahun`', 3, EWR_DATATYPE_NUMBER, -1);
		$this->Tahun->Sortable = TRUE; // Allow sort
		$this->Tahun->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
		$this->fields['Tahun'] = &$this->Tahun;
		$this->Tahun->DateFilter = "";
		$this->Tahun->SqlSelect = "";
		$this->Tahun->SqlOrderBy = "";

		// Bulan
		$this->Bulan = new crField('luasview', 'luasview', 'x_Bulan', 'Bulan', '`Bulan`', 3, EWR_DATATYPE_NUMBER, -1);
		$this->Bulan->Sortable = TRUE; // Allow sort
		$this->Bulan->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
		$this->fields['Bulan'] = &$this->Bulan;
		$this->Bulan->DateFilter = "";
		$this->Bulan->SqlSelect = "";
		$this->Bulan->SqlOrderBy = "";

		// Luas
		$this->Luas = new crField('luasview', 'luasview', 'x_Luas', 'Luas', '`Luas`', 131, EWR_DATATYPE_NUMBER, -1);
		$this->Luas->Sortable = TRUE; // Allow sort
		$this->Luas->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectFloat");
		$this->fields['Luas'] = &$this->Luas;
		$this->Luas->DateFilter = "";
		$this->Luas->SqlSelect = "";
		$this->Luas->SqlOrderBy = "";

		// Estimasi_Panen
		$this->Estimasi_Panen = new crField('luasview', 'luasview', 'x_Estimasi_Panen', 'Estimasi_Panen', '`Estimasi_Panen`', 131, EWR_DATATYPE_NUMBER, -1);
		$this->Estimasi_Panen->Sortable = TRUE; // Allow sort
		$this->Estimasi_Panen->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectFloat");
		$this->fields['Estimasi_Panen'] = &$this->Estimasi_Panen;
		$this->Estimasi_Panen->DateFilter = "";
		$this->Estimasi_Panen->SqlSelect = "";
		$this->Estimasi_Panen->SqlOrderBy = "";

		// Aktual_Panen
		$this->Aktual_Panen = new crField('luasview', 'luasview', 'x_Aktual_Panen', 'Aktual_Panen', '`Aktual_Panen`', 131, EWR_DATATYPE_NUMBER, -1);
		$this->Aktual_Panen->Sortable = TRUE; // Allow sort
		$this->Aktual_Panen->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectFloat");
		$this->fields['Aktual_Panen'] = &$this->Aktual_Panen;
		$this->Aktual_Panen->DateFilter = "";
		$this->Aktual_Panen->SqlSelect = "";
		$this->Aktual_Panen->SqlOrderBy = "";

		// Rata_rata_Skor
		$this->Rata_rata_Skor = new crField('luasview', 'luasview', 'x_Rata_rata_Skor', 'Rata_rata_Skor', '`Rata_rata_Skor`', 5, EWR_DATATYPE_NUMBER, -1);
		$this->Rata_rata_Skor->Sortable = TRUE; // Allow sort
		$this->Rata_rata_Skor->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectFloat");
		$this->fields['Rata_rata_Skor'] = &$this->Rata_rata_Skor;
		$this->Rata_rata_Skor->DateFilter = "";
		$this->Rata_rata_Skor->SqlSelect = "";
		$this->Rata_rata_Skor->SqlOrderBy = "";

		// Chart1
		$this->Chart1 = new crChart($this->DBID, 'luasview', 'luasview', 'Chart1', 'Chart1', 'Pic', 'Luas', '', 5, 'SUM', 800, 440);
		$this->Chart1->SqlSelect = "SELECT `Pic`, '', SUM(`Luas`) FROM ";
		$this->Chart1->SqlGroupBy = "`Pic`";
		$this->Chart1->SqlOrderBy = "";
		$this->Chart1->SeriesDateType = "";
		$this->Chart1->ChartDefaultDecimalPrecision = 0;

		// Chart2
		$this->Chart2 = new crChart($this->DBID, 'luasview', 'luasview', 'Chart2', 'Chart2', 'Pic', 'Estimasi_Panen', '', 19, 'SUM', 800, 440);
		$this->Chart2->SqlSelect = "SELECT `Pic`, '', SUM(`Estimasi_Panen`), SUM(`Aktual_Panen`) FROM ";
		$this->Chart2->SqlGroupBy = "`Pic`";
		$this->Chart2->SqlOrderBy = "";
		$this->Chart2->SeriesDateType = "";

		// Chart3
		$this->Chart3 = new crChart($this->DBID, 'luasview', 'luasview', 'Chart3', 'Chart3', 'Pic', 'Rata_rata_Skor', '', 5, 'AVG', 800, 440);
		$this->Chart3->SqlSelect = "SELECT `Pic`, '', AVG(`Rata_rata_Skor`) FROM ";
		$this->Chart3->SqlGroupBy = "`Pic`";
		$this->Chart3->SqlOrderBy = "";
		$this->Chart3->SeriesDateType = "";
	}

	// Set Field Visibility
	function SetFieldVisibility($fldparm) {
		global $Security;
		return $this->$fldparm->Visible; // Returns original value
	}

	// Single column sort
	function UpdateSort(&$ofld) {
		if ($this->CurrentOrder == $ofld->FldName) {
			$sSortField = $ofld->FldExpression;
			$sLastSort = $ofld->getSort();
			if ($this->CurrentOrderType == "ASC" || $this->CurrentOrderType == "DESC") {
				$sThisSort = $this->CurrentOrderType;
			} else {
				$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			}
			$ofld->setSort($sThisSort);
			if ($ofld->GroupingFieldId == 0)
				$this->setDetailOrderBy($sSortField . " " . $sThisSort); // Save to Session
		} else {
			if ($ofld->GroupingFieldId == 0) $ofld->setSort("");
		}
	}

	// Get Sort SQL
	function SortSql() {
		$sDtlSortSql = $this->getDetailOrderBy(); // Get ORDER BY for detail fields from session
		$argrps = array();
		foreach ($this->fields as $fld) {
			if ($fld->getSort() <> "") {
				$fldsql = $fld->FldExpression;
				if ($fld->GroupingFieldId > 0) {
					if ($fld->FldGroupSql <> "")
						$argrps[$fld->GroupingFieldId] = str_replace("%s", $fldsql, $fld->FldGroupSql) . " " . $fld->getSort();
					else
						$argrps[$fld->GroupingFieldId] = $fldsql . " " . $fld->getSort();
				}
			}
		}
		$sSortSql = "";
		foreach ($argrps as $grp) {
			if ($sSortSql <> "") $sSortSql .= ", ";
			$sSortSql .= $grp;
		}
		if ($sDtlSortSql <> "") {
			if ($sSortSql <> "") $sSortSql .= ", ";
			$sSortSql .= $sDtlSortSql;
		}
		return $sSortSql;
	}

	// Table level SQL
	// From

	var $_SqlFrom = "";

	function getSqlFrom() {
		return ($this->_SqlFrom <> "") ? $this->_SqlFrom : "`luasview`";
	}

	function SqlFrom() { // For backward compatibility
		return $this->getSqlFrom();
	}

	function setSqlFrom($v) {
		$this->_SqlFrom = $v;
	}

	// Select
	var $_SqlSelect = "";

	function getSqlSelect() {
		return ($this->_SqlSelect <> "") ? $this->_SqlSelect : "SELECT * FROM " . $this->getSqlFrom();
	}

	function SqlSelect() { // For backward compatibility
		return $this->getSqlSelect();
	}

	function setSqlSelect($v) {
		$this->_SqlSelect = $v;
	}

	// Where
	var $_SqlWhere = "";

	function getSqlWhere() {
		$sWhere = ($this->_SqlWhere <> "") ? $this->_SqlWhere : "";
		return $sWhere;
	}

	function SqlWhere() { // For backward compatibility
		return $this->getSqlWhere();
	}

	function setSqlWhere($v) {
		$this->_SqlWhere = $v;
	}

	// Group By
	var $_SqlGroupBy = "";

	function getSqlGroupBy() {
		return ($this->_SqlGroupBy <> "") ? $this->_SqlGroupBy : "";
	}

	function SqlGroupBy() { // For backward compatibility
		return $this->getSqlGroupBy();
	}

	function setSqlGroupBy($v) {
		$this->_SqlGroupBy = $v;
	}

	// Having
	var $_SqlHaving = "";

	function getSqlHaving() {
		return ($this->_SqlHaving <> "") ? $this->_SqlHaving : "";
	}

	function SqlHaving() { // For backward compatibility
		return $this->getSqlHaving();
	}

	function setSqlHaving($v) {
		$this->_SqlHaving = $v;
	}

	// Order By
	var $_SqlOrderBy = "";

	function getSqlOrderBy() {
		return ($this->_SqlOrderBy <> "") ? $this->_SqlOrderBy : "";
	}

	function SqlOrderBy() { // For backward compatibility
		return $this->getSqlOrderBy();
	}

	function setSqlOrderBy($v) {
		$this->_SqlOrderBy = $v;
	}

	// Select Aggregate
	var $_SqlSelectAgg = "";

	function getSqlSelectAgg() {
		return ($this->_SqlSelectAgg <> "") ? $this->_SqlSelectAgg : "SELECT SUM(`Luas`) AS `sum_luas`, SUM(`Estimasi_Panen`) AS `sum_estimasi_panen`, SUM(`Aktual_Panen`) AS `sum_aktual_panen`, SUM(`Rata_rata_Skor`) AS `sum_rata_rata_skor` FROM " . $this->getSqlFrom();
	}

	function SqlSelectAgg() { // For backward compatibility
		return $this->getSqlSelectAgg();
	}

	function setSqlSelectAgg($v) {
		$this->_SqlSelectAgg = $v;
	}

	// Aggregate Prefix
	var $_SqlAggPfx = "";

	function getSqlAggPfx() {
		return ($this->_SqlAggPfx <> "") ? $this->_SqlAggPfx : "";
	}

	function SqlAggPfx() { // For backward compatibility
		return $this->getSqlAggPfx();
	}

	function setSqlAggPfx($v) {
		$this->_SqlAggPfx = $v;
	}

	// Aggregate Suffix
	var $_SqlAggSfx = "";

	function getSqlAggSfx() {
		return ($this->_SqlAggSfx <> "") ? $this->_SqlAggSfx : "";
	}

	function SqlAggSfx() { // For backward compatibility
		return $this->getSqlAggSfx();
	}

	function setSqlAggSfx($v) {
		$this->_SqlAggSfx = $v;
	}

	// Select Count
	var $_SqlSelectCount = "";

	function getSqlSelectCount() {
		return ($this->_SqlSelectCount <> "") ? $this->_SqlSelectCount : "SELECT COUNT(*) FROM " . $this->getSqlFrom();
	}

	function SqlSelectCount() { // For backward compatibility
		return $this->getSqlSelectCount();
	}

	function setSqlSelectCount($v) {
		$this->_SqlSelectCount = $v;
	}

	// Sort URL
	function SortUrl(&$fld) {
		return "";
	}

	// Setup lookup filters of a field
	function SetupLookupFilters($fld) {
		global $gsLanguage;
		switch ($fld->FldVar) {
		case "x_Pic":
			$sSqlWrk = "";
		$sSqlWrk = "SELECT DISTINCT `Pic`, `Pic` AS `DispFld`, '' AS `DispFld2`, '' AS `DispFld3`, '' AS `DispFld4` FROM `luasview`";
		$sWhereWrk = "";
		$this->Pic->LookupFilters = array();
			$fld->LookupFilters += array("s" => $sSqlWrk, "d" => "DB", "f0" => '`Pic` = {filter_value}', "t0" => "200", "fn0" => "", "dlm" => ewr_Encrypt($fld->FldDelimiter));
			$sSqlWrk = "";
		$this->Lookup_Selecting($this->Pic, $sWhereWrk); // Call Lookup selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Pic` DESC";
			if ($sSqlWrk <> "")
				$fld->LookupFilters["s"] .= $sSqlWrk;
			break;
		case "x_varietas":
			$sSqlWrk = "";
		$sSqlWrk = "SELECT DISTINCT `varietas`, `varietas` AS `DispFld`, '' AS `DispFld2`, '' AS `DispFld3`, '' AS `DispFld4` FROM `luasview`";
		$sWhereWrk = "";
		$this->varietas->LookupFilters = array();
			$fld->LookupFilters += array("s" => $sSqlWrk, "d" => "DB", "f0" => '`varietas` = {filter_value}', "t0" => "200", "fn0" => "", "dlm" => ewr_Encrypt($fld->FldDelimiter));
			$sSqlWrk = "";
		$this->Lookup_Selecting($this->varietas, $sWhereWrk); // Call Lookup selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `varietas` ASC";
			if ($sSqlWrk <> "")
				$fld->LookupFilters["s"] .= $sSqlWrk;
			break;
		case "x_Provinsi":
			$sSqlWrk = "";
		$sSqlWrk = "SELECT DISTINCT `Provinsi`, `Provinsi` AS `DispFld`, '' AS `DispFld2`, '' AS `DispFld3`, '' AS `DispFld4` FROM `luasview`";
		$sWhereWrk = "";
		$this->Provinsi->LookupFilters = array();
			$fld->LookupFilters += array("s" => $sSqlWrk, "d" => "DB", "f0" => '`Provinsi` = {filter_value}', "t0" => "200", "fn0" => "", "dlm" => ewr_Encrypt($fld->FldDelimiter));
			$sSqlWrk = "";
		$this->Lookup_Selecting($this->Provinsi, $sWhereWrk); // Call Lookup selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Provinsi` ASC";
			if ($sSqlWrk <> "")
				$fld->LookupFilters["s"] .= $sSqlWrk;
			break;
		case "x_Kabupaten":
			$sSqlWrk = "";
		$sSqlWrk = "SELECT DISTINCT `Kabupaten`, `Kabupaten` AS `DispFld`, '' AS `DispFld2`, '' AS `DispFld3`, '' AS `DispFld4` FROM `luasview`";
		$sWhereWrk = "";
		$this->Kabupaten->LookupFilters = array();
			$fld->LookupFilters += array("s" => $sSqlWrk, "d" => "DB", "f0" => '`Kabupaten` = {filter_value}', "t0" => "200", "fn0" => "", "dlm" => ewr_Encrypt($fld->FldDelimiter));
			$sSqlWrk = "";
		$this->Lookup_Selecting($this->Kabupaten, $sWhereWrk); // Call Lookup selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Kabupaten` ASC";
			if ($sSqlWrk <> "")
				$fld->LookupFilters["s"] .= $sSqlWrk;
			break;
		case "x_Koordinator":
			$sSqlWrk = "";
		$sSqlWrk = "SELECT DISTINCT `Koordinator`, `Koordinator` AS `DispFld`, '' AS `DispFld2`, '' AS `DispFld3`, '' AS `DispFld4` FROM `luasview`";
		$sWhereWrk = "";
		$this->Koordinator->LookupFilters = array();
			$fld->LookupFilters += array("s" => $sSqlWrk, "d" => "DB", "f0" => '`Koordinator` = {filter_value}', "t0" => "200", "fn0" => "", "dlm" => ewr_Encrypt($fld->FldDelimiter));
			$sSqlWrk = "";
		$this->Lookup_Selecting($this->Koordinator, $sWhereWrk); // Call Lookup selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Koordinator` ASC";
			if ($sSqlWrk <> "")
				$fld->LookupFilters["s"] .= $sSqlWrk;
			break;
		case "x_Tahun":
			$sSqlWrk = "";
		$sSqlWrk = "SELECT DISTINCT `Tahun`, `Tahun` AS `DispFld`, '' AS `DispFld2`, '' AS `DispFld3`, '' AS `DispFld4` FROM `luasview`";
		$sWhereWrk = "";
		$this->Tahun->LookupFilters = array();
			$fld->LookupFilters += array("s" => $sSqlWrk, "d" => "DB", "f0" => '`Tahun` = {filter_value}', "t0" => "3", "fn0" => "", "dlm" => ewr_Encrypt($fld->FldDelimiter));
			$sSqlWrk = "";
		$this->Lookup_Selecting($this->Tahun, $sWhereWrk); // Call Lookup selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Tahun` DESC";
			if ($sSqlWrk <> "")
				$fld->LookupFilters["s"] .= $sSqlWrk;
			break;
		case "x_Bulan":
			$sSqlWrk = "";
		$sSqlWrk = "SELECT DISTINCT `Bulan`, `Bulan` AS `DispFld`, '' AS `DispFld2`, '' AS `DispFld3`, '' AS `DispFld4` FROM `luasview`";
		$sWhereWrk = "";
		$this->Bulan->LookupFilters = array();
			$fld->LookupFilters += array("s" => $sSqlWrk, "d" => "DB", "f0" => '`Bulan` = {filter_value}', "t0" => "3", "fn0" => "", "dlm" => ewr_Encrypt($fld->FldDelimiter));
			$sSqlWrk = "";
		$this->Lookup_Selecting($this->Bulan, $sWhereWrk); // Call Lookup selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Bulan` ASC";
			if ($sSqlWrk <> "")
				$fld->LookupFilters["s"] .= $sSqlWrk;
			break;
		}
	}

	// Setup AutoSuggest filters of a field
	function SetupAutoSuggestFilters($fld) {
		global $gsLanguage;
		switch ($fld->FldVar) {
		}
	}

	// Table level events
	// Page Selecting event
	function Page_Selecting(&$filter) {

		// Enter your code here
	}

	// Page Breaking event
	function Page_Breaking(&$break, &$content) {

		// Example:
		//$break = FALSE; // Skip page break, or
		//$content = "<div style=\"page-break-after:always;\">&nbsp;</div>"; // Modify page break content

	}

	// Row Rendering event
	function Row_Rendering() {

		// Enter your code here
	}

	// Cell Rendered event
	function Cell_Rendered(&$Field, $CurrentValue, &$ViewValue, &$ViewAttrs, &$CellAttrs, &$HrefValue, &$LinkAttrs) {

		//$ViewValue = "xxx";
		//$ViewAttrs["style"] = "xxx";

	}

	// Row Rendered event
	function Row_Rendered() {

		// To view properties of field class, use:
		//var_dump($this-><FieldName>);

	}

	// User ID Filtering event
	function UserID_Filtering(&$filter) {

		// Enter your code here
	}

	// Load Filters event
	function Page_FilterLoad() {

		// Enter your code here
		// Example: Register/Unregister Custom Extended Filter
		//ewr_RegisterFilter($this-><Field>, 'StartsWithA', 'Starts With A', 'GetStartsWithAFilter'); // With function, or
		//ewr_RegisterFilter($this-><Field>, 'StartsWithA', 'Starts With A'); // No function, use Page_Filtering event
		//ewr_UnregisterFilter($this-><Field>, 'StartsWithA');

	}

	// Page Filter Validated event
	function Page_FilterValidated() {

		// Example:
		//$this->MyField1->SearchValue = "your search criteria"; // Search value

	}

	// Page Filtering event
	function Page_Filtering(&$fld, &$filter, $typ, $opr = "", $val = "", $cond = "", $opr2 = "", $val2 = "") {

		// Note: ALWAYS CHECK THE FILTER TYPE ($typ)! Example:
		//if ($typ == "dropdown" && $fld->FldName == "MyField") // Dropdown filter
		//	$filter = "..."; // Modify the filter
		//if ($typ == "extended" && $fld->FldName == "MyField") // Extended filter
		//	$filter = "..."; // Modify the filter
		//if ($typ == "popup" && $fld->FldName == "MyField") // Popup filter
		//	$filter = "..."; // Modify the filter
		//if ($typ == "custom" && $opr == "..." && $fld->FldName == "MyField") // Custom filter, $opr is the custom filter ID
		//	$filter = "..."; // Modify the filter

	}

	// Email Sending event
	function Email_Sending(&$Email, &$Args) {

		//var_dump($Email); var_dump($Args); exit();
		return TRUE;
	}

	// Lookup Selecting event
	function Lookup_Selecting($fld, &$filter) {

		// Enter your code here
	}
}
?>
