Location: PHPKode > projects > PhpWAFr - PHP Web Application Framework > phpwafr-1.1.2/content/object_association.php
<?php
/**
 * object_association.php ::  Está página exibe um modelo de associação de registros,
 * 							 onde um ou mais registros são selecionados e logo após salvos.
 *
 * 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);

/*
	liga/desliga utilização de filtro
*/
$filterOn = true;

/*
	recupera chave, se existir
*/
$id = getParam("id");

/*
	conexão com o banco de dados,
	altere somente se a conexão for diferente do default
*/
$conn = new db();
$conn->open();

/*
	lista destino,
	configure conforme sua necessidade
*/
$sql = "SELECT sistema_usuario.sistema_id as id, sistema.nome_sistema as val " .
       "FROM sistema_usuario, sistema " .
       "WHERE sistema_usuario.sistema_id=sistema.sistema_id " .
       "AND sistema_usuario.usuario_id=$id " .
       "ORDER BY sistema.nome_sistema";
$rsDestination = new query($conn, $sql);
while ($rsDestination->getrow()) $aList[] = $rsDestination->field("id");
$list=is_array($aList)?implode(",",$aList):"0";
$rsDestination->free();
$rsDestination = new query($conn, $sql);


/*
	lista origem,
	configure conforme sua necessidade
*/
$sql = "SELECT sistema_id as id, nome_sistema as val " .
       "FROM sistema ".
	   "WHERE sistema_id NOT IN ($list) ".
	   "ORDER BY nome_sistema";
$rsSource = new query($conn, $sql);
?>
<html>
<head>
	<title>object-association</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/moveselect.js"></script>
	<?php if ($filterOn) { ?>
	<script language="JavaScript" src="../inc/js/filterlist.js"></script>
	<?php } ?>
	<script language="JavaScript">
	/*
		função que chama a rotina de processamento,
		altere somente o nome da página
	*/
	function save() {
		getSelectedObjects();
		parent.content.document.frm.target = "control";
		parent.content.document.frm.action = "../content/object_associate.php";
		parent.content.document.frm.submit();
	}
	function initiate() {
		<?php if ($filterOn) { ?>
		parent.content.document.frm.searchSource.focus();
		<?php } ?>
	}
	</script>
</head>
<body class="contentBODY" onLoad="initiate()">

<?php
pageTitle("Objeto","Associação");

// botões de ações,
// configure conforme sua necessidade
$button = new Button;
$button->addItem(" Salvar ", "javascript:save()",          "content");
$button->addItem(" Fechar ", "../content/object_list.php", "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=$id");
$tabs->addItem("Associação", true);
$tabs->addItem("Ordenação",  false, "../content/object_ordering.php?id=$id");
$tabs->addItem("Detalhe",    false, "../content/object_read.php?id=$id");
$tabs->addItem("Lista 1:N",  false, "../content/object_list_1n.php?id=$id",3);
echo $tabs->writeHTML();
?>
<form name="frm" method="post">
<!-- variável de controle -->
<input type="hidden" name="executed" value="s">
<!-- chave primária -->
<input type="hidden" name="f_id" value="">
<?php
// montagem da lista de origem
if ($filterOn) {
	$source  = "<input type=\"text\" name=\"searchSource\" size=\"30\" style=\"WIDTH: 100%\" onKeyUp=\"javascript:filterSource.set(this.value)\"><br>";
} else {
	$source = "";
}
$source .= "<select id=\"f_source\" name=\"f_source\" multiple size=\"16\" style=\"WIDTH: 100%\" valign=\"top\">";
while ($rsSource->getrow()) {
	$source .= "<option value='".$rsSource->field("id")."'>".$rsSource->field("val")."</option>";
}
$source .= "</select>";

// montagem da lista de destino
if ($filterOn) {
	$destination  = "<input type=\"text\" name=\"searchDestino\" size=\"30\" style=\"WIDTH: 100%\" onKeyUp=\"javascript:filterDestination.set(this.value)\"><br>";
} else {
	$destination  = "";
}
$destination .= "<select name=\"f_destination[]\" id=\"f_destination\" multiple size=\"16\" style=\"WIDTH: 100%;\">";
while ($rsDestination->getrow()) {
	$destination .= "<option value='".$rsDestination->field("id")."'>".$rsDestination->field("val")."</option>";
}
$destination .= "</select>";

// monta botões
if ($filterOn) {
	$js = "filterDestination.init();filterSource.init();";
} 
$buttons  = "<input type=\"button\" onClick=\"move(parent.content.document.frm.f_source,parent.content.document.frm.f_destination);$js\" value=\" >> \">";
$buttons .= "<br><br>";
$buttons .= "<input type=\"button\" onClick=\"move(parent.content.document.frm.f_destination,parent.content.document.frm.f_source);$js\" value=\" << \">";


// layout
$table = new Table("","100%",3);
// cabeçalho
$table->addColumnHeader("Objetos Disponíveis",  false, "47%", "C");
$table->addColumnHeader("",                     false,  "6%", "C");
$table->addColumnHeader("Objetos Selecionados", false, "47%", "C");
$table->addRow();
// caixas de seleção
$table->addData($source,      "C");
$table->addData($buttons,     "C");
$table->addData($destination, "C");
$table->addRow();
echo $table->writeHTML();
echo help("Associação","Utilize a tecla CTRL pressionada para efetuar seleção múltipla de registros.");
?>
<!-- layout do formulário -->
<?php if ($filterOn) { ?>
<script>
var filterSource      = new filterlist(document.frm.f_source);
var filterDestination = new filterlist(document.frm.f_destination);
</script>
<?php } ?>
</form>


</body>
</html>
<?php
$conn->close();
?>
Return current item: PhpWAFr - PHP Web Application Framework