This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathListe.class.php
311 lines (291 loc) · 12.9 KB
/
Liste.class.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
<?php
require_once 'DucksManager_Core.class.php';
require_once 'Affichage.class.php';
require_once 'Inducks.class.php';
class Liste {
public $texte;
public $collection= [];
public static $types_listes= [];
static function set_types_listes() {
$rep = "Listes/";
$dir = opendir($rep);
$prefixe='Liste.';
$suffixe='.class.php';
while ($f = readdir($dir)) {
if (strpos($f,'Debug')!==false) {
continue;
}
if (is_file($rep . $f) && startswith($f, $prefixe) && endswith($f, $suffixe)) {
$nom=substr($f,strlen($prefixe),strlen($f)-strlen($suffixe)-strlen($prefixe));
include_once('Listes/Liste.'.$nom.'.class.php');
$a=new ReflectionProperty($nom, 'titre');
self::$types_listes[$nom]=$a->getValue();
}
}
return self::$types_listes;
}
function __construct($texte=false) {
if (!$texte) {
return;
}
$this->texte=$texte;
}
function sous_liste($pays,$magazine=false) {
$nouvelle_liste=new Liste();
if (!$magazine) {
$nouvelle_liste->collection= [$pays=> [$this->collection[$pays]]];
}
else {
if (isset($this->collection[$pays][$magazine])) {
$nouvelle_liste->collection= [$pays=> [$magazine=>$this->collection[$pays][$magazine]]];
}
}
return $nouvelle_liste;
}
function get_publication_la_plus_possedee() {
$cpt_numeros = [];
foreach($this->collection as $pays=>$numeros_pays) {
foreach(array_keys($numeros_pays) as $magazine) {
$cpt_numeros[$pays.'/'.$magazine] = count($numeros_pays[$magazine]);
}
}
if (count($cpt_numeros) > 0) {
arsort($cpt_numeros);
return key($cpt_numeros);
}
return null;
}
function liste_magazines($pays_magazine_supplementaire=null) {
$publication_codes= [];
foreach($this->collection as $pays=>$numeros_pays) {
foreach(array_keys($numeros_pays) as $magazine) {
$publication_codes[]=$pays.'/'.$magazine;
}
}
if (!is_null($pays_magazine_supplementaire)) {
$publication_codes[]=$pays_magazine_supplementaire;
}
$noms_pays = Inducks::get_noms_complets_pays($publication_codes);
$noms_magazines = Inducks::get_noms_complets_magazines($publication_codes);
return [$noms_pays,$noms_magazines];
}
function statistiques($onglet) {
$id_user=$_SESSION['id_user'];
$counts= [];
foreach($this->collection as $pays=>$numeros_pays) {
$counts[$pays]= [];
foreach($numeros_pays as $magazine=>$numeros) {
$counts[$pays][$magazine]=count($numeros);
}
}
$onglets= [PUBLICATIONS=> ['magazines',PUBLICATIONS_COURT],
POSSESSIONS=> ['possessions',POSSESSIONS_COURT],
ETATS_NUMEROS=> ['etats',ETATS_NUMEROS_COURT],
ACHATS=> ['achats',ACHATS_COURT],
AUTEURS=> ['auteurs',AUTEURS_COURT]];
Affichage::onglets($onglet,$onglets,'onglet','?action=stats');
if (count($counts)===0) {
?><div class="alert alert-info">
<?=AUCUN_NUMERO_POSSEDE_1?>
<a href="?action=gerer&onglet=ajout_suppr"><?=ICI?></a>
<?=AUCUN_NUMERO_POSSEDE_2?></div>
<?php
return;
}
switch($onglet) {
case 'magazines':
?>
<div id="canvas-holder">
<canvas id="graph_publications"></canvas>
</div><?php
break;
case 'possessions':
$types = ['abs' => AFFICHER_VALEURS_REELLES, 'cpt'=> AFFICHER_POURCENTAGES]; ?>
<div id="canvas-controls" class="btn-group hidden" data-toggle="buttons">
<?php foreach($types as $type=>$label) {?>
<label class="btn btn-default graph_type <?=$type==='abs' ? 'active': ''?>" onclick="toggleGraphs(this, 'possessions')">
<input type="radio" name="options_graph" autocomplete="off" /> <?=$label?>
</label><?php
}?>
</div>
<br />
<div id="message_possessions"><?=CHARGEMENT?></div>
<div id="canvas-holder" class="hidden">
<?php foreach($types as $type=>$label) {
?><canvas class="graph_possessions <?=$type?> <?=$type==='cpt' ? 'hidden' : ''?>"
width="100%" height="500px"></canvas><?php
}?>
</div><?php
break;
case 'etats': ?>
<div id="canvas-holder">
<canvas id="graph_conditions"></canvas>
</div><?php
break;
case 'achats':
$types = ['nouv' => AFFICHER_NOUVELLES_ACQUISITIONS, 'tot'=> AFFICHER_POSSESSIONS_TOTALES]; ?>
<div id="message_achats"><?=CHARGEMENT?></div>
<div class="alert alert-info">
<div><?=EXPLICATION_GRAPH_ACHATS_1?></div><br />
<div><?=EXPLICATION_GRAPH_ACHATS_2?></div>
<div><?=EXPLICATION_GRAPH_ACHATS_3?></div>
<div><?=sprintf(EXPLICATION_GRAPH_ACHATS_4, '<a href="/?action=gerer">'.GERER_COLLECTION.'</a>')?></div>
<div id="message_achats_vide" class="hidden">
<a href="/?action=gerer">
<img height="300px" src="images/demo_selection_achat_<?=$_SESSION['lang']?>.png" />
</a>
</div>
</div>
<br />
<div id="fin_achats" class="hidden">
<div class="btn-group" data-toggle="buttons">
<?php foreach($types as $type=>$label) {?>
<label class="btn btn-default graph_type <?=$type==='abs' ? 'active': ''?>" onclick="toggleGraphs(this, 'achats')">
<input type="radio" name="options_graph" autocomplete="off" /> <?=$label?>
</label><?php
}?>
</div>
<div id="canvas-holder" class="hidden" style="background: whitesmoke">
<?php foreach($types as $type=>$label) {
?><canvas class="graph_achats <?=$type?> <?=$type==='tot' ? 'hidden' : ''?>"
width="100%" height="500px"></canvas><?php
}?>
</div>
</div>
<?php
break;
case 'auteurs':
$requete_auteurs_surveilles='SELECT NomAuteurAbrege FROM auteurs_pseudos WHERE ID_User='.$id_user;
$resultats_auteurs_surveilles=DM_Core::$d->requete($requete_auteurs_surveilles);
if (count($resultats_auteurs_surveilles) === 0) { ?>
<div class="alert alert-warning"><?=AUCUN_AUTEUR_SURVEILLE?></div><?php
}
else {
$types = ['abs' => AFFICHER_VALEURS_REELLES, 'pct'=> AFFICHER_POURCENTAGES]; ?>
<div id="aucun_resultat_stats_auteur" class="alert alert-info hidden">
<?=CALCULS_PAS_ENCORE_FAITS?>
</div>
<div id="chargement_stats_auteur">
<?=CHARGEMENT?>
</div>
<div id="fin_stats_auteur" class="hidden">
<div class="btn-group" data-toggle="buttons">
<?php foreach($types as $type=>$label) {?>
<label class="btn btn-default graph_type <?=$type==='abs' ? 'active': ''?>" onclick="toggleGraphs(this, 'auteurs')">
<input type="radio" name="options_graph" autocomplete="off" /> <?=$label?>
</label><?php
}?>
</div>
</div>
<br />
<div id="canvas-holder" class="hidden">
<?php foreach($types as $type=>$label) {
?><canvas class="graph_auteurs <?=$type?> <?=$type==='pct' ? 'hidden' : ''?>"></canvas><?php
}?>
</div>
<?php
}
?><br /><br />
<?=STATISTIQUES_QUOTIDIENNES?>
<br /><br />
<hr /><?php
if (isset($_POST['auteur_id'])) {
DM_Core::$d->ajouter_auteur($_POST['auteur_id']);
}
?>
<br /><br />
<?=AUTEURS_FAVORIS_INTRO_1?>
<a href="?action=agrandir&onglet=suggestions_achat"><?=AUTEURS_FAVORIS_INTRO_2?></a>
<br /><br />
<div style="clear: both">
<br /><br /><?php
DM_Core::$d->afficher_liste_auteurs_surveilles($resultats_auteurs_surveilles); ?>
</div>
<div class="form-group">
<form method="post" class="row" action="?action=stats&onglet=auteurs">
<label for="auteur_nom" class="col-sm-1 control-label" style="white-space: nowrap"><?=AUTEUR?> :</label>
<div class="col-sm-4">
<input class="form-control" autocomplete="off" type="text" name="auteur_nom" id="auteur_nom" value="" />
</div>
<input type="hidden" id="auteur_id" name="auteur_id" />
<div class="col-sm-4">
<input class="btn btn-default center" type="submit" value="<?=AJOUTER?>" />
</div>
</form>
</div><?php
break;
}
}
function remove_from_database($id_user) {
$cpt=0;
foreach($this->collection as $pays=>$numeros_pays) {
if ($pays!=='country') {
foreach($numeros_pays as $magazine=>$numeros) {
foreach($numeros as $numero) {
$num_final=is_array($numero) && array_key_exists(4,$numero) ? $numero[4] : $numero;
$requete='DELETE FROM numeros WHERE (ID_Utilisateur ='.$id_user.' AND PAYS = \''.$pays.'\' AND Magazine = \''.$magazine.'\' AND Numero = \''.$num_final.'\')';
DM_Core::$d->requete($requete);
$cpt++;
}
}
}
}
return $cpt;
}
function afficher($type,$parametres=null) {
$type=strtolower($type);
$list_file = 'Listes/Liste.'.$type.'.class.php';
if (file_exists($list_file)) {
@require_once $list_file;
/** @var Format_liste $o */
$o=new $type();
if (!is_null($parametres)) {
foreach($parametres as $nom_parametre=>$parametre) {
$o->parametres->$nom_parametre = $parametre;
}
}
$o->afficher($this->collection);
}
else {
echo ERREUR_TYPE_LISTE_INVALIDE;
}
}
function get_etat_numero_possede($pays, $magazine, $numero) {
if (array_key_exists($pays, $this->collection)
&& array_key_exists($magazine, $this->collection[$pays])) {
foreach($this->collection[$pays][$magazine] as $numero_liste) {
if (nettoyer_numero($numero_liste[2])===$numero) {
return $numero_liste[3];
}
}
}
return null;
}
function get_numero_collection($pays, $magazine, $numero) {
if (isset($this->collection[$pays][$magazine])
&& array_key_exists($numero, $this->collection[$pays][$magazine])) {
return $this->collection[$pays][$magazine][$numero];
}
return null;
}
function nettoyer_collection() {
foreach($this->collection as $pays=>$liste_magazines) {
foreach($liste_magazines as $magazine=>$liste_numeros) {
foreach($liste_numeros as $i=>&$numero_liste) {
$numero_liste[0] = nettoyer_numero($numero_liste[0]);
}
unset($numero_liste);
}
}
}
}
if (isset($_POST['parametres'])) {
$_POST['parametres'] = str_replace('\"', '"', $_POST['parametres']);
}
function startswith($hay, $needle) {
return $needle === $hay or strpos($hay, $needle) === 0;
}
function endswith($hay, $needle) {
return $needle === $hay or strpos(strrev($hay), strrev($needle)) === 0;
}
?>