<?php
/**
* object_list_1n.php :: Modelo de página que apresenta uma lista de registros em relacionamentos 1:N,
*
* PHP version 4
*
* phpWAFr version 1.1.2
* copyright (c) 2007 Associação SoftwareLivre.org
*
* phpWAFr is an open source PHP library designed to accelerate
* the development of transactional database Web applications.
*
* phpWAFr is released under the terms of the LGPL license 2.1
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPL License 2.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* @package phpWAFr
* @version 1.1.2
* @author Marcelo Rezende <hide@address.com>
* @copyright copyright (c) 2007 Associação SoftwareLivre.org
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPL License 2.1
*/
require_once("../inc/common.php");
/*
verificação do nível do usuário
*/
verifyUser(3);
/*
conexão com o banco de dados
*/
$conn = new db();
$conn->open();
/*
se a lista faz parte de um relacionamento 1:N
*/
$fk_id = getParam("id");
/*
determina a página a ser exibida
*/
$pg = getParam("page");
if ($pg == "") $pg = 1;
/*
expressão SQL que define a lista, configure conforme sua necessidade
*/
$sql = "SELECT * " .
"FROM historico " .
"WHERE usuario_id=$fk_id " .
"ORDER BY data_cadastro DESC";
/*
criação do recordset, o último parâmetro corresponde a quantidade de registros por página
*/
$rs = new query($conn, $sql, $pg, 10);
?>
<html>
<head>
<title>object-list-1N</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="<?=CSS_CONTENT?>">
<script language="JavaScript" src="../inc/js/janela.js"></script>
<script language="javascript" src="../inc/js/checkall.js"></script>
<script language="JavaScript">
/*
função que chama a rotina de exclusão,
altere somente o nome da página (action)
*/
function delete() {
if (confirm('Excluir registros selecionados?')) {
parent.content.document.frm.target = "control";
parent.content.document.frm.action = "#";
parent.content.document.frm.submit();
}
}
function abreEdicao(id) {
// atenção, o separador "&" deve ser substituido por vírgula ","
openAuxiliaryWindow('../content/object_edit_aux.php?fk_id=<?=$fk_id?>,id=' + id);
}
</script>
</head>
<body class="contentBODY">
<?php
pageTitle("Objeto", "Lista de ocorrências do objeto");
/*
botões de ações
*/
$button = new Button;
/*
botões de navegação, não deve ser alterado
*/
$pg_ant = $pg - 1;
$pg_prox = $pg + 1;
if ($pg > 1) $button->addItem(LIST_PREVIOUS, $_SERVER['PHP_SELF'] . "?page=$pg_ant&id=$fk_id" , "content");
if ($pg < $rs->totalpages()) $button->addItem(LIST_NEXT , $_SERVER['PHP_SELF'] . "?page=$pg_prox&id=$fk_id", "content");
/*
botões de ações, configure conforme sua necessidade
*/
$button->addItem("Novo Relacionamento", "javascript:abreEdicao(0)", "content");
$button->addItem("Excluir", "javascript:delete()", "content");
echo $button->writeHTML();
/*
controle de abas, true, se for a aba da página atual, false, se for qualquer outra aba,
configure conforme o exemplo abaixo
*/
$tabs = new Tabs();
$tabs->addItem("Geral", false, "../content/object_edit.php?id=$fk_id");
$tabs->addItem("Associação", false, "../content/object_association.php?id=$fk_id");
$tabs->addItem("Ordenação", false, "../content/object_ordering.php?id=$fk_id");
$tabs->addItem("Detalhe", false, "../content/object_read.php?id=$fk_id");
$tabs->addItem("Lista 1:N", true);
echo $tabs->writeHTML();
?>
<!-- Lista -->
<div align="center">
<form name="frm" method="post">
<input type="hidden" name="fk_id" value="<?=$fk_id?>">
<?php
/*
inicialização da tabela
*/
$table = new Table("Título da Lista", "100%", 3); // Título, Largura, Quantidade de colunas
/*
construção dos cabeçalhos da tabela
*/
$table->addColumnHeader("<input type=\"checkbox\" name=\"checkall\" onclick=\"CheckAll()\">");
$table->addColumnHeader("Data", false, "15%"); // Título, Ordenar?, Largura
$table->addColumnHeader("Descrição", false, "85%");
$table->addRow();
while ($rs->getrow()) {
$id = $rs->field("historico_id"); // captura chave primária
/*
adiciona colunas
*/
$table->addData("<input type=\"checkbox\" name=\"sel[]\" value=\"$id\">");
$table->addData(stod( $rs->field("data_cadastro")));
$table->addData(addLink($rs->field("descricao"), "javascript:abreEdicao($id)", "Clique para consultar ou editar registro"));
$table->addRow(); // adiciona linha
}
/*
Desenha a tabela
*/
if ($rs->numrows()>0) {
echo $table->writeHTML();
echo "<div class='DataFONT'>Página " . $pg . " de " . $rs->totalpages() . "</div>";
} else {
echo "<div class='DataFONT'>Nenhum registro encontrado!</div>";
}
?>
</form>
</div>
</body>
</html>
<?php
/*
fecha a conexão com o banco de dados
*/
$conn->close();
?>