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