This repository was archived by the owner on Apr 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadminModificaLista.php
More file actions
151 lines (129 loc) · 6.85 KB
/
adminModificaLista.php
File metadata and controls
151 lines (129 loc) · 6.85 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
$title = "Modifica Lista Scarpe - CorsaIdeale";
$description = "Gestisci l'elenco delle scarpe disponibili su CorsaIdeale.";
$keywords = "lista,scarpe,gestione,catalogo,admin,modelli,recensioni";
require_once('dbconnection.php');
require_once('controls.php');
session_start();
use Conn\DbConnection;
setlocale(LC_ALL, 'it_IT');
$connection = new DbConnection();
if (!$connection->startDbConnection()) {
die("Connessione al database fallita.");
}
include "header.php";
$HTMLpage = file_get_contents('HTML/adminModificaLista.html');
if($connection->isAdmin($_SESSION["username"])){
$lista_scarpe = "";
$info = "";
if(isset($_POST['delete'])){
$idScarpa = intval($_POST['delete_id']);
$shoe = $connection->getShoe($idScarpa);
if($connection->deleteShoe($idScarpa)){
$info = '<p class="success_text" id="info" role="alert">La scarpa '.$shoe["nome"].' è stata eliminata con successo</p>';
}else{
$info = '<p class="error_text" id="info" role="alert">Errore: eliminazione non possibile, la scarpa non esiste</p>';
}
}
$lista_scarpe = "";
$query = "SELECT * FROM SCARPA WHERE nome LIKE '%' ";
if(!empty($_POST['nomescarpa'])){
$query = "SELECT * FROM SCARPA WHERE nome LIKE '%" . $_POST['nomescarpa'] . "%' ";
$HTMLpage = str_replace('value=""', 'value="' . $_POST['nomescarpa'] . '" selected', $HTMLpage);
}
if (!empty($_POST['marca']) AND $_POST['marca'] != 'all') {
$query = $query . "AND marca = '" . $_POST['marca']. "' ";
$HTMLpage = str_replace('value="' . $_POST['marca'] . '"', 'value="' . $_POST['marca'] . '" selected', $HTMLpage);
}
if (!empty($_POST['tipo']) AND $_POST['tipo'] != 'all') {
$query = $query . "AND tipo = '" . $_POST['tipo']. "' ";
$HTMLpage = str_replace('value="' . $_POST['tipo'] . '"', 'value="' . $_POST['tipo'] . '" selected', $HTMLpage);
}
if (!empty($_POST['ordina'])) {
$HTMLpage = str_replace('value="' . $_POST['ordina'] . '"', 'value="' . $_POST['ordina'] . '" selected', $HTMLpage);
if($_POST['ordina'] == "nomeCres"){
$query = $query . "ORDER BY nome ASC ";
}elseif($_POST['ordina'] == "nomeDesc"){
$query = $query . "ORDER BY nome DESC ";
}elseif($_POST['ordina'] == "votoCres"){
$query = $query . "ORDER BY votoexp ASC ";
}elseif($_POST['ordina'] == "votoDesc"){
$query = $query . "ORDER BY votoexp DESC ";
}elseif($_POST['ordina'] == "ordNonStand"){
$query = $query . "ORDER BY data_aggiunta ASC ";
}else{
$query = $query . "ORDER BY data_aggiunta DESC ";
}
}else{
$query = $query . "ORDER BY data_aggiunta DESC ";
}
$all_shoes = $connection->query($query);
$connection->endDbConnection();
$lista_scarpe .= '
<div class="table-wrapper-admin">
<p id="sum">Tabella che contiene tutte le scarpe presenti nel sito, sono presenti nome, marca, descrizione, tipo, <span lang="en">feedback</span> dell\'esperto e foto per ogni scarpa</p>
<table aria-describedby="sum" class="table-admin-list">
<caption>Lista di tutte le scarpe</caption>
<thead>
<tr>
<th scope="col">Nome</th>
<th scope="col" class="hide-tablet">Marca</th>
<th scope="col" class="hide-tablet">Descrizione</th>
<th scope="col" class="hide-mobile">Tipo</th>
<th scope="col" class="hide-mobile" lang="en">Feedback</th>
<th scope="col">Immagine</th>
<th scope="col">Comandi</th>
</tr>
</thead>
<tbody>
';
foreach($all_shoes as $shoe){
$lista_scarpe .= '
<tr>
<th class="table int-row" scope="row" lang="en">'.$shoe["nome"] .'</th>
<td class="table hide-tablet" lang="en">'.$shoe["marca"] .'</td>
<td class="table hide-tablet">'.$shoe["descrizione"] .'</td>
<td class="table hide-mobile">'.$shoe["tipo"] .'</td>
<td class="table hide-mobile"><span lang="en">'.$shoe["feedback"].'</span><br>
<div class="review-stars">
<img class="stars" src="assets/' . $shoe["votoexp"] . '.png" alt="" />('.
$shoe["votoexp"].')
</div>
</td>
<td><img src="assets/'.$shoe["immagine"] .'" alt="" class="scarpa-admin"/></td>
<td>
<a class="link-con-icona" aria-label="Modifica scarpa '.$shoe["nome"] .'" href="adminModificaScarpa.php?mod=' . urlencode($shoe['id']) . '"><img src="assets/edit.png" alt="modifica" class="icona" /></a>
<button type="button" aria-label="Elimina scarpa '.$shoe["nome"] .'" class="link-con-icona" name="delete-shoe-'.$shoe['id'].'" onclick="openModal(\'delete-shoe-admin-modal-'.$shoe['id'].'\')">
<img src="assets/delete.png" alt="elimina" class="icona" />
</button>
<div id="delete-shoe-admin-modal-'.$shoe['id'].'" class="delete-admin-modal hidden">
<div class="modal-content-delete">
<div class="modal-header">
<span class="close-btn" onclick="closeModal(\'delete-shoe-admin-modal-'.$shoe['id'].'\')">×</span>
<h2>Conferma Eliminazione</h2>
<p>Sei sicuro di voler eliminare questa scarpa?</p>
</div>
<form id="delete-review-admin-form-'.$shoe['id'].'" action="'.$_SERVER['PHP_SELF'].'" method="POST">
<input type="hidden" class="delete-id" value="'.$shoe['id'].'"/>
<button aria-label="Conferma eliminazione '.$shoe["nome"] .'" class="delete-button" type="submit">Conferma</button>
</form>
</div>
</div>
</td>
</tr>
';
}
$lista_scarpe .= '
</tbody>
</table>
</div>
';
$HTMLpage = str_replace("{lista_scarpe}", $lista_scarpe, $HTMLpage);
$HTMLpage = str_replace("{info}", $info, $HTMLpage);
echo $HTMLpage;
include "footer.php";
}else{
$connection->endDbConnection();
header("Location: error404.php");
}
?>