This repository has been archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
clients.php
251 lines (214 loc) · 10.4 KB
/
clients.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
<?php
define('page_titre', "Clients • Caisse Foyer");
include_once 'inclus/zoneadmin.inc.php';
// Traitement AJAX
if(isset($_GET['ajax'])
and !empty($_POST['id'])
and !empty($_POST['nom'])
and !empty($_POST['prenom'])
and isset($_POST['solde'])
and !empty($_POST['statut'])
){
logue("Modification du client {$_POST['prenom']} {$_POST['nom']} ({$_POST['solde']}€ et {$_POST['statut']})","clients","warn");
$_POST['id'] = intval($_POST['id']);
$_POST['solde'] = floatval($_POST['solde']);
$_POST['nom'] = htmlentities(ucwords($_POST['nom']),ENT_QUOTES,'utf-8');
$_POST['prenom'] = htmlentities(ucwords($_POST['prenom']),ENT_QUOTES,'utf-8');
$_POST['statut'] = $sql->secur($_POST['statut']);
$sql->rek( "UPDATE clients SET nom='{$_POST['nom']}',prenom='{$_POST['prenom']}',solde='{$_POST['solde']}',active='{$_POST['statut']}' WHERE id='{$_POST['id']}'" );
echo $sql->nbrchangements();
exit();
}
$head_HTML = '<script type="text/javascript" src="scripts/admin.js"></script><script type="text/javascript" src="scripts/ajax.js"></script><script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"></script>';
include_once 'inclus/tete.html.php';
?>
<div class="central bloc clients">
<a href="./administration.php" class="maison">Retour</a>
<h1>Nos beaux pochtrons</h1>
<?php
if(!empty($_GET['efface'])){
$id = intval($_GET['efface']);
$sql->rek( "DELETE FROM clients WHERE id='$id'" );
if($sql->nbrchangements() != 1){
logue("Erreur lors de la suppression d'un client !","erreur",'critique');
echo '<div class="notif argh"><strong>Échec</strong>Impossible de supprimer ce client #'.$id.'... C\'est dommage ! Demande à la mafia ?</div>';
}
else{
logue("Suppression du client #$id",'clients','warn');
echo '<div class="notif yeah estompe"><strong>Client supprimé</strong>En espérant que la police viendra pas roder par ici...</div>';
}
}
if(!empty($_GET['ajout'])){
if(!empty($_POST['nom'])
and !empty($_POST['prenom'])
and isset($_POST['solde'])
and !empty($_POST['statut'])
){
$_POST['solde'] = floatval($_POST['solde']);
$_POST['nom'] = htmlentities(ucwords($_POST['nom']),ENT_QUOTES,'utf-8');
$_POST['prenom'] = htmlentities(ucwords($_POST['prenom']),ENT_QUOTES,'utf-8');
$_POST['statut'] = $sql->secur($_POST['statut']);
$sql->rek( "INSERT INTO clients (`nom` ,`prenom` ,`solde`,`active`) VALUES ('{$_POST['nom']}','{$_POST['prenom']}','{$_POST['solde']}','{$_POST['statut']}')" );
if($sql->nbrchangements() != 1){
logue("Erreur lors de l'ajout d'un client ({$_POST['prenom']} {$_POST['nom']}) !","erreur",'critique');
echo '<div class="notif argh"><strong>Échec</strong>Une erreur s\'est produite, il n\'a pas été possible d\'enregistrer ce client...</div>';
}
else{
logue("Ajout du client {$_POST['prenom']} {$_POST['nom']}",'clients','warn');
echo '<div class="notif yeah estompe"><strong>Client ajouté</strong>Et un de plus !</div>';
}
}
}
?>
<div id="notifs"></div>
<form onsubmit="return false;">
<table class="clients lignes lignes-hover" id="clients">
<thead>
<tr><th></th><th>Nom</th><th>Prénom</th><th>Solde</th><th>Consos</th><th>État</th><th></th></tr>
</thead>
<tfoot><tr><td colspan="7">
<?php
$sql->rek( 'SELECT `id` ,prenom,nom,solde,active,nb_consos FROM clients ORDER BY (solde<0) DESC, nom ASC' );
echo $sql->nbrlignes();
?> clients connus</td></tr></tfoot>
<tbody>
<?php
while($a = $sql->fetch()){
$photo = (file_exists("images/photos/".$a['id'].".jpg")) ? $a['id'] : "sans_photo";
echo "<tr".(($a['solde']<0) ? ' class="stock-alerte"' : '')." id='c{$a['id']}'>
<td>
<img class='ico-client' src='images/photos/$photo.jpg' alt=''>
<input type='hidden' value='{$a['id']}' name='id'></td>
<td><input name='nom' type='text' value='{$a['nom']}'></td>
<td><input name='prenom' type='text' value='{$a['prenom']}'></td>
<td><input name='solde' type='number' step='0.1' value='{$a['solde']}'>€".(($a['solde']<0) ? '<span class="fam-attention" title="Le solde est négatif !"></span>' : '')."</td>
<td>{$a['nb_consos']}</td>
<td class='statut'><select name='statut'>
<option value='activé'".(($a['active']=='activé') ? ' selected' : '').">Normal</option>
<option value='inactif'".(($a['active']=='inactif') ? ' selected' : '').">Désactivé</option>
<option value='bloqué'".(($a['active']=='bloqué') ? ' selected' : '').">Bloqué</option>
</select> ".(($a['active']!='activé') ? '<span class="fam-attention" title="Ce client n\'est pas activé !"></span>' : '')."</td>
<td><input title='Appliquer les modifications' type='image' class='action invisible' alt='Édition' src='images/icones/icons/pencil_go.png'>
<img title='Télécharger la photo du client à partir de Facebook' class='action' name='dlFBimg' alt='Télécharger la photo' src='images/icones/icons/user_go.png'>
<img title='Éditer cette ligne' class='action' name='edit' alt='Édition' src='images/icones/icons/pencil.png'>
<img title='Supprimer cette ligne' class='action' onclick='suppc({$a['id']})' alt='Supprimer' src='images/icones/icons/delete.png'></td></tr>";
/*
echo "<tr".(($a['solde']<0) ? ' class="stock-alerte"' : '')." id='c{$a['id']}'><td><img class='ico-client' src='images/produits/photos/{$a['id']}.png' alt=''></td><td><span name='nom{$a['id']}'>{$a['nom']}</span></td><td><span name='prenom'>{$a['prenom']}</span></td><td>{$a['solde']}€".(($a['solde']<0) ? '<span class="fam-attention" title="Le solde est négatif !"></span>' : '')."</td><td>{$a['nb_consos']}</td><td class='statut'>{$a['active']} ".(($a['active']!='activé') ? '<span class="fam-attention" title="Ce client n\'est pas activé !"></span>' : '')."</td><td><button>Edit</button><img class='action' id='edit' onclick='editc({$a['id']})' alt='Édition' src='images/icones/icons/pencil.png'><img class='action' onclick='suppc({$a['id']})' alt='Supprimer' src='images/icones/icons/delete.png'></td></tr>";*/
}
?>
</tbody>
</table>
</form>
<form action="clients.php?ajout=1" method="POST">
<table class="lignes" id="nouveauclient">
<caption><span>Enregistrer un client</span></caption>
<thead><tr>
<th>
<label for="prenom">Prénom</label>
</th>
<th>
<label for="nom">Nom</label></th>
<th>
<label for="solde">Solde de départ</label></th>
<th>
<label for="statut">Statut</label></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" name="prenom" id="prenom" required>
</td>
<td>
<input type="text" name="nom" id="nom" required></td>
<td>
<input type="number" value="0" min="0" step="0.1" name="solde" id="solde" required title="Solde placé sur le compte pour l'ouverture"> €</td>
<td><select name="statut" id="statut">
<option value="activé">Normal</option>
<option value="inactif">Désactivé</option>
<option value="bloqué">Bloqué</option>
</select></td>
</tr>
<tr><td colspan="4">
<input type="submit" class="vert ajout-client" value="Enregistrer ce client">
<input type="reset" value="On efface tout">
</td></tr>
</tbody></table>
</form>
</div>
<script>
function setupRows(context) {
$("span.view", context).remove();
$('input[type="text"], input[type="number"], select', context).each(function () {
$("<span />", {
text: this.value,
"class": "view"
}).insertAfter(this);
$(this).hide();
});
$('input[type="image"]', context).each(function () {
$(this).hide();
});
}
// Estomper les éléments qui le demandent
$(document).ready(function(){
// $(".estompe").css("opacity","0");
$(".invisible").hide();
setupRows('#clients');
});
$("table#clients input, table#clients select").change(function(){
$(this).closest("tr").find("img[name='edit']").hide();
$(this).closest("tr").find("input[type='image']").show();
});
$("img[name='edit']").toggle(function () {
$(this).closest("tr").find("input[type='text'], input[type='number'], select, span.view").toggle();
}, function () {
setupRows($(this).closest("tr"));
});
$("table#clients input[type='image']").click(function(){
$.post("clients.php?ajax=1",
{
id: $(this).closest("tr").find("input[name='id']").val(),
prenom: $(this).closest("tr").find("input[name='prenom']").val(),
nom: $(this).closest("tr").find("input[name='nom']").val(),
solde: $(this).closest("tr").find("input[name='solde']").val(),
statut: $(this).closest("tr").find("select[name='statut']").val()
},
function(data,status){
if(status=="success" && data=="1"){
$("#notifs").prepend('<div class="notif yeah estompe"><strong>Modification effectuée</strong>Ce client a bien été modifié.</div>');
$("img[name='edit']").show();
$("input[type='image']").hide();
setTimeout( "jQuery('.estompe').fadeOut();",4000 );
$(".notif").click(function(){$(this).fadeOut();});
setupRows('#clients');
}
else{
$("#notifs").prepend('<div class="notif argh estompe"><strong>Modification ratée</strong>Comme qui dirait, Something Went Wrong...</div>');
}
});
});
function dlFBimg_post_Callback(data, old_GET_args)
{
var GET_args = {'id' : old_GET_args.id, 'fb_id':data.reponse}; //Arguments de la requète GET
ajax_url("image_upload.php", GET_args, fonction_callback_upload, dlFBimg_err_Callback);//Appel AJAX
}
function dlFBimg_err_Callback(data, old_GET_args)
{
// alert("Erreur "+erreur_id+" : "+reponse);
$("#notifs").prepend('<div class="notif argh"><strong>Erreur ' + data.code_erreur + '</strong>Une erreur s\'est produite : <em>' + data.reponse + '</em></div>');
}
function fonction_callback_upload(data, old_GET_args)
{
$("tr#c"+old_GET_args.id).find("img[class='ico-client']").attr("src","images/photos/"+old_GET_args.id+".jpg");
$("#notifs").prepend('<div class="notif yeah estompe"><strong>Téléchargement réussi</strong>La photo de profil a bien été mise à jour pour cet invidu.</div>');
}
$("img[name='dlFBimg']").click(function () {
$("#notifs").prepend('<div class="notif estompe"><strong>Téléchargement en cours</strong>Veuillez patienter...</div>');
var GET_args = {'id' : $(this).closest("tr").find("input[name='id']").val() }; //Arguments de la requête GET
ajax_url("image_search.php", GET_args, dlFBimg_post_Callback, dlFBimg_err_Callback);//Appel AJAX
});
</script>
<?php
include 'inclus/pied.html.php';
?>