-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditar_perfil.php
302 lines (243 loc) · 9.54 KB
/
editar_perfil.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
include 'header_nonav.php';
$query = mysqli_query($link, "SELECT * FROM users WHERE id='".$_SESSION['login']['1']."'");
$info_user = mysqli_fetch_assoc($query);
$nome = $info_user['nome'];
$apelido = $info_user['apelido'];
$email = $info_user['email'];
$password = $info_user['password'];
$foto = $info_user['foto'];
$telefone = $info_user['telefone'];
$data_nascimento = $info_user['data_nascimento'];
?>
<div id="uploadimageModal" class="modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Redimensionar Imagem</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body text-center" style="margin: 0 auto;">
<div class="col-md-8 text-center">
<div id="image_demo" style="width:350px; margin-top:30px"></div>
</div><br>
<div>
<button class="btn btn-primary crop_image btn-lg" style="width: 100%;">Feito</button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" id="fechar_modal">Fechar</button>
</div>
</div>
</div>
</div>
<div style="display: inline-block;padding-top: 2%; width: 81%;" id="second_nav_content" class="Neue-regular text-white">
<div data-aos="zoom-in-right" style="padding-left: 4%">
<h1 style="color: #414042; font-size: 80px;" class="Neue-bold" id="dashboard_title">Editar Perfil</h1>
</div>
<div class="col-md-8" style="margin: 0 auto;">
<div class="card" style="background-color: #fff; border:0px; margin-bottom: 100px;">
<div class="card-body text-center">
<p class="text-danger Neue-bold" id="error"><?php if (isset($_SESSION['error'])) { echo $_SESSION['error']; unset($_SESSION['error']); } ?></p>
<p class="text-success Neue-bold" id="sucesso"><?php if (isset($_SESSION['success'])) { echo $_SESSION['success']; unset($_SESSION['success']); } ?></p>
<div class="col-md-4" style="margin: 0 auto;">
<img class="img-responsive foto_perfil" src="<?php echo $foto; ?>" style="width: 150px; border-radius: 50%;"><br>
<br>
<div class="btn btn-warning btn-file" style="width: 100%;">
<div id="mudar_foto">Mudar Foto</div> <input type="file" name="file_perfil" id="file_perfil">
</div>
</div>
<br><br><br>
<div class="col-sm-4" style="display: inline-block;">
<label id="label_form_editar">Nome</label>
<div class="form-group">
<input type="text" name="nome" class="form-control" value="<?php echo $nome; ?>" id="nome">
</div>
</div>
<div class="col-sm-4" style="display: inline-block;">
<label id="label_form_editar">Apelido</label>
<div class="form-group">
<input type="text" name="apelido" class="form-control" value="<?php echo $apelido; ?>" id="apelido">
</div>
</div><br>
<div class="col-sm-4" style="display: inline-block;">
<label id="label_form_editar">Email</label>
<div class="form-group">
<input type="email" name="email" class="form-control" value="<?php echo $email; ?>" id="email">
</div>
</div>
<div class="col-sm-4" style="display: inline-block;">
<label id="label_form_editar">Password</label>
<div class="form-group">
<input type="password" name="password" class="form-control" value="secretpass" id="password">
</div>
</div><br>
<div class="col-sm-4" style="display: inline-block;">
<label id="label_form_editar">Data de Nascimento</label>
<div class="form-group">
<input type="date" name="data_nascimento" class="form-control" value="<?php echo $data_nascimento ?>" id="data_nascimento">
</div>
</div>
<div class="col-sm-4" style="display: inline-block;">
<label id="label_form_editar">Número de Telemóvel</label>
<div class="form-group">
<input type="number" name="telefone" class="form-control" value="<?php echo $telefone; ?>" id="telemovel">
</div>
</div><br><br><br>
<div class="col-md-8" style="margin: 0 auto;">
<button class="bnt btn-primary btn-lg" style="width: 100%;" id="editar_perfil">Alterar Dados</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$image_crop = $('#image_demo').croppie({
enableExif: true,
viewport: {
width:200,
height:200,
type:'square' //circle
},
boundary:{
width:300,
height:300
}
});
var formData = new FormData();
$("#file_perfil").change(function(){
if (document.getElementById("file_perfil").files.length > 0) {
$("#mudar_foto").html('<span class="spinner-border spinner-border-sm"></span> Carregando');
console.log("a ir buscar o file");
$("#mudar_foto").html('<span class="spinner-border spinner-border-sm"></span> Carregando');
$('#editar_perfil').prop('disabled', true);
$("#editar_perfil").html('<span class="spinner-border spinner-border-sm"></span> Carregando Foto');
var name = document.getElementById("file_perfil").files[0].name;
var oFReader = new FileReader();
oFReader.onload = function (event) {
$image_crop.croppie('bind', {
url: event.target.result
}).then(function(){
console.log('jQuery bind complete');
});
}
oFReader.readAsDataURL(document.getElementById("file_perfil").files[0]);
$('#uploadimageModal').modal('show');
//oFReader.readAsDataURL(document.getElementById("file_perfil").files[0]);
//formData.append("file", document.getElementById('file_perfil').files[0]);
//console.log("appended");
}
});
$("#fechar_modal").click(function(event) {
setTimeout(
function()
{
$('#editar_perfil').prop('disabled', false);
$("#editar_perfil").html('Alterar Dados');
$("#mudar_foto").html('Mudar Foto <i class="fas fa-check"></i>');
}, 1500);
});
$(".crop_image").click(function(event) {
$image_crop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function(response){
formData.append("file", response);
});
$('#uploadimageModal').modal('hide');
setTimeout(
function()
{
$('#editar_perfil').prop('disabled', false);
$("#editar_perfil").html('Alterar Dados');
$("#mudar_foto").html('Mudar Foto <i class="fas fa-check"></i>');
}, 1500);
});
$("#editar_perfil").click(function(event) {
var nome = $("#nome").val();
var apelido = $("#apelido").val();
var email = $("#email").val();
var password = $("#password").val();
var telemovel = $("#telemovel").val();
var date = new Date($('#data_nascimento').val());
day = date.getDate();
month = date.getMonth() + 1;
year = date.getFullYear();
var data = [day, month, year].join('/');
console.log("NOME: " + nome + " Apelido: " + apelido + " email: " + email + "telemovel" + telemovel + "Data" + data);
if (nome == "" || apelido == "" || email == "" || password == "" || data == "" || telemovel == "") {
$("#error").text("Preencha todos os campos");
} else {
formData.append('nome', nome);
formData.append('apelido', apelido);
formData.append('email', email);
formData.append('password', password);
formData.append('data', data);
formData.append('telemovel', telemovel);
$.ajax({
url: "ajax/editar_perfil.php",
data: formData,
type: "POST",
cache: false,
contentType: false,
processData: false,
dataType : 'json',
beforeSend: function() {
/*
$('#progress_formulario').show();
$("#span_enviar_anexo").html("<div id='loader-icon'><img src='img/loader.gif' style='width: 21%;' /></div>");
//$('#loader-icon').show();
$('.progress-bar').width('50%');
$('#enviar').prop('disabled', true);
*/
},
success:function(data)
{
//console.log(JSON.stringify(data));
$(".foto_perfil").attr("src", data.foto_perfil);
$(".nome_perfil").text(data.nome);
$(".apelido_perfil").text(data.apelido);
if (data.status == "0") {
$("#error").text(data.mensagem);
} else {
$("#sucesso").text(data.mensagem);
}
},
error:function(data){
$("#error").text(data);
}
});
}
});
if (window.matchMedia('(max-width: 768px)').matches) {
$("#left_dashboard_nav").hide();
$("#btn_responsive_nonav").show();
$("#btn_responsive_nonav").css('display', 'inline-block');
$("#second_nav_content").css('width', '96%');
$("#btn_responsive_nonav_2").css("display", "block");
}
$("#btn_responsive_nonav").click(function(event) {
$("#btn_responsive_nonav").hide(300);
$("#left_dashboard_nav").css('width', '100%', 'important');
$("#left_dashboard_nav").show(300);
$("#menu_left").css('padding-top', '0%', 'important');
$("#second_nav_content").css('display', 'none');9
$("#img_dash_div").css('padding-top', '10%', 'important');
$("#img_dash").css('width', '40%', 'important');
//$("#second_nav_content").css('width', '82%');
//$("#second_nav_content").css('padding-left', '5%');
});
$("#btn_responsive_nonav_2").click(function(event) {
$("#left_dashboard_nav").hide(300);
$("#btn_responsive_nonav").show(300);
$("#btn_responsive_nonav").css('display', 'inline-block');
$("#second_nav_content").css('width', '96%');
$("#second_nav_content").css('display', 'inline-block');
//$("img_dash_div").css('padding-top', '10%', 'important');
});
});
</script>
<script async src="//cdn.iframe.ly/embed.js" charset="utf-8"></script>
<?php
include 'footer.php';
?>