-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontacto.php
181 lines (157 loc) · 6.65 KB
/
contacto.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
require_once 'conexao.php';
$email = array_key_exists('email', $_POST) ? $_POST['email'] : "";
$nome = array_key_exists('nome', $_POST) ? $_POST['nome'] : "";
$assunto = array_key_exists('assunto', $_POST) ? $_POST['assunto'] : "";
$mensagem = array_key_exists('mensagem', $_POST) ? $_POST['mensagem'] : "";
$msg_erro = "";
if (isset($_POST["newcontato"])) {
if ($email == "" || $nome == "" || $assunto == "" || $mensagem == "")
$msg_erro = "Campos não preenchidos";
else {
if ($conn->connect_errno) {
$code = $conn->connect_errno;
$message = $conn->connect_error;
$msg_erro = "Falha na ligação à BaseDados ($code $message)!";
} else {
$email = $conn->real_escape_string($email);
$nome = $conn->real_escape_string($nome);
$assunto = $conn->real_escape_string($assunto);
$mensagem = $conn->real_escape_string($mensagem);
$query = "INSERT INTO `contacto` (`email`, `nome`, `assunto`, `mensagem`) VALUES ('$email', '$nome', '$assunto', '$mensagem')";
$sucesso_query = $conn->query($query);
if ($sucesso_query) {
header("Location: contacto.php");
exit(0);
} else {
$code = $conn->errno;
$message = $conn->error;
$msg_erro = "Falha na query! ($code $message)";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
require_once 'sheets/head.php';
?>
<title>Contactos</title>
</head>
<body>
<header id="header" class="fixed-top ">
<?php
require_once 'sheets/navbar.php';
?>
</header>
<main id="main">
<section id="contact" class="contact section-bg">
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="info-box mb-4">
<i class="bx bx-map"></i>
<h3>Endereço</h3>
<p>Rua da Praia do Molho Leste, Peniche, 2520-206</p>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="info-box mb-4">
<i class="bx bx-envelope"></i>
<h3>Email</h3>
<p>[email protected]</p>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="info-box mb-4">
<i class="bx bx-phone-call"></i>
<h3>Telefone</h3>
<p>+351 262 777 111</p>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 ">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3014.977444350692!2d-9.368743958631846!3d39.35025750943084!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0xd1f48a9de96c075%3A0x59825346bd0e936a!2sPraia%20do%20Molhe%20Leste!5e1!3m2!1spt-PT!2spt!4v1679914429168!5m2!1spt-PT!2spt" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
</div>
<div class="col-lg-6">
<form id="contacto" action="contacto.php" method="POST" role="form" class="php-email-form" enctype="multipart/form-data">
<div class="row">
<?php
if (isset($_SESSION['authenticated'])) {
$query = "SELECT nome,email FROM users WHERE email = '{$_SESSION['email']}'";
$user = mysqli_query($conn, $query);
if ($user->num_rows) {
$row = $user->fetch_object();
$nome = $row->nome;
$email = $row->email;
}
?>
<div class="col-md-6 form-group">
<input type="text" class="form-control" name="nome" id="nome" placeholder="Nome" value="<?= $nome ?>" maxlength="30" readonly required>
</div>
<div class="col-md-6 form-group mt-3 mt-md-0">
<input type="email" class="form-control" name="email" id="email" placeholder="Email" value="<?= $email ?>" pattern="^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$" readonly required>
</div>
<?php
} else {
?>
<div class="col-md-6 form-group">
<input type="text" class="form-control" name="nome" id="nome" placeholder="Nome" maxlength="30" required>
</div>
<div class="col-md-6 form-group mt-3 mt-md-0">
<input type="email" class="form-control" name="email" id="email" placeholder="Email" pattern="^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$" required>
</div>
<?php
}
?>
</div>
<div class="form-group mt-3">
<input type="text" class="form-control" name="assunto" id="assunto" placeholder="Assunto" maxlength="60" required>
</div>
<div class="form-group mt-3">
<textarea class="form-control" name="mensagem" id="mensagem" rows="10" placeholder="Mensagem" style="resize: none" required></textarea>
</div>
<br>
<?php
if (isset($_SESSION['authenticated'])) {
?>
<div class="text-center"><button type="submit" name="newcontato" value="newcontato">Enviar</button></div>
<?php
} else {
?>
<div class="text-center" onclick="exibirAlerta()"><button type="submit">Enviar</button></div>
<?php
}
?>
</form>
</div>
</div>
</div>
</section>
</main>
<footer id="footer">
<?php
require_once 'sheets/footer.php';
?>
</footer>
<a href="#" class="back-to-top d-flex align-items-center
justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
<script src="assets/vendor/purecounter/purecounter_vanilla.js"></script>
<script src="assets/vendor/aos/aos.js"></script>
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/glightbox/js/glightbox.min.js"></script>
<script src="assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
<script src="assets/vendor/swiper/swiper-bundle.min.js"></script>
<!-- <script src="assets/vendor/php-email-form/validate.js"></script> -->
<script src="assets/js/main.js"></script>
<script src="assets/js/jquery-3.4.1.min.js"></script>
<script>
function exibirAlerta() {
alert("Só pode enviar uma mensagem se tiver o login feito!");
}
</script>
</body>
</html>