Subversion Repositories Sites.tela-botanica.org

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
261 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_appartenance_asso.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) {
75
	if (($mois)/12 > 1) {
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_ASS, COUNT( U_ASS ) AS nbre, LABEL_ASS '.
82
				'FROM annuaire_tela, annuaire_LABEL_ASS '.
83
				'WHERE U_DATE >= "'.date('Y-m-d H:i:s', $tps_courrant).'" '.
84
				'AND U_NIV = ID_LABEL_ASS '.
85
				'AND U_DATE < "'.date('Y-m-d H:i:s', $tps_mois_suivant).'" '.
86
				'GROUP BY ID_LABEL_ASS ';
87
	$resultat = $db->query($requete) ;
88
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
89
    	$id = $ligne->ID_LABEL_ASS;
90
    	$legende_libelle = $ligne->LABEL_ASS;
91
    	$tab_donnees[$id][$i] = $tab_donnees[$id][$i-1] + $ligne->nbre;
92
    	if (!isset($legende[$id])) {
93
    		$tab_legende[$id] = $legende_libelle;
94
    	}
95
	}
96
	//echo ' - '.$resultat->numRows().'<br/>';
97
	$tab_legende_axe_x[$i] = $tab_mois[$mois-1].' '.$annee;
98
	$tps_courrant = $tps_mois_suivant;
99
	$mois++;
100
	$i++;
101
}
102
//echo '<pre>'.print_r($tab_donnees, true).'</pre>';
103
 
104
$graph = new Graph(500, 490, 'auto');
105
$graph->img->SetMargin(50, 30, 50, 100);
106
$graph->SetMarginColor('white');
107
$graph->SetScale('textint');
108
$graph->xaxis->SetTickLabels($tab_legende_axe_x);
109
$graph->xaxis->SetLabelAngle(90);
110
$graph->xaxis->SetTextLabelInterval(4);
111
$graph->SetShadow();
112
$graph->title->Set("Évolution de l'appartenance a une association au ".date('d-m-Y', $tps_fin));
113
$graph->title->SetFont(FF_FONT1,FS_BOLD);
114
$graph->legend->SetLayout(LEGEND_VERT);
115
$graph->legend->Pos(0.15, 0.10, 'left', 'top');
116
 
117
$txt = new Text('Mois depuis le 1er avril 2002', 270, 460);
118
$graph->AddText($txt);
119
 
120
// Création des lignes
121
$p1 = new LinePlot($tab_donnees[1]); // Oui
122
$p2 = new LinePlot($tab_donnees[2]); // Non
123
$p3 = new LinePlot($tab_donnees[3]); // Ne se prononce pas
124
 
125
// Attribution des couleurs
126
$p1->SetFillColor('green');
127
$p2->SetFillColor('red');
128
$p3->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
 
135
// Nous ajoutons ensemble les lignes
136
$ap = new AccLinePlot(array($p3, $p2, $p1));
137
 
138
// Add the accumulated line plot to the graph
139
$graph->Add($ap);
140
$graph->Stroke();
141
 
142
/* +--Fin du code ----------------------------------------------------------------------------------------+
143
*
144
* $Log$
145
*
146
* +-- Fin du code ----------------------------------------------------------------------------------------+
147
*/
148
?>