Subversion Repositories Applications.referentiel

Rev

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

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