This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvendi-libro.php
74 lines (62 loc) · 2.66 KB
/
vendi-libro.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
70
71
72
73
74
<?php
$root= ".";
require_once ("./globale.php");
unset($_SESSION['redirect_url']);
if(!isset($_SESSION['Username'])){
header("Location: login.php");
exit();
}
if(isset($_POST['submit_vendi_libro'])){
$venditore = $_SESSION['Username'];
$titolo = contrassegnaParoleInglesi($_POST['titolo']);
$autore = contrassegnaParoleInglesi($_POST['autore']);
$categoria = contrassegnaParoleInglesi($_POST['categoria']);
$anno = $_POST['anno'];
$descrizione = contrassegnaParoleInglesi($_POST['descrizione']);
$prezzo = $_POST['prezzo'];
if($_FILES['book_picture_path']['size'] > 0){
$book_picture_path = $_FILES['book_picture_path']['tmp_name'];
$book_picture_name = $_FILES['book_picture_path']['name'];
$book_picture_size = $_FILES['book_picture_path']['size'];
$book_picture_type = $_FILES['book_picture_path']['type'];
$book_picture_error = $_FILES['book_picture_path']['error'];
$book_picture = file_get_contents($book_picture_path);
$book_picture = "./media/book-pictures/" . $username . "_" . time() . "_" . $book_picture_name;
if(!move_uploaded_file($book_picture_path, $book_picture))
$book_picture = null;
}
else
$book_picture = null;
if($book_picture != null) {
if($db->vendi_libro($venditore, $titolo, $autore, $categoria, $anno, $descrizione, $prezzo, $book_picture)) {
header("Location: compro-vendo-libri.php?messaggio=Libro aggiunto con successo");
exit();
}
else {
header("Location: vendi-libro.php?messaggio=Errore nell'aggiunta del libro");
exit();
}
}else{
if($db->vendi_libro($venditore, $titolo, $autore, $categoria, $anno, $descrizione, $prezzo)){
header("Location: compro-vendo-libri.php?messaggio=Libro aggiunto con successo");
exit();
}
else{
header("Location: vendi-libro.php?messaggio=Errore nell'aggiunta del libro");
exit();
}
}
}
$vendilibro_template = $template_engine->load_template("vendi-libro-template.html");
$vendilibro_template->insert_multiple("menu", build_menu());
if(isset($_GET['messaggio'])){
$messaggio = htmlspecialchars($_GET['messaggio']);
$vendilibro_template->insert_multiple("messaggio", "<div class='messaggioerrore'>".$messaggio."</div>");
}else{
$vendilibro_template->insert_multiple("messaggio", "");
}
$vendilibro_template->insert_multiple("suggeriti", build_lista_suggeriti());
$vendilibro_template->insert("header", build_header());
$vendilibro_template->insert("goback", build_goback());
$vendilibro_template->insert("footer", build_footer());
echo $vendilibro_template->build();