<?php

// PHPMaker 6 configuration for Table categoria
$categoria = new ccategoria; // Initialize table object

// Define table class
class ccategoria {

	// Define table level constants
	var $TableVar;
	var $TableName;
	var $SelectLimit = FALSE;
	var $cod_categoria;
	var $des_categoria;
	var $des_imagen;
	var $ind_activo;
	var $margen;
	var $displayConf;
	var $displayCat;
	var $ind_cat;
	var $orden;
	var $cod_usuario_registro;
	var $fec_registro;
	var $cod_usuario_modificacion;
	var $fec_ultima_modificacion;
	var $fields = array();
	var $UseTokenInUrl = EW_USE_TOKEN_IN_URL;
	var $Export; // Export
	var $ExportOriginalValue = EW_EXPORT_ORIGINAL_VALUE;
	var	$ExportAll = EW_EXPORT_ALL;
	var $SendEmail; // Send Email
	var $TableCustomInnerHtml; // Custom Inner Html

	function ccategoria() {
		$this->TableVar = "categoria";
		$this->TableName = "categoria";
		$this->SelectLimit = TRUE;
		$this->cod_categoria = new cField('categoria', 'x_cod_categoria', 'cod_categoria', "`cod_categoria`", 200, -1, FALSE);
		$this->fields['cod_categoria'] =& $this->cod_categoria;
		$this->des_categoria = new cField('categoria', 'x_des_categoria', 'des_categoria', "`des_categoria`", 200, -1, FALSE);
		$this->fields['des_categoria'] =& $this->des_categoria;
		$this->des_imagen = new cField('categoria', 'x_des_imagen', 'des_imagen', "`des_imagen`", 200, -1, TRUE);
		$this->fields['des_imagen'] =& $this->des_imagen;
		$this->ind_activo = new cField('categoria', 'x_ind_activo', 'ind_activo', "`ind_activo`", 200, -1, FALSE);
		$this->fields['ind_activo'] =& $this->ind_activo;
		$this->margen = new cField('categoria', 'x_margen', 'margen', "`margen`", 131, -1, FALSE);
		$this->fields['margen'] =& $this->margen;
		$this->displayConf = new cField('categoria', 'x_displayConf', 'displayConf', "`displayConf`", 16, -1, FALSE);
		$this->fields['displayConf'] =& $this->displayConf;
		$this->displayCat = new cField('categoria', 'x_displayCat', 'displayCat', "`displayCat`", 16, -1, FALSE);
		$this->fields['displayCat'] =& $this->displayCat;
		$this->ind_cat = new cField('categoria', 'x_ind_cat', 'ind_cat', "`ind_cat`", 16, -1, FALSE);
		$this->fields['ind_cat'] =& $this->ind_cat;
		$this->orden = new cField('categoria', 'x_orden', 'orden', "`orden`", 3, -1, FALSE);
		$this->fields['orden'] =& $this->orden;
		$this->cod_usuario_registro = new cField('categoria', 'x_cod_usuario_registro', 'cod_usuario_registro', "`cod_usuario_registro`", 3, -1, FALSE);
		$this->fields['cod_usuario_registro'] =& $this->cod_usuario_registro;
		$this->fec_registro = new cField('categoria', 'x_fec_registro', 'fec_registro', "`fec_registro`", 135, 5, FALSE);
		$this->fields['fec_registro'] =& $this->fec_registro;
		$this->cod_usuario_modificacion = new cField('categoria', 'x_cod_usuario_modificacion', 'cod_usuario_modificacion', "`cod_usuario_modificacion`", 3, -1, FALSE);
		$this->fields['cod_usuario_modificacion'] =& $this->cod_usuario_modificacion;
		$this->fec_ultima_modificacion = new cField('categoria', 'x_fec_ultima_modificacion', 'fec_ultima_modificacion', "`fec_ultima_modificacion`", 135, 5, FALSE);
		$this->fields['fec_ultima_modificacion'] =& $this->fec_ultima_modificacion;
	}

	// Records per page
	function getRecordsPerPage() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_REC_PER_PAGE];
	}

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

	// Start record number
	function getStartRecordNumber() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_START_REC];
	}

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

	// Search Highlight Name
	function HighlightName() {
		return "categoria_Highlight";
	}

	// Advanced search
	function getAdvancedSearch($fld) {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld];
	}

	function setAdvancedSearch($fld, $v) {
		if (@$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld] <> $v) {
			$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld] = $v;
		}
	}

	// Basic search Keyword
	function getBasicSearchKeyword() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH];
	}

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

	// Basic Search Type
	function getBasicSearchType() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH_TYPE];
	}

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

	// Search where clause
	function getSearchWhere() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_SEARCH_WHERE];
	}

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

	// 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("");
		}
	}

	// Session WHERE Clause
	function getSessionWhere() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_WHERE];
	}

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

	// Session ORDER BY
	function getSessionOrderBy() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ORDER_BY];
	}

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

	// Session Key
	function getKey($fld) {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_KEY . "_" . $fld];
	}

	function setKey($fld, $v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_KEY . "_" . $fld] = $v;
	}

	// Table level SQL
	function SqlSelect() { // Select
		return "SELECT * FROM `categoria`";
	}

	function SqlWhere() { // Where
		return "";
	}

	function SqlGroupBy() { // Group By
		return "";
	}

	function SqlHaving() { // Having
		return "";
	}

	function SqlOrderBy() { // Order By
		return "`orden` ASC";
	}

	// SQL variables
	var $CurrentFilter; // Current filter
	var $CurrentOrder; // Current order
	var $CurrentOrderType; // Current order type

	// Get SQL
	function GetSQL($where, $orderby) {
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$where, $orderby);
	}

	// Table SQL
	function SQL() {
		$sFilter = $this->CurrentFilter;
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$sFilter, $sSort);
	}

	// Return table sql with list page filter
	function SelectSQL() {
		$sFilter = $this->getSessionWhere();
		if ($this->CurrentFilter <> "") {
			if ($sFilter <> "") $sFilter .= " AND ";
			$sFilter .= $this->CurrentFilter;
		}
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$sFilter, $sSort);
	}

	// Return record count
	function SelectRecordCount() {
		global $conn;
		$cnt = -1;
		$sFilter = $this->CurrentFilter;
		$this->Recordset_Selecting($this->CurrentFilter);
		if ($this->SelectLimit) {
			$sSelect = $this->SelectSQL();
			if (strtoupper(substr($sSelect, 0, 13)) == "SELECT * FROM") {
				$sSelect = "SELECT COUNT(*) FROM" . substr($sSelect, 13);
				if ($rs = $conn->Execute($sSelect)) {
					if (!$rs->EOF)
						$cnt = $rs->fields[0];
					$rs->Close();
				}
			}
		}
		if ($cnt == -1) {
			if ($rs = $conn->Execute($this->SelectSQL())) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $sFilter;
		return intval($cnt);
	}

	// INSERT statement
	function InsertSQL(&$rs) {
		$names = "";
		$values = "";
		foreach ($rs as $name => $value) {
			$names .= $this->fields[$name]->FldExpression . ",";
			$values .= (is_null($value) ? "NULL" : ew_QuotedValue($value, $this->fields[$name]->FldDataType)) . ",";
		}
		if (substr($names, -1) == ",") $names = substr($names, 0, strlen($names)-1);
		if (substr($values, -1) == ",") $values = substr($values, 0, strlen($values)-1);
		return "INSERT INTO `categoria` ($names) VALUES ($values)";
	}

	// UPDATE statement
	function UpdateSQL(&$rs) {
		$SQL = "UPDATE `categoria` SET ";
		foreach ($rs as $name => $value) {
			$SQL .= $this->fields[$name]->FldExpression . "=" .
					(is_null($value) ? "NULL" : ew_QuotedValue($value, $this->fields[$name]->FldDataType)) . ",";
		}
		if (substr($SQL, -1) == ",") $SQL = substr($SQL, 0, strlen($SQL)-1);
		if ($this->CurrentFilter <> "")	$SQL .= " WHERE " . $this->CurrentFilter;
		return $SQL;
	}

	// DELETE statement
	function DeleteSQL(&$rs) {
		$SQL = "DELETE FROM `categoria` WHERE ";
		$SQL .= EW_DB_QUOTE_START . 'cod_categoria' . EW_DB_QUOTE_END . '=' .	ew_QuotedValue($rs['cod_categoria'], $this->cod_categoria->FldDataType) . ' AND ';
		if (substr($SQL, -5) == " AND ") $SQL = substr($SQL, 0, strlen($SQL)-5);
		if ($this->CurrentFilter <> "")	$SQL .= " AND " . $this->CurrentFilter;
		return $SQL;
	}

	// Key filter for table
	function SqlKeyFilter() {
		return "`cod_categoria` = '@cod_categoria@'";
	}

	// Return Key filter for table
	function KeyFilter() {
		$sKeyFilter = $this->SqlKeyFilter();
		$sKeyFilter = str_replace("@cod_categoria@", ew_AdjustSql($this->cod_categoria->CurrentValue), $sKeyFilter); // Replace key value
		return $sKeyFilter;
	}

	// Return url
	function getReturnUrl() {

		// 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[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL] = ew_ServerVar("HTTP_REFERER"); // Save to Session
		if (@$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL] <> "") {
			return $_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL];
		} else {
			return "categorialist.php";
		}
	}

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

	// View url
	function ViewUrl() {
		return $this->KeyUrl("categoriaview.php", $this->UrlParm());
	}

	// Add url
	function AddUrl() {
		$AddUrl = "categoriaadd.php";
		$sUrlParm = $this->UrlParm();
		if ($sUrlParm <> "")
			$AddUrl .= "?" . $sUrlParm;
		return $AddUrl;
	}

	// Edit url
	function EditUrl() {
		return $this->KeyUrl("categoriaedit.php", $this->UrlParm());
	}

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

	// Copy url
	function CopyUrl() {
		return $this->KeyUrl("categoriaadd.php", $this->UrlParm());
	}

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

	// Delete url
	function DeleteUrl() {
		return $this->KeyUrl("categoriadelete.php", $this->UrlParm());
	}

	// Key url
	function KeyUrl($url, $parm = "") {
		$sUrl = $url . "?";
		if ($parm <> "") $sUrl .= $parm . "&";
		if (!is_null($this->cod_categoria->CurrentValue)) {
			$sUrl .= "cod_categoria=" . urlencode($this->cod_categoria->CurrentValue);
		} else {
			return "javascript:alert('Invalid Record! Key is null');";
		}
		return $sUrl;
	}

	// Sort Url
	function SortUrl(&$fld) {
		if ($this->CurrentAction <> "" || $this->Export <> "" ||
			($fld->FldType == 205)) { // Unsortable data type
			return "";
		} else {
			$sUrlParm = $this->UrlParm("order=" . urlencode($fld->FldName) . "&ordertype=" . $fld->ReverseSort());
			return ew_CurrentPage() . "?" . $sUrlParm;
		}
	}

	// URL parm
	function UrlParm($parm = "") {
		$UrlParm = ($this->UseTokenInUrl) ? "t=categoria" : "";
		if ($parm <> "") {
			if ($UrlParm <> "")
				$UrlParm .= "&";
			$UrlParm .= $parm;
		}
		return $UrlParm;
	}

	// Function LoadRs
	// - Load rows based on filter
	function LoadRs($sFilter) {
		global $conn;

		// Set up filter (Sql Where Clause) and get Return Sql
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		return $conn->Execute($sSql);
	}

	// Load row values from recordset
	function LoadListRowValues(&$rs) {
		$this->cod_categoria->setDbValue($rs->fields('cod_categoria'));
		$this->des_categoria->setDbValue($rs->fields('des_categoria'));
		$this->des_imagen->Upload->DbValue = $rs->fields('des_imagen');
		$this->ind_activo->setDbValue($rs->fields('ind_activo'));
		$this->margen->setDbValue($rs->fields('margen'));
		$this->displayConf->setDbValue($rs->fields('displayConf'));
		$this->displayCat->setDbValue($rs->fields('displayCat'));
		$this->ind_cat->setDbValue($rs->fields('ind_cat'));
		$this->orden->setDbValue($rs->fields('orden'));
		$this->cod_usuario_registro->setDbValue($rs->fields('cod_usuario_registro'));
		$this->fec_registro->setDbValue($rs->fields('fec_registro'));
		$this->cod_usuario_modificacion->setDbValue($rs->fields('cod_usuario_modificacion'));
		$this->fec_ultima_modificacion->setDbValue($rs->fields('fec_ultima_modificacion'));
	}

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

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

		// cod_categoria
		$this->cod_categoria->ViewValue = $this->cod_categoria->CurrentValue;
		$this->cod_categoria->CssStyle = "";
		$this->cod_categoria->CssClass = "";
		$this->cod_categoria->ViewCustomAttributes = "";

		// des_categoria
		$this->des_categoria->ViewValue = $this->des_categoria->CurrentValue;
		$this->des_categoria->CssStyle = "";
		$this->des_categoria->CssClass = "";
		$this->des_categoria->ViewCustomAttributes = "";

		// des_imagen
		if (!is_null($this->des_imagen->Upload->DbValue)) {
			$this->des_imagen->ViewValue = $this->des_imagen->Upload->DbValue;
			$this->des_imagen->ImageWidth = 120;
			$this->des_imagen->ImageHeight = 0;
			$this->des_imagen->ImageAlt = "";
		} else {
			$this->des_imagen->ViewValue = "";
		}
		$this->des_imagen->CssStyle = "";
		$this->des_imagen->CssClass = "";
		$this->des_imagen->ViewCustomAttributes = "";

		// margen
		$this->margen->ViewValue = $this->margen->CurrentValue;
		$this->margen->CssStyle = "";
		$this->margen->CssClass = "";
		$this->margen->ViewCustomAttributes = "";

		// displayCat
		if (strval($this->displayCat->CurrentValue) <> "") {
			switch ($this->displayCat->CurrentValue) {
				case "1":
					$this->displayCat->ViewValue = "Si";
					break;
				case "0":
					$this->displayCat->ViewValue = "No";
					break;
				default:
					$this->displayCat->ViewValue = $this->displayCat->CurrentValue;
			}
		} else {
			$this->displayCat->ViewValue = NULL;
		}
		$this->displayCat->CssStyle = "";
		$this->displayCat->CssClass = "";
		$this->displayCat->ViewCustomAttributes = "";

		// orden
		$this->orden->ViewValue = $this->orden->CurrentValue;
		$this->orden->CssStyle = "";
		$this->orden->CssClass = "";
		$this->orden->ViewCustomAttributes = "";

		// cod_categoria
		$this->cod_categoria->HrefValue = "";

		// des_categoria
		$this->des_categoria->HrefValue = "";

		// des_imagen
		$this->des_imagen->HrefValue = "";

		// margen
		$this->margen->HrefValue = "";

		// displayCat
		$this->displayCat->HrefValue = "";

		// orden
		$this->orden->HrefValue = "";

		// Call Row Rendered event
		$this->Row_Rendered();
	}
	var $CurrentAction; // Current action
	var $EventName; // Event name
	var $EventCancelled; // Event cancelled
	var $CancelMessage; // Cancel message
	var $RowType; // Row Type
	var $CssClass; // Css class
	var $CssStyle; // Css style
	var $RowClientEvents; // Row client events

	// Row Attribute
	function RowAttributes() {
		$sAtt = "";
		if (trim($this->CssStyle) <> "") {
			$sAtt .= " style=\"" . trim($this->CssStyle) . "\"";
		}
		if (trim($this->CssClass) <> "") {
			$sAtt .= " class=\"" . trim($this->CssClass) . "\"";
		}
		if ($this->Export == "") {
			if (trim($this->RowClientEvents) <> "") {
				$sAtt .= " " . trim($this->RowClientEvents);
			}
		}
		return $sAtt;
	}

	// Field objects
	function fields($fldname) {
		return $this->fields[$fldname];
	}

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

	}

	// Row Inserting event
	function Row_Inserting(&$rs) {

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

		return TRUE;
	}

	// Row Inserted event
	function Row_Inserted(&$rs) {

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