<? include_once ("bancodedados_.php"); ?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<?

$id = $_GET['idxs'];

if($id != '' or NULL){

	if (isset($_POST["nome"])){
	$nome = $_POST["nome"];
	$email = $_POST["email"];
	$cpf = $_POST["cpf"];
	$valor = $_POST["valor"];
	$inse = mysqli_query($link, "update pedidos set nome='$nome', email='$email', cpf='$cpf', valor='$valor' where id='$id'");
	if (mysqli_affected_rows($link) > 0){
		echo "Alterado com sucesso...";
	}
	}

$get = mysqli_query($link, "select * from pedidos where id='$id'");
$get_r = mysqli_fetch_array($get);
$nome = $get_r['nome'];
$email = $get_r['email'];
$cpf = $get_r['cpf'];
$valor = $get_r['valor'];
?>
      </p>
      <div style=" width:680px; margin:10px; text-align:center; font:Arial, Helvetica, sans-serif;">
      
      <form action="" method="post">
       <p> <a href="editar_pedido.php">Editar outro pedido</a></p>
     <div style="">Nome:<br />
      <input name="nome" type="text" value="<?=$nome?>" size="60" id="nome" style=" border: 1px solid #CCC" /></div>
        <div style=""> Email:<br />
      <input name="email" type="text" value="<?=$email?>" size="60" id="email" style=" border: 1px solid #CCC" /></div>
	  <div style=""> CPF:<br />
	  <input name="cpf" type="text" value="<?=$cpf?>" size="60" id="cpf" style=" border: 1px solid #CCC" /></div>
	  <div style=""> Valor:<br />
      <input name="valor" type="text" value="<?=$valor?>" size="60" id="valor" style=" border: 1px solid #CCC" /></div>
      <div style=" text-align:center">
      <input type="submit" name="submit" value="Alterar" class="bt rosa" /></div>
      </form>
               </div>
      
      <?


}else{


	?>
      <?

	$func = $_GET['func'];
	if($func == 'deletar'){
		$act = $_GET['act'];
		$exec = mysqli_query($link, "DELETE FROM pedidos WHERE id ='$act'");
		echo"<b>Pedido deletado com sucesso</b>";


		echo "<script>location.href='editar_pedido.php';</script>";


	}


	?>
      <table width="800" align="center" id="tabela-rank">
        <tr>
          <th width="20" scope="col" abbr="Pos.">Id</th>
          <th width="150" scope="col" abbr="Level">Nome</th>
          <th width="200" scope="col" abbr="Cash.">Email</th>
          <th width="150" scope="col" abbr="Cash.">CPF</th>
		  <th width="40" scope="col" abbr="Cash.">Valor</th>
        </tr>
        <?php 





 if (!isset($_GET["pg"])) {


        $pg = 0;


    } else{


	if (!is_numeric($_GET["pg"])){


	$pg = 0;


	}

	$pg = $_GET["pg"];


	}





$numreg = 200;
$inicial = $pg * $numreg;



if(isset($_POST['pesquisa'])){


$pesquisa = $_POST['pesquisa'];


$sql = "SELECT *  FROM pedidos WHERE 'id' LIKE '%$pesquisa%' order by id DESC LIMIT $inicial,$numreg";


$r = mysqli_query($link, $sql);


}else{


$sql = "SELECT * from pedidos order by id DESC LIMIT $inicial, $numreg";


$r = mysqli_query($link, $sql);


}





while($row = mysqli_fetch_array($r))


  {


	  $ids = $row['id'];


	  echo"<tr>\n";


	  echo "<td align='left'>" . $row['id'] . "</td>\n";


	  echo "<td align='left'>" . $row['nome'] . "</td>\n";


	  echo "<td align='left'>" . $row['email'] . "</td>\n";
	  
	  
	  echo "<td align='left'>" . $row['cpf'] . "</td>\n";
	  

	  echo "<td align='left'>" . $row['valor'] . "</td>\n";	


	  echo "<td align='center'><a href='?idxs=".$ids."'><img src='img/b_edit.png' /></a>


	  <a href='?act=".$ids."&func=deletar'><img src='img/b_drop.png' /></a></td>\n";


	  echo"</tr>\n";


  }


?>
      </table>
      <? }?>
</body>
</html>