-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.php
88 lines (73 loc) · 2.55 KB
/
export.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
84
85
86
87
88
<?php
require_once('Logic/session_cleaner.php');
require_once('Models/Util.php');
if(empty($_SESSION['contacts']) && empty($_SESSION['solved_duplicates'])) {
echo json_encode(['status' => 400, 'message' => 'No contacts to export']);
exit();
}
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename=" . "solved_duplicates_" . date("Y-m-d") . ".csv");
header("Content-Transfer-Encoding: binary");
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
$duplicate_guids = [];
$solved_duplicates = json_decode(json_encode($_SESSION['solved_duplicates']), true);
$contacts = \qos\Models\Util::getFilteredContacts(true, true, false, false);
foreach ($solved_duplicates as $d) {
$duplicate_guids[] = $d['Guid'];
}
$payload = [];
foreach ($contacts as $contact) {
if(in_array($contact->Guid, $duplicate_guids)) {
continue;
}
$contact->Email = [$contact->Email];
$contact->Phone = [$contact->Phone];
$contact->PhotoUrl = [$contact->PhotoUrl];
$contact->Birthday = [$contact->Birthday];
$contact->Company = [$contact->Company];
$contact->City = [$contact->City];
$contact->Occupation = [$contact->Occupation];
$contact->Source = [$contact->Source];
$contact->StreetAddress = [$contact->StreetAddress];
$payload[] = json_decode(json_encode($contact), true);
}
$contacts_list = array_merge($payload, $solved_duplicates);
fputcsv($output, [
'Guid',
'Name',
'Email',
'Phone',
'PhotoUrl',
'Birthday',
'Company',
'City',
'Occupation',
'Source',
'StreetAddress'
], ';');
foreach ($contacts_list as $contact) {
fputcsv($output, [
$contact['Guid'],
$contact['GivenName']. ' ' . $contact['Surname'],
implode($contact['Email'], '|'),
implode($contact['Phone'], '|'),
implode($contact['PhotoUrl'], '|'),
implode($contact['Birthday'], '|'),
implode($contact['Company'], '|'),
implode($contact['City'], '|'),
implode($contact['Occupation'], '|'),
implode($contact['Source'], '|'),
implode($contact['StreetAddress'], '|')
], ';');
}
// output the column headings
die();