-
Notifications
You must be signed in to change notification settings - Fork 51
/
downlist.php
83 lines (61 loc) · 1.9 KB
/
downlist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* SPDX-License-Identifier: GPL-3.0-or-later
* This file is part of Dolibarr module Abricot
*/
$s_name = $_POST['session_name'] or die('Pas de session trouvée');
session_name($s_name);
session_start();
if(empty($_SESSION['token_list_'.$_POST['token']])) die('token de session liste invalide');
$TData = unserialize( gzinflate( $_SESSION['token_list_'.$_POST['token']]) );
$mode = $_POST['mode'];
$title = $TData['title'];
$sql = $TData['sql'];
$TBind = $TData['TBind'];
$TEntete = $TData['TEntete'];
$TChamps = $TData['TChamps'];
$utf8_with_bom = chr(239) . chr(187) . chr(191);
if(empty($title)) $title = 'report';
if($mode == 'CSV') {
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='. $title.'.csv');
header('Pragma: no-cache');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$r='';
foreach($TEntete as &$entete) {
$r.='"'.addslashes($entete['libelle']).'";';
}
$r.=PHP_EOL;
foreach($TChamps as $row) {
foreach($row as $v) {
$r.='"'.addslashes(strip_tags( (string) $v )).'";';
}
$r.=PHP_EOL;
}
if( mb_detect_encoding($r, 'UTF-8', true) ) $r = $utf8_with_bom.$r;
echo $r;
exit();
}
else if($mode == 'TXT') {
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='. $title.'.txt');
header('Pragma: no-cache');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$r='';
foreach($TEntete as &$entete) {
$r.='"'.addslashes($entete['libelle']).'"'."\t";
}
$r.=PHP_EOL;
foreach($TChamps as $row) {
foreach($row as $v) {
$r.='"'.addslashes(strip_tags((string) $v)).'"'."\t";
}
$r.=PHP_EOL;
}
echo $r;
exit();
}
else if ($mode == 'PDF') {
}