Subversion Repositories Applications.referentiel

Rev

Rev 48 | Rev 51 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 48 Rev 49
Line 17... Line 17...
17
	const SCRIPT_A_LANCER = 'versionnage';
17
	const SCRIPT_A_LANCER = 'versionnage';
Line 18... Line 18...
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
		'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;
Line 25... Line 25...
25
	private $traitementDao = null;
25
	private $traitementDao = null;
Line 97... Line 97...
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] = strip_tags(stripslashes($_POST[$champ]));
102
				$version[$champ] = stripslashes($_POST[$champ]);
103
			} else {
103
			} else {
Line 104... Line 104...
104
				$version[$champ] = $this->getValeurParDefaut($champ);
104
				$version[$champ] = $this->getValeurParDefaut($champ);
105
				
105
				
Line 119... Line 119...
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();
-
 
125
			$parametres_serialises = serialize($parametres);
124
			$this->ajouterTraitement($this->referentiel, self::SCRIPT_A_LANCER);
126
			$this->ajouterTraitementParametre($this->referentiel, $parametres_serialises, self::SCRIPT_A_LANCER);
125
		}
127
		}
126
		$this->afficherInterface();
128
		$this->afficherInterface();
127
	}
129
	}
Line 128... Line 130...
128
	
130
	
129
	/**
131
	/**
130
	 * Vérifie les données du formulaire
132
	 * Vérifie les données du formulaire
131
	 */
133
	 */
132
	public function verifierMetadonnees() {
134
	public function verifierMetadonnees() {
133
		$ok = true;
135
		$ok = true;
-
 
136
		if (! $this->verifierChampsObligatoires()) {
-
 
137
			$ok = false;
-
 
138
		}
-
 
139
		if (! $this->verifierChampsMajuscule()) {
-
 
140
			$ok = false;
-
 
141
		}
-
 
142
		if (! $this->verifierChampsContact()) {
-
 
143
			$ok = false;
-
 
144
		}
-
 
145
		if (! $this->verifierChampsCourriel()) {
-
 
146
			$ok = false;
134
		$ok = ($this->verifierChampsObligatoires()) ? true : false;
147
		}
135
		return $ok;
148
		return $ok;
Line 136... Line 149...
136
	}
149
	}
137
	
150
	
Line 141... Line 154...
141
			'acronyme' => 'Acronyme',
154
			'acronyme' => 'Acronyme',
142
			'version' => 'Version',
155
			'version' => 'Version',
143
			'auteur_principal' => 'Auteur Principal',
156
			'auteur_principal' => 'Auteur Principal',
144
			'coordinateur' => 'coordinateur',
157
			'coordinateur' => 'coordinateur',
145
			'contact' => 'Courriel de contact',
158
			'contact' => 'Courriel de contact',
-
 
159
			'classification' => 'Classification par défaut',
146
			'dom_tax' => 'Domaine taxonomique',
160
			'dom_tax' => 'Domaine taxonomique',
147
			'dom_geo' => 'Domaine géographique',
161
			'dom_geo' => 'Domaine géographique',
148
			'dom_code' => 'Codes botaniques utilisés',
162
			'dom_code' => 'Codes botaniques utilisés',
149
			'referencement' => 'Comment citer ce référentiel?');
163
			'referencement' => 'Comment citer ce référentiel?');
150
		foreach ($champs_obligatoires as $champ_id => $champ_nom) {
164
		foreach ($champs_obligatoires as $champ_id => $champ_nom) {
Line 153... Line 167...
153
				$ok = false;
167
				$ok = false;
154
			}
168
			}
155
		}
169
		}
156
		return $ok;
170
		return $ok;
157
	}
171
	}
-
 
172
	
-
 
173
	public function verifierChampsMajuscule() {
-
 
174
		$ok = true;
-
 
175
		$champs_en_majuscule = array('acronyme' => 'Acronyme');
-
 
176
		foreach ($champs_en_majuscule as $champ_id => $champ_nom) {
-
 
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.");
-
 
179
				$ok = false;
-
 
180
			}
-
 
181
		}
-
 
182
		return $ok;
-
 
183
	}
-
 
184
	
-
 
185
	/**
-
 
186
	 * Vérifie la mise en majuscule
-
 
187
	 */
-
 
188
	public function verifierMajusculeSansAccent($txt) {
-
 
189
		$ok = (preg_match('/^[A-Z]+$/', $txt)) ? true : false;
-
 
190
		return $ok;
-
 
191
	}
-
 
192
	
-
 
193
	public function verifierChampsContact() {
-
 
194
		$ok = true;
-
 
195
		$champs_contact = array('auteur_principal' => 'Auteur Principal',
-
 
196
			'coordinateur' => 'coordinateur',
-
 
197
			'contributeur' => 'Auteurs/Contributeurs');
-
 
198
		foreach ($champs_contact as $champ_id => $champ_nom) {
-
 
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>.");
-
 
201
				$ok = false;
-
 
202
			}
-
 
203
		}
-
 
204
		return $ok;
-
 
205
	}
-
 
206
	
-
 
207
	/**
-
 
208
	 * Vérifie que le texte est au format : 
-
 
209
	 * Prénom1 NOM1 (Organisation1) <courriel1>,
-
 
210
	 * Prénom2 NOM2 (Organisation2) <courriel2>. 
-
 
211
	 */
-
 
212
	public function verifierContact($txt) {
-
 
213
		$ok = true;
-
 
214
		if ($txt != '') {
-
 
215
			$pp = Pattern::PRENOM;
-
 
216
			$pn = Pattern::NOM;
-
 
217
			$po = "\([^\)]+\)";// Pattern organisation
-
 
218
			$pc = Pattern::COURRIEL;
-
 
219
 
-
 
220
			$contacts = explode(',', $txt);
-
 
221
			foreach ($contacts as $contact) {
-
 
222
				$contact = trim($contact);
-
 
223
				if (! preg_match("/^$pp $pn $po <$pc>(?:|.)$/u", $contact)) {
-
 
224
					$ok = false;
-
 
225
				}
-
 
226
			}
-
 
227
		}
-
 
228
		return $ok;
-
 
229
	}
-
 
230
	
-
 
231
	public function verifierChampsCourriel() {
-
 
232
		$ok = true;
-
 
233
		$champs_courriel = array('contact' => 'Courriel de contact');
-
 
234
		foreach ($champs_courriel as $champ_id => $champ_nom) {
-
 
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.");
-
 
237
				$ok = false;
-
 
238
			}
-
 
239
		}
-
 
240
		return $ok;
-
 
241
	}
-
 
242
	
-
 
243
	/**
-
 
244
	 * Vérifie que le texte est une adresse de courriel valide.
-
 
245
	 */
-
 
246
	public function verifierCourriel($txt) {
-
 
247
		$pattern_courriel =  Pattern::COURRIEL;
-
 
248
		$ok = (preg_match('/^'.$pattern_courriel.'+$/', $txt)) ? true : false;
-
 
249
		return $ok;
-
 
250
	}
158
}
251
}
159
?>
252
?>
160
253