<?php
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg6.php" ?>
<?php include "ewmysql6.php" ?>
<?php include "phpfn6.php" ?>
<?php include "pv_deltron_catinfo.php" ?>
<?php include "usuarioinfo.php" ?>
<?php include "userfn6.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Define page object
$pv_deltron_cat_list = new cpv_deltron_cat_list();
$Page =& $pv_deltron_cat_list;

// Page init processing
$pv_deltron_cat_list->Page_Init();

// Page main processing
$pv_deltron_cat_list->Page_Main();
?>
<?php include "header.php" ?>
<?php if ($pv_deltron_cat->Export == "") { ?>
<script type="text/javascript">
<!--

// Create page object
var pv_deltron_cat_list = new ew_Page("pv_deltron_cat_list");

// page properties
pv_deltron_cat_list.PageID = "list"; // page ID
var EW_PAGE_ID = pv_deltron_cat_list.PageID; // for backward compatibility

// extend page with Form_CustomValidate function
pv_deltron_cat_list.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
pv_deltron_cat_list.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
pv_deltron_cat_list.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<?php } ?>
<?php if ($pv_deltron_cat->Export == "") { ?>
<?php } ?>
<?php
	$bSelectLimit = ($pv_deltron_cat->Export == "" && $pv_deltron_cat->SelectLimit);
	if (!$bSelectLimit)
		$rs = $pv_deltron_cat_list->LoadRecordset();
	$pv_deltron_cat_list->lTotalRecs = ($bSelectLimit) ? $pv_deltron_cat->SelectRecordCount() : $rs->RecordCount();
	$pv_deltron_cat_list->lStartRec = 1;
	if ($pv_deltron_cat_list->lDisplayRecs <= 0) // Display all records
		$pv_deltron_cat_list->lDisplayRecs = $pv_deltron_cat_list->lTotalRecs;
	if (!($pv_deltron_cat->ExportAll && $pv_deltron_cat->Export <> ""))
		$pv_deltron_cat_list->SetUpStartRec(); // Set up start record position
	if ($bSelectLimit)
		$rs = $pv_deltron_cat_list->LoadRecordset($pv_deltron_cat_list->lStartRec-1, $pv_deltron_cat_list->lDisplayRecs);
?>
<p><span class="phpmaker" style="white-space: nowrap;">TABLA: DTcat
<?php if ($pv_deltron_cat->Export == "" && $pv_deltron_cat->CurrentAction == "") { ?>
&nbsp;&nbsp;<a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>export=excel"><img src='images/exportxls.gif' width='16' height='16' border='0' alt='Exportar a Excel'></a>
&nbsp;&nbsp;<a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>export=word"><img src='images/exportdoc.gif' width='16' height='16' border='0' alt='Exportar a Word'></a>
&nbsp;&nbsp;<a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>export=csv"><img src='images/exportcsv.gif' width='16' height='16' border='0' alt='Exportar a CSV'></a>
<?php } ?>
</span></p>
<?php if ($Security->IsLoggedIn()) { ?>
<?php if ($pv_deltron_cat->Export == "" && $pv_deltron_cat->CurrentAction == "") { ?>
<a href="javascript:ew_ToggleSearchPanel(pv_deltron_cat_list);" style="text-decoration: none;"><img id="pv_deltron_cat_list_SearchImage" src="images/collapse.gif" alt="" width="9" height="9" border="0"></a><span class="phpmaker">&nbsp;Buscar</span><br>
<div id="pv_deltron_cat_list_SearchPanel">
<form name="fpv_deltron_catlistsrch" id="fpv_deltron_catlistsrch" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
<input type="hidden" id="t" name="t" value="pv_deltron_cat">
<table class="ewBasicSearch">
	<tr>
		<td><span class="phpmaker">
			<input type="text" name="<?php echo EW_TABLE_BASIC_SEARCH ?>" id="<?php echo EW_TABLE_BASIC_SEARCH ?>" size="20" value="<?php echo ew_HtmlEncode($pv_deltron_cat->getBasicSearchKeyword()) ?>">
			<input type="Submit" name="Submit" id="Submit" value="Buscar (*)">&nbsp;
			<a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>cmd=reset">Ver Todo</a>&nbsp;
		</span></td>
	</tr>
	<tr>
	<td><span class="phpmaker"><label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value=""<?php if ($pv_deltron_cat->getBasicSearchType() == "") { ?> checked="checked"<?php } ?>>Frase exacta</label>&nbsp;&nbsp;<label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="AND"<?php if ($pv_deltron_cat->getBasicSearchType() == "AND") { ?> checked="checked"<?php } ?>>Todas las palabras</label>&nbsp;&nbsp;<label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="OR"<?php if ($pv_deltron_cat->getBasicSearchType() == "OR") { ?> checked="checked"<?php } ?>>Cualquier palabra</label></span></td>
	</tr>
</table>
</form>
</div>
<?php } ?>
<?php } ?>
<?php $pv_deltron_cat_list->ShowMessage() ?>
<br>
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<form name="fpv_deltron_catlist" id="fpv_deltron_catlist" class="ewForm" action="" method="post">
<?php if ($pv_deltron_cat_list->lTotalRecs > 0) { ?>
<table cellspacing="0" rowhighlightclass="ewTableHighlightRow" rowselectclass="ewTableSelectRow" roweditclass="ewTableEditRow" class="ewTable ewTableSeparate">
<?php
	$pv_deltron_cat_list->lOptionCnt = 0;
if ($Security->IsLoggedIn()) {
	$pv_deltron_cat_list->lOptionCnt++; // view
}
if ($Security->IsLoggedIn()) {
	$pv_deltron_cat_list->lOptionCnt++; // edit
}
if ($Security->IsLoggedIn()) {
	$pv_deltron_cat_list->lOptionCnt++; // copy
}
if ($Security->IsLoggedIn()) {
	$pv_deltron_cat_list->lOptionCnt++; // Delete
}
if ($Security->IsLoggedIn()) {
	$pv_deltron_cat_list->lOptionCnt++; // Detail
}
	$pv_deltron_cat_list->lOptionCnt += count($pv_deltron_cat_list->ListOptions->Items); // Custom list options
?>
<?php echo $pv_deltron_cat->TableCustomInnerHtml ?>
<thead><!-- Table header -->
	<tr class="ewTableHeader">
<?php if ($pv_deltron_cat->id->Visible) { // id ?>
	<?php if ($pv_deltron_cat->SortUrl($pv_deltron_cat->id) == "") { ?>
		<td>Id</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron_cat->SortUrl($pv_deltron_cat->id) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>Id</td><td style="width: 10px;"><?php if ($pv_deltron_cat->id->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron_cat->id->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron_cat->categoria->Visible) { // categoria ?>
	<?php if ($pv_deltron_cat->SortUrl($pv_deltron_cat->categoria) == "") { ?>
		<td>Categoria</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron_cat->SortUrl($pv_deltron_cat->categoria) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>Categoria&nbsp;(*)</td><td style="width: 10px;"><?php if ($pv_deltron_cat->categoria->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron_cat->categoria->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron_cat->margen->Visible) { // margen ?>
	<?php if ($pv_deltron_cat->SortUrl($pv_deltron_cat->margen) == "") { ?>
		<td>Margen</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron_cat->SortUrl($pv_deltron_cat->margen) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>Margen</td><td style="width: 10px;"><?php if ($pv_deltron_cat->margen->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron_cat->margen->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron_cat->Export == "") { ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;">&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;">&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;">&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;">&nbsp;</td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;">&nbsp;</td>
<?php } ?>
<?php

// Custom list options
foreach ($pv_deltron_cat_list->ListOptions->Items as $ListOption) {
	if ($ListOption->Visible)
		echo $ListOption->HeaderCellHtml;
}
?>
<?php } ?>
	</tr>
</thead>
<?php
if ($pv_deltron_cat->ExportAll && $pv_deltron_cat->Export <> "") {
	$pv_deltron_cat_list->lStopRec = $pv_deltron_cat_list->lTotalRecs;
} else {
	$pv_deltron_cat_list->lStopRec = $pv_deltron_cat_list->lStartRec + $pv_deltron_cat_list->lDisplayRecs - 1; // Set the last record to display
}
$pv_deltron_cat_list->lRecCount = $pv_deltron_cat_list->lStartRec - 1;
if ($rs && !$rs->EOF) {
	$rs->MoveFirst();
	if (!$pv_deltron_cat->SelectLimit && $pv_deltron_cat_list->lStartRec > 1)
		$rs->Move($pv_deltron_cat_list->lStartRec - 1);
}
$pv_deltron_cat_list->lRowCnt = 0;
while (($pv_deltron_cat->CurrentAction == "gridadd" || !$rs->EOF) &&
	$pv_deltron_cat_list->lRecCount < $pv_deltron_cat_list->lStopRec) {
	$pv_deltron_cat_list->lRecCount++;
	if (intval($pv_deltron_cat_list->lRecCount) >= intval($pv_deltron_cat_list->lStartRec)) {
		$pv_deltron_cat_list->lRowCnt++;

	// Init row class and style
	$pv_deltron_cat->CssClass = "";
	$pv_deltron_cat->CssStyle = "";
	$pv_deltron_cat->RowClientEvents = "onmouseover='ew_MouseOver(event, this);' onmouseout='ew_MouseOut(event, this);' onclick='ew_Click(event, this);'";
	if ($pv_deltron_cat->CurrentAction == "gridadd") {
		$pv_deltron_cat_list->LoadDefaultValues(); // Load default values
	} else {
		$pv_deltron_cat_list->LoadRowValues($rs); // Load row values
	}
	$pv_deltron_cat->RowType = EW_ROWTYPE_VIEW; // Render view

	// Render row
	$pv_deltron_cat_list->RenderRow();
?>
	<tr<?php echo $pv_deltron_cat->RowAttributes() ?>>
	<?php if ($pv_deltron_cat->id->Visible) { // id ?>
		<td<?php echo $pv_deltron_cat->id->CellAttributes() ?>>
<div<?php echo $pv_deltron_cat->id->ViewAttributes() ?>><?php echo $pv_deltron_cat->id->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron_cat->categoria->Visible) { // categoria ?>
		<td<?php echo $pv_deltron_cat->categoria->CellAttributes() ?>>
<div<?php echo $pv_deltron_cat->categoria->ViewAttributes() ?>><?php echo $pv_deltron_cat->categoria->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron_cat->margen->Visible) { // margen ?>
		<td<?php echo $pv_deltron_cat->margen->CellAttributes() ?>>
<div<?php echo $pv_deltron_cat->margen->ViewAttributes() ?>><?php echo $pv_deltron_cat->margen->ListViewValue() ?></div>
</td>
	<?php } ?>
<?php if ($pv_deltron_cat->Export == "") { ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;"><span class="phpmaker">
<a href="<?php echo $pv_deltron_cat->ViewUrl() ?>"><img src='images/browse.gif' width='16' height='16' border='0' alt='Ver'></a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;"><span class="phpmaker">
<a href="<?php echo $pv_deltron_cat->EditUrl() ?>"><img src='images/edit.gif' width='16' height='16' border='0' alt='Editar'></a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;"><span class="phpmaker">
<a href="<?php echo $pv_deltron_cat->CopyUrl() ?>"><img src='images/copy.gif' width='16' height='16' border='0' alt='Copiar'></a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;"><span class="phpmaker">
<a href="<?php echo $pv_deltron_cat->DeleteUrl() ?>"><img src='images/delete.gif' width='16' height='16' border='0' alt='Borrar'></a>
</span></td>
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<td style="white-space: nowrap;"><span class="phpmaker">
<a href="pv_deltronlist.php?<?php echo EW_TABLE_SHOW_MASTER ?>=pv_deltron_cat&categoria=<?php echo urlencode(strval($pv_deltron_cat->categoria->CurrentValue)) ?>">DTprod<img src='images/detail.gif' width='16' height='16' border='0' alt='Detalles'></a>
</span></td>
<?php } ?>
<?php

// Custom list options
foreach ($pv_deltron_cat_list->ListOptions->Items as $ListOption) {
	if ($ListOption->Visible)
		echo $ListOption->BodyCellHtml;
}
?>
<?php } ?>
	</tr>
<?php
	}
	if ($pv_deltron_cat->CurrentAction <> "gridadd")
		$rs->MoveNext();
}
?>
</tbody>
</table>
<?php } ?>
</form>
<?php

// Close recordset
if ($rs)
	$rs->Close();
?>
</div>
<?php if ($pv_deltron_cat->Export == "") { ?>
<div class="ewGridLowerPanel">
<?php if ($pv_deltron_cat->CurrentAction <> "gridadd" && $pv_deltron_cat->CurrentAction <> "gridedit") { ?>
<form name="ewpagerform" id="ewpagerform" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
<table border="0" cellspacing="0" cellpadding="0" class="ewPager">
	<tr>
		<td nowrap>
<?php if (!isset($pv_deltron_cat_list->Pager)) $pv_deltron_cat_list->Pager = new cPrevNextPager($pv_deltron_cat_list->lStartRec, $pv_deltron_cat_list->lDisplayRecs, $pv_deltron_cat_list->lTotalRecs) ?>
<?php if ($pv_deltron_cat_list->Pager->RecordCount > 0) { ?>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpmaker">Página&nbsp;</span></td>
<!--first page button-->
	<?php if ($pv_deltron_cat_list->Pager->FirstButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>start=<?php echo $pv_deltron_cat_list->Pager->FirstButton->Start ?>"><img src="images/first.gif" alt="Primera" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/firstdisab.gif" alt="Primera" width="16" height="16" border="0"></td>
	<?php } ?>
<!--previous page button-->
	<?php if ($pv_deltron_cat_list->Pager->PrevButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>start=<?php echo $pv_deltron_cat_list->Pager->PrevButton->Start ?>"><img src="images/prev.gif" alt="Previo" width="16" height="16" border="0"></a></td>
	<?php } else { ?>
	<td><img src="images/prevdisab.gif" alt="Previo" width="16" height="16" border="0"></td>
	<?php } ?>
<!--current page number-->
	<td><input type="text" name="<?php echo EW_TABLE_PAGE_NO ?>" id="<?php echo EW_TABLE_PAGE_NO ?>" value="<?php echo $pv_deltron_cat_list->Pager->CurrentPage ?>" size="4"></td>
<!--next page button-->
	<?php if ($pv_deltron_cat_list->Pager->NextButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>start=<?php echo $pv_deltron_cat_list->Pager->NextButton->Start ?>"><img src="images/next.gif" alt="Siguiente" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/nextdisab.gif" alt="Siguiente" width="16" height="16" border="0"></td>
	<?php } ?>
<!--last page button-->
	<?php if ($pv_deltron_cat_list->Pager->LastButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_cat_list->PageUrl() ?>start=<?php echo $pv_deltron_cat_list->Pager->LastButton->Start ?>"><img src="images/last.gif" alt="Ultima" width="16" height="16" border="0"></a></td>	
	<?php } else { ?>
	<td><img src="images/lastdisab.gif" alt="Ultima" width="16" height="16" border="0"></td>
	<?php } ?>
	<td><span class="phpmaker">&nbsp;de <?php echo $pv_deltron_cat_list->Pager->PageCount ?></span></td>
	</tr></table>
	</td>	
	<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td>
	<span class="phpmaker">Registros <?php echo $pv_deltron_cat_list->Pager->FromIndex ?> a <?php echo $pv_deltron_cat_list->Pager->ToIndex ?> de <?php echo $pv_deltron_cat_list->Pager->RecordCount ?></span>
<?php } else { ?>
	<?php if ($pv_deltron_cat_list->sSrchWhere == "0=101") { ?>
	<span class="phpmaker">Ingresar criterio de búsqueda</span>
	<?php } else { ?>
	<span class="phpmaker">No se encontraron registros</span>
	<?php } ?>
<?php } ?>
		</td>
<?php if ($pv_deltron_cat_list->lTotalRecs > 0) { ?>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td><table border="0" cellspacing="0" cellpadding="0"><tr><td>Tamaño&nbsp;</td><td>
<input type="hidden" id="t" name="t" value="pv_deltron_cat">
<select name="<?php echo EW_TABLE_REC_PER_PAGE ?>" id="<?php echo EW_TABLE_REC_PER_PAGE ?>" onchange="this.form.submit();" class="phpmaker">
<option value="20"<?php if ($pv_deltron_cat_list->lDisplayRecs == 20) { ?> selected="selected"<?php } ?>>20</option>
<option value="50"<?php if ($pv_deltron_cat_list->lDisplayRecs == 50) { ?> selected="selected"<?php } ?>>50</option>
<option value="ALL"<?php if ($pv_deltron_cat->getRecordsPerPage() == -1) { ?> selected="selected"<?php } ?>>Todos</option>
</select></td></tr></table>
		</td>
<?php } ?>
	</tr>
</table>
</form>
<?php } ?>
<?php //if ($pv_deltron_cat_list->lTotalRecs > 0) { ?>
<span class="phpmaker">
<?php if ($Security->IsLoggedIn()) { ?>
<a href="<?php echo $pv_deltron_cat->AddUrl() ?>">Agregar</a>&nbsp;&nbsp;
<?php } ?>
</span>
<?php //} ?>
</div>
<?php } ?>
</td></tr></table>
<?php if ($pv_deltron_cat->Export == "" && $pv_deltron_cat->CurrentAction == "") { ?>
<script type="text/javascript">
<!--

//ew_ToggleSearchPanel(pv_deltron_cat_list); // uncomment to init search panel as collapsed
//-->

</script>
<?php } ?>
<?php if ($pv_deltron_cat->Export == "") { ?>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php } ?>
<?php include "footer.php" ?>
<?php

//
// Page Class
//
class cpv_deltron_cat_list {

	// Page ID
	var $PageID = 'list';

	// Table Name
	var $TableName = 'pv_deltron_cat';

	// Page Object Name
	var $PageObjName = 'pv_deltron_cat_list';

	// Page Name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page Url
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $pv_deltron_cat;
		if ($pv_deltron_cat->UseTokenInUrl) $PageUrl .= "t=" . $pv_deltron_cat->TableVar . "&"; // add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show Message
	function ShowMessage() {
		if ($this->getMessage() <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $this->getMessage() . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate Page request
	function IsPageRequest() {
		global $objForm, $pv_deltron_cat;
		if ($pv_deltron_cat->UseTokenInUrl) {

			//IsPageRequest = False
			if ($objForm)
				return ($pv_deltron_cat->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($pv_deltron_cat->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	//  Class initialize
	//  - init objects
	//  - open connection
	//
	function cpv_deltron_cat_list() {
		global $conn;

		// Initialize table object
		$GLOBALS["pv_deltron_cat"] = new cpv_deltron_cat();

		// Initialize other table object
		$GLOBALS['usuario'] = new cusuario();

		// Intialize page id (for backward compatibility)
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'list', TRUE);

		// Initialize table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'pv_deltron_cat', TRUE);

		// Open connection to the database
		$conn = ew_Connect();

		// Initialize list options
		$this->ListOptions = new cListOptions();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $pv_deltron_cat;
		global $Security;
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
	$pv_deltron_cat->Export = @$_GET["export"]; // Get export parameter
	$gsExport = $pv_deltron_cat->Export; // Get export parameter, used in header
	$gsExportFile = $pv_deltron_cat->TableVar; // Get export file, used in header
	if ($pv_deltron_cat->Export == "excel") {
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment; filename=' . $gsExportFile .'.xls');
	}
	if ($pv_deltron_cat->Export == "word") {
		header('Content-Type: application/vnd.ms-word');
		header('Content-Disposition: attachment; filename=' . $gsExportFile .'.doc');
	}
	if ($pv_deltron_cat->Export == "csv") {
		header('Content-Type: application/csv');
		header('Content-Disposition: attachment; filename=' . $gsExportFile .'.csv');
	}

		// Global page loading event (in userfn6.php)
		Page_Loading();

		// Page load event, used in current page
		$this->Page_Load();
	}

	//
	//  Page_Terminate
	//  - called when exit page
	//  - if URL specified, redirect to the URL
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page unload event, used in current page
		$this->Page_Unload();

		// Global page unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close Connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			ob_end_clean();
			header("Location: $url");
		}
		exit();
	}
	var $lDisplayRecs; // Number of display records
	var $lStartRec;
	var $lStopRec;
	var $lTotalRecs;
	var $lRecRange;
	var $sSrchWhere;
	var $lRecCnt;
	var $lEditRowCnt;
	var $lRowCnt;
	var $lRowIndex;
	var $lOptionCnt;
	var $lRecPerRow;
	var $lColCnt;
	var $sDeleteConfirmMsg; // Delete confirm message
	var $sDbMasterFilter;
	var $sDbDetailFilter;
	var $bMasterRecordExists;	
	var $ListOptions;
	var $sMultiSelectKey;

	//
	// Page main processing
	//
	function Page_Main() {
		global $objForm, $gsSearchError, $Security, $pv_deltron_cat;
		$this->lDisplayRecs = 50;
		$this->lRecRange = 10;
		$this->lRecCnt = 0; // Record count

		// Search filters
		$sSrchAdvanced = ""; // Advanced search filter
		$sSrchBasic = ""; // Basic search filter
		$sFilter = "";
		$this->sSrchWhere = ""; // Search WHERE clause

		// Master/Detail
		$this->sDbMasterFilter = ""; // Master filter
		$this->sDbDetailFilter = ""; // Detail filter
		if ($this->IsPageRequest()) { // Validate request

			// Set up records per page dynamically
			$this->SetUpDisplayRecs();

			// Handle reset command
			$this->ResetCmd();

			// Get basic search criteria
			if ($gsSearchError == "")
				$sSrchBasic = $this->BasicSearchWhere();

			// Set Up Sorting Order
			$this->SetUpSortOrder();
		} // End Validate Request

		// Restore display records
		if ($pv_deltron_cat->getRecordsPerPage() <> "") {
			$this->lDisplayRecs = $pv_deltron_cat->getRecordsPerPage(); // Restore from Session
		} else {
			$this->lDisplayRecs = 50; // Load default
		}

		// Load Sorting Order
		$this->LoadSortOrder();

		// Build search criteria
		if ($sSrchAdvanced <> "")
			$this->sSrchWhere = ($this->sSrchWhere <> "") ? "($this->sSrchWhere) AND ($sSrchAdvanced)" : $sSrchAdvanced;
		if ($sSrchBasic <> "")
			$this->sSrchWhere = ($this->sSrchWhere <> "") ? "($this->sSrchWhere) AND ($sSrchBasic)" : $sSrchBasic;

		// Call Recordset_Searching event
		$pv_deltron_cat->Recordset_Searching($this->sSrchWhere);

		// Save search criteria
		if ($this->sSrchWhere <> "") {
			if ($sSrchBasic == "")
				$this->ResetBasicSearchParms();
			$pv_deltron_cat->setSearchWhere($this->sSrchWhere); // Save to Session
			$this->lStartRec = 1; // Reset start record counter
			$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
		} else {
			$this->RestoreSearchParms();
		}

		// Build filter
		$sFilter = "";
		if ($this->sDbDetailFilter <> "")
			$sFilter = ($sFilter <> "") ? "($sFilter) AND (" . $this->sDbDetailFilter . ")" : $this->sDbDetailFilter;
		if ($this->sSrchWhere <> "")
			$sFilter = ($sFilter <> "") ? "($sFilter) AND (". $this->sSrchWhere . ")" : $this->sSrchWhere;

		// Set up filter in Session
		$pv_deltron_cat->setSessionWhere($sFilter);
		$pv_deltron_cat->CurrentFilter = "";

		// Export data only
		if (in_array($pv_deltron_cat->Export, array("html","word","excel","xml","csv"))) {
			$this->ExportData();
			$this->Page_Terminate(); // Terminate response
			exit();
		}
	}

	// Set up number of records displayed per page
	function SetUpDisplayRecs() {
		global $pv_deltron_cat;
		$sWrk = @$_GET[EW_TABLE_REC_PER_PAGE];
		if ($sWrk <> "") {
			if (is_numeric($sWrk)) {
				$this->lDisplayRecs = intval($sWrk);
			} else {
				if (strtolower($sWrk) == "all") { // Display all records
					$this->lDisplayRecs = -1;
				} else {
					$this->lDisplayRecs = 50; // Non-numeric, load default
				}
			}
			$pv_deltron_cat->setRecordsPerPage($this->lDisplayRecs); // Save to Session

			// Reset start position
			$this->lStartRec = 1;
			$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
		}
	}

	// Return Basic Search sql
	function BasicSearchSQL($Keyword) {
		global $pv_deltron_cat;
		$sKeyword = ew_AdjustSql($Keyword);
		$sql = "";
		$sql .= $pv_deltron_cat->categoria->FldExpression . " LIKE '%" . $sKeyword . "%' OR ";
		if (substr($sql, -4) == " OR ") $sql = substr($sql, 0, strlen($sql)-4);
		return $sql;
	}

	// Return Basic Search Where based on search keyword and type
	function BasicSearchWhere() {
		global $Security, $pv_deltron_cat;
		$sSearchStr = "";
		$sSearchKeyword = ew_StripSlashes(@$_GET[EW_TABLE_BASIC_SEARCH]);
		$sSearchType = @$_GET[EW_TABLE_BASIC_SEARCH_TYPE];
		if ($sSearchKeyword <> "") {
			$sSearch = trim($sSearchKeyword);
			if ($sSearchType <> "") {
				while (strpos($sSearch, "  ") !== FALSE)
					$sSearch = str_replace("  ", " ", $sSearch);
				$arKeyword = explode(" ", trim($sSearch));
				foreach ($arKeyword as $sKeyword) {
					if ($sSearchStr <> "") $sSearchStr .= " " . $sSearchType . " ";
					$sSearchStr .= "(" . $this->BasicSearchSQL($sKeyword) . ")";
				}
			} else {
				$sSearchStr = $this->BasicSearchSQL($sSearch);
			}
		}
		if ($sSearchKeyword <> "") {
			$pv_deltron_cat->setBasicSearchKeyword($sSearchKeyword);
			$pv_deltron_cat->setBasicSearchType($sSearchType);
		}
		return $sSearchStr;
	}

	// Clear all search parameters
	function ResetSearchParms() {

		// Clear search where
		global $pv_deltron_cat;
		$this->sSrchWhere = "";
		$pv_deltron_cat->setSearchWhere($this->sSrchWhere);

		// Clear basic search parameters
		$this->ResetBasicSearchParms();
	}

	// Clear all basic search parameters
	function ResetBasicSearchParms() {

		// Clear basic search parameters
		global $pv_deltron_cat;
		$pv_deltron_cat->setBasicSearchKeyword("");
		$pv_deltron_cat->setBasicSearchType("");
	}

	// Restore all search parameters
	function RestoreSearchParms() {
		global $gsSearchError, $pv_deltron_cat;
		$this->sSrchWhere = $pv_deltron_cat->getSearchWhere();
	}

	// Set up Sort parameters based on Sort Links clicked
	function SetUpSortOrder() {
		global $pv_deltron_cat;

		// Check for an Order parameter
		if (@$_GET["order"] <> "") {
			$pv_deltron_cat->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
			$pv_deltron_cat->CurrentOrderType = @$_GET["ordertype"];
			$pv_deltron_cat->UpdateSort($pv_deltron_cat->id); // Field 
			$pv_deltron_cat->UpdateSort($pv_deltron_cat->categoria); // Field 
			$pv_deltron_cat->UpdateSort($pv_deltron_cat->margen); // Field 
			$pv_deltron_cat->setStartRecordNumber(1); // Reset start position
		}
	}

	// Load Sort Order parameters
	function LoadSortOrder() {
		global $pv_deltron_cat;
		$sOrderBy = $pv_deltron_cat->getSessionOrderBy(); // Get order by from Session
		if ($sOrderBy == "") {
			if ($pv_deltron_cat->SqlOrderBy() <> "") {
				$sOrderBy = $pv_deltron_cat->SqlOrderBy();
				$pv_deltron_cat->setSessionOrderBy($sOrderBy);
			}
		}
	}

	// Reset command based on querystring parameter cmd=
	// - RESET: reset search parameters
	// - RESETALL: reset search & master/detail parameters
	// - RESETSORT: reset sort parameters
	function ResetCmd() {
		global $pv_deltron_cat;

		// Get reset cmd
		if (@$_GET["cmd"] <> "") {
			$sCmd = $_GET["cmd"];

			// Reset search criteria
			if (strtolower($sCmd) == "reset" || strtolower($sCmd) == "resetall")
				$this->ResetSearchParms();

			// Reset sort criteria
			if (strtolower($sCmd) == "resetsort") {
				$sOrderBy = "";
				$pv_deltron_cat->setSessionOrderBy($sOrderBy);
				$pv_deltron_cat->id->setSort("");
				$pv_deltron_cat->categoria->setSort("");
				$pv_deltron_cat->margen->setSort("");
			}

			// Reset start position
			$this->lStartRec = 1;
			$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
		}
	}

	// Set up Starting Record parameters based on Pager Navigation
	function SetUpStartRec() {
		global $pv_deltron_cat;
		if ($this->lDisplayRecs == 0)
			return;
		if ($this->IsPageRequest()) { // Validate request			
			if (@$_GET[EW_TABLE_START_REC] <> "") { // Check for "start" parameter
				$this->lStartRec = $_GET[EW_TABLE_START_REC];
				$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
			} elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
				$this->nPageNo = $_GET[EW_TABLE_PAGE_NO];
				if (is_numeric($this->nPageNo)) {
					$this->lStartRec = ($this->nPageNo-1)*$this->lDisplayRecs+1;
					if ($this->lStartRec <= 0) {
						$this->lStartRec = 1;
					} elseif ($this->lStartRec >= intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1) {
						$this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1;
					}
					$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
				}
			}
		}
		$this->lStartRec = $pv_deltron_cat->getStartRecordNumber();

		// Check if correct start record counter
		if (!is_numeric($this->lStartRec) || $this->lStartRec == "") { // Avoid invalid start record counter
			$this->lStartRec = 1; // Reset start record counter
			$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
		} elseif (intval($this->lStartRec) > intval($this->lTotalRecs)) { // Avoid starting record > total records
			$this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to last page first record
			$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
		} elseif (($this->lStartRec-1) % $this->lDisplayRecs <> 0) {
			$this->lStartRec = intval(($this->lStartRec-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to page boundary
			$pv_deltron_cat->setStartRecordNumber($this->lStartRec);
		}
	}

	// Load recordset
	function LoadRecordset($offset = -1, $rowcnt = -1) {
		global $conn, $pv_deltron_cat;

		// Call Recordset Selecting event
		$pv_deltron_cat->Recordset_Selecting($pv_deltron_cat->CurrentFilter);

		// Load list page SQL
		$sSql = $pv_deltron_cat->SelectSQL();
		if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";

		// Load recordset
		$conn->raiseErrorFn = 'ew_ErrorFn';	
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';

		// Call Recordset Selected event
		$pv_deltron_cat->Recordset_Selected($rs);
		return $rs;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $pv_deltron_cat;
		$sFilter = $pv_deltron_cat->KeyFilter();

		// Call Row Selecting event
		$pv_deltron_cat->Row_Selecting($sFilter);

		// Load sql based on filter
		$pv_deltron_cat->CurrentFilter = $sFilter;
		$sSql = $pv_deltron_cat->SQL();
		if ($rs = $conn->Execute($sSql)) {
			if ($rs->EOF) {
				$LoadRow = FALSE;
			} else {
				$LoadRow = TRUE;
				$rs->MoveFirst();
				$this->LoadRowValues($rs); // Load row values

				// Call Row Selected event
				$pv_deltron_cat->Row_Selected($rs);
			}
			$rs->Close();
		} else {
			$LoadRow = FALSE;
		}
		return $LoadRow;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $pv_deltron_cat;
		$pv_deltron_cat->id->setDbValue($rs->fields('id'));
		$pv_deltron_cat->categoria->setDbValue($rs->fields('categoria'));
		$pv_deltron_cat->margen->setDbValue($rs->fields('margen'));
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $pv_deltron_cat;

		// Call Row_Rendering event
		$pv_deltron_cat->Row_Rendering();

		// Common render codes for all row types
		// id

		$pv_deltron_cat->id->CellCssStyle = "";
		$pv_deltron_cat->id->CellCssClass = "";

		// categoria
		$pv_deltron_cat->categoria->CellCssStyle = "";
		$pv_deltron_cat->categoria->CellCssClass = "";

		// margen
		$pv_deltron_cat->margen->CellCssStyle = "";
		$pv_deltron_cat->margen->CellCssClass = "";
		if ($pv_deltron_cat->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$pv_deltron_cat->id->ViewValue = $pv_deltron_cat->id->CurrentValue;
			$pv_deltron_cat->id->CssStyle = "";
			$pv_deltron_cat->id->CssClass = "";
			$pv_deltron_cat->id->ViewCustomAttributes = "";

			// categoria
			$pv_deltron_cat->categoria->ViewValue = $pv_deltron_cat->categoria->CurrentValue;
			$pv_deltron_cat->categoria->CssStyle = "";
			$pv_deltron_cat->categoria->CssClass = "";
			$pv_deltron_cat->categoria->ViewCustomAttributes = "";

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

			// id
			$pv_deltron_cat->id->HrefValue = "";

			// categoria
			$pv_deltron_cat->categoria->HrefValue = "";

			// margen
			$pv_deltron_cat->margen->HrefValue = "";
		}

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

	// Export data in XML or CSV format
	function ExportData() {
		global $pv_deltron_cat;
		$sCsvStr = "";

		// Default export style
		$sExportStyle = "h";

		// Load recordset
		$rs = $this->LoadRecordset();
		$this->lTotalRecs = $rs->RecordCount();
		$this->lStartRec = 1;

		// Export all
		if ($pv_deltron_cat->ExportAll) {
			$this->lStopRec = $this->lTotalRecs;
		} else { // Export 1 page only
			$this->SetUpStartRec(); // Set up start record position

			// Set the last record to display
			if ($this->lDisplayRecs < 0) {
				$this->lStopRec = $this->lTotalRecs;
			} else {
				$this->lStopRec = $this->lStartRec + $this->lDisplayRecs - 1;
			}
		}
		if ($pv_deltron_cat->Export == "xml") {
			$XmlDoc = new cXMLDocument();
		} else {
			echo ew_ExportHeader($pv_deltron_cat->Export);

			// Horizontal format, write header
			if ($sExportStyle <> "v" || $pv_deltron_cat->Export == "csv") {
				$sExportStr = "";
				ew_ExportAddValue($sExportStr, 'id', $pv_deltron_cat->Export);
				ew_ExportAddValue($sExportStr, 'categoria', $pv_deltron_cat->Export);
				ew_ExportAddValue($sExportStr, 'margen', $pv_deltron_cat->Export);
				echo ew_ExportLine($sExportStr, $pv_deltron_cat->Export);
			}
		}

		// Move to first record
		$this->lRecCnt = $this->lStartRec - 1;
		if (!$rs->EOF) {
			$rs->MoveFirst();
			$rs->Move($this->lStartRec - 1);
		}
		while (!$rs->EOF && $this->lRecCnt < $this->lStopRec) {
			$this->lRecCnt++;
			if (intval($this->lRecCnt) >= intval($this->lStartRec)) {
				$this->LoadRowValues($rs);

				// Render row for display
				$pv_deltron_cat->RowType = EW_ROWTYPE_VIEW; // Render view
				$this->RenderRow();
				if ($pv_deltron_cat->Export == "xml") {
					$XmlDoc->BeginRow();
					$XmlDoc->AddField('id', $pv_deltron_cat->id->CurrentValue);
					$XmlDoc->AddField('categoria', $pv_deltron_cat->categoria->CurrentValue);
					$XmlDoc->AddField('margen', $pv_deltron_cat->margen->CurrentValue);
					$XmlDoc->EndRow();
				} else {
					if ($sExportStyle == "v" && $pv_deltron_cat->Export <> "csv") { // Vertical format
						echo ew_ExportField('id', $pv_deltron_cat->id->ExportValue($pv_deltron_cat->Export, $pv_deltron_cat->ExportOriginalValue), $pv_deltron_cat->Export);
						echo ew_ExportField('categoria', $pv_deltron_cat->categoria->ExportValue($pv_deltron_cat->Export, $pv_deltron_cat->ExportOriginalValue), $pv_deltron_cat->Export);
						echo ew_ExportField('margen', $pv_deltron_cat->margen->ExportValue($pv_deltron_cat->Export, $pv_deltron_cat->ExportOriginalValue), $pv_deltron_cat->Export);
					}	else { // Horizontal format
						$sExportStr = "";
						ew_ExportAddValue($sExportStr, $pv_deltron_cat->id->ExportValue($pv_deltron_cat->Export, $pv_deltron_cat->ExportOriginalValue), $pv_deltron_cat->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron_cat->categoria->ExportValue($pv_deltron_cat->Export, $pv_deltron_cat->ExportOriginalValue), $pv_deltron_cat->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron_cat->margen->ExportValue($pv_deltron_cat->Export, $pv_deltron_cat->ExportOriginalValue), $pv_deltron_cat->Export);
						echo ew_ExportLine($sExportStr, $pv_deltron_cat->Export);
					}
				}
			}
			$rs->MoveNext();
		}

		// Close recordset
		$rs->Close();
		if ($pv_deltron_cat->Export == "xml") {
			header("Content-Type: text/xml");
			echo $XmlDoc->XML();
		} else {
			echo ew_ExportFooter($pv_deltron_cat->Export);
		}
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
