PageRenderTime 66ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/cierre_gestion_guardar.php

https://github.com/fredd-for/emaus_tesoreria
PHP | 595 lines | 397 code | 94 blank | 104 comment | 76 complexity | 1402641c0925083d0d30bc5f2c05c12a 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 "cierre_gestioninfo.php" ?>
  9. <?php include "userfn6.php" ?>
  10. <?php include "Connections/conexion.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. $cierre_gestion_list = new ccierre_gestion_list();
  21. $Page =& $cierre_gestion_list;
  22. // Page init processing
  23. $cierre_gestion_list->Page_Init();
  24. // Page main processing
  25. $cierre_gestion_list->Page_Main();
  26. ?>
  27. <?php
  28. if($_POST['guardar']){
  29. $fechaOnly = explode ("-",$_POST['fi']);
  30. $fi=date("Y-m-d", mktime(0, 0, 0, $fechaOnly[1], $fechaOnly[0], $fechaOnly[2]));
  31. $fechaOnly = explode ("-",$_POST['ff']);
  32. $ff=date("Y-m-d", mktime(0, 0, 0, $fechaOnly[1], $fechaOnly[0], $fechaOnly[2]));
  33. mysql_select_db($database_conexion, $conexion);
  34. $query = "UPDATE saldo_cuenta SET estado = 2 WHERE fecha BETWEEN '".$fi."' AND '".date("Y-m-d", strtotime("$ff + 1 day"))."'";
  35. $mostrar= mysql_query($query, $conexion) or die(mysql_error());
  36. mysql_select_db($database_conexion, $conexion);
  37. $query = "UPDATE diezmo SET estado = 2 WHERE fecha BETWEEN '".$fi."' AND '".date("Y-m-d", strtotime("$ff + 1 day"))."'";
  38. $mostrar= mysql_query($query, $conexion) or die(mysql_error());
  39. }
  40. Header("Location: cierre_gestionlist.php");
  41. ?>
  42. <?php
  43. //
  44. // Page Class
  45. //
  46. class ccierre_gestion_list {
  47. // Page ID
  48. var $PageID = 'list';
  49. // Table Name
  50. var $TableName = 'cierre_gestion';
  51. // Page Object Name
  52. var $PageObjName = 'cierre_gestion_list';
  53. // Page Name
  54. function PageName() {
  55. return ew_CurrentPage();
  56. }
  57. // Page Url
  58. function PageUrl() {
  59. $PageUrl = ew_CurrentPage() . "?";
  60. global $cierre_gestion;
  61. if ($cierre_gestion->UseTokenInUrl) $PageUrl .= "t=" . $cierre_gestion->TableVar . "&"; // add page token
  62. return $PageUrl;
  63. }
  64. // Message
  65. function getMessage() {
  66. return @$_SESSION[EW_SESSION_MESSAGE];
  67. }
  68. function setMessage($v) {
  69. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
  70. $_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
  71. } else {
  72. $_SESSION[EW_SESSION_MESSAGE] = $v;
  73. }
  74. }
  75. // Show Message
  76. function ShowMessage() {
  77. if ($this->getMessage() <> "") { // Message in Session, display
  78. echo "<p><span class=\"ewMessage\">" . $this->getMessage() . "</span></p>";
  79. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
  80. }
  81. }
  82. // Validate Page request
  83. function IsPageRequest() {
  84. global $objForm, $cierre_gestion;
  85. if ($cierre_gestion->UseTokenInUrl) {
  86. //IsPageRequest = False
  87. if ($objForm)
  88. return ($cierre_gestion->TableVar == $objForm->GetValue("t"));
  89. if (@$_GET["t"] <> "")
  90. return ($cierre_gestion->TableVar == $_GET["t"]);
  91. } else {
  92. return TRUE;
  93. }
  94. }
  95. //
  96. // Class initialize
  97. // - init objects
  98. // - open connection
  99. //
  100. function ccierre_gestion_list() {
  101. global $conn;
  102. // Initialize table object
  103. $GLOBALS["cierre_gestion"] = new ccierre_gestion();
  104. // Intialize page id (for backward compatibility)
  105. if (!defined("EW_PAGE_ID"))
  106. define("EW_PAGE_ID", 'list', TRUE);
  107. // Initialize table name (for backward compatibility)
  108. if (!defined("EW_TABLE_NAME"))
  109. define("EW_TABLE_NAME", 'cierre_gestion', TRUE);
  110. // Open connection to the database
  111. $conn = ew_Connect();
  112. // Initialize list options
  113. $this->ListOptions = new cListOptions();
  114. }
  115. //
  116. // Page_Init
  117. //
  118. function Page_Init() {
  119. global $gsExport, $gsExportFile, $cierre_gestion;
  120. $cierre_gestion->Export = @$_GET["export"]; // Get export parameter
  121. $gsExport = $cierre_gestion->Export; // Get export parameter, used in header
  122. $gsExportFile = $cierre_gestion->TableVar; // Get export file, used in header
  123. if ($cierre_gestion->Export == "excel") {
  124. header('Content-Type: application/vnd.ms-excel');
  125. header('Content-Disposition: attachment; filename=' . $gsExportFile .'.xls');
  126. }
  127. // Global page loading event (in userfn6.php)
  128. Page_Loading();
  129. // Page load event, used in current page
  130. $this->Page_Load();
  131. }
  132. //
  133. // Page_Terminate
  134. // - called when exit page
  135. // - if URL specified, redirect to the URL
  136. //
  137. function Page_Terminate($url = "") {
  138. global $conn;
  139. // Page unload event, used in current page
  140. $this->Page_Unload();
  141. // Global page unloaded event (in userfn*.php)
  142. Page_Unloaded();
  143. // Close Connection
  144. $conn->Close();
  145. // Go to URL if specified
  146. if ($url <> "") {
  147. ob_end_clean();
  148. header("Location: $url");
  149. }
  150. exit();
  151. }
  152. var $lDisplayRecs; // Number of display records
  153. var $lStartRec;
  154. var $lStopRec;
  155. var $lTotalRecs;
  156. var $lRecRange;
  157. var $sSrchWhere;
  158. var $lRecCnt;
  159. var $lEditRowCnt;
  160. var $lRowCnt;
  161. var $lRowIndex;
  162. var $lOptionCnt;
  163. var $lRecPerRow;
  164. var $lColCnt;
  165. var $sDeleteConfirmMsg; // Delete confirm message
  166. var $sDbMasterFilter;
  167. var $sDbDetailFilter;
  168. var $bMasterRecordExists;
  169. var $ListOptions;
  170. var $sMultiSelectKey;
  171. //
  172. // Page main processing
  173. //
  174. function Page_Main() {
  175. global $objForm, $gsSearchError, $Security, $cierre_gestion;
  176. $this->lDisplayRecs = 20;
  177. $this->lRecRange = 10;
  178. $this->lRecCnt = 0; // Record count
  179. // Search filters
  180. $sSrchAdvanced = ""; // Advanced search filter
  181. $sSrchBasic = ""; // Basic search filter
  182. $sFilter = "";
  183. $this->sSrchWhere = ""; // Search WHERE clause
  184. $this->sDeleteConfirmMsg = "�Quiere borrar este registro?"; // Delete confirm message
  185. // Master/Detail
  186. $this->sDbMasterFilter = ""; // Master filter
  187. $this->sDbDetailFilter = ""; // Detail filter
  188. if ($this->IsPageRequest()) { // Validate request
  189. // Set up records per page dynamically
  190. $this->SetUpDisplayRecs();
  191. // Handle reset command
  192. $this->ResetCmd();
  193. // Set Up Sorting Order
  194. $this->SetUpSortOrder();
  195. } // End Validate Request
  196. // Restore display records
  197. if ($cierre_gestion->getRecordsPerPage() <> "") {
  198. $this->lDisplayRecs = $cierre_gestion->getRecordsPerPage(); // Restore from Session
  199. } else {
  200. $this->lDisplayRecs = 20; // Load default
  201. }
  202. // Load Sorting Order
  203. $this->LoadSortOrder();
  204. // Build filter
  205. $sFilter = "";
  206. if ($this->sDbDetailFilter <> "")
  207. $sFilter = ($sFilter <> "") ? "($sFilter) AND (" . $this->sDbDetailFilter . ")" : $this->sDbDetailFilter;
  208. if ($this->sSrchWhere <> "")
  209. $sFilter = ($sFilter <> "") ? "($sFilter) AND (". $this->sSrchWhere . ")" : $this->sSrchWhere;
  210. // Set up filter in Session
  211. $cierre_gestion->setSessionWhere($sFilter);
  212. $cierre_gestion->CurrentFilter = "";
  213. // Export data only
  214. if (in_array($cierre_gestion->Export, array("html","word","excel","xml","csv"))) {
  215. $this->ExportData();
  216. $this->Page_Terminate(); // Terminate response
  217. exit();
  218. }
  219. }
  220. // Set up number of records displayed per page
  221. function SetUpDisplayRecs() {
  222. global $cierre_gestion;
  223. $sWrk = @$_GET[EW_TABLE_REC_PER_PAGE];
  224. if ($sWrk <> "") {
  225. if (is_numeric($sWrk)) {
  226. $this->lDisplayRecs = intval($sWrk);
  227. } else {
  228. if (strtolower($sWrk) == "all") { // Display all records
  229. $this->lDisplayRecs = -1;
  230. } else {
  231. $this->lDisplayRecs = 20; // Non-numeric, load default
  232. }
  233. }
  234. $cierre_gestion->setRecordsPerPage($this->lDisplayRecs); // Save to Session
  235. // Reset start position
  236. $this->lStartRec = 1;
  237. $cierre_gestion->setStartRecordNumber($this->lStartRec);
  238. }
  239. }
  240. // Set up Sort parameters based on Sort Links clicked
  241. function SetUpSortOrder() {
  242. global $cierre_gestion;
  243. // Check for an Order parameter
  244. if (@$_GET["order"] <> "") {
  245. $cierre_gestion->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
  246. $cierre_gestion->CurrentOrderType = @$_GET["ordertype"];
  247. $cierre_gestion->UpdateSort($cierre_gestion->idCuenta); // Field
  248. $cierre_gestion->UpdateSort($cierre_gestion->cuenta); // Field
  249. $cierre_gestion->UpdateSort($cierre_gestion->saldo); // Field
  250. $cierre_gestion->setStartRecordNumber(1); // Reset start position
  251. }
  252. }
  253. // Load Sort Order parameters
  254. function LoadSortOrder() {
  255. global $cierre_gestion;
  256. $sOrderBy = $cierre_gestion->getSessionOrderBy(); // Get order by from Session
  257. if ($sOrderBy == "") {
  258. if ($cierre_gestion->SqlOrderBy() <> "") {
  259. $sOrderBy = $cierre_gestion->SqlOrderBy();
  260. $cierre_gestion->setSessionOrderBy($sOrderBy);
  261. }
  262. }
  263. }
  264. // Reset command based on querystring parameter cmd=
  265. // - RESET: reset search parameters
  266. // - RESETALL: reset search & master/detail parameters
  267. // - RESETSORT: reset sort parameters
  268. function ResetCmd() {
  269. global $cierre_gestion;
  270. // Get reset cmd
  271. if (@$_GET["cmd"] <> "") {
  272. $sCmd = $_GET["cmd"];
  273. // Reset sort criteria
  274. if (strtolower($sCmd) == "resetsort") {
  275. $sOrderBy = "";
  276. $cierre_gestion->setSessionOrderBy($sOrderBy);
  277. $cierre_gestion->idCuenta->setSort("");
  278. $cierre_gestion->cuenta->setSort("");
  279. $cierre_gestion->saldo->setSort("");
  280. }
  281. // Reset start position
  282. $this->lStartRec = 1;
  283. $cierre_gestion->setStartRecordNumber($this->lStartRec);
  284. }
  285. }
  286. // Set up Starting Record parameters based on Pager Navigation
  287. function SetUpStartRec() {
  288. global $cierre_gestion;
  289. if ($this->lDisplayRecs == 0)
  290. return;
  291. if ($this->IsPageRequest()) { // Validate request
  292. if (@$_GET[EW_TABLE_START_REC] <> "") { // Check for "start" parameter
  293. $this->lStartRec = $_GET[EW_TABLE_START_REC];
  294. $cierre_gestion->setStartRecordNumber($this->lStartRec);
  295. } elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
  296. $this->nPageNo = $_GET[EW_TABLE_PAGE_NO];
  297. if (is_numeric($this->nPageNo)) {
  298. $this->lStartRec = ($this->nPageNo-1)*$this->lDisplayRecs+1;
  299. if ($this->lStartRec <= 0) {
  300. $this->lStartRec = 1;
  301. } elseif ($this->lStartRec >= intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1) {
  302. $this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1;
  303. }
  304. $cierre_gestion->setStartRecordNumber($this->lStartRec);
  305. }
  306. }
  307. }
  308. $this->lStartRec = $cierre_gestion->getStartRecordNumber();
  309. // Check if correct start record counter
  310. if (!is_numeric($this->lStartRec) || $this->lStartRec == "") { // Avoid invalid start record counter
  311. $this->lStartRec = 1; // Reset start record counter
  312. $cierre_gestion->setStartRecordNumber($this->lStartRec);
  313. } elseif (intval($this->lStartRec) > intval($this->lTotalRecs)) { // Avoid starting record > total records
  314. $this->lStartRec = intval(($this->lTotalRecs-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to last page first record
  315. $cierre_gestion->setStartRecordNumber($this->lStartRec);
  316. } elseif (($this->lStartRec-1) % $this->lDisplayRecs <> 0) {
  317. $this->lStartRec = intval(($this->lStartRec-1)/$this->lDisplayRecs)*$this->lDisplayRecs+1; // Point to page boundary
  318. $cierre_gestion->setStartRecordNumber($this->lStartRec);
  319. }
  320. }
  321. // Load recordset
  322. function LoadRecordset($offset = -1, $rowcnt = -1) {
  323. global $conn, $cierre_gestion;
  324. // Call Recordset Selecting event
  325. $cierre_gestion->Recordset_Selecting($cierre_gestion->CurrentFilter);
  326. // Load list page SQL
  327. $sSql = $cierre_gestion->SelectSQL();
  328. if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";
  329. // Load recordset
  330. $conn->raiseErrorFn = 'ew_ErrorFn';
  331. $rs = $conn->Execute($sSql);
  332. $conn->raiseErrorFn = '';
  333. // Call Recordset Selected event
  334. $cierre_gestion->Recordset_Selected($rs);
  335. return $rs;
  336. }
  337. // Load row based on key values
  338. function LoadRow() {
  339. global $conn, $Security, $cierre_gestion;
  340. $sFilter = $cierre_gestion->KeyFilter();
  341. // Call Row Selecting event
  342. $cierre_gestion->Row_Selecting($sFilter);
  343. // Load sql based on filter
  344. $cierre_gestion->CurrentFilter = $sFilter;
  345. $sSql = $cierre_gestion->SQL();
  346. if ($rs = $conn->Execute($sSql)) {
  347. if ($rs->EOF) {
  348. $LoadRow = FALSE;
  349. } else {
  350. $LoadRow = TRUE;
  351. $rs->MoveFirst();
  352. $this->LoadRowValues($rs); // Load row values
  353. // Call Row Selected event
  354. $cierre_gestion->Row_Selected($rs);
  355. }
  356. $rs->Close();
  357. } else {
  358. $LoadRow = FALSE;
  359. }
  360. return $LoadRow;
  361. }
  362. // Load row values from recordset
  363. function LoadRowValues(&$rs) {
  364. global $cierre_gestion;
  365. $cierre_gestion->idCuenta->setDbValue($rs->fields('idCuenta'));
  366. $cierre_gestion->cuenta->setDbValue($rs->fields('cuenta'));
  367. $cierre_gestion->porcentaje->setDbValue($rs->fields('porcentaje'));
  368. $cierre_gestion->saldo->setDbValue($rs->fields('saldo'));
  369. $cierre_gestion->estado->setDbValue($rs->fields('estado'));
  370. }
  371. // Render row values based on field settings
  372. function RenderRow() {
  373. global $conn, $Security, $cierre_gestion;
  374. // Call Row_Rendering event
  375. $cierre_gestion->Row_Rendering();
  376. // Common render codes for all row types
  377. // idCuenta
  378. $cierre_gestion->idCuenta->CellCssStyle = "";
  379. $cierre_gestion->idCuenta->CellCssClass = "";
  380. // cuenta
  381. $cierre_gestion->cuenta->CellCssStyle = "";
  382. $cierre_gestion->cuenta->CellCssClass = "";
  383. // saldo
  384. $cierre_gestion->saldo->CellCssStyle = "";
  385. $cierre_gestion->saldo->CellCssClass = "";
  386. if ($cierre_gestion->RowType == EW_ROWTYPE_VIEW) { // View row
  387. // idCuenta
  388. $cierre_gestion->idCuenta->ViewValue = $cierre_gestion->idCuenta->CurrentValue;
  389. $cierre_gestion->idCuenta->CssStyle = "";
  390. $cierre_gestion->idCuenta->CssClass = "";
  391. $cierre_gestion->idCuenta->ViewCustomAttributes = "";
  392. // cuenta
  393. $cierre_gestion->cuenta->ViewValue = $cierre_gestion->cuenta->CurrentValue;
  394. $cierre_gestion->cuenta->CssStyle = "";
  395. $cierre_gestion->cuenta->CssClass = "";
  396. $cierre_gestion->cuenta->ViewCustomAttributes = "";
  397. // saldo
  398. $cierre_gestion->saldo->ViewValue = $cierre_gestion->saldo->CurrentValue;
  399. $cierre_gestion->saldo->CssStyle = "";
  400. $cierre_gestion->saldo->CssClass = "";
  401. $cierre_gestion->saldo->ViewCustomAttributes = "";
  402. // idCuenta
  403. $cierre_gestion->idCuenta->HrefValue = "";
  404. // cuenta
  405. $cierre_gestion->cuenta->HrefValue = "";
  406. // saldo
  407. $cierre_gestion->saldo->HrefValue = "";
  408. }
  409. // Call Row Rendered event
  410. $cierre_gestion->Row_Rendered();
  411. }
  412. // Export data in XML or CSV format
  413. function ExportData() {
  414. global $cierre_gestion;
  415. $sCsvStr = "";
  416. // Default export style
  417. $sExportStyle = "h";
  418. // Load recordset
  419. $rs = $this->LoadRecordset();
  420. $this->lTotalRecs = $rs->RecordCount();
  421. $this->lStartRec = 1;
  422. // Export all
  423. if ($cierre_gestion->ExportAll) {
  424. $this->lStopRec = $this->lTotalRecs;
  425. } else { // Export 1 page only
  426. $this->SetUpStartRec(); // Set up start record position
  427. // Set the last record to display
  428. if ($this->lDisplayRecs < 0) {
  429. $this->lStopRec = $this->lTotalRecs;
  430. } else {
  431. $this->lStopRec = $this->lStartRec + $this->lDisplayRecs - 1;
  432. }
  433. }
  434. if ($cierre_gestion->Export == "xml") {
  435. $XmlDoc = new cXMLDocument();
  436. } else {
  437. echo ew_ExportHeader($cierre_gestion->Export);
  438. // Horizontal format, write header
  439. if ($sExportStyle <> "v" || $cierre_gestion->Export == "csv") {
  440. $sExportStr = "";
  441. ew_ExportAddValue($sExportStr, 'idCuenta', $cierre_gestion->Export);
  442. ew_ExportAddValue($sExportStr, 'saldo', $cierre_gestion->Export);
  443. echo ew_ExportLine($sExportStr, $cierre_gestion->Export);
  444. }
  445. }
  446. // Move to first record
  447. $this->lRecCnt = $this->lStartRec - 1;
  448. if (!$rs->EOF) {
  449. $rs->MoveFirst();
  450. $rs->Move($this->lStartRec - 1);
  451. }
  452. while (!$rs->EOF && $this->lRecCnt < $this->lStopRec) {
  453. $this->lRecCnt++;
  454. if (intval($this->lRecCnt) >= intval($this->lStartRec)) {
  455. $this->LoadRowValues($rs);
  456. // Render row for display
  457. $cierre_gestion->RowType = EW_ROWTYPE_VIEW; // Render view
  458. $this->RenderRow();
  459. if ($cierre_gestion->Export == "xml") {
  460. $XmlDoc->BeginRow();
  461. $XmlDoc->AddField('idCuenta', $cierre_gestion->idCuenta->CurrentValue);
  462. $XmlDoc->AddField('saldo', $cierre_gestion->saldo->CurrentValue);
  463. $XmlDoc->EndRow();
  464. } else {
  465. if ($sExportStyle == "v" && $cierre_gestion->Export <> "csv") { // Vertical format
  466. echo ew_ExportField('idCuenta', $cierre_gestion->idCuenta->ExportValue($cierre_gestion->Export, $cierre_gestion->ExportOriginalValue), $cierre_gestion->Export);
  467. echo ew_ExportField('saldo', $cierre_gestion->saldo->ExportValue($cierre_gestion->Export, $cierre_gestion->ExportOriginalValue), $cierre_gestion->Export);
  468. } else { // Horizontal format
  469. $sExportStr = "";
  470. ew_ExportAddValue($sExportStr, $cierre_gestion->idCuenta->ExportValue($cierre_gestion->Export, $cierre_gestion->ExportOriginalValue), $cierre_gestion->Export);
  471. ew_ExportAddValue($sExportStr, $cierre_gestion->saldo->ExportValue($cierre_gestion->Export, $cierre_gestion->ExportOriginalValue), $cierre_gestion->Export);
  472. echo ew_ExportLine($sExportStr, $cierre_gestion->Export);
  473. }
  474. }
  475. }
  476. $rs->MoveNext();
  477. }
  478. // Close recordset
  479. $rs->Close();
  480. if ($cierre_gestion->Export == "xml") {
  481. header("Content-Type: text/xml");
  482. echo $XmlDoc->XML();
  483. } else {
  484. echo ew_ExportFooter($cierre_gestion->Export);
  485. }
  486. }
  487. // Page Load event
  488. function Page_Load() {
  489. //echo "Page Load";
  490. }
  491. // Page Unload event
  492. function Page_Unload() {
  493. //echo "Page Unload";
  494. }
  495. // Form Custom Validate event
  496. function Form_CustomValidate(&$CustomError) {
  497. // Return error message in CustomError
  498. return TRUE;
  499. }
  500. }
  501. ?>