2f98536933a61dccf849a1c8a935c24abd1015c0
[memberdb.git] / include / xlsexport.php
1 <?php
2
3 function action_export_members()
4 {
5     error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
6
7     // Creating a workbook
8     $workbook = new Spreadsheet_Excel_Writer();
9     $workbook->setVersion(8);
10
11     // sending HTTP headers
12     $workbook->send('Mitglieder.xls');
13
14     // Creating a worksheet
15     $members = db_get_members();
16
17     $row = 0;
18     $col = 0;
19
20     $worksheet =& $workbook->addWorksheet('Mitglieder');
21     $worksheet->setInputEncoding('UTF-8');
22     $worksheet->write($row, $col++, 'Mitgliedsnummer');
23     $worksheet->write($row, $col++, 'Nickname');
24     $worksheet->write($row, $col++, 'E-Mail');
25     $worksheet->write($row, $col++, 'Vorname');
26     $worksheet->write($row, $col++, 'Nachname');
27     $worksheet->write($row, $col++, 'Stra├če');
28     $worksheet->write($row, $col++, 'Hausnummer');
29     $worksheet->write($row, $col++, 'PLZ');
30     $worksheet->write($row, $col++, 'Ort');
31     $worksheet->write($row, $col++, 'Land');
32     $worksheet->write($row, $col++, 'Telefon');
33     $worksheet->write($row, $col++, 'Fax');
34     $worksheet->write($row, $col++, 'Handy');
35     $worksheet->write($row, $col++, 'Jabber');
36     $worksheet->write($row, $col++, 'ICQ');
37     $worksheet->write($row, $col++, 'MSN');
38     $worksheet->write($row, $col++, 'AIM');
39     $worksheet->write($row, $col++, 'Skype');
40     $worksheet->write($row, $col++, 'Website');
41     $worksheet->write($row, $col++, 'Twitter');
42     $worksheet->write($row, $col++, 'Lastschrifteinzug');
43     $worksheet->write($row, $col++, 'Mandatunterschriftsdatum');
44     $worksheet->write($row, $col, 'Status');
45     $row++;
46
47     foreach ($members as $member) {
48         $col = 0;
49         $worksheet->write($row, $col++, $member['number']);
50         $worksheet->write($row, $col++, $member['nickname']);
51         $worksheet->write($row, $col++, $member['email']);
52         $worksheet->write($row, $col++, $member['firstname']);
53         $worksheet->write($row, $col++, $member['lastname']);
54         $worksheet->write($row, $col++, $member['street']);
55         $worksheet->write($row, $col++, $member['housenumber']);
56         $worksheet->write($row, $col++, $member['postcode']);
57         $worksheet->write($row, $col++, $member['city']);
58         $worksheet->write($row, $col++, $member['country']);
59         $worksheet->write($row, $col++, $member['phone']);
60         $worksheet->write($row, $col++, $member['fax']);
61         $worksheet->write($row, $col++, $member['mobile']);
62         $worksheet->write($row, $col++, $member['jabber']);
63         $worksheet->write($row, $col++, $member['icq']);
64         $worksheet->write($row, $col++, $member['msn']);
65         $worksheet->write($row, $col++, $member['aim']);
66         $worksheet->write($row, $col++, $member['skype']);
67         $worksheet->write($row, $col++, $member['url']);
68         $worksheet->write($row, $col++, $member['twitter']);
69         $worksheet->write($row, $col++, $member['directdebit']);
70         $worksheet->write($row, $col++, $member['ddmandatesigdate']);
71         $membership_info = fees_info_for_member($member['id'], time());
72         $worksheet->write($row, $col, $membership_info['is_member']);
73         $row++;
74     }
75
76     // Let's send the file
77     $workbook->close();
78
79     $content = ob_get_contents();
80     ob_end_clean();
81     echo $content;
82     exit();
83 }
84
85 function action_export_payments()
86 {
87     global $EARNING_TYPES, $EXPENSE_TYPES;
88
89     error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
90
91     // Creating a workbook
92     $workbook = new Spreadsheet_Excel_Writer();
93     $workbook->setVersion(8);
94
95     // sending HTTP headers
96     $workbook->send('Finanzen.xls');
97
98     // Creating a worksheet
99     $payments = db_get_finished_payments(0, 1000000000);
100
101
102     $row = 0;
103     $col = 0;
104     $current_year = '';
105     foreach ($payments as $payment) {
106         $year = substr($payment['date'], 0, 4);
107         if ($year != $current_year) {
108             $current_year = $year;
109             $worksheet =& $workbook->addWorksheet($year);
110             $worksheet->setInputEncoding('UTF-8');
111             $row = 0;
112
113             $worksheet->write($row, $col++, 'Id');
114             $worksheet->write($row, $col++, 'Datum');
115             $worksheet->write($row, $col++, 'Kategorie');
116             $worksheet->write($row, $col++, 'Betrag');
117             $worksheet->write($row, $col++, 'Beschreibung');
118             $worksheet->write($row, $col++, 'Mitglied');
119             $worksheet->write($row, $col++, 'Kontostand');
120             $worksheet->write($row, $col++, 'Kassenstand');
121             $worksheet->write($row, $col, 'Gesamt');
122             $row++;
123             $col = 0;
124         }
125         $worksheet->write($row, $col++, $payment['id']);
126         $worksheet->write($row, $col++, $payment['date']);
127         $worksheet->write($row, $col++,
128             $payment['ptype'] == 'earning' ? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]);
129         $worksheet->write($row, $col++, ($payment['ptype'] == 'earning' ? 1 : -1) * $payment['value']);
130         $worksheet->write($row, $col++, $payment['description']);
131         $worksheet->write($row, $col++, $payment['nickname']);
132         $worksheet->write($row, $col++, $payment['bank']);
133         $worksheet->write($row, $col++, $payment['cash']);
134         $worksheet->write($row, $col, $payment['total']);
135
136         $col = 0;
137         $row++;
138     }
139
140     // Let's send the file
141     $workbook->close();
142
143     $content = ob_get_contents();
144     ob_end_clean();
145     echo $content;
146     exit();
147 }