-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewCustomer.php
91 lines (89 loc) · 3.81 KB
/
viewCustomer.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
<?php
session_start();
require_once('config.php');
require_once('autoload.php');
Helper_Access::rejectIfLogout();
if(isset($_POST['id'])) {
$customer = new Model_Customer($_POST['id']);
$customer->remove();
echo 'ok';
die;
}
if(!isset($_GET['id']))
$customers = Model_Customer::getAllCustomers();
else
$customers = array(new Model_Customer($_GET['id']));
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var action_alert = "<img src=\"media/alert.png\" alt=\"Erreur\" />";
var action_loading = "<img src=\"media/loading-mini.gif\" alt=\"Chargement\" />";
var action_delete = "<img src=\"media/delete.png\" alt=\"Supprimer\" class=\"customer_delete pointer\" />";
$(".customer_delete").live('click',function(){
var id = $(".customer_action").index($(this).parent());
var id_db = $($(".customer_id")[id]).text()
var fname = $($(".customer_fname")[id]).text();
var lname = $($(".customer_lname")[id]).text();
$($(".customer_action")[id]).html(action_loading);
if(confirm("Êtes-vous sûr de vouloir supprimer le client "+fname+" "+lname+" ?")) {
$.ajax({
type: "POST",
url: "viewCustomer.php",
data: "id="+id_db,
success: function(msg) {
if($.trim(msg) == "ok") {
$($(".customer_line")[id]).fadeOut(1000, function() {
$(this).remove();
})
} else {
$($(".customer_action")[id]).html(action_alert);
}
}
})
} else {
$($(".customer_action")[id]).html(action_delete);
}
})
})
</script>
<style type="text/css">
table {
border-collapse: collapse;
}
td, th {
border: 1px black solid;
padding: 5px 5px 5px 5px;
}
.pointer {
cursor: pointer;
}
</style>
</head>
<body>
<?php include 'search.php';?>
<table>
<thead><th>Identifiant</th><th>Prénom</th><th>Nom</th><th>Téléphone</th><th>Structure</th><th>Fonction</th><th>Adresse</th></thead>
<tbody>
<?php foreach($customers as $customer) {
$structure = new Model_Structure($customer->getStructure());?>
<tr class="customer_line">
<td class="customer_id"><?php echo $customer->getId(); ?></td>
<td class="customer_fname"><?php echo $customer->getFname();?></td>
<td class="customer_lname"><?php echo $customer->getLname();?></td>
<td><?php echo $customer->getPhone();?></td>
<td><?php echo $structure->getName();?></td>
<td><?php echo $customer->getFunction();?></td>
<td><?php echo $customer->getAddress();?></td>
<td class="customer_action"><img src="media/delete.png" alt="Supprimer" class="customer_delete pointer" /></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>