This repository was archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexportlog.php
83 lines (68 loc) · 1.97 KB
/
exportlog.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
// Get the PHP helper library from twilio.com/docs/php/install
require __DIR__ . '/vendor/autoload.php'; // Loads the library. This may vary depending on how you installed the library.
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = $_POST['sid'];
$token = $_POST['authToken'];
$from = $_POST['from'];
$to = $_POST['to'];
$date = '';
echo $to;
echo '<br>';
echo $from;
echo '<br>';
$client = new Client($sid, $token);
/* Download data from Twilio API */
if (!empty($from) || !empty($to)){
if ($from == $to){
$date = array
(
'dateSent' => $from
);
}
if (!empty($from) && empty($to)){
$date = array
(
'dateSentAfter' => $from,
);
}
if (empty($from) && !empty($to)){
$date = array
(
'dateSentBefore' => $to,
);
}
if (!empty($from) && !empty($to) && $from != $to){
$date = array
(
'dateSentAfter' => $from,
'dateSentBefore' => $to,
);
}
}
$messages = $client->messages->stream($date);
// /* Browser magic */
$filename = $sid."_sms.csv";
header("Content-Type: application/csv");
header("Content-Disposition: attachment; filename={$filename}");
/* Write headers */
$fields = array( 'SMS Message SID', 'From', 'To', 'Date Created', 'Date Sent', 'Date Updated', 'Status', 'Direction', 'Message Segments', 'Price', 'Body' );
echo '"'.implode('","', $fields).'"'."\n";
/* Write rows */
foreach ($messages as $sms) {
$row = array(
$sms->sid,
$sms->from,
$sms->to,
$sms->dateCreated->format('Y-m-d H:i:s'),
$sms->dateSent->format('Y-m-d H:i:s'),
$sms->dateCreated->format('Y-m-d H:i:s'),
$sms->status,
$sms->direction,
$sms->numSegments,
$sms->price,
$sms->body
);
echo '"'.implode('","', $row).'"'."\n";
}