bf7d12bef79ea18ead943505715aa3941da7b262
[ptitvelo/web/www.git] / www / plugins-dist / statistiques / prive / squelettes / contenu / stats_repartition_fonctions.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2013 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined("_ECRIRE_INC_VERSION")) return;
14
15 include_spip('inc/presentation');
16
17 // http://doc.spip.org/@enfants
18 function enfants($id_parent, $critere, &$nombre_vis, &$nombre_abs){
19 $result = sql_select("id_rubrique", "spip_rubriques", "id_parent=".intval($id_parent));
20
21 $nombre = 0;
22
23 while($row = sql_fetch($result)) {
24 $id_rubrique = $row['id_rubrique'];
25
26 $visites = intval(sql_getfetsel("SUM(".$critere.")", "spip_articles", "id_rubrique=".intval($id_rubrique)));
27 $nombre_abs[$id_rubrique] = $visites;
28 $nombre_vis[$id_rubrique] = $visites;
29 $nombre += $visites + enfants($id_rubrique, $critere, $nombre_vis, $nombre_abs);
30 }
31 if (!isset($nombre_vis[$id_parent])) $nombre_vis[$id_parent]=0;
32 $nombre_vis[$id_parent] += $nombre;
33 return $nombre;
34 }
35
36
37 // http://doc.spip.org/@enfants_aff
38 function enfants_aff($id_parent,$decalage, $taille, $critere, $gauche=0) {
39 global $spip_lang_right, $spip_lang_left;
40 static $abs_total=null;
41 static $niveau=0;
42 static $nombre_vis;
43 static $nombre_abs;
44 if (is_null($abs_total)){
45 $nombre_vis = array();
46 $nombre_abs = array();
47 $abs_total = enfants(0, $critere, $nombre_vis, $nombre_abs);
48 if ($abs_total<1) $abs_total=1;
49 $nombre_vis[0] = 0;
50 }
51 $visites_abs = 0;
52 $out = "";
53
54 $result = sql_select("id_rubrique, titre, descriptif", "spip_rubriques", "id_parent=$id_parent",'', '0+titre,titre');
55
56 while($row = sql_fetch($result)){
57 $id_rubrique = $row['id_rubrique'];
58 $titre = typo($row['titre']);
59 $descriptif = attribut_html(couper(typo($row['descriptif']),80));
60
61 if ($nombre_vis[$id_rubrique]>0 OR $nombre_abs[$id_rubrique]>0){
62 $largeur_rouge = floor(($nombre_vis[$id_rubrique] - $nombre_abs[$id_rubrique]) * $taille / $abs_total);
63 $largeur_vert = floor($nombre_abs[$id_rubrique] * $taille / $abs_total);
64
65 if ($largeur_rouge+$largeur_vert>0){
66
67 if ($niveau == 0) {
68 $couleur="#cccccc";
69 }
70
71 else if ($niveau == 1) {
72 $couleur="#eeeeee";
73 }
74 else {
75 $couleur="white";
76 }
77 $out .= "<table cellpadding='2' cellspacing='0' border='0' width='100%'>";
78 $out .= "\n<tr style='background-color: $couleur'>";
79 $out .= "\n<td style='border-bottom: 1px solid #aaaaaa; padding-$spip_lang_left: ".($niveau*20+5)."px;'>";
80
81
82 if ( $largeur_rouge > 2)
83 $out .= bouton_block_depliable("<a href='" . generer_url_entite($id_rubrique,'rubrique') . "' style='color: black;' title=\"$descriptif\">$titre</a>","incertain", "stats$id_rubrique");
84 else
85 $out .= "<div class='verdana1' style='padding-left: 18px; padding-top: 4px; padding-bottom: 3px;'>"
86 . "<a href='" . generer_url_entite($id_rubrique,'rubrique') . "' style='color: black;' title=\"$descriptif\">$titre</a>"
87 . "</div>";
88 $out .= "</td>";
89
90
91 if ($niveau==0 OR 1==1){
92 $pourcent = round($nombre_vis[$id_rubrique]/$abs_total*1000)/10;
93 $out .= "\n<td class='verdana1' style='text-align: $spip_lang_right; width: 40px; border-bottom: 1px solid #aaaaaa;'>$pourcent%</td>";
94 }
95 else {
96 $out .= "<td style='width: 10px; border-bottom: 1px solid #aaaaaa;'></td>";
97 }
98
99
100 $out .= "\n<td align='right' style='border-bottom: 1px solid #aaaaaa; width:" . ($taille+5) ."px'>";
101
102
103 $out .= "\n<table cellpadding='0' cellspacing='0' border='0' width='".($decalage+1+$gauche)."'>";
104 $out .= "\n<tr>";
105 if ($gauche > 0) $out .= "<td style='width: " .$gauche."px'></td>";
106 $out .= "\n<td style='border: 0px; white-space: nowrap;'>";
107 $out .= "<div style='border: 1px solid #999999; background-color: #dddddd; height: 12px; padding: 0px; margin: 0px;'>";
108 if ($visites_abs > 0) $out .= "<img src='" . chemin_image('rien.gif') . "' style='vertical-align: top; height: 12px; border: 0px; width: ".$visites_abs."px;' alt= ' '/>";
109 if ($largeur_rouge>0) $out .= "<img src='" . chemin_image('rien.gif') . "' class='couleur_cumul' style='vertical-align: top; height: 12px; border: 0px; width: " . $largeur_rouge . "px;' alt=' ' />";
110 if ($largeur_vert>0) $out .= "<img src='" . chemin_image('rien.gif') . "' class='couleur_nombre' style='vertical-align: top; width: " . $largeur_vert ."px; height: 12px; border: 0px' alt=' ' />";
111 $out .= "</div>";
112 $out .= "</td></tr></table>\n";
113 $out .= "</td></tr></table>";
114 }
115 }
116
117 if (isset($largeur_rouge) && ($largeur_rouge > 0)) {
118 $niveau++;
119 $out .= debut_block_depliable(false,"stats$id_rubrique");
120 $out .= enfants_aff($id_rubrique,$largeur_rouge, $taille, $critere, $visites_abs+$gauche);
121 $out .= fin_block();
122 $niveau--;
123 }
124 $visites_abs = $visites_abs + round($nombre_vis[$id_rubrique]/$abs_total*$taille);
125 }
126 return $out;
127 }
128
129 ?>