-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.php
113 lines (93 loc) · 2.96 KB
/
file.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
<?php
include 'connect.php';
// check id param
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = -1;
}
?>
<!DOCTYPE html>
<html lang="en"></html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fiche contact</title>
<link href="styles.css" rel="stylesheet">
<script src="xtras/jquery.min.js"></script>
<link rel="icon" type="image/png" href="favicon.ico" />
</head>
<body>
<script>
var user = null;
var id = <?php echo $id; ?>;
$(document).ready(function() {
if (id >= 0) {
loadData(id);
}
});
let fields = [
<?php
$n = 0;
foreach ($fields as $f => $v) {
if ($n > 0) echo (", ");
echo ("\"$f\"");
$n++;
}
?>
];
function displayUser(){
fields.forEach((field, idx) => {
if (user) {
if (user[field]) $("#" + field).val(user[field]);
else $("#" + field).val("");
} else {
$("#" + field).val("");
}
});
if (user && user.avatarpath) {
console.log(user.avatar);
var ts = new Date().getTime(); // to avoid cache problems
$("#avatar").attr("src", user.avatarpath + "?" + ts);
} else {
$("#avatar").attr("src", "avatars/user.png");
}
}
function loadData(userId) {
$.post("./dbio.php", {
action: "loadbyid",
id: userId
},
function(json) {
console.log(json);
var data = JSON.parse(json);
user = data.data;
console.log(user);
displayUser();
}
);
}
</script>
<div class="container">
<p> <a href="index.php">Trombinoscope</a> </p>
<div class="tb-picture tb-picture-big">
<img id="avatar" src="avatars/user.png" alt="avatar">
</div>
<?php
include 'config.php';
foreach ($fields as $f => $v) {
echo '<div class="formgroup">';
echo '<label>' . $v["label"] . '</label> ';
if ($v["input"] == "textarea") {
echo '<textarea readonly id="' . $f . '" name="' . $f . '" cols="80" rows="5"';
if(isset($v['other']) ) { foreach($v['other'] as $index => $value) {echo ' '.$index .($value !== null ? '="'.$value.'"' : '');} } echo '></textarea>'.PHP_EOL;
} else {
echo '<input readonly type="' . $v["input"] . '" name="' . $f . '" id="' . $f . '" value=""';
if(isset($v['other']) ) { foreach($v['other'] as $index => $value) {echo ' '.$index .($value !== null ? '="'.$value.'"' : '');} } echo '>'.PHP_EOL;
}
echo ('</div>');
}
?>
</div>
</body>