Subversion Repositories eFlore/Applications.cel

Rev

Rev 1502 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1502 aurelien 1
<?php
2
class CelValidationObservation extends Cel {
3
	/**
4
	* Méthode appelée avec une requête de type POST avec un identifiant d'obs.
5
	* Modifie le taxon associé à une observation avec les informations envoyées
1870 raphael 6
	* Utilisé par:
7
	* - del/services/modules/0.1/determinations/ValiderDetermination.php::modifierObservationParDetermination()
1502 aurelien 8
	*
9
	* @param int $uid[0] identifiant observation
10
	* @param pairs array tableau contenant les valeurs à modifier
11
	*/
1870 raphael 12
	public function updateElement($uid, $pairs) {
1502 aurelien 13
		// ce service est uniquement destiné à être appelé en local,
14
		// depuis le serveur lui même
15
		// en particulier par l'application identiplante
16
		$this->controleAppelIpAutorisee();
1870 raphael 17
		self::verifierParametresObligatoires($uid, $pairs);
1502 aurelien 18
		$id = $uid[0];
19
 
20
		$gestion_observation = new GestionObservation($this->config);
21
		$utilisateur = $pairs['ce_utilisateur'];
1870 raphael 22
		unset($pairs['ce_utilisateur'], $pairs['id_observation']);
1502 aurelien 23
		$modification = $gestion_observation->modifierObservationPublique($utilisateur, $id, $pairs);
1870 raphael 24
 
25
		if($modification) {
26
			header("Content-Type: text/plain; charset=utf-8");
27
			die("OK"); // attention, compatibilité avec ValiderDetermination.php de DEL !
1502 aurelien 28
		}
1870 raphael 29
		elseif($modification === 0) {
30
			http_response_code(304); // Not Modified
31
			header("Content-Type: text/plain; charset=utf-8");
32
			die("Not Modified");
33
		}
34
		else {
35
			http_response_code(500); // Internal Server Error
36
			header("Content-Type: text/plain; charset=utf-8");
37
			die("Impossible de modifier l'observation associée à cet identifiant " . mysql_error());
38
		}
1502 aurelien 39
	}
40
 
1870 raphael 41
	static function verifierParametresObligatoires($uid, $params) {
42
		if(!@intval($uid[0]) || !@intval($params['id_observation'])) {
43
			header("Content-Type: text/plain; charset=utf-8");
44
			die("L'identifiant d'observation doit être un entier");
1502 aurelien 45
		}
1870 raphael 46
 
47
		// TODO: check sur 'id_observation' en tant que param est superflu ?
48
		$params_obligatoires = array('id_observation', 'ce_utilisateur', 'nom_sel');
1502 aurelien 49
		foreach($params_obligatoires as $param) {
1870 raphael 50
			if(@trim($params[$param])) continue;
51
			http_response_code(412); // Precondition Failed
52
			header("Content-Type: text/plain; charset=utf-8");
53
			die(sprintf("Paramètre %s manquant (parmi %s)", $param, implode(', ', $params_obligatoires)));
1502 aurelien 54
		}
55
	}
56
}