Merge branch 'master' of ssh://git.ccc-ffm.de/memberdb
[memberdb.git] / include / members.php
index 71d7cb0..a98ff46 100644 (file)
@@ -12,6 +12,7 @@ $SQL_CREATE_MEMBERS = sprintf('
       `bankcode` blob NOT NULL,
       `bankname` blob NOT NULL,
       `directdebit` tinyint(1) NOT NULL,
+      `ddmandatesigdate` datetime NOT NULL,
       `street` varchar(255) NOT NULL,
       `housenumber` varchar(255) NOT NULL,
       `postcode` varchar(255) NOT NULL,
@@ -98,32 +99,33 @@ function db_get_member_with_number($member_number) {
 
 function validate_member($userdata, &$dbdata, &$validation) {/*{{{*/
     $fields = array(
-        'id'            => 'number',
-        'number'        => 'number',
-        'firstname'     => 'string',
-        'lastname'      => 'string',
-        'nickname'      => 'string',
-        'accountholder' => 'string',
-        'accountnumber' => 'string',
-        'bankcode'      => 'string',
-        'bankname'      => 'string',
-        'directdebit'   => 'number',
-        'street'        => 'string',
-        'housenumber'   => 'string',
-        'postcode'      => 'string',
-        'city'          => 'string',
-        'country'       => 'string',
-        'email'         => 'string',
-        'phone'         => 'string',
-        'fax'           => 'string',
-        'mobile'        => 'string',
-        'jabber'        => 'string',
-        'icq'           => 'string',
-        'msn'           => 'string',
-        'aim'           => 'string',
-        'skype'         => 'string',
-        'url'           => 'string',
-        'twitter'       => 'string',
+        'id'               => 'number',
+        'number'           => 'number',
+        'firstname'        => 'string',
+        'lastname'         => 'string',
+        'nickname'         => 'string',
+        'accountholder'    => 'string',
+        'accountnumber'    => 'string',
+        'bankcode'         => 'string',
+        'bankname'         => 'string',
+        'directdebit'      => 'number',
+        'ddmandatesigdate' => 'string',
+        'street'           => 'string',
+        'housenumber'      => 'string',
+        'postcode'         => 'string',
+        'city'             => 'string',
+        'country'          => 'string',
+        'email'            => 'string',
+        'phone'            => 'string',
+        'fax'              => 'string',
+        'mobile'           => 'string',
+        'jabber'           => 'string',
+        'icq'              => 'string',
+        'msn'              => 'string',
+        'aim'              => 'string',
+        'skype'            => 'string',
+        'url'              => 'string',
+        'twitter'          => 'string',
     );
     $orig = $dbdata;
     foreach ($fields as $name => $type) {
@@ -285,6 +287,9 @@ function ibanhin_close() {/*{{{*/
 function action_list_members() {/*{{{*/
     $members = db_get_members();
     $count   = 0;
+    $regular = 0;
+    $patron = 0;
+    $honorary = 0;
     ?>
     <h2>Liste der Mitglieder</h2>
     <?php if (isset($members)) : ?>
@@ -297,7 +302,15 @@ function action_list_members() {/*{{{*/
             </tr>
         <?php foreach ($members as $member) : ?>
             <?php $membership_info = fees_info_for_member($member['id'], time()); ?>
-                       <?php if (!empty($membership_info['is_member'])) $count++; ?>
+           <?php 
+                if (!empty($membership_info['is_member'])) {
+                    switch($membership_info['member_type']) {
+                        case 'regular': $regular++; break;
+                        case 'honorary': $honorary++; break;
+                        case 'patron': $patron++; break;
+                    }
+                }
+           ?>
             <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>
@@ -308,8 +321,18 @@ function action_list_members() {/*{{{*/
         </table>
     <?php else : ?>
         <p>Bisher gibt es noch keine Mitglieder.</p>
-    <?php endif ?>
-        <p>Derzeit gibt es <?=$count?> aktive Mitglieder.</p>
+    <?php
+        endif;
+        $count = $regular + $honorary + $patron;
+    ?>
+        <p>Derzeit gibt es <?=$count?> Vereinsmitglieder. Davon:
+            <ul>
+                <li><?=$regular?> ordentliche Mitglieder</li>
+                <li><?=$honorary?> Ehrenmitglieder</li>
+                <li style="font-weight: bold;"><?=$regular+$honorary?> stimmberechtigte Mitglieder</li>
+                <li><?=$patron?> F√∂rdermitglieder</li>
+            </ul>
+        </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>
@@ -320,7 +343,6 @@ function action_view_member() {/*{{{*/
     if (!isset($_REQUEST['id'])) redirect(link_to());
     $member = db_get_member_with_id($_REQUEST['id']);
     if (!isset($member)) redirect(link_to());
-
     form_member($member, true);
     action_list_events($member);
     action_create_event($member);
@@ -331,8 +353,18 @@ function action_create_member() {/*{{{*/
     $log_messages = array();
     if (isset($_POST['submit'])) {
         unset($_POST['id']);
+        
         if (validate_member($_POST, $member, $log_messages)) {
             if (empty($member['number'])) $member['number'] = db_get_next_free_member_number();
+            
+            if (($member['ddmandatesigdate'] == 'TT.MM.JJJJ') ||
+                ($member['ddmandatesigdate'] == ''))
+            {
+              $member['ddmandatesigdate'] = '0000-00-00 00:00:00';
+            } else {
+              $member['ddmandatesigdate'] = db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
+            }
+            
             if ($member_id = db_create_member($member)) {
                 redirect(link_to('view_member', array('id' => $member_id)) . '#events');
             }
@@ -350,6 +382,15 @@ function action_change_member() {/*{{{*/
     if (isset($_POST['submit'])) {
         if (validate_member($_POST, $member, $log_messages)) {
             if (empty($member['number'])) $member['number'] = db_get_next_free_member_number();
+                        
+            if (($member['ddmandatesigdate'] == 'TT.MM.JJJJ') ||
+                ($member['ddmandatesigdate'] == ''))
+            {
+              $member['ddmandatesigdate'] = '0000-00-00 00:00:00';
+            } else {
+              $member['ddmandatesigdate'] = db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
+            }
+
             if (db_change_member($member)) {
                 redirect(link_to('view_member', array('id' => $member['id'])));
             }
@@ -428,11 +469,9 @@ function form_member($member = array(), $readonly = false, $log_messages = array
         <fieldset id="bank_details">
             <legend>Bankverbindung</legend>
             <?=html_text_field('Kontoinhaber', 'accountholder', $member, true)?>
-            <?=html_text_field('Kontonummer', 'accountnumber', $member, true)?>
-            <?=html_text_field('Bankleitzahl', 'bankcode', $member, true)?>
+            <?=html_text_field('Kontonummer/IBAN', 'accountnumber', $member, true)?>
+            <?=html_text_field('Bankleitzahl/BIC', 'bankcode', $member, true)?>
             <?=html_text_field('Name der Bank', 'bankname', $member, true)?>
-            <?=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) : ?>
@@ -440,6 +479,18 @@ function form_member($member = array(), $readonly = false, $log_messages = array
             <?php else : ?>
                 <input class="submit" type="button" name="btn_bank_details" value="Bankverbindung &auml;ndern" onclick="bank_details_ask_pass()" id="btn_bank_details"/>
             <?php endif ?>
+            <?=html_list_box('Beitragseinzug', 'directdebit', $DIRECTDEBIT_STATES, $member, $readonly)?>
+            <?php
+              if ((!isset($member['ddmandatesigdate'])) ||
+                  ($member['ddmandatesigdate'] == '') ||
+                  ($member['ddmandatesigdate'] == '0000-00-00 00:00:00'))
+              {
+                $member['ddmandatesigdate'] = ($readonly) ? '' : html_escape('TT.MM.JJJJ');
+              } else {              
+                $member['ddmandatesigdate'] = html_escape(format_date(db_date2unixtime($member['ddmandatesigdate'])));
+              }
+            ?>
+            <?=html_text_field('Mandatsunterschrift', 'ddmandatesigdate', $member, $readonly)?>
         </fieldset>
         <fieldset style="clear: left;">
             <legend>Anschrift</legend>
@@ -502,8 +553,8 @@ function form_member($member = array(), $readonly = false, $log_messages = array
         <fieldset>
             <legend>Bankverbindung</legend>
             <?=html_text_field('Kontoinhaber', 'tmp_accountholder', $member, $readonly)?>
-            <?=html_text_field('Kontonummer', 'tmp_accountnumber', $member, $readonly)?>
-            <?=html_text_field('Bankleitzahl', 'tmp_bankcode', $member, $readonly)?>
+            <?=html_text_field('Kontonummer/IBAN', 'tmp_accountnumber', $member, $readonly)?>
+            <?=html_text_field('Bankleitzahl/BIC', 'tmp_bankcode', $member, $readonly)?>
             <?=html_text_field('Name der Bank', 'tmp_bankname', $member, $readonly)?>
             <?php if (!isset($member['id'])) : ?>
                 <input class="submit" type="button" name="btn_bank_details_save" value="&Uuml;bernehmen" onclick="bank_details_save()"/>
@@ -654,7 +705,9 @@ function bank_details_save() {/*{{{*/
     $("#tmp_accountnumber").val('');
     $("#tmp_bankcode").val('');
     $("#tmp_bankname").val('');
-
+    
+    accountnumber = accountnumber.replace(/\s+/g, '');
+    bankcode = bankcode.replace(/\s+/g, '');
     // 4.2 Encrypt/Decrypt data using AES with masterkey
     if (accountholder != "") { $('#accountholder').val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(accountholder), the_masterkey)); } else { $('#accountholder').val(''); }
     if (accountnumber != "") { $('#accountnumber').val(Crypto.AES.encrypt(Crypto.charenc.UTF8.stringToBytes(accountnumber), the_masterkey)); } else { $('#accountnumber').val(''); }