-
Notifications
You must be signed in to change notification settings - Fork 0
/
designation.php
250 lines (238 loc) · 9.22 KB
/
designation.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
<?php
if (isset($_GET['a'])) {
$action = $_GET['a'];
} else {
$action = 'index';
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$index = true;
// Inclusion de fluxbb
define('PUN_ROOT', '../home/');
require PUN_ROOT.'include/common.php';
require 'functions.php';
if ($pun_user['is_guest'] == 1) { // L'utilisateur n'est pas connecté
header('Location: login.php');
exit();
} elseif ($pun_user['group_id'] == 1 || $pun_user['group_id'] == 2 || $pun_user['group_id'] == 11) {
// Configuration et connexion MySql
require_once ('config.php');
$sql = "SELECT competences_designation.id,
competences_designation.designation,
competences_designation.categories_id,
competences_categories.nom
FROM `competences_designation`
RIGHT JOIN `competences_categories` ON competences_categories.id=competences_designation.categories_id
ORDER BY competences_categories.nom ASC";
$query = $connexion->query($sql);
$designations = $query->fetchAll(PDO::FETCH_OBJ);
$query->closeCursor();
/* Création d'une désignation */
if ($action == 'new' && isset($_POST['submit']) && isset($_POST['des']) && isset($_POST['cat'])) {
$des = $connexion->quote($_POST['des'], PDO::PARAM_STR);
$cat = $connexion->quote($_POST['cat'], PDO::PARAM_STR);
$query = $connexion->query("SELECT id FROM `competences_categories` WHERE nom=".$cat);
$id = $query->fetch();
$query->closeCursor();
$cid = $id[0];
$sql = "INSERT INTO `competences_designation` (designation, categories_id) VALUES(".$des.", ".$cid.")";
if ($connexion->exec($sql)) {
$created = TRUE;
} else {
$created = FALSE;
}
} elseif ($action == 'new' && !isset($_POST['submit']) && !isset($_POST['des'])) {
$sql = "SELECT nom FROM `competences_categories`";
$query = $connexion->query($sql);
$categories = $query->fetchAll(PDO::FETCH_ASSOC);
$query->closeCursor();
}
/* Suppresion d'une désignation */
if ($action == 'delete' && isset($id)) {
$id = $connexion->quote($id, PDO::PARAM_INT);
$sql = "SELECT * FROM competences_designation WHERE id=".$id;
$query = $connexion->query($sql);
$array = $query->fetchAll(PDO::FETCH_ASSOC);
if (isset($array[0])) {
$sql = "DELETE FROM `competences_designation` WHERE id=".$id;
if ($connexion->exec($sql)) {
$deleted = TRUE;
} else {
$deleted = FALSE;
}
} else {
$deleted = FALSE;
}
$query->closeCursor();
}
/* Edition d'une désignation */
if ($action == 'edit' && isset($id) && isset($_POST['submit']) && isset($_POST['des']) && isset($_POST['cat'])) {
$des = $connexion->quote($_POST['des'], PDO::PARAM_STR);
$did = $connexion->quote($id, PDO::PARAM_INT);
$cat = $connexion->quote($_POST['cat'], PDO::PARAM_STR);
$query = $connexion->query("SELECT id FROM `competences_categories` WHERE nom=".$cat);
$id = $query->fetch();
$query->closeCursor();
$cid = $id[0];
$sql = "SELECT * FROM `competences_designation` WHERE id=".$did;
$query = $connexion->query($sql);
$array = $query->fetchAll(PDO::FETCH_ASSOC);
if (isset($array[0])) {
$sql = "UPDATE `competences_designation` SET designation=".$des.", categories_id=".$cid." WHERE id=".$did;
if ($connexion->query($sql)) {
$edited = TRUE;
} else {
$edited = FALSE;
}
} else {
$edited = FALSE;
}
$query->closeCursor();
} elseif ($action == 'edit' && isset($id) && !isset($_POST['submit']) && !isset($_POST['des'])) {
$did = $connexion->quote($id, PDO::PARAM_INT);
$sql = "SELECT competences_designation.designation FROM `competences_designation` WHERE competences_designation.id=".$did;
$query = $connexion->query($sql);
$nom = $query->fetch();
$query->closeCursor();
$sql = "SELECT nom FROM `competences_categories`";
$query = $connexion->query($sql);
$categories = $query->fetchAll(PDO::FETCH_ASSOC);
$query->closeCursor();
foreach ($designations as $des) {
if ($des->designation == $nom[0]) {
$current = $des->nom;
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Gestion des désignations</title>
</head>
<body>
<div id="container">
<? if ($action == 'index'): /* Liste des désignations */?>
<a href="?a=new">Nouvelle désignation</a>
<table id="designations">
<thead>
<tr>
<th>
Désignation
</th>
<th>
Catégorie
</th>
<th>
Actions
</th>
</tr>
</thead>
<tbody>
<? foreach ($designations as $des): ?>
<tr>
<td>
<?= $des->designation?>
</td>
<td>
<?= $des->nom?>
</td>
<td>
<a href="?a=delete&id=<?= $des->id ?>">Delete</a> <a href="?a=edit&id=<?= $des->id ?>">Edit</a>
</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
<? elseif ($action == 'delete' && isset($deleted)): /* Suppression d'une désignation */?>
<? if ($deleted == TRUE): ?>
<p>
La désignation
<?= $des[0]['nom']?>
à bien été supprimée !
</p>
<? else : ?>
<p>
La désignation n'a pas été supprimée !
</p>
<? endif; ?>
<a href="?a=index">Retour aux désignations</a>
<? elseif ($action == 'new'): /* Création d'une désignation */?>
<? if (isset($created) && $created == TRUE): ?>
<p>
La désignation
<?= $des?>
à bien été crée !
</p>
<? elseif (isset($created) && $created == FALSE): ?>
<p>
La désignation
<?= $des?>
n'a pas été crée !
</p>
<? endif; ?>
<form id="new" method="post">
<fieldset>
<legend>
Nouvelle désignation
</legend>
<input type="text" name="des" />
<select name="cat">
<? foreach ($categories as $cat): ?>
<option value="<?= $cat['nom'] ?>">
<?= $cat['nom']?>
</option>
<? endforeach; ?>
</select>
<input type="submit" name="submit" value="Créer" />
</fieldset>
</form><a href="?a=index">Retour aux désignations</a>
<? elseif ($action == 'edit' && isset($id)): /* Edition d'une désignation */?>
<? if (isset($edited) && $edited == TRUE): ?>
<p>
La désignation
<?= $des?>
à bien été éditée !
</p>
<? elseif (isset($edited) && $edited == FALSE): ?>
<p>
La désignation
<?= $des?>
n'a pas été éditée !
</p>
<? endif; ?>
<form id="edit" method="post">
<fieldset>
<legend>
Edition de désignation
</legend>
<input type="text" name="des" value="<?= $nom[0] ?>" />
<select name="cat">
<? foreach ($categories as $cat): ?>
<? if ($current == $cat['nom']): ?>
<option value="<?= $cat['nom'] ?>" selected="selected">
<?= $cat['nom']?>
</option>
<? else : ?>
<option value="<?= $cat['nom'] ?>">
<?= $cat['nom']?>
</option>
<? endif; ?>
<? endforeach; ?>
</select>
<input type="submit" name="submit" value="Editer" />
</fieldset>
</form><a href="?a=index">Retour aux désignations</a>
<? endif; ?>
<a href="index.php" title="Accueil">Retour au tableau des compétences</a>
</div>
</body>
</html>
<?php
}
else {
exit('Vous n\'êtes pas autorisés à venir ici !');
}
?>