Extend members possible directdebit status.
[memberdb.git] / include / members.php
index 7abcc9d..71d7cb0 100644 (file)
@@ -35,6 +35,13 @@ $SQL_CREATE_MEMBERS = sprintf('
     ) ENGINE=InnoDB DEFAULT CHARSET=%2$s
     ', DB_TABLE_MEMBERS, DB_CHARSET);
 
+$DIRECTDEBIT_STATES = array(
+    '' => '- (Barzahler)',
+    1 => 'DTAUS',
+    2 => 'SEPA Ersteinzug',
+    3 => 'SEPA Folgeeinzug'
+); 
+    
 /* DB functions {{{ */
 
 function db_create_member($member) {
@@ -100,7 +107,7 @@ function validate_member($userdata, &$dbdata, &$validation) {/*{{{*/
         'accountnumber' => 'string',
         'bankcode'      => 'string',
         'bankname'      => 'string',
-        'directdebit'   => 'bool',
+        'directdebit'   => 'number',
         'street'        => 'string',
         'housenumber'   => 'string',
         'postcode'      => 'string',
@@ -156,9 +163,128 @@ function validate_member_number($member_number, $member_id = NULL) {/*{{{*/
     return false;
 }/*}}}*/
 
+function action_export_ibanhin() {/*{{{*/
+    $members = db_get_members();
+    if (empty($members)) return;
+    js_modal_windows();
+    js_get_master_key();
+?>
+    <noscript>
+        <p class="error">
+            <strong>Achtung:</strong> Ohne JavaScript geht hier gar nichts. Bitte aktivieren!
+        </p>
+    </noscript>
+
+    <h2>IBAN-hin</h2>
+<input class="submit" type="button" name="btn_ibanhin" value="IBAN-hin erzeugen" onclick="ask_for_password()" id="btn_export_iban_hin"/>
+<br/>
+<br/>
+
+
+<div id="password_popup" class="modal_window">
+    <fieldset>
+        <legend>Passwortabfrage</legend>
+        <?=html_password_field('Passwort', 'password')?>
+        <input class="submit" type="button" name="btn_export_ibanhin" value="IBAN-hin erzeugen" onclick="export_ibanhin()"/>
+        <input class="submit" type="button" name="btn_cancel" value="Abbrechen" onclick="cancel_ask_for_password()"/>
+    </fieldset>
+</div>
+<div id="ibanhin_popup" class="modal_window">
+    <fieldset>
+        <legend>IBAN-hin</legend>
+            <textarea id="ibanhin_content" style="width: 100%" rows="30" readonly="readonly"></textarea>
+            <input class="submit" type="button" name="btn_ibanhin_close" value="Schlie├čen" onclick="ibanhin_close()"/>
+    </fieldset>
+</div>
+
+<script type="text/javascript">
+
+  var members = new Array(<?=join(",\n", array_map('json_encode', $members)) ?>);
+
+
+
+$(document).ready(function(){  
+    $('#password').keypress( function(event) { if (event.keyCode == '13') { export_ibanhin(); } });
+    $('#btn_ibanhin').focus();
+});  
+
+
+function ask_for_password() {/*{{{*/
+    modal_window_show($("#password_popup"));
+    $("#password").focus();
+    return;
+}/*}}}*/
+
+function cancel_ask_for_password() {/*{{{*/
+    modal_window_hide();
+    $("#btn_ibanhin").focus();
+    return;
+}/*}}}*/
+
+
+function export_ibanhin() {/*{{{*/
+    
+    var ibanhin_content = "";
+
+    var password = $('#password').val();
+    $("#password").val('');
+
+    // We pass a closure so that get_master_key may defer execution
+    get_master_key(password, function(masterkey) {
+
+    modal_window_replace($("#ibanhin_popup"));
+
+    for (var i = 0; i < members.length; i++) {
+      if (members[i]['directdebit'] == "1") {
+       var accountnumber = members[i]['accountnumber'];
+       var bankcode      = members[i]['bankcode'];
+       if (accountnumber != "") accountnumber = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(accountnumber, masterkey));
+       if (bankcode      != "") bankcode      = Crypto.charenc.UTF8.bytesToString(Crypto.AES.decrypt(bankcode,      masterkey));
+        if (accountnumber != "" && bankcode != "") {
+          /* ZKA-Spezifikation-IBAN-hin-IBAN-rueck
+             01. Satzart
+             02. Anwender
+             03. Internes Kennzeichen des Anwenders
+             04. BIC-ALT
+             IBAN-ALT
+             05. LK/PZ-ALT
+             06. BLZ-ALT
+             07. KTONR-ALT
+             IBAN-NEU
+             08. LK/PZ-NEU
+             09. BLZ-NEU
+             10. KTONR-NEU
+             11. UMST-KZ
+           */
+          ibanhin_content += '"DE";;"' + members[i]['number'] + '";;;"' + bankcode + '";"' + accountnumber + '";;;;;' + "\n";
+        }
+      }
+    }
+
+    $('#ibanhin_content').val(ibanhin_content);
+    $('#ibanhin_content').focus();
+    $('#ibanhin_content').select();
+    
+    });
+
+}/*}}}*/
+
+function ibanhin_close() {/*{{{*/
+    modal_window_hide();
+    $("#ibanhin_content").val('');
+}/*}}}*/
+
+
+</script>
+
+<?php
+
+}/*}}}*/
+
 
 function action_list_members() {/*{{{*/
     $members = db_get_members();
+    $count   = 0;
     ?>
     <h2>Liste der Mitglieder</h2>
     <?php if (isset($members)) : ?>
@@ -170,7 +296,9 @@ function action_list_members() {/*{{{*/
                 <th>Nachname</th>
             </tr>
         <?php foreach ($members as $member) : ?>
-            <tr>
+            <?php $membership_info = fees_info_for_member($member['id'], time()); ?>
+                       <?php if (!empty($membership_info['is_member'])) $count++; ?>
+            <tr <?php if (empty($membership_info['is_member'])) : ?>class="inactive"<?php endif ?>>
                 <td><a href="<?=html_escape(link_to('view_member', array('id'=> $member['id'])))?>"><?=html_escape($member['number'])?></a></td>
                 <td><?=html_escape($member['nickname'])?></td>
                 <td><?=html_escape($member['firstname'])?></td>
@@ -179,10 +307,12 @@ function action_list_members() {/*{{{*/
         <?php endforeach ?>
         </table>
     <?php else : ?>
-        <p>Bisher gibt's noch keine Mitglieder.</p>
+        <p>Bisher gibt es noch keine Mitglieder.</p>
     <?php endif ?>
+        <p>Derzeit gibt es <?=$count?> aktive Mitglieder.</p>
         <a href="<?=link_to('create_member')?>">Neues Mitglied</a>
         <a href="<?=link_to('export_email')?>">E-Mail-Adressen</a>
+        <a href="<?=link_to('export_members')?>">XLS Export</a>
     <?php
 }/*}}}*/
 
@@ -236,7 +366,7 @@ function action_export_email() {/*{{{*/
     ?>
     <h2>E-Mail-Adressen</h2>
     <?php if (isset($members)) : ?>
-        <?php foreach ($members as $member) : ?><?php if (empty($member['email'])) continue; ?><?php if ($first) : $first = false; else :?>,<?php endif ?> <?=$member['email']?><?php endforeach ?>
+        <?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 ?>
     <?php else : ?>
         <p>Bisher gibt's noch keine Mitglieder.</p>
     <?php endif ?>
@@ -257,6 +387,8 @@ function html_member_list_box($label, $name, $selected, $readonly = false, $id =
 
 function form_member($member = array(), $readonly = false, $log_messages = array()) {/*{{{*/
     
+    global $DIRECTDEBIT_STATES;
+    
     $keys = db_get_crypto_keys();
     if (empty($keys)) {
 ?>
@@ -299,7 +431,8 @@ function form_member($member = array(), $readonly = false, $log_messages = array
             <?=html_text_field('Kontonummer', 'accountnumber', $member, true)?>
             <?=html_text_field('Bankleitzahl', 'bankcode', $member, true)?>
             <?=html_text_field('Name der Bank', 'bankname', $member, true)?>
-            <?=html_checkbox('Lastschrifteinzug', 'directdebit', $member, 1, $readonly)?>
+            <?=html_list_box('Lastschrifteinzug', 'directdebit', $DIRECTDEBIT_STATES, $member, $readonly)?>
+            
             <?php if (!isset($member['id'])) : ?>
                 <input class="submit" type="button" name="btn_bank_details" value="Bankverbindung erfassen" onclick="bank_details_ask_pass()" id="btn_bank_details"/>
             <?php elseif ($readonly) : ?>