Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde,
Criei uma tela de registro de relatórios porem percebi que o usuário teria a necessidade de ver os últimos relatórios enviados por ele para não haver a possibilidade de repetição do relatório ou ate a falta de envio de um relatório por esse usuário, sendo assim criei um sistema de busca que mostra os 10 últimos relatórios enviados por esse usuário que fica na mesma tela onde ele envia um novo relatório, porem percebi dois problemas:
1° O usuário teria que clicar em um botão para mostrar esses 10 últimos relatórios enviados o certo seria esses 10 últimos relatórios aparecer automaticamente assim q ele entrar na tela para enviar o relatório
2° o resultado dado pelo sistema de busca dos 10 últimos relatórios esta triplicando o resultado ou seja um relatório que o usuário envio aparece três vezes no resultado
agradeço se puderem me dar uma força
Mayck
Segue o codigo em php da tela de registro de relatórios
<?php require_once('Connections/dbconnect_report2.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "erro.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tb_report (id, usuario, voo_arr, voo_dep, res_ocorrencia, avi, skiff, relatorio, data_ini) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['usuario'], "text"),
GetSQLValueString($_POST['voo_arr'], "date"),
GetSQLValueString($_POST['voo_dep'], "date"),
GetSQLValueString($_POST['res_ocorrencia'], "text"),
GetSQLValueString($_POST['avi'], "int"),
GetSQLValueString($_POST['skiff'], "int"),
GetSQLValueString($_POST['relatorio'], "text"),
GetSQLValueString($_POST['data_ini'], "date"));
mysql_select_db($database_dbconnect_report2, $dbconnect_report2);
$Result1 = mysql_query($insertSQL, $dbconnect_report2) or die(mysql_error());
$insertGoTo = "gerarrelatoriousu.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tb_report (id, usuario, voo_arr, voo_dep, res_ocorrencia, avi, skiff, relatorio, data_ini) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['usuario'], "text"),
GetSQLValueString($_POST['voo_arr'], "date"),
GetSQLValueString($_POST['voo_dep'], "date"),
GetSQLValueString($_POST['res_ocorrencia'], "text"),
GetSQLValueString($_POST['avi'], "int"),
GetSQLValueString($_POST['skiff'], "int"),
GetSQLValueString($_POST['relatorio'], "text"),
GetSQLValueString($_POST['data_ini'], "date"));
mysql_select_db($database_dbconnect_report2, $dbconnect_report2);
$Result1 = mysql_query($insertSQL, $dbconnect_report2) or die(mysql_error());
$insertGoTo = "gerarrelatoriousu.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tb_report (id, usuario, voo_arr, voo_dep, res_ocorrencia, avi, skiff, relatorio, data_ini) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['usuario'], "text"),
GetSQLValueString($_POST['voo_arr'], "date"),
GetSQLValueString($_POST['voo_dep'], "date"),
GetSQLValueString($_POST['res_ocorrencia'], "text"),
GetSQLValueString($_POST['avi'], "int"),
GetSQLValueString($_POST['skiff'], "int"),
GetSQLValueString($_POST['relatorio'], "text"),
GetSQLValueString($_POST['data_ini'], "date"));
mysql_select_db($database_dbconnect_report2, $dbconnect_report2);
$Result1 = mysql_query($insertSQL, $dbconnect_report2) or die(mysql_error());
$insertGoTo = "gerarrelatoriousu.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$colname_Recordset1 = "1";
if (isset($_POST['busca'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['busca'] : addslashes($_POST['busca']);
}
mysql_select_db($database_dbconnect_report2, $dbconnect_report2);
$query_Recordset1 = sprintf("SELECT * FROM tb_report WHERE usuario = '%s' ORDER BY id DESC", $colname_Recordset1);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $dbconnect_report2) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1']; $all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css"> font-family: Arial, Helvetica, sans-serif;
}
.style2 {
color: #EEEEEE;
font-weight: bold;
}</style>
</head>
<body>
<div align="center">
<p class="style1">Gerar Relatório ! </p>
<p class="style1">
</p>
<p> </p>
<p> </p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Usuario:</td>
<td colspan="2"><input name="usuario" type="text" value="<?php echo $_SESSION['MM_Username'] ?>" size="32" readonly="true"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Voo_arr:</td>
<td colspan="2"><input name="voo_arr" type="text" value="0000" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Voo_dep:</td>
<td colspan="2"><input type="text" name="voo_dep" value="0000" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Res_ocorrencia:</td>
<td colspan="2"><select name="res_ocorrencia">
<option value="sem ocorrência">sem ocorrência</option>
<option value="com ocorrência">com ocorrência</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Avi:</td>
<td colspan="2"><input type="text" name="avi" value="00" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Skiff:</td>
<td colspan="2"><input type="text" name="skiff" value="00" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap>Relatorio:</td>
<td colspan="2"><textarea name="relatorio" cols="100" rows="20">digite aqui o seu relatório
</textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Gerar Relatório"></td>
<td><div align="right">
<input type="reset" name="Reset" value="limpar">
</div></td>
</tr>
</table>
<p>
<input type="hidden" name="id" value="">
<input type="hidden" name="data_ini" value="">
<input type="hidden" name="MM_insert" value="form1">
</p>
</form>
<form name="form3" method="post" action="">
<div align="left">
<input name="busca" type="text" id="busca" value="<?php echo $_SESSION['MM_Username'] ?>" readonly="true">
<input type="submit" name="Submit" value="Mostrar ultimo relatórios enviados">
</div>
</form>
<table border="0">
<tr bgcolor="#770000">
<td colspan="7"><div align="center" class="style2">Ultimos relatorios enviados </div></td>
</tr>
<tr bgcolor="#BBBBBB">
<td><div align="center">voo_arr</div></td>
<td><div align="center">voo_dep</div></td>
<td><div align="center">res_ocorrencia</div></td>
<td><div align="center">avi</div></td>
<td><div align="center">skiff</div></td>
<td><div align="center">relatorio</div></td>
<td><div align="center">data_ini</div></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['voo_arr']; ?></td>
<td><?php echo $row_Recordset1['voo_dep']; ?></td>
<td><?php echo $row_Recordset1['res_ocorrencia']; ?></td>
<td><?php echo $row_Recordset1['avi']; ?></td>
<td><?php echo $row_Recordset1['skiff']; ?></td>
<td><?php echo $row_Recordset1['relatorio']; ?></td>
<td><?php echo $row_Recordset1['data_ini']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<form name="form2" method="post" action="menu_usu.php">
<div align="left">
<p>
<input type="submit" name="Submit" value="Sair">
</p>
</div>
</form>
<p> </p>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>Carregando comentários...