-
Notifications
You must be signed in to change notification settings - Fork 0
/
retirar_campo.php
69 lines (51 loc) · 1.88 KB
/
retirar_campo.php
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
<html>
<body>
<h2>Bloco de Notas</h2>
<h4>Retirar campo</h4>
<?php
session_start();
include 'functions.php';
echo("<h5>Sessão de {$_SESSION['nome']} </h5>");
$connection=createConnection();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$campoId = test_input($_POST["campo_id"]);
}
$typeCounter = $_SESSION['aux'];
try{
$connection->beginTransaction();
//criar campocnt do novo campo (apagado)
$newCampoCounter = geraId(campocnt, campo, $connection);
//obter informacao do campo
$sql = "SELECT * from campo WHERE userid=".$_SESSION['id']." AND campocnt=$campoId AND typecnt=$typeCounter AND ativo=1";
$result = $connection->query($sql);
$rows = $result->fetchAll();
if (count($rows)<1) {
echo("<p>$sql</p>");
die('Campo inexistente' . mysql_error());
//significa que alguem apagou antes da transacao comecar
}
$nomeCampo = $rows[0]['nome'];
//receber novo idseq da nova entrada no log
$idSeq = geraIdSeq($connection);
//colocar ativa a 0
$sql = "UPDATE campo SET ativo=0 WHERE userid=".$_SESSION['id']." AND campocnt=$campoId AND ativo=1";
if ($connection->query($sql) === FALSE) {
die( "Error: " . $sql . "<br>" . $conn->error);
}
$sql = "INSERT INTO campo (userid, typecnt, campocnt, idseq, ativo, nome, pcampocnt)
VALUES (".$rows[0][userid].", ".$rows[0][typecnt].", $newCampoCounter, $idSeq, 0, '$nomeCampo', $campoId)";
if ($connection->query($sql) === FALSE) {
die( "Error: " . $sql . "<br>" . $conn->error);
}
$connection->commit();
} catch (Exception $e) {
$connection->rollBack();
echo "Failed: " . $e->getMessage();
}
echo("<br></br>");
echo("<p>Campo removido com sucesso</p>");
buttons();
$connection->close();
?>
</body>
</html>