-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretirar_pagina.php
64 lines (49 loc) · 1.77 KB
/
retirar_pagina.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
<html>
<body>
<h2>Bloco de Notas</h2>
<h4>Retirar página</h4>
<?php
session_start();
include('functions.php');
echo("<h5>Sessão de {$_SESSION['nome']} </h5>");
$connection=createConnection();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$pageId = test_input($_POST["pag_id"]);
}
try{
$connection->beginTransaction();
//criar page counter da nova pagina (apagada)
$newPageCounter = geraId(pagecounter, pagina, $connection);
//obter pagecounter da pagina
$sql = "SELECT * from pagina WHERE userid=".$_SESSION['id']." AND pagecounter=$pageId AND ativa=1";
$result = $connection->query($sql);
if (!$result) {
echo($sql);
die('Página inexistente ' . mysql_error());
//significa que alguem apagou antes da transacao comecar
}
$rows = $result->fetchAll();
//receber novo idseq da nova entrada no log
$idSeq = geraIdSeq($connection);
//colocar ativa a 0
$sql = "UPDATE pagina SET ativa=0 WHERE userid=".$_SESSION['id']." AND pagecounter=$pageId AND ativa=1";
if ($connection->query($sql) === FALSE) {
die( "Error: " . $sql . "<br>" . $conn->error);
}
$sql = "INSERT INTO pagina (userid, ppagecounter, nome, ativa, pagecounter, idseq)
VALUES (".$rows[0][userid].", $pageId, '".$rows[0][nome]."', 0, $newPageCounter, $idSeq)";
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>Página removida com sucesso</p>");
buttons();
$connection->close();
?>
</body>
</html>