-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-put.php
More file actions
172 lines (142 loc) · 5.86 KB
/
admin-put.php
File metadata and controls
172 lines (142 loc) · 5.86 KB
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
<?php
include "admin-verification.php";
include "header.php";
$message = "";
$employeCourant = (new EmployeBuilder())->build();
if(isset($_GET['id'])) {
$employeCourant = (new EmployeDao())->getById($_GET['id']);
}
if (estRetourFormulaire()) {
$message = putUser($employeCourant, $_POST);
if(isset($_GET['id'])) {
$employeCourant = (new EmployeDao())->getById($_GET['id']);
}
}
?>
<div class="container">
<div class="page-header">
<div id="message">
<?php
if (isset($message)) {
echo $message;
}
?>
</div>
<?php
if(isset($_GET['id'])) {
echo "<h1>Modifier un utilisateur</h1>";
} else {
echo "<h1>Créer un nouvel utilisateur</h1>";
}
?>
</div>
<form method="post" action="admin-put.php<?php if(isset($_GET['id'])){ echo "?id=" . $_GET['id']; } ?>" enctype="multipart/form-data">
<?php if(isset($_GET['id'])){
echo "<input type=\"hidden\" id=\"id\" name=\"id\" value=\"" . $_GET['id'] . "\"/>";
} ?>
<label>
Prénom : <input type="text" name="prenom" id="prenom" placeholder="(ex : Olivier)"
onkeyup="proposeDonnees()" value="<?php echo $employeCourant->getFirstName(); ?>">
</label><br>
<label>
Nom : <input type="text" name="nomfamille" id="nomfamille" placeholder="(ex : Lafleur)"
onkeyup="proposeDonnees()" value="<?php echo $employeCourant->getLastName(); ?>">
</label><br>
<label>
Nom d'utilisateur : <input type="text" name="username" id="username" placeholder="(ex : lafleuro)"
value="<?php echo $employeCourant->getUsername(); ?>">
</label><br>
<label>
Courriel : <input type="email" name="email" id="email" placeholder="(ex: admin@admin.com)" value="<?php echo $employeCourant->getEmail(); ?>">
</label><br>
<label>
Image : <input type="hidden" name="MAX_FILE_SIZE" value="5000000"/>
<input type="file" name="image" accept="image/*" id="image"><br>
</label><br>
<div id="image-explication"></div>
<div id="image-container">
<?php
if ($employeCourant->getPicture() != "") {
echo '<img src="picture.php?id=' . $employeCourant->getId() . '" width="300px" id="target"><br>';
} else {
echo '<img src="" width="300px" height="400px" id="target"><br>';
}
?>
</div>
<input type="hidden" id="x" name="x"/>
<input type="hidden" id="y" name="y"/>
<input type="hidden" id="w" name="w"/>
<input type="hidden" id="h" name="h"/>
<label>
Mot de passe : <input type="password" name="password1">
</label><br>
<label>
Entrez de nouveau : <input type="password" name="password2">
</label><br>
<label>
Droits d'administrateur : <input type="checkbox" id="admin" name="admin" <?php if($employeCourant->isAdmin()) {echo "checked";} ?>>
</label><br>
<label>
Raspberry Pi :
<input type="checkbox" id="rpi" name="rpi" <?php if($employeCourant->getHasRpi()) {echo "checked";} ?>>
</label><br>
<label>
Couleur :</label> <br><?php include "colorpicker.php" ?>
<br>
<button type="submit" class="btn btn-primary">Créer</button>
</form>
</div>
<script language="JavaScript">
function proposeDonnees() {
var prenom = cleanUpSpecialChars(document.getElementById('prenom').value.toLowerCase());
var nomfamille = cleanUpSpecialChars(document.getElementById('nomfamille').value.toLowerCase());
if (prenom != "" || nomfamile != "") {
document.getElementById('email').value = prenom + "." + nomfamille + "@cll.qc.ca";
document.getElementById('username').value = nomfamille + prenom[0];
}
}
function cleanUpSpecialChars(str) {
str = str.replace(/[àáâãäå]/g, "a");
str = str.replace(/[èéêë]/g, "e");
str = str.replace(/[îï]/g, "i");
str = str.replace(/[ôö]/g, "o");
str = str.replace(/[ ']/g, "");
str = str.replace(/[ûü]/g, "u");
return str.replace(/[^a-z0-9]/gi, ''); // final clean up
}
</script>
<script language="JavaScript">
function afficheImage(evt) {
var file = evt.target.files[0];
if (!file.type.match('image.*')) {
return;
}
var reader = new FileReader();
reader.onload = (function () {
return function (e) {
var image = new Image();
image.src = e.target.result;
image.onload = function () {
if (this.width < 300 || this.height < 400) {
jQuery(function ($) {
$('#image').val("");
});
swal({
title: "Erreur",
text: 'Image trop petite. Elle doit être au moins de 300x400 px',
type: "error"
});
} else {
jcrop_api.enable();
jcrop_api.setImage(this.src);
jcrop_api.setSelect([0, 400, 300, 0]);
document.getElementById('image-explication').innerHTML = '<b>Veuillez sélectionner la zone d\'intérêt</b>';
}
};
};
})();
reader.readAsDataURL(file);
}
document.getElementById('image').addEventListener('change', afficheImage, false);
</script>
<?php include "footer.php"; ?>