Subversion Repositories eFlore/Applications.cel

Rev

Rev 1914 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1914 Rev 1936
Line 38... Line 38...
38
	'nom_commun' => 'Nom Commun',
38
	'nom_commun' => 'Nom Commun',
Line 39... Line 39...
39
 
39
 
40
	'observateur' => 'Observateur',
40
	'observateur' => 'Observateur',
Line -... Line 41...
-
 
41
);
Line 41... Line 42...
41
);
42
 
42
 
43
define('URLPREFIX', 'service:cel:');
-
 
44
 
43
 
45
function cel_get_obs() {
44
function cel_get_obs() {
46
	$URL = DOMAIN . '/' . URLPREFIX . 'InventoryObservationList/' . USER;
Line 45... Line 47...
45
	$URL = DOMAIN . '/jrest/InventoryObservationList/' . USER;
47
	// 5000 (memory_limit)
46
	return json_decode(file_get_contents($URL . '/?limite=100000&numero_page=0'));
48
	return json_decode(file_get_contents($URL . '/?limite=5000&numero_page=0'));
47
}
49
}
48
 
50
 
Line 49... Line 51...
49
function cel_get_images() {
51
function cel_get_images() {
50
	$URL = DOMAIN . '/jrest/InventoryImageList/' . USER;
52
	$URL = DOMAIN . '/' . URLPREFIX . 'InventoryImageList/' . USER;
51
	return json_decode(file_get_contents($URL . '/?limite=100000&numero_page=0'));
53
	return json_decode(file_get_contents($URL . '/?limite=100000&numero_page=0'));
Line 52... Line 54...
52
}
54
}
53
 
55
 
54
function cel_delete_obs($obs) {
56
function cel_delete_obs($obs) {
55
	$URL = DOMAIN . '/jrest/InventoryObservationList/' . USER;
57
	$URL = DOMAIN . '/' . URLPREFIX . 'InventoryObservationList/' . USER;
-
 
58
	$ch = curl_init();
-
 
59
 
56
	$ch = curl_init();
60
	//set the url, number of POST vars, POST data
57
 
61
	curl_setopt($ch,CURLOPT_URL, $URL . '/' . implode(',', $obs));
58
	//set the url, number of POST vars, POST data
62
	curl_setopt($ch,CURLOPT_POSTFIELDS, array('action' => 'DELETE'));
59
	curl_setopt($ch,CURLOPT_URL, $URL . '/' . implode(',', $obs));
63
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
60
	curl_setopt($ch,CURLOPT_POSTFIELDS, array('action' => 'DELETE'));
64
 
Line 61... Line 65...
61
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
65
	if(DEBUG) @fwrite(STDERR, sprintf("curl -F action=DELETE '%s/%s'\n", $URL, implode(',', $obs)));
62
	//execute post
66
	//execute post
63
	$result = curl_exec($ch);
67
	$result = curl_exec($ch);
Line 64... Line 68...
64
	curl_close($ch);
68
	curl_close($ch);
65
	return $result;
69
	return $result;
66
}
70
}
Line 79... Line 83...
79
	return $result;
83
	return $result;
80
}
84
}
Line 81... Line 85...
81
 
85
 
82
 
86
 
83
function cel_delete_all_obs() {
87
function cel_delete_all_obs() {
-
 
88
    while( ($obs = cel_get_obs()) ) {
-
 
89
	$ordres = array_map(function($item) { return $item->ordre; }, $obs);
84
	$obs = cel_get_obs();
90
	// les chunks permettent d'éviter des REQUEST-URI too long (500 id * 4 digits + 500 (virgules)) < 4k
-
 
91
	while( $ordres_chunk = array_splice($ordres, 0, 500)) {
-
 
92
	    cel_delete_obs($ordres_chunk);
85
	$ordres = array_map(function($item) { return $item->ordre; }, $obs);
93
	}
Line 86... Line 94...
86
	cel_delete_obs($ordres);
94
    }
87
}
95
}
Line 93... Line 101...
93
	cel_delete_image($ids);
101
	cel_delete_image($ids);
94
}
102
}
Line 95... Line 103...
95
 
103
 
96
function cel_upload_image($file) {
104
function cel_upload_image($file) {
97
	if(! file_exists($file)) return NULL;
105
	if(! file_exists($file)) return NULL;
Line 98... Line 106...
98
	$URL = DOMAIN . '/jrest/InventoryImage';
106
	$URL = DOMAIN . '/' . URLPREFIX . 'InventoryImage';
Line 99... Line 107...
99
 
107
 
100
	$ch = curl_init();
108
	$ch = curl_init();
Line 114... Line 122...
114
	curl_close($ch);
122
	curl_close($ch);
115
	return $result;
123
	return $result;
116
}
124
}
Line 117... Line 125...
117
 
125
 
118
function cel_link_images($user, $id_image, $id_obs) {
126
function cel_link_images($user, $id_image, $id_obs) {
119
	$URL = DOMAIN . '/jrest/inventoryImageLink/';
127
	$URL = DOMAIN . '/' . URLPREFIX . 'inventoryImageLink/';
Line 120... Line 128...
120
	$ch = curl_init();
128
	$ch = curl_init();
121
 
129
 
122
	//set the url, number of POST vars, POST data
130
	//set the url, number of POST vars, POST data
Line 137... Line 145...
137
 
145
 
138
function auth() {
146
function auth() {
139
	// TODO: CURLOPT_NETRC + Cel API support
147
	// TODO: CURLOPT_NETRC + Cel API support
140
	if(!defined('EMAIL') || !defined('PASS') || ! EMAIL || ! PASS) return FALSE;
148
	if(!defined('EMAIL') || !defined('PASS') || ! EMAIL || ! PASS) return FALSE;
141
	if(defined('COOKIE') && COOKIE) return TRUE;
149
	if(defined('COOKIE') && COOKIE) return TRUE;
Line 142... Line 150...
142
	$URL = DOMAIN . '/jrest/User/' . EMAIL . '/' . PASS;
150
	$URL = DOMAIN . '/' . URLPREFIX . 'User/' . EMAIL . '/' . PASS;
Line 143... Line 151...
143
 
151
 
144
	$ch = curl_init();
152
	$ch = curl_init();
Line 182... Line 190...
182
	fclose($out);
190
	fclose($out);
183
	return $csv;
191
	return $csv;
184
}
192
}
Line 185... Line 193...
185
 
193
 
186
function import($d) {
194
function import($d) {
187
	$URL = DOMAIN . '/jrest/ImportXLS';
195
	$URL = DOMAIN . '/' . URLPREFIX . 'ImportXLS';
188
	if(!is_file($d)) return FALSE;
196
	if(!is_file($d)) return FALSE;
Line 189... Line 197...
189
	$ch = curl_init();
197
	$ch = curl_init();
190
 
198
 
Line 206... Line 214...
206
	curl_close($ch);
214
	curl_close($ch);
207
	return $result;
215
	return $result;
208
}
216
}
Line 209... Line 217...
209
 
217
 
210
function importXLS($d) {
218
function importXLS($d) {
211
	$URL = DOMAIN . '/jrest/ImportXLS';
219
	$URL = DOMAIN . '/' . URLPREFIX . 'ImportXLS';
212
	if(!is_file($d)) return FALSE;
220
	if(!is_file($d)) return FALSE;
213
	exec("csvtool -o /tmp/a.csv col 1- $d");
221
	exec("csvtool -o /tmp/a.csv col 1- $d");
214
	exec(__DIR__ . "/bin/csv2xls -v 0 -f -o /tmp/a /tmp/a.csv &>/dev/null");
222
	exec(__DIR__ . "/bin/csv2xls -v 0 -f -o /tmp/a /tmp/a.csv &>/dev/null");
215
	if(DEBUG) fwrite(STDERR,
223
	if(DEBUG) fwrite(STDERR,
Line 240... Line 248...
240
}
248
}
Line 241... Line 249...
241
 
249
 
242
function export($cols = "standard,avance") {
250
function export($cols = "standard,avance") {
Line 243... Line 251...
243
	if(!defined('COOKIE')) return FALSE;
251
	if(!defined('COOKIE')) return FALSE;
244
 
252
 
245
	$URL = DOMAIN . '/jrest/CelWidgetExport/export?';
253
	$URL = DOMAIN . '/' . URLPREFIX . 'CelWidgetExport/export?';
246
	$URL .= http_build_query(array('colonnes' => $cols,
254
	$URL .= http_build_query(array('colonnes' => $cols,
247
								   'id_utilisateur' => USER,
255
								   'id_utilisateur' => USER,
Line 263... Line 271...
263
function exportXLS($cols = "standard,avance") {
271
function exportXLS($cols = "standard,avance") {
264
	if(!defined('COOKIE')) return FALSE;
272
	if(!defined('COOKIE')) return FALSE;
Line 265... Line 273...
265
 
273
 
Line 266... Line 274...
266
	$file = "/tmp/b.xls";
274
	$file = "/tmp/b.xls";
267
 
275
 
268
	$URL = DOMAIN . '/jrest/CelWidgetExport/export?';
276
	$URL = DOMAIN . '/' . URLPREFIX . 'CelWidgetExport/export?';
269
	$URL .= http_build_query(array('colonnes' => $cols,
277
	$URL .= http_build_query(array('colonnes' => $cols,
270
								   'id_utilisateur' => USER,
278
								   'id_utilisateur' => USER,
Line 319... Line 327...
319
	return array_combine($head, $l);
327
	return array_combine($head, $l);
320
}
328
}
Line 321... Line 329...
321
 
329
 
-
 
330
 
322
 
331
function champsLongToShort($a) {
323
function champsLongToShort($a) {
332
    if(! $a) return array();
324
	$r = array();
333
	$r = array();
325
	$x = array_flip($GLOBALS['champs']);
334
	$x = array_flip($GLOBALS['champs']);
326
	foreach($a as $k => $v) {
335
	foreach($a as $k => $v) {