Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 416 Rev 861
1
<?php
1
<?php
-
 
2
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
-
 
3
 
2
/**
4
/**
3
* PHP Version 5
5
* PHP Version 5
4
*
6
*
5
* @category  PHP
7
* @category  PHP
6
* @package   papyrus_bp
8
* @package   papyrus_bp
7
* @author    aurelien <aurelien@tela-botanica.org>
9
* @author    aurelien <aurelien@tela-botanica.org>
8
* @copyright 2010 Tela-Botanica
10
* @copyright 2010 Tela-Botanica
9
* @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
10
* @version   SVN: <svn_id>
12
* @version   SVN: <svn_id>
11
* @link      /doc/papyrus_bp/
13
* @link      /doc/papyrus_bp/
12
*/
14
*/
13
 
-
 
14
Class Resume extends DBAccessor {
15
 
15
 
16
/**
16
	function Resume($config) {
17
 * Classe renvoyant un petit bout de html contenant les dernières obs publiques d'un utilisateur
17
 
-
 
18
        $this->config=$config;
18
 * 
-
 
19
 */
19
    }
20
class Resume extends Cel {
20
 
21
 
21
	function getElement($uid){
22
	function getElement($uid){
22
 
-
 
23
		$DB=$this->connectDB($this->config,'cel_db');
-
 
24
 
23
 
25
        $query = 'SELECT * FROM cel_inventory'.
24
        $requete_dernieres_obs = 'SELECT * FROM cel_obs'.
26
        		' WHERE identifiant = "'.$uid[1].'"'.
-
 
27
        		/*' AND ordre IN (SELECT coi_ce_observation
-
 
28
								FROM cel_obs_images
-
 
29
								WHERE coi_ce_utilisateur ="'.$uid[1].'" )'.*/
25
        		' WHERE ce_utilisateur = '.$uid[1].
30
				' AND transmission =  1'.
26
				' AND transmission =  0'.
-
 
27
				' ORDER BY date_modification DESC LIMIT 0,5';
-
 
28
 
-
 
29
        $resultat_dernieres_obs = $this->requeter($requete_dernieres_obs);
31
				' ORDER BY date_modification DESC LIMIT 0,5';
30
        
32
 
31
        $dernieres_obs = array();
33
        $res =& $DB->query($query);
32
        $resume = array();
34
 
33
 
35
        if (DB::isError($res)) {
-
 
36
            die($res->getMessage());
-
 
37
        }
34
        if (is_array($resultat_dernieres_obs)) {
38
 
35
            $dernieres_obs = $resultat_dernieres_obs;
39
        $resume = array();
36
        }
40
 
37
 
41
        $resume['titre'] = 'Vos dernières observations publiées';
38
        $resume['titre'] = 'Vos dernières observations publiées';
42
        $resume['lien_appli'] = '<a href="www.tela-botanica.org/appli:cel2"> Accéder au carnet en ligne </a>';
39
        $resume['lien_appli'] = '<a href="www.tela-botanica.org/appli:cel2"> Accéder au carnet en ligne </a>';
43
 
40
 
44
        if(!$res || $res->numRows() == 0) {
41
        if (count($dernieres_obs) == 0) {
45
        	$resume['message'] = 'Aucune observation saisie pour le moment';
42
        	$resume['message'] = 'Aucune observation saisie pour le moment';
46
        }
43
        }
47
 
44
 
48
		while ($obs =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
-
 
49
 
-
 
50
           $chemin_sur_serveur = $this->config['cel_db']['url_images'];
-
 
51
 
-
 
52
           $req_liaison = 'SELECT * FROM cel_images WHERE ci_id_image IN (SELECT coi_ce_image FROM cel_obs_images WHERE coi_ce_observation = "'.$obs['ordre'].'") AND ci_ce_utilisateur = "'.$obs['identifiant'].'"' ;
45
		foreach ($dernieres_obs as $obs) {
53
	   
-
 
54
           $res_liaison =& $DB->query($req_liaison);
-
 
55
 
-
 
56
           if (DB::isError($res_liaison)) {
-
 
57
                die($res_liaison->getMessage());
-
 
58
            }
46
 
59
	    
47
           	$chemin_sur_serveur = $this->config['cel_db']['url_images'];
60
 
48
 
61
		    $date = 'Datée du '.$obs['date_modification'].'<br/>'  ;
49
		   	$date = 'Datée du '.$obs['date_modification'].'<br/>'  ;
62
		    $lieu = 'Lieu : '.trim($obs['location'],'000null').' ('.trim($obs['id_location'],'000null').') '.trim($obs['station'],'000null').' '.trim($obs['lieudit'],'000null').'<br/>'  ;
50
		  	$lieu = 'Lieu : '.trim($obs['location'],'000null').' ('.trim($obs['id_location'],'000null').') '.trim($obs['station'],'000null').' '.trim($obs['lieudit'],'000null').'<br/>'  ;
63
 
51
 
64
			$image ='';
52
			$image ='';
65
			$cible_lien = '';
53
			$cible_lien = '';
66
		
-
 
67
			    		
54
		    		
-
 
55
			$req_liaison = 'SELECT * FROM cel_images WHERE id_image IN (SELECT id_image FROM cel_obs_images WHERE id_observation = "'.$obs['id_observation'].'") AND ce_utilisateur = "'.$obs['ce_utilisateur'].'"' ;
68
			$row = null;
56
           	$res_liaison = $this->requeter($req_liaison);
-
 
57
 
-
 
58
			$ligne_image = null;
69
 
59
			
70
			while ($img =& $res_liaison->fetchrow(DB_FETCHMODE_ASSOC)) {
60
			foreach ($res_liaison as $img) {
71
				$row = $img;
61
				$row = $img;
72
			}
62
			}
73
 
63
 
74
			if($row != null) {
64
			if($row != null) {
75
			
65
			
76
				$row['ci_nom_original'] = htmlspecialchars($row['ci_nom_original']);
66
				$row['nom_original'] = htmlspecialchars($row['nom_original']);
77
				   $row['ci_id_image'] = htmlspecialchars($row['ci_id_image']);
67
				$row['id_image'] = htmlspecialchars($row['id_image']);
78
				   $id = $row['ci_id_image'];
68
				$id = $row['id_image'];
79
	
69
	
80
				   $tailleXY = $this->calculerDimensions(array($row['ci_meta_width'], $row['ci_meta_height']));
70
				$tailleXY = $this->calculerDimensions(array($row['largeur'], $row['hauteur']));
81
	
71
	
82
				    $id = sprintf('%09s', $id) ;
72
				$id = sprintf('%09s', $id) ;
83
				    $id = wordwrap($id, 3 , '_', true) ;
73
				$id = wordwrap($id, 3 , '_', true) ;
84
	
74
	
85
				    $id_fichier = $id.".jpg" ;
75
				$id_fichier = $id.".jpg" ;
86
	
76
	
87
				    $niveauDossier = split("_", $id) ;
77
				$niveauDossier = split("_", $id) ;
88
	
78
	
89
				    $dossierNiveau1 = $niveauDossier[0] ;
79
				$dossierNiveau1 = $niveauDossier[0] ;
90
				    $dossierNiveau2 = $niveauDossier[1] ;
80
				$dossierNiveau2 = $niveauDossier[1] ;
91
	
81
	
92
				    $chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
82
				$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
93
	
83
	
94
				    $chemin_fichier = $chemin_sur_serveur_final.'/L/'.$id."_L.jpg" ;
84
				$chemin_fichier = $chemin_sur_serveur_final.'/L/'.$id."_L.jpg" ;
95
				    $chemin_fichier_s = $chemin_sur_serveur_final.'/M/'.$id."_M.jpg" ;
85
				$chemin_fichier_s = $chemin_sur_serveur_final.'/M/'.$id."_M.jpg" ;
96
			
86
			
97
				$image = '<img src="'.$chemin_fichier_s.'" alt="'.$row['ci_nom_original'].'" height="'.$tailleXY[1].'px" width="'.$tailleXY[0].'px"></img>';
87
				$image = '<img src="'.$chemin_fichier_s.'" alt="'.$row['nom_original'].'" height="'.$tailleXY[1].'px" width="'.$tailleXY[0].'px"></img>';
98
				$cible_lien = $chemin_fichier;
88
				$cible_lien = $chemin_fichier;
99
			}
89
			}
100
	
90
	
101
			$resume_item = array('element' => $obs['nom_ret'].$date.$lieu, 'lien' => $cible_lien,'image' => $image);
91
			$resume_item = array('element' => $obs['nom_ret'].$date.$lieu, 'lien' => $cible_lien,'image' => $image);
102
			$resume['elements'][] = $resume_item;
92
			$resume['elements'][] = $resume_item;
103
        }
93
        }
104
 
94
 
105
		header("Content-Type: text/html; charset=UTF-8");
95
		header("Content-Type: text/html; charset=UTF-8");
106
        print json_encode($resume);
96
        print json_encode($resume);
107
        exit;
97
        exit;
108
    }
98
    }
109
 
99
 
110
    public function calculerDimensions($tailleXY) {
100
    public function calculerDimensions($tailleXY) {
111
 
101
 
112
        $tailleOr = 75 ;
102
        $tailleOr = 75 ;
113
 
103
 
114
        if($tailleXY[1] == 0) {
104
        if($tailleXY[1] == 0) {
115
            $tailleXY[1] = $tailleOr;
105
            $tailleXY[1] = $tailleOr;
116
        }
106
        }
117
 
107
 
118
        if($tailleXY[0] == 0) {
108
        if($tailleXY[0] == 0) {
119
            $tailleXY[0] = $tailleOr;
109
            $tailleXY[0] = $tailleOr;
120
        }
110
        }
121
 
111
 
122
        $maxTaille = max($tailleXY[1],$tailleXY[0]) ;
112
        $maxTaille = max($tailleXY[1],$tailleXY[0]) ;
123
 
113
 
124
        if($maxTaille == $tailleXY[1]) {
114
        if($maxTaille == $tailleXY[1]) {
125
 
115
 
126
            $rapport = $tailleXY[1]/$tailleXY[0] ;
116
            $rapport = $tailleXY[1]/$tailleXY[0] ;
127
            $tailleXY[1] = 75 ;
117
            $tailleXY[1] = 75 ;
128
            $tailleXY[0] = round($tailleXY[1]/$rapport,0) ;
118
            $tailleXY[0] = round($tailleXY[1]/$rapport,0) ;
129
 
119
 
130
        }else {
120
        }else {
131
            $rapport = $tailleXY[0]/$tailleXY[1] ;
121
            $rapport = $tailleXY[0]/$tailleXY[1] ;
132
            $tailleXY[0] = 75 ;
122
            $tailleXY[0] = 75 ;
133
            $tailleXY[1] = round($tailleXY[0]/$rapport,0) ;
123
            $tailleXY[1] = round($tailleXY[0]/$rapport,0) ;
134
        }
124
        }
135
 
125
 
136
        return $tailleXY ;
126
        return $tailleXY ;
137
    }
127
    }
138
 
128
 
139
}
129
}
140
?>
130
?>