Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1802 Rev 1803
Line 147... Line 147...
147
	$result = curl_exec($ch);
147
	$result = curl_exec($ch);
148
	curl_close($ch);
148
	curl_close($ch);
149
	$sess = $id = array();
149
	$sess = $id = array();
150
	preg_match('/.*PHPSESSID=(\w+)/', $result, $sess);
150
	preg_match('/.*PHPSESSID=(\w+)/', $result, $sess);
151
	preg_match('/"id_utilisateur":"(\d+)"/', $result, $id);
151
	preg_match('/"id_utilisateur":"(\d+)"/', $result, $id);
-
 
152
 
152
	if(DEBUG) fwrite(STDERR, "curl \"".$URL ."\" : {$sess[1]} / {$id[1]}\n");
153
	if(DEBUG) @fwrite(STDERR, "curl \"".$URL ."\" : {$sess[1]} / {$id[1]}\n");
153
	if(isset($sess[1])) {
154
	if(isset($sess[1])) {
154
		define('COOKIE', $sess[1]);
155
		define('COOKIE', $sess[1]);
155
		if(!defined('USER')) {
156
		if(!defined('USER')) {
156
			if(!isset($id[1])) return FALSE;
157
			if(!isset($id[1])) return FALSE;
157
			define('USER', $id[1]);
158
			define('USER', $id[1]);
Line 200... Line 201...
200
	$result = curl_exec($ch);
201
	$result = curl_exec($ch);
201
	curl_close($ch);
202
	curl_close($ch);
202
	return $result;
203
	return $result;
203
}
204
}
Line -... Line 205...
-
 
205
 
-
 
206
function importXLS($d) {
-
 
207
	$URL = DOMAIN . '/jrest/ImportXLS';
-
 
208
	if(!is_file($d)) return FALSE;
-
 
209
	exec("csvtool -o /tmp/a.csv col 1- $d");
-
 
210
	exec(__DIR__ . "/bin/csv2xls -v 0 -f -o /tmp/a /tmp/a.csv &>/dev/null");
-
 
211
	if(DEBUG) fwrite(STDERR,
-
 
212
					 "csvtool -o /tmp/a.csv col 1- $d;\n" . 
-
 
213
					 __DIR__ . "/bin/csv2xls -v 0 -f -o /tmp/a /tmp/a.csv\n");
-
 
214
	$d = "/tmp/a.xls";
-
 
215
	if(!is_file($d)) { die('error: ' . __FILE__ . ':' . __LINE__); }
-
 
216
 
-
 
217
	$ch = curl_init();
-
 
218
 
-
 
219
	// curl does not support setting filename="X.csv";type=application/octet-stream'
-
 
220
	// with plain POST variables
-
 
221
 
-
 
222
	curl_setopt($ch,CURLOPT_URL, $URL);
-
 
223
	curl_setopt($ch,CURLOPT_POSTFIELDS, array(
-
 
224
		'upload' => '@' . $d . ';filename=test.xls',
-
 
225
		'utilisateur' => USER
-
 
226
	));
-
 
227
 
-
 
228
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
-
 
229
 
-
 
230
	if(DEBUG) fwrite(STDERR, "curl -F \"upload=@$d;filename=test.xls\" -F utilisateur=" . USER . " \"$URL\"\n");
-
 
231
 
-
 
232
	//execute post
-
 
233
	$result = curl_exec($ch);
-
 
234
	curl_close($ch);
-
 
235
	return $result;
-
 
236
}
204
 
237
 
205
function export($cols = "standard,avance") {
238
function export($cols = "standard,avance") {
Line 206... Line 239...
206
	if(!defined('COOKIE')) return FALSE;
239
	if(!defined('COOKIE')) return FALSE;
207
 
240
 
Line 212... Line 245...
212
	$ch = curl_init();
245
	$ch = curl_init();
Line 213... Line 246...
213
 
246
 
214
	curl_setopt($ch,CURLOPT_URL, $URL);
247
	curl_setopt($ch,CURLOPT_URL, $URL);
Line 215... Line -...
215
	curl_setopt($ch,CURLOPT_COOKIE, 'PHPSESSID=' . COOKIE);
-
 
216
 
-
 
217
	if(DEBUG) fwrite(STDERR, "curl -b PHPSESSID=" . COOKIE . ' "' . $URL ."\"\n");
248
	curl_setopt($ch,CURLOPT_COOKIE, 'PHPSESSID=' . COOKIE);
-
 
249
 
-
 
250
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
218
 
251
 
219
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
252
	if(DEBUG) fwrite(STDERR, "curl -b PHPSESSID=" . COOKIE . ' "' . $URL ."\"\n");
220
	//execute post
253
	//execute post
221
	$result = curl_exec($ch);
254
	$result = curl_exec($ch);
222
	curl_close($ch);
255
	curl_close($ch);
Line -... Line 256...
-
 
256
	return $result;
-
 
257
}
-
 
258
 
-
 
259
function exportXLS($cols = "standard,avance") {
-
 
260
	if(!defined('COOKIE')) return FALSE;
-
 
261
 
-
 
262
	$file = "/tmp/b.xls";
-
 
263
 
-
 
264
	$URL = DOMAIN . '/jrest/CelWidgetExport/export?';
-
 
265
	$URL .= http_build_query(array('colonnes' => $cols,
-
 
266
								   'id_utilisateur' => USER,
-
 
267
								   'format' => 'xls'));
-
 
268
	$ch = curl_init();
-
 
269
 
-
 
270
	curl_setopt($ch,CURLOPT_URL, $URL);
-
 
271
	curl_setopt($ch,CURLOPT_COOKIE, 'PHPSESSID=' . COOKIE);
-
 
272
 
-
 
273
	$fh = fopen($file, 'w'); 
-
 
274
	curl_setopt($ch,CURLOPT_FILE, $fh);
-
 
275
 
-
 
276
	if(DEBUG) fwrite(STDERR, "curl -o $file -b PHPSESSID=" . COOKIE . ' "' . $URL ."\"\n");
-
 
277
	//execute post
-
 
278
	curl_exec($ch);
-
 
279
 
-
 
280
	fflush($fh); 
-
 
281
	fclose($fh);
-
 
282
	curl_close($ch);
-
 
283
 
-
 
284
	// if(DEBUG) fwrite(STDERR, "xls2csv $file\n");
-
 
285
	// exec("xls2csv $file", $result, $ret);
-
 
286
	// return implode("\n", $result);
-
 
287
	if(DEBUG) fwrite(STDERR, __DIR__ . "/bin/xls2csv-separate-sheets.pl -i $file\n");
-
 
288
	exec(__DIR__ . "/bin/xls2csv-separate-sheets.pl -i $file &>/dev/null", $result, $ret);
-
 
289
	$newfile = substr($file, 0, -4) . '-Liste' . '.csv';
-
 
290
 
-
 
291
	// because xls2csv-separate-sheets.pl does latin9
-
 
292
	if(DEBUG) fwrite(STDERR, "iconv -f latin9 -t utf8 $newfile >| /tmp/.x; mv -f /tmp/.x $newfile\n");
-
 
293
	exec("iconv -f latin9 -t utf8 -o /tmp/.x $newfile; mv -f /tmp/.x $newfile");
-
 
294
	if($ret) die('error: ' . __FILE__ . ':' . __LINE__);
-
 
295
 
223
	return $result;
296
	return file_get_contents($newfile);
224
}
297
}
Line 225... Line 298...
225
 
298
 
226
function getCSV_line($csv, $line) {
299
function getCSV_line($csv, $line) {
Line 233... Line 306...
233
	$head = champsLongToShort(fgetcsv($out));
306
	$head = champsLongToShort(fgetcsv($out));
234
	while ($line--) fgetcsv($out);
307
	while ($line--) fgetcsv($out);
235
	$l = fgetcsv($out);
308
	$l = fgetcsv($out);
236
	fclose($out);
309
	fclose($out);
237
	if(!$l) return FALSE;
310
	if(!$l) return FALSE;
-
 
311
	// xls2csv-separate-sheets.pl supprime les trailing champs vides
-
 
312
	if(count($l) != count($head)) {
-
 
313
		$l += array_fill(count($l), count($head) - count($l), "");
-
 
314
	}
238
	return array_combine($head, $l);
315
	return array_combine($head, $l);
239
}
316
}
Line 240... Line 317...
240
 
317