[SPIP] ~maj SPIP v3.0.17 --> v3.0.19
[lhc/web/clavette_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-2014 *
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://code.spip.net/@enfants
18 function enfants($id_parent, $critere, &$nombre_branche, &$nombre_rub){
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_rub[$id_rubrique] = $visites;
28 $nombre_branche[$id_rubrique] = $visites;
29 $nombre += $visites + enfants($id_rubrique, $critere, $nombre_branche, $nombre_rub);
30 }
31 if (!isset($nombre_branche[$id_parent])) $nombre_branche[$id_parent]=0;
32 $nombre_branche[$id_parent] += $nombre;
33 return $nombre;
34 }
35
36
37 // http://code.spip.net/@enfants_aff
38 function enfants_aff($id_parent,$decalage, $taille, $critere, $gauche=0) {
39 global $spip_lang_right, $spip_lang_left;
40 static $total_site=null;
41 static $niveau=0;
42 static $nombre_branche;
43 static $nombre_rub;
44 if (is_null($total_site)){
45 $nombre_branche = array();
46 $nombre_rub = array();
47 $total_site = enfants(0, $critere, $nombre_branche, $nombre_rub);
48 if ($total_site<1) $total_site=1;
49 }
50 $visites_abs = 0;
51 $out = "";
52 $width = intval(floor(($nombre_branche[$id_parent]/$total_site)*$taille));
53 $width = "width:{$width}px;float:$spip_lang_left;";
54
55
56 $result = sql_select("id_rubrique, titre, descriptif", "spip_rubriques", "id_parent=$id_parent",'', '0+titre,titre');
57
58 while($row = sql_fetch($result)){
59 $id_rubrique = $row['id_rubrique'];
60 $titre = typo($row['titre']);
61 $descriptif = attribut_html(couper(typo($row['descriptif']),80));
62
63 if ($nombre_branche[$id_rubrique]>0 OR $nombre_rub[$id_rubrique]>0){
64 $largeur_branche = floor(($nombre_branche[$id_rubrique] - $nombre_rub[$id_rubrique]) * $taille / $total_site);
65 $largeur_rub = floor($nombre_rub[$id_rubrique] * $taille / $total_site);
66
67 if ($largeur_branche+$largeur_rub>0){
68
69 if ($niveau == 0) {
70 $couleur="#cccccc";
71 }
72
73 else if ($niveau == 1) {
74 $couleur="#eeeeee";
75 }
76 else {
77 $couleur="white";
78 }
79 $out .= "<table cellpadding='2' cellspacing='0' border='0' width='100%'>";
80 $out .= "\n<tr style='background-color: $couleur'>";
81 $out .= "\n<td style='border-bottom: 1px solid #aaaaaa; padding-$spip_lang_left: ".($niveau*20+5)."px;'>";
82
83
84 if ( $largeur_branche > 2)
85 $out .= bouton_block_depliable("<a href='" . generer_url_entite($id_rubrique,'rubrique') . "' style='color: black;' title=\"$descriptif\">$titre</a>","incertain", "stats$id_rubrique");
86 else
87 $out .= "<div class='rubsimple' style='padding-left: 18px;'>"
88 . "<a href='" . generer_url_entite($id_rubrique,'rubrique') . "' style='color: black;' title=\"$descriptif\">$titre</a>"
89 . "</div>";
90 $out .= "</td>";
91
92
93 // pourcentage de visites dans la branche par rapport au total du site
94 $pourcent = round($nombre_branche[$id_rubrique]/$total_site*1000)/10;
95 $out .= "\n<td class='verdana1' style='text-align: $spip_lang_right; width: 40px; border-bottom: 1px solid #aaaaaa;'>$pourcent%</td>";
96
97
98 $out .= "\n<td align='right' style='border-bottom: 1px solid #aaaaaa; width:" . ($taille+5) ."px'>";
99
100
101 $out .= "\n<table cellpadding='0' cellspacing='0' border='0' width='".($decalage+1+$gauche)."'>";
102 $out .= "\n<tr>";
103 if ($gauche > 0) $out .= "<td style='width: " .$gauche."px'></td>";
104 $out .= "\n<td style='border: 0px; white-space: nowrap;'>";
105 $out .= "<div style='border: 1px solid #999999; background-color: #dddddd; height: 1em; padding: 0px; margin: 0px;$width'>";
106 if ($visites_abs > 0) $out .= "<img src='" . chemin_image('rien.gif') . "' style='vertical-align: top; height: 1em; border: 0px; width: ".$visites_abs."px;' alt= ' '/>";
107 if ($largeur_branche>0) $out .= "<img src='" . chemin_image('rien.gif') . "' class='couleur_cumul' style='vertical-align: top; height: 1em; border: 0px; width: " . $largeur_branche . "px;' alt=' ' />";
108 if ($largeur_rub>0) $out .= "<img src='" . chemin_image('rien.gif') . "' class='couleur_nombre' style='vertical-align: top; width: " . $largeur_rub ."px; height: 1em; border: 0px' alt=' ' />";
109 $out .= "</div>";
110 $out .= "</td></tr></table>\n";
111 $out .= "</td></tr></table>";
112 }
113 }
114
115 if (isset($largeur_branche) && ($largeur_branche > 0)) {
116 $niveau++;
117 $out .= debut_block_depliable(false,"stats$id_rubrique");
118 $out .= enfants_aff($id_rubrique,$largeur_branche, $taille, $critere, $visites_abs+$gauche);
119 $out .= fin_block();
120 $niveau--;
121 }
122 $visites_abs = $visites_abs + round($nombre_branche[$id_rubrique]/$total_site*$taille);
123 }
124 return $out;
125 }
126
127 ?>