[go: up one dir, main page]

Menu

[728b31]: / contas.php  Maximize  Restore  History

Download this file

121 lines (116 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* General functions
*
* @author Antonio Henrique Oliveira
* @copyright (c) 2017, Antonio Henrique Oliveira
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License (GPL) v3
*
*/
include_once 'functions/functions.php';
include_once 'functions/html.php';
include 'contas_config.php';
include 'objects/Account.php';
include 'objects/AccountType.php';
function edit_row($row = NULL) {
if ($row == NULL) {
$row = new Account();
}
$tipo_opt = "";
foreach (AccountType::getElementList() as $value) {
$tipo_opt = sprintf("{$tipo_opt}<option value=\"{$value->id}\" %s>{$value->description}</option>\n", ($row->tipo_id == $value->id ? "selected" : ""));
}
print "<td style=\"text-align: right\"><input type=\"hidden\" name=\"conta_id\" value=\"{$row->id}\"/>{$row->id}</td>\n";
print "<td style=\"text-align: left\"><input type=text size=16 maxlength=30 name=\"conta_nome\" value=\"{$row->conta_nome}\"></td>";
print "<td><input type=text size=15 maxlength=30 name=\"conta_num\" value=\"{$row->conta_num}\"></td>";
print "<td><select name=\"tipo_id\">{$tipo_opt}</select>";
print "<td><input type=text size=24 maxlength=24 name=\"conta_nib\" value=\"{$row->conta_nib}\"></td>";
print "<td>";
print "<select name=\"aberturaAA\">" . year_opt(date("Y", $row->conta_abertura)) . "</select>";
print "<select name=\"aberturaMM\">" . mon_opt(date("m", $row->conta_abertura)) . "</select>";
print "<select name=\"aberturaDD\">" . day_opt(date("d", $row->conta_abertura)) . "</select>";
print "</td>";
print "<td>";
print "<select name=\"fechoAA\">" . year_opt(date("Y", $row->conta_fecho)) . "</select>";
print "<select name=\"fechoMM\">" . mon_opt(date("m", $row->conta_fecho)) . "</select>";
print "<select name=\"fechoDD\">" . day_opt(date("d", $row->conta_fecho)) . "</select>";
print "</td>";
print "<td><input type=\"checkbox\" name=\"activa\" " . ($row->activa ? "checked" : "") . "></td>";
print "<td><input class=\"submit\" type=\"submit\" name=\"update\" value=\"Gravar\"></td>";
}
dtd_hdr("strict");
print "<html>\n";
print "<head>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
print "<link rel=\"StyleSheet\" href=\"contas.css\" type=\"text/css\">\n";
print "<title>" . Config::$caixa_nome . " - Contas</title>\n";
$conta = new Account();
if (filter_input(INPUT_SERVER, "REQUEST_METHOD", FILTER_SANITIZE_STRING) == "POST") {
if (stristr($_POST["update"], "gravar")) {
if (filter_input(INPUT_POST, "conta_nome", FILTER_SANITIZE_STRING, FILTER_FLAG_EMPTY_STRING_NULL) == NULL) {
myalert("Nome de conta invalido!");
} else {
$conta->id = filter_input(INPUT_POST, "conta_id", FILTER_SANITIZE_NUMBER_INT);
$conta->tipo_id = filter_input(INPUT_POST, "tipo_id", FILTER_SANITIZE_NUMBER_INT);
$conta->conta_nome = filter_input(INPUT_POST, "conta_nome", FILTER_SANITIZE_STRING);
$conta->conta_num = filter_input(INPUT_POST, "conta_num", FILTER_SANITIZE_STRING);
$conta->activa = filter_has_var(INPUT_POST, "activa");
$conta->conta_abertura = strtotime(sprintf("%s-%s-%s", filter_input(INPUT_POST, "aberturaAA", FILTER_SANITIZE_NUMBER_INT), filter_input(INPUT_POST, "aberturaMM", FILTER_SANITIZE_NUMBER_INT), filter_input(INPUT_POST, "aberturaDD", FILTER_SANITIZE_NUMBER_INT)));
$conta->conta_fecho = strtotime(sprintf("%s-%s-%s", filter_input(INPUT_POST, "fechoAA", FILTER_SANITIZE_NUMBER_INT), filter_input(INPUT_POST, "fechoMM", FILTER_SANITIZE_NUMBER_INT), filter_input(INPUT_POST, "fechoDD", FILTER_SANITIZE_NUMBER_INT)));
$conta->activa = !($conta->activa == NULL);
if ($conta->write()) {
myalert("Registo gravado");
} else {
myalert("Ocorreu um erro na gravacao");
}
}
} else {
$conta->id = filter_input(INPUT_POST, "conta_id", FILTER_SANITIZE_NUMBER_INT);
if (!$conta->delete()) {
myalert("Registo eliminado");
}
}
}
print "</head>\n";
print "<body>\n";
include("menu.inc");
$conta = new Account();
if (filter_input(INPUT_SERVER, "REQUEST_METHOD", FILTER_SANITIZE_STRING) == "GET") {
if (filter_has_var(INPUT_GET, "conta_id")) {
$conta->getElementById(filter_input(INPUT_GET, "conta_id", FILTER_SANITIZE_NUMBER_INT));
}
}
if ($conta->id == NULL) {
$conta->getFreeId();
}
print "<div id=\"main\">\n";
print "<form method=\"POST\" action=\"contas.php\" name=\"contas\">\n";
print "<table class=\"contas\">\n";
print "<tr><th>ID<th>Nome<th>Numero<th>Tipo<th>NIB<th>Abertura<th>Fecho<th>Activa<th>Apagar</tr>";
foreach (Account::getElementList() as $row) {
print "<tr>";
if ($conta->id == $row->id && filter_has_var(INPUT_GET, "conta_id")) {
edit_row($row);
} else {
print "<td style=\"text-align: right;\"><a href=\"" . $_SERVER["SCRIPT_NAME"] . "?conta_id={$row->id}\">{$row->id}</a></td>";
print "<td style=\"text-align: left\">{$row->conta_nome}</td>";
print "<td style=\"text-align: right\">{$row->conta_num}</td>";
print "<td>{$row->tipo_desc}</td>";
print "<td>{$row->conta_nib}</td>";
print "<td>" . date("Y-m-d", $row->conta_abertura) . "</td>";
print "<td>" . date("Y-m-d", $row->conta_fecho) . "</td>";
print "<td>{$row->activa_txt}</td>";
print "<td class=\"lista\"><a href=\"" . $_SERVER["SCRIPT_NAME"] . "?update=Apagar&amp;conta_id={$row->id}\">Apagar</a></td>";
}
print "</tr>\n";
}
if (!filter_has_var(INPUT_GET, "conta_id")) {
print "<tr>";
edit_row($conta);
print "</tr>\n";
}
print "</table>";
print "</form>";
print "</div>";
print "</body>";
print "</html>";