Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
2
 
3
 
4
// In :  utf8
5
// Out : utf8
6
 
7
Class InventoryItemList extends DBAccessor {
8
 
9
 
10
	var $config;
11
 
12
	function InventoryItemList($config) {
13
 
14
		$this->config=$config;
15
	}
16
 
17
 
18
	function getElement($uid){
19
 
20
		 // Controle detournement utilisateur
21
		    session_start();
22
		 	$this->controleUtilisateur($uid[0]);
23
 
24
			// uid[0] : utilisateur obligatoire
25
			// uid[1] : si absent : valeur 'all' (departement)
26
			// uid[2] : si absent : valeur 'all' (commune)
27
			// uid[3] : si absent : valeur 'all' (annee)
28
			// uid[4] : si absent : valeur 'all' (mois)
29
			// uid[5] : si absent : valeur 'all' (jour)
30
			// uid[6] : si absent : valeur 'all' (recherche libre)
31
			// uid[7] : si absent : valeur 'all' (lieudit)
32
			// uid[8] et uid[9] : selection intervalle
33
 
34
			$DB=$this->connectDB($this->config,'database_cel');
35
 
36
 
37
			if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
38
				$uid[1]="all";
39
				$query_id_location="";
40
			}
41
			else {
42
				$query_id_location=" AND id_location='".$DB->escapeSimple($uid[1])."' ";
43
			}
44
 
45
 
46
			if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all" ) {
47
				$uid[2]="all";
48
				$query_location="";
49
			}
50
			else {
51
				$query_location=" AND location='".$DB->escapeSimple($uid[2])."' ";
52
			}
53
 
54
			if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
55
				$uid[3]="all";
56
				$query_year="";
57
			}
58
			else {
59
				$query_year=" AND year(date_observation)='".$DB->escapeSimple($uid[3])."' ";
60
			}
61
 
62
 
63
			if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
64
				$uid[4]="all";
65
				$query_month="";
66
			}
67
			else {
68
				$query_month=" AND month(date_observation)='".$DB->escapeSimple($uid[4])."' ";
69
			}
70
 
71
			if (!isset($uid[5]) || $uid[5]=="" || $uid[5]=="all") {
72
				$uid[5]="all";
73
				$query_day="";
74
			}
75
			else {
76
				$query_day=" AND day(date_observation)='".$DB->escapeSimple($uid[5])."' ";
77
			}
78
 
79
 
80
			if (!isset($uid[6]) || $uid[6]=="" || $uid[6]=="all") {
81
				$uid[6]="all";
82
				$query_libre="";
83
			}
84
			else {
85
				$query_libre=" AND (nom_sel like '%".$DB->escapeSimple($uid[6])."%' OR nom_ret like '%".$DB->escapeSimple($uid[6])."%' OR station like '%".$DB->escapeSimple($uid[6])."%'  OR milieu like '%".$DB->escapeSimple($uid[6])."%' OR commentaire like '%".$DB->escapeSimple($uid[6])."%') ";
86
			}
87
 
88
			if (!isset($uid[7]) || $uid[7]=="" || $uid[7]=="all") {
89
				$uid[7]="all";
90
				$query_lieudit="";
91
			}
92
			else {
93
				$query_lieudit=" AND lieudit='".$DB->escapeSimple($uid[7])."' ";
94
			}
95
 
96
 
97
			$value=array();
98
 
99
 
100
			if (isset($uid[8]) && isset($uid[9])) {
101
	           	$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, date_observation," .
102
	           			" lieudit, station, milieu, commentaire, transmission  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
103
	           			$query_id_location.
104
	           			$query_location.
105
	           			$query_year.
106
	           			$query_month.
107
	           			$query_day.
108
	           			$query_libre.
109
	           			$query_lieudit.
110
	           			" ORDER BY ordre LIMIT ".$uid[8].",".$uid[9];
111
			}
112
 
113
			else {
114
				if (isset($uid[8])) {
115
						// les n derniers
116
			          	$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, date_observation," .
117
			          	" lieudit, station, milieu, commentaire, transmission  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
118
	           			$query_id_location.
119
	           			$query_location.
120
	           		    $query_year.
121
	           			$query_month.
122
	           			$query_day.
123
	           			$query_libre.
124
	           			$query_lieudit.
125
			          	" ORDER BY ordre LIMIT ".$uid[8].",18446744073709551615";
126
				}
127
				else {
128
			           	$query="SELECT count(*) as count FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."'" .
129
	           			$query_id_location.
130
						$query_location.
131
	           			$query_year.
132
	           			$query_month.
133
	           			$query_day.
134
	           			$query_libre.
135
	           			$query_lieudit;
136
 
137
           			    $res =& $DB->query($query);
138
 
139
 
140
				        if (DB::isError($res)) {
141
			    	        die($res->getMessage());
142
			        	}
143
				        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
144
			                $value=$row['count'];
145
			    	    }
146
 
423 aurelien 147
						$output = json_encode((integer)$value);
416 aurelien 148
						print($output);
149
 
150
						return true;
151
 
152
				}
153
			}
154
 
155
 
156
		    $res =& $DB->query($query);
157
 
158
	        if (DB::isError($res)) {
159
    	        die($res->getMessage());
160
        	}
161
	        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
162
	        	if ($row['date_observation']!="0000-00-00 00:00:00") {
163
	                list($year,$month,$day)= split ('-',$row['date_observation']);
164
    	            list($day)= split (' ',$day);
165
	                $row['date_observation']=$day."/".$month."/".$year;
166
	        	}
167
                $value[]=array($row['nom_sel'], $row['num_nom_sel'],$row['nom_ret'],$row['num_nom_ret'],$row['num_taxon'],$row['famille'], $row['location'], $row['ordre'], $row['date_observation'], $row['lieudit'], $row['station'], $row['milieu'], $row['commentaire'], $row['transmission']);
168
 
169
    	    }
170
 
423 aurelien 171
			$output = json_encode($value);
416 aurelien 172
			print($output);
173
 
174
			return true;
175
 
176
 
177
	}
178
 
179
 
180
 
181
}
182
 
183
/* +--Fin du code ---------------------------------------------------------------------------------------+
184
* $Log$
185
* Revision 1.7  2008-11-13 11:29:12  ddelon
186
* Reecriture gwt-ext
187
*
188
* Revision 1.6  2008-01-30 08:57:28  ddelon
189
* fin mise en place mygwt
190
*
191
* Revision 1.5  2007-05-22 12:54:08  ddelon
192
* Securisation acces utilisateur
193
*
194
*
195
*
196
*/
197
 
198
 
199
?>