This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheures_pilote_image.php
153 lines (137 loc) · 6.34 KB
/
heures_pilote_image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* List all known operations for a pilot.
* An admin can see operations for an other pilote.
*
* PHP version 5
*
* Copyright © 2011 Mélissa Djebel
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* Plugin Pilote is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*
* @category Plugins
* @package GalettePilote
*
* @author Mélissa Djebel <[email protected]>
* @copyright 2011 Mélissa Djebel
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @version 0.7
* @link http://galette.tuxfamily.org
* @since Available since 0.7
*/
define('GALETTE_BASE_PATH', '../../');
require_once GALETTE_BASE_PATH . 'includes/galette.inc.php';
// Import des classes de notre plugin
require_once '_config.inc.php';
if (!$login->isLogged() || !(PiloteInstructeur::isPiloteInstructeur($login->login) || $login->isAdmin() || $login->isStaff())) {
header('location: ' . GALETTE_BASE_PATH . 'index.php');
die();
}
// Récupération du tri
$tri = filter_has_var(INPUT_GET, 'tri') ? filter_input(INPUT_GET, 'tri') : 'nom';
$direction = filter_has_var(INPUT_GET, 'direction') ? filter_input(INPUT_GET, 'direction') : 'asc';
switch ($tri) {
case 'nom':
$tri_sql = 'nom_adh';
break;
case 'prenom':
$tri_sql = 'prenom_adh';
break;
case 'pseudo':
$tri_sql = 'login_adh';
break;
case 'an-1':
$tri_sql = 'somme_last_year';
break;
case 'an':
$tri_sql = 'somme_this_year';
break;
case 'glissant':
$tri_sql = 'somme_glissant';
break;
}
// Liste des pilotes
$stats = PiloteOperation::getStatistiquesPilotes('all', $tri_sql, $direction);
// Définition taille image + police utilisée
$width = 750;
$height = 30 * count($stats) + 30;
$font_path = 'SourceSansPro-Regular.ttf';
// Nouvelle image
$image = imagecreate($width, $height);
// Couleurs
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$grey50 = imagecolorallocate($image, 100, 100, 100);
$grey215 = imagecolorallocate($image, 215, 215, 215);
$blue = imagecolorallocate($image, 0, 0, 255);
$purple = imagecolorallocate($image, 131, 0, 146);
// Fond en blanc
imagefill($image, 0, 0, $white);
$max_minute = 10;
$left_border = 30;
// Trace du nom des adhérents actifs
for ($i = 0; $i < count($stats); $i++) {
if (is_numeric($stats [$i]->somme_last_year) && $max_minute < $stats[$i]->somme_last_year) {
$max_minute = $stats[$i]->somme_last_year;
}
if (is_numeric($stats [$i]->somme_this_year) && $max_minute < $stats[$i]->somme_this_year) {
$max_minute = $stats[$i]->somme_this_year;
}
imagettftext($image, 10, 0, 0, ( $height - 30) / count($stats) * $i + 17, $grey50, $font_path, $stats[$i]->login_adh);
imagettftext($image, 10, 0, 0, ( $height - 30) / count($stats) * $i + 27, $grey50, $font_path, $stats[$i]->nom_adh);
$size = imagettfbbox(10, 0, $font_path, $stats [$i]->nom_adh);
if ($left_border < $size [2] + 4) {
$left_border = $size[2] + 4;
}
}
// Bordure gauche, bas, droite
imageline($image, $left_border, 5, $left_border, $height - 25, $black);
imageline($image, $left_border, $height - 25, $width - 30, $height - 25, $black);
imageline($image, $width - 30, 5, $width - 30, $height - 25, $black);
// Agrandissement de qq % du graphique
$max_minute *= 1.07;
// Trace des ordonnées
for ($i = 1; $i < 10; $i ++) {
imageline($image, ($width - $left_border - 30) / 10 * $i + $left_border, 5, ($width - $left_border - 30 ) / 10 * $i + $left_border, $height - 26, $grey215);
$nb_h = floor($max_minute / 10 * $i / 60);
$nb_m = floor($max_minute / 10 * $i - $nb_h * 60);
$txt = $nb_h . 'h' . ($nb_m < 10 ? '0' : '') . $nb_m;
$size = imagettfbbox(10, 0, $font_path, $txt);
imagettftext($image, 10, 0, ($width - $left_border - 30 ) / 10 * $i + $left_border - $size[2] / 2, $height - 12, $grey50, $font_path, $txt);
}
// Max minute
$nb_h = floor($max_minute / 60);
$nb_m = floor($max_minute - $nb_h * 60);
$txt = $nb_h . 'h' . ($nb_m < 10 ? '0' : '' ) . $nb_m;
$size = imagettfbbox(10, 0, $font_path, $txt);
imagettftext($image, 10, 0, $width - 30 - $size[2] / 2, $height - 12, $grey50, $font_path, $txt);
// Trace des longueurs adhérents
for ($i = 0; $i < count($stats); $i++) {
if (is_numeric($stats[$i]->somme_last_year)) {
imagefilledrectangle($image, $left_border + 1, ( $height - 30 ) / count($stats) * $i + 7, ($width - $left_border - 30) / $max_minute * $stats[$i]->somme_last_year + $left_border, ( $height - 30) / count($stats) * $i + 16, $blue);
$nb_h = floor($stats[$i]->somme_last_year / 60);
$nb_m = $stats[$i]->somme_last_year - $nb_h * 60;
$txt = ($nb_h > 0 ? $nb_h . 'h' : '') . ($nb_m < 10 ? '0' : '') . $nb_m . 'min';
imagettftext($image, 10, 0, ($width - $left_border - 30) / $max_minute * $stats [$i]->somme_last_year + $left_border + 2, ( $height - 30) / count($stats) * $i + 17, $blue, $font_path, $txt);
}
if (is_numeric($stats[$i]->somme_this_year)) {
imagefilledrectangle($image, $left_border + 1, ( $height - 30 ) / count($stats) * $i + 17, ($width - $left_border - 30) / $max_minute * $stats[$i]->somme_this_year + $left_border, ( $height - 30) / count($stats) * $i + 26, $purple);
$nb_h = floor($stats[$i]->somme_this_year / 60);
$nb_m = $stats[$i]->somme_this_year - $nb_h * 60;
$txt = ($nb_h > 0 ? $nb_h . 'h' : '') . ($nb_m < 10 ? '0' : '') . $nb_m . 'min';
imagettftext($image, 10, 0, ($width - $left_border - 30) / $max_minute * $stats [$i]->somme_this_year + $left_border + 2, ( $height - 30) / count($stats) * $i + 27, $purple, $font_path, $txt);
}
}
// Modification du header pour indiquer qu'il s'agit d'une image
header("Content-type:image/png");
header("Content-Disposition:inline ; filename=heures_pilote.png");
// Ecriture de l'image en PNG
imagepng($image);