-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpre_notification_export.php
211 lines (187 loc) · 7.61 KB
/
pre_notification_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
***********************************************************************************************
* Modul pre_notification_export fuer das Admidio-Plugin Mitgliedsbeitrag
*
* @copyright The Admidio Team
* @see https://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
*
* Parameters: none
*
***********************************************************************************************
*/
require_once(__DIR__ . '/../../adm_program/system/common.php');
require_once(__DIR__ . '/common_function.php');
require_once(__DIR__ . '/classes/configtable.php');
// only authorized user are allowed to start this module
if (!isUserAuthorized($_SESSION['pMembershipFee']['script_name']))
{
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
}
$pPreferences = new ConfigTablePMB();
$pPreferences->read();
$user = new User($gDb, $gProfileFields);
// initialize some special mode parameters
$separator = '';
$valueQuotes = '';
$charset = '';
$csvStr = '';
$header = array(); //'xlsx'
$rows = array(); //'xlsx'
$columnValues = array();
$filename = $pPreferences->config['SEPA']['vorabinformation_dateiname'];
$exportMode = $pPreferences->config['SEPA']['vorabinformation_dateityp'];
switch ($exportMode)
{
case 'csv-ms':
$separator = ';'; // Microsoft Excel 2007 or new needs a semicolon
$valueQuotes = '"'; // all values should be set with quotes
$exportMode = 'csv';
$charset = 'iso-8859-1';
break;
case 'csv-oo':
$separator = ','; // a CSV file should have a comma
$valueQuotes = '"'; // all values should be set with quotes
$exportMode = 'csv';
$charset = 'utf-8';
break;
case 'xlsx':
include_once(__DIR__ . '/libs/PHP_XLSXWriter/xlsxwriter.class.php');
$exportMode = 'xlsx';
break;
default:
break;
}
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_SERIAL_NUMBER');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_MEMBERNUMBER');
$columnValues[] = $gL10n->get('SYS_FIRSTNAME');
$columnValues[] = $gL10n->get('SYS_LASTNAME');
$columnValues[] = $gL10n->get('SYS_STREET');
$columnValues[] = $gL10n->get('SYS_POSTCODE');
$columnValues[] = $gL10n->get('SYS_CITY');
$columnValues[] = $gL10n->get('SYS_EMAIL');
$columnValues[] = $gL10n->get('SYS_PHONE');
$columnValues[] = $gL10n->get('SYS_MOBILE');
$columnValues[] = $gL10n->get('SYS_BIRTHDAY');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_ACCESSION');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_ACCOUNT_HOLDER').'/'.$gL10n->get('PLG_MITGLIEDSBEITRAG_DEBTOR');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_STREET');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_POSTCODE');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_CITY');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_EMAIL');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_BANK');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_BIC');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_IBAN');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_MANDATEDATE');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_MANDATEID');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_DUEDATE');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_FEE');
$columnValues[] = $gL10n->get('PLG_MITGLIEDSBEITRAG_CONTRIBUTORY_TEXT');
$rows[] = $columnValues;
if ($exportMode === 'csv')
{
for ($i = 0; $i < (sizeof($columnValues)); $i++)
{
if ($i !== 0)
{
$csvStr .= $separator;
}
$csvStr .= $valueQuotes. $columnValues[$i]. $valueQuotes;
}
$csvStr .= "\n";
}
$nr = 1;
foreach ($_SESSION['pMembershipFee']['checkedArray'] as $UserId => $dummy)
{
$user->readDataById($UserId);
$columnValues = array();
$columnValues[] = $nr;
$columnValues[] = $user->getValue('MEMBERNUMBER'.$gCurrentOrgId);
$columnValues[] = $user->getValue('FIRST_NAME');
$columnValues[] = $user->getValue('LAST_NAME');
$columnValues[] = $user->getValue('STREET');
$columnValues[] = $user->getValue('POSTCODE');
$columnValues[] = $user->getValue('CITY');
$columnValues[] = $user->getValue('EMAIL');
$columnValues[] = $user->getValue('PHONE');
$columnValues[] = $user->getValue('MOBILE');
$columnValues[] = $user->getValue('BIRTHDAY');
$columnValues[] = $user->getValue('ACCESSION'.$gCurrentOrgId);
if (strlen($user->getValue('DEBTOR')) !== 0)
{
$columnValues[] = $user->getValue('DEBTOR');
$columnValues[] = $user->getValue('DEBTOR_STREET');
$columnValues[] = $user->getValue('DEBTOR_POSTCODE');
$columnValues[] = $user->getValue('DEBTOR_CITY');
$columnValues[] = $user->getValue('DEBTOR_EMAIL');
}
else
{
$columnValues[] = $user->getValue('FIRST_NAME').' '.$user->getValue('LAST_NAME');
$columnValues[] = $user->getValue('STREET');
$columnValues[] = $user->getValue('POSTCODE');
$columnValues[] = $user->getValue('CITY');
$columnValues[] = $user->getValue('EMAIL');
}
$columnValues[] = $user->getValue('BANK');
$columnValues[] = $user->getValue('BIC');
$columnValues[] = $user->getValue('IBAN');
$columnValues[] = $user->getValue('MANDATEDATE'.$gCurrentOrgId);
$columnValues[] = $user->getValue('MANDATEID'.$gCurrentOrgId);
$columnValues[] = $user->getValue('DUEDATE'.$gCurrentOrgId);
$columnValues[] = $user->getValue('FEE'.$gCurrentOrgId);
$columnValues[] = $user->getValue('CONTRIBUTORY_TEXT'.$gCurrentOrgId);
if ($exportMode === 'csv')
{
for ($i = 0; $i < (sizeof($columnValues)); $i++)
{
if ($i !== 0)
{
$csvStr .= $separator;
}
$csvStr .= $valueQuotes. $columnValues[$i]. $valueQuotes;
}
$csvStr .= "\n";
}
elseif ($exportMode === 'xlsx')
{
$rows[] = $columnValues;
}
$nr += 1;
}
$filename = FileSystemUtils::getSanitizedPathEntry($filename) . '.' . $exportMode;
header('Content-Disposition: attachment; filename="'.$filename.'"');
// neccessary for IE6 to 8, because without it the download with SSL has problems
header('Cache-Control: private');
header('Pragma: public');
if ($exportMode === 'csv')
{
// download CSV file
header('Content-Type: text/comma-separated-values; charset='.$charset);
if ($charset === 'iso-8859-1')
{
echo utf8_decode($csvStr);
}
else
{
echo $csvStr;
}
}
elseif ($exportMode === 'xlsx')
{
header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$writer = new XLSXWriter();
$writer->setAuthor($gCurrentUser->getValue('FIRST_NAME').' '.$gCurrentUser->getValue('LAST_NAME'));
$writer->setTitle($filename);
$writer->setSubject($gL10n->get('PLG_MITGLIEDSBEITRAG_MEMBERSHIP_FEE'));
$writer->setCompany($gCurrentOrganization->getValue('org_longname'));
$writer->setKeywords(array($gL10n->get('PLG_MITGLIEDSBEITRAG_MEMBERSHIP_FEE'), $gL10n->get('PLG_MITGLIEDSBEITRAG_PRE_NOTIFICATION'), $gL10n->get('PLG_MITGLIEDSBEITRAG_SEPA')));
$writer->setDescription($gL10n->get('PLG_MITGLIEDSBEITRAG_CREATED_WITH'));
$writer->writeSheet($rows,'', $header);
$writer->writeToStdOut();
}