-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
382 lines (322 loc) · 13.4 KB
/
index.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
session_start();
include_once 'config.php';
if (!isset($_SESSION['user'])){
header("Location: login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PHP Phone Directory</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
</head>
<input type="checkbox" name="" class="form-check-input" id="">
<body class="bg-light">
<div class="container">
<div class="row">
<div class="col-md-8 mx-auto bg-dark rounded shadow py-3">
<h1 class="text-center text-light">PHP Phone Directory</h1>
<a href="logout.php">
<h3 class='float-right text-danger px-2 py-0 bg-success rounded-circle text-capitalize'
style="cursor: pointer;" title="Logout as <?php echo $_SESSION['user'] ?> ">
<b><b><b><?php echo $_SESSION['user'][0] ?></b></b></b>
</h3>
</a>
</div>
</div>
<div class="col-md-8 mx-auto">
<?php if (!empty($_REQUEST['resback'])){
echo '<div class="alert " id="alert">
'.$_REQUEST['resback'].'
</div>';
} ?>
<div class="alert " id="alert">
</div>
</div>
<div class="row my-1">
<div class="col-md-8 mx-auto form-inline">
<input type="search" name="item" id="item" onkeyup="LoadData()" class="form-control w-75 mx-0"
placeholder="Search Item">
<button class="btn btn-info ml-auto" onclick="show_model()" data-toggle="modal" data-target="data_model"
data-whatever="@getbootstrap">Add Record <i class="fas fa-user-plus"></i></button>
<a href="export_to_csv.php" class="btn btn-secondary my-2">Export CSV <i
class="fas fa-file-csv"></i></a>
<button class="ml-1 btn btn-primary my-2" id="importCSV" onclick="importCSV()" data-toggle="modal"
data-target="importCSV_model" data-whatever="@getbootstrap">Import CSV <i
class="fas fa-file-csv"></i></button>
<a href="save_to_pdf.php" class="ml-1 btn btn-warning my-2">Save PDF <i class="fas fa-file-pdf"></i></a>
<button class="ml-1 btn btn-danger my-2" id="deleteChecked">Delete Checked <i
class="fas fa-trash-alt"></i> </buttobutton>
</div>
</div>
<div class="row">
<div class="col-md-8 mx-auto bg-light shadow p-0 ">
<table class="table table-hover table-white table-striped ">
<thead class="bg-warning">
<th title="sort by ID" onclick="orderby('id')" style="cursor:pointer"># <i class="fa fa-sort"></i> </th>
<th title="sort by name" onclick="orderby('name')" style="cursor:pointer">Name <i class="fa fa-sort"></i> </th>
<th title="sort by phone number" onclick="orderby('phone')" style="cursor:pointer">Phone <i class="fa fa-sort"></i></th>
<th>Actions</th>
</thead>
<tbody class="table-bordered " id="tbody">
</tbody>
</table>
</div>
</div>
</div>
<br>
<footer class="mt-4">
<div class="container mt-auto ">
<div class="row">
<div class="col-md-8 mx-auto bg-dark rounded shadow py-1">
<p class="text-center text-light ">© By <a href="www.githib.com/tauseedzaman">Tauseed Zaman</a>
</p>
</div>
</div>
</footer>
<!-- Import csv Modal -->
<div class="modal fade" id="importCSV_model" tabindex="-1" role="dialog" aria-labelledby="importCSV_model"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="import_data_model">Import Data From CSV File</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="">
<form id="importCSV_form" method="post" action="import_csv.php" enctype="multipart/form-data">
<div class="form-group">
<label for="recipient-name" class="col-form-label">Choose .csv file</label>
<input type="file" required="" name="file" class="form-control-file" id="">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success " id="">Import</button>
</div>
</form>
</div>
</div>
</div>
<!-- modal create and edit -->
<div class="modal fade" id="data_model" tabindex="-1" role="dialog" aria-labelledby="data_model" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="data_model">Add Record</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="">
<form id="data_form">
<div class="form-group">
<label for="recipient-name" class="col-form-label">Name</label>
<input type="text" required="" class="form-control" id="name">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Phone</label>
<input type="number" required="" min="100000000" max="100000000000" class="form-control"
id="phone">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary save_data" id="save_data">Save</button>
</div>
</div>
</div>
</div>
<!-- edit modal -->
<div class="modal fade" id="edit_modal" tabindex="-1" role="dialog" aria-labelledby="edit_modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="">Edit Record</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="modal_body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" id="update_data">Update</button>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function importCSV() {
$("#importCSV_model").modal('show');
}
function show_model() {
$("#data_model").modal('show');
}
/*
* Add Data
*/
$(document).ready(function() {
$("#alert").hide();
$(document).on('click', "#edit", function() {
$("#edit_modal").modal('show');
var id = $(this).data('id')
$('#update_data').attr('data-id', id);
$.ajax({
url: "./operate.php",
type: "GET",
data: {
type: "edit",
id: id
},
success: function(data) {
$("#modal_body").html(data)
}
})
});
LoadData()
$("#save_data").click(function() {
var name = $("#name").val();
var phone = $("#phone").val();
$.ajax({
type: 'POST',
url: "./operate.php",
data: {
type: "create",
name: name,
phone: phone,
},
success: function(data) {
$("#alert").removeClass("alert-info");
$("#alert").removeClass("alert-danger");
$("#alert").addClass("alert-success");
$("#alert").html("Added Successfully!")
$("#data_model").modal('hide');
$("#phone").val('');
$("#name").val('');
LoadData()
}
});
});
$("#update_data").click(function() {
var id = $(this).data('id');
var name = $("#ename").val();
var phone = $("#ephone").val();
console.log(id, name, phone)
$.ajax({
data: {
type: "update",
id: id,
name: name,
phone: phone
},
type: "POST",
url: "./operate.php",
success: function(dataResult) {
$("#alert").removeClass("alert-danger");
$("#alert").removeClass("alert-success");
$("#alert").addClass("alert-info");
$("#alert").html("Updated Successfully!")
LoadData()
$("#edit_modal").modal('hide');
}
});
});
/*
* Delete Data
*/
$(document).on("click", "#delete", function() {
if (confirm("Are You Sure?")) {
$.ajax({
url: "./operate.php",
type: "POST",
data: {
type: "delete",
id: $(this).data('id')
},
success: function(dataResult) {
$("#alert").removeClass("alert-info");
$("#alert").removeClass("alert-success");
$("#alert").addClass("alert-danger");
$("#alert").html("Deleted Successfully!")
LoadData();
}
});
}
});
});
function LoadData(orderby='id') {
var item = $("#item").val();
$.ajax({
url: "./operate.php",
type: "GET",
data: {
type: "load",
orderby: orderby,
item: item,
},
success: function(dataResult) {
if (dataResult) {
$("#tbody").html(dataResult);
} else {
$("#tbody").html('<h1 class="text-danger p-3">No Data!!</h1>');
}
},
error: function(error) {
console.log(error)
}
});
}
$(document).on('click', "#checked", function() {
let x = $(this).data('id');
alert(x);
});
$(document).on('click', '#deleteChecked', function() {
let x = document.querySelectorAll("#check");
let list = Array();
let i = 0;
if (confirm("Are You Sure?")) {
x.forEach(element => {
if (element.checked) {
list[i] = element.getAttribute("data-id");
i++;
}
});
if (list.length > 0) {
$.ajax({
url: "./operate.php",
type: "POST",
data: {
type: "deleteChecked",
ids: list
},
success: function(dataResult) {
$("#alert").removeClass("alert-info");
$("#alert").removeClass("alert-success");
$("#alert").addClass("alert-danger");
$("#alert").html("Deleted Successfully!")
LoadData();
}
});
} else {
alert("Please Check Rows You wants to delete!");
}
}
});
function orderby(index) {
LoadData(index);
}
</script>
<!-- <script src="js/script.js"></script> -->
</body>
</html>