Subversion Repositories Applications.referentiel

Rev

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

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