<?php
include("../sol/sessao.php");
//Verifica permissao
$nivelnecessario = 0;
if ($_SESSION["univel"] > $nivelnecessario)
{
header('Location:/sol/index.php?erroperm='.$nivelnecessario);
}
//Conecta ao banco e abre query
$dados = new dados();
$dados->get_conexao();
$idand = str_replace('#', '', $_GET["id"]);
$editando = false;
if (!empty($idand))
{
if ($_GET['acao'] == 'editar')
{
$sql = "UPDATE
andamentos
SET
id_departamento = ".$_POST['departamento'].",
andamento = '".TrataStr($_POST['andamento'])."',
andamento_prosseguimento = ".$_POST['andpro'].",
andamento_retorno = ".$_POST['andret'].",
status = '".$_POST['status']."'
WHERE
id_andamento = ".$idand;
mysql_query($sql);
header('Location:/sol/andamentos.php');
}
else
{
$editando = true;
//Lista andamento para edicap
$sql = "SELECT * FROM andamentos WHERE id_andamento = ".$idand;
$rs = mysql_query($sql);
$reg = mysql_fetch_array($rs);
}
}
else
{
$idand = 0;
if ($_GET['acao'] == 'inserir')
{
$sql = "INSERT INTO
andamentos (id_departamento, andamento, andamento_prosseguimento, andamento_retorno, status)
VALUES
(".$_POST['departamento'].", '".TrataStr($_POST['andamento'])."', ".$_POST['andpro'].",
".$_POST['andret'].", '".$_POST['status']."')";
mysql_query($sql);
header('Location:/sol/andamentos.php');
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SolBT - <?=$sitenome?></title>
<link rel="StyleSheet" type="text/css" href="../sol/includes/estilos.css" id="estilo" />
<script language='JavaScript' src='../sol/includes/FuncoesTela.js' type="text/javascript"></script>
<script language='JavaScript' type="text/javascript">
function TrimCampo(campo)
{
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
document.getElementById(campo).value = document.getElementById(campo).value.trim();
}
function Salvar()
{
if (document.getElementById('andamento').value.length == 0)
{
alert('Informe uma descrição para o andamento.');
document.getElementById('andamento').focus();
return;
}
if (document.getElementById('departamento').value == 0)
{
alert('Informe o departamento ao qual este andamento é vinculado.');
document.getElementById('departamento').focus();
return;
}
if ((document.getElementById('andpro').value == 0) && (document.getElementById('andret').value == 0))
{
//alert('Vocẽ deve informar um andamento de prosseguimento ou de retorno.');
//document.getElementById('andpro').focus();
//return;
}
else
{
if (document.getElementById('andpro').value == document.getElementById('andret').value)
{
alert('O andamento de retorno não pode ser igual ao de prosseguimento.');
document.getElementById('andret').focus();
return;
}
}
if (document.getElementById('status').value == '')
{
alert('Informe um status para este andamento.');
document.getElementById('status').focus();
return;
}
//Posta
document.forms.frmEditar.submit();
}
</script>
</head>
<body onload="document.getElementById('andamento').focus();">
<?php
include("../sol/includes/menus.php");
?>
<table width="100%">
<?php
include("../sol/includes/top.php");
?>
<!-- CONTEUDO DA PAGINA -->
<tr>
<td id="Conteudo">
<br />
<span class="Titulo">Cadastro de andamento</span><br /> <br />
<?php
if ($editando) echo 'Editando andamento '.str_pad($idand, 3, "0", STR_PAD_LEFT).'<br /> <br />';
?>
<form action="andamento_editar.php?acao=<? if ($idand == 0) echo 'inserir'; else echo 'editar&id='.$idand; ?>" method="post" id="frmEditar">
Andamento: <input type="text" id="andamento" name="andamento" value="<?=utf8_encode($reg["andamento"])?>" maxlength="50" size="50" onblur="TrimCampo('andamento');" />
<br /> <br />
Vinculado ao departamento:
<select name="departamento" id="departamento">
<option value="0">Selecione...</option>
<?php
//Lista todos os andamentos acima mais os de abertura
$sql = "SELECT id, departamento FROM departamentos ORDER BY departamento ASC";
$rsx = mysql_query($sql);
while ($regx = mysql_fetch_array($rsx))
{
echo '<option value="'.$regx["id"].'"';
if ($regx["id"] == $reg["id_departamento"]) echo ' selected';
echo '>'.utf8_encode($regx["departamento"]).'</option>';
}
?>
</select>
<br /> <br />
Andamento de prosseguimento:
<select name="andpro" id="andpro">
<option value="0"></option>
<?php
//Lista todos os andamentos acima mais os de abertura
$sql = "SELECT id_andamento, andamento FROM andamentos WHERE id_andamento != ".$idand." ORDER BY andamento ASC";
$rsx = mysql_query($sql);
while ($regx = mysql_fetch_array($rsx))
{
echo '<option value="'.$regx["id_andamento"].'"';
if ($regx["id_andamento"] == $reg["andamento_prosseguimento"]) echo ' selected';
echo '>'.utf8_encode($regx["andamento"]).'</option>';
}
?>
</select>
<br /> <br />
Andamento de retorno:
<select name="andret" id="andret">
<option value="0"></option>
<?php
//Lista todos os andamentos acima mais os de abertura
$sql = "SELECT id_andamento, andamento FROM andamentos WHERE id_andamento != ".$idand." ORDER BY andamento ASC";
$rsx = mysql_query($sql);
while ($regx = mysql_fetch_array($rsx))
{
echo '<option value="'.$regx["id_andamento"].'"';
if ($regx["id_andamento"] == $reg["andamento_retorno"]) echo ' selected';
echo '>'.utf8_encode($regx["andamento"]).'</option>';
}
?>
</select>
<br /> <br />
Status:
<select name="status" id="status">
<option value="">Selecione...</option>
<option value="A"<? if ($reg["status"] == "A") echo ' selected'; ?>>Abertura</option>
<option value="N"<? if ($reg["status"] == "N") echo ' selected'; ?>>Andamento normal</option>
<option value="F"<? if ($reg["status"] == "F") echo ' selected'; ?>>Fechamento</option>
</select>
<br /> <br />
<input type="button" value="Salvar" id="btnSalvar" onclick="Salvar();" style="font-weight:bold;" />
<input type="button" value="Cancelar" onclick="window.open('andamentos.php', '_self');" />
</form>
<br /> <br />
</td>
</tr>
<!-- FIM DE CONTEUDO DA PAGINA -->
<?php
include("../sol/includes/rp.php");
?>
</table>
</body>
</html>
<?php
@mysql_close();
?>