<?php
include 'renderer.php';

class Members extends Renderer {
    public function __construct(?string $templateName = null) {
        parent::__construct($templateName);
        $members = $this->getMemberList(true);
        $activeMembers = 0;
        $tableBody = '<tbody>';
        foreach ($members as $row) {
            $tableBody .= '<tr' . ($row['status_text'] !== 'Mitgliedschaft bestätigt' ? ' style="color:#a0a0a0"' : '') . '>'
                    . '<td>' . $row['id'] . '</td>'
                    . '<td>' . $row['last_name'] . ', ' . $row['first_name'] . '</td>'
                    . '<td>' . $row['email'] . '</td>'
                    . '<td>' . $row['last_payment'] . '</td>'
                    . '<td>' . $row['membership_start'] . '</td>'
                    . '<td>' . $row['status_text'] . '</td>'
                    . '<td><a href="editmember?id=' . $row['id'] . '">Bearbeiten</a>&nbsp;'
                    . '<a href="payings?id=' . $row['id'] . '">Zahlungen</a></td>' 
                    . '</tr>';
            if ($row['status_text'] == 'Mitgliedschaft bestätigt') {
                $activeMembers++;
            }
        }
        $tableBody .= '</tbody>';
        $this->content['memberlist'] = $tableBody;
        $this->content['numbermembers'] = $activeMembers;
    }
}
