Skip to content

Commit dd513f6

Browse files
committed
Merge branch 'master' of github.com:detiuaveiro/project-1---vulnerabilities-equipa_8
2 parents 649860e + 65de7b4 commit dd513f6

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

app_sec/img/20-1920x1080.jpg

194 KB
Loading

app_sec/img/440-1920x1080.jpg

181 KB
Loading

app_sec/news.php

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?php
2+
require '../php/check-session.php';
3+
4+
// check if there was a delete submition
5+
if(isset($_POST['delete-submit'])) {
6+
// require database handler page
7+
require '../php/db-handler.php';
8+
9+
// Make sure that value of ID is a integer and clean all other strings
10+
$id = intval($_POST['delete-submit'], 10);
11+
if (!is_int($id)){
12+
header("Location: news.php?submit=invalid");
13+
exit();
14+
}
15+
16+
// Delete news and reset auto increment to not leave blank IDs unused
17+
$sql = "DELETE FROM news WHERE id=".$id."; ALTER TABLE news AUTO_INCREMENT = 1";
18+
$query = mysqli_multi_query($conn, $sql);
19+
if(mysqli_affected_rows($conn) === -1){
20+
header("Location: news.php?submit=error");
21+
exit();
22+
}elseif(mysqli_affected_rows($conn) === 0){
23+
header("Location: news.php?submit=invalid");
24+
exit();
25+
}else{
26+
header("Location: news.php?submit=success");
27+
exit();
28+
}
29+
}
30+
?>
31+
32+
<!DOCTYPE html>
33+
<html lang="en">
34+
35+
<head>
36+
<meta charset="utf-8">
37+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
38+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
39+
40+
<title>Gerir notícias | Área de Administração</title>
41+
42+
<!-- Custom fonts for this template-->
43+
<link href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet" type="text/css">
44+
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
45+
46+
<!-- Custom styles for this template-->
47+
<link href="https://cdnjs.cloudflare.com/ajax/libs/startbootstrap-sb-admin-2/4.1.4/css/sb-admin-2.min.css" rel="stylesheet">
48+
49+
</head>
50+
51+
<body id="page-top">
52+
53+
<!-- Page Wrapper -->
54+
<div id="wrapper">
55+
56+
<!-- Sidebar -->
57+
<?php
58+
require 'sidebar.php';
59+
?>
60+
61+
<!-- Content Wrapper -->
62+
<div id="content-wrapper" class="d-flex flex-column">
63+
64+
<!-- Main Content -->
65+
<div id="content">
66+
67+
<!-- Navbar -->
68+
<?php
69+
require 'navbar.php';
70+
?>
71+
72+
<!-- Begin Page Content -->
73+
<div class="container-fluid">
74+
75+
<!-- Page Heading -->
76+
<div class="d-sm-flex align-items-center justify-content-between mb-4">
77+
<h1 class="h3 mb-0 text-gray-800">Gerir Notícias</h1>
78+
</div>
79+
80+
<!-- Content Row -->
81+
<div class="row">
82+
83+
<!-- Area Chart -->
84+
<div class="col-xl-8 col-lg-7">
85+
86+
<?php
87+
// put error messages
88+
if (isset($_GET['submit'])) {
89+
switch ($_GET['submit']) {
90+
case 'success':
91+
echo "
92+
<div class=\"alert alert-success alert-dismissible fade show\">
93+
<i class=\"fas fa-check-circle\"></i> <strong>SUCESSO:</strong> A notícia foi eliminada com sucesso!
94+
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">
95+
<span aria-hidden=\"true\">×</span>
96+
</button>
97+
</div>
98+
";
99+
break;
100+
101+
case 'invalid':
102+
echo "
103+
<div class=\"alert alert-danger alert-dismissible fade show\">
104+
<i class=\"fas fa-times-circle\"></i> <strong>ERRO:</strong> Não foi encontrada nenhuma notícia com o ID selecionado!
105+
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">
106+
<span aria-hidden=\"true\">×</span>
107+
</button>
108+
</div>
109+
";
110+
break;
111+
112+
case 'error':
113+
echo "
114+
<div class=\"alert alert-danger alert-dismissible fade show\">
115+
<i class=\"fas fa-times-circle\"></i> <strong>ERRO:</strong> Ocorreu um problema ao tentar eliminar a notícia!
116+
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">
117+
<span aria-hidden=\"true\">×</span>
118+
</button>
119+
</div>
120+
";
121+
break;
122+
}
123+
}
124+
?>
125+
126+
<div class="card shadow mb-4">
127+
<!-- Card Header - Dropdown -->
128+
<div
129+
class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
130+
<h6 class="m-0 font-weight-bold text-primary">Lista de notícias</h6>
131+
</div>
132+
<!-- Card Body -->
133+
<div class="card-body">
134+
<form method="post" onsubmit="return confirm('Tem a certeza que pretende eliminar permanentemente esta notícia?\nTenha em atenção que esta ação é irreversível.');">
135+
<div class="table-responsive">
136+
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
137+
<thead>
138+
<tr>
139+
<th>Título</th>
140+
<th>Imagem de Capa</th>
141+
<th>Corpo</th>
142+
<th>Autor</th>
143+
<th>Ações</th>
144+
</tr>
145+
</thead>
146+
<tbody>
147+
<?php
148+
// require database handler page
149+
require '../php/db-handler.php';
150+
151+
$sql = "SELECT * FROM news";
152+
$result = mysqli_query($conn, $sql);
153+
154+
while($row = mysqli_fetch_array($result)){
155+
echo "<tr>
156+
<td>" . $row['title'] . "</td>
157+
<td>
158+
<img src=". $row['img'] . " alt=\"\" width=\"150\" class=\"img-fluid\">
159+
</td>
160+
<td>" . $row['body'] . "</td>
161+
<td>" . $row['author'] . "</td>
162+
<td>
163+
<button title=\"Eliminar notícia " . $row['id'] . "\" type=\"submit\" class=\"btn btn-danger btn-block\" name=\"delete-submit\" value=\"" . $row['id'] . "\">
164+
<i class=\"fas fa-trash\"></i>
165+
</button>
166+
</td>
167+
</tr>";
168+
}
169+
?>
170+
</tbody>
171+
</table>
172+
</div>
173+
</form>
174+
</div>
175+
</div>
176+
</div>
177+
</div>
178+
</div>
179+
</div>
180+
</div>
181+
182+
</div>
183+
<!-- End of Page Wrapper -->
184+
185+
<!-- Scroll to Top Button-->
186+
<a class="scroll-to-top rounded" href="#page-top">
187+
<i class="fas fa-angle-up"></i>
188+
</a>
189+
190+
<!-- Bootstrap core JavaScript-->
191+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
192+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
193+
194+
<!-- Custom scripts for all pages-->
195+
<script src="https://cdnjs.cloudflare.com/ajax/libs/startbootstrap-sb-admin-2/4.1.4/js/sb-admin-2.min.js"></script>
196+
197+
</body>
198+
199+
</html>

0 commit comments

Comments
 (0)