-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalterar_tag.php
More file actions
116 lines (108 loc) · 3.74 KB
/
Copy pathalterar_tag.php
File metadata and controls
116 lines (108 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php include 'header.php' ?>
<?php include 'nav.php' ?>
<?php include 'authenticate.php';
include 'conexao.php';
if(!$admin){ ?>
<div class="container alert alert-danger">
<h2>Você não tem permissão para acessar essa página, por favor faça login no sistema.</h2>
</div>
<?php die;
}
$rowTag = NULL;?>
<?php
function limpaCaracter($valor){
$valor = trim($valor);
$valor = str_replace(".", "", $valor);
$valor = str_replace(",", "", $valor);
$valor = str_replace("-", "", $valor);
$valor = str_replace("/", "", $valor);
return $valor;
}
if (isset($_POST['pesquisar'])) {
if (!empty($_POST['pesquisar'])) {
$tag = limpaCaracter($_POST['pesquisar']);
$sqlT = "SELECT * FROM tags WHERE id = '$tag';";
$resultadoT = mysqli_query($conexao,$sqlT);
$rowTag = mysqli_fetch_row($resultadoT);
if ($rowTag != NULL) {
$pessoaId = $rowTag[1];
$mestra = $rowTag[2];
$dataInicio = $rowTag[3];
$dataFim = $rowTag[4];
if ($mestra == 1){
echo "<p class=\"text-warning\">Não é possível alterar nem remover tag mestra</p> ";
$tag="";
}
}else {
echo "<p class=\"text-warning\">Tag nao encontrada!</p> ";
}
}
}
if (isset($_POST['altera'])) {
$tagA = limpaCaracter($_POST['altTag']);
$update = $_POST['usuario'];
for ($i=0; $i < 3; $i++) {
$sqlAL = "UPDATE tags SET pessoa_id = '$update' WHERE id = $tagA;";
$resultadoAL = mysqli_query($conexao, $sqlAL);
if ($resultadoAL){
echo "<p class=\"text-success\"> TAG alterada com sucesso.</p>";
}
}
}
if (isset($_POST['apagar'])) {
$tagD = limpaCaracter($_POST['altTag']);
$sqlD = "DELETE FROM tags WHERE id = '$tagD';";
$resultadoD = mysqli_query($conexao, $sqlD);
if ($resultadoD){
echo "<p class=\"text-success\"> TAG removida com sucesso.</p>";
}
}
?>
<main>
<div class="container">
<h1 class="text-info">Alterar TAG</h1>
<div class="formgroup">
<form class="" action="alterar_tag.php" method="post">
<div class="form-group">
<label for="tag">Digite o número da TAG</label>
<input class="form-control tag-field" type="text" name="pesquisar" value="<?php if (isset($_POST['pesquisar'])) {echo $tag ;} ?>">
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit" name="">Pesquisar</button>
</div>
</form>
</div>
<?php if (($rowTag != NULL) && ($mestra==0)): ?>
<h2>Editar</h2>
<form class="" action="alterar_tag.php" method="post">
<div class="form-group">
<label for="altTag">Número TAG</label>
<input class="form-control tag-field" type="text" name="altTag" value="<?php echo $tag ?>">
</div>
<div class="form-group">
<label for="usuario">Usuário</label>
<?php
$sqlPes = "SELECT * FROM pessoas";
$resultadoPes = mysqli_query($conexao, $sqlPes);
$rowsP = mysqli_fetch_all($resultadoPes);
?>
<select name="usuario" id="usuario" class="form-control">
<?php
for ($i=0; $i < count($rowsP); $i++) {
$id_pes = $rowsP[$i][0];
$nome_pes = $rowsP[$i][1];
echo "<option value=\"$id_pes\"";
if ($pessoaId == $id_pes) {
echo"selected";
}
echo ">$nome_pes</option>";
}?>
</select>
<div class="form-group">
<button class="btn btn-success" type="submit" name="altera">Alterar</button>
</div>
<button class="btn btn-danger" type="" name="apagar">Apagar TAG</button>
<?php endif; ?>
</div>
</main>
<?php include 'footer.php' ?>