[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / exec / statistiques_repartition.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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){
19 global $nombre_vis, $nombre_abs;
20
21 $result = sql_select("id_rubrique", "spip_rubriques", "id_parent=$id_parent");
22
23 $nombre = 0;
24
25 while($row = sql_fetch($result)) {
26 $id_rubrique = $row['id_rubrique'];
27
28 $visites = intval(sql_getfetsel("SUM(".$critere.")", "spip_articles", "id_rubrique=$id_rubrique"));
29 $nombre_abs[$id_rubrique] = $visites;
30 $nombre_vis[$id_rubrique] = $visites;
31 $nombre += $visites + enfants($id_rubrique, $critere);
32 }
33 if (!isset($nombre_vis[$id_parent])) $nombre_vis[$id_parent]=0;
34 $nombre_vis[$id_parent] += $nombre;
35 return $nombre;
36 }
37
38
39 // http://doc.spip.org/@enfants_aff
40 function enfants_aff($id_parent,$decalage, $critere, $gauche=0) {
41
42 global $niveau;
43 global $nombre_vis;
44 global $nombre_abs;
45 global $spip_lang_right, $spip_lang_left;
46 global $abs_total;
47 global $taille;
48 $visites_abs = 0;
49
50 $result = sql_select("id_rubrique, titre, descriptif", "spip_rubriques", "id_parent=$id_parent",'', '0+titre,titre');
51
52 while($row = sql_fetch($result)){
53 $id_rubrique = $row['id_rubrique'];
54 $titre = typo($row['titre']);
55 $descriptif = attribut_html(couper(typo($row['descriptif']),80));
56
57 if ($nombre_vis[$id_rubrique]>0 OR $nombre_abs[$id_rubrique]>0){
58 $largeur_rouge = floor(($nombre_vis[$id_rubrique] - $nombre_abs[$id_rubrique]) * $taille / $abs_total);
59 $largeur_vert = floor($nombre_abs[$id_rubrique] * $taille / $abs_total);
60
61 if ($largeur_rouge+$largeur_vert>0){
62
63 if ($niveau == 0) {
64 $couleur="#cccccc";
65 }
66
67 else if ($niveau == 1) {
68 $couleur="#eeeeee";
69 }
70 else {
71 $couleur="white";
72 }
73 echo "<table cellpadding='2' cellspacing='0' border='0' width='100%'>";
74 echo "\n<tr style='background-color: $couleur'>";
75 echo "\n<td style='border-bottom: 1px solid #aaaaaa; padding-$spip_lang_left: ".($niveau*20+5)."px;'>";
76
77
78 if ( $largeur_rouge > 2)
79 echo bouton_block_depliable("<a href='" . generer_url_ecrire("naviguer","id_rubrique=$id_rubrique") . "' style='color: black;' title=\"$descriptif\">$titre</a>","incertain", "stats$id_rubrique");
80 else
81 echo "<div class='verdana1' style='padding-left: 18px; padding-top: 4px; padding-bottom: 3px;'>",
82 "<a href='" . generer_url_ecrire("naviguer","id_rubrique=$id_rubrique") . "' style='color: black;' title=\"$descriptif\">$titre</a>",
83 "</div>";
84 echo "</td>";
85
86
87 if ($niveau==0 OR 1==1){
88 $pourcent = round($nombre_vis[$id_rubrique]/$abs_total*1000)/10;
89 echo "\n<td class='verdana1' style='text-align: $spip_lang_right; width: 40px; border-bottom: 1px solid #aaaaaa;'>$pourcent%</td>";
90 }
91 else { echo "<td style='width: 10px; border-bottom: 1px solid #aaaaaa;'></td>"; }
92
93
94 echo "\n<td align='right' style='border-bottom: 1px solid #aaaaaa; width:" . ($taille+5) ."px'>";
95
96
97 echo "\n<table cellpadding='0' cellspacing='0' border='0' width='".($decalage+1+$gauche)."'>";
98 echo "\n<tr>";
99 if ($gauche > 0) echo "<td style='width: " .$gauche."px'></td>";
100 echo "\n<td style='border: 0px; white-space: nowrap;'>";
101 echo "<div style='border: 1px solid #999999; background-color: #dddddd; height: 12px; padding: 0px; margin: 0px;'>";
102 if ($visites_abs > 0) echo "<img src='" . chemin_image('rien.gif') . "' style='vertical-align: top; height: 12px; border: 0px; width: ".$visites_abs."px;' alt= ' '/>";
103 if ($largeur_rouge>0) echo "<img src='" . chemin_image('rien.gif') . "' class='couleur_cumul' style='vertical-align: top; height: 12px; border: 0px; width: " . $largeur_rouge . "px;' alt=' ' />";
104 if ($largeur_vert>0) echo "<img src='" . chemin_image('rien.gif') . "' class='couleur_nombre' style='vertical-align: top; width: " . $largeur_vert ."px; height: 12px; border: 0px' alt=' ' />";
105 echo "</div>";
106 echo "</td></tr></table>\n";
107 echo "</td></tr></table>";
108 }
109 }
110
111 if (isset($largeur_rouge) && ($largeur_rouge > 0)) {
112 $niveau++;
113 echo debut_block_depliable(false,"stats$id_rubrique");
114 enfants_aff($id_rubrique,$largeur_rouge, $critere, $visites_abs+$gauche);
115 echo fin_block();
116 $niveau--;
117 }
118 $visites_abs = $visites_abs + round($nombre_vis[$id_rubrique]/$abs_total*$taille);
119 }
120 }
121
122 // http://doc.spip.org/@exec_statistiques_repartition_dist
123 function exec_statistiques_repartition_dist()
124 {
125
126 global $abs_total, $nombre_vis, $taille, $spip_ecran;
127
128 if (!autoriser('voirstats')) {
129 include_spip('inc/minipres');
130 echo minipres();
131 } else {
132
133 $taille = _request('taille');
134 $commencer_page = charger_fonction('commencer_page', 'inc');
135 echo $commencer_page(_T('titre_page_statistiques'), "statistiques_visites", "repartition");
136
137 echo debut_grand_cadre(true);
138 echo gros_titre(_T('titre_page_statistiques'),'',false);
139 if ($spip_ecran == "large") {
140 $largeur_table = 974;
141 $taille = 550;
142 } else {
143 $largeur_table = 750;
144 $taille = 400;
145 }
146
147 echo "\n<br /><br /><table width='$largeur_table'><tr><td class='verdana2' style='text-align: center; width: $largeur_table" . "px;'>";
148 $critere = _request('critere');
149 if ($critere == "debut") {
150 $critere = "visites";
151 echo barre_onglets("stat_depuis", "debut");
152 }
153 else {
154 $critere = "popularite";
155 echo barre_onglets("stat_depuis", "popularite");
156 }
157
158 $abs_total=enfants(0, $critere);
159 if ($abs_total<1) $abs_total=1;
160 $nombre_vis[0] = 0;
161
162 echo debut_cadre_relief("statistiques-24.gif",true);
163 echo "<div style='border: 1px solid #aaaaaa; border-bottom: 0px;'>";
164 enfants_aff(0,$taille, $critere);
165 echo "</div><br />",
166 "<div class='verdana3' style='text-align: left;'>",
167 _T('texte_signification'),
168 "</div>";
169 echo fin_cadre_relief(true);
170 echo "</td></tr></table>";
171 echo fin_grand_cadre(true),fin_page();
172 }
173 }
174 ?>