Subversion Repositories Applications.referentiel

Rev

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

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