-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodification_ordre.php
143 lines (81 loc) · 2.51 KB
/
modification_ordre.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
<?php include ('menu.php');
include ('files.php');
if (isset($_GET['action'])){
$dat=Array();
if ($_GET['target']==='prod'){
$dat=unserialize(file_get_contents('produits.dat'));
$record='produits.dat';
}
else {echo 'ERROR';die();}
if ($_GET['action']==='up'&&is_numeric($_GET['index'])) {
$debut=array_slice($dat, 0, $_GET['index']-1);
$mover=array_slice($dat, $_GET['index'], 1);
$flip=array_slice($dat, $_GET['index']-1, 1);
if ($_GET['index']==count ($dat)-1){
$after=array();
} else {
$after=array_slice($dat, $_GET['index']+1, -1);
}
if (count($debut)==0){
$temp=array();
}else {
$temp=$debut;
}
$temp = array_merge ($temp, $mover);
$temp = array_merge ($temp, $flip);
if (count($after)!=0) {
$temp = array_merge ($temp, $after);
}
$dat=$temp;
}
else if ($_GET['action']==='down'&&is_numeric($_GET['index'])) {
if ($_GET['index']==0){
$debut=array();
} else {
$debut=array_slice($dat, 0, $_GET['index']);
}
$mover=array_slice($dat, $_GET['index'], 1);
$flip=array_slice($dat, $_GET['index']+1, 1);
$after=array_slice($dat, $_GET['index']+2, -1);
if (count($debut)==0){
$temp=array();
}else {
$temp=$debut;
}
$temp = array_merge ($temp, $flip);
$temp = array_merge ($temp, $mover);
if (count($after)!=0) {
$temp = array_merge ($temp, $after);
}
$dat=$temp;
}
else {echo 'ERROR';die();}
file_put_contents($record, serialize($dat));
}
echo '<h1>Modification de l\'ordre d\'affichage des produits</h1><h2>L\'ordre d\'affichage des catégories primera toujours sur l\'ordre individuel des produits</h2><ol>';
if (file_exists('produits.dat')) {
$prods=unserialize(file_get_contents('produits.dat'));
echo '<ol>';
$j=0;
foreach ($prods as $prod) {
?>
<li>Produit : <em><?php echo htmlspecialchars($prod['nom']);?></em>
(<?php echo htmlspecialchars($prod['categorie']);?>)
<?php echo htmlspecialchars($prod['description']);?>
<?php echo htmlspecialchars($prod['prix']);?>
<?php
if ($j!==0) {
echo '<a href="?action=up&target=prod&index='.$j.'">Monter</a> ';
}
if ($j!=count($prods)-1) {
echo '<a href="?action=down&target=prod&index='.$j.'">Descendre</a>';
}
echo '</li>';
$j++;
echo '';
}
echo '</ol>';
}
else {echo 'Merci de créer tout d\'abord de nouveaux produits';}
include ('footer.php');
?>