<?php
/**
* object_list.php :: Modelo de página que apresenta uma lista de registros.
*
* 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, altere conforme sua necessidade, quanto maior o valor,
maior a restrição
*/
verifyUser(1);
/*
conexão com o banco de dados, altere somente se a conexão for diferente do default
*/
$conn = new db();
$conn->open();
/*
determina a página a ser exibida, não precisa alterar
*/
$pg = getParam("page");
if ($pg == "") $pg = 1;
/*
Limpa ordenação e filtro, não deve ser alterado
*/
if (getParam("clear") == 1) {
setSession("sOrder", "");
setSession("where", "");
setSession("current_page", "");
}
/*
Salva o status da página atual, não deve ser alterado
*/
if ($_SERVER['PHP_SELF'] != getSession("current_page")) {
$same_page = false;
setSession("current_page", $_SERVER['PHP_SELF']);
} else {
$same_page = true;
}
/*
construção da ordenação
*/
$iSort = getParam("Sorting");
$iSorted = getParam("Sorted");
if ((!$iSort) && (!$same_page)) {
$form_sorting = "";
$iSort = 2; // configure a ordenação inicial da lista de acordo com as colunas da tabela
$iSorted = ""; // se a ordenação estiver DESCENDENTE, repita o mesmo valor abaixo
}
if ($iSort) {
if ($iSort == $iSorted) {
$form_sorting = "";
$sDirection = " DESC";
$sSortParams = "Sorting=" . $iSort . "&Sorted=" . $iSort . "&";
} else {
$form_sorting = $iSort;
$sDirection = " ASC";
$sSortParams = "Sorting=" . $iSort . "&Sorted=" . "&";
}
/*
coloque aqui a definição das ordenações das colunas de acordo com as colunas da tabela
*/
if ($iSort == 2) setSession("sOrder"," order by usuario.nome_usuario" . $sDirection);
if ($iSort == 3) setSession("sOrder"," order by usuario.nome_real" . $sDirection);
if ($iSort == 4) setSession("sOrder"," order by usuario.nivel_acesso" . $sDirection);
if ($iSort == 5) setSession("sOrder"," order by departamento.nome_departamento" . $sDirection);
}
if (getParam("executed") == "s") { // se ocorreu pesquisa...
$where = "";
/*
construa a string WHERE conforme o exemplo abaixo
*/
if (getParam("search_nome_usuario") != "") $where .= "AND usuario.nome_usuario LIKE '%" . getParam("search_nome_usuario") . "%'";
if (getParam("search_nome_real") != "") $where .= "AND usuario.nome_real LIKE '%" . getParam("search_nome_real") . "%'";
if (getParam("search_departamento_id") != "") $where .= "AND usuario.departamento_id = " . getParam("search_departamento_id") . "";
setSession("where",$where);
}
/*
flag pra informar se o filtro está ou não ativo
*/
if (strlen(getSession("where")) > 0) {
$filtered = ACTIVE_FILTER;
} else {
$filtered = "";
}
/*
expressão SQL que define a lista, construa livremente observando a concatenação com as
sessions WHERE e sOrder, conforme exemplo abaixo
*/
$sql = "SELECT usuario.*, departamento.nome_departamento "
. "FROM usuario, departamento "
. "WHERE usuario.departamento_id=departamento.departamento_id " . getSession("where") . getSession("sOrder");
/*
criação do recordset, altere somente o último parâmetro que corresponde a quantidade de
registros por página
*/
$rs = new query($conn, $sql, $pg, 10);
?>
<html>
<head>
<title>object-list</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/checkall.js"></script>
<script language="JavaScript">
/*
função que chama a rotina de exclusão de registros, altere somente o nome da página
a ser chamada
*/
function delete() {
if (confirm('Excluir registros selecionados?')) {
parent.content.document.frm.target = "control";
parent.content.document.frm.action = "../content/object_delete.php";
parent.content.document.frm.submit();
}
}
/*
função de exemplo para chamar um processamento qualquer
*/
function execute() {
if (confirm('Processar registros selecionados?')) {
parent.content.document.frm.target = "control";
parent.content.document.frm.action = "../content/object_execute.php";
parent.content.document.frm.submit();
}
}
</script>
</head>
<body class="contentBODY">
<?php
pageTitle("Objeto", "Lista");
/*
botões de ações
*/
$button = new Button;
/*
botões de navegação da lista, não deve ser alterada
*/
$pg_ant = $pg - 1;
$pg_prox = $pg + 1;
if ($pg > 1) $button->addItem(LIST_PREVIOUS, $_SERVER['PHP_SELF'] . "?page=$pg_ant" , "content");
if ($pg < $rs->totalpages()) $button->addItem(LIST_NEXT , $_SERVER['PHP_SELF'] . "?page=$pg_prox", "content");
/*
botões de ações da lista, altere conforme suas necessidades
*/
$button->addItem("Novo Objeto", "../content/object_edit.php", "content");
$button->addItem("Pesquisa", "../content/object_search.php", "content");
$button->addItem("Excluir", "javascript:delete()", "content");
$button->addItem("Processar", "javascript:execute()", "content", 3);
$button->addItem("Imprimir", "../content/object_print.php", "control");
echo $button->writeHTML();
?>
<!-- Lista -->
<div align="center">
<form name="frm" method="post">
<?php
/*
inicialização da tabela
*/
$table = new Table("", "100%", 6); // Título, Largura, Quantidade de colunas
/*
Configuração das colunas da tabela
*/
$table->addColumnHeader("<input type=\"checkbox\" name=\"checkall\"onclick=\"CheckAll()\">"); // Coluna com checkbox
$table->addColumnHeader("Usuário", true, "25%", "L"); // Título, Ordenar?, Largura, Alinhamento
$table->addColumnHeader("Nome Real", true, "35%", "L");
$table->addColumnHeader("Nivel", true, "10%", "C");
$table->addColumnHeader("Departamento", true, "20%", "L");
$table->addColumnHeader("Ativo", false, "10%", "C");
$table->addRow(); // adiciona linha (TR)
while ($rs->getrow()) {
$id = $rs->field("usuario_id"); // captura a chave primária do recordset
// exemplo do método addBreak
if (($rs->field("nome_departamento") != $ult_cat) && (strpos(getSession("sOrder"), "departamento"))) {
$table->addBreak("<b>Departamento: " . $rs->field("nome_departamento") . "</b>");
$ult_cat = $rs->field("nome_departamento");
}
$table->addData("<input type=\"checkbox\" name=\"sel[]\" value=\"$id\">");
$table->addData(addLink($rs->field("nome_usuario"),"../content/object_edit.php?id=$id&page=$pg","Clique para consultar ou editar registro"));
$table->addData( $rs->field("nome_real"));
$table->addData( $rs->field("nivel_acesso"), "C");
$table->addData( $rs->field("nome_departamento"));
$table->addData( $rs->field("ativo")==1?"Sim":"Não", "C");
$table->addRow();
}
echo "<div class='DataFONT' align='right'><b>$filtered</b></div>";
/*
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, não deve ser alterado
*/
$conn->close();
?>