Merge branch 'master' of ssh://git.ccc-ffm.de/memberdb
[memberdb.git] / include / members.php
index 05ad46a..a98ff46 100644 (file)
@@ -1,8 +1,5 @@
 <?php
 
-// UPGRADE EXISTING DATABASE TABLE:
-// ALTER TABLE `memberdb_members` ADD `ddmandatesigdate` datetime NULL AFTER `directdebit`;
-
 $SQL_CREATE_MEMBERS = sprintf('
     CREATE TABLE IF NOT EXISTS `%1$s` (
       `id` int(10) unsigned NOT NULL auto_increment,
@@ -15,7 +12,7 @@ $SQL_CREATE_MEMBERS = sprintf('
       `bankcode` blob NOT NULL,
       `bankname` blob NOT NULL,
       `directdebit` tinyint(1) NOT NULL,
-      `ddmandatesigdate` datetime NULL,
+      `ddmandatesigdate` datetime NOT NULL,
       `street` varchar(255) NOT NULL,
       `housenumber` varchar(255) NOT NULL,
       `postcode` varchar(255) NOT NULL,
@@ -50,7 +47,6 @@ $DIRECTDEBIT_STATES = array(
 
 function db_create_member($member) {
     unset($member['id']);
-    $member['ddmandatesigdate'] = ($member['ddmandatesigdate'] == "") ? '0' : db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
     $member['created_at']   = db_unixtime2datetime(time());
     $member['modified_at']  = db_unixtime2datetime(time());
     if (!db_insert_single(DB_TABLE_MEMBERS, $member)) return false;
@@ -60,7 +56,6 @@ function db_create_member($member) {
 function db_change_member($member) {
     $id = $member['id'];
     unset($member['id']);
-    $member['ddmandatesigdate'] = ($member['ddmandatesigdate'] == "") ? '0' : db_unixtime2datetime(ui_date2unixtime($member['ddmandatesigdate']));
     $member['modified_at']  = db_unixtime2datetime(time());
     return db_update_single(DB_TABLE_MEMBERS, $member, sprintf('id=\'%1$d\'', db_escape($id)));
 }
@@ -292,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)) : ?>
@@ -304,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>
@@ -315,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>
@@ -337,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');
             }
@@ -356,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'])));
             }
@@ -434,8 +469,8 @@ 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)?>
             <?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"/>
@@ -445,7 +480,16 @@ function form_member($member = array(), $readonly = false, $log_messages = array
                 <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 $member['ddmandatesigdate'] = ($member['ddmandatesigdate'] != 0) ? html_escape(format_date(db_date2unixtime($member['ddmandatesigdate']))) : "";  ?>
+            <?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;">
@@ -509,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()"/>
@@ -661,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(''); }