PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/cuentalist.php

https://github.com/fredd-for/emaus_tesoreria
PHP | 922 lines | 693 code | 105 blank | 124 comment | 187 complexity | 11f7868383ef6b57efae4853380060c4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. session_start(); // Initialize session data
  3. ob_start(); // Turn on output buffering
  4. ?>
  5. <?php include "ewcfg6.php" ?>
  6. <?php include "ewmysql6.php" ?>
  7. <?php include "phpfn6.php" ?>
  8. <?php include "cuentainfo.php" ?>
  9. <?php include "usuarioinfo.php" ?>
  10. <?php include "userfn6.php" ?>
  11. <?php
  12. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  13. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
  14. header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
  15. header("Cache-Control: post-check=0, pre-check=0", false);
  16. header("Pragma: no-cache"); // HTTP/1.0
  17. ?>
  18. <?php
  19. // Define page object
  20. $cuenta_list = new ccuenta_list();
  21. $Page =& $cuenta_list;
  22. // Page init processing
  23. $cuenta_list->Page_Init();
  24. // Page main processing
  25. $cuenta_list->Page_Main();
  26. ?>
  27. <?php include "header.php" ?>
  28. <?php if ($cuenta->Export == "") { ?>
  29. <script type="text/javascript">
  30. <!--
  31. // Create page object
  32. var cuenta_list = new ew_Page("cuenta_list");
  33. // page properties
  34. cuenta_list.PageID = "list"; // page ID
  35. var EW_PAGE_ID = cuenta_list.PageID; // for backward compatibility
  36. // extend page with Form_CustomValidate function
  37. cuenta_list.Form_CustomValidate =
  38. function(fobj) { // DO NOT CHANGE THIS LINE!
  39. // Your custom validation code here, return false if invalid.
  40. return true;
  41. }
  42. <?php if (EW_CLIENT_VALIDATE) { ?>
  43. cuenta_list.ValidateRequired = true; // uses JavaScript validation
  44. <?php } else { ?>
  45. cuenta_list.ValidateRequired = false; // no JavaScript validation
  46. <?php } ?>
  47. //-->
  48. </script>
  49. <script language="JavaScript" type="text/javascript">
  50. <!--
  51. // Write your client script here, no need to add script tags.
  52. // To include another .js script, use:
  53. // ew_ClientScriptInclude("my_javascript.js");
  54. //-->
  55. </script>
  56. <?php } ?>
  57. <?php if ($cuenta->Export == "") { ?>
  58. <?php } ?>
  59. <?php
  60. $bSelectLimit = ($cuenta->Export == "" && $cuenta->SelectLimit);
  61. if (!$bSelectLimit)
  62. $rs = $cuenta_list->LoadRecordset();
  63. $cuenta_list->lTotalRecs = ($bSelectLimit) ? $cuenta->SelectRecordCount() : $rs->RecordCount();
  64. $cuenta_list->lStartRec = 1;
  65. if ($cuenta_list->lDisplayRecs <= 0) // Display all records
  66. $cuenta_list->lDisplayRecs = $cuenta_list->lTotalRecs;
  67. if (!($cuenta->ExportAll && $cuenta->Export <> ""))
  68. $cuenta_list->SetUpStartRec(); // Set up start record position
  69. if ($bSelectLimit)
  70. $rs = $cuenta_list->LoadRecordset($cuenta_list->lStartRec-1, $cuenta_list->lDisplayRecs);
  71. ?>
  72. <p><span class="phpmaker" style="white-space: nowrap;">TABLA: Cuenta
  73. <?php if ($cuenta->Export == "" && $cuenta->CurrentAction == "") { ?>
  74. &nbsp;&nbsp;<a href="<?php echo $cuenta_list->PageUrl() ?>export=excel">Exportar a Excel</a>
  75. <?php } ?>
  76. </span></p>
  77. <?php $cuenta_list->ShowMessage() ?>
  78. <br>
  79. <table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
  80. <div class="ewGridMiddlePanel">
  81. <form name="fcuentalist" id="fcuentalist" class="ewForm" action="" method="post">
  82. <?php if ($cuenta_list->lTotalRecs > 0) { ?>
  83. <table cellspacing="0" rowhighlightclass="ewTableHighlightRow" rowselectclass="ewTableSelectRow" roweditclass="ewTableEditRow" class="ewTable ewTableSeparate">
  84. <?php
  85. $cuenta_list->lOptionCnt = 0;
  86. if ($Security->CanView()) {
  87. $cuenta_list->lOptionCnt++; // view
  88. }
  89. if ($Security->CanEdit()) {
  90. $cuenta_list->lOptionCnt++; // edit
  91. }
  92. if ($Security->CanDelete()) {
  93. $cuenta_list->lOptionCnt++; // Delete
  94. }
  95. $cuenta_list->lOptionCnt += count($cuenta_list->ListOptions->Items); // Custom list options
  96. ?>
  97. <?php echo $cuenta->TableCustomInnerHtml ?>
  98. <thead><!-- Table header -->
  99. <tr class="ewTableHeader">
  100. <?php if ($cuenta->idCuenta->Visible) { // idCuenta ?>
  101. <?php if ($cuenta->SortUrl($cuenta->idCuenta) == "") { ?>
  102. <td>Nro</td>
  103. <?php } else { ?>
  104. <td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $cuenta->SortUrl($cuenta->idCuenta) ?>',1);">
  105. <table cellspacing="0" class="ewTableHeaderBtn"><tr><td>Nro</td><td style="width: 10px;"><?php if ($cuenta->idCuenta->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($cuenta->idCuenta->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
  106. </td>
  107. <?php } ?>
  108. <?php } ?>
  109. <?php if ($cuenta->cuenta->Visible) { // cuenta ?>
  110. <?php if ($cuenta->SortUrl($cuenta->cuenta) == "") { ?>
  111. <td>Cuenta</td>
  112. <?php } else { ?>
  113. <td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $cuenta->SortUrl($cuenta->cuenta) ?>',1);">
  114. <table cellspacing="0" class="ewTableHeaderBtn"><tr><td>Cuenta</td><td style="width: 10px;"><?php if ($cuenta->cuenta->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($cuenta->cuenta->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
  115. </td>
  116. <?php } ?>
  117. <?php } ?>
  118. <?php if ($cuenta->porcentaje->Visible) { // porcentaje ?>
  119. <?php if ($cuenta->SortUrl($cuenta->porcentaje) == "") { ?>
  120. <td>Porcentaje</td>
  121. <?php } else { ?>
  122. <td class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $cuenta->SortUrl($cuenta->porcentaje) ?>',1);">
  123. <table cellspacing="0" class="ewTableHeaderBtn"><tr><td>Porcentaje</td><td style="width: 10px;"><?php if ($cuenta->porcentaje->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($cuenta->porcentaje->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></table>
  124. </td>
  125. <?php } ?>
  126. <?php } ?>
  127. <?php if ($cuenta->Export == "") { ?>
  128. <?php if ($Security->CanView()) { ?>
  129. <td style="white-space: nowrap;">&nbsp;</td>
  130. <?php } ?>
  131. <?php if ($Security->CanEdit()) { ?>
  132. <td style="white-space: nowrap;">&nbsp;</td>
  133. <?php } ?>
  134. <?php if ($Security->CanDelete()) { ?>
  135. <td style="white-space: nowrap;">&nbsp;</td>
  136. <?php } ?>
  137. <?php
  138. // Custom list options
  139. foreach ($cuenta_list->ListOptions->Items as $ListOption) {
  140. if ($ListOption->Visible)
  141. echo $ListOption->HeaderCellHtml;
  142. }
  143. ?>
  144. <?php } ?>
  145. </tr>
  146. </thead>
  147. <?php
  148. if ($cuenta->ExportAll && $cuenta->Export <> "") {
  149. $cuenta_list->lStopRec = $cuenta_list->lTotalRecs;
  150. } else {
  151. $cuenta_list->lStopRec = $cuenta_list->lStartRec + $cuenta_list->lDisplayRecs - 1; // Set the last record to display
  152. }
  153. $cuenta_list->lRecCount = $cuenta_list->lStartRec - 1;
  154. if ($rs && !$rs->EOF) {
  155. $rs->MoveFirst();
  156. if (!$cuenta->SelectLimit && $cuenta_list->lStartRec > 1)
  157. $rs->Move($cuenta_list->lStartRec - 1);
  158. }
  159. $cuenta_list->lRowCnt = 0;
  160. while (($cuenta->CurrentAction == "gridadd" || !$rs->EOF) &&
  161. $cuenta_list->lRecCount < $cuenta_list->lStopRec) {
  162. $cuenta_list->lRecCount++;
  163. if (intval($cuenta_list->lRecCount) >= intval($cuenta_list->lStartRec)) {
  164. $cuenta_list->lRowCnt++;
  165. // Init row class and style
  166. $cuenta->CssClass = "";
  167. $cuenta->CssStyle = "";
  168. $cuenta->RowClientEvents = "onmouseover='ew_MouseOver(event, this);' onmouseout='ew_MouseOut(event, this);' onclick='ew_Click(event, this);'";
  169. if ($cuenta->CurrentAction == "gridadd") {
  170. $cuenta_list->LoadDefaultValues(); // Load default values
  171. } else {
  172. $cuenta_list->LoadRowValues($rs); // Load row values
  173. }
  174. $cuenta->RowType = EW_ROWTYPE_VIEW; // Render view
  175. // Render row
  176. $cuenta_list->RenderRow();
  177. ?>
  178. <tr<?php echo $cuenta->RowAttributes() ?>>
  179. <?php if ($cuenta->idCuenta->Visible) { // idCuenta ?>
  180. <td<?php echo $cuenta->idCuenta->CellAttributes() ?>>
  181. <div<?php echo $cuenta->idCuenta->ViewAttributes() ?>><?php echo $cuenta->idCuenta->ListViewValue() ?></div>
  182. </td>
  183. <?php } ?>
  184. <?php if ($cuenta->cuenta->Visible) { // cuenta ?>
  185. <td<?php echo $cuenta->cuenta->CellAttributes() ?>>
  186. <div<?php echo $cuenta->cuenta->ViewAttributes() ?>><?php echo $cuenta->cuenta->ListViewValue() ?></div>
  187. </td>
  188. <?php } ?>
  189. <?php if ($cuenta->porcentaje->Visible) { // porcentaje ?>
  190. <td<?php echo $cuenta->porcentaje->CellAttributes() ?>>
  191. <div<?php echo $cuenta->porcentaje->ViewAttributes() ?>><?php echo $cuenta->porcentaje->ListViewValue() ?></div>
  192. </td>
  193. <?php } ?>
  194. <?php if ($cuenta->Export == "") { ?>
  195. <?php if ($Security->CanView()) { ?>
  196. <td style="white-space: nowrap;"><span class="phpmaker">
  197. <a href="<?php echo $cuenta->ViewUrl() ?>">Ver</a>
  198. </span></td>
  199. <?php } ?>
  200. <?php if ($Security->CanEdit()) { ?>
  201. <td style="white-space: nowrap;"><span class="phpmaker">
  202. <a href="<?php echo $cuenta->EditUrl() ?>">Editar</a>
  203. </span></td>
  204. <?php } ?>
  205. <?php if ($Security->CanDelete()) { ?>
  206. <td style="white-space: nowrap;"><span class="phpmaker">
  207. <a onclick="ew_ClickDelete(this);return ew_ConfirmDelete('<?php echo $cuenta_list->sDeleteConfirmMsg ?>', this);" href="<?php echo $cuenta->DeleteUrl() ?>">Borrar</a>
  208. </span></td>
  209. <?php } ?>
  210. <?php
  211. // Custom list options
  212. foreach ($cuenta_list->ListOptions->Items as $ListOption) {
  213. if ($ListOption->Visible)
  214. echo $ListOption->BodyCellHtml;
  215. }
  216. ?>
  217. <?php } ?>
  218. </tr>
  219. <?php
  220. }
  221. if ($cuenta->CurrentAction <> "gridadd")
  222. $rs->MoveNext();
  223. }
  224. ?>
  225. </tbody>
  226. </table>
  227. <?php } ?>
  228. </form>
  229. <?php
  230. // Close recordset
  231. if ($rs)
  232. $rs->Close();
  233. ?>
  234. </div>
  235. <?php if ($cuenta->Export == "") { ?>
  236. <div class="ewGridLowerPanel">
  237. <?php if ($cuenta->CurrentAction <> "gridadd" && $cuenta->CurrentAction <> "gridedit") { ?>
  238. <form name="ewpagerform" id="ewpagerform" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
  239. <table border="0" cellspacing="0" cellpadding="0" class="ewPager">
  240. <tr>
  241. <td nowrap>
  242. <?php if (!isset($cuenta_list->Pager)) $cuenta_list->Pager = new cPrevNextPager($cuenta_list->lStartRec, $cuenta_list->lDisplayRecs, $cuenta_list->lTotalRecs) ?>
  243. <?php if ($cuenta_list->Pager->RecordCount > 0) { ?>
  244. <table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpmaker">Página&nbsp;</span></td>
  245. <!--first page button-->
  246. <?php if ($cuenta_list->Pager->FirstButton->Enabled) { ?>
  247. <td><a href="<?php echo $cuenta_list->PageUrl() ?>start=<?php echo $cuenta_list->Pager->FirstButton->Start ?>"><img src="images/first.gif" alt="Primera" width="16" height="16" border="0"></a></td>
  248. <?php } else { ?>
  249. <td><img src="images/firstdisab.gif" alt="Primera" width="16" height="16" border="0"></td>
  250. <?php } ?>
  251. <!--previous page button-->
  252. <?php if ($cuenta_list->Pager->PrevButton->Enabled) { ?>
  253. <td><a href="<?php echo $cuenta_list->PageUrl() ?>start=<?php echo $cuenta_list->Pager->PrevButton->Start ?>"><img src="images/prev.gif" alt="Anterior" width="16" height="16" border="0"></a></td>
  254. <?php } else { ?>
  255. <td><img src="images/prevdisab.gif" alt="Anterior" width="16" height="16" border="0"></td>
  256. <?php } ?>
  257. <!--current page number-->
  258. <td><input type="text" name="<?php echo EW_TABLE_PAGE_NO ?>" id="<?php echo EW_TABLE_PAGE_NO ?>" value="<?php echo $cuenta_list->Pager->CurrentPage ?>" size="4"></td>
  259. <!--next page button-->
  260. <?php if ($cuenta_list->Pager->NextButton->Enabled) { ?>
  261. <td><a href="<?php echo $cuenta_list->PageUrl() ?>start=<?php echo $cuenta_list->Pager->NextButton->Start ?>"><img src="images/next.gif" alt="Siguiente" width="16" height="16" border="0"></a></td>
  262. <?php } else { ?>
  263. <td><img src="images/nextdisab.gif" alt="Siguiente" width="16" height="16" border="0"></td>
  264. <?php } ?>
  265. <!--last page button-->
  266. <?php if ($cuenta_list->Pager->LastButton->Enabled) { ?>
  267. <td><a href="<?php echo $cuenta_list->PageUrl() ?>start=<?php echo $cuenta_list->Pager->LastButton->Start ?>"><img src="images/last.gif" alt="Ultima" width="16" height="16" border="0"></a></td>
  268. <?php } else { ?>
  269. <td><img src="images/lastdisab.gif" alt="Ultima" width="16" height="16" border="0"></td>
  270. <?php } ?>
  271. <td><span class="phpmaker">&nbsp;de <?php echo $cuenta_list->Pager->PageCount ?></span></td>
  272. </tr></table>
  273. </td>
  274. <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  275. <td>
  276. <span class="phpmaker">Registro <?php echo $cuenta_list->Pager->FromIndex ?> a <?php echo $cuenta_list->Pager->ToIndex ?> de <?php echo $cuenta_list->Pager->RecordCount ?></span>
  277. <?php } else { ?>
  278. <?php if ($Security->CanList()) { ?>
  279. <?php if ($cuenta_list->sSrchWhere == "0=101") { ?>
  280. <span class="phpmaker">Por favor ingrese criterio de busqueda</span>
  281. <?php } else { ?>
  282. <span class="phpmaker">No se encontraron registros</span>
  283. <?php } ?>
  284. <?php } else { ?>
  285. <span class="phpmaker">No tiene permisos para consultar esta página</span>
  286. <?php } ?>
  287. <?php } ?>
  288. </td>
  289. <?php if ($cuenta_list->lTotalRecs > 0) { ?>
  290. <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  291. <td><table border="0" cellspacing="0" cellpadding="0"><tr><td>Registros por página&nbsp;</td><td>
  292. <input type="hidden" id="t" name="t" value="cuenta">
  293. <select name="<?php echo EW_TABLE_REC_PER_PAGE ?>" id="<?php echo EW_TABLE_REC_PER_PAGE ?>" onchange="this.form.submit();" class="phpmaker">
  294. <option value="20"<?php if ($cuenta_list->lDisplayRecs == 20) { ?> selected="selected"<?php } ?>>20</option>
  295. <option value="50"<?php if ($cuenta_list->lDisplayRecs == 50) { ?> selected="selected"<?php } ?>>50</option>
  296. <option value="ALL"<?php if ($cuenta->getRecordsPerPage() == -1) { ?> selected="selected"<?php } ?>>Todos los registros</option>
  297. </select></td></tr></table>
  298. </td>
  299. <?php } ?>
  300. </tr>
  301. </table>
  302. </form>
  303. <?php } ?>
  304. <?php //if ($cuenta_list->lTotalRecs > 0) { ?>
  305. <span class="phpmaker">
  306. <?php if ($Security->CanAdd()) { ?>
  307. <a href="<?php echo $cuenta->AddUrl() ?>">Agregar</a>&nbsp;&nbsp;
  308. <?php } ?>
  309. </span>
  310. <?php //} ?>
  311. </div>
  312. <?php } ?>
  313. </td></tr></table>
  314. <?php if ($cuenta->Export == "" && $cuenta->CurrentAction == "") { ?>
  315. <script type="text/javascript">
  316. <!--
  317. //ew_ToggleSearchPanel(cuenta_list); // uncomment to init search panel as collapsed
  318. //-->
  319. </script>
  320. <?php } ?>
  321. <?php if ($cuenta->Export == "") { ?>
  322. <script language="JavaScript" type="text/javascript">
  323. <!--
  324. // Write your table-specific startup script here
  325. // document.write("page loaded");
  326. //-->
  327. </script>
  328. <?php } ?>
  329. <?php include "footer.php" ?>
  330. <?php
  331. //
  332. // Page Class
  333. //
  334. class ccuenta_list {
  335. // Page ID
  336. var $PageID = 'list';
  337. // Table Name
  338. var $TableName = 'cuenta';
  339. // Page Object Name
  340. var $PageObjName = 'cuenta_list';
  341. // Page Name
  342. function PageName() {
  343. return ew_CurrentPage();
  344. }
  345. // Page Url
  346. function PageUrl() {
  347. $PageUrl = ew_CurrentPage() . "?";
  348. global $cuenta;
  349. if ($cuenta->UseTokenInUrl) $PageUrl .= "t=" . $cuenta->TableVar . "&"; // add page token
  350. return $PageUrl;
  351. }
  352. // Message
  353. function getMessage() {
  354. return @$_SESSION[EW_SESSION_MESSAGE];
  355. }
  356. function setMessage($v) {
  357. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
  358. $_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
  359. } else {
  360. $_SESSION[EW_SESSION_MESSAGE] = $v;
  361. }
  362. }
  363. // Show Message
  364. function ShowMessage() {
  365. if ($this->getMessage() <> "") { // Message in Session, display
  366. echo "<p><span class=\"ewMessage\">" . $this->getMessage() . "</span></p>";
  367. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
  368. }
  369. }
  370. // Validate Page request
  371. function IsPageRequest() {
  372. global $objForm, $cuenta;
  373. if ($cuenta->UseTokenInUrl) {
  374. //IsPageRequest = False
  375. if ($objForm)
  376. return ($cuenta->TableVar == $objForm->GetValue("t"));
  377. if (@$_GET["t"] <> "")
  378. return ($cuenta->TableVar == $_GET["t"]);
  379. } else {
  380. return TRUE;
  381. }
  382. }
  383. //
  384. // Class initialize
  385. // - init objects
  386. // - open connection
  387. //
  388. function ccuenta_list() {
  389. global $conn;
  390. // Initialize table object
  391. $GLOBALS["cuenta"] = new ccuenta();
  392. // Initialize other table object
  393. $GLOBALS['usuario'] = new cusuario();
  394. // Intialize page id (for backward compatibility)
  395. if (!defined("EW_PAGE_ID"))
  396. define("EW_PAGE_ID", 'list', TRUE);
  397. // Initialize table name (for backward compatibility)
  398. if (!defined("EW_TABLE_NAME"))
  399. define("EW_TABLE_NAME", 'cuenta', TRUE);
  400. // Open connection to the database
  401. $conn = ew_Connect();
  402. // Initialize list options
  403. $this->ListOptions = new cListOptions();
  404. }
  405. //
  406. // Page_Init
  407. //
  408. function Page_Init() {
  409. global $gsExport, $gsExportFile, $cuenta;
  410. global $Security;
  411. $Security = new cAdvancedSecurity();
  412. if (!$Security->IsLoggedIn()) $Security->AutoLogin();
  413. if (!$Security->IsLoggedIn()) {
  414. $Security->SaveLastUrl();
  415. $this->Page_Terminate("login.php");
  416. }
  417. $Security->TablePermission_Loading();
  418. $Security->LoadCurrentUserLevel($this->TableName);
  419. $Security->TablePermission_Loaded();
  420. if (!$Security->IsLoggedIn()) {
  421. $Security->SaveLastUrl();
  422. $this->Page_Terminate("login.php");
  423. }
  424. if (!$Security->CanList()) {
  425. $Security->SaveLastUrl();
  426. $this->Page_Terminate("login.php");
  427. }
  428. $cuenta->Export = @$_GET["export"]; // Get export parameter
  429. $gsExport = $cuenta->Export; // Get export parameter, used in header
  430. $gsExportFile = $cuenta->TableVar; // Get export file, used in header
  431. if ($cuenta->Export == "excel") {
  432. header('Content-Type: application/vnd.ms-excel');
  433. header('Content-Disposition: attachment; filename=' . $gsExportFile .'.xls');
  434. }
  435. // Global page loading event (in userfn6.php)
  436. Page_Loading();
  437. // Page load event, used in current page
  438. $this->Page_Load();
  439. }
  440. //
  441. // Page_Terminate
  442. // - called when exit page
  443. // - if URL specified, redirect to the URL
  444. //
  445. function Page_Terminate($url = "") {
  446. global $conn;
  447. // Page unload event, used in current page
  448. $this->Page_Unload();
  449. // Global page unloaded event (in userfn*.php)
  450. Page_Unloaded();
  451. // Close Connection
  452. $conn->Close();
  453. // Go to URL if specified
  454. if ($url <> "") {
  455. ob_end_clean();
  456. header("Location: $url");
  457. }
  458. exit();
  459. }
  460. var $lDisplayRecs; // Number of display records
  461. var $lStartRec;
  462. var $lStopRec;
  463. var $lTotalRecs;
  464. var $lRecRange;
  465. var $sSrchWhere;
  466. var $lRecCnt;
  467. var $lEditRowCnt;
  468. var $lRowCnt;
  469. var $lRowIndex;
  470. var $lOptionCnt;
  471. var $lRecPerRow;
  472. var $lColCnt;
  473. var $sDeleteConfirmMsg; // Delete confirm message
  474. var $sDbMasterFilter;
  475. var $sDbDetailFilter;
  476. var $bMasterRecordExists;
  477. var $ListOptions;
  478. var $sMultiSelectKey;
  479. //
  480. // Page main processing
  481. //
  482. function Page_Main() {
  483. global $objForm, $gsSearchError, $Security, $cuenta;
  484. $this->lDisplayRecs = 20;
  485. $this->lRecRange = 10;
  486. $this->lRecCnt = 0; // Record count
  487. // Search filters
  488. $sSrchAdvanced = ""; // Advanced search filter
  489. $sSrchBasic = ""; // Basic search filter
  490. $sFilter = "";
  491. $this->sSrchWhere = ""; // Search WHERE clause
  492. $this->sDeleteConfirmMsg = "żQuiere borrar este registro?"; // Delete confirm message
  493. // Master/Detail
  494. $this->sDbMasterFilter = ""; // Master filter
  495. $this->sDbDetailFilter = ""; // Detail filter
  496. if ($this->IsPageRequest()) { // Validate request
  497. // Set up records per page dynamically
  498. $this->SetUpDisplayRecs();
  499. // Handle reset command
  500. $this->ResetCmd();
  501. // Set Up Sorting Order
  502. $this->SetUpSortOrder();
  503. } // End Validate Request
  504. // Restore display records
  505. if ($cuenta->getRecordsPerPage() <> "") {
  506. $this->lDisplayRecs = $cuenta->getRecordsPerPage(); // Restore from Session
  507. } else {
  508. $this->lDisplayRecs = 20; // Load default
  509. }
  510. // Load Sorting Order
  511. $this->LoadSortOrder();
  512. // Build filter
  513. $sFilter = "";
  514. if (!$Security->CanList()) {
  515. $sFilter = "(0=1)"; // Filter all records
  516. }
  517. if ($this->sDbDetailFilter <> "")
  518. $sFilter = ($sFilter <> "") ? "($sFilter) AND (" . $this->sDbDetailFilter . ")" : $this->sDbDetailFilter;
  519. if ($this->sSrchWhere <> "")
  520. $sFilter = ($sFilter <> "") ? "($sFilter) AND (". $this->sSrchWhere . ")" : $this->sSrchWhere;
  521. // Set up filter in Session
  522. $cuenta->setSessionWhere($sFilter);
  523. $cuenta->CurrentFilter = "";
  524. // Export data only
  525. if (in_array($cuenta->Export, array("html","word","excel","xml","csv"))) {
  526. $this->ExportData();
  527. $this->Page_Terminate(); // Terminate response
  528. exit();
  529. }
  530. }
  531. // Set up number of records displayed per page
  532. function SetUpDisplayRecs() {
  533. global $cuenta;
  534. $sWrk = @$_GET[EW_TABLE_REC_PER_PAGE];
  535. if ($sWrk <> "") {
  536. if (is_numeric($sWrk)) {
  537. $this->lDisplayRecs = intval($sWrk);
  538. } else {
  539. if (strtolower($sWrk) == "all") { // Display all records
  540. $this->lDisplayRecs = -1;
  541. } else {
  542. $this->lDisplayRecs = 20; // Non-numeric, load default
  543. }
  544. }
  545. $cuenta->setRecordsPerPage($this->lDisplayRecs); // Save to Session
  546. // Reset start position
  547. $this->lStartRec = 1;
  548. $cuenta->setStartRecordNumber($this->lStartRec);
  549. }
  550. }
  551. // Set up Sort parameters based on Sort Links clicked
  552. function SetUpSortOrder() {
  553. global $cuenta;
  554. // Check for an Order parameter
  555. if (@$_GET["order"] <> "") {
  556. $cuenta->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
  557. $cuenta->CurrentOrderType = @$_GET["ordertype"];
  558. $cuenta->UpdateSort($cuenta->idCuenta); // Field
  559. $cuenta->UpdateSort($cuenta->cuenta); // Field
  560. $cuenta->UpdateSort($cuenta->porcentaje); // Field
  561. $cuenta->setStartRecordNumber(1); // Reset start position
  562. }
  563. }
  564. // Load Sort Order parameters
  565. function LoadSortOrder() {
  566. global $cuenta;
  567. $sOrderBy = $cuenta->getSessionOrderBy(); // Get order by from Session
  568. if ($sOrderBy == "") {
  569. if ($cuenta->SqlOrderBy() <> "") {
  570. $sOrderBy = $cuenta->SqlOrderBy();
  571. $cuenta->setSessionOrderBy($sOrderBy);
  572. }
  573. }
  574. }
  575. // Reset command based on querystring parameter cmd=
  576. // - RESET: reset search parameters
  577. // - RESETALL: reset search & master/detail parameters
  578. // - RESETSORT: reset sort parameters
  579. function ResetCmd() {
  580. global $cuenta;
  581. // Get reset cmd
  582. if (@$_GET["cmd"] <> "") {
  583. $sCmd = $_GET["cmd"];
  584. // Reset sort criteria
  585. if (strtolower($sCmd) == "resetsort") {
  586. $sOrderBy = "";
  587. $cuenta->setSessionOrderBy($sOrderBy);
  588. $cuenta->idCuenta->setSort("");
  589. $cuenta->cuenta->setSort("");
  590. $cuenta->porcentaje->setSort("");
  591. }
  592. // Reset start position
  593. $this->lStartRec = 1;
  594. $cuenta->setStartRecordNumber($this->lStartRec);
  595. }
  596. }
  597. // Set up Starting Record parameters based on Pager Navigation
  598. function SetUpStartRec() {
  599. global $cuenta;
  600. if ($this->lDisplayRecs == 0)
  601. return;
  602. if ($this->IsPageRequest()) { // Validate request
  603. if (@$_GET[EW_TABLE_START_REC] <> "") { // Check for "start" parameter
  604. $this->lStartRec = $_GET[EW_TABLE_START_REC];
  605. $cuenta->setStartRecordNumber($this->lStartRec);
  606. } elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
  607. $this->nPageNo = $_GET[EW_TABLE_PAGE_NO];
  608. if (is_numeric($this->nPageNo)) {
  609. $this->lStartRec = ($this->nPageNo-1)*$this->lDisplayRecs+1;
  610. if ($this->lStartRec <= 0) {
  611. $this->lStartRec = 1;
  612. } elseif ($this->lStartRec >= intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1) {
  613. $this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1;
  614. }
  615. $cuenta->setStartRecordNumber($this->lStartRec);
  616. }
  617. }
  618. }
  619. $this->lStartRec = $cuenta->getStartRecordNumber();
  620. // Check if correct start record counter
  621. if (!is_numeric($this->lStartRec) || $this->lStartRec == "") { // Avoid invalid start record counter
  622. $this->lStartRec = 1; // Reset start record counter
  623. $cuenta->setStartRecordNumber($this->lStartRec);
  624. } elseif (intval($this->lStartRec) > intval($this->lTotalRecs)) { // Avoid starting record > total records
  625. $this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to last page first record
  626. $cuenta->setStartRecordNumber($this->lStartRec);
  627. } elseif (($this->lStartRec-1) % $this->lDisplayRecs <> 0) {
  628. $this->lStartRec = intval(($this->lStartRec-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to page boundary
  629. $cuenta->setStartRecordNumber($this->lStartRec);
  630. }
  631. }
  632. // Load recordset
  633. function LoadRecordset($offset = -1, $rowcnt = -1) {
  634. global $conn, $cuenta;
  635. // Call Recordset Selecting event
  636. $cuenta->Recordset_Selecting($cuenta->CurrentFilter);
  637. // Load list page SQL
  638. $sSql = $cuenta->SelectSQL();
  639. if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";
  640. // Load recordset
  641. $conn->raiseErrorFn = 'ew_ErrorFn';
  642. $rs = $conn->Execute($sSql);
  643. $conn->raiseErrorFn = '';
  644. // Call Recordset Selected event
  645. $cuenta->Recordset_Selected($rs);
  646. return $rs;
  647. }
  648. // Load row based on key values
  649. function LoadRow() {
  650. global $conn, $Security, $cuenta;
  651. $sFilter = $cuenta->KeyFilter();
  652. // Call Row Selecting event
  653. $cuenta->Row_Selecting($sFilter);
  654. // Load sql based on filter
  655. $cuenta->CurrentFilter = $sFilter;
  656. $sSql = $cuenta->SQL();
  657. if ($rs = $conn->Execute($sSql)) {
  658. if ($rs->EOF) {
  659. $LoadRow = FALSE;
  660. } else {
  661. $LoadRow = TRUE;
  662. $rs->MoveFirst();
  663. $this->LoadRowValues($rs); // Load row values
  664. // Call Row Selected event
  665. $cuenta->Row_Selected($rs);
  666. }
  667. $rs->Close();
  668. } else {
  669. $LoadRow = FALSE;
  670. }
  671. return $LoadRow;
  672. }
  673. // Load row values from recordset
  674. function LoadRowValues(&$rs) {
  675. global $cuenta;
  676. $cuenta->idCuenta->setDbValue($rs->fields('idCuenta'));
  677. $cuenta->cuenta->setDbValue($rs->fields('cuenta'));
  678. $cuenta->porcentaje->setDbValue($rs->fields('porcentaje'));
  679. $cuenta->estado->setDbValue($rs->fields('estado'));
  680. $cuenta->fechaCreacion->setDbValue($rs->fields('fechaCreacion'));
  681. $cuenta->fechaModificacion->setDbValue($rs->fields('fechaModificacion'));
  682. }
  683. // Render row values based on field settings
  684. function RenderRow() {
  685. global $conn, $Security, $cuenta;
  686. // Call Row_Rendering event
  687. $cuenta->Row_Rendering();
  688. // Common render codes for all row types
  689. // idCuenta
  690. $cuenta->idCuenta->CellCssStyle = "";
  691. $cuenta->idCuenta->CellCssClass = "";
  692. // cuenta
  693. $cuenta->cuenta->CellCssStyle = "";
  694. $cuenta->cuenta->CellCssClass = "";
  695. // porcentaje
  696. $cuenta->porcentaje->CellCssStyle = "";
  697. $cuenta->porcentaje->CellCssClass = "";
  698. if ($cuenta->RowType == EW_ROWTYPE_VIEW) { // View row
  699. // idCuenta
  700. $cuenta->idCuenta->ViewValue = $cuenta->idCuenta->CurrentValue;
  701. $cuenta->idCuenta->CssStyle = "";
  702. $cuenta->idCuenta->CssClass = "";
  703. $cuenta->idCuenta->ViewCustomAttributes = "";
  704. // cuenta
  705. $cuenta->cuenta->ViewValue = $cuenta->cuenta->CurrentValue;
  706. $cuenta->cuenta->CssStyle = "";
  707. $cuenta->cuenta->CssClass = "";
  708. $cuenta->cuenta->ViewCustomAttributes = "";
  709. // porcentaje
  710. $cuenta->porcentaje->ViewValue = $cuenta->porcentaje->CurrentValue;
  711. $cuenta->porcentaje->CssStyle = "";
  712. $cuenta->porcentaje->CssClass = "";
  713. $cuenta->porcentaje->ViewCustomAttributes = "";
  714. // idCuenta
  715. $cuenta->idCuenta->HrefValue = "";
  716. // cuenta
  717. $cuenta->cuenta->HrefValue = "";
  718. // porcentaje
  719. $cuenta->porcentaje->HrefValue = "";
  720. }
  721. // Call Row Rendered event
  722. $cuenta->Row_Rendered();
  723. }
  724. // Export data in XML or CSV format
  725. function ExportData() {
  726. global $cuenta;
  727. $sCsvStr = "";
  728. // Default export style
  729. $sExportStyle = "h";
  730. // Load recordset
  731. $rs = $this->LoadRecordset();
  732. $this->lTotalRecs = $rs->RecordCount();
  733. $this->lStartRec = 1;
  734. // Export all
  735. if ($cuenta->ExportAll) {
  736. $this->lStopRec = $this->lTotalRecs;
  737. } else { // Export 1 page only
  738. $this->SetUpStartRec(); // Set up start record position
  739. // Set the last record to display
  740. if ($this->lDisplayRecs < 0) {
  741. $this->lStopRec = $this->lTotalRecs;
  742. } else {
  743. $this->lStopRec = $this->lStartRec + $this->lDisplayRecs - 1;
  744. }
  745. }
  746. if ($cuenta->Export == "xml") {
  747. $XmlDoc = new cXMLDocument();
  748. } else {
  749. echo ew_ExportHeader($cuenta->Export);
  750. // Horizontal format, write header
  751. if ($sExportStyle <> "v" || $cuenta->Export == "csv") {
  752. $sExportStr = "";
  753. ew_ExportAddValue($sExportStr, 'idCuenta', $cuenta->Export);
  754. ew_ExportAddValue($sExportStr, 'cuenta', $cuenta->Export);
  755. ew_ExportAddValue($sExportStr, 'porcentaje', $cuenta->Export);
  756. echo ew_ExportLine($sExportStr, $cuenta->Export);
  757. }
  758. }
  759. // Move to first record
  760. $this->lRecCnt = $this->lStartRec - 1;
  761. if (!$rs->EOF) {
  762. $rs->MoveFirst();
  763. $rs->Move($this->lStartRec - 1);
  764. }
  765. while (!$rs->EOF && $this->lRecCnt < $this->lStopRec) {
  766. $this->lRecCnt++;
  767. if (intval($this->lRecCnt) >= intval($this->lStartRec)) {
  768. $this->LoadRowValues($rs);
  769. // Render row for display
  770. $cuenta->RowType = EW_ROWTYPE_VIEW; // Render view
  771. $this->RenderRow();
  772. if ($cuenta->Export == "xml") {
  773. $XmlDoc->BeginRow();
  774. $XmlDoc->AddField('idCuenta', $cuenta->idCuenta->CurrentValue);
  775. $XmlDoc->AddField('cuenta', $cuenta->cuenta->CurrentValue);
  776. $XmlDoc->AddField('porcentaje', $cuenta->porcentaje->CurrentValue);
  777. $XmlDoc->EndRow();
  778. } else {
  779. if ($sExportStyle == "v" && $cuenta->Export <> "csv") { // Vertical format
  780. echo ew_ExportField('idCuenta', $cuenta->idCuenta->ExportValue($cuenta->Export, $cuenta->ExportOriginalValue), $cuenta->Export);
  781. echo ew_ExportField('cuenta', $cuenta->cuenta->ExportValue($cuenta->Export, $cuenta->ExportOriginalValue), $cuenta->Export);
  782. echo ew_ExportField('porcentaje', $cuenta->porcentaje->ExportValue($cuenta->Export, $cuenta->ExportOriginalValue), $cuenta->Export);
  783. } else { // Horizontal format
  784. $sExportStr = "";
  785. ew_ExportAddValue($sExportStr, $cuenta->idCuenta->ExportValue($cuenta->Export, $cuenta->ExportOriginalValue), $cuenta->Export);
  786. ew_ExportAddValue($sExportStr, $cuenta->cuenta->ExportValue($cuenta->Export, $cuenta->ExportOriginalValue), $cuenta->Export);
  787. ew_ExportAddValue($sExportStr, $cuenta->porcentaje->ExportValue($cuenta->Export, $cuenta->ExportOriginalValue), $cuenta->Export);
  788. echo ew_ExportLine($sExportStr, $cuenta->Export);
  789. }
  790. }
  791. }
  792. $rs->MoveNext();
  793. }
  794. // Close recordset
  795. $rs->Close();
  796. if ($cuenta->Export == "xml") {
  797. header("Content-Type: text/xml");
  798. echo $XmlDoc->XML();
  799. } else {
  800. echo ew_ExportFooter($cuenta->Export);
  801. }
  802. }
  803. // Page Load event
  804. function Page_Load() {
  805. //echo "Page Load";
  806. }
  807. // Page Unload event
  808. function Page_Unload() {
  809. //echo "Page Unload";
  810. }
  811. // Form Custom Validate event
  812. function Form_CustomValidate(&$CustomError) {
  813. // Return error message in CustomError
  814. return TRUE;
  815. }
  816. }
  817. ?>