Subversion Repositories Sites.tela-botanica.org

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
260 jpm 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 5.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org)                                    |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This file is part of tela_botanica_v4.                                                                         |
9
// |                                                                                                      |
10
// | Foobar is free software; you can redistribute it and/or modify                                       |
11
// | it under the terms of the GNU General Public License as published by                                 |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
13
// | (at your option) any later version.                                                                  |
14
// |                                                                                                      |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
18
// | GNU General Public License for more details.                                                         |
19
// |                                                                                                      |
20
// | You should have received a copy of the GNU General Public License                                    |
21
// | along with Foobar; if not, write to the Free Software                                                |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
23
// +------------------------------------------------------------------------------------------------------+
24
// CVS : $Id$
25
/**
26
* tela_botanica_v4 - graph_niveau_bota.php
27
*
28
* Description :
29
*
30
*@package tela_botanica_v4
31
//Auteur original :
32
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
33
//Autres auteurs :
34
*@author        Aucun
35
*@copyright     Tela-Botanica 1999-2007
36
*@version       $Revision$ $Date$
37
// +------------------------------------------------------------------------------------------------------+
38
*/
39
 
40
// +------------------------------------------------------------------------------------------------------+
41
// |                                            ENTÊTE du PROGRAMME                                       |
42
// +------------------------------------------------------------------------------------------------------+
43
include ("../../../../api/jpgraph_1.12.2/jpgraph.php") ;
44
include ("../../../../api/jpgraph_1.12.2/jpgraph_line.php") ;
45
include ("../../../../api/jpgraph_1.12.2/jpgraph_bar.php");
46
include ("../../../../papyrus/configuration/pap_config.inc.php") ;
47
 
48
include_once 'DB.php' ;
49
 
50
// +------------------------------------------------------------------------------------------------------+
51
// |                                            CORPS du PROGRAMME                                        |
52
// +------------------------------------------------------------------------------------------------------+
53
 
54
$db = DB::connect (PAP_DSN) ;
55
if (DB::isError($db)) {
56
    echo 'Message Standard         : ' . $db->getMessage() . "\n";
57
    echo 'Message DBMS/Utilisateur : ' . $db->getUserInfo() . "\n";
58
    echo 'Message DBMS/D&eacute;boguage   : ' . $db->getDebugInfo() . "\n";
59
    exit;
60
}
61
 
62
$tab_mois = array('Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Août', 'Sep', 'Oct', 'Nov', 'Dec');
63
$tab_legende_axe_x = array('');
64
$tab_legende = array();
65
$tab_donnees = array() ;
66
$tab_donnees_max = array();
67
$annee = 2002;
68
$tps_debut = mktime(0,0,0,1,1,$annee);
69
$tps_courrant = $tps_debut;
70
$tps_fin = mktime(0,0,0,0,0);// dernier jour du mois précedent le mois courrant
71
//Requete par mois
72
$i = 0;
73
while  ($tps_courrant <= $tps_fin) {
74
	$tps_suivant = mktime(0,0,0,1,1,$annee+1);
75
	//echo date('Y-m-d H:i:s', $tps_courrant).' - '.date('Y-m-d H:i:s', $tps_suivant);
76
	$requete = 	'SELECT ID_LABEL_NIV, COUNT( U_NIV ) AS nbre, LABEL_NIV '.
77
				'FROM annuaire_tela, annuaire_LABEL_NIV '.
78
				'WHERE U_DATE >= "'.date('Y-m-d H:i:s', $tps_courrant).'" '.
79
				'AND U_NIV = ID_LABEL_NIV '.
80
				'AND U_DATE < "'.date('Y-m-d H:i:s', $tps_suivant).'" '.
81
				'GROUP BY ID_LABEL_NIV ';
82
	$resultat = $db->query($requete) ;
83
	$tab_donnees_max[$i] = 0;
84
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
85
    	$tab_donnees[$ligne->ID_LABEL_NIV][$i] = $ligne->nbre;
86
    	$tab_donnees_max[$i] += $ligne->nbre;
87
    	if (!isset($legende[$ligne->ID_LABEL_NIV])) {
88
    		$tab_legende[$ligne->ID_LABEL_NIV] = $ligne->LABEL_NIV;
89
    	}
90
	}
91
	//echo ' - '.$resultat->numRows().'<br/>';
92
	$tab_legende_axe_x[$i] = $annee;
93
	$tps_courrant = $tps_suivant;
94
	$annee++;
95
	$i++;
96
}
97
//echo '<pre>'.print_r($tab_donnees, true).'</pre>';
98
foreach ($tab_donnees as $cle1 => $niveaux) {
99
	foreach ($niveaux as $cle2 => $quantite) {
100
		$tab_donnees[$cle1][$cle2] = $quantite/$tab_donnees_max[$cle2]*100;
101
	}
102
}
103
$graph = new Graph(500, 550, 'auto');
104
$graph->img->SetMargin(50, 30, 50, 150);
105
$graph->SetMarginColor('white');
106
$graph->SetScale('textint');
107
$graph->xaxis->SetTickLabels($tab_legende_axe_x);
108
$graph->xaxis->SetLabelAngle(90);
109
$graph->SetShadow();
110
$graph->title->Set("Évolution du niveau en botanique des inscrits au Réseau au ".date('d-m-Y', $tps_fin));
111
$graph->title->SetFont(FF_FONT1,FS_BOLD);
112
$graph->legend->SetLayout(LEGEND_VERT);
113
$graph->legend->Pos(0.10, 0.80, 'left', 'top');
114
 
115
$txt = new Text('Années', 400, 450);
116
$graph->AddText($txt);
117
 
118
// Création des lignes
119
$p1 = new BarPlot($tab_donnees[1]); // Débutant
120
$p1->value->Show();
121
$p1->value->SetFormat('%01.0f%%');
122
$p1->value->SetFont(FF_FONT1,FS_BOLD);
123
$p2 = new BarPlot($tab_donnees[2]); // Ayant une bonne pratique
124
$p2->value->Show();
125
$p2->value->SetFormat('%01.0f%%');
126
$p2->value->SetFont(FF_FONT1,FS_BOLD);
127
$p3 = new BarPlot($tab_donnees[3]); // Confirmé
128
$p3->value->Show();
129
$p3->value->SetFont(FF_FONT1,FS_BOLD);
130
$p3->value->SetFormat('%01.0f%%');
131
$p4 = new BarPlot($tab_donnees[4]); // Ne se prononce pas
132
$p4->value->Show();
133
$p4->value->SetFormat('%01.0f%%');
134
$p4->value->SetFont(FF_FONT1,FS_BOLD);
135
 
136
// Attribution des couleurs
137
$p1->SetFillColor('#cc3333');
138
$p2->SetFillColor('#c3d9ff');
139
$p3->SetFillColor('green');
140
$p4->SetFillColor('white');
141
 
142
// Attribution des textes pour la légende
143
$p1->SetLegend($tab_legende[1]);
144
$p2->SetLegend($tab_legende[2]);
145
$p3->SetLegend($tab_legende[3]);
146
$p4->SetLegend($tab_legende[4]);
147
 
148
// Nous ajoutons ensemble les lignes
149
$ap = new AccBarPlot(array($p4, $p3, $p2, $p1));
150
 
151
// Add the accumulated line plot to the graph
152
$graph->Add($ap);
153
$graph->Stroke();
154
 
155
/* +--Fin du code ----------------------------------------------------------------------------------------+
156
*
157
* $Log$
158
*
159
* +-- Fin du code ----------------------------------------------------------------------------------------+
160
*/
161
?>