24 |
*/ |
*/ |
25 |
require ("../../master.inc.php"); |
require ("../../master.inc.php"); |
26 |
|
|
27 |
|
$nbdays = 1; |
28 |
|
|
29 |
|
for ($i = 1 ; $i < sizeof($argv) ; $i++) |
30 |
|
{ |
31 |
|
if ($argv[$i] == "-n") |
32 |
|
{ |
33 |
|
$nbdays = $argv[$i+1]; |
34 |
|
} |
35 |
|
if ($argv[$i] == "-v") |
36 |
|
{ |
37 |
|
$verbose = 1; |
38 |
|
} |
39 |
|
} |
40 |
|
|
41 |
|
if (! is_numeric($nbdays)) |
42 |
|
{ |
43 |
|
die("Bad argument $nbdays\n"); |
44 |
|
} |
45 |
|
|
46 |
$ftp_server = GETCDR_FTP_SERVER; |
$ftp_server = GETCDR_FTP_SERVER; |
47 |
$ftp_user_name = GETCDR_FTP_USER; |
$ftp_user_name = GETCDR_FTP_USER; |
48 |
$ftp_user_pass = GETCDR_FTP_PASS; |
$ftp_user_pass = GETCDR_FTP_PASS; |
69 |
exit; |
exit; |
70 |
} |
} |
71 |
|
|
72 |
$date = time() - (24 * 3600); |
if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/temp/')) |
73 |
|
{ |
74 |
|
create_dir(DOL_DATA_ROOT.'/telephonie/CDR/temp/'); |
75 |
|
} |
76 |
|
|
77 |
|
$date = time() - (24 * 3600 * $nbdays); |
78 |
|
|
79 |
$file = "daily_report_".strftime("%Y%m%d", $date).".zip"; |
$file = "daily_report_".strftime("%Y%m%d", $date).".zip"; |
80 |
|
|
81 |
$remote_file = 'cdr/'.$file; |
$remote_file = 'cdr/'.$file; |
82 |
$local_file = DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.$file; |
$local_file = DOL_DATA_ROOT.'/telephonie/CDR/temp/'.$file; |
83 |
$handle = fopen($local_file, 'w'); |
$handle = fopen($local_file, 'w'); |
84 |
|
|
85 |
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) |
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) |
86 |
{ |
{ |
87 |
//echo "Le chargement a réussi dans ".$local_file."\n"; |
if ($verbose) |
88 |
|
echo "Le chargement a réussi dans ".$local_file."\n"; |
89 |
} |
} |
90 |
else |
else |
91 |
{ |
{ |
94 |
|
|
95 |
// Fermeture du flux FTP |
// Fermeture du flux FTP |
96 |
ftp_close($conn_id); |
ftp_close($conn_id); |
97 |
|
|
98 |
|
// Dezippage du fichier |
99 |
|
|
100 |
|
$zip = zip_open($local_file); |
101 |
|
|
102 |
|
if ($zip) { |
103 |
|
|
104 |
|
while ($zip_entry = zip_read($zip)) |
105 |
|
{ |
106 |
|
if ($verbose) |
107 |
|
{ |
108 |
|
echo "Nom du fichier : " . zip_entry_name($zip_entry) . "\n"; |
109 |
|
echo "Taille réelle : " . zip_entry_filesize($zip_entry) . "\n"; |
110 |
|
echo "Taille compressée : " . zip_entry_compressedsize($zip_entry) . "\n"; |
111 |
|
echo "Méthode : " . zip_entry_compressionmethod($zip_entry) . "\n"; |
112 |
|
} |
113 |
|
|
114 |
|
if (zip_entry_open($zip, $zip_entry, "r")) |
115 |
|
{ |
116 |
|
if ($verbose) |
117 |
|
echo "Decompression dans ".DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry)."\n"; |
118 |
|
|
119 |
|
$fp = fopen(DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry),"w"); |
120 |
|
|
121 |
|
if ($fp) |
122 |
|
{ |
123 |
|
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); |
124 |
|
|
125 |
|
if (fwrite($fp, $buf) === FALSE) |
126 |
|
{ |
127 |
|
echo "Erreur d'ecriture\n"; |
128 |
|
} |
129 |
|
fclose($fp); |
130 |
|
} |
131 |
|
zip_entry_close($zip_entry); |
132 |
|
} |
133 |
|
} |
134 |
|
zip_close($zip); |
135 |
|
} |
136 |
|
|
137 |
|
// Archivage du fichier |
138 |
|
|
139 |
|
if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/archive/')) |
140 |
|
{ |
141 |
|
create_dir(DOL_DATA_ROOT.'/telephonie/CDR/archive/'); |
142 |
|
} |
143 |
|
|
144 |
|
$dir = DOL_DATA_ROOT.'/telephonie/CDR/archive/'.strftime("%Y", $date); |
145 |
|
if (!file_exists($dir)) |
146 |
|
create_dir($dir); |
147 |
|
|
148 |
|
$dir = DOL_DATA_ROOT.'/telephonie/CDR/archive/'.strftime("%Y", $date).'/'.strftime("%m", $date); |
149 |
|
if (!file_exists($dir)) |
150 |
|
create_dir($dir); |
151 |
|
|
152 |
|
function create_dir($dir) |
153 |
|
{ |
154 |
|
if (! file_exists($dir)) |
155 |
|
{ |
156 |
|
umask(0); |
157 |
|
if (! @mkdir($dir, 0755)) |
158 |
|
{ |
159 |
|
die ("Erreur: Le répertoire ".$dir." n'existe pas et Dolibarr n'a pu le créer."); |
160 |
|
} |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
?> |
?> |