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