Added XLS export of members.
[memberdb.git] / include / members.php
1 <?php
2
3 $SQL_CREATE_MEMBERS = sprintf('
4     CREATE TABLE IF NOT EXISTS `%1$s` (
5       `id` int(10) unsigned NOT NULL auto_increment,
6       `number` int(10) unsigned NOT NULL,
7       `firstname` varchar(255) NOT NULL,
8       `lastname` varchar(255) NOT NULL,
9       `nickname` varchar(255) NOT NULL,
10       `accountholder` blob NOT NULL,
11       `accountnumber` blob NOT NULL,
12       `bankcode` blob NOT NULL,
13       `bankname` blob NOT NULL,
14       `directdebit` tinyint(1) NOT NULL,
15       `street` varchar(255) NOT NULL,
16       `housenumber` varchar(255) NOT NULL,
17       `postcode` varchar(255) NOT NULL,
18       `city` varchar(255) NOT NULL,
19       `country` varchar(255) NOT NULL,
20       `email` varchar(255) NOT NULL,
21       `phone` varchar(255) NOT NULL,
22       `fax` varchar(255) NOT NULL,
23       `mobile` varchar(255) NOT NULL,
24       `jabber` varchar(255) NOT NULL,
25       `icq` varchar(255) NOT NULL,
26       `msn` varchar(255) NOT NULL,
27       `aim` varchar(255) NOT NULL,
28       `skype` varchar(255) NOT NULL,
29       `url` varchar(255) NOT NULL,
30       `twitter` varchar(255) NOT NULL,
31       `created_at` datetime NOT NULL,
32       `modified_at` datetime NOT NULL,
33       PRIMARY KEY  (`id`),
34       UNIQUE KEY `number` (`number`)
35     ) ENGINE=InnoDB DEFAULT CHARSET=%2$s
36     ', DB_TABLE_MEMBERS, DB_CHARSET);
37
38 /* DB functions {{{ */
39
40 function db_create_member($member) {
41     unset($member['id']);
42     $member['created_at']   = db_unixtime2datetime(time());
43     $member['modified_at']  = db_unixtime2datetime(time());
44     if (!db_insert_single(DB_TABLE_MEMBERS, $member)) return false;
45     return db_insert_id();
46 }
47
48 function db_change_member($member) {
49     $id = $member['id'];
50     unset($member['id']);
51     $member['modified_at']  = db_unixtime2datetime(time());
52     return db_update_single(DB_TABLE_MEMBERS, $member, sprintf('id=\'%1$d\'', db_escape($id)));
53 }
54
55 function db_get_members() {
56     $sql = 'SELECT * FROM %1$s ORDER BY number ASC';
57     return db_select_multi(sprintf($sql, DB_TABLE_MEMBERS));
58 }
59
60 function db_get_member_with_id($member_id) {
61     $sql = 'SELECT * FROM %1$s WHERE id=\'%2$d\' LIMIT 1';
62     return db_select_single(sprintf($sql, DB_TABLE_MEMBERS, db_escape($member_id)));
63 }
64
65 function db_get_next_free_member_number() {/*{{{*/
66     $row = db_select_single(sprintf('SELECT MAX(number) AS number FROM %1$s', DB_TABLE_MEMBERS));
67     if (!isset($row)) return 2;
68
69     $number = $row['number'] + 1;
70     // Some numbers are reserved for honorary members
71     $number = (int) $number;
72     switch ($number) {
73         case 1:
74         case 23:
75         case 42:
76         case 666:
77         case 1337:
78         case 31337:
79             return $number + 1;
80     }
81     return $number;
82 };/*}}}*/
83
84
85 function db_get_member_with_number($member_number) {
86     $sql = 'SELECT * FROM %1$s WHERE number=\'%2$d\' LIMIT 1';
87     return db_select_single(sprintf($sql, DB_TABLE_MEMBERS, db_escape($member_number)));
88 }
89
90 /* }}} */
91
92 function validate_member($userdata, &$dbdata, &$validation) {/*{{{*/
93     $fields = array(
94         'id'            => 'number',
95         'number'        => 'number',
96         'firstname'     => 'string',
97         'lastname'      => 'string',
98         'nickname'      => 'string',
99         'accountholder' => 'string',
100         'accountnumber' => 'string',
101         'bankcode'      => 'string',
102         'bankname'      => 'string',
103         'directdebit'   => 'bool',
104         'street'        => 'string',
105         'housenumber'   => 'string',
106         'postcode'      => 'string',
107         'city'          => 'string',
108         'country'       => 'string',
109         'email'         => 'string',
110         'phone'         => 'string',
111         'fax'           => 'string',
112         'mobile'        => 'string',
113         'jabber'        => 'string',
114         'icq'           => 'string',
115         'msn'           => 'string',
116         'aim'           => 'string',
117         'skype'         => 'string',
118         'url'           => 'string',
119         'twitter'       => 'string',
120     );
121     $orig = $dbdata;
122     foreach ($fields as $name => $type) {
123         if ($type == 'bool') {
124             $dbdata[$name] = !empty($userdata[$name]);
125             continue;
126         }
127         if (!isset($userdata[$name])) continue;
128         $dbdata[$name] = $userdata[$name];
129     }
130 //      ids must be equal
131 //      number must be equal. if changed - check if free and allowed
132     if (isset($orig['id'])) {
133         if ($dbdata['id'] != $orig['id']) {
134             $validation[] = 'Irgendwas ist sehr sehr komisch.';
135         }
136         if (!validate_member_number($dbdata['number'], $dbdata['id'])) {
137             $validation[] = 'Die Mitgliedsnummer ist schon vergeben.';
138         }
139         return (count($validation) == 0);
140     }
141     if (!validate_member_number($dbdata['number'])) {
142         $validation[] = 'Die Mitgliedsnummer ist schon vergeben.';
143     }
144     return (count($validation) == 0);
145 }/*}}}*/
146
147 function validate_member_number($member_number, $member_id = NULL) {/*{{{*/
148     $member = db_get_member_with_number($member_number);
149
150     // theres no member with this number
151     if (!isset($member)) return true;
152
153     // there is a member, but maybe its the one we got passed
154     if (isset($member_id) && $member_id == $member['id']) return true;
155
156     return false;
157 }/*}}}*/
158
159 function action_export_ibanhin() {/*{{{*/
160     $members = db_get_members();
161     if (empty($members)) return;
162     js_modal_windows();
163     js_get_master_key();
164 ?>
165     <noscript>
166         <p class="error">
167             <strong>Achtung:</strong> Ohne JavaScript geht hier gar nichts. Bitte aktivieren!
168         </p>
169     </noscript>
170
171     <h2>IBAN-hin</h2>
172 <input class="submit" type="button" name="btn_ibanhin" value="IBAN-hin erzeugen" onclick="ask_for_password()" id="btn_export_iban_hin"/>
173 <br/>
174 <br/>
175
176
177 <div id="password_popup" class="modal_window">
178     <fieldset>
179         <legend>Passwortabfrage</legend>
180         <?=html_password_field('Passwort', 'password')?>
181         <input class="submit" type="button" name="btn_export_ibanhin" value="IBAN-hin erzeugen" onclick="export_ibanhin()"/>
182         <input class="submit" type="button" name="btn_cancel" value="Abbrechen" onclick="cancel_ask_for_password()"/>
183     </fieldset>
184 </div>
185 <div id="ibanhin_popup" class="modal_window">
186     <fieldset>
187         <legend>IBAN-hin</legend>
188             <textarea id="ibanhin_content" style="width: 100%" rows="30" readonly="readonly"></textarea>
189             <input class="submit" type="button" name="btn_ibanhin_close" value="Schließen" onclick="ibanhin_close()"/>
190     </fieldset>
191 </div>
192
193 <script type="text/javascript">
194
195   var members = new Array(<?=join(",\n", array_map('json_encode', $members)) ?>);
196
197
198
199 $(document).ready(function(){  
200     $('#password').keypress( function(event) { if (event.keyCode == '13') { export_ibanhin(); } });
201     $('#btn_ibanhin').focus();
202 });  
203
204
205 function ask_for_password() {/*{{{*/
206     modal_window_show($("#password_popup"));
207     $("#password").focus();
208     return;
209 }/*}}}*/
210
211 function cancel_ask_for_password() {/*{{{*/
212     modal_window_hide();
213     $("#btn_ibanhin").focus();
214     return;
215 }/*}}}*/
216
217
218 function export_ibanhin() {/*{{{*/
219     
220     var ibanhin_content = "";
221
222     var password = $('#password').val();
223     $("#password").val('');
224
225     // We pass a closure so that get_master_key may defer execution
226     get_master_key(password, function(masterkey) {
227
228     modal_window_replace($("#ibanhin_popup"));
229
230     for (var i = 0; i < members.length; i++) {
231       if (members[i]['directdebit'] = "1") {
232         var accountnumber = members[i]['accountnumber'];
233         var bankcode      = members[i]['bankcode'];
234         if (accountnumber != "") accountnumber = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountnumber, masterkey));
235         if (bankcode      != "") bankcode      = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankcode,      masterkey));
236         if (accountnumber != "" && bankcode != "") {
237           /* ZKA-Spezifikation-IBAN-hin-IBAN-rueck
238              01. Satzart
239              02. Anwender
240              03. Internes Kennzeichen des Anwenders
241              04. BIC-ALT
242              IBAN-ALT
243              05. LK/PZ-ALT
244              06. BLZ-ALT
245              07. KTONR-ALT
246              IBAN-NEU
247              08. LK/PZ-NEU
248              09. BLZ-NEU
249              10. KTONR-NEU
250              11. UMST-KZ
251            */
252           ibanhin_content += '"DE";;"' + members[i]['number'] + '";;;"' + bankcode + '";"' + accountnumber + '";;;;;' + "\n";
253         }
254       }
255     }
256
257     $('#ibanhin_content').val(ibanhin_content);
258     $('#ibanhin_content').focus();
259     $('#ibanhin_content').select();
260     
261     });
262
263 }/*}}}*/
264
265 function ibanhin_close() {/*{{{*/
266     modal_window_hide();
267     $("#ibanhin_content").val('');
268 }/*}}}*/
269
270
271 </script>
272
273 <?php
274
275 }/*}}}*/
276
277
278 function action_list_members() {/*{{{*/
279     $members = db_get_members();
280     $count   = 0;
281     ?>
282     <h2>Liste der Mitglieder</h2>
283     <?php if (isset($members)) : ?>
284         <table>
285             <tr>
286                 <th>Mitgliedsnummer</th>
287                 <th>Nickname</th>
288                 <th>Vorname</th>
289                 <th>Nachname</th>
290             </tr>
291         <?php foreach ($members as $member) : ?>
292             <?php $membership_info = fees_info_for_member($member['id'], time()); ?>
293                         <?php if (!empty($membership_info['is_member'])) $count++; ?>
294             <tr <?php if (empty($membership_info['is_member'])) : ?>class="inactive"<?php endif ?>>
295                 <td><a href="<?=html_escape(link_to('view_member', array('id'=> $member['id'])))?>"><?=html_escape($member['number'])?></a></td>
296                 <td><?=html_escape($member['nickname'])?></td>
297                 <td><?=html_escape($member['firstname'])?></td>
298                 <td><?=html_escape($member['lastname'])?></td>
299             </tr>
300         <?php endforeach ?>
301         </table>
302     <?php else : ?>
303         <p>Bisher gibt es noch keine Mitglieder.</p>
304     <?php endif ?>
305         <p>Derzeit gibt es <?=$count?> aktive Mitglieder.</p>
306         <a href="<?=link_to('create_member')?>">Neues Mitglied</a>
307         <a href="<?=link_to('export_email')?>">E-Mail-Adressen</a>
308         <a href="<?=link_to('export_members')?>">XLS Export</a>
309     <?php
310 }/*}}}*/
311
312 function action_view_member() {/*{{{*/
313     if (!isset($_REQUEST['id'])) redirect(link_to());
314     $member = db_get_member_with_id($_REQUEST['id']);
315     if (!isset($member)) redirect(link_to());
316
317     form_member($member, true);
318     action_list_events($member);
319     action_create_event($member);
320 }/*}}}*/
321
322 function action_create_member() {/*{{{*/
323     $member = array();
324     $log_messages = array();
325     if (isset($_POST['submit'])) {
326         unset($_POST['id']);
327         if (validate_member($_POST, $member, $log_messages)) {
328             if (empty($member['number'])) $member['number'] = db_get_next_free_member_number();
329             if ($member_id = db_create_member($member)) {
330                 redirect(link_to('view_member', array('id' => $member_id)) . '#events');
331             }
332             echo db_error();
333         }
334     }
335     form_member($member, false, $log_messages);
336 }/*}}}*/
337
338 function action_change_member() {/*{{{*/
339     if (!isset($_REQUEST['id'])) redirect(link_to());
340     $member = db_get_member_with_id($_REQUEST['id']);
341     if (!isset($member)) redirect(link_to());
342     $log_messages = array();
343     if (isset($_POST['submit'])) {
344         if (validate_member($_POST, $member, $log_messages)) {
345             if (empty($member['number'])) $member['number'] = db_get_next_free_member_number();
346             if (db_change_member($member)) {
347                 redirect(link_to('view_member', array('id' => $member['id'])));
348             }
349             echo db_error();
350         }
351     }
352     form_member($member, false, $log_messages);
353 }/*}}}*/
354
355
356 function action_export_email() {/*{{{*/
357     $members = db_get_members();
358     $first = true;
359     ?>
360     <h2>E-Mail-Adressen</h2>
361     <?php if (isset($members)) : ?>
362         <?php foreach ($members as $member) : ?><?php $membership_info = fees_info_for_member($member['id'], time()); ?><?php if (!empty($membership_info['is_member'])) : ?><?php if (empty($member['email'])) continue; ?><?php if ($first) : $first = false; else :?>,<?php endif ?> <?=$member['email']?><?php endif ?><?php endforeach ?>
363     <?php else : ?>
364         <p>Bisher gibt's noch keine Mitglieder.</p>
365     <?php endif ?>
366     <?php
367 }/*}}}*/
368
369
370 function html_member_list_box($label, $name, $selected, $readonly = false, $id = NULL, $tag_params = '') {
371     $list = array(0 => '-');
372     $members = db_get_members();
373     if (!empty($members)) {
374         foreach ($members as $member) {
375             $list[$member['id']] = $member['number'] . ' ' . $member['nickname'];
376         }
377     }
378     return html_list_box($label, $name, $list, $selected, $readonly, $id, $tag_params);
379 }
380
381 function form_member($member = array(), $readonly = false, $log_messages = array()) {/*{{{*/
382     
383     $keys = db_get_crypto_keys();
384     if (empty($keys)) {
385 ?>
386         <p class="error">
387             <strong>Achtung:</strong> Bitte zuerst <a href="<?=link_to('cryptography')?>">Kryptographie einrichten</a>.
388         </p>
389 <?php
390         return;
391     }
392
393     js_modal_windows();
394     js_get_master_key();
395
396     ?>
397     <noscript>
398         <p class="error">
399             <strong>Achtung:</strong> Ohne JavaScript geht hier gar nichts. Bitte aktivieren!
400         </p>
401     </noscript>
402     <?php if (!isset($member['id'])) : ?>
403         <h2>Neues Mitglied</h2>
404     <?php elseif ($readonly) : ?>
405         <h2>Mitgliedsdetails</h2>
406     <?php else : ?>
407         <h2>Mitglied &auml;ndern</h2>
408     <?php endif ?>
409     <?php log_messages($log_messages); ?>
410     <form action="" method="post" class="clearfix">
411         <?php if (isset($member['id']) && !$readonly) : ?><?=html_hidden_field('id', $member)?><?php endif ?>
412         <fieldset>
413             <legend>Allgemein</legend>
414             <?=html_text_field('Mitgliedsnummer', 'number', $member, $readonly)?>
415             <?php if (!$readonly) : ?><small>Wird automatisch vergeben wenn leer.</small><?php endif ?>
416             <?=html_text_field('Nickname', 'nickname', $member, $readonly)?>
417             <?=html_text_field('E-Mail', 'email', $member, $readonly)?>
418         </fieldset>
419         <fieldset id="bank_details">
420             <legend>Bankverbindung</legend>
421             <?=html_text_field('Kontoinhaber', 'accountholder', $member, true)?>
422             <?=html_text_field('Kontonummer', 'accountnumber', $member, true)?>
423             <?=html_text_field('Bankleitzahl', 'bankcode', $member, true)?>
424             <?=html_text_field('Name der Bank', 'bankname', $member, true)?>
425             <?=html_checkbox('Lastschrifteinzug', 'directdebit', $member, 1, $readonly)?>
426             <?php if (!isset($member['id'])) : ?>
427                 <input class="submit" type="button" name="btn_bank_details" value="Bankverbindung erfassen" onclick="bank_details_ask_pass()" id="btn_bank_details"/>
428             <?php elseif ($readonly) : ?>
429                 <input class="submit" type="button" name="btn_bank_details" value="Bankverbindung betrachten" onclick="bank_details_ask_pass()" id="btn_bank_details"/>
430             <?php else : ?>
431                 <input class="submit" type="button" name="btn_bank_details" value="Bankverbindung &auml;ndern" onclick="bank_details_ask_pass()" id="btn_bank_details"/>
432             <?php endif ?>
433         </fieldset>
434         <fieldset style="clear: left;">
435             <legend>Anschrift</legend>
436             <?=html_text_field('Vorname', 'firstname', $member, $readonly)?>
437             <?=html_text_field('Nachname', 'lastname', $member, $readonly)?>
438             <?=html_text_field('Straße', 'street', $member, $readonly)?>
439             <?=html_text_field('Hausnummer', 'housenumber', $member, $readonly)?>
440             <?=html_text_field('PLZ', 'postcode', $member, $readonly)?>
441             <?=html_text_field('Ort', 'city', $member, $readonly)?>
442             <?=html_text_field('Land', 'country', $member, $readonly)?>
443         </fieldset>
444         <fieldset>
445             <legend>Sonstiges</legend>
446             <?=html_text_field('Telefon', 'phone', $member, $readonly)?>
447             <?=html_text_field('Fax', 'fax', $member, $readonly)?>
448             <?=html_text_field('Handy', 'mobile', $member, $readonly)?>
449             <?=html_text_field('Jabber', 'jabber', $member, $readonly)?>
450             <?=html_text_field('ICQ', 'icq', $member, $readonly)?>
451             <?=html_text_field('MSN', 'msn', $member, $readonly)?>
452             <?=html_text_field('AIM', 'aim', $member, $readonly)?>
453             <?=html_text_field('Skype', 'skype', $member, $readonly)?>
454             <?=html_text_field('Website', 'url', $member, $readonly)?>
455             <?=html_text_field('Twitter', 'twitter', $member, $readonly)?>
456         </fieldset>
457         <?php if (!$readonly) : ?>
458             <input class="submit" type="submit" name="submit" value="Speichern"/>
459         <?php else : ?>
460             <br style="clear: left;"/>
461             <a href="<?=html_escape(link_to('change_member', array('id' => $member['id'])))?>">Mitglied &auml;ndern</a>
462         <?php endif ?>
463     </form>
464     <?php if (!isset($member['id'])) : ?>
465     <input class="submit" type="button" name="btn_import_qrcode1" value="QR-Code importieren" onclick="import_qrcode_ask_pass()" id="btn_import_qrcode1"/>
466     <div id="password_popup2" class="modal_window">
467         <fieldset>
468             <legend>Passwortabfrage</legend>
469             <?=html_password_field('Passwort', 'password2')?>
470             <input class="submit" type="button" name="btn_import_qrcode2" value="QR-Code importieren" onclick="import_qrcode()"/>
471         <input class="submit" type="button" name="btn_cancel_import_qrcode" value="Abbrechen" onclick="cancel_import_qrcode()"/>
472         </fieldset>
473     </div>
474     <div id="qrcode_popup" class="modal_window">
475         <fieldset>
476             <legend>QR-Code</legend>
477             <textarea id="qrcode_content" style="width: 100%" rows="30"></textarea>
478             <input class="submit" type="button" name="btn_qrcode_close" value="Importieren" onclick="qrcode_close()"/>
479         </fieldset>
480     </div>
481     <?php endif ?>
482     
483     <div id="password_popup" class="modal_window">
484         <fieldset>
485             <legend>Passwortabfrage</legend>
486             <?=html_password_field('Passwort', 'password1')?>
487             <input class="submit" type="button" name="btn_decrypt_bank_details" value="Bankdaten entschl&uuml;sseln" onclick="decrypt_bank_details()"/>
488         <input class="submit" type="button" name="btn_cancel" value="Abbrechen" onclick="cancel_change_bank_details()"/>
489         </fieldset>
490     </div>
491     <div id="bank_detail_popup" class="modal_window">
492         <fieldset>
493             <legend>Bankverbindung</legend>
494             <?=html_text_field('Kontoinhaber', 'tmp_accountholder', $member, $readonly)?>
495             <?=html_text_field('Kontonummer', 'tmp_accountnumber', $member, $readonly)?>
496             <?=html_text_field('Bankleitzahl', 'tmp_bankcode', $member, $readonly)?>
497             <?=html_text_field('Name der Bank', 'tmp_bankname', $member, $readonly)?>
498             <?php if (!isset($member['id'])) : ?>
499                 <input class="submit" type="button" name="btn_bank_details_save" value="&Uuml;bernehmen" onclick="bank_details_save()"/>
500                 <input class="submit" type="button" name="btn_bank_details_cancel" value="Abbrechen" onclick="bank_details_cancel()"/>
501             <?php elseif ($readonly) : ?>
502                 <input class="submit" type="button" name="btn_bank_details_cancel" value="Zur&uuml;ck" onclick="bank_details_cancel()" id="btn_bank_details_cancel"/>
503             <?php else : ?>
504                 <input class="submit" type="button" name="btn_bank_details_save" value="&Uuml;bernehmen" onclick="bank_details_save()"/>
505                 <input class="submit" type="button" name="btn_bank_details_cancel" value="Abbrechen" onclick="bank_details_cancel()"/>
506             <?php endif ?>
507         </fieldset>
508     </div>
509 <script type="text/javascript">
510
511
512 var the_masterkey;
513
514 $(document).ready(function(){  
515     $('#accountholder').focus( function() { $("#btn_bank_details").focus(); });
516 <?php if ($readonly) : ?>
517     $('#btn_bank_details_cancel').keypress( function(event) { if (event.keyCode == '13') { bank_details_cancel(); } });
518 <?php else : ?>
519     $('#tmp_bankname').keypress( function(event) { if (event.keyCode == '13') { bank_details_save(); } });
520 <?php endif ?>
521     $('#password1').keypress( function(event) { if (event.keyCode == '13') { decrypt_bank_details(); } });
522     <?php if (!isset($member['id'])) : ?>
523     $('#password2').keypress( function(event) { if (event.keyCode == '13') { import_qrcode(); } });
524 <?php endif ?>
525 });  
526
527 function bank_details_ask_pass() {/*{{{*/
528     modal_window_show($("#password_popup"));
529     $("#password1").focus();
530     return;
531 }/*}}}*/
532
533
534 function import_qrcode_ask_pass() {/*{{{*/
535     modal_window_show($("#password_popup2"));
536     $("#password2").focus();
537     return;
538 }/*}}}*/
539
540 function cancel_change_bank_details() {/*{{{*/
541     modal_window_hide();
542     $("#btn_bank_details").focus();
543     $("#password1").val('');
544     return;
545 }/*}}}*/
546
547 function cancel_import_qrcode() {/*{{{*/
548     modal_window_hide();
549     $("#password2").val('');
550     return;
551 }/*}}}*/
552
553 function decrypt_bank_details() {/*{{{*/
554
555     var password = $('#password1').val();
556     $("#password1").val('');
557
558     // We pass a closure so that get_master_key may defer execution
559     get_master_key(password, function(masterkey) {
560
561         modal_window_replace($("#bank_detail_popup"));
562 <?php if ($readonly) : ?>
563         $('#btn_bank_details_cancel').focus();
564 <?php else : ?>
565         $('#tmp_accountholder').focus();
566 <?php endif ?>
567
568         var accountholder = $('#accountholder').val();
569         var accountnumber = $('#accountnumber').val();
570         var bankcode      = $('#bankcode').val();
571         var bankname      = $('#bankname').val();
572
573         // Encrypt/Decrypt data using AES with masterkey
574         if (accountholder != "") { $('#tmp_accountholder').val(Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountholder, masterkey))); }
575         if (accountnumber != "") { $('#tmp_accountnumber').val(Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountnumber, masterkey))); }
576         if (bankcode      != "") { $('#tmp_bankcode'     ).val(Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankcode,      masterkey))); }
577         if (bankname      != "") { $('#tmp_bankname'     ).val(Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankname,      masterkey))); }
578         the_masterkey = masterkey; // cache masterkey until popup is closed
579     });
580
581 }/*}}}*/
582
583 function import_qrcode() {/*{{{*/
584
585     var password = $('#password2').val();
586     $("#password2").val('');
587
588     // We pass a closure so that get_master_key may defer execution
589     get_master_key(password, function(masterkey) {
590
591         modal_window_replace($("#qrcode_popup"));
592         the_masterkey = masterkey; // cache masterkey until popup is closed
593     });
594
595 }/*}}}*/
596
597 function qrcode_close() {/*{{{*/
598
599     modal_window_hide();
600
601     var qrcode_content = $('#qrcode_content').val();
602     $("#qrcode_content").val('');
603     var qrcode = qrcode_content.split(';');
604     if (qrcode.length >= 17) { 
605         $("#nickname").val(qrcode[0]);
606         // XXX birthdate - unused
607         $("#email").val(qrcode[2]);
608         // XXX cccmember - unused
609         $("#firstname").val(qrcode[4]);
610         $("#lastname").val(qrcode[5]);
611         $("#street").val(qrcode[6]);
612         $("#housenumber").val(qrcode[7]);
613         $("#postcode").val(qrcode[8]);
614         $("#city").val(qrcode[9]);
615         $("#country").val(qrcode[10]);
616         // XXX fee unused
617         $("#paymentinterval").val(qrcode[12]);
618         var accountholder = qrcode[13];
619         var accountnumber = qrcode[14];
620         var bankcode = qrcode[15];
621         var bankname = qrcode[16];
622         // XXX amount unused - wurde erst am 4.5. ergänzt, war vorher leer.
623     }
624
625
626     // 4.2 Encrypt/Decrypt data using AES with masterkey
627     if (accountholder != "") { $('#accountholder').val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(accountholder), the_masterkey)); } else { $('#accountholder').val(''); }
628     if (accountnumber != "") { $('#accountnumber').val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(accountnumber), the_masterkey)); } else { $('#accountnumber').val(''); }
629     if (bankcode      != "") { $('#bankcode'     ).val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(bankcode),      the_masterkey)); } else { $('#bankcode').val(''); }
630     if (bankname      != "") { $('#bankname'     ).val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(bankname),      the_masterkey)); } else { $('#bankname').val(''); }
631     the_masterkey = '';
632
633 }/*}}}*/
634
635 function bank_details_save() {/*{{{*/
636
637     modal_window_hide();
638
639     var accountholder = $('#tmp_accountholder').val();
640     var accountnumber = $('#tmp_accountnumber').val();
641     var bankcode      = $('#tmp_bankcode').val();
642     var bankname      = $('#tmp_bankname').val();
643     $("#tmp_accountholder").val('');
644     $("#tmp_accountnumber").val('');
645     $("#tmp_bankcode").val('');
646     $("#tmp_bankname").val('');
647
648     // 4.2 Encrypt/Decrypt data using AES with masterkey
649     if (accountholder != "") { $('#accountholder').val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(accountholder), the_masterkey)); } else { $('#accountholder').val(''); }
650     if (accountnumber != "") { $('#accountnumber').val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(accountnumber), the_masterkey)); } else { $('#accountnumber').val(''); }
651     if (bankcode      != "") { $('#bankcode'     ).val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(bankcode),      the_masterkey)); } else { $('#bankcode').val(''); }
652     if (bankname      != "") { $('#bankname'     ).val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(bankname),      the_masterkey)); } else { $('#bankname').val(''); }
653     the_masterkey = '';
654
655 }/*}}}*/
656
657 function bank_details_cancel() {/*{{{*/
658
659     modal_window_hide();
660
661     $("#tmp_accountholder").val('');
662     $("#tmp_accountnumber").val('');
663     $("#tmp_bankcode").val('');
664     $("#tmp_bankname").val('');
665
666     the_masterkey = '';
667 }/*}}}*/
668
669 </script>
670     <?php
671 }/*}}}*/
672
673