999 |
aurelien |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
Class CelEfloreImages extends Cel {
|
|
|
4 |
|
|
|
5 |
function getElement($uid) {
|
|
|
6 |
return getRessource();
|
|
|
7 |
}
|
|
|
8 |
|
|
|
9 |
function getRessource(){
|
|
|
10 |
|
|
|
11 |
$parametres = $this->recupererParametresBruts();
|
|
|
12 |
$num_nom = $parametres['masque.nn'];
|
|
|
13 |
|
|
|
14 |
$retour = isset($parametres['retour']) ? $parametres['retour'] : 'image/jpeg';
|
|
|
15 |
$format = isset($parametres['retour.format']) ? $parametres['retour.format'] : 'M';
|
|
|
16 |
$dimensions = $this->config['cel_db']['format_'.$format];
|
|
|
17 |
|
|
|
18 |
$generateur_image = new ImageRecreation($this->config);
|
|
|
19 |
|
|
|
20 |
$id_image = $this->obtenirImageAuHasardPourNN($num_nom);
|
|
|
21 |
$infos_image = $generateur_image->obtenirImageEtInfosPourId($id_image);
|
|
|
22 |
|
|
|
23 |
if(!$infos_image) {
|
|
|
24 |
header('HTTP/1.0 404 Not Found');
|
|
|
25 |
exit;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
$image_generee = $generateur_image->creerMiniatureImageSelonFormat($infos_image, $format);
|
|
|
29 |
|
|
|
30 |
header('Content-type: '.$retour);
|
|
|
31 |
imagejpeg($image_generee);
|
|
|
32 |
exit;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
private function obtenirImageAuHasardPourNN($numero_nomenclatural) {
|
|
|
36 |
// Construction de la requête
|
|
|
37 |
$requete = 'SELECT cim.ci_id_image as id_image '.
|
|
|
38 |
'FROM cel_obs_images AS coi '.
|
|
|
39 |
'LEFT JOIN cel_inventory AS ci '.
|
|
|
40 |
'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
|
|
|
41 |
'LEFT JOIN cel_images AS cim '.
|
|
|
42 |
'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.
|
|
|
43 |
'WHERE ci.transmission = 1 '.
|
|
|
44 |
' AND num_nom_sel = '.$this->proteger($numero_nomenclatural).
|
|
|
45 |
' AND ci.identifiant = cim.ci_ce_utilisateur ';
|
|
|
46 |
|
|
|
47 |
$resultat_images = $this->executerRequete($requete);
|
|
|
48 |
//TODO que faire si pas de résultat ?
|
|
|
49 |
$id_image_hasard = $resultat_images[array_rand($resultat_images)]['id_image'];
|
|
|
50 |
return $id_image_hasard;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
private function nettoyerParametres(Array $parametres) {
|
|
|
54 |
// Pas besoin d'utiliser urldecode car déjà fait par php pour les clés et valeur de $_GET
|
|
|
55 |
if (isset($parametres) && count($parametres) > 0) {
|
|
|
56 |
foreach ($parametres as $cle => $valeur) {
|
|
|
57 |
$verifier = array('NULL', "\n", "\r", "\\", "'", '"', "\x00", "\x1a", ';');
|
|
|
58 |
$parametres[$cle] = strip_tags(str_replace($verifier, '', $valeur));
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
return $parametres;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
private function recupererParametresBruts() {
|
|
|
65 |
$parametres_bruts = array();
|
|
|
66 |
if (!empty($_SERVER['QUERY_STRING'])) {
|
|
|
67 |
$paires = explode('&', $_SERVER['QUERY_STRING']);
|
|
|
68 |
foreach ($paires as $paire) {
|
|
|
69 |
$nv = explode('=', $paire);
|
|
|
70 |
$nom = urldecode($nv[0]);
|
|
|
71 |
$valeur = urldecode($nv[1]);
|
|
|
72 |
$parametres_bruts[$nom] = $valeur;
|
|
|
73 |
}
|
|
|
74 |
$parametres_bruts = $this->nettoyerParametres($parametres_bruts);
|
|
|
75 |
}
|
|
|
76 |
return $parametres_bruts;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
?>
|