Subversion Repositories Sites.tela-botanica.org

Rev

Rev 260 | Details | Compare with Previous | 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(0) ;
66
$annee_debut = 2002;
67
$mois = 4;
68
$annee = 2002;
69
$tps_debut = mktime(0,0,0,$mois,1,$annee);
70
$tps_courrant = $tps_debut;
71
$tps_fin = mktime(0, 0, 0, date('m'), 0);// dernier jour du mois précedent le mois courrant
72
//Requete par mois
73
$i = 0;
74
while  ($tps_courrant <= $tps_fin) {
262 jpm 75
	if ($mois/12 > 1) {
260 jpm 76
		$mois = 1;
77
		$annee = $annee+1;
78
	}
79
	$tps_mois_suivant = mktime(0,0,0,$mois+1,1,$annee);
80
	//echo date('Y-m-d H:i:s', $tps_courrant).' - '.date('Y-m-d H:i:s', $tps_mois_suivant);
81
	$requete = 	'SELECT ID_LABEL_NIV, COUNT( U_NIV ) AS nbre, LABEL_NIV '.
82
				'FROM annuaire_tela, annuaire_LABEL_NIV '.
83
				'WHERE U_DATE >= "'.date('Y-m-d H:i:s', $tps_courrant).'" '.
84
				'AND U_NIV = ID_LABEL_NIV '.
85
				'AND U_DATE < "'.date('Y-m-d H:i:s', $tps_mois_suivant).'" '.
86
				'GROUP BY ID_LABEL_NIV ';
87
	$resultat = $db->query($requete) ;
88
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
89
    	$tab_donnees[$ligne->ID_LABEL_NIV][$i] = $tab_donnees[$ligne->ID_LABEL_NIV][$i-1] + $ligne->nbre;
90
    	if (!isset($legende[$ligne->ID_LABEL_NIV])) {
91
    		$tab_legende[$ligne->ID_LABEL_NIV] = $ligne->LABEL_NIV;
92
    	}
93
	}
94
	//echo ' - '.$resultat->numRows().'<br/>';
95
	$tab_legende_axe_x[$i] = $tab_mois[$mois-1].' '.$annee;
96
	$tps_courrant = $tps_mois_suivant;
97
	$mois++;
98
	$i++;
99
}
100
//echo '<pre>'.print_r($tab_donnees, true).'</pre>';
101
 
102
$graph = new Graph(500, 490, 'auto');
103
$graph->img->SetMargin(50, 30, 50, 100);
104
$graph->SetMarginColor('white');
105
$graph->SetScale('textint');
106
$graph->xaxis->SetTickLabels($tab_legende_axe_x);
107
$graph->xaxis->SetLabelAngle(90);
108
$graph->xaxis->SetTextLabelInterval(4);
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.15, 0.10, 'left', 'top');
114
 
115
$txt = new Text('Mois depuis le 1er avril 2002', 270, 460);
116
$graph->AddText($txt);
117
 
118
// Création des lignes
119
$p1 = new LinePlot($tab_donnees[1]); // Débutant
120
$p2 = new LinePlot($tab_donnees[2]); // Ayant une bonne pratique
121
$p3 = new LinePlot($tab_donnees[3]); // Confirmé
122
$p4 = new LinePlot($tab_donnees[4]); // Ne se prononce pas
123
 
124
// Attribution des couleurs
125
$p1->SetFillColor('red');
126
$p2->SetFillColor('blue');
127
$p3->SetFillColor('green');
128
$p4->SetFillColor('white');
129
 
130
// Attribution des textes pour la légende
131
$p1->SetLegend($tab_legende[1]);
132
$p2->SetLegend($tab_legende[2]);
133
$p3->SetLegend($tab_legende[3]);
134
$p4->SetLegend($tab_legende[4]);
135
 
136
// Nous ajoutons ensemble les lignes
137
$ap = new AccLinePlot(array($p4, $p3, $p2, $p1));
138
 
139
// Add the accumulated line plot to the graph
140
$graph->Add($ap);
141
$graph->Stroke();
142
 
143
/* +--Fin du code ----------------------------------------------------------------------------------------+
144
*
145
* $Log$
146
*
147
* +-- Fin du code ----------------------------------------------------------------------------------------+
148
*/
149
?>