private function printFormParallel()
    {
        $params = array();
        if ($this->_age_brackets) {
            $params['(age_bracket'] = $this->_age_brackets;
        }
        if ($this->_statuses) {
            $params['(status'] = $this->_statuses;
        }
        $totalPersons = Attendance_Record_Set::getPersonDataForCohorts($this->_cohortids, $params);
        $totalPrinted = 0;
        $cancelURL = build_url(array('*' => NULL, 'view' => 'attendance__record', 'cohortids' => $this->_cohortids, 'attendance_date' => $this->_attendance_date, 'release' => 1));
        $dummy = new Person();
        ?>
		<table class="table table-condensed table-auto-width valign-middle">
			<thead>
				<tr>
			<?php 
        if (SizeDetector::isWide()) {
            ?>
				<th>ID</th>
				<?php 
        }
        if ($this->_show_photos) {
            ?>
					<th>&nbsp;</th>
				</td>
				<?php 
        }
        ?>
					<th><?php 
        echo _('Name');
        ?>
</th>
			<?php 
        if (SizeDetector::isWide()) {
            ?>
				<th><?php 
            echo _('Status');
            ?>
</th>
				<?php 
        }
        foreach ($this->_record_sets as $prefix => $set) {
            ?>
				<th class="center"><?php 
            echo $set->getCohortName();
            ?>
 </th>
				<?php 
        }
        if (SizeDetector::isWide()) {
            ?>
				<th><?php 
            echo _('Actions');
            ?>
</th>
				<?php 
        }
        ?>
				</tr>
			</thead>
			<tbody>


			<?php 
        foreach ($totalPersons as $personid => $detail) {
            ?>
				<tr>
				<?php 
            if (SizeDetector::isWide()) {
                ?>
					<td><?php 
                echo $personid;
                ?>
</td>
					<?php 
            }
            if ($this->_show_photos) {
                ?>
					<td>
						<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
">
							<img style="width: 50px; max-width: 50px" src="?call=photo&personid=<?php 
                echo (int) $personid;
                ?>
" />
						</a>
					</td>
					<?php 
            }
            ?>
					<td><?php 
            echo ents($detail['first_name'] . ' ' . $detail['last_name']);
            ?>
</td>
				<?php 
            if (SizeDetector::isWide()) {
                ?>
					<td class=""><?php 
                $dummy->printFieldValue('status', $detail['status']);
                ?>
</td>
					<?php 
            }
            foreach ($this->_record_sets as $prefix => $set) {
                ?>
					<td class="parallel-attendance">
						<?php 
                $totalPrinted += $set->printWidget($prefix, $personid);
                ?>
					</td>
					<?php 
            }
            if (SizeDetector::isWide()) {
                ?>
					<td class="action-cell narrow">
						<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-user"></i><?php 
                echo _('View');
                ?>
</a> &nbsp;
						<a class="med-popup" tabindex="-1" href="?view=_edit_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-wrench"></i><?php 
                echo _('Edit');
                ?>
</a> &nbsp;
						<a class="med-popup" tabindex="-1" href="?view=_add_note_to_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-pencil"></i><?php 
                echo _('Add Note');
                ?>
</a>
					</td>
					<?php 
            }
            ?>
				</tr>
				<?php 
        }
        ?>
				<tr class="headcount">
					<th class="right" colspan="<?php 
        echo 1 + 2 * (int) SizeDetector::isWide() + (int) $this->_show_photos;
        ?>
"><?php 
        echo _('Total Headcount:');
        ?>
 &nbsp;</th>
				<?php 
        foreach ($this->_record_sets as $prefix => $set) {
            ?>
					<td class="center parallel-attendance"><?php 
            $set->printHeadcountField();
            ?>
</td>
					<?php 
        }
        ?>
					<td>&nbsp;</td>
				</tr>
			</tbody>
		</table>
		<input type="submit" class="btn" value="Save All Attendances" />
		<a href="<?php 
        echo $cancelURL;
        ?>
" class="btn">Cancel</a>
		<?php 
        return $totalPrinted;
    }
    /**
     * Print the value of a field to the HTML interface
     *
     * Subclasses should add links and other HTML markup by overriding this
     */
    function printFieldValue($name, $value = null)
    {
        if (is_null($value)) {
            $value = $this->getValue($name);
        }
        if ($name == 'restrictions') {
            ?>
			<table class="standard">
				<tr>
					<th>Congregation Restrictions: &nbsp;</th>
					<th>Group Restrictions:</th>
				</tr>
				<tr>
					<td>
						<?php 
            if (!empty($value['congregation'])) {
                foreach ($GLOBALS['system']->getDBObjectData('congregation', array('(id' => $value['congregation'])) as $cong) {
                    echo ents($cong['name']) . '<br />';
                }
            } else {
                echo '(None)';
            }
            ?>
					</td>
					<td>
						<?php 
            if (!empty($value['group'])) {
                foreach ($GLOBALS['system']->getDBObjectData('person_group', array('(id' => $value['group'])) as $group) {
                    echo ents($group['name']) . '<br />';
                }
            } else {
                echo '(None)';
            }
            ?>
					</td>
				</tr>
			</table>
			<?php 
        } else {
            return parent::printFieldValue($name, $value);
        }
    }
    function _printResultSet($congid, $groupid)
    {
        echo '<h3>';
        if ($congid) {
            $cong = $GLOBALS['system']->getDBObject('congregation', $congid);
            $cong->printFieldValue('name');
            echo ' Congregation';
        } else {
            $group = $GLOBALS['system']->getDBObject('person_group', $groupid);
            $group->printFieldValue('name');
            echo ' Group';
        }
        echo '</h3>';
        list($dates, $attendances, $totals) = Attendance_Record_Set::getAttendances((array) $congid, $groupid, $this->age_bracket, $this->start_date, $this->end_date);
        if (empty($attendances)) {
            ?>
			<p><i>No attendance records found.  Try adjusting your criteria.</i></p>
			<?php 
            return;
        }
        $headcounts = Headcount::fetchRange($congid ? 'congregation' : 'person_group', $congid ? $congid : $groupid, $this->start_date, $this->end_date);
        $letters = array(0 => 'A', 1 => 'P', '' => '?');
        $classes = array(0 => 'absent', 1 => 'present', '' => 'unknown');
        $dummy = new Person();
        ?>
		<form method="post" action="" class="bulk-person-action">
		<table class="table table-hover table-auto-width nowrap table-bordered table-condensed">
			<thead>
				<tr>
					<th>Last Name</th>
					<th>First Name</th>
					<th><?php 
        echo $this->groupid ? 'Membership Status' : 'Status';
        ?>
</th>
				<?php 
        foreach ($dates as $date) {
            ?>
					<th><?php 
            echo date('j M', strtotime($date));
            ?>
</th>
					<?php 
        }
        ?>
					<th>Actions</th>
					<th class="narrow selector form-inline"><input type="checkbox" class="select-all" title="Select all" /></th>
				</tr>
			</thead>
			<tbody>
			<?php 
        foreach ($attendances as $personid => $record) {
            ?>
				<tr <?php 
            if ($record['status'] == 'archived') {
                echo 'class="archived"';
            }
            ?>
>
					<td><?php 
            echo ents($record['last_name']);
            ?>
</td>
					<td><?php 
            echo ents($record['first_name']);
            ?>
</td>
					<td>
						<?php 
            if ($this->groupid) {
                echo ents($record['membership_status']);
            } else {
                $dummy->printFieldValue('status', $record['status']);
            }
            ?>
					</td>
				<?php 
            foreach ($dates as $date) {
                $letter = $letters[array_get($record, $date, '')];
                $class = $classes[array_get($record, $date, '')];
                echo '<td class="' . $class . '">' . $letter . '</td>';
            }
            ?>
					<td class="narrow action-cell">
						<a class="med-popup" href="?view=persons&personid=<?php 
            echo $personid;
            ?>
"><i class="icon-user"></i>View</a> &nbsp;
					<?php 
            if ($GLOBALS['user_system']->havePerm(PERM_EDITPERSON)) {
                ?>
						<a class="med-popup" href="?view=_edit_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-wrench"></i>Edit</a> &nbsp;
						<?php 
            }
            if ($GLOBALS['user_system']->havePerm(PERM_EDITNOTE)) {
                ?>
						<a class="med-popup" href="?view=_add_note_to_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-pencil"></i>Add Note</a>
						<?php 
            }
            ?>
					</td>
					<td class="selector"><input name="personid[]" type="checkbox" value="<?php 
            echo $personid;
            ?>
" /></td>
				</tr>
				<?php 
        }
        ?>
			</tbody>
			<tfoot class="attendance-stats">
				<tr class="headcount">
					<th colspan="3">Total Headcount</th>
				<?php 
        foreach ($dates as $date) {
            ?>
					<td>
						<?php 
            echo array_get($headcounts, $date);
            ?>
					</td>
					<?php 
        }
        ?>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr class="present">
					<th colspan="3">Total Present</th>
				<?php 
        foreach ($dates as $date) {
            ?>
					<td>
						<?php 
            echo array_get($totals[$date], 1, 0);
            ?>
					</td>
					<?php 
        }
        ?>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr class="absent">
					<th colspan="3">Total Absent</th>
				<?php 
        foreach ($dates as $date) {
            ?>
					<td>
						<?php 
            echo array_get($totals[$date], 0, 0);
            ?>
					</td>
					<?php 
        }
        ?>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr class="extras">
					<th colspan="3">Extras</th>
				<?php 
        foreach ($dates as $date) {
            ?>
					<td>
						<?php 
            if (isset($headcounts[$date])) {
                echo $headcounts[$date] - array_get($totals[$date], 1, 0);
            }
            ?>
					</td>
					<?php 
        }
        ?>
					<td colspan="2">&nbsp;</td>
				</tr>
			</tfoot>
		</table>
		<?php 
        include 'templates/bulk_actions.template.php';
        ?>
		</form>
		<?php 
    }
    public function printForm($prefix = 0)
    {
        if (empty($this->_persons)) {
            return 0;
        }
        $GLOBALS['system']->includeDBClass('person');
        $dummy = new Person();
        ?>
		<table class="table table-condensed table-auto-width valign-middle">
		<?php 
        $is_first = TRUE;
        foreach ($this->_persons as $personid => $details) {
            $dummy->populate($personid, $details);
            ?>
			<tr>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td><?php 
                echo $personid;
                ?>
</td>
				<?php 
            }
            if ($this->show_photos) {
                ?>
				<td>
					<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
">
						<img style="width: 50px; max-width: 50px" src="?call=photo&personid=<?php 
                echo (int) $personid;
                ?>
" />
					</a>
				</td>
				<?php 
            }
            ?>
				<td>
					<?php 
            echo ents($details['first_name'] . ' ' . $details['last_name']);
            ?>
				</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td>
					<?php 
                if ($this->groupid) {
                    echo ents($details['membership_status']);
                } else {
                    $dummy->printFieldValue('status');
                }
                ?>
				</td>
				<?php 
            }
            ?>
				<td class="narrow">
					<?php 
            $this->printWidget($prefix, $personid);
            ?>
				</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td class="action-cell narrow">
					<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-user"></i>View</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_edit_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-wrench"></i>Edit</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_add_note_to_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-pencil"></i>Add Note</a>
				</td>
				<?php 
            }
            ?>
			</tr>
			<?php 
            $is_first = FALSE;
        }
        ?>
		</table>
		<?php 
        return count($this->_persons);
    }
    foreach ($special_fields as $field) {
        ?>
			<td>
				<?php 
        if (isset($callbacks[$field])) {
            call_user_func($callbacks[$field], $id, array_get($details, $field, ''));
        } else {
            echo array_get($details, $field, '');
        }
        ?>
				</td>
			<?php 
    }
    ?>
			<td><?php 
    $dummy_person->printFieldValue('status');
    ?>
</td>
			<td><?php 
    $dummy_person->printFieldValue('age_bracket');
    ?>
</td>
			<td><?php 
    $dummy_person->printFieldValue('gender');
    ?>
</td>
			<?php 
    if (defined('PERSON_LIST_SHOW_GROUPS') && PERSON_LIST_SHOW_GROUPS) {
        ?>
					<td>  
				  	  <?php 
Example #6
0
    function _printSummaryRows()
    {
        parent::_printSummaryRows();
        include_once 'include/size_detector.class.php';
        if (SizeDetector::isNarrow()) {
            ?>
			<tr class="divider-before">
				<td colspan="2" id="family-members-container">
				<h4>&nbsp;Members:</h4>
			<?php 
        } else {
            ?>
			<tr class="divider-before">
				<th>Members</th>
				<td id="family-members-container">
			<?php 
        }
        $persons = $this->getMemberData();
        $show_actions = !empty($this->id);
        // hide actions if this is a "draft" family
        if (isset($this->_tmp['show_member_callback'])) {
            call_user_func($this->_tmp['show_member_callback'], $persons);
        } else {
            if (empty($this->_tmp['abbreviate_member_list'])) {
                ?>
					<div style="float: left" id="member-details-container">
					<?php 
                // full blown version
                $special_fields = array('congregation');
                if (!empty($this->_tmp['member_list_special_fields'])) {
                    $special_fields = $this->_tmp['member_list_special_fields'];
                }
                include 'templates/person_list.template.php';
                ?>
					</div>
					<?php 
                if ($GLOBALS['system']->featureEnabled('PHOTOS') && $this->id) {
                    ?>
						<div style="float: left; " id="family-photos-container">
						<?php 
                    foreach ($persons as $personid => $details) {
                        ?>
							<a href="?view=persons&personid=<?php 
                        echo (int) $personid;
                        ?>
"><img title="<?php 
                        echo ents($details['first_name'] . ' ' . $details['last_name']);
                        ?>
" src="?call=person_photo&personid=<?php 
                        echo (int) $personid;
                        ?>
" /></a>
							<?php 
                    }
                    ?>
						</div>
						<?php 
                }
            } else {
                // abbreviated version
                $GLOBALS['system']->includeDBClass('person');
                $dummy_person = new Person();
                ?>
					<table>
					<?php 
                foreach ($persons as $id => $person) {
                    $dummy_person->populate($id, $person);
                    $tr_class = $person['status'] == 'archived' ? ' class="archived"' : '';
                    ?>
						<tr<?php 
                    echo $tr_class;
                    ?>
>
							<td class="nowrap"><a href="?view=persons&personid=<?php 
                    echo $id;
                    ?>
"><?php 
                    echo ents($dummy_person->toString());
                    ?>
</a></td>
							<td><?php 
                    $dummy_person->printFieldValue('gender');
                    ?>
</td>
							<td><?php 
                    $dummy_person->printFieldValue('age_bracket');
                    ?>
</td>
						</tr>
						<?php 
                }
                ?>
					</table>
					<?php 
            }
        }
        ?>
			</td>
		</tr>
		<?php 
    }
    private function _printResultsTabular()
    {
        $GLOBALS['system']->includeDBClass('attendance_record_set');
        $GLOBALS['system']->includeDBClass('person');
        $dummy = new Person();
        $all_persons = Attendance_Record_Set::getPersonIDsForCohorts($this->cohortids);
        $all_dates = $all_attendances = $all_totals = $all_headcounts = array();
        if (!empty($this->cohortids)) {
            foreach ($this->cohortids as $cohortid) {
                $congid = $groupid = NULL;
                list($type, $id) = explode('-', $cohortid);
                if ($type == 'c') {
                    $congid = $id;
                }
                if ($type == 'g') {
                    $groupid = $id;
                }
                list($cdates, $cattendances, $ctotals) = Attendance_Record_Set::getAttendances((array) $congid, $groupid, $this->age_bracket, $this->start_date, $this->end_date);
                $hc = Headcount::fetchRange($congid ? 'congregation' : 'person_group', $congid ? $congid : $groupid, $this->start_date, $this->end_date);
                foreach ($hc as $date => $c) {
                    $all_headcounts[$date][$cohortid] = $c;
                }
                $all_dates = array_merge($all_dates, $cdates);
                foreach ($ctotals as $date => $t) {
                    $all_totals[$date][$cohortid] = $t;
                }
                foreach ($cattendances as $personid => $cat) {
                    $all_persons[$personid]['cohortids'][] = $cohortid;
                    foreach ($cat as $k => $v) {
                        if (!in_array($k, array('first_name', 'last_name', 'membership_status', 'status'))) {
                            $all_attendances[$personid][$cohortid][$k] = $v;
                        }
                    }
                }
            }
        }
        $all_dates = array_unique($all_dates);
        ?>
		<table class="table table-hover table-condensed table-auto-width valign-middle table-bordered parallel-attendance-report">
			<thead>
				<tr>
					<th <?php 
        if ($this->format != 'totals') {
            echo 'rowspan="2"';
        }
        ?>
>Name</th>
				<?php 
        if (SizeDetector::isWide()) {
            ?>
					<th <?php 
            if ($this->format != 'totals') {
                echo 'rowspan="2"';
            }
            ?>
>Status</th>
					<?php 
        }
        if ($this->format == 'totals') {
            $colspan = 1;
        } else {
            $colspan = count($this->cohortids);
        }
        foreach ($all_dates as $date) {
            $classes = 'center nowrap';
            if ($this->format != 'totals') {
                $classes .= ' new-cohort';
            }
            ?>
					<th class="<?php 
            echo $classes;
            ?>
" colspan="<?php 
            echo $colspan;
            ?>
"><?php 
            echo format_date($date);
            ?>
</th>
					<?php 
        }
        ?>
					<th <?php 
        if ($this->format != 'totals') {
            echo 'rowspan="2"';
        }
        ?>
></th>
					<th class="narrow selector form-inline" rowspan="2"><input type="checkbox" class="select-all" title="Select all" /></th>					
				</tr>

			<?php 
        if ($this->format != 'totals') {
            ?>
				<tr>
				<?php 
            foreach ($all_dates as $date) {
                $first = TRUE;
                foreach ($this->cohortids as $cohortid) {
                    $name = '';
                    list($type, $id) = explode('-', $cohortid);
                    if ($type == 'c') {
                        $congregation = $GLOBALS['system']->getDBObject('congregation', $id);
                        $name = $congregation->getValue('name');
                    } else {
                        if ($type == 'g') {
                            $group =& $GLOBALS['system']->getDBObject('person_group', $id);
                            $name = $group->getValue('name');
                        }
                    }
                    $short = reset(explode(' ', $name));
                    if (strlen($short) > 5 && !preg_match('/[0-9]/', $short)) {
                        $short = substr($short, 0, 3) . '…';
                    }
                    $class = $first ? 'new-cohort' : '';
                    ?>
						<th class="nowrap <?php 
                    echo $class;
                    ?>
" title="<?php 
                    echo ents($name);
                    ?>
"><?php 
                    echo ents($short);
                    ?>
</th>
						<?php 
                    $first = FALSE;
                }
            }
            ?>
				</tr>
				<?php 
        }
        ?>
			</thead>
			<tbody>
			<?php 
        foreach ($all_persons as $personid => $details) {
            if (!isset($all_attendances[$personid])) {
                continue;
            }
            ?>
				<tr <?php 
            if ($details['status'] == 'archived') {
                echo 'class="archived"';
            }
            ?>
>
					<td class="nowrap">
						<?php 
            echo ents($details['first_name'] . ' ' . $details['last_name']);
            ?>
					</td>
				<?php 
            if (SizeDetector::isWide()) {
                ?>
					<td><?php 
                $dummy->printFieldValue('status', $details['status']);
                ?>
</th>
					<?php 
            }
            foreach ($all_dates as $date) {
                $first = TRUE;
                if ($this->format == 'totals') {
                    $score = '';
                    foreach ($this->cohortids as $cohortid) {
                        $catt = array_get($all_attendances[$personid], $cohortid, array());
                        $x = array_get($catt, $date, '');
                        if (strlen($x)) {
                            $score = (int) $score + $x;
                        }
                    }
                    $class = $this->classes[$score > 0 ? 1 : $score];
                    if ($score === '') {
                        $score = '?';
                    }
                    echo '<td class="center ' . $class . '">' . $score . '</td>';
                } else {
                    foreach ($this->cohortids as $cohortid) {
                        if (!in_array($cohortid, array_get($all_persons[$personid], 'cohortids', array()))) {
                            $class = 'disabled';
                            $letter = '';
                        } else {
                            $catt = array_get($all_attendances[$personid], $cohortid, array());
                            $v = array_get($catt, $date, '');
                            $letter = $this->letters[$v];
                            $class = $this->classes[$v];
                        }
                        if ($first) {
                            $class .= ' new-cohort';
                        }
                        echo '<td class="' . $class . '">' . $letter . '</td>';
                        $first = FALSE;
                    }
                }
            }
            $this->_printActionsAndSelector($personid);
            ?>
	
				</tr>
				<?php 
        }
        ?>
			</tbody>
			<?php 
        if ($this->format != 'totals') {
            // headcounts don't make sense when we collapse groups down into totals
            $colspan = SizeDetector::isWide() ? 'colspan="2"' : '';
            ?>
			<tfoot class="attendance-stats">
				<tr class="headcount">
					<th <?php 
            echo $colspan;
            ?>
>Total Headcount</th>
				<?php 
            foreach ($all_dates as $date) {
                $hc = array_get($all_headcounts, $date, array());
                foreach ($this->cohortids as $cohortid) {
                    ?>
						<td>
							<?php 
                    echo array_get($hc, $cohortid, '');
                    ?>
						</td>
						<?php 
                }
            }
            ?>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr class="present">
					<th <?php 
            echo $colspan;
            ?>
>Total Present</th>
				<?php 
            foreach ($all_dates as $date) {
                $tots = array_get($all_totals, $date, array());
                foreach ($this->cohortids as $cohortid) {
                    ?>
						<td>
							<?php 
                    echo array_get(array_get($tots, $cohortid, array()), 1, 0);
                    ?>
						</td>
						<?php 
                }
            }
            ?>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr class="absent">
					<th <?php 
            echo $colspan;
            ?>
>Total Absent</th>
				<?php 
            foreach ($all_dates as $date) {
                $tots = array_get($all_totals, $date, array());
                foreach ($this->cohortids as $cohortid) {
                    ?>
						<td>
							<?php 
                    echo array_get(array_get($tots, $cohortid, array()), 0, 0);
                    ?>
						</td>
						<?php 
                }
            }
            ?>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr class="extras">
					<th <?php 
            echo $colspan;
            ?>
>Extras</th>
				<?php 
            foreach ($all_dates as $date) {
                $tots = array_get($all_totals, $date, array());
                $hc = array_get($all_headcounts, $date, array());
                foreach ($this->cohortids as $cohortid) {
                    $present = array_get(array_get($tots, $cohortid, array()), 1, 0);
                    $absent = array_get(array_get($tots, $cohortid, array()), 0, 0);
                    $headcount = array_get($hc, $cohortid, NULL);
                    ?>
						<td>
							<?php 
                    if ($headcount) {
                        echo $headcount - $present - $absent;
                    }
                    ?>
						</td>
						<?php 
                }
            }
            ?>
					<td colspan="2">&nbsp;</td>
				</tr>
			</tfoot>
			<?php 
        }
        ?>
		</table>
		<?php 
        include 'templates/bulk_actions.template.php';
    }
    function printForm($prefix = 0)
    {
        require_once 'include/size_detector.class.php';
        $order = defined('ATTENDANCE_LIST_ORDER') ? constant('ATTENDANCE_LIST_ORDER') : self::LIST_ORDER_DEFAULT;
        if ($this->congregationid) {
            $conds = array('congregationid' => $this->congregationid, '!status' => 'archived');
            if (strlen($this->age_bracket)) {
                $conds['age_bracket'] = $this->age_bracket;
            }
            $members = $GLOBALS['system']->getDBObjectData('person', $conds, 'AND', $order);
        } else {
            $group =& $GLOBALS['system']->getDBObject('person_group', $this->groupid);
            $members =& $group->getMembers(FALSE, $order);
            if (strlen($this->age_bracket)) {
                // Not the most efficient but it's a problem when it's a problem
                foreach ($members as $i => $person) {
                    if ($person['age_bracket'] != $this->age_bracket) {
                        unset($members[$i]);
                    }
                }
            }
        }
        $GLOBALS['system']->includeDBClass('person');
        $dummy = new Person();
        ?>
		<table class="table table-condensed table-auto-width valign-middle">
		<?php 
        $is_first = TRUE;
        foreach ($members as $personid => $details) {
            $v = isset($this->_attendance_records[$personid]) ? $this->_attendance_records[$personid] ? 'present' : 'absent' : (empty($this->_attendance_records) ? '' : 'unknown');
            $dummy->populate($personid, $details);
            ?>
			<tr>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td><?php 
                echo $personid;
                ?>
</td>
				<?php 
            }
            if ($this->show_photos) {
                ?>
				<td>
					<img style="width: 50px; max-width: 50px" src="?call=person_photo&personid=<?php 
                echo (int) $personid;
                ?>
" />
				</td>
				<?php 
            }
            ?>
				<td><?php 
            echo ents($details['last_name']);
            ?>
</td>
				<td><?php 
            echo ents($details['first_name']);
            ?>
</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td>
					<?php 
                if ($this->groupid) {
                    echo ents($details['membership_status']);
                } else {
                    $dummy->printFieldValue('status');
                }
                ?>
				</td>
				<?php 
            }
            ?>
				<td class="narrow">
					<?php 
            print_widget('attendances[' . $prefix . '][' . $personid . ']', array('options' => array('unknown' => '?', 'present' => 'Present', 'absent' => 'Absent'), 'type' => 'select', 'style' => 'colour-buttons', 'class' => $is_first ? 'autofocus' : ''), $v);
            ?>
				</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td class="action-cell narrow">
					<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-user"></i>View</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_edit_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-wrench"></i>Edit</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_add_note_to_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-pencil"></i>Add Note</a>
				</td>
				<?php 
            }
            ?>
			</tr>
			<?php 
            $is_first = FALSE;
        }
        ?>
		</table>
		<?php 
        return count($members);
    }