<?php

// PHPMaker 6 configuration for Table producto
$producto = new cproducto; // Initialize table object

// Define table class
class cproducto {

	// Define table level constants
	var $TableVar;
	var $TableName;
	var $SelectLimit = FALSE;
	var $id;
	var $cod_producto;
	var $cod_pvDT;
	var $cod_proveedor;
	var $cod_tipo_moneda;
	var $cod_tipo_solucion;
	var $cod_unidad_medida;
	var $cod_tipo_producto;
	var $cod_tipo_inventario;
	var $cod_garantia;
	var $cod_linea_producto;
	var $cod_categoria;
	var $cod_marca;
	var $des_producto;
	var $des_adicional;
	var $des_tecnicas;
	var $des_palabra_busqueda;
	var $stk_disponible;
	var $stk_minimo;
	var $pre_costo_promedio_anterior;
	var $pre_costo_promedio;
	var $pre_venta_publico_anterior;
	var $pre_venta_publico;
	var $pre_venta_corporativo_anterior;
	var $pre_venta_corporativo;
	var $pre_venta_minimo;
	var $pre_oferta;
	var $fec_inicio_oferta;
	var $fec_fin_oferta;
	var $des_web_referencial;
	var $ind_activo_web;
	var $des_imagen_pequena;
	var $des_imagen_grande;
	var $num_mes;
	var $num_trimestre;
	var $num_ano;
	var $displayConf;
	var $displayCat;
	var $ind_mostrar_categoria;
	var $ind_mostrar_portal;
	var $ind_oferta;
	var $ind_activo;
	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 cproducto() {
		$this->TableVar = "producto";
		$this->TableName = "producto";
		$this->SelectLimit = TRUE;
		$this->id = new cField('producto', 'x_id', 'id', "`id`", 3, -1, FALSE);
		$this->fields['id'] =& $this->id;
		$this->cod_producto = new cField('producto', 'x_cod_producto', 'cod_producto', "`cod_producto`", 200, -1, FALSE);
		$this->fields['cod_producto'] =& $this->cod_producto;
		$this->cod_pvDT = new cField('producto', 'x_cod_pvDT', 'cod_pvDT', "`cod_pvDT`", 200, -1, FALSE);
		$this->fields['cod_pvDT'] =& $this->cod_pvDT;
		$this->cod_proveedor = new cField('producto', 'x_cod_proveedor', 'cod_proveedor', "`cod_proveedor`", 200, -1, FALSE);
		$this->fields['cod_proveedor'] =& $this->cod_proveedor;
		$this->cod_tipo_moneda = new cField('producto', 'x_cod_tipo_moneda', 'cod_tipo_moneda', "`cod_tipo_moneda`", 3, -1, FALSE);
		$this->fields['cod_tipo_moneda'] =& $this->cod_tipo_moneda;
		$this->cod_tipo_solucion = new cField('producto', 'x_cod_tipo_solucion', 'cod_tipo_solucion', "`cod_tipo_solucion`", 200, -1, FALSE);
		$this->fields['cod_tipo_solucion'] =& $this->cod_tipo_solucion;
		$this->cod_unidad_medida = new cField('producto', 'x_cod_unidad_medida', 'cod_unidad_medida', "`cod_unidad_medida`", 3, -1, FALSE);
		$this->fields['cod_unidad_medida'] =& $this->cod_unidad_medida;
		$this->cod_tipo_producto = new cField('producto', 'x_cod_tipo_producto', 'cod_tipo_producto', "`cod_tipo_producto`", 3, -1, FALSE);
		$this->fields['cod_tipo_producto'] =& $this->cod_tipo_producto;
		$this->cod_tipo_inventario = new cField('producto', 'x_cod_tipo_inventario', 'cod_tipo_inventario', "`cod_tipo_inventario`", 3, -1, FALSE);
		$this->fields['cod_tipo_inventario'] =& $this->cod_tipo_inventario;
		$this->cod_garantia = new cField('producto', 'x_cod_garantia', 'cod_garantia', "`cod_garantia`", 200, -1, FALSE);
		$this->fields['cod_garantia'] =& $this->cod_garantia;
		$this->cod_linea_producto = new cField('producto', 'x_cod_linea_producto', 'cod_linea_producto', "`cod_linea_producto`", 200, -1, FALSE);
		$this->fields['cod_linea_producto'] =& $this->cod_linea_producto;
		$this->cod_categoria = new cField('producto', 'x_cod_categoria', 'cod_categoria', "`cod_categoria`", 200, -1, FALSE);
		$this->fields['cod_categoria'] =& $this->cod_categoria;
		$this->cod_marca = new cField('producto', 'x_cod_marca', 'cod_marca', "`cod_marca`", 200, -1, FALSE);
		$this->fields['cod_marca'] =& $this->cod_marca;
		$this->des_producto = new cField('producto', 'x_des_producto', 'des_producto', "`des_producto`", 200, -1, FALSE);
		$this->fields['des_producto'] =& $this->des_producto;
		$this->des_adicional = new cField('producto', 'x_des_adicional', 'des_adicional', "`des_adicional`", 200, -1, FALSE);
		$this->fields['des_adicional'] =& $this->des_adicional;
		$this->des_tecnicas = new cField('producto', 'x_des_tecnicas', 'des_tecnicas', "`des_tecnicas`", 201, -1, FALSE);
		$this->fields['des_tecnicas'] =& $this->des_tecnicas;
		$this->des_palabra_busqueda = new cField('producto', 'x_des_palabra_busqueda', 'des_palabra_busqueda', "`des_palabra_busqueda`", 200, -1, FALSE);
		$this->fields['des_palabra_busqueda'] =& $this->des_palabra_busqueda;
		$this->stk_disponible = new cField('producto', 'x_stk_disponible', 'stk_disponible', "`stk_disponible`", 3, -1, FALSE);
		$this->fields['stk_disponible'] =& $this->stk_disponible;
		$this->stk_minimo = new cField('producto', 'x_stk_minimo', 'stk_minimo', "`stk_minimo`", 3, -1, FALSE);
		$this->fields['stk_minimo'] =& $this->stk_minimo;
		$this->pre_costo_promedio_anterior = new cField('producto', 'x_pre_costo_promedio_anterior', 'pre_costo_promedio_anterior', "`pre_costo_promedio_anterior`", 4, -1, FALSE);
		$this->fields['pre_costo_promedio_anterior'] =& $this->pre_costo_promedio_anterior;
		$this->pre_costo_promedio = new cField('producto', 'x_pre_costo_promedio', 'pre_costo_promedio', "`pre_costo_promedio`", 4, -1, FALSE);
		$this->fields['pre_costo_promedio'] =& $this->pre_costo_promedio;
		$this->pre_venta_publico_anterior = new cField('producto', 'x_pre_venta_publico_anterior', 'pre_venta_publico_anterior', "`pre_venta_publico_anterior`", 4, -1, FALSE);
		$this->fields['pre_venta_publico_anterior'] =& $this->pre_venta_publico_anterior;
		$this->pre_venta_publico = new cField('producto', 'x_pre_venta_publico', 'pre_venta_publico', "`pre_venta_publico`", 4, -1, FALSE);
		$this->fields['pre_venta_publico'] =& $this->pre_venta_publico;
		$this->pre_venta_corporativo_anterior = new cField('producto', 'x_pre_venta_corporativo_anterior', 'pre_venta_corporativo_anterior', "`pre_venta_corporativo_anterior`", 4, -1, FALSE);
		$this->fields['pre_venta_corporativo_anterior'] =& $this->pre_venta_corporativo_anterior;
		$this->pre_venta_corporativo = new cField('producto', 'x_pre_venta_corporativo', 'pre_venta_corporativo', "`pre_venta_corporativo`", 4, -1, FALSE);
		$this->fields['pre_venta_corporativo'] =& $this->pre_venta_corporativo;
		$this->pre_venta_minimo = new cField('producto', 'x_pre_venta_minimo', 'pre_venta_minimo', "`pre_venta_minimo`", 4, -1, FALSE);
		$this->fields['pre_venta_minimo'] =& $this->pre_venta_minimo;
		$this->pre_oferta = new cField('producto', 'x_pre_oferta', 'pre_oferta', "`pre_oferta`", 4, -1, FALSE);
		$this->fields['pre_oferta'] =& $this->pre_oferta;
		$this->fec_inicio_oferta = new cField('producto', 'x_fec_inicio_oferta', 'fec_inicio_oferta', "`fec_inicio_oferta`", 133, 5, FALSE);
		$this->fields['fec_inicio_oferta'] =& $this->fec_inicio_oferta;
		$this->fec_fin_oferta = new cField('producto', 'x_fec_fin_oferta', 'fec_fin_oferta', "`fec_fin_oferta`", 133, 5, FALSE);
		$this->fields['fec_fin_oferta'] =& $this->fec_fin_oferta;
		$this->des_web_referencial = new cField('producto', 'x_des_web_referencial', 'des_web_referencial', "`des_web_referencial`", 200, -1, FALSE);
		$this->fields['des_web_referencial'] =& $this->des_web_referencial;
		$this->ind_activo_web = new cField('producto', 'x_ind_activo_web', 'ind_activo_web', "`ind_activo_web`", 200, -1, FALSE);
		$this->fields['ind_activo_web'] =& $this->ind_activo_web;
		$this->des_imagen_pequena = new cField('producto', 'x_des_imagen_pequena', 'des_imagen_pequena', "`des_imagen_pequena`", 200, -1, TRUE);
		$this->fields['des_imagen_pequena'] =& $this->des_imagen_pequena;
		$this->des_imagen_grande = new cField('producto', 'x_des_imagen_grande', 'des_imagen_grande', "`des_imagen_grande`", 200, -1, TRUE);
		$this->fields['des_imagen_grande'] =& $this->des_imagen_grande;
		$this->num_mes = new cField('producto', 'x_num_mes', 'num_mes', "`num_mes`", 200, -1, FALSE);
		$this->fields['num_mes'] =& $this->num_mes;
		$this->num_trimestre = new cField('producto', 'x_num_trimestre', 'num_trimestre', "`num_trimestre`", 200, -1, FALSE);
		$this->fields['num_trimestre'] =& $this->num_trimestre;
		$this->num_ano = new cField('producto', 'x_num_ano', 'num_ano', "`num_ano`", 200, -1, FALSE);
		$this->fields['num_ano'] =& $this->num_ano;
		$this->displayConf = new cField('producto', 'x_displayConf', 'displayConf', "`displayConf`", 16, -1, FALSE);
		$this->fields['displayConf'] =& $this->displayConf;
		$this->displayCat = new cField('producto', 'x_displayCat', 'displayCat', "`displayCat`", 16, -1, FALSE);
		$this->fields['displayCat'] =& $this->displayCat;
		$this->ind_mostrar_categoria = new cField('producto', 'x_ind_mostrar_categoria', 'ind_mostrar_categoria', "`ind_mostrar_categoria`", 200, -1, FALSE);
		$this->fields['ind_mostrar_categoria'] =& $this->ind_mostrar_categoria;
		$this->ind_mostrar_portal = new cField('producto', 'x_ind_mostrar_portal', 'ind_mostrar_portal', "`ind_mostrar_portal`", 200, -1, FALSE);
		$this->fields['ind_mostrar_portal'] =& $this->ind_mostrar_portal;
		$this->ind_oferta = new cField('producto', 'x_ind_oferta', 'ind_oferta', "`ind_oferta`", 200, -1, FALSE);
		$this->fields['ind_oferta'] =& $this->ind_oferta;
		$this->ind_activo = new cField('producto', 'x_ind_activo', 'ind_activo', "`ind_activo`", 200, -1, FALSE);
		$this->fields['ind_activo'] =& $this->ind_activo;
		$this->cod_usuario_registro = new cField('producto', '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('producto', 'x_fec_registro', 'fec_registro', "`fec_registro`", 135, 5, FALSE);
		$this->fields['fec_registro'] =& $this->fec_registro;
		$this->cod_usuario_modificacion = new cField('producto', '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('producto', '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 "producto_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;
	}

	// Current master table name
	function getCurrentMasterTable() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_MASTER_TABLE];
	}

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

	// Session master where clause
	function getMasterFilter() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_MASTER_FILTER];
	}

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

	// Session detail where clause
	function getDetailFilter() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_DETAIL_FILTER];
	}

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

	// Master filter
	function SqlMasterFilter_categoria() {
		return "`cod_categoria`='@cod_categoria@'";
	}

	// Detail filter
	function SqlDetailFilter_categoria() {
		return "`cod_categoria`='@cod_categoria@'";
	}

	// Master filter
	function SqlMasterFilter_linea_producto() {
		return "`cod_linea_producto`='@cod_linea_producto@'";
	}

	// Detail filter
	function SqlDetailFilter_linea_producto() {
		return "`cod_linea_producto`='@cod_linea_producto@'";
	}

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

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

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

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

	function SqlOrderBy() { // Order By
		return "`cod_pvDT` DESC,`des_producto` 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 `producto` ($names) VALUES ($values)";
	}

	// UPDATE statement
	function UpdateSQL(&$rs) {
		$SQL = "UPDATE `producto` 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 `producto` WHERE ";
		$SQL .= EW_DB_QUOTE_START . 'cod_producto' . EW_DB_QUOTE_END . '=' .	ew_QuotedValue($rs['cod_producto'], $this->cod_producto->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_producto` = '@cod_producto@'";
	}

	// Return Key filter for table
	function KeyFilter() {
		$sKeyFilter = $this->SqlKeyFilter();
		$sKeyFilter = str_replace("@cod_producto@", ew_AdjustSql($this->cod_producto->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 "productolist.php";
		}
	}

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

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

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

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

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

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

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

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

	// Key url
	function KeyUrl($url, $parm = "") {
		$sUrl = $url . "?";
		if ($parm <> "") $sUrl .= $parm . "&";
		if (!is_null($this->cod_producto->CurrentValue)) {
			$sUrl .= "cod_producto=" . urlencode($this->cod_producto->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=producto" : "";
		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->id->setDbValue($rs->fields('id'));
		$this->cod_producto->setDbValue($rs->fields('cod_producto'));
		$this->cod_pvDT->setDbValue($rs->fields('cod_pvDT'));
		$this->cod_proveedor->setDbValue($rs->fields('cod_proveedor'));
		$this->cod_tipo_moneda->setDbValue($rs->fields('cod_tipo_moneda'));
		$this->cod_tipo_solucion->setDbValue($rs->fields('cod_tipo_solucion'));
		$this->cod_unidad_medida->setDbValue($rs->fields('cod_unidad_medida'));
		$this->cod_tipo_producto->setDbValue($rs->fields('cod_tipo_producto'));
		$this->cod_tipo_inventario->setDbValue($rs->fields('cod_tipo_inventario'));
		$this->cod_garantia->setDbValue($rs->fields('cod_garantia'));
		$this->cod_linea_producto->setDbValue($rs->fields('cod_linea_producto'));
		$this->cod_categoria->setDbValue($rs->fields('cod_categoria'));
		$this->cod_marca->setDbValue($rs->fields('cod_marca'));
		$this->des_producto->setDbValue($rs->fields('des_producto'));
		$this->des_adicional->setDbValue($rs->fields('des_adicional'));
		$this->des_tecnicas->setDbValue($rs->fields('des_tecnicas'));
		$this->des_palabra_busqueda->setDbValue($rs->fields('des_palabra_busqueda'));
		$this->stk_disponible->setDbValue($rs->fields('stk_disponible'));
		$this->stk_minimo->setDbValue($rs->fields('stk_minimo'));
		$this->pre_costo_promedio_anterior->setDbValue($rs->fields('pre_costo_promedio_anterior'));
		$this->pre_costo_promedio->setDbValue($rs->fields('pre_costo_promedio'));
		$this->pre_venta_publico_anterior->setDbValue($rs->fields('pre_venta_publico_anterior'));
		$this->pre_venta_publico->setDbValue($rs->fields('pre_venta_publico'));
		$this->pre_venta_corporativo_anterior->setDbValue($rs->fields('pre_venta_corporativo_anterior'));
		$this->pre_venta_corporativo->setDbValue($rs->fields('pre_venta_corporativo'));
		$this->pre_venta_minimo->setDbValue($rs->fields('pre_venta_minimo'));
		$this->pre_oferta->setDbValue($rs->fields('pre_oferta'));
		$this->fec_inicio_oferta->setDbValue($rs->fields('fec_inicio_oferta'));
		$this->fec_fin_oferta->setDbValue($rs->fields('fec_fin_oferta'));
		$this->des_web_referencial->setDbValue($rs->fields('des_web_referencial'));
		$this->ind_activo_web->setDbValue($rs->fields('ind_activo_web'));
		$this->des_imagen_pequena->Upload->DbValue = $rs->fields('des_imagen_pequena');
		$this->des_imagen_grande->Upload->DbValue = $rs->fields('des_imagen_grande');
		$this->num_mes->setDbValue($rs->fields('num_mes'));
		$this->num_trimestre->setDbValue($rs->fields('num_trimestre'));
		$this->num_ano->setDbValue($rs->fields('num_ano'));
		$this->displayConf->setDbValue($rs->fields('displayConf'));
		$this->displayCat->setDbValue($rs->fields('displayCat'));
		$this->ind_mostrar_categoria->setDbValue($rs->fields('ind_mostrar_categoria'));
		$this->ind_mostrar_portal->setDbValue($rs->fields('ind_mostrar_portal'));
		$this->ind_oferta->setDbValue($rs->fields('ind_oferta'));
		$this->ind_activo->setDbValue($rs->fields('ind_activo'));
		$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_producto
		$this->cod_producto->ViewValue = $this->cod_producto->CurrentValue;
		$this->cod_producto->CssStyle = "";
		$this->cod_producto->CssClass = "";
		$this->cod_producto->ViewCustomAttributes = "";

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

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

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

		// pre_venta_publico
		$this->pre_venta_publico->ViewValue = $this->pre_venta_publico->CurrentValue;
		$this->pre_venta_publico->CssStyle = "";
		$this->pre_venta_publico->CssClass = "";
		$this->pre_venta_publico->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 = "";

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

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

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

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

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

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

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

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