Subversion Repositories Applications.referentiel

Rev

Rev 156 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 181
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Classe Controleur du module Versionnage.
4
 * Classe Controleur du module Versionnage.
5
 * Permet de publier une nouvelle version d'un référentiel de travail. 
5
 * Permet de publier une nouvelle version d'un référentiel de travail. 
6
 * 
6
 * 
7
 * @package		Referentiel
7
 * @package		Referentiel
8
 * @category	Php5.2
8
 * @category	Php5.2
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @copyright	2010 Tela-Botanica
10
 * @copyright	2010 Tela-Botanica
11
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @version		SVN: $Id$
13
 * @version		SVN: $Id$
14
 */
14
 */
15
class Versionnage extends AppliControleur {
15
class Versionnage extends AppliControleur {
16
	
16
	
17
	const SCRIPT_A_LANCER = 'versionnage';
17
	const SCRIPT_A_LANCER = 'versionnage';
18
	
18
	
19
	private $version = array('titre', 'acronyme', 'version', 'date_prod', 
19
	private $version = array('titre', 'acronyme', 'version', 'date_prod', 
20
		'auteur_principal', 'coordinateur', 'editeur', 'contact', 
20
		'auteur_principal', 'coordinateur', 'editeur', 'contact', 
21
		'contributeur', 
21
		'contributeur', 
22
		'classification', 'dom_tax', 'dom_geo', 'dom_code', 
22
		'classification', 'dom_tax', 'dom_geo', 'dom_code', 
23
		'source', 'copyright', 'licence', 'referencement');
23
		'source', 'copyright', 'licence', 'referencement');
24
	private $referentiel = null;
24
	private $referentiel = null;
-
 
25
	private $referentielDao = null;
25
	private $traitementDao = null;
26
	private $traitementDao = null;
26
	
27
	
27
	public function __construct()  {
28
	public function __construct()  {
28
		parent::__construct();
29
		parent::__construct();
29
		
30
		
30
		// Récupération de paramêtres
31
		// Récupération de paramêtres
31
		if (isset($_GET['ref'])) { // code du projet courrant
32
		if (isset($_GET['ref'])) { // code du projet courrant
32
			$this->referentiel = strtolower($_GET['ref']);
33
			$this->referentiel = strtolower($_GET['ref']);
33
		}
34
		}
34
		
35
		
35
		// Chargement des DAO nécessaires
36
		// Chargement des DAO nécessaires
-
 
37
		$this->referentielDao = new ReferentielDao();
36
		$this->traitementDao = new TraitementDao();
38
		$this->traitementDao = new TraitementDao();
37
	}
39
	}
38
	
40
	
39
	//+----------------------------------------------------------------------------------------------------------------+
41
	//+----------------------------------------------------------------------------------------------------------------+
40
	// Méthodes
42
	// Méthodes
41
	/**
43
	/**
42
	 * Fonction d'affichage par défaut
44
	 * Fonction d'affichage par défaut
43
	 */
45
	 */
44
	public function executerActionParDefaut() {
46
	public function executerActionParDefaut() {
45
		return $this->afficherInterface();
47
		return $this->afficherInterface();
46
	}
48
	}
47
 
49
 
48
	/**
50
	/**
49
	 * Affiche le formulaire de demande de versionnage
51
	 * Affiche le formulaire de demande de versionnage
50
	 */
52
	 */
51
	public function afficherInterface() {
53
	public function afficherInterface() {
52
		if ($this->authentifierCoordinateur()) {
54
		if ($this->authentifierCoordinateur()) {
53
			$donnees = array();
55
			$donnees = array();
54
			$this->definirCommeModulePrincipal(get_class($this));
56
			$this->definirCommeModulePrincipal(get_class($this));
55
			
57
			
56
			// Paramêtres pour l'url du formulaire
58
			// Paramêtres pour l'url du formulaire
57
			$this->url->unsetVariablesRequete(array('module', 'action', 'ref'));
59
			$this->url->unsetVariablesRequete(array('module', 'action', 'ref'));
58
			$donnees['url_form'] = $this->obtenirUrlDemandeVersionnage($this->referentiel);
60
			$donnees['url_form'] = $this->obtenirUrlDemandeVersionnage($this->referentiel);
59
			$donnees['url_module'] = 'Versionnage';
61
			$donnees['url_module'] = 'Versionnage';
60
			$donnees['url_action_rafraichir'] = 'afficherInterface';
62
			$donnees['url_action_rafraichir'] = 'afficherInterface';
61
			
63
			
62
			$donnees['version'] = $this->instancierChampsVersionnage();
64
			$donnees['version'] = $this->instancierChampsVersionnage();
63
			$donnees['version'] = $this->traiterCasesACocher($donnees['version']);
65
			$donnees['version'] = $this->traiterCasesACocher($donnees['version']);
64
			
66
			
65
			// Récupération des paramètres de configuration du manuel des référentiels
67
			// Récupération des paramètres de configuration du manuel des référentiels
66
			$donnees['domaine_geo'] = explode(';', $this->manuel['domaine_geo']);
68
			$donnees['domaine_geo'] = explode(';', $this->manuel['domaine_geo']);
67
			$donnees['domaine_taxo'] = explode(';', $this->manuel['domaine_taxo']);
69
			$donnees['domaine_taxo'] = explode(';', $this->manuel['domaine_taxo']);
68
			$donnees['domaine_code'] = explode(';', $this->manuel['domaine_code']);
70
			$donnees['domaine_code'] = explode(';', $this->manuel['domaine_code']);
69
			
71
			
70
			// Traitement de l'info sur le code du référentiel
72
			// Traitement de l'info sur le code du référentiel
71
			if (isset($this->referentiel)) {
73
			if (isset($this->referentiel)) {
-
 
74
				// Récupération du nom du référentiel courrant
-
 
75
				$donnees['nom_referentiel'] = $this->referentielDao->getNom($this->referentiel);
-
 
76
				
72
				// Récupération du référentiel courrant
77
				// Récupération du référentiel courrant
73
				$donnees['ref'] = $this->referentiel;
78
				$donnees['ref'] = $this->referentiel;
74
				
79
				
75
				// Recherche des traitements en attente
80
				// Recherche des traitements en attente
76
				$donnees['traitements_en_attente'] = $this->traitementDao->getTraitementsEnAttente($this->referentiel, self::SCRIPT_A_LANCER);
81
				$donnees['traitements_en_attente'] = $this->traitementDao->getTraitementsEnAttente($this->referentiel, self::SCRIPT_A_LANCER);
77
				
82
				
78
				// Recherche des traitements en cours d'éxecution
83
				// Recherche des traitements en cours d'éxecution
79
				$donnees['traitements_en_cours'] = $this->traitementDao->getTraitementsEnCours($this->referentiel, self::SCRIPT_A_LANCER);
84
				$donnees['traitements_en_cours'] = $this->traitementDao->getTraitementsEnCours($this->referentiel, self::SCRIPT_A_LANCER);
80
				
85
				
81
				// Recherche des traitements déjà effectué
86
				// Recherche des traitements déjà effectué
82
				$resultat = $this->traitementDao->getTraitementsTermines($this->referentiel, self::SCRIPT_A_LANCER);
87
				$resultat = $this->traitementDao->getTraitementsTermines($this->referentiel, self::SCRIPT_A_LANCER);
83
				if (is_array($resultat)) {
88
				if (is_array($resultat)) {
84
					// Ajout de l'url vers la fiche du traitement
89
					// Ajout de l'url vers la fiche du traitement
85
					foreach ($resultat as &$traitement) {
90
					foreach ($resultat as &$traitement) {
86
						$traitement['url'] = $this->obtenirUrlFicheTraitement($this->referentiel, $traitement['id_traitement']);
91
						$traitement['url'] = $this->obtenirUrlFicheTraitement($this->referentiel, $traitement['id_traitement']);
87
					}
92
					}
88
					$donnees['traitements_termines'] = $resultat;
93
					$donnees['traitements_termines'] = $resultat;
89
				}
94
				}
90
			} else {
95
			} else {
91
				$this->addMessage("Aucun code de projet de référentiel n'est indiqué (Ex. bdtfx).");
96
				$this->addMessage("Aucun code de projet de référentiel n'est indiqué (Ex. bdtfx).");
92
			}
97
			}
93
			
98
			
94
			$donnees['messages'] = $this->getMessages();
99
			$donnees['messages'] = $this->getMessages();
95
			$this->traiterEsperluette($donnees);
100
			$this->traiterEsperluette($donnees);
96
			$this->setSortie(self::RENDU_CORPS, $this->getVue('form_version', $donnees), false);
101
			$this->setSortie(self::RENDU_CORPS, $this->getVue('form_version', $donnees), false);
97
			$this->construireMenu($this->referentiel);
102
			$this->construireMenu($this->referentiel);
98
			$this->construireFilAriane($this->referentiel);
103
			$this->construireFilAriane($this->referentiel);
99
		}
104
		}
100
	}
105
	}
101
	
106
	
102
	public function instancierChampsVersionnage() {
107
	public function instancierChampsVersionnage() {
103
		$version = array();
108
		$version = array();
104
		foreach ($this->version as $champ) {
109
		foreach ($this->version as $champ) {
105
			if (isset($_POST[$champ])) {
110
			if (isset($_POST[$champ])) {
106
				$version[$champ] = $this->supprimerSlash($_POST[$champ]);
111
				$version[$champ] = $this->supprimerSlash($_POST[$champ]);
107
			} else {
112
			} else {
108
				$version[$champ] = $this->getValeurParDefaut($champ);
113
				$version[$champ] = $this->getValeurParDefaut($champ);
109
				
114
				
110
			}
115
			}
111
		}
116
		}
112
		return $version;
117
		return $version;
113
	}
118
	}
114
	
119
	
115
	public function getValeurParDefaut($champ) {
120
	public function getValeurParDefaut($champ) {
116
		$valeur = '';
121
		$valeur = '';
117
		if ('date_prod' == $champ) {
122
		if ('date_prod' == $champ) {
118
			$valeur = date('Y-m-d');
123
			$valeur = date('Y-m-d');
119
		}
124
		}
120
		return $valeur;
125
		return $valeur;
121
	}
126
	}
122
 
127
 
123
	private function traiterCasesACocher(Array $donnees) {
128
	private function traiterCasesACocher(Array $donnees) {
124
		foreach ($donnees as $cle => $valeur) {
129
		foreach ($donnees as $cle => $valeur) {
125
			if (is_array($valeur)) {
130
			if (is_array($valeur)) {
126
				$this->traiterEsperluette($valeur);
131
				$this->traiterEsperluette($valeur);
127
				$donnees[$cle] = array_flip($valeur);
132
				$donnees[$cle] = array_flip($valeur);
128
			}
133
			}
129
		}
134
		}
130
		return $donnees;
135
		return $donnees;
131
	}
136
	}
132
	
137
	
133
	/**
138
	/**
134
	 * Lance l'ajout d'un traitement
139
	 * Lance l'ajout d'un traitement
135
	 */
140
	 */
136
	public function demanderTraitement() {
141
	public function demanderTraitement() {
137
		if ($this->verifierMetadonnees()) {
142
		if ($this->verifierMetadonnees()) {
138
			$parametres = $this->instancierChampsVersionnage();
143
			$parametres = $this->instancierChampsVersionnage();
139
			$parametres_serialises = serialize($parametres);
144
			$parametres_serialises = serialize($parametres);
140
			$this->ajouterTraitementParametre($this->referentiel, $parametres_serialises, self::SCRIPT_A_LANCER);
145
			$this->ajouterTraitementParametre($this->referentiel, $parametres_serialises, self::SCRIPT_A_LANCER);
141
		}
146
		}
142
		$this->afficherInterface();
147
		$this->afficherInterface();
143
	}
148
	}
144
	
149
	
145
	/**
150
	/**
146
	 * Vérifie les données du formulaire
151
	 * Vérifie les données du formulaire
147
	 */
152
	 */
148
	public function verifierMetadonnees() {
153
	public function verifierMetadonnees() {
149
		$ok = true;
154
		$ok = true;
150
		if (! $this->verifierChampsObligatoires()) {
155
		if (! $this->verifierChampsObligatoires()) {
151
			$ok = false;
156
			$ok = false;
152
		}
157
		}
153
		if (! $this->verifierChampsMajuscule()) {
158
		if (! $this->verifierChampsMajuscule()) {
154
			$ok = false;
159
			$ok = false;
155
		}
160
		}
156
		if (! $this->verifierChampsContact()) {
161
		if (! $this->verifierChampsContact()) {
157
			$ok = false;
162
			$ok = false;
158
		}
163
		}
159
		if (! $this->verifierChampsCourriel()) {
164
		if (! $this->verifierChampsCourriel()) {
160
			$ok = false;
165
			$ok = false;
161
		}
166
		}
162
		return $ok;
167
		return $ok;
163
	}
168
	}
164
	
169
	
165
	public function verifierChampsObligatoires() {
170
	public function verifierChampsObligatoires() {
166
		$ok = true;
171
		$ok = true;
167
		$champs_obligatoires = array('titre' => 'Titre',
172
		$champs_obligatoires = array('titre' => 'Titre',
168
			'acronyme' => 'Acronyme',
173
			'acronyme' => 'Acronyme',
169
			'version' => 'Version',
174
			'version' => 'Version',
170
			'auteur_principal' => 'Auteur Principal',
175
			'auteur_principal' => 'Auteur Principal',
171
			'coordinateur' => 'coordinateur',
176
			'coordinateur' => 'coordinateur',
172
			'contact' => 'Courriel de contact',
177
			'contact' => 'Courriel de contact',
173
			'classification' => 'Classification par défaut',
178
			'classification' => 'Classification par défaut',
174
			'dom_tax' => 'Domaine taxonomique',
179
			'dom_tax' => 'Domaine taxonomique',
175
			'dom_geo' => 'Domaine géographique',
180
			'dom_geo' => 'Domaine géographique',
176
			'dom_code' => 'Codes botaniques utilisés',
181
			'dom_code' => 'Codes botaniques utilisés',
177
			'referencement' => 'Comment citer ce référentiel?');
182
			'referencement' => 'Comment citer ce référentiel?');
178
		foreach ($champs_obligatoires as $champ_id => $champ_nom) {
183
		foreach ($champs_obligatoires as $champ_id => $champ_nom) {
179
			if (!isset($_POST[$champ_id]) || empty($_POST[$champ_id])) {
184
			if (!isset($_POST[$champ_id]) || empty($_POST[$champ_id])) {
180
				$this->addMessage("Le champ '$champ_nom' doit être obligatoirement rempli.");
185
				$this->addMessage("Le champ '$champ_nom' doit être obligatoirement rempli.");
181
				$ok = false;
186
				$ok = false;
182
			}
187
			}
183
		}
188
		}
184
		return $ok;
189
		return $ok;
185
	}
190
	}
186
	
191
	
187
	public function verifierChampsMajuscule() {
192
	public function verifierChampsMajuscule() {
188
		$ok = true;
193
		$ok = true;
189
		$champs_en_majuscule = array('acronyme' => 'Acronyme');
194
		$champs_en_majuscule = array('acronyme' => 'Acronyme');
190
		foreach ($champs_en_majuscule as $champ_id => $champ_nom) {
195
		foreach ($champs_en_majuscule as $champ_id => $champ_nom) {
191
			if (isset($_POST[$champ_id]) && ! $this->verifierMajusculeSansAccent($_POST[$champ_id])) {
196
			if (isset($_POST[$champ_id]) && ! $this->verifierMajusculeSansAccent($_POST[$champ_id])) {
192
				$this->addMessage("Le champ '$champ_nom' doit être obligatoirement composé de majuscules non accentuées.");
197
				$this->addMessage("Le champ '$champ_nom' doit être obligatoirement composé de majuscules non accentuées.");
193
				$ok = false;
198
				$ok = false;
194
			}
199
			}
195
		}
200
		}
196
		return $ok;
201
		return $ok;
197
	}
202
	}
198
	
203
	
199
	/**
204
	/**
200
	 * Vérifie la mise en majuscule
205
	 * Vérifie la mise en majuscule
201
	 */
206
	 */
202
	public function verifierMajusculeSansAccent($txt) {
207
	public function verifierMajusculeSansAccent($txt) {
203
		$ok = (preg_match('/^[A-Z]+$/', $txt)) ? true : false;
208
		$ok = (preg_match('/^[A-Z]+$/', $txt)) ? true : false;
204
		return $ok;
209
		return $ok;
205
	}
210
	}
206
	
211
	
207
	public function verifierChampsContact() {
212
	public function verifierChampsContact() {
208
		$ok = true;
213
		$ok = true;
209
		$champs_contact = array('auteur_principal' => 'Auteur Principal',
214
		$champs_contact = array('auteur_principal' => 'Auteur Principal',
210
			'coordinateur' => 'coordinateur',
215
			'coordinateur' => 'coordinateur',
211
			'contributeur' => 'Auteurs/Contributeurs');
216
			'contributeur' => 'Auteurs/Contributeurs');
212
		foreach ($champs_contact as $champ_id => $champ_nom) {
217
		foreach ($champs_contact as $champ_id => $champ_nom) {
213
			if (isset($_POST[$champ_id]) && ! $this->verifierContact($_POST[$champ_id])) {
218
			if (isset($_POST[$champ_id]) && ! $this->verifierContact($_POST[$champ_id])) {
214
				$this->addMessage("Le champ '$champ_nom' n'est pas au format : Prénom1 NOM1 (Organisation1) [courriel1], Prénom2 NOM2 (Organisation2) [courriel2].");
219
				$this->addMessage("Le champ '$champ_nom' n'est pas au format : Prénom1 NOM1 (Organisation1) [courriel1], Prénom2 NOM2 (Organisation2) [courriel2].");
215
				$ok = false;
220
				$ok = false;
216
			}
221
			}
217
		}
222
		}
218
		return $ok;
223
		return $ok;
219
	}
224
	}
220
	
225
	
221
	/**
226
	/**
222
	 * Vérifie que le texte est au format : 
227
	 * Vérifie que le texte est au format : 
223
	 * Prénom1 NOM1 (Organisation1) <courriel1>,
228
	 * Prénom1 NOM1 (Organisation1) <courriel1>,
224
	 * Prénom2 NOM2 (Organisation2) <courriel2>. 
229
	 * Prénom2 NOM2 (Organisation2) <courriel2>. 
225
	 */
230
	 */
226
	public function verifierContact($txt) {
231
	public function verifierContact($txt) {
227
		$ok = true;
232
		$ok = true;
228
		if ($txt != '') {
233
		if ($txt != '') {
229
			$pp = Pattern::PRENOM;
234
			$pp = Pattern::PRENOM;
230
			$pn = Pattern::NOM;
235
			$pn = Pattern::NOM;
231
			$po = "\([^\)]+\)";// Pattern organisation
236
			$po = "\([^\)]+\)";// Pattern organisation
232
			$pc = Pattern::COURRIEL;
237
			$pc = Pattern::COURRIEL;
233
 
238
 
234
			$contacts = explode(',', $txt);
239
			$contacts = explode(',', $txt);
235
			foreach ($contacts as $contact) {
240
			foreach ($contacts as $contact) {
236
				$contact = trim($contact);
241
				$contact = trim($contact);
237
				if (! preg_match("/^$pp $pn $po \[$pc\](?:|.)$/u", $contact)) {
242
				if (! preg_match("/^$pp $pn $po \[$pc\](?:|.)$/u", $contact)) {
238
					$ok = false;
243
					$ok = false;
239
				}
244
				}
240
			}
245
			}
241
		}
246
		}
242
		return $ok;
247
		return $ok;
243
	}
248
	}
244
	
249
	
245
	public function verifierChampsCourriel() {
250
	public function verifierChampsCourriel() {
246
		$ok = true;
251
		$ok = true;
247
		$champs_courriel = array('contact' => 'Courriel de contact');
252
		$champs_courriel = array('contact' => 'Courriel de contact');
248
		foreach ($champs_courriel as $champ_id => $champ_nom) {
253
		foreach ($champs_courriel as $champ_id => $champ_nom) {
249
			if (isset($_POST[$champ_id]) && ! $this->verifierCourriel($_POST[$champ_id])) {
254
			if (isset($_POST[$champ_id]) && ! $this->verifierCourriel($_POST[$champ_id])) {
250
				$this->addMessage("Le champ '$champ_nom' ne comptient pas une adresse de courriel valide.");
255
				$this->addMessage("Le champ '$champ_nom' ne comptient pas une adresse de courriel valide.");
251
				$ok = false;
256
				$ok = false;
252
			}
257
			}
253
		}
258
		}
254
		return $ok;
259
		return $ok;
255
	}
260
	}
256
	
261
	
257
	/**
262
	/**
258
	 * Vérifie que le texte est une adresse de courriel valide.
263
	 * Vérifie que le texte est une adresse de courriel valide.
259
	 */
264
	 */
260
	public function verifierCourriel($txt) {
265
	public function verifierCourriel($txt) {
261
		$pattern_courriel =  Pattern::COURRIEL;
266
		$pattern_courriel =  Pattern::COURRIEL;
262
		$ok = (preg_match('/^'.$pattern_courriel.'+$/', $txt)) ? true : false;
267
		$ok = (preg_match('/^'.$pattern_courriel.'+$/', $txt)) ? true : false;
263
		return $ok;
268
		return $ok;
264
	}
269
	}
265
}
270
}
266
?>
271
?>