-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
executable file
·284 lines (270 loc) · 7.47 KB
/
user.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
<?php
include ('includes/header.php');
include('includes/db_connexion.php');
$query ="SELECT * FROM system_group";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
?>
<style type="text/css">
.categorie-left{
width: 50%;
float: left;
}
.categorie-right{
width: 50%;
float: right;
}
.panel-h{
color: #fff!important;
background-color: green!important;
border-color: #ddd;
height: 41px;
}
</style>
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title categorie-left">Liste des Utilisateurs</h3>
<h3 class="card-title categorie-right" align="right">
<button type="button" name="add" class="btn btn-primary btn-sm add" id="add"><i class="nav-icon fas fa-plus"></i> Ajouter</button>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div id="user_data" class="table-responsive">
</div>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
<div id="user_dialog" title="Add Data">
<form method="post" id="user_form">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>Saisissez le Nom</label>
<input type="text" name="nom" id="nom" class="form-control" />
<span id="error_nom" class="text-danger"></span>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Saisissez le Prenom</label>
<input type="text" name="prenom" id="prenom" class="form-control" />
<span id="error_prenom" class="text-danger"></span>
</div>
</div>
</div>
<div class="form-group">
<label>Adresse mail</label>
<input type="text" name="email" id="email" class="form-control" />
<span id="error_email" class="text-danger"></span>
</div>
<div class="form-group">
<label>Saisissez le login</label>
<input type="text" name="login" id="login" class="form-control" />
<span id="error_login" class="text-danger"></span>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>Mot de passe</label>
<input type="text" name="password" id="password" class="form-control" />
<span id="password_err" class="text-danger"></span>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Saisissez a nouveau</label>
<input type="text" name="confirm_password" id="confirm_password" class="form-control" />
<span id="confirm_password_err" class="text-danger"></span>
</div>
</div>
</div>
<div class="form-group">
<label>Selectionner groupe</label>
<select class="form-control" type="text" id="role" name="role">
<option value="">Selectionnez</option>
<?php if ($total_row > 0){
foreach ($result as $row){?>
<option value="<?php echo $row["id_group"];?>"><?php echo $row["name"]."-".$row["id_group"];?></option>
<?php }}?>
</select>
<span id="error_role" class="text-danger"></span>
</div>
<div class="form-group">
<input type="hidden" name="action" id="action" value="insert" />
<input type="hidden" name="hidden_id" id="hidden_id" />
<input type="submit" name="form_action" id="form_action" class="btn btn-info" value="Ajouter" />
</div>
</form>
</div>
<div id="action_alert" title="Action">
</div>
<div id="delete_confirmation" title="Confirmation">
<p>Êtes-vous sûr de vouloir supprimer ces données?</p>
</div>
<?php include ('includes/footer.php') ?>
<script>
$(document).ready(function(){
load_data();
function load_data()
{
$.ajax({
url:"user_fetch.php",
method:"POST",
success:function(data){
$('#user_data').html(data);
}
})
}
$("#user_dialog").dialog({
autoOpen: false,
width:600
});
$("#add").click(function(){
$('#user_dialog').attr('title', 'Add Data');
$('#action').val('insert');
$('#form_action').val("Ajouter");
$('#user_form')[0].reset();
$('#form_action').attr('disabled', false);
$('#user_dialog').dialog('open');
});
$('#user_form').on('submit', function(event){
event.preventDefault();
var error_nom = '';
var error_prenom = '';
var error_login = '';
var error_role = '';
if ($('#nom').val() == '')
{
error_nom = 'Le nom est obligatoire';
$('#error_nom').text(error_nom);
$('#nom').css('border-color', '#cc0000');
}
else
{
error_nom = '';
$('#error_nom').text(error_nom);
$('#nom').css('border-color', '');
}
if ($('#prenom').val() == '')
{
error_prenom = 'Le prenom est obligatoire';
$('#error_prenom').text(error_prenom);
$('#prenom').css('border-color', '#cc0000');
}
else
{
error_prenom = '';
$('#error_prenom').text(error_prenom);
$('#prenom').css('border-color', '');
}
if ($('#login').val() == '')
{
error_login= 'Le login est obligatoire';
$('#error_login').text(error_login);
$('#login').css('border-color', '#cc0000');
}
else
{
error_login = '';
$('#error_login').text(error_login);
$('#login').css('border-color', '');
}
if ($('#role').val() == '')
{
error_role= 'Le group est obligatoire';
$('#error_role').text(error_role);
$('#role').css('border-color', '#cc0000');
}
else
{
error_role = '';
$('#error_role').text(error_role);
$('#role').css('border-color', '');
}
if (error_nom != '' || error_prenom !='' || error_login != '' || error_role != '')
{
return false;
}
else
{
$('#form_action').attr('disabled', 'disabled');
var form_data = $(this).serialize();
$.ajax({
url:"action/action.php",
method:"POST",
data:form_data,
success:function(data)
{
$('#user_dialog').dialog('close');
$('#action_alert').html(data);
$('#action_alert').dialog('open');
load_data();
$('#form_action').attr('disabled', false);
}
});
}
});
$('#action_alert').dialog({
autoOpen:false
});
$(document).on('click', '.edit', function(){
var id = $(this).attr('id');
var action = 'fetch_single';
$.ajax({
url:"action/action.php",
method:"POST",
data:{id:id, action:action},
dataType:"json",
success:function(data)
{
$('#nom').val(data.nom);
$('#prenom').val(data.prenom);
$('#login').val(data.login);
$('#role').val(data.role);
$('#email').val(data.email);
$('#password').val(data.password);
$('#user_dialog').attr('title', 'Edit Data');
$('#action').val('update');
$('#hidden_id').val(id);
$('#form_action').val('Update');
$('#user_dialog').dialog('open');
}
});
});
$('#delete_confirmation').dialog({
autoOpen:false,
modal: true,
buttons:{
Ok : function(){
var id = $(this).data('id');
var action = 'delete';
$.ajax({
url:"action/action.php",
method:"POST",
data:{id:id, action:action},
success:function(data)
{
$('#delete_confirmation').dialog('close');
$('#action_alert').html(data);
$('#action_alert').dialog('open');
load_data();
}
});
},
Cancel : function(){
$(this).dialog('close');
}
}
});
$(document).on('click', '.delete', function(){
var id = $(this).attr("id");
$('#delete_confirmation').data('id', id).dialog('open');
});
});
</script>