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