-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
122 lines (98 loc) · 4.99 KB
/
profile.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
<?php
if(!isset($_SESSION['user_id']) && empty($_SESSION['user_id'])){
echo "<script type='text/javascript'> document.location = './index.php?page=login'; </script>";
exit();
}
$idusers = (int)$_SESSION['user_id'];
$sql = "SELECT * FROM users";
$stmt = $pdo->prepare($sql);
$stmt->execute([$idusers]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
?>
<?=template_header('Profile')?>
<div class="my-form">
<div class="row justify-content-center">
<div class="col-sm-8">
<div class="card user-form">
<div class="card-header">
<h1 class="card-title">Uporabniški podatki</h1>
</div>
<div class="card-body">
<form class="content user-info" method="post">
<div class="form-group row">
<label class="col-md-4 col-form-label text-md-right" for="fname">Ime</label>
<div class="col-md-6">
<input type="text" class="form-control" name="fname" id="fname" value="<?=$result['fname']?>" disabled>
</div>
<label class="col-md-4 col-form-label text-md-right" for="lname">Priimek</label>
<div class="col-md-6">
<input type="text" class="form-control" name="lname" id="lname" value="<?=$result['lname']?>" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label text-md-right" for="num_ani">Število živali</label>
<div class="col-md-6">
<?php
$sql = "SELECT COUNT(*) FROM animals WHERE fk_idusers = ?";
$total_animals = $pdo->query("SELECT * FROM animals WHERE fk_idusers = $idusers")->rowCount()
?>
<input type="text" class="form-control" name="num_ani" id="num_ani" value="<?=$total_animals?>" disabled>
</div>
</div>
<div class="form-group row password">
<label class="col-md-4 col-form-label text-md-right" for="password">Staro geslo</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password" id="old_pass" placeholder="Staro geslo" disabled required>
</div>
<label class="col-md-4 col-form-label text-md-right" for="password">Novo geslo</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password" id="new_pass" placeholder="Novo geslo" disabled required>
</div>
<label class="col-md-4 col-form-label text-md-right" for="confirm_password">Potrdite geslo</label>
<div class="col-md-6">
<input type="password" class="form-control" name="confirm_password" id="confirm_password" placeholder="Potrdite geslo" disabled required>
</div>
</div>
<div class="col-md-6 offset-md-4">
<input type="button" name="edit" class="btn btn-primary" id="btnEdit" value="Spremeni geslo">
</div>
<div class="col-md-6 offset-md-4">
<button type="submit" name="update" class="btn btn-primary" id="update" value="Shrani">Shrani geslo</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$("#update").click(function(e){
e.preventDefault();
var old_pass = $( "#old_pass" ).val();
var new_pass = $( "#new_pass" ).val();
var confirm_password = $( "#confirm_password" ).val();
console.log(old_pass);
console.log(new_pass);
console.log(confirm_password);
$.ajax({
type: 'POST',
data: 'old_pass=' + old_pass + '&new_pass=' + new_pass + '&confirm_password=' + confirm_password,
url:'./inc/user.pass-update.inc.php',
success:function(data){
alert(data);
}
});
})
</script>
<script>
$(document).ready(function () {
$('.user-info input[type=password]').prop("disabled", true);
$("input[name=edit]").on("click", function(){
$("input[type=password]").removeAttr("disabled");
})
$("input[name=update]").on("click",function(){
$(".user-info input[type=text], .user-info input[name=update]").prop("disabled",true);
})
})
</script>
<?=template_footer()?>