<?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_deltroninfo.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_list = new cpv_deltron_list();
$Page =& $pv_deltron_list;

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

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

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

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

// extend page with Form_CustomValidate function
pv_deltron_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_list.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
pv_deltron_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->Export == "") { ?>
<?php
$gsMasterReturnUrl = "pv_deltron_catlist.php";
if ($pv_deltron_list->sDbMasterFilter <> "" && $pv_deltron->getCurrentMasterTable() == "pv_deltron_cat") {
	if ($pv_deltron_list->bMasterRecordExists) {
		if ($pv_deltron->getCurrentMasterTable() == $pv_deltron->TableVar) $gsMasterReturnUrl .= "?" . EW_TABLE_SHOW_MASTER . "=";
?>
<?php include "pv_deltron_catmaster.php" ?>
<?php
	}
}
?>
<?php } ?>
<?php
	$bSelectLimit = ($pv_deltron->Export == "" && $pv_deltron->SelectLimit);
	if (!$bSelectLimit)
		$rs = $pv_deltron_list->LoadRecordset();
	$pv_deltron_list->lTotalRecs = ($bSelectLimit) ? $pv_deltron->SelectRecordCount() : $rs->RecordCount();
	$pv_deltron_list->lStartRec = 1;
	if ($pv_deltron_list->lDisplayRecs <= 0) // Display all records
		$pv_deltron_list->lDisplayRecs = $pv_deltron_list->lTotalRecs;
	if (!($pv_deltron->ExportAll && $pv_deltron->Export <> ""))
		$pv_deltron_list->SetUpStartRec(); // Set up start record position
	if ($bSelectLimit)
		$rs = $pv_deltron_list->LoadRecordset($pv_deltron_list->lStartRec-1, $pv_deltron_list->lDisplayRecs);
?>
<p><span class="phpmaker" style="white-space: nowrap;">TABLA: DTprod
<?php if ($pv_deltron->Export == "" && $pv_deltron->CurrentAction == "") { ?>
&nbsp;&nbsp;<a href="<?php echo $pv_deltron_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_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_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->Export == "" && $pv_deltron->CurrentAction == "") { ?>
<a href="javascript:ew_ToggleSearchPanel(pv_deltron_list);" style="text-decoration: none;"><img id="pv_deltron_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_list_SearchPanel">
<form name="fpv_deltronlistsrch" id="fpv_deltronlistsrch" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
<input type="hidden" id="t" name="t" value="pv_deltron">
<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->getBasicSearchKeyword()) ?>">
			<input type="Submit" name="Submit" id="Submit" value="Buscar (*)">&nbsp;
			<a href="<?php echo $pv_deltron_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->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->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->getBasicSearchType() == "OR") { ?> checked="checked"<?php } ?>>Cualquier palabra</label></span></td>
	</tr>
</table>
</form>
</div>
<?php } ?>
<?php } ?>
<?php $pv_deltron_list->ShowMessage() ?>
<br>
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<form name="fpv_deltronlist" id="fpv_deltronlist" class="ewForm" action="" method="post">
<?php if ($pv_deltron_list->lTotalRecs > 0) { ?>
<table cellspacing="0" rowhighlightclass="ewTableHighlightRow" rowselectclass="ewTableSelectRow" roweditclass="ewTableEditRow" class="ewTable ewTableSeparate">
<?php
	$pv_deltron_list->lOptionCnt = 0;
	$pv_deltron_list->lOptionCnt += count($pv_deltron_list->ListOptions->Items); // Custom list options
?>
<?php echo $pv_deltron->TableCustomInnerHtml ?>
<thead><!-- Table header -->
	<tr class="ewTableHeader">
<?php if ($pv_deltron->categoria->Visible) { // categoria ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->categoria) == "") { ?>
		<td>categoria</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->categoria) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>categoria&nbsp;(*)</td><td style="width: 10px;"><?php if ($pv_deltron->categoria->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->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->codigo->Visible) { // codigo ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->codigo) == "") { ?>
		<td>codigo</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->codigo) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>codigo&nbsp;(*)</td><td style="width: 10px;"><?php if ($pv_deltron->codigo->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->codigo->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron->nombre->Visible) { // nombre ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->nombre) == "") { ?>
		<td>nombre</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->nombre) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>nombre&nbsp;(*)</td><td style="width: 10px;"><?php if ($pv_deltron->nombre->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->nombre->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron->stockDT->Visible) { // stockDT ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->stockDT) == "") { ?>
		<td>stock DT</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->stockDT) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>stock DT</td><td style="width: 10px;"><?php if ($pv_deltron->stockDT->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->stockDT->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron->prDT->Visible) { // prDT ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->prDT) == "") { ?>
		<td>pr DT</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->prDT) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>pr DT</td><td style="width: 10px;"><?php if ($pv_deltron->prDT->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->prDT->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron->precio_s->Visible) { // precio_s ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->precio_s) == "") { ?>
		<td>precio s</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->precio_s) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>precio s</td><td style="width: 10px;"><?php if ($pv_deltron->precio_s->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->precio_s->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron->garantia->Visible) { // garantia ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->garantia) == "") { ?>
		<td>garantia</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->garantia) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>garantia&nbsp;(*)</td><td style="width: 10px;"><?php if ($pv_deltron->garantia->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->garantia->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron->marca->Visible) { // marca ?>
	<?php if ($pv_deltron->SortUrl($pv_deltron->marca) == "") { ?>
		<td>marca</td>
	<?php } else { ?>
		<td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $pv_deltron->SortUrl($pv_deltron->marca) ?>',1);">
			<table cellspacing="0" class="ewTableHeaderBtn"><tr><td>marca&nbsp;(*)</td><td style="width: 10px;"><?php if ($pv_deltron->marca->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($pv_deltron->marca->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
		</td>
	<?php } ?>
<?php } ?>		
<?php if ($pv_deltron->Export == "") { ?>
<?php

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

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

	// Render row
	$pv_deltron_list->RenderRow();
?>
	<tr<?php echo $pv_deltron->RowAttributes() ?>>
	<?php if ($pv_deltron->categoria->Visible) { // categoria ?>
		<td<?php echo $pv_deltron->categoria->CellAttributes() ?>>
<div<?php echo $pv_deltron->categoria->ViewAttributes() ?>><?php echo $pv_deltron->categoria->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron->codigo->Visible) { // codigo ?>
		<td<?php echo $pv_deltron->codigo->CellAttributes() ?>>
<div<?php echo $pv_deltron->codigo->ViewAttributes() ?>>
<?php if ($pv_deltron->codigo->HrefValue <> "") { ?>
<a href="http://www-spd.deltron.com.pe/modulos/productos/items/postsql.php?item_number=<?php echo $pv_deltron->codigo->HrefValue ?>" target="_blank"><?php echo $pv_deltron->codigo->ListViewValue() ?></a>
<?php } else { ?>
<?php echo $pv_deltron->codigo->ListViewValue() ?>
<?php } ?>
</div>
</td>
	<?php } ?>
	<?php if ($pv_deltron->nombre->Visible) { // nombre ?>
		<td<?php echo $pv_deltron->nombre->CellAttributes() ?>>
<div<?php echo $pv_deltron->nombre->ViewAttributes() ?>><?php echo $pv_deltron->nombre->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron->stockDT->Visible) { // stockDT ?>
		<td<?php echo $pv_deltron->stockDT->CellAttributes() ?>>
<div<?php echo $pv_deltron->stockDT->ViewAttributes() ?>><?php echo $pv_deltron->stockDT->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron->prDT->Visible) { // prDT ?>
		<td<?php echo $pv_deltron->prDT->CellAttributes() ?>>
<div<?php echo $pv_deltron->prDT->ViewAttributes() ?>><?php echo $pv_deltron->prDT->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron->precio_s->Visible) { // precio_s ?>
		<td<?php echo $pv_deltron->precio_s->CellAttributes() ?>>
<div<?php echo $pv_deltron->precio_s->ViewAttributes() ?>><?php echo $pv_deltron->precio_s->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron->garantia->Visible) { // garantia ?>
		<td<?php echo $pv_deltron->garantia->CellAttributes() ?>>
<div<?php echo $pv_deltron->garantia->ViewAttributes() ?>><?php echo $pv_deltron->garantia->ListViewValue() ?></div>
</td>
	<?php } ?>
	<?php if ($pv_deltron->marca->Visible) { // marca ?>
		<td<?php echo $pv_deltron->marca->CellAttributes() ?>>
<div<?php echo $pv_deltron->marca->ViewAttributes() ?>><?php echo $pv_deltron->marca->ListViewValue() ?></div>
</td>
	<?php } ?>
<?php if ($pv_deltron->Export == "") { ?>
<?php

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

// Close recordset
if ($rs)
	$rs->Close();
?>
</div>
<?php if ($pv_deltron->Export == "") { ?>
<div class="ewGridLowerPanel">
<?php if ($pv_deltron->CurrentAction <> "gridadd" && $pv_deltron->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_list->Pager)) $pv_deltron_list->Pager = new cPrevNextPager($pv_deltron_list->lStartRec, $pv_deltron_list->lDisplayRecs, $pv_deltron_list->lTotalRecs) ?>
<?php if ($pv_deltron_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_list->Pager->FirstButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_list->PageUrl() ?>start=<?php echo $pv_deltron_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_list->Pager->PrevButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_list->PageUrl() ?>start=<?php echo $pv_deltron_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_list->Pager->CurrentPage ?>" size="4"></td>
<!--next page button-->
	<?php if ($pv_deltron_list->Pager->NextButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_list->PageUrl() ?>start=<?php echo $pv_deltron_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_list->Pager->LastButton->Enabled) { ?>
	<td><a href="<?php echo $pv_deltron_list->PageUrl() ?>start=<?php echo $pv_deltron_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_list->Pager->PageCount ?></span></td>
	</tr></table>
	</td>	
	<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td>
	<span class="phpmaker">Registros <?php echo $pv_deltron_list->Pager->FromIndex ?> a <?php echo $pv_deltron_list->Pager->ToIndex ?> de <?php echo $pv_deltron_list->Pager->RecordCount ?></span>
<?php } else { ?>
	<?php if ($pv_deltron_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_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">
<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_list->lDisplayRecs == 20) { ?> selected="selected"<?php } ?>>20</option>
<option value="50"<?php if ($pv_deltron_list->lDisplayRecs == 50) { ?> selected="selected"<?php } ?>>50</option>
<option value="ALL"<?php if ($pv_deltron->getRecordsPerPage() == -1) { ?> selected="selected"<?php } ?>>Todos</option>
</select></td></tr></table>
		</td>
<?php } ?>
	</tr>
</table>
</form>
<?php } ?>
<?php //if ($pv_deltron_list->lTotalRecs > 0) { ?>
<span class="phpmaker">
</span>
<?php //} ?>
</div>
<?php } ?>
</td></tr></table>
<?php if ($pv_deltron->Export == "" && $pv_deltron->CurrentAction == "") { ?>
<script type="text/javascript">
<!--

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

</script>
<?php } ?>
<?php if ($pv_deltron->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_list {

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

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

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

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

	// Page Url
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $pv_deltron;
		if ($pv_deltron->UseTokenInUrl) $PageUrl .= "t=" . $pv_deltron->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;
		if ($pv_deltron->UseTokenInUrl) {

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

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

		// Initialize table object
		$GLOBALS["pv_deltron"] = new cpv_deltron();

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

			// Set up master detail parameters
			$this->SetUpMasterDetail();

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

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

		// Restore display records
		if ($pv_deltron->getRecordsPerPage() <> "") {
			$this->lDisplayRecs = $pv_deltron->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->Recordset_Searching($this->sSrchWhere);

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

		// Build filter
		$sFilter = "`stockDT` > 0";

		// Restore master/detail filter
		$this->sDbMasterFilter = $pv_deltron->getMasterFilter(); // Restore master filter
		$this->sDbDetailFilter = $pv_deltron->getDetailFilter(); // Restore detail filter
		if ($this->sDbDetailFilter <> "")
			$sFilter = ($sFilter <> "") ? "($sFilter) AND (" . $this->sDbDetailFilter . ")" : $this->sDbDetailFilter;
		if ($this->sSrchWhere <> "")
			$sFilter = ($sFilter <> "") ? "($sFilter) AND (". $this->sSrchWhere . ")" : $this->sSrchWhere;

		// Load master record
		if ($pv_deltron->getMasterFilter() <> "" && $pv_deltron->getCurrentMasterTable() == "pv_deltron_cat") {
			global $pv_deltron_cat;
			$rsmaster = $pv_deltron_cat->LoadRs($this->sDbMasterFilter);
			$this->bMasterRecordExists = ($rsmaster && !$rsmaster->EOF);
			if (!$this->bMasterRecordExists) {
				$pv_deltron->setMasterFilter(""); // Clear master filter
				$pv_deltron->setDetailFilter(""); // Clear detail filter
				$this->setMessage("No se encontraron registros"); // Set no record found
				$this->Page_Terminate($pv_deltron->getReturnUrl()); // Return to caller
			} else {
				$pv_deltron_cat->LoadListRowValues($rsmaster);
				$pv_deltron_cat->RowType = EW_ROWTYPE_MASTER; // Master row
				$pv_deltron_cat->RenderListRow();
				$rsmaster->Close();
			}
		}

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

		// Export data only
		if (in_array($pv_deltron->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;
		$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->setRecordsPerPage($this->lDisplayRecs); // Save to Session

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

	// Return Basic Search sql
	function BasicSearchSQL($Keyword) {
		global $pv_deltron;
		$sKeyword = ew_AdjustSql($Keyword);
		$sql = "";
		$sql .= $pv_deltron->categoria->FldExpression . " LIKE '%" . $sKeyword . "%' OR ";
		$sql .= $pv_deltron->codigo->FldExpression . " LIKE '%" . $sKeyword . "%' OR ";
		$sql .= $pv_deltron->nombre->FldExpression . " LIKE '%" . $sKeyword . "%' OR ";
		$sql .= $pv_deltron->garantia->FldExpression . " LIKE '%" . $sKeyword . "%' OR ";
		$sql .= $pv_deltron->marca->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;
		$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->setBasicSearchKeyword($sSearchKeyword);
			$pv_deltron->setBasicSearchType($sSearchType);
		}
		return $sSearchStr;
	}

	// Clear all search parameters
	function ResetSearchParms() {

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

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

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

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

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

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

		// Check for an Order parameter
		if (@$_GET["order"] <> "") {
			$pv_deltron->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
			$pv_deltron->CurrentOrderType = @$_GET["ordertype"];
			$pv_deltron->UpdateSort($pv_deltron->categoria); // Field 
			$pv_deltron->UpdateSort($pv_deltron->codigo); // Field 
			$pv_deltron->UpdateSort($pv_deltron->nombre); // Field 
			$pv_deltron->UpdateSort($pv_deltron->stockDT); // Field 
			$pv_deltron->UpdateSort($pv_deltron->prDT); // Field 
			$pv_deltron->UpdateSort($pv_deltron->precio_s); // Field 
			$pv_deltron->UpdateSort($pv_deltron->garantia); // Field 
			$pv_deltron->UpdateSort($pv_deltron->marca); // Field 
			$pv_deltron->setStartRecordNumber(1); // Reset start position
		}
	}

	// Load Sort Order parameters
	function LoadSortOrder() {
		global $pv_deltron;
		$sOrderBy = $pv_deltron->getSessionOrderBy(); // Get order by from Session
		if ($sOrderBy == "") {
			if ($pv_deltron->SqlOrderBy() <> "") {
				$sOrderBy = $pv_deltron->SqlOrderBy();
				$pv_deltron->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;

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

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

			// Reset master/detail keys
			if (strtolower($sCmd) == "resetall") {
				$pv_deltron->getCurrentMasterTable = ""; // Clear master table
				$pv_deltron->setMasterFilter(""); // Clear master filter
				$this->sDbMasterFilter = "";
				$pv_deltron->setDetailFilter(""); // Clear detail filter
				$this->sDbDetailFilter = "";
				$pv_deltron->categoria->setSessionValue("");
			}

			// Reset sort criteria
			if (strtolower($sCmd) == "resetsort") {
				$sOrderBy = "";
				$pv_deltron->setSessionOrderBy($sOrderBy);
				$pv_deltron->categoria->setSort("");
				$pv_deltron->codigo->setSort("");
				$pv_deltron->nombre->setSort("");
				$pv_deltron->stockDT->setSort("");
				$pv_deltron->prDT->setSort("");
				$pv_deltron->precio_s->setSort("");
				$pv_deltron->garantia->setSort("");
				$pv_deltron->marca->setSort("");
			}

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

	// Set up Starting Record parameters based on Pager Navigation
	function SetUpStartRec() {
		global $pv_deltron;
		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->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->setStartRecordNumber($this->lStartRec);
				}
			}
		}
		$this->lStartRec = $pv_deltron->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->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->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->setStartRecordNumber($this->lStartRec);
		}
	}

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

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

		// Load list page SQL
		$sSql = $pv_deltron->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->Recordset_Selected($rs);
		return $rs;
	}

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

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

		// Load sql based on filter
		$pv_deltron->CurrentFilter = $sFilter;
		$sSql = $pv_deltron->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->Row_Selected($rs);
			}
			$rs->Close();
		} else {
			$LoadRow = FALSE;
		}
		return $LoadRow;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $pv_deltron;
		$pv_deltron->categoria->setDbValue($rs->fields('categoria'));
		$pv_deltron->codigo->setDbValue($rs->fields('codigo'));
		$pv_deltron->nombre->setDbValue($rs->fields('nombre'));
		$pv_deltron->stockDT->setDbValue($rs->fields('stockDT'));
		$pv_deltron->prDT->setDbValue($rs->fields('prDT'));
		$pv_deltron->precio_s->setDbValue($rs->fields('precio_s'));
		$pv_deltron->garantia->setDbValue($rs->fields('garantia'));
		$pv_deltron->marca->setDbValue($rs->fields('marca'));
	}

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

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

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

		$pv_deltron->categoria->CellCssStyle = "";
		$pv_deltron->categoria->CellCssClass = "";

		// codigo
		$pv_deltron->codigo->CellCssStyle = "";
		$pv_deltron->codigo->CellCssClass = "";

		// nombre
		$pv_deltron->nombre->CellCssStyle = "";
		$pv_deltron->nombre->CellCssClass = "";

		// stockDT
		$pv_deltron->stockDT->CellCssStyle = "";
		$pv_deltron->stockDT->CellCssClass = "";

		// prDT
		$pv_deltron->prDT->CellCssStyle = "";
		$pv_deltron->prDT->CellCssClass = "";

		// precio_s
		$pv_deltron->precio_s->CellCssStyle = "";
		$pv_deltron->precio_s->CellCssClass = "";

		// garantia
		$pv_deltron->garantia->CellCssStyle = "";
		$pv_deltron->garantia->CellCssClass = "";

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

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

			// codigo
			$pv_deltron->codigo->ViewValue = $pv_deltron->codigo->CurrentValue;
			$pv_deltron->codigo->CssStyle = "";
			$pv_deltron->codigo->CssClass = "";
			$pv_deltron->codigo->ViewCustomAttributes = "";

			// nombre
			$pv_deltron->nombre->ViewValue = $pv_deltron->nombre->CurrentValue;
			$pv_deltron->nombre->CssStyle = "";
			$pv_deltron->nombre->CssClass = "";
			$pv_deltron->nombre->ViewCustomAttributes = "";

			// stockDT
			$pv_deltron->stockDT->ViewValue = $pv_deltron->stockDT->CurrentValue;
			$pv_deltron->stockDT->CssStyle = "";
			$pv_deltron->stockDT->CssClass = "";
			$pv_deltron->stockDT->ViewCustomAttributes = "";

			// prDT
			$pv_deltron->prDT->ViewValue = $pv_deltron->prDT->CurrentValue;
			$pv_deltron->prDT->CssStyle = "";
			$pv_deltron->prDT->CssClass = "";
			$pv_deltron->prDT->ViewCustomAttributes = "";

			// precio_s
			$pv_deltron->precio_s->ViewValue = $pv_deltron->precio_s->CurrentValue;
			$pv_deltron->precio_s->CssStyle = "";
			$pv_deltron->precio_s->CssClass = "";
			$pv_deltron->precio_s->ViewCustomAttributes = "";

			// garantia
			$pv_deltron->garantia->ViewValue = $pv_deltron->garantia->CurrentValue;
			$pv_deltron->garantia->CssStyle = "";
			$pv_deltron->garantia->CssClass = "";
			$pv_deltron->garantia->ViewCustomAttributes = "";

			// marca
			$pv_deltron->marca->ViewValue = $pv_deltron->marca->CurrentValue;
			$pv_deltron->marca->CssStyle = "";
			$pv_deltron->marca->CssClass = "";
			$pv_deltron->marca->ViewCustomAttributes = "";

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

			// codigo
			if (!is_null($pv_deltron->codigo->CurrentValue)) {
				$pv_deltron->codigo->HrefValue = ((!empty($pv_deltron->codigo->ViewValue)) ? $pv_deltron->codigo->ViewValue : $pv_deltron->codigo->CurrentValue);
				if ($pv_deltron->Export <> "") $pv_deltron->codigo->HrefValue = ew_ConvertFullUrl($pv_deltron->codigo->HrefValue);
			} else {
				$pv_deltron->codigo->HrefValue = "";
			}

			// nombre
			$pv_deltron->nombre->HrefValue = "";

			// stockDT
			$pv_deltron->stockDT->HrefValue = "";

			// prDT
			$pv_deltron->prDT->HrefValue = "";

			// precio_s
			$pv_deltron->precio_s->HrefValue = "";

			// garantia
			$pv_deltron->garantia->HrefValue = "";

			// marca
			$pv_deltron->marca->HrefValue = "";
		}

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

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

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

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

		// Export all
		if ($pv_deltron->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->Export == "xml") {
			$XmlDoc = new cXMLDocument();
		} else {
			echo ew_ExportHeader($pv_deltron->Export);

			// Horizontal format, write header
			if ($sExportStyle <> "v" || $pv_deltron->Export == "csv") {
				$sExportStr = "";
				ew_ExportAddValue($sExportStr, 'categoria', $pv_deltron->Export);
				ew_ExportAddValue($sExportStr, 'codigo', $pv_deltron->Export);
				ew_ExportAddValue($sExportStr, 'nombre', $pv_deltron->Export);
				ew_ExportAddValue($sExportStr, 'stockDT', $pv_deltron->Export);
				ew_ExportAddValue($sExportStr, 'prDT', $pv_deltron->Export);
				ew_ExportAddValue($sExportStr, 'precio_s', $pv_deltron->Export);
				ew_ExportAddValue($sExportStr, 'garantia', $pv_deltron->Export);
				ew_ExportAddValue($sExportStr, 'marca', $pv_deltron->Export);
				echo ew_ExportLine($sExportStr, $pv_deltron->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->RowType = EW_ROWTYPE_VIEW; // Render view
				$this->RenderRow();
				if ($pv_deltron->Export == "xml") {
					$XmlDoc->BeginRow();
					$XmlDoc->AddField('categoria', $pv_deltron->categoria->CurrentValue);
					$XmlDoc->AddField('codigo', $pv_deltron->codigo->CurrentValue);
					$XmlDoc->AddField('nombre', $pv_deltron->nombre->CurrentValue);
					$XmlDoc->AddField('stockDT', $pv_deltron->stockDT->CurrentValue);
					$XmlDoc->AddField('prDT', $pv_deltron->prDT->CurrentValue);
					$XmlDoc->AddField('precio_s', $pv_deltron->precio_s->CurrentValue);
					$XmlDoc->AddField('garantia', $pv_deltron->garantia->CurrentValue);
					$XmlDoc->AddField('marca', $pv_deltron->marca->CurrentValue);
					$XmlDoc->EndRow();
				} else {
					if ($sExportStyle == "v" && $pv_deltron->Export <> "csv") { // Vertical format
						echo ew_ExportField('categoria', $pv_deltron->categoria->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportField('codigo', $pv_deltron->codigo->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportField('nombre', $pv_deltron->nombre->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportField('stockDT', $pv_deltron->stockDT->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportField('prDT', $pv_deltron->prDT->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportField('precio_s', $pv_deltron->precio_s->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportField('garantia', $pv_deltron->garantia->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportField('marca', $pv_deltron->marca->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
					}	else { // Horizontal format
						$sExportStr = "";
						ew_ExportAddValue($sExportStr, $pv_deltron->categoria->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron->codigo->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron->nombre->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron->stockDT->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron->prDT->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron->precio_s->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron->garantia->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						ew_ExportAddValue($sExportStr, $pv_deltron->marca->ExportValue($pv_deltron->Export, $pv_deltron->ExportOriginalValue), $pv_deltron->Export);
						echo ew_ExportLine($sExportStr, $pv_deltron->Export);
					}
				}
			}
			$rs->MoveNext();
		}

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

	// Set up Master Detail based on querystring parameter
	function SetUpMasterDetail() {
		global $pv_deltron;
		$bValidMaster = FALSE;

		// Get the keys for master table
		if (@$_GET[EW_TABLE_SHOW_MASTER] <> "") {
			$sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER];
			if ($sMasterTblVar == "") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = "";
				$this->sDbDetailFilter = "";
			}
			if ($sMasterTblVar == "pv_deltron_cat") {
				$bValidMaster = TRUE;
				$this->sDbMasterFilter = $pv_deltron->SqlMasterFilter_pv_deltron_cat();
				$this->sDbDetailFilter = $pv_deltron->SqlDetailFilter_pv_deltron_cat();
				if (@$_GET["categoria"] <> "") {
					$GLOBALS["pv_deltron_cat"]->categoria->setQueryStringValue($_GET["categoria"]);
					$pv_deltron->categoria->setQueryStringValue($GLOBALS["pv_deltron_cat"]->categoria->QueryStringValue);
					$pv_deltron->categoria->setSessionValue($pv_deltron->categoria->QueryStringValue);
					$this->sDbMasterFilter = str_replace("@categoria@", ew_AdjustSql($GLOBALS["pv_deltron_cat"]->categoria->QueryStringValue), $this->sDbMasterFilter);
					$this->sDbDetailFilter = str_replace("@categoria@", ew_AdjustSql($GLOBALS["pv_deltron_cat"]->categoria->QueryStringValue), $this->sDbDetailFilter);
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

			// Save current master table
			$pv_deltron->setCurrentMasterTable($sMasterTblVar);

			// Reset start record counter (new master key)
			$this->lStartRec = 1;
			$pv_deltron->setStartRecordNumber($this->lStartRec);
			$pv_deltron->setMasterFilter($this->sDbMasterFilter); // Set up master filter
			$pv_deltron->setDetailFilter($this->sDbDetailFilter); // Set up detail filter

			// Clear previous master session values
			if ($sMasterTblVar <> "pv_deltron_cat") {
				if ($pv_deltron->categoria->QueryStringValue == "") $pv_deltron->categoria->setSessionValue("");
			}
		} else {
			$this->sDbMasterFilter = $pv_deltron->getMasterFilter(); //  Restore master filter
			$this->sDbDetailFilter = $pv_deltron->getDetailFilter(); // Restore detail filter
		}
	}

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