0
I’m doing a system of accreditation with checkin and checkout. It’s all working, but I just can’t do the following: When I do the checkin, he registers; when I do it again, he registers again. I need him to file this record saying he’s already "inside the fair"; only when he goes through checkout he may enter again.
<?php
require_once('../controller/checkinsController.php');
salvarCheckin();
?>
<?php
require_once ('../config.php');
require_once ("../inc/visibilidade-header.php");
?>
<script>
jQuery(function($){
$("#campoCPF").mask("999.999.999-99");
});
</script>
<?php if ($_REQUEST['posicao']=='checkin'):
$posicao = '1';
?>
<h2>Check-in</h2>
<?php endif; ?>
<?php if ($_REQUEST['posicao']=='checkout'):
$posicao = '0';
?>
<h2>Check-out</h2>
<?php endif; ?>
<form id="formCheckin" action="add.php?posicao_atual=<?php echo $posicao; ?>" method="post">
<!-- area de campos do form -->
<hr />
<div class="row">
<div class="form-group col-md-2">
<label for="name">CODIGO DE BARRA</label>
<input type="text" name="codigo_barra" onfocus="if(this.value.length==10){submeter()}" maxlength="10" onchange="if(this.value.length==10){submeter()}" onkeyup="if(this.value.length==10){submeter()}" onblur="if(this.value.length==10){submeter()}" id="codigo_barra" />
</div>
</div>
<div id="actions" class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-success" >Estou aqui!</button>
<a href="../index.php" class="btn btn-default">Voltar</a>
</div>
</div>
</form>
<?php include(FOOTER_TEMPLATE); ?>
This is my Controller
:
<?php
/**
* Created by PhpStorm.
* User: andre.luis.a.costa
* Date: 03/12/2016
* Time: 16:07
*/
require_once('../config.php');
require_once(DBAPI);
$checkin = null;
/**
*
*/
function salvarCheckin() {
$db = open_database();
if (!empty($_POST['codigo_barra'])) {
$posicao = $_REQUEST['posicao_atual'];
$today = date_create('now', new DateTimeZone('America/Recife'));
$checkin["codigo_barra"] = $_POST['codigo_barra'];
$checkin["posicao"] = $posicao;
$checkin['created'] = $today->format("Y-m-d H:i:s");
$checkin['modified'] = $checkin['created'];
$retorno = ultimaPosicaoVisitante($checkin['codigo_barra'], $db, $posicao);
$retorno = validarCadastroCodigoVisitante($checkin['codigo_barra'], $db);
if($retorno){
save('checkins', $checkin);
echo "<script>alert(".json_encode($_SESSION['message']).")</script>";
} else{
$_SESSION['message'] = "Visitante não cadastrado! Favor realizar o cadastro!";
echo "<script>alert(".json_encode($_SESSION['message']).")</script>";
}
}
}
function validarCadastroCodigoVisitante($codigo_barra, $db) {
$existeVisitante = false;
$sql = "SELECT * FROM visitantes WHERE codigo_barra = '$codigo_barra' ";
$search = mysqli_query($db, $sql);
//mysqli_result['num_rows']
// var_dump($search);
if (isset($search)) {
$row = mysqli_fetch_array($search,MYSQLI_ASSOC);
}
if(isset($row) > 0){
$existeVisitante = true;
}
return $existeVisitante;
}
function ultimaPosicaoVisitante($codigo_barra, $db, $posicao) {
$posicaoVisitante = false;
$sql = "SELECT * FROM checkins WHERE codigo_barra = '$codigo_barra' LIMIT 1 ORDER BY id DESC ";
$search = mysqli_query($db, $sql);
//mysqli_result['num_rows']
// var_dump($search);
if (isset($search)) {
$row = mysqli_fetch_array($search,MYSQLI_ASSOC);
}
if(isset($row['posicao']) == "$posicao"){
$posicaoVisitante = true;
}
return $posicaoVisitante;
}
?>
That function
save($checkin)
is included in a databasecheckin
, correct? The bid would be to check, before saving, if thecodigo_barra
already exists in this table, no? Or it can do checkin and checkout several times?– Daniel
Exactly friend @Daniel is coming from a DB, the barcode is coming from the DB too, I’m not getting exactly this, that the same codigo_barra Ex: 05552225 gave 'Checkin' --- if I go to pass this again appears the error message, only releasing if you pass the 'Checkout'
– LionDrums
That line:
$retorno = validarCadastroCodigoVisitante($checkin['codigo_barra'], $db);

is returning true or false, right? You need to do something similar, with what you did invalidarCadastroCodigoVisitante
before saving (or inside the save function). Make aSELECT
and see if there’s anyone with that barcode in the checkin register.– Daniel
like exactly, that’s where the problem is, I’m not finding the way to do it, it could be clearer, I’m beginner with it :P @Daniel
– LionDrums
Ué, you did it dude: you checked if the barcode already exists in the visitors table. Just do the same thing on the checkin table. It would be something like
SELECT * FROM checkins WHERE codigo_barra = '$codigo_barra'
and checks if the return came empty:count($checkins)
.– Daniel
Nothing, I created Select in Salvarchekin and it made no difference! I think that I fell all over myself... because he’s constantly creating, he’s not stopping at what he’s already created! Can’t you help me by showing me the code above?? help me friend! Please! Let me be clearer!!! ! a number EX: 12345678 presses the Checkin it records there it gets like 1, if again the 12345678 press on the Checkin it’s going to creating again with the 0 instead of locking his passage!!! !
– LionDrums
Does it look like 1? Where? Dude, put the code of this function
save()
if it doesn’t make it hard to help.– Daniel
that comment was before you sent, I’m testing aqi ja 1 Mint qe ja te te te me funfou! : D
– LionDrums