<?php

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

//
// Table class for bibit
//
class cbibit extends cTable {
	var $id;
	var $tgl_tanam;
	var $jumlah_tanam;
	var $jumlah_panen_stek;
	var $ket;
	var $var_nama;
	var $id_gen;
	var $k_id_kontrak;
	var $co_nama;
	var $koord_nama;
	var $pet_nama;
	var $prov_nama;
	var $kab_nama;
	var $kec_nama;
	var $desa_nama;
	var $id_asal_bibit;

	//
	// Table class constructor
	//
	function __construct() {
		global $Language;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();
		$this->TableVar = 'bibit';
		$this->TableName = 'bibit';
		$this->TableType = 'VIEW';

		// Update Table
		$this->UpdateTable = "`bibit`";
		$this->DBID = 'DB';
		$this->ExportAll = TRUE;
		$this->ExportPageBreakCount = 0; // Page break per every n record (PDF only)
		$this->ExportPageOrientation = "portrait"; // Page orientation (PDF only)
		$this->ExportPageSize = "a4"; // Page size (PDF only)
		$this->ExportExcelPageOrientation = ""; // Page orientation (PHPExcel only)
		$this->ExportExcelPageSize = ""; // Page size (PHPExcel only)
		$this->ExportWordPageOrientation = "portrait"; // Page orientation (PHPWord only)
		$this->ExportWordColumnWidth = NULL; // Cell width (PHPWord only)
		$this->DetailAdd = FALSE; // Allow detail add
		$this->DetailEdit = FALSE; // Allow detail edit
		$this->DetailView = FALSE; // Allow detail view
		$this->ShowMultipleDetails = FALSE; // Show multiple details
		$this->GridAddRowCount = 5;
		$this->AllowAddDeleteRow = TRUE; // Allow add/delete row
		$this->UserIDAllowSecurity = 0; // User ID Allow
		$this->BasicSearch = new cBasicSearch($this->TableVar);

		// id
		$this->id = new cField('bibit', 'bibit', 'x_id', 'id', '`id`', '`id`', 3, -1, FALSE, '`id`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'NO');
		$this->id->Sortable = TRUE; // Allow sort
		$this->id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['id'] = &$this->id;

		// tgl_tanam
		$this->tgl_tanam = new cField('bibit', 'bibit', 'x_tgl_tanam', 'tgl_tanam', '`tgl_tanam`', ew_CastDateFieldForLike('`tgl_tanam`', 0, "DB"), 133, 0, FALSE, '`tgl_tanam`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->tgl_tanam->Sortable = TRUE; // Allow sort
		$this->tgl_tanam->FldDefaultErrMsg = str_replace("%s", $GLOBALS["EW_DATE_FORMAT"], $Language->Phrase("IncorrectDate"));
		$this->fields['tgl_tanam'] = &$this->tgl_tanam;

		// jumlah_tanam
		$this->jumlah_tanam = new cField('bibit', 'bibit', 'x_jumlah_tanam', 'jumlah_tanam', '`jumlah_tanam`', '`jumlah_tanam`', 3, -1, FALSE, '`jumlah_tanam`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->jumlah_tanam->Sortable = TRUE; // Allow sort
		$this->jumlah_tanam->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['jumlah_tanam'] = &$this->jumlah_tanam;

		// jumlah_panen_stek
		$this->jumlah_panen_stek = new cField('bibit', 'bibit', 'x_jumlah_panen_stek', 'jumlah_panen_stek', '`jumlah_panen_stek`', '`jumlah_panen_stek`', 3, -1, FALSE, '`jumlah_panen_stek`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->jumlah_panen_stek->Sortable = TRUE; // Allow sort
		$this->jumlah_panen_stek->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['jumlah_panen_stek'] = &$this->jumlah_panen_stek;

		// ket
		$this->ket = new cField('bibit', 'bibit', 'x_ket', 'ket', '`ket`', '`ket`', 200, -1, FALSE, '`ket`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->ket->Sortable = TRUE; // Allow sort
		$this->fields['ket'] = &$this->ket;

		// var_nama
		$this->var_nama = new cField('bibit', 'bibit', 'x_var_nama', 'var_nama', '`var_nama`', '`var_nama`', 200, -1, FALSE, '`var_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->var_nama->Sortable = TRUE; // Allow sort
		$this->var_nama->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->var_nama->PleaseSelectText = $Language->Phrase("PleaseSelect"); // PleaseSelect text
		$this->fields['var_nama'] = &$this->var_nama;

		// id_gen
		$this->id_gen = new cField('bibit', 'bibit', 'x_id_gen', 'id_gen', '`id_gen`', '`id_gen`', 200, -1, FALSE, '`id_gen`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->id_gen->Sortable = TRUE; // Allow sort
		$this->id_gen->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->id_gen->PleaseSelectText = $Language->Phrase("PleaseSelect"); // PleaseSelect text
		$this->fields['id_gen'] = &$this->id_gen;

		// k_id_kontrak
		$this->k_id_kontrak = new cField('bibit', 'bibit', 'x_k_id_kontrak', 'k_id_kontrak', '`k_id_kontrak`', '`k_id_kontrak`', 200, -1, FALSE, '`k_id_kontrak`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->k_id_kontrak->Sortable = TRUE; // Allow sort
		$this->k_id_kontrak->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->k_id_kontrak->PleaseSelectText = $Language->Phrase("PleaseSelect"); // PleaseSelect text
		$this->fields['k_id_kontrak'] = &$this->k_id_kontrak;

		// co_nama
		$this->co_nama = new cField('bibit', 'bibit', 'x_co_nama', 'co_nama', '`co_nama`', '`co_nama`', 200, -1, FALSE, '`co_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->co_nama->Sortable = TRUE; // Allow sort
		$this->co_nama->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->co_nama->PleaseSelectText = $Language->Phrase("PleaseSelect"); // PleaseSelect text
		$this->fields['co_nama'] = &$this->co_nama;

		// koord_nama
		$this->koord_nama = new cField('bibit', 'bibit', 'x_koord_nama', 'koord_nama', '`koord_nama`', '`koord_nama`', 200, -1, FALSE, '`koord_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->koord_nama->Sortable = TRUE; // Allow sort
		$this->fields['koord_nama'] = &$this->koord_nama;

		// pet_nama
		$this->pet_nama = new cField('bibit', 'bibit', 'x_pet_nama', 'pet_nama', '`pet_nama`', '`pet_nama`', 200, -1, FALSE, '`pet_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->pet_nama->Sortable = TRUE; // Allow sort
		$this->fields['pet_nama'] = &$this->pet_nama;

		// prov_nama
		$this->prov_nama = new cField('bibit', 'bibit', 'x_prov_nama', 'prov_nama', '`prov_nama`', '`prov_nama`', 200, -1, FALSE, '`prov_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->prov_nama->Sortable = TRUE; // Allow sort
		$this->fields['prov_nama'] = &$this->prov_nama;

		// kab_nama
		$this->kab_nama = new cField('bibit', 'bibit', 'x_kab_nama', 'kab_nama', '`kab_nama`', '`kab_nama`', 200, -1, FALSE, '`kab_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->kab_nama->Sortable = TRUE; // Allow sort
		$this->fields['kab_nama'] = &$this->kab_nama;

		// kec_nama
		$this->kec_nama = new cField('bibit', 'bibit', 'x_kec_nama', 'kec_nama', '`kec_nama`', '`kec_nama`', 200, -1, FALSE, '`kec_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->kec_nama->Sortable = TRUE; // Allow sort
		$this->fields['kec_nama'] = &$this->kec_nama;

		// desa_nama
		$this->desa_nama = new cField('bibit', 'bibit', 'x_desa_nama', 'desa_nama', '`desa_nama`', '`desa_nama`', 200, -1, FALSE, '`desa_nama`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->desa_nama->Sortable = TRUE; // Allow sort
		$this->fields['desa_nama'] = &$this->desa_nama;

		// id_asal_bibit
		$this->id_asal_bibit = new cField('bibit', 'bibit', 'x_id_asal_bibit', 'id_asal_bibit', '`id_asal_bibit`', '`id_asal_bibit`', 3, -1, FALSE, '`id_asal_bibit`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->id_asal_bibit->Sortable = TRUE; // Allow sort
		$this->id_asal_bibit->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['id_asal_bibit'] = &$this->id_asal_bibit;
	}

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

	// Column CSS classes
	var $LeftColumnClass = "col-sm-2 control-label ewLabel";
	var $RightColumnClass = "col-sm-10";
	var $OffsetColumnClass = "col-sm-10 col-sm-offset-2";

	// Set left column class (must be predefined col-*-* classes of Bootstrap grid system)
	function SetLeftColumnClass($class) {
		if (preg_match('/^col\-(\w+)\-(\d+)$/', $class, $match)) {
			$this->LeftColumnClass = $class . " control-label ewLabel";
			$this->RightColumnClass = "col-" . $match[1] . "-" . strval(12 - intval($match[2]));
			$this->OffsetColumnClass = $this->RightColumnClass . " " . str_replace($match[1], $match[1] + "-offset", $class);
		}
	}

	// 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);
			$this->setSessionOrderBy($sSortField . " " . $sThisSort); // Save to Session
		} else {
			$ofld->setSort("");
		}
	}

	// Table level SQL
	var $_SqlFrom = "";

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

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

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

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

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

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

	function getSqlWhere() { // Where
		$sWhere = ($this->_SqlWhere <> "") ? $this->_SqlWhere : "";
		$this->TableFilter = "";
		ew_AddFilter($sWhere, $this->TableFilter);
		return $sWhere;
	}

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

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

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

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

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

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

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

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

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

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

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

	// Apply User ID filters
	function ApplyUserIDFilters($sFilter) {
		return $sFilter;
	}

	// Check if User ID security allows view all
	function UserIDAllow($id = "") {
		$allow = EW_USER_ID_ALLOW;
		switch ($id) {
			case "add":
			case "copy":
			case "gridadd":
			case "register":
			case "addopt":
				return (($allow & 1) == 1);
			case "edit":
			case "gridedit":
			case "update":
			case "changepwd":
			case "forgotpwd":
				return (($allow & 4) == 4);
			case "delete":
				return (($allow & 2) == 2);
			case "view":
				return (($allow & 32) == 32);
			case "search":
				return (($allow & 64) == 64);
			default:
				return (($allow & 8) == 8);
		}
	}

	// Get SQL
	function GetSQL($where, $orderby) {
		return ew_BuildSelectSql($this->getSqlSelect(), $this->getSqlWhere(),
			$this->getSqlGroupBy(), $this->getSqlHaving(), $this->getSqlOrderBy(),
			$where, $orderby);
	}

	// Table SQL
	function SQL() {
		$filter = $this->CurrentFilter;
		$filter = $this->ApplyUserIDFilters($filter);
		$sort = $this->getSessionOrderBy();
		return $this->GetSQL($filter, $sort);
	}

	// Table SQL with List page filter
	var $UseSessionForListSQL = TRUE;

	function ListSQL() {
		$sFilter = $this->UseSessionForListSQL ? $this->getSessionWhere() : "";
		ew_AddFilter($sFilter, $this->CurrentFilter);
		$sFilter = $this->ApplyUserIDFilters($sFilter);
		$this->Recordset_Selecting($sFilter);
		$sSelect = $this->getSqlSelect();
		$sSort = $this->UseSessionForListSQL ? $this->getSessionOrderBy() : "";
		return ew_BuildSelectSql($sSelect, $this->getSqlWhere(), $this->getSqlGroupBy(),
			$this->getSqlHaving(), $this->getSqlOrderBy(), $sFilter, $sSort);
	}

	// Get ORDER BY clause
	function GetOrderBy() {
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql("", "", "", "", $this->getSqlOrderBy(), "", $sSort);
	}

	// Try to get record count
	function TryGetRecordCount($sql) {
		$cnt = -1;
		$pattern = "/^SELECT \* FROM/i";
		if (($this->TableType == 'TABLE' || $this->TableType == 'VIEW' || $this->TableType == 'LINKTABLE') && preg_match($pattern, $sql)) {
			$sql = "SELECT COUNT(*) FROM" . preg_replace($pattern, "", $sql);
		} else {
			$sql = "SELECT COUNT(*) FROM (" . $sql . ") EW_COUNT_TABLE";
		}
		$conn = &$this->Connection();
		if ($rs = $conn->Execute($sql)) {
			if (!$rs->EOF && $rs->FieldCount() > 0) {
				$cnt = $rs->fields[0];
				$rs->Close();
			}
		}
		return intval($cnt);
	}

	// Get record count based on filter (for detail record count in master table pages)
	function LoadRecordCount($filter) {
		$origFilter = $this->CurrentFilter;
		$this->CurrentFilter = $filter;
		$this->Recordset_Selecting($this->CurrentFilter);
		$select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : "SELECT * FROM " . $this->getSqlFrom();
		$groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
		$having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
		$sql = ew_BuildSelectSql($select, $this->getSqlWhere(), $groupBy, $having, "", $this->CurrentFilter, "");
		$cnt = $this->TryGetRecordCount($sql);
		if ($cnt == -1) {
			if ($rs = $this->LoadRs($this->CurrentFilter)) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $origFilter;
		return intval($cnt);
	}

	// Get record count (for current List page)
	function ListRecordCount() {
		$filter = $this->getSessionWhere();
		ew_AddFilter($filter, $this->CurrentFilter);
		$filter = $this->ApplyUserIDFilters($filter);
		$this->Recordset_Selecting($filter);
		$select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : "SELECT * FROM " . $this->getSqlFrom();
		$groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
		$having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
		$sql = ew_BuildSelectSql($select, $this->getSqlWhere(), $groupBy, $having, "", $filter, "");
		$cnt = $this->TryGetRecordCount($sql);
		if ($cnt == -1) {
			$conn = &$this->Connection();
			if ($rs = $conn->Execute($sql)) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		return intval($cnt);
	}

	// INSERT statement
	function InsertSQL(&$rs) {
		$names = "";
		$values = "";
		foreach ($rs as $name => $value) {
			if (!isset($this->fields[$name]) || $this->fields[$name]->FldIsCustom)
				continue;
			$names .= $this->fields[$name]->FldExpression . ",";
			$values .= ew_QuotedValue($value, $this->fields[$name]->FldDataType, $this->DBID) . ",";
		}
		$names = preg_replace('/,+$/', "", $names);
		$values = preg_replace('/,+$/', "", $values);
		return "INSERT INTO " . $this->UpdateTable . " ($names) VALUES ($values)";
	}

	// Insert
	function Insert(&$rs) {
		$conn = &$this->Connection();
		$bInsert = $conn->Execute($this->InsertSQL($rs));
		if ($bInsert) {

			// Get insert id if necessary
			$this->id->setDbValue($conn->Insert_ID());
			$rs['id'] = $this->id->DbValue;
		}
		return $bInsert;
	}

	// UPDATE statement
	function UpdateSQL(&$rs, $where = "", $curfilter = TRUE) {
		$sql = "UPDATE " . $this->UpdateTable . " SET ";
		foreach ($rs as $name => $value) {
			if (!isset($this->fields[$name]) || $this->fields[$name]->FldIsCustom)
				continue;
			$sql .= $this->fields[$name]->FldExpression . "=";
			$sql .= ew_QuotedValue($value, $this->fields[$name]->FldDataType, $this->DBID) . ",";
		}
		$sql = preg_replace('/,+$/', "", $sql);
		$filter = ($curfilter) ? $this->CurrentFilter : "";
		if (is_array($where))
			$where = $this->ArrayToFilter($where);
		ew_AddFilter($filter, $where);
		if ($filter <> "")	$sql .= " WHERE " . $filter;
		return $sql;
	}

	// Update
	function Update(&$rs, $where = "", $rsold = NULL, $curfilter = TRUE) {
		$conn = &$this->Connection();
		$bUpdate = $conn->Execute($this->UpdateSQL($rs, $where, $curfilter));
		return $bUpdate;
	}

	// DELETE statement
	function DeleteSQL(&$rs, $where = "", $curfilter = TRUE) {
		$sql = "DELETE FROM " . $this->UpdateTable . " WHERE ";
		if (is_array($where))
			$where = $this->ArrayToFilter($where);
		if ($rs) {
			if (array_key_exists('id', $rs))
				ew_AddFilter($where, ew_QuotedName('id', $this->DBID) . '=' . ew_QuotedValue($rs['id'], $this->id->FldDataType, $this->DBID));
		}
		$filter = ($curfilter) ? $this->CurrentFilter : "";
		ew_AddFilter($filter, $where);
		if ($filter <> "")
			$sql .= $filter;
		else
			$sql .= "0=1"; // Avoid delete
		return $sql;
	}

	// Delete
	function Delete(&$rs, $where = "", $curfilter = TRUE) {
		$bDelete = TRUE;
		$conn = &$this->Connection();
		if ($bDelete)
			$bDelete = $conn->Execute($this->DeleteSQL($rs, $where, $curfilter));
		return $bDelete;
	}

	// Key filter WHERE clause
	function SqlKeyFilter() {
		return "`id` = @id@";
	}

	// Key filter
	function KeyFilter() {
		$sKeyFilter = $this->SqlKeyFilter();
		if (!is_numeric($this->id->CurrentValue))
			return "0=1"; // Invalid key
		if (is_null($this->id->CurrentValue))
			return "0=1"; // Invalid key
		else
			$sKeyFilter = str_replace("@id@", ew_AdjustSql($this->id->CurrentValue, $this->DBID), $sKeyFilter); // Replace key value
		return $sKeyFilter;
	}

	// Return page URL
	function getReturnUrl() {
		$name = EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL;

		// Get referer URL automatically
		if (ew_ServerVar("HTTP_REFERER") <> "" && ew_ReferPage() <> ew_CurrentPage() && ew_ReferPage() <> "login.php") // Referer not same page or login page
			$_SESSION[$name] = ew_ServerVar("HTTP_REFERER"); // Save to Session
		if (@$_SESSION[$name] <> "") {
			return $_SESSION[$name];
		} else {
			return "bibitlist.php";
		}
	}

	function setReturnUrl($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL] = $v;
	}

	// Get modal caption
	function GetModalCaption($pageName) {
		global $Language;
		if ($pageName == "bibitview.php")
			return $Language->Phrase("View");
		elseif ($pageName == "bibitedit.php")
			return $Language->Phrase("Edit");
		elseif ($pageName == "bibitadd.php")
			return $Language->Phrase("Add");
		else
			return "";
	}

	// List URL
	function GetListUrl() {
		return "bibitlist.php";
	}

	// View URL
	function GetViewUrl($parm = "") {
		if ($parm <> "")
			$url = $this->KeyUrl("bibitview.php", $this->UrlParm($parm));
		else
			$url = $this->KeyUrl("bibitview.php", $this->UrlParm(EW_TABLE_SHOW_DETAIL . "="));
		return $this->AddMasterUrl($url);
	}

	// Add URL
	function GetAddUrl($parm = "") {
		if ($parm <> "")
			$url = "bibitadd.php?" . $this->UrlParm($parm);
		else
			$url = "bibitadd.php";
		return $this->AddMasterUrl($url);
	}

	// Edit URL
	function GetEditUrl($parm = "") {
		$url = $this->KeyUrl("bibitedit.php", $this->UrlParm($parm));
		return $this->AddMasterUrl($url);
	}

	// Inline edit URL
	function GetInlineEditUrl() {
		$url = $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=edit"));
		return $this->AddMasterUrl($url);
	}

	// Copy URL
	function GetCopyUrl($parm = "") {
		$url = $this->KeyUrl("bibitadd.php", $this->UrlParm($parm));
		return $this->AddMasterUrl($url);
	}

	// Inline copy URL
	function GetInlineCopyUrl() {
		$url = $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=copy"));
		return $this->AddMasterUrl($url);
	}

	// Delete URL
	function GetDeleteUrl() {
		return $this->KeyUrl("bibitdelete.php", $this->UrlParm());
	}

	// Add master url
	function AddMasterUrl($url) {
		return $url;
	}

	function KeyToJson() {
		$json = "";
		$json .= "id:" . ew_VarToJson($this->id->CurrentValue, "number", "'");
		return "{" . $json . "}";
	}

	// Add key value to URL
	function KeyUrl($url, $parm = "") {
		$sUrl = $url . "?";
		if ($parm <> "") $sUrl .= $parm . "&";
		if (!is_null($this->id->CurrentValue)) {
			$sUrl .= "id=" . urlencode($this->id->CurrentValue);
		} else {
			return "javascript:ew_Alert(ewLanguage.Phrase('InvalidRecord'));";
		}
		return $sUrl;
	}

	// Sort URL
	function SortUrl(&$fld) {
		if ($this->CurrentAction <> "" || $this->Export <> "" ||
			in_array($fld->FldType, array(128, 204, 205))) { // Unsortable data type
				return "";
		} elseif ($fld->Sortable) {
			$sUrlParm = $this->UrlParm("order=" . urlencode($fld->FldName) . "&amp;ordertype=" . $fld->ReverseSort());
			return $this->AddMasterUrl(ew_CurrentPage() . "?" . $sUrlParm);
		} else {
			return "";
		}
	}

	// Get record keys from $_POST/$_GET/$_SESSION
	function GetRecordKeys() {
		global $EW_COMPOSITE_KEY_SEPARATOR;
		$arKeys = array();
		$arKey = array();
		if (isset($_POST["key_m"])) {
			$arKeys = $_POST["key_m"];
			$cnt = count($arKeys);
		} elseif (isset($_GET["key_m"])) {
			$arKeys = $_GET["key_m"];
			$cnt = count($arKeys);
		} elseif (!empty($_GET) || !empty($_POST)) {
			$isPost = ew_IsPost();
			if ($isPost && isset($_POST["id"]))
				$arKeys[] = $_POST["id"];
			elseif (isset($_GET["id"]))
				$arKeys[] = $_GET["id"];
			else
				$arKeys = NULL; // Do not setup

			//return $arKeys; // Do not return yet, so the values will also be checked by the following code
		}

		// Check keys
		$ar = array();
		if (is_array($arKeys)) {
			foreach ($arKeys as $key) {
				if (!is_numeric($key))
					continue;
				$ar[] = $key;
			}
		}
		return $ar;
	}

	// Get key filter
	function GetKeyFilter() {
		$arKeys = $this->GetRecordKeys();
		$sKeyFilter = "";
		foreach ($arKeys as $key) {
			if ($sKeyFilter <> "") $sKeyFilter .= " OR ";
			$this->id->CurrentValue = $key;
			$sKeyFilter .= "(" . $this->KeyFilter() . ")";
		}
		return $sKeyFilter;
	}

	// Load rows based on filter
	function &LoadRs($filter) {

		// Set up filter (SQL WHERE clause) and get return SQL
		//$this->CurrentFilter = $filter;
		//$sql = $this->SQL();

		$sql = $this->GetSQL($filter, "");
		$conn = &$this->Connection();
		$rs = $conn->Execute($sql);
		return $rs;
	}

	// Load row values from recordset
	function LoadListRowValues(&$rs) {
		$this->id->setDbValue($rs->fields('id'));
		$this->tgl_tanam->setDbValue($rs->fields('tgl_tanam'));
		$this->jumlah_tanam->setDbValue($rs->fields('jumlah_tanam'));
		$this->jumlah_panen_stek->setDbValue($rs->fields('jumlah_panen_stek'));
		$this->ket->setDbValue($rs->fields('ket'));
		$this->var_nama->setDbValue($rs->fields('var_nama'));
		$this->id_gen->setDbValue($rs->fields('id_gen'));
		$this->k_id_kontrak->setDbValue($rs->fields('k_id_kontrak'));
		$this->co_nama->setDbValue($rs->fields('co_nama'));
		$this->koord_nama->setDbValue($rs->fields('koord_nama'));
		$this->pet_nama->setDbValue($rs->fields('pet_nama'));
		$this->prov_nama->setDbValue($rs->fields('prov_nama'));
		$this->kab_nama->setDbValue($rs->fields('kab_nama'));
		$this->kec_nama->setDbValue($rs->fields('kec_nama'));
		$this->desa_nama->setDbValue($rs->fields('desa_nama'));
		$this->id_asal_bibit->setDbValue($rs->fields('id_asal_bibit'));
	}

	// Render list row values
	function RenderListRow() {
		global $Security, $gsLanguage, $Language;

		// Call Row Rendering event
		$this->Row_Rendering();

	// Common render codes
		// id
		// tgl_tanam
		// jumlah_tanam
		// jumlah_panen_stek
		// ket
		// var_nama
		// id_gen
		// k_id_kontrak
		// co_nama
		// koord_nama
		// pet_nama
		// prov_nama
		// kab_nama
		// kec_nama
		// desa_nama
		// id_asal_bibit
		// id

		$this->id->ViewValue = $this->id->CurrentValue;
		$this->id->ViewCustomAttributes = "";

		// tgl_tanam
		$this->tgl_tanam->ViewValue = $this->tgl_tanam->CurrentValue;
		$this->tgl_tanam->ViewValue = ew_FormatDateTime($this->tgl_tanam->ViewValue, 0);
		$this->tgl_tanam->ViewCustomAttributes = "";

		// jumlah_tanam
		$this->jumlah_tanam->ViewValue = $this->jumlah_tanam->CurrentValue;
		$this->jumlah_tanam->ViewCustomAttributes = "";

		// jumlah_panen_stek
		$this->jumlah_panen_stek->ViewValue = $this->jumlah_panen_stek->CurrentValue;
		$this->jumlah_panen_stek->ViewCustomAttributes = "";

		// ket
		$this->ket->ViewValue = $this->ket->CurrentValue;
		$this->ket->ViewCustomAttributes = "";

		// var_nama
		if (strval($this->var_nama->CurrentValue) <> "") {
			$sFilterWrk = "`var_nama`" . ew_SearchString("=", $this->var_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `var_nama`, `var_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `varietas`";
		$sWhereWrk = "";
		$this->var_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->var_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->var_nama->ViewValue = $this->var_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->var_nama->ViewValue = $this->var_nama->CurrentValue;
			}
		} else {
			$this->var_nama->ViewValue = NULL;
		}
		$this->var_nama->ViewCustomAttributes = "";

		// id_gen
		if (strval($this->id_gen->CurrentValue) <> "") {
			$sFilterWrk = "`id_gen`" . ew_SearchString("=", $this->id_gen->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `id_gen`, `id_gen` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `generasi_bibit`";
		$sWhereWrk = "";
		$this->id_gen->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->id_gen, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->id_gen->ViewValue = $this->id_gen->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->id_gen->ViewValue = $this->id_gen->CurrentValue;
			}
		} else {
			$this->id_gen->ViewValue = NULL;
		}
		$this->id_gen->ViewCustomAttributes = "";

		// k_id_kontrak
		if (strval($this->k_id_kontrak->CurrentValue) <> "") {
			$sFilterWrk = "`k_id_kontrak`" . ew_SearchString("=", $this->k_id_kontrak->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `k_id_kontrak`, `k_id_kontrak` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `kontrak`";
		$sWhereWrk = "";
		$this->k_id_kontrak->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->k_id_kontrak, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->k_id_kontrak->ViewValue = $this->k_id_kontrak->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->k_id_kontrak->ViewValue = $this->k_id_kontrak->CurrentValue;
			}
		} else {
			$this->k_id_kontrak->ViewValue = NULL;
		}
		$this->k_id_kontrak->ViewCustomAttributes = "";

		// co_nama
		if (strval($this->co_nama->CurrentValue) <> "") {
			$sFilterWrk = "`co_nama`" . ew_SearchString("=", $this->co_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `co_nama`, `co_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `co`";
		$sWhereWrk = "";
		$this->co_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->co_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->co_nama->ViewValue = $this->co_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->co_nama->ViewValue = $this->co_nama->CurrentValue;
			}
		} else {
			$this->co_nama->ViewValue = NULL;
		}
		$this->co_nama->ViewCustomAttributes = "";

		// koord_nama
		$this->koord_nama->ViewValue = $this->koord_nama->CurrentValue;
		if (strval($this->koord_nama->CurrentValue) <> "") {
			$sFilterWrk = "`koord_nama`" . ew_SearchString("=", $this->koord_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `koord_nama`, `koord_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `koord`";
		$sWhereWrk = "";
		$this->koord_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->koord_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->koord_nama->ViewValue = $this->koord_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->koord_nama->ViewValue = $this->koord_nama->CurrentValue;
			}
		} else {
			$this->koord_nama->ViewValue = NULL;
		}
		$this->koord_nama->ViewCustomAttributes = "";

		// pet_nama
		$this->pet_nama->ViewValue = $this->pet_nama->CurrentValue;
		if (strval($this->pet_nama->CurrentValue) <> "") {
			$sFilterWrk = "`pet_nama`" . ew_SearchString("=", $this->pet_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `pet_nama`, `pet_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `petani`";
		$sWhereWrk = "";
		$this->pet_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->pet_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->pet_nama->ViewValue = $this->pet_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->pet_nama->ViewValue = $this->pet_nama->CurrentValue;
			}
		} else {
			$this->pet_nama->ViewValue = NULL;
		}
		$this->pet_nama->ViewCustomAttributes = "";

		// prov_nama
		$this->prov_nama->ViewValue = $this->prov_nama->CurrentValue;
		if (strval($this->prov_nama->CurrentValue) <> "") {
			$sFilterWrk = "`prov_nama`" . ew_SearchString("=", $this->prov_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `prov_nama`, `prov_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `prov`";
		$sWhereWrk = "";
		$this->prov_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->prov_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->prov_nama->ViewValue = $this->prov_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->prov_nama->ViewValue = $this->prov_nama->CurrentValue;
			}
		} else {
			$this->prov_nama->ViewValue = NULL;
		}
		$this->prov_nama->ViewCustomAttributes = "";

		// kab_nama
		$this->kab_nama->ViewValue = $this->kab_nama->CurrentValue;
		if (strval($this->kab_nama->CurrentValue) <> "") {
			$sFilterWrk = "`kab_nama`" . ew_SearchString("=", $this->kab_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `kab_nama`, `kab_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `kab`";
		$sWhereWrk = "";
		$this->kab_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->kab_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->kab_nama->ViewValue = $this->kab_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->kab_nama->ViewValue = $this->kab_nama->CurrentValue;
			}
		} else {
			$this->kab_nama->ViewValue = NULL;
		}
		$this->kab_nama->ViewCustomAttributes = "";

		// kec_nama
		$this->kec_nama->ViewValue = $this->kec_nama->CurrentValue;
		if (strval($this->kec_nama->CurrentValue) <> "") {
			$sFilterWrk = "`kec_nama`" . ew_SearchString("=", $this->kec_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `kec_nama`, `kec_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `kec`";
		$sWhereWrk = "";
		$this->kec_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->kec_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->kec_nama->ViewValue = $this->kec_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->kec_nama->ViewValue = $this->kec_nama->CurrentValue;
			}
		} else {
			$this->kec_nama->ViewValue = NULL;
		}
		$this->kec_nama->ViewCustomAttributes = "";

		// desa_nama
		$this->desa_nama->ViewValue = $this->desa_nama->CurrentValue;
		if (strval($this->desa_nama->CurrentValue) <> "") {
			$sFilterWrk = "`desa_nama`" . ew_SearchString("=", $this->desa_nama->CurrentValue, EW_DATATYPE_STRING, "");
		$sSqlWrk = "SELECT `desa_nama`, `desa_nama` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `desa`";
		$sWhereWrk = "";
		$this->desa_nama->LookupFilters = array();
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->desa_nama, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = $rswrk->fields('DispFld');
				$this->desa_nama->ViewValue = $this->desa_nama->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->desa_nama->ViewValue = $this->desa_nama->CurrentValue;
			}
		} else {
			$this->desa_nama->ViewValue = NULL;
		}
		$this->desa_nama->ViewCustomAttributes = "";

		// id_asal_bibit
		$this->id_asal_bibit->ViewValue = $this->id_asal_bibit->CurrentValue;
		if (strval($this->id_asal_bibit->CurrentValue) <> "") {
			$sFilterWrk = "`id`" . ew_SearchString("=", $this->id_asal_bibit->CurrentValue, EW_DATATYPE_NUMBER, "");
		$sSqlWrk = "SELECT `id`, `tgl_tanam` AS `DispFld`, `gen_bibit` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `tanam_bibit`";
		$sWhereWrk = "";
		$this->id_asal_bibit->LookupFilters = array("df1" => "0");
		ew_AddFilter($sWhereWrk, $sFilterWrk);
		$this->Lookup_Selecting($this->id_asal_bibit, $sWhereWrk); // Call Lookup Selecting
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = Conn()->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$arwrk = array();
				$arwrk[1] = ew_FormatDateTime($rswrk->fields('DispFld'), 0);
				$arwrk[2] = $rswrk->fields('Disp2Fld');
				$this->id_asal_bibit->ViewValue = $this->id_asal_bibit->DisplayValue($arwrk);
				$rswrk->Close();
			} else {
				$this->id_asal_bibit->ViewValue = $this->id_asal_bibit->CurrentValue;
			}
		} else {
			$this->id_asal_bibit->ViewValue = NULL;
		}
		$this->id_asal_bibit->ViewCustomAttributes = "";

		// id
		$this->id->LinkCustomAttributes = "";
		$this->id->HrefValue = "";
		$this->id->TooltipValue = "";

		// tgl_tanam
		$this->tgl_tanam->LinkCustomAttributes = "";
		$this->tgl_tanam->HrefValue = "";
		$this->tgl_tanam->TooltipValue = "";

		// jumlah_tanam
		$this->jumlah_tanam->LinkCustomAttributes = "";
		$this->jumlah_tanam->HrefValue = "";
		$this->jumlah_tanam->TooltipValue = "";

		// jumlah_panen_stek
		$this->jumlah_panen_stek->LinkCustomAttributes = "";
		$this->jumlah_panen_stek->HrefValue = "";
		$this->jumlah_panen_stek->TooltipValue = "";

		// ket
		$this->ket->LinkCustomAttributes = "";
		$this->ket->HrefValue = "";
		$this->ket->TooltipValue = "";

		// var_nama
		$this->var_nama->LinkCustomAttributes = "";
		$this->var_nama->HrefValue = "";
		$this->var_nama->TooltipValue = "";

		// id_gen
		$this->id_gen->LinkCustomAttributes = "";
		$this->id_gen->HrefValue = "";
		$this->id_gen->TooltipValue = "";

		// k_id_kontrak
		$this->k_id_kontrak->LinkCustomAttributes = "";
		$this->k_id_kontrak->HrefValue = "";
		$this->k_id_kontrak->TooltipValue = "";

		// co_nama
		$this->co_nama->LinkCustomAttributes = "";
		$this->co_nama->HrefValue = "";
		$this->co_nama->TooltipValue = "";

		// koord_nama
		$this->koord_nama->LinkCustomAttributes = "";
		$this->koord_nama->HrefValue = "";
		$this->koord_nama->TooltipValue = "";

		// pet_nama
		$this->pet_nama->LinkCustomAttributes = "";
		$this->pet_nama->HrefValue = "";
		$this->pet_nama->TooltipValue = "";

		// prov_nama
		$this->prov_nama->LinkCustomAttributes = "";
		$this->prov_nama->HrefValue = "";
		$this->prov_nama->TooltipValue = "";

		// kab_nama
		$this->kab_nama->LinkCustomAttributes = "";
		$this->kab_nama->HrefValue = "";
		$this->kab_nama->TooltipValue = "";

		// kec_nama
		$this->kec_nama->LinkCustomAttributes = "";
		$this->kec_nama->HrefValue = "";
		$this->kec_nama->TooltipValue = "";

		// desa_nama
		$this->desa_nama->LinkCustomAttributes = "";
		$this->desa_nama->HrefValue = "";
		$this->desa_nama->TooltipValue = "";

		// id_asal_bibit
		$this->id_asal_bibit->LinkCustomAttributes = "";
		$this->id_asal_bibit->HrefValue = "";
		$this->id_asal_bibit->TooltipValue = "";

		// Call Row Rendered event
		$this->Row_Rendered();

		// Save data for Custom Template
		$this->Rows[] = $this->CustomTemplateFieldValues();
	}

	// Render edit row values
	function RenderEditRow() {
		global $Security, $gsLanguage, $Language;

		// Call Row Rendering event
		$this->Row_Rendering();

		// id
		$this->id->EditAttrs["class"] = "form-control";
		$this->id->EditCustomAttributes = "";
		$this->id->EditValue = $this->id->CurrentValue;
		$this->id->ViewCustomAttributes = "";

		// tgl_tanam
		$this->tgl_tanam->EditAttrs["class"] = "form-control";
		$this->tgl_tanam->EditCustomAttributes = "";
		$this->tgl_tanam->EditValue = ew_FormatDateTime($this->tgl_tanam->CurrentValue, 8);
		$this->tgl_tanam->PlaceHolder = ew_RemoveHtml($this->tgl_tanam->FldCaption());

		// jumlah_tanam
		$this->jumlah_tanam->EditAttrs["class"] = "form-control";
		$this->jumlah_tanam->EditCustomAttributes = "";
		$this->jumlah_tanam->EditValue = $this->jumlah_tanam->CurrentValue;
		$this->jumlah_tanam->PlaceHolder = ew_RemoveHtml($this->jumlah_tanam->FldCaption());

		// jumlah_panen_stek
		$this->jumlah_panen_stek->EditAttrs["class"] = "form-control";
		$this->jumlah_panen_stek->EditCustomAttributes = "";
		$this->jumlah_panen_stek->EditValue = $this->jumlah_panen_stek->CurrentValue;
		$this->jumlah_panen_stek->PlaceHolder = ew_RemoveHtml($this->jumlah_panen_stek->FldCaption());

		// ket
		$this->ket->EditAttrs["class"] = "form-control";
		$this->ket->EditCustomAttributes = "";
		$this->ket->EditValue = $this->ket->CurrentValue;
		$this->ket->PlaceHolder = ew_RemoveHtml($this->ket->FldCaption());

		// var_nama
		$this->var_nama->EditAttrs["class"] = "form-control";
		$this->var_nama->EditCustomAttributes = "";

		// id_gen
		$this->id_gen->EditAttrs["class"] = "form-control";
		$this->id_gen->EditCustomAttributes = "";

		// k_id_kontrak
		$this->k_id_kontrak->EditAttrs["class"] = "form-control";
		$this->k_id_kontrak->EditCustomAttributes = "";

		// co_nama
		$this->co_nama->EditAttrs["class"] = "form-control";
		$this->co_nama->EditCustomAttributes = "";

		// koord_nama
		$this->koord_nama->EditAttrs["class"] = "form-control";
		$this->koord_nama->EditCustomAttributes = "";
		$this->koord_nama->EditValue = $this->koord_nama->CurrentValue;
		$this->koord_nama->PlaceHolder = ew_RemoveHtml($this->koord_nama->FldCaption());

		// pet_nama
		$this->pet_nama->EditAttrs["class"] = "form-control";
		$this->pet_nama->EditCustomAttributes = "";
		$this->pet_nama->EditValue = $this->pet_nama->CurrentValue;
		$this->pet_nama->PlaceHolder = ew_RemoveHtml($this->pet_nama->FldCaption());

		// prov_nama
		$this->prov_nama->EditAttrs["class"] = "form-control";
		$this->prov_nama->EditCustomAttributes = "";
		$this->prov_nama->EditValue = $this->prov_nama->CurrentValue;
		$this->prov_nama->PlaceHolder = ew_RemoveHtml($this->prov_nama->FldCaption());

		// kab_nama
		$this->kab_nama->EditAttrs["class"] = "form-control";
		$this->kab_nama->EditCustomAttributes = "";
		$this->kab_nama->EditValue = $this->kab_nama->CurrentValue;
		$this->kab_nama->PlaceHolder = ew_RemoveHtml($this->kab_nama->FldCaption());

		// kec_nama
		$this->kec_nama->EditAttrs["class"] = "form-control";
		$this->kec_nama->EditCustomAttributes = "";
		$this->kec_nama->EditValue = $this->kec_nama->CurrentValue;
		$this->kec_nama->PlaceHolder = ew_RemoveHtml($this->kec_nama->FldCaption());

		// desa_nama
		$this->desa_nama->EditAttrs["class"] = "form-control";
		$this->desa_nama->EditCustomAttributes = "";
		$this->desa_nama->EditValue = $this->desa_nama->CurrentValue;
		$this->desa_nama->PlaceHolder = ew_RemoveHtml($this->desa_nama->FldCaption());

		// id_asal_bibit
		$this->id_asal_bibit->EditAttrs["class"] = "form-control";
		$this->id_asal_bibit->EditCustomAttributes = "";
		$this->id_asal_bibit->EditValue = $this->id_asal_bibit->CurrentValue;
		$this->id_asal_bibit->PlaceHolder = ew_RemoveHtml($this->id_asal_bibit->FldCaption());

		// Call Row Rendered event
		$this->Row_Rendered();
	}

	// Aggregate list row values
	function AggregateListRowValues() {
	}

	// Aggregate list row (for rendering)
	function AggregateListRow() {

		// Call Row Rendered event
		$this->Row_Rendered();
	}
	var $ExportDoc;

	// Export data in HTML/CSV/Word/Excel/Email/PDF format
	function ExportDocument(&$Doc, &$Recordset, $StartRec, $StopRec, $ExportPageType = "") {
		if (!$Recordset || !$Doc)
			return;
		if (!$Doc->ExportCustom) {

			// Write header
			$Doc->ExportTableHeader();
			if ($Doc->Horizontal) { // Horizontal format, write header
				$Doc->BeginExportRow();
				if ($ExportPageType == "view") {
					if ($this->id->Exportable) $Doc->ExportCaption($this->id);
					if ($this->tgl_tanam->Exportable) $Doc->ExportCaption($this->tgl_tanam);
					if ($this->jumlah_tanam->Exportable) $Doc->ExportCaption($this->jumlah_tanam);
					if ($this->jumlah_panen_stek->Exportable) $Doc->ExportCaption($this->jumlah_panen_stek);
					if ($this->ket->Exportable) $Doc->ExportCaption($this->ket);
					if ($this->var_nama->Exportable) $Doc->ExportCaption($this->var_nama);
					if ($this->id_gen->Exportable) $Doc->ExportCaption($this->id_gen);
					if ($this->k_id_kontrak->Exportable) $Doc->ExportCaption($this->k_id_kontrak);
					if ($this->co_nama->Exportable) $Doc->ExportCaption($this->co_nama);
					if ($this->koord_nama->Exportable) $Doc->ExportCaption($this->koord_nama);
					if ($this->pet_nama->Exportable) $Doc->ExportCaption($this->pet_nama);
					if ($this->prov_nama->Exportable) $Doc->ExportCaption($this->prov_nama);
					if ($this->kab_nama->Exportable) $Doc->ExportCaption($this->kab_nama);
					if ($this->kec_nama->Exportable) $Doc->ExportCaption($this->kec_nama);
					if ($this->desa_nama->Exportable) $Doc->ExportCaption($this->desa_nama);
					if ($this->id_asal_bibit->Exportable) $Doc->ExportCaption($this->id_asal_bibit);
				} else {
					if ($this->id->Exportable) $Doc->ExportCaption($this->id);
					if ($this->tgl_tanam->Exportable) $Doc->ExportCaption($this->tgl_tanam);
					if ($this->jumlah_tanam->Exportable) $Doc->ExportCaption($this->jumlah_tanam);
					if ($this->jumlah_panen_stek->Exportable) $Doc->ExportCaption($this->jumlah_panen_stek);
					if ($this->ket->Exportable) $Doc->ExportCaption($this->ket);
					if ($this->var_nama->Exportable) $Doc->ExportCaption($this->var_nama);
					if ($this->id_gen->Exportable) $Doc->ExportCaption($this->id_gen);
					if ($this->k_id_kontrak->Exportable) $Doc->ExportCaption($this->k_id_kontrak);
					if ($this->co_nama->Exportable) $Doc->ExportCaption($this->co_nama);
					if ($this->koord_nama->Exportable) $Doc->ExportCaption($this->koord_nama);
					if ($this->pet_nama->Exportable) $Doc->ExportCaption($this->pet_nama);
					if ($this->prov_nama->Exportable) $Doc->ExportCaption($this->prov_nama);
					if ($this->kab_nama->Exportable) $Doc->ExportCaption($this->kab_nama);
					if ($this->kec_nama->Exportable) $Doc->ExportCaption($this->kec_nama);
					if ($this->desa_nama->Exportable) $Doc->ExportCaption($this->desa_nama);
					if ($this->id_asal_bibit->Exportable) $Doc->ExportCaption($this->id_asal_bibit);
				}
				$Doc->EndExportRow();
			}
		}

		// Move to first record
		$RecCnt = $StartRec - 1;
		if (!$Recordset->EOF) {
			$Recordset->MoveFirst();
			if ($StartRec > 1)
				$Recordset->Move($StartRec - 1);
		}
		while (!$Recordset->EOF && $RecCnt < $StopRec) {
			$RecCnt++;
			if (intval($RecCnt) >= intval($StartRec)) {
				$RowCnt = intval($RecCnt) - intval($StartRec) + 1;

				// Page break
				if ($this->ExportPageBreakCount > 0) {
					if ($RowCnt > 1 && ($RowCnt - 1) % $this->ExportPageBreakCount == 0)
						$Doc->ExportPageBreak();
				}
				$this->LoadListRowValues($Recordset);

				// Render row
				$this->RowType = EW_ROWTYPE_VIEW; // Render view
				$this->ResetAttrs();
				$this->RenderListRow();
				if (!$Doc->ExportCustom) {
					$Doc->BeginExportRow($RowCnt); // Allow CSS styles if enabled
					if ($ExportPageType == "view") {
						if ($this->id->Exportable) $Doc->ExportField($this->id);
						if ($this->tgl_tanam->Exportable) $Doc->ExportField($this->tgl_tanam);
						if ($this->jumlah_tanam->Exportable) $Doc->ExportField($this->jumlah_tanam);
						if ($this->jumlah_panen_stek->Exportable) $Doc->ExportField($this->jumlah_panen_stek);
						if ($this->ket->Exportable) $Doc->ExportField($this->ket);
						if ($this->var_nama->Exportable) $Doc->ExportField($this->var_nama);
						if ($this->id_gen->Exportable) $Doc->ExportField($this->id_gen);
						if ($this->k_id_kontrak->Exportable) $Doc->ExportField($this->k_id_kontrak);
						if ($this->co_nama->Exportable) $Doc->ExportField($this->co_nama);
						if ($this->koord_nama->Exportable) $Doc->ExportField($this->koord_nama);
						if ($this->pet_nama->Exportable) $Doc->ExportField($this->pet_nama);
						if ($this->prov_nama->Exportable) $Doc->ExportField($this->prov_nama);
						if ($this->kab_nama->Exportable) $Doc->ExportField($this->kab_nama);
						if ($this->kec_nama->Exportable) $Doc->ExportField($this->kec_nama);
						if ($this->desa_nama->Exportable) $Doc->ExportField($this->desa_nama);
						if ($this->id_asal_bibit->Exportable) $Doc->ExportField($this->id_asal_bibit);
					} else {
						if ($this->id->Exportable) $Doc->ExportField($this->id);
						if ($this->tgl_tanam->Exportable) $Doc->ExportField($this->tgl_tanam);
						if ($this->jumlah_tanam->Exportable) $Doc->ExportField($this->jumlah_tanam);
						if ($this->jumlah_panen_stek->Exportable) $Doc->ExportField($this->jumlah_panen_stek);
						if ($this->ket->Exportable) $Doc->ExportField($this->ket);
						if ($this->var_nama->Exportable) $Doc->ExportField($this->var_nama);
						if ($this->id_gen->Exportable) $Doc->ExportField($this->id_gen);
						if ($this->k_id_kontrak->Exportable) $Doc->ExportField($this->k_id_kontrak);
						if ($this->co_nama->Exportable) $Doc->ExportField($this->co_nama);
						if ($this->koord_nama->Exportable) $Doc->ExportField($this->koord_nama);
						if ($this->pet_nama->Exportable) $Doc->ExportField($this->pet_nama);
						if ($this->prov_nama->Exportable) $Doc->ExportField($this->prov_nama);
						if ($this->kab_nama->Exportable) $Doc->ExportField($this->kab_nama);
						if ($this->kec_nama->Exportable) $Doc->ExportField($this->kec_nama);
						if ($this->desa_nama->Exportable) $Doc->ExportField($this->desa_nama);
						if ($this->id_asal_bibit->Exportable) $Doc->ExportField($this->id_asal_bibit);
					}
					$Doc->EndExportRow($RowCnt);
				}
			}

			// Call Row Export server event
			if ($Doc->ExportCustom)
				$this->Row_Export($Recordset->fields);
			$Recordset->MoveNext();
		}
		if (!$Doc->ExportCustom) {
			$Doc->ExportTableFooter();
		}
	}

	// Get auto fill value
	function GetAutoFill($id, $val) {
		$rsarr = array();
		$rowcnt = 0;

		// Output
		if (is_array($rsarr) && $rowcnt > 0) {
			$fldcnt = count($rsarr[0]);
			for ($i = 0; $i < $rowcnt; $i++) {
				for ($j = 0; $j < $fldcnt; $j++) {
					$str = strval($rsarr[$i][$j]);
					$str = ew_ConvertToUtf8($str);
					if (isset($post["keepCRLF"])) {
						$str = str_replace(array("\r", "\n"), array("\\r", "\\n"), $str);
					} else {
						$str = str_replace(array("\r", "\n"), array(" ", " "), $str);
					}
					$rsarr[$i][$j] = $str;
				}
			}
			return ew_ArrayToJson($rsarr);
		} else {
			return FALSE;
		}
	}

	// Table level events
	// Recordset Selecting event
	function Recordset_Selecting(&$filter) {

		// Enter your code here
	}

	// Recordset Selected event
	function Recordset_Selected(&$rs) {

		//echo "Recordset Selected";
	}

	// Recordset Search Validated event
	function Recordset_SearchValidated() {

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

	}

	// Recordset Searching event
	function Recordset_Searching(&$filter) {

		// Enter your code here
	}

	// Row_Selecting event
	function Row_Selecting(&$filter) {

		// Enter your code here
	}

	// Row Selected event
	function Row_Selected(&$rs) {

		//echo "Row Selected";
	}

	// Row Inserting event
	function Row_Inserting($rsold, &$rsnew) {

		// Enter your code here
		// To cancel, set return value to FALSE

		return TRUE;
	}

	// Row Inserted event
	function Row_Inserted($rsold, &$rsnew) {

		//echo "Row Inserted"
	}

	// Row Updating event
	function Row_Updating($rsold, &$rsnew) {

		// Enter your code here
		// To cancel, set return value to FALSE

		return TRUE;
	}

	// Row Updated event
	function Row_Updated($rsold, &$rsnew) {

		//echo "Row Updated";
	}

	// Row Update Conflict event
	function Row_UpdateConflict($rsold, &$rsnew) {

		// Enter your code here
		// To ignore conflict, set return value to FALSE

		return TRUE;
	}

	// Grid Inserting event
	function Grid_Inserting() {

		// Enter your code here
		// To reject grid insert, set return value to FALSE

		return TRUE;
	}

	// Grid Inserted event
	function Grid_Inserted($rsnew) {

		//echo "Grid Inserted";
	}

	// Grid Updating event
	function Grid_Updating($rsold) {

		// Enter your code here
		// To reject grid update, set return value to FALSE

		return TRUE;
	}

	// Grid Updated event
	function Grid_Updated($rsold, $rsnew) {

		//echo "Grid Updated";
	}

	// Row Deleting event
	function Row_Deleting(&$rs) {

		// Enter your code here
		// To cancel, set return value to False

		return TRUE;
	}

	// Row Deleted event
	function Row_Deleted(&$rs) {

		//echo "Row Deleted";
	}

	// 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) {

		//var_dump($fld->FldName, $fld->LookupFilters, $filter); // Uncomment to view the filter
		// Enter your code here

	}

	// Row Rendering event
	function Row_Rendering() {

		// Enter your code here
	}

	// 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
	}
}
?>
