Ir para conteúdo

Pedido/recados


tklucas

Posts Recomendados

Não sei ao certo onde postar, por isso estou postando aqui.

É um sistema bem simples e desenvolvido a algum tempo.

Espero que seja útil para alguem, mesmo que para estudo.

 

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sistema de Pedidos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<p align="center">
<?php
include("functions.php");
if(isset($_POST['Submit']))
{
$name = safeText($_POST['nome']);
$email = safeText($_POST['email']);
$town = safeText($_POST['cidade']);
$state = safeText($_POST['estado']);
$request = safeText($_POST['pedido']);

if(createRequest($name, $town, $state, $email, $request))
	echo("Pedido enviado com sucesso!");
else
	echo("Falha ao enviar pedido!");
}
?>
<form name="form1" method="post" action="">
<div align="center"><strong>Envie um Pedido</strong>
   </div>
<table width="40%" border="1" align="center">
 <tr>
   <td width="12%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Nome:</font></td>
   <td width="88%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
     <input name="nome" type="text" id="nome" size="40">
   </font></td>
 </tr>
 <tr>
   <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email:</font></td>
   <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
     <input name="email" type="text" id="email" size="40">
   </font></td>
 </tr>
 <tr>
   <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Cidade:</font></td>
   <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
     <input name="cidade" type="text" id="cidade" size="40">
   </font></td>
 </tr>
 <tr>
   <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Estado:</font></td>
   <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
     <input name="estado" type="text" id="estado" size="40">
   </font></td>
 </tr>
 <tr>
   <td height="51"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Recado:</font></td>
   <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
     <textarea name="pedido" cols="35" rows="10"></textarea>
   </font></td>
 </tr>
 <tr>
   <td height="52" colspan="2"><div align="center">
     <input type="submit" name="Submit" value="Enviar Recado">
   </div></td>
   </tr>
</table>
</p>

<p align="center"> </p>
</form>
</body>
</html>

 

functions.php - that's the magic!

<?php
/*
- functions core [event listener, file parser]
@ lolima@me.com
*/
function safeText($name)
{ 
   $except = array("<var>", "<id>", "<next>"); 
   return str_replace($except, '', $name); 
}

function returnDatabase()
{
$fhandler = fopen("db.txt", "a+");
$db = fread($fhandler, filesize("db.txt")+1);
fclose($fhandler);

return $db;
}

function showRequests()
{
$db = returnDatabase();
$requests = explode("<next>", $db);
foreach($requests as $request)
{
	$request = explode("<id>", $request);
	if($request[0] != "" && $request[1] != "")
	{
		$request_var = explode("<var>", $request[0]);
		echo("<br><b>".$request_var[0]."</b> - ".$request_var[3]." (".$request_var[1]." - ".$request_var[2].") diz:<br><i>".$request_var[4]."</i><br>");
		echo("<a href=\"admin_index.php?delete=".$request[1]."\">[Deletar]</a><br>");
	}
}

return;
}

function createRequest($name, $town, $state, $email, $text)
{
$aid = 1000;
$db = returnDatabase();
$requests = explode("<next>", $db);
foreach($requests as $request)
{
	$aid++;
}

$fhandler = fopen("db.txt", "a+");
fwrite($fhandler, "$name<var>$town<var>$state<var>$email<var>$text<id>$aid<next>");
fclose($fhandler);

return true;
}

function deleteRequest($aid)
{
$newDatabase = "";
$db = returnDatabase();
$requests = explode("<next>", $db);
foreach($requests as $request)
{
	$request = explode("<id>", $request);
	if($request[1] != $aid)
	{
		$newDatabase = $newDatabase.$request[0]."<id>".$request[1]."<next>";
	}
}

$fhandler = fopen("db.txt", "w");
fwrite($fhandler, $newDatabase);
fclose($fhandler);

return true;	
}


function refreshPage($page)
{
header("location:$page");
}

?>

 

login.php

<?php
/*
-login administração
@lolima@me.com
*/
ob_start();

@session_start();
$admin_senha="12345";
if(isset($_POST['password']) && $_POST['password'] == $admin_senha)
{
 $_SESSION['logged_in'] = true;
 header("location: admin_index.php");
}
if(isset($_GET['logout']) && $_GET['logout'] == "true")
{
 @session_destroy();
 header("location: index.php");
}

?>
<html>
<head>
<title>Administração</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body link="#000000" vlink="#000000" alink="#000000">
<form name="form1" method="post" action="">
<p align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Administração<br>
     <font color="#666666" size="1">Sistema de Pedidos</font></strong></font></p>
<hr>
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
 Senha:</font> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
 <input name="password" type="password" id="password3">
 <input type="submit" name="Submit" value="Entrar">
 </font>
</div>
<div align="center"></div>
<hr>
<div align="center">
 <p><font color="#666666" size="1" face="Verdana, Arial, Helvetica, sans-serif">Acesso
     restrito, somente pessoal autorizado.<br>
 Seu IP:
     [ <?php echo($_SERVER['REMOTE_ADDR']); ?> ]</font></p>
 <p align="right"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Desenvolvido
     por lolima@me.com</font></p>
</div>
<p align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font></p>
</form>
</body>
</html>

 

admin_index.php

<?php
/*
- Pedidos 
@ lolima@me.com
*/
include("functions.php");
ob_start();
@session_start();
?>

<html>
<head>
<title>Administração </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body link="#000000" vlink="#000000" alink="#000000">
<?php
if(isset($_SESSION['logged_in']))
{
$delete = $_GET['delete'];
?>
 <div align="center">
 <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Bem
         vindo a administração de pedidos
         - <a href="admin_index.php">Atualizar</a> - <a href="login.php?logout=true">Logout</a></strong></font></p>
 <hr>
 <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
 <?php
 	if($delete != "")
{
	if(deleteRequest($delete))
	{
		echo("Pedido deletado com successo!<br>");
	}
}
 	showRequests();
 ?>
 </font>
 <hr>
 <p align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Desenvolvido por lolima@me.com</font></p>
 <p> </p>
</div>
<?php
}
?>
</body>
</html>

 

FAVOR NÃO RETIRAR OS CRÉDITOS

 

Não é necessário utilizar MySQL, o db é um arquivo .txt que salva os recados.

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...