Subversion Repositories Applications.referentiel

Rev

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

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