Subversion Repositories eFlore/Applications.cel

Rev

Rev 2458 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2458 Rev 2552
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service d'export de données d'observation du CEL au format XLS.
4
 * Service d'export de données d'observation du CEL au format XLS.
5
 *
5
 *
6
 * Format du service :
6
 * Format du service :
7
 * POST /ExportXLS
7
 * POST /ExportXLS
8
 * POST /ExportXLS/<Utilisateur>
8
 * POST /ExportXLS/<Utilisateur>
9
 * TODO: GET /ExportXLS/<Utilisateur> [ sans "range" ? ]
9
 * TODO: GET /ExportXLS/<Utilisateur> [ sans "range" ? ]
10
 *
10
 *
11
 * Les données POST acceptées sont:
11
 * Les données POST acceptées sont:
12
 * range (obligatoire): un range d'id_observation sous la forme d'entier ou d'intervalles d'entiers
12
 * range (obligatoire): un range d'id_observation sous la forme d'entier ou d'intervalles d'entiers
13
 * séparés par des virgules ou bien '*' (pour toutes)
13
 * séparés par des virgules ou bien '*' (pour toutes)
14
 * TODO: limit
14
 * TODO: limit
15
 * TODO: départ
15
 * TODO: départ
16
 * TODO: sets (ou colonnes, ou extended)
16
 * TODO: sets (ou colonnes, ou extended)
17
 * TODO: + les critères supportés par fabriquerSousRequeteRecherche()
17
 * TODO: + les critères supportés par fabriquerSousRequeteRecherche()
18
 *
18
 *
19
 * Si <Utilisateur> est fourni, celui-ci doit être authentifié
19
 * Si <Utilisateur> est fourni, celui-ci doit être authentifié
20
 * TODO: export des données public et non-sensible d'un utilisateur
20
 * TODO: export des données public et non-sensible d'un utilisateur
21
 *
21
 *
22
 * Si <Utilisateur> est fourni, le observations seront le résultat de l'intersection des 2 contraintes
22
 * Si <Utilisateur> est fourni, le observations seront le résultat de l'intersection des 2 contraintes
23
 *
23
 *
24
 * @internal   Mininum PHP version : 5.2
24
 * @internal   Mininum PHP version : 5.2
25
 * @category   CEL
25
 * @category   CEL
26
 * @package    Services
26
 * @package    Services
27
 * @subpackage Observations
27
 * @subpackage Observations
28
 * @version    0.1
28
 * @version    0.1
29
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
29
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
30
 * @author     Raphaël Droz <raphael@tela-botania.org>
30
 * @author     Raphaël Droz <raphael@tela-botania.org>
31
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
31
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
32
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
32
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
33
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
33
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
34
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
34
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
35
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
35
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
36
 */
36
 */
37
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
37
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
38
ini_set('html_errors', 0);
38
ini_set('html_errors', 0);
39
ini_set('xdebug.cli_color', 2);
39
ini_set('xdebug.cli_color', 2);
40
require_once 'lib/PHPExcel/Classes/PHPExcel.php';
40
require_once 'lib/PHPExcel/Classes/PHPExcel.php';
41
require_once 'lib/FormateurGroupeColonne.php';
41
require_once 'lib/FormateurGroupeColonne.php';
42
 
42
 
43
class ExportXLS extends Cel  {
43
class ExportXLS extends Cel  {
44
 
44
 
45
	private $id_utilisateur = NULL;
45
	private $id_utilisateur = NULL;
46
	private $parametres_defaut = array('range' => '*', 'format' => 'CSV');
46
	private $parametres_defaut = array('range' => '*', 'format' => 'CSV');
47
 
47
 
48
	private $filtres_autorises = array(
48
	private $filtres_autorises = array(
49
		'id_utilisateur' => 'id_utilisateur',
49
		'id_utilisateur' => 'id_utilisateur',
50
		'utilisateur' => 'courriel_utilisateur',
50
		'utilisateur' => 'courriel_utilisateur',
51
		'commune' => 'zone_geo',
51
		'commune' => 'zone_geo',
52
		'dept' => 'departement',
52
		'dept' => 'departement',
53
		'projet' => 'mots_cles',
53
		'projet' => 'mots_cles',
54
		'num_taxon' => 'nt',
54
		'num_taxon' => 'nt',
55
		'date_debut' => 'date_debut',
55
		'date_debut' => 'date_debut',
56
		'date_fin' => 'date_fin',
56
		'date_fin' => 'date_fin',
57
		'taxon' => 'taxon'
57
		'taxon' => 'taxon'
58
	);
58
	);
59
 
59
 
60
	public function __construct($config) {
60
	public function __construct($config) {
61
		parent::__construct($config);
61
		parent::__construct($config);
62
	}
62
	}
63
 
63
 
64
	public function getRessource() {
64
	public function getRessource() {
65
		return $this->getElement(array());
65
		return $this->getElement(array());
66
	}
66
	}
67
 
67
 
68
	public function getElement($uid) {
68
	public function getElement($uid) {
69
		$parametres_format = $this->traiterParametresFormat($uid, $_GET);
69
		$parametres_format = $this->traiterParametresFormat($uid, $_GET);
70
		$filtres = $this->traiterFiltres($_GET);
70
		$filtres = $this->traiterFiltres($_GET);
71
		$this->export($parametres_format, $filtres);
71
		$this->export($parametres_format, $filtres);
72
		exit();
72
		exit();
73
	}
73
	}
74
 
74
 
75
	private function traiterParametresFormat($uid, $params) {
75
	private function traiterParametresFormat($uid, $params) {
76
		$parametres = $this->parametres_defaut;
76
		$parametres = $this->parametres_defaut;
77
		if (isset($params['format'])) {
77
		if (isset($params['format'])) {
78
			if($params['format'] == 'csv') $parametres['format'] = 'CSV';
78
			if($params['format'] == 'csv') $parametres['format'] = 'CSV';
79
			if($params['format'] == 'xls') $parametres['format'] = 'Excel5';
79
			if($params['format'] == 'xls') $parametres['format'] = 'Excel5';
80
			if($params['format'] == 'xlsx') $parametres['format'] = 'Excel2007';
80
			if($params['format'] == 'xlsx') $parametres['format'] = 'Excel2007';
81
			if($params['format'] == 'pdf') $parametres['format'] = 'pdf';
81
			if($params['format'] == 'pdf') $parametres['format'] = 'pdf';
82
		}
82
		}
83
		// TODO: $params['part'] pour le multi-part
83
		// TODO: $params['part'] pour le multi-part
84
		$parametres['widget'] = isset($params['widget']) ? $params['widget'] : 'CEL';
84
		$parametres['widget'] = isset($params['widget']) ? $params['widget'] : 'CEL';
85
		$parametres['debut'] = isset($params['debut']) ? intval($params['debut']) : 0;
85
		$parametres['debut'] = isset($params['debut']) ? intval($params['debut']) : 0;
86
		$parametres['limite'] = isset($params['limite']) ? intval($params['limite']) : 0;
86
		$parametres['limite'] = isset($params['limite']) ? intval($params['limite']) : 0;
87
		$parametres['id_utilisateur'] = $this->traiterIdUtilisateur($uid);
87
		$parametres['id_utilisateur'] = $this->traiterIdUtilisateur($uid);
88
		$parametres['groupe_champs'] = isset($params['colonnes']) ? $params['colonnes'] : 'standard,avance';
88
		$parametres['groupe_champs'] = isset($params['colonnes']) ? $params['colonnes'] : 'standard,avance';
89
 
89
 
90
		return $parametres;
90
		return $parametres;
91
	}
91
	}
92
 
92
 
93
	private function traiterIdUtilisateur($uid) {
93
	private function traiterIdUtilisateur($uid) {
94
		$id_utilisateur = null;
94
		$id_utilisateur = null;
95
		// TODO: controleUtilisateur()
95
		// TODO: controleUtilisateur()
96
		if (isset($uid[0])) {
96
		if (isset($uid[0])) {
97
			$id_utilisateur = intval($uid[0]);
97
			$id_utilisateur = intval($uid[0]);
98
		}
98
		}
99
		return $id_utilisateur;
99
		return $id_utilisateur;
100
	}
100
	}
101
 
101
 
102
	private function traiterFiltres($params) {
102
	private function traiterFiltres($params) {
103
		$obs_ids = $this->traiterObsIds($params);
103
		$obs_ids = $this->traiterObsIds($params);
104
		$filtres = array();
104
		$filtres = array();
105
		if (!$obs_ids || count($obs_ids) == 1 && $obs_ids[0] == '*') {
105
		if (!$obs_ids || count($obs_ids) == 1 && $obs_ids[0] == '*') {
106
			unset($filtres['sql_brut']);
106
			unset($filtres['sql_brut']);
107
		} else {
107
		} else {
108
			$filtres = Array('sql_brut' =>
108
			$filtres = Array('sql_brut' =>
109
			sprintf('id_observation IN (%s)', implode(',', $obs_ids)));
109
			sprintf('id_observation IN (%s)', implode(',', $obs_ids)));
110
		}
110
		}
111
		foreach ($params as $cle => $valeur) {
111
		foreach ($params as $cle => $valeur) {
112
			if (trim($valeur) != '' && isset($this->filtres_autorises[$cle])) {
112
			if (trim($valeur) != '' && isset($this->filtres_autorises[$cle])) {
113
				$filtres[$this->filtres_autorises[$cle]] = $valeur;
113
				$filtres[$this->filtres_autorises[$cle]] = $valeur;
114
			}
114
			}
115
		}
115
		}
116
		return $filtres;
116
		return $filtres;
117
	}
117
	}
118
 
118
 
119
	private function traiterObsIds($params) {
119
	private function traiterObsIds($params) {
120
		$obs_ids = Array('*');
120
		$obs_ids = Array('*');
121
		if (isset($params['range']) && trim($params['range']) != '*') {
121
		if (isset($params['range']) && trim($params['range']) != '*') {
122
			// trim() car: `POST http://url<<<"range=*"`
122
			// trim() car: `POST http://url<<<"range=*"`
123
			$obs_ids = self::rangeToList(trim($params['range']));
123
			$obs_ids = self::rangeToList(trim($params['range']));
124
		}
124
		}
125
		return $obs_ids;
125
		return $obs_ids;
126
	}
126
	}
127
 
127
 
128
	/*
128
	/*
129
	 * $param: Tableau associatif, indexes supportés:
129
	 * $param: Tableau associatif, indexes supportés:
130
	 *   - widget: le nom du widget d'origine (utilisé pour les méta-données du tableur)
130
	 *   - widget: le nom du widget d'origine (utilisé pour les méta-données du tableur)
131
	 *
131
	 *
132
	 */
132
	 */
133
	private function export(Array $parametres_format = Array(),Array $filtres = array()) {
133
	private function export(Array $parametres_format = Array(),Array $filtres = array()) {
134
		$chercheur_observations = new RechercheObservation($this->config);
134
		$chercheur_observations = new RechercheObservation($this->config);
135
 
135
 
136
		$observations = $chercheur_observations
136
		$observations = $chercheur_observations
137
			->rechercherObservations($parametres_format['id_utilisateur'], $filtres, $parametres_format['debut'], $parametres_format['limite'], TRUE)
137
			->rechercherObservations($parametres_format['id_utilisateur'], $filtres, $parametres_format['debut'], $parametres_format['limite'], TRUE)
138
			->get();
138
			->get();
139
		// debug //echo ($chercheur_observations->requete_selection_observations);
139
		// debug //echo ($chercheur_observations->requete_selection_observations);
140
		// XXX: malheureusement l'instance de JRest n'est pas accessible ici
140
		// XXX: malheureusement l'instance de JRest n'est pas accessible ici
141
		if (!$observations) {
141
		if (!$observations) {
142
			header('HTTP/1.0 204 No Content');
142
			header('HTTP/1.0 204 No Content');
143
			exit();
143
			exit();
144
		}
144
		}
145
 
145
 
146
		if ($parametres_format['format'] == 'pdf') {
146
		if ($parametres_format['format'] == 'pdf') {
147
			if (count($observations) > 300) {
147
			if (count($observations) > 300) {
148
				die('too much');
148
				die('too much');
149
			}
149
			}
150
			require_once('GenerateurPDF.php');
150
			require_once('GenerateurPDF.php');
151
 
151
 
152
			$pdf = new GenerateurPDF();
152
			$pdf = new GenerateurPDF();
153
			$pdf->export($observations);
153
			$pdf->export($observations);
154
			//$pdf->export1($observations);
154
			//$pdf->export1($observations);
155
			//$pdf->export2($observations);
155
			//$pdf->export2($observations);
156
			$pdf->pdf->Output('etiquettes.pdf', 'I');
156
			$pdf->pdf->Output('etiquettes.pdf', 'I');
157
			die();
157
			die();
158
		}
158
		}
159
 
159
 
160
		$colonnes = FormateurGroupeColonne::nomEnsembleVersListeColonnes($parametres_format['groupe_champs']);
160
		$colonnes = FormateurGroupeColonne::nomEnsembleVersListeColonnes($parametres_format['groupe_champs']);
161
		// $colonne_abbrev = array_keys($colonnes);
161
		// $colonne_abbrev = array_keys($colonnes);
162
		$objPHPExcel = $this->gerenerFeuilleImportFormatee($parametres_format);
162
		$objPHPExcel = $this->gerenerFeuilleImportFormatee($parametres_format);
163
		$feuille = $objPHPExcel->setActiveSheetIndex(0);
163
		$feuille = $objPHPExcel->setActiveSheetIndex(0);
164
		// attention formaterColonnesFeuille prend ses 2 premiers paramètres par référence
164
		// attention formaterColonnesFeuille prend ses 2 premiers paramètres par référence
165
		$this->formaterColonnesFeuille($feuille, $colonnes, $parametres_format);
165
		$this->formaterColonnesFeuille($feuille, $colonnes, $parametres_format);
166
		$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(12);
166
		$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(12);
167
 
167
 
168
		$no_ligne = 2;
168
		$no_ligne = 2;
169
		foreach ($observations as $obs) {
169
		foreach ($observations as $obs) {
170
			// attention traiterLigneObservation prend ses 3 premiers paramètres par référence
170
			// attention traiterLigneObservation prend ses 3 premiers paramètres par référence
171
			$this->traiterLigneObservation($obs, $colonnes, $feuille, $no_ligne);
171
			$this->traiterLigneObservation($obs, $colonnes, $feuille, $no_ligne);
172
			$no_ligne++;
172
			$no_ligne++;
173
		}
173
		}
174
 
174
 
175
		$this->envoyerFeuille($objPHPExcel, $parametres_format);
175
		$this->envoyerFeuille($objPHPExcel, $parametres_format);
176
	}
176
	}
177
 
177
 
178
	private function envoyerFeuille($objPHPExcel, $parametres_format) {
178
	private function envoyerFeuille($objPHPExcel, $parametres_format) {
179
		header('Content-Type: application/vnd.ms-excel');
179
		header('Content-Type: application/vnd.ms-excel');
180
		header('Content-Disposition: attachment; filename="liste.xls"; charset=utf-8');
180
		header('Content-Disposition: attachment; filename="liste.xls"; charset=utf-8');
181
		header('Cache-Control: max-age=0');
181
		header('Cache-Control: max-age=0');
182
 
182
 
183
		// csv|xls|xlsx => CSV|Excel5|Excel2007
183
		// csv|xls|xlsx => CSV|Excel5|Excel2007
184
		// Note: le format Excel2007 utilise un fichier temporaire
184
		// Note: le format Excel2007 utilise un fichier temporaire
185
		$generateur = PHPExcel_IOFactory::createWriter($objPHPExcel, $parametres_format['format']);
185
		$generateur = PHPExcel_IOFactory::createWriter($objPHPExcel, $parametres_format['format']);
186
		$generateur->save('php://output');
186
		$generateur->save('php://output');exit;
187
		exit;
-
 
188
	}
187
	}
189
 
188
 
190
	private function traiterLigneObservation(&$obs, &$colonnes, &$feuille, $no_ligne) {
189
	private function traiterLigneObservation(&$obs, &$colonnes, &$feuille, $no_ligne) {
191
		$no_colonne = 0;
190
		$no_colonne = 0;
192
		foreach ($colonnes as $abbrev => $colonne) {
191
		foreach ($colonnes as $abbrev => $colonne) {
193
			$valeur = null;
192
			$valeur = null;
194
			if ($colonne['extra'] == 2 || ! is_null($colonne['dyna'])) {
193
			if ($colonne['extra'] == 2 || ! is_null($colonne['dyna'])) {
195
				continue;
194
				continue;
196
			}
195
			}
197
 
196
 
198
			// valeur direct depuis cel_obs ?
197
			// valeur direct depuis cel_obs ?
199
			if (isset($obs[$abbrev])) {
198
			if (isset($obs[$abbrev])) {
200
				$valeur = $obs[$abbrev];
199
				$valeur = $obs[$abbrev];
201
			}
200
			}
202
 
201
 
203
			// pré-processeur de la champs
202
			// pré-processeur de la champs
204
			if (function_exists($colonne['fonction'])) {
203
			if (function_exists($colonne['fonction'])) {
205
				$valeur = $colonne['fonction']($valeur);
204
				$valeur = $colonne['fonction']($valeur);
206
			} else if (method_exists('FormateurGroupeColonne', $colonne['fonction'])) {
205
			} else if (method_exists('FormateurGroupeColonne', $colonne['fonction'])) {
207
				$valeur = call_user_func(array('FormateurGroupeColonne', $colonne['fonction']), $valeur);
206
				$valeur = call_user_func(array('FormateurGroupeColonne', $colonne['fonction']), $valeur);
208
			} else if (method_exists(__CLASS__, $colonne['fonction'])) {
207
			} else if (method_exists(__CLASS__, $colonne['fonction'])) {
209
				$valeur = call_user_func(array(__CLASS__, $colonne['fonction']), $valeur);
208
				$valeur = call_user_func(array(__CLASS__, $colonne['fonction']), $valeur);
210
			} else if ($colonne['fonction']) {
209
			} else if ($colonne['fonction']) {
211
				die("méthode {$colonne['fonction']} introuvable");
210
				die("méthode {$colonne['fonction']} introuvable");
212
			} else if (function_exists($colonne['fonction_data'])) { // fonction pour obtenir des champs (étendus)
211
			} else if (function_exists($colonne['fonction_data'])) { // fonction pour obtenir des champs (étendus)
213
				$valeur = $colonne['fonction_data']($obs);
212
				$valeur = $colonne['fonction_data']($obs);
214
			} else if (method_exists(__CLASS__, $colonne['fonction_data'])) {
213
			} else if (method_exists(__CLASS__, $colonne['fonction_data'])) {
215
				$valeur = call_user_func(array(__CLASS__, $colonne['fonction_data']), $obs);
214
				$valeur = call_user_func(array(__CLASS__, $colonne['fonction_data']), $obs);
216
			}
215
			}
217
 
216
 
218
			// // cette section devrait être vide:
217
			// // cette section devrait être vide:
219
			// // cas particuliers ingérable avec l'architecture actuelle:
218
			// // cas particuliers ingérable avec l'architecture actuelle:
220
			if (false && $abbrev == 'date_observation' && $valeur == "0000-00-00") {
219
			if (false && $abbrev == 'date_observation' && $valeur == "0000-00-00") {
221
				/* blah */
220
				/* blah */
222
			}
221
			}
223
			if ($abbrev == 'images') {
222
			if ($abbrev == 'images') {
224
				$valeur = FormateurGroupeColonne::getImages($obs, $this->id_utilisateur, $this);
223
				$valeur = FormateurGroupeColonne::getImages($obs, $this->id_utilisateur, $this);
225
			}
224
			}
226
			if ($abbrev == 'nom-commun') {
225
			if ($abbrev == 'nom-commun') {
227
				$valeur = FormateurGroupeColonne::getNomCommun_v4($obs, $this);
226
				$valeur = FormateurGroupeColonne::getNomCommun_v4($obs, $this);
228
			}
227
			}
229
 
228
 
230
			// // fin de section "cas particuliers"
229
			// // fin de section "cas particuliers"
231
			$feuille->setCellValueByColumnAndRow($no_colonne, $no_ligne, $valeur);
230
			$feuille->setCellValueByColumnAndRow($no_colonne, $no_ligne, $valeur);
232
			$no_colonne++;
231
			$no_colonne++;
233
		}
232
		}
234
	}
233
	}
235
 
234
 
236
	private function gerenerFeuilleImportFormatee($parametres_format) {
235
	private function gerenerFeuilleImportFormatee($parametres_format) {
237
		$objPHPExcel = new PHPExcel();
236
		$objPHPExcel = new PHPExcel();
238
 
237
 
239
		$objPHPExcel->getProperties()->setCreator($parametres_format['widget']) // ou $uid ?
238
		$objPHPExcel->getProperties()->setCreator($parametres_format['widget']) // ou $uid ?
240
			->setLastModifiedBy("XX") // TODO: $uid
239
			->setLastModifiedBy("XX") // TODO: $uid
241
			->setTitle("Export des observation du carnet en ligne") // TODO
240
			->setTitle("Export des observation du carnet en ligne") // TODO
242
			->setSubject("Export") // TODO
241
			->setSubject("Export") // TODO
243
			->setDescription("Export");
242
			->setDescription("Export");
244
 
243
 
245
		$objPHPExcel->getActiveSheet()->setTitle("Observations");
244
		$objPHPExcel->getActiveSheet()->setTitle("Observations");
246
		return $objPHPExcel;
245
		return $objPHPExcel;
247
	}
246
	}
248
 
247
 
249
	private function formaterColonnesFeuille(&$feuille, &$colonnes, $parametres_format) {
248
	private function formaterColonnesFeuille(&$feuille, &$colonnes, $parametres_format) {
250
		$colid = 0;
249
		$colid = 0;
251
		foreach ($colonnes as $colonne) {
250
		foreach ($colonnes as $colonne) {
252
			if ($colonne['extra'] == 2) {
251
			if ($colonne['extra'] == 2) {
253
				continue;
252
				continue;
254
			}
253
			}
255
 
254
 
256
			$feuille->setCellValueByColumnAndRow($colid, 1, $colonne['nom']);
255
			$feuille->setCellValueByColumnAndRow($colid, 1, $colonne['nom']);
257
			if ($colonne['extra'] == 1) {
256
			if ($colonne['extra'] == 1) {
258
				$feuille->getStyleByColumnAndRow($colid, 1)->getBorders()->applyFromArray(
257
				$feuille->getStyleByColumnAndRow($colid, 1)->getBorders()->applyFromArray(
259
					array(
258
					array(
260
						'allborders' => array(
259
						'allborders' => array(
261
							'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
260
							'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
262
							'color' => array('rgb' => PHPExcel_Style_Color::COLOR_BLUE)
261
							'color' => array('rgb' => PHPExcel_Style_Color::COLOR_BLUE)
263
						)
262
						)
264
					)
263
					)
265
				);
264
				);
266
			}
265
			}
267
			if (! $colonne['importable']) {
266
			if (! $colonne['importable']) {
268
				$feuille->getStyleByColumnAndRow($colid, 1)->getFill()->applyFromArray(
267
				$feuille->getStyleByColumnAndRow($colid, 1)->getFill()->applyFromArray(
269
					array(
268
					array(
270
						'type' => PHPExcel_Style_Fill::FILL_SOLID,
269
						'type' => PHPExcel_Style_Fill::FILL_SOLID,
271
						'color' => array('rgb' => PHPExcel_Style_Color::COLOR_YELLOW)
270
						'color' => array('rgb' => PHPExcel_Style_Color::COLOR_YELLOW)
272
					)
271
					)
273
				);
272
				);
274
			}
273
			}
275
			$colid++;
274
			$colid++;
276
		}
275
		}
277
	}
276
	}
278
 
277
 
279
	/*
278
	/*
280
	 * @param $fieldSets: un range, eg: 1-5,8,32,58-101
279
	 * @param $fieldSets: un range, eg: 1-5,8,32,58-101
281
	 * @return un tableau trié, eg: 1,2,3,4,5,8,32,58,...,101
280
	 * @return un tableau trié, eg: 1,2,3,4,5,8,32,58,...,101
282
	 * http://stackoverflow.com/questions/7698664/converting-a-range-or-partial-array-in-the-form-3-6-or-3-6-12-into-an-arra
281
	 * http://stackoverflow.com/questions/7698664/converting-a-range-or-partial-array-in-the-form-3-6-or-3-6-12-into-an-arra
283
	 */
282
	 */
284
	static function rangeToList($in = '') {
283
	static function rangeToList($in = '') {
285
		$inSets = explode(',', $in);
284
		$inSets = explode(',', $in);
286
		$outSets = array();
285
		$outSets = array();
287
 
286
 
288
		foreach ($inSets as $inSet) {
287
		foreach ($inSets as $inSet) {
289
			list($start,$end) = explode('-', $inSet . '-' . $inSet);
288
			list($start,$end) = explode('-', $inSet . '-' . $inSet);
290
			// ignore les ranges trop importants
289
			// ignore les ranges trop importants
291
			if ($start > 10000000 || $end > 10000000 || abs($start-$end) > 10000) {
290
			if ($start > 10000000 || $end > 10000000 || abs($start-$end) > 10000) {
292
				continue;
291
				continue;
293
			}
292
			}
294
			$outSets = array_merge($outSets,range($start,$end));
293
			$outSets = array_merge($outSets,range($start,$end));
295
		}
294
		}
296
		$outSets = array_unique($outSets);
295
		$outSets = array_unique($outSets);
297
		$outSets = array_filter($outSets, 'is_numeric');
296
		$outSets = array_filter($outSets, 'is_numeric');
298
		sort($outSets);
297
		sort($outSets);
299
		return $outSets;
298
		return $outSets;
300
	}
299
	}
301
}
300
}