private function printFormSequential()
    {
        $cancelURL = build_url(array('*' => NULL, 'view' => 'attendance__record', 'cohortids' => $this->_cohortids, 'attendance_date' => $this->_attendance_date, 'release' => 1));
        $totalPrinted = 0;
        foreach ($this->_record_sets as $i => $set) {
            if ((int) $set->congregationid) {
                $congregation = $GLOBALS['system']->getDBObject('congregation', (int) $set->congregationid);
            } else {
                if ($set->groupid) {
                    $group =& $GLOBALS['system']->getDBObject('person_group', $set->groupid);
                } else {
                    return;
                }
            }
            $title = $set->getCohortName();
            $stats = $abs = array();
            if ($set->statuses) {
                $options = Attendance_Record_Set::getStatusOptions();
                foreach ($set->statuses as $s) {
                    $stats[] = $options[$s];
                }
            }
            if ($set->age_brackets) {
                $GLOBALS['system']->includeDBClass('person');
                $p = new Person();
                foreach ($set->age_brackets as $ab) {
                    $p->setValue('age_bracket', $ab);
                    $abs[] = $p->getFormattedValue('age_bracket');
                }
            }
            $title = implode(', ', $stats) . ' ' . implode(',', $abs) . ' in ' . $title;
            ?>
			<h3><?php 
            echo ents($title);
            ?>
</h3>
			<div class="width-really-auto form-inline">
				<?php 
            $setPrinted = $set->printForm($i);
            if ($setPrinted > 0) {
                $totalPrinted += $setPrinted;
                ?>
					<div class="container row-fluid control-group">
						<p class="span6">
							<?php 
                echo _('Total headcount:');
                ?>
							<?php 
                $set->printHeadcountField();
                ?>
						</p>
						<p class="span6 align-right nowrap">
							<input type="submit" class="btn" value="Save All Attendances" />
							<a href="<?php 
                echo $cancelURL;
                ?>
" class="btn">Cancel</a>
						</p>
					</div>
					<?php 
            } else {
                ?>
					<i><?php 
                echo _('(No persons in this listing)');
                ?>
</i>
					<?php 
            }
            ?>
			</div>
			<?php 
        }
        return $totalPrinted;
    }
Esempio n. 2
0
 function save($update_members = TRUE)
 {
     $msg = '';
     if ($update_members) {
         if (!empty($this->_old_values['status'])) {
             if ($this->getValue('status') == 'archived') {
                 // Status has just been changed to 'archived' so archive members too
                 $members = $this->getMemberData();
                 if (!empty($members)) {
                     $GLOBALS['system']->includeDBClass('person');
                     $member = new Person();
                     $all_members_archived = TRUE;
                     foreach ($members as $id => $details) {
                         $member->populate($id, $details);
                         if ($member->canAcquireLock()) {
                             $member->acquireLock();
                             $member->setValue('status', 'archived');
                             $member->save(FALSE);
                             $member->releaseLock();
                         } else {
                             $all_members_archived = FALSE;
                         }
                     }
                     if ($all_members_archived) {
                         $msg = 'The ' . count($members) . ' members of the family have also been archived';
                     } else {
                         $msg = 'Not all members of the family could be accordingly archived because another user holds the lock';
                     }
                 }
             } else {
                 if ($this->_old_values['status'] == 'archived') {
                     // Status has just been changed from archived to something else
                     $msg = 'NB Members of the family will need to be de-archived separately';
                 }
             }
         }
         if (!empty($this->_old_values['family_name'])) {
             // Family name has changed
             // We update all the members' last names to match if
             // (a) there is only one member, or
             // (b) all members' current last name = the old family name
             $members = $this->getMemberData();
             if (count($members) == 1) {
                 $member = $GLOBALS['system']->getDBObject('person', key($members));
                 if ($member->canAcquireLock()) {
                     $member->acquireLock();
                     $member->setValue('last_name', $this->getValue('family_name'));
                     $member->save(FALSE);
                     $member->releaseLock();
                     $msg = 'The last name of the family\'s one member has also been set to "' . $this->getValue('family_name') . '"';
                 } else {
                     $msg = 'The family\'s one member could not be updated accordingly because another user holds the lock';
                 }
             } else {
                 if (!empty($members)) {
                     $members_all_have_family_name = TRUE;
                     foreach ($members as $id => $member) {
                         if ($member['last_name'] != $this->_old_values['family_name']) {
                             $members_all_have_family_name = FALSE;
                             break;
                         }
                     }
                     if ($members_all_have_family_name) {
                         $all_members_updated = TRUE;
                         $GLOBALS['system']->includeDBClass('person');
                         $member = new Person();
                         foreach ($members as $id => $details) {
                             $member->populate($id, $details);
                             if ($member->canAcquireLock()) {
                                 $member->acquireLock();
                                 $member->setValue('last_name', $this->getValue('family_name'));
                                 $member->save(FALSE);
                                 $member->releaseLock();
                             } else {
                                 $all_members_updated = FALSE;
                             }
                         }
                         if ($all_members_updated) {
                             $msg = 'Each family member\'s last name has also been set to "' . $this->getValue('family_name') . '"';
                         } else {
                             $msg = 'Not all family members could be updated with the new last name because another user holds the lock';
                         }
                     } else {
                         $msg = 'Family members have not been updated because they already have different last names';
                     }
                 }
             }
         }
     }
     $res = parent::save();
     if ($msg) {
         add_message($msg);
     }
     return $res;
 }
 function processView()
 {
     $GLOBALS['system']->includeDBClass('family');
     $this->_family = new Family();
     if (array_get($_REQUEST, 'new_family_submitted')) {
         // some initial checks
         $i = 0;
         $found_member = FALSE;
         while (isset($_POST['members_' . $i . '_first_name'])) {
             if (!empty($_POST['members_' . $i . '_first_name'])) {
                 $found_member = TRUE;
             }
             $i++;
         }
         if (!$found_member) {
             add_message('New family must have at least one member', 'failure');
             return FALSE;
         }
         if ($GLOBALS['user_system']->havePerm(PERM_EDITNOTE)) {
             if (REQUIRE_INITIAL_NOTE && empty($_POST['initial_note_subject'])) {
                 add_message("A subject must be supplied for the initial family note", 'failure');
                 return FALSE;
             }
         }
         $GLOBALS['system']->doTransaction('begin');
         // Create the family record itself
         $this->_family->processForm();
         $success = $this->_family->create();
         if ($success) {
             // Add members
             $i = 0;
             $members = array();
             $GLOBALS['system']->includeDBClass('person');
             while (isset($_POST['members_' . $i . '_first_name'])) {
                 if (!empty($_POST['members_' . $i . '_first_name'])) {
                     $member = new Person();
                     $member->setValue('familyid', $this->_family->id);
                     $member->processForm('members_' . $i . '_');
                     if (!$member->create()) {
                         $success = FALSE;
                         break;
                     }
                     $members[] =& $member;
                 }
                 $i++;
             }
         }
         if ($success) {
             if ($GLOBALS['user_system']->havePerm(PERM_EDITNOTE)) {
                 if (REQUIRE_INITIAL_NOTE || !empty($_POST['initial_note_subject'])) {
                     // Add note
                     if (count($members) > 1) {
                         $GLOBALS['system']->includeDBClass('family_note');
                         $note = new Family_Note();
                         $note->setValue('familyid', $this->_family->id);
                     } else {
                         $GLOBALS['system']->includeDBClass('person_note');
                         $note = new Person_Note();
                         $note->setValue('personid', $members[0]->id);
                     }
                     $note->processForm('initial_note_');
                     $success = $note->create();
                 }
             }
             if (!empty($_POST['execute_plan'])) {
                 foreach ($_POST['execute_plan'] as $planid) {
                     $plan = $GLOBALS['system']->getDBObject('action_plan', $planid);
                     $plan->execute('family', $this->_family->id, process_widget('plan_reference_date', array('type' => 'date')));
                 }
             }
         }
         // Before committing, check for duplicates
         if (empty($_REQUEST['override_dup_check'])) {
             $this->_similar_families = $this->_family->findSimilarFamilies();
             if (!empty($this->_similar_families)) {
                 $GLOBALS['system']->doTransaction('rollback');
                 return;
             }
         }
         if ($success) {
             $GLOBALS['system']->doTransaction('commit');
             add_message('Family Created');
             redirect('families', array('familyid' => $this->_family->id));
         } else {
             $GLOBALS['system']->doTransaction('rollback');
             $this->_family->id = 0;
             add_message('Error during family creation, family not created', 'failure');
         }
     }
 }
    function processView()
    {
        $GLOBALS['system']->includeDBClass('family');
        $GLOBALS['system']->includeDBClass('person');
        $GLOBALS['system']->includeDBClass('person_group');
        $GLOBALS['system']->includeDBClass('congregation');
        $GLOBALS['system']->includeDBClass('person_note');
        if (!empty($_REQUEST['done'])) {
            $this->_stage = 'done';
        } else {
            if (!empty($_POST['confirm_import'])) {
                ini_set('memory_limit', '256M');
                ini_set('max_execution_time', 60 * 10);
                ini_set('zlib.output_compression', 'Off');
                // read from session and create
                $GLOBALS['system']->doTransaction('BEGIN');
                $group = $GLOBALS['system']->getDBObject('person_group', $_SESSION['import']['groupid']);
                $this->_captureErrors();
                $done = 0;
                ?>
			<h1 style="position: absolute; text-align: center; top: 40%; color: #ccc; width: 100%">Importing...</h1>
			<div style="border: 1px solid; width: 50%; height: 30px; top: 50%; left: 25%; position: absolute"><div id="progress" style="background: blue; height: 30px; width: 2%; overflow: visible; line-height: 30px; text-align: center; color: white" /></div>
			<p style="text-align: center; color: #888">If this indicator stops making progress, your import may still be running in the background.<br />You should <a href="<?php 
                echo build_url(array('view' => 'persons__list_all'));
                ?>
">check your system for the imported persons</a> before running the import again.</p>
			<?php 
                foreach ($_SESSION['import']['families'] as $familydata) {
                    $members = $familydata['members'];
                    unset($familydata['members']);
                    $family = new Family();
                    $family->populate(0, $familydata);
                    if ($family->create()) {
                        foreach ($members as $persondata) {
                            $notetext = null;
                            if (!empty($persondata['note'])) {
                                $notetext = $persondata['note'];
                                unset($persondata['note']);
                            }
                            $person = new Person();
                            $person->populate(0, $persondata);
                            $person->setValue('familyid', $family->id);
                            if ($person->create()) {
                                $group->addMember($person->id);
                                if ($notetext) {
                                    $note = new Person_Note();
                                    $note->setValue('subject', 'Import note');
                                    $note->setvalue('details', $notetext);
                                    $note->setValue('personid', $person->id);
                                    $note->create();
                                    unset($note);
                                }
                                unset($person);
                            }
                        }
                        $done++;
                        if ($done % 20 == 0) {
                            ?>
<script>var d = document.getElementById('progress'); d.innerHTML = 'Importing family <?php 
                            echo $done . ' of ' . $_SESSION['import']['total_families'];
                            ?>
'; d.style.width = '<?php 
                            echo (int) ($done / $_SESSION['import']['total_families'] * 100);
                            ?>
%'</script><?php 
                            echo str_repeat('    ', 1024 * 4);
                        }
                        flush();
                        unset($family);
                    }
                }
                if ($errors = $this->_getErrors()) {
                    $msg = 'Errors during import - import aborted. <ul><li>' . implode('</li></li>', $errors) . '</li></ul>';
                    add_message($msg, 'failure', true);
                    $GLOBALS['system']->doTransaction('ROLLBACK');
                } else {
                    add_message('Import complete', 'success');
                    $GLOBALS['system']->doTransaction('COMMIT');
                }
                ?>
<script>document.location = '<?php 
                echo build_url(array());
                ?>
&done=1';</script>
			<?php 
                exit;
            } else {
                if (!empty($_FILES['import'])) {
                    if (empty($_REQUEST['groupid'])) {
                        add_message("You must choose a group first", 'error');
                        $this->stage = 'begin';
                        return;
                    }
                    if (empty($_FILES['import']) || empty($_FILES['import']['tmp_name'])) {
                        add_message("You must upload a file", 'error');
                        return;
                    }
                    $this->_dummy_family = new Family();
                    $this->_dummy_person = new Person();
                    // read the csv and save to session
                    $fp = fopen($_FILES['import']['tmp_name'], 'r');
                    if (!$fp) {
                        add_message("There was a problem reading your CSV file.  Please try again.", 'error');
                        $this->stage = 'begin';
                        return;
                    }
                    $map = fgetcsv($fp, 0, ",", '"');
                    $_SESSION['import']['groupid'] = (int) $_POST['groupid'];
                    $_SESSION['import']['families'] = array();
                    $_SESSION['import']['total_families'] = 0;
                    $_SESSION['import']['total_persons'] = 0;
                    $_SESSION['import']['total_notes'] = 0;
                    $row_errors = array();
                    $family = NULL;
                    $i = 1;
                    while ($rawrow = fgetcsv($fp, 0, ",", '"')) {
                        $row = array();
                        foreach ($map as $index => $fieldname) {
                            $row[$fieldname] = array_get($rawrow, $index);
                        }
                        if ($this->_isEmptyRow($row)) {
                            // Blank row = start a new family for the next row
                            unset($family);
                            continue;
                        }
                        if (!isset($family) || $this->_isNewFamily($row, $family)) {
                            // Add family
                            $this->_dummy_family->values = array();
                            $this->_dummy_family->setValue('status', 'current');
                            $this->_captureErrors();
                            $familyrow = $row;
                            unset($familyrow['status']);
                            $this->_dummy_family->fromCsvRow($familyrow);
                            if ($errors = $this->_getErrors()) {
                                $row_errors[$i] = $errors;
                            } else {
                                $_SESSION['import']['families'][] = $this->_dummy_family->values;
                                $family =& $_SESSION['import']['families'][count($_SESSION['import']['families']) - 1];
                                $_SESSION['import']['total_families']++;
                            }
                        } else {
                            // see if there's anything to update
                            // eg if the second family member has a home tel
                            foreach ($family as $fi => $fv) {
                                if ($family[$fi] === '' && $row[$fi] !== '') {
                                    $family[$fi] = $row[$fi];
                                }
                            }
                        }
                        $this->_captureErrors();
                        // Add a person and note
                        $this->_dummy_person->values = array();
                        $this->_dummy_person->setValue('familyid', '-1');
                        if (!empty($row['congregation'])) {
                            $row['congregationid'] = Congregation::findByName($row['congregation']);
                        }
                        $this->_dummy_person->fromCsvRow($row);
                        if ($errors = $this->_getErrors()) {
                            $row_errors[$i] = array_merge(array_get($row_errors, $i, array()), $errors);
                        } else {
                            $member = $this->_dummy_person->values + array('congregation' => $this->_dummy_person->getFormattedValue('congregationid'));
                            if (!empty($row['note'])) {
                                $member['note'] = $row['note'];
                                $_SESSION['import']['total_notes']++;
                            }
                            $family['members'][] = $member;
                            $_SESSION['import']['total_persons']++;
                        }
                        $i++;
                    }
                    if (!empty($row_errors)) {
                        $msg = 'Your import file is not valid.  Please correct the following errors and try again:<ul>';
                        foreach ($row_errors as $line => $errors) {
                            $msg .= '<li>Row ' . ($line + 1) . ': ' . implode('; ', $errors) . '</li>';
                        }
                        $msg .= '</ul>';
                        add_message($msg, 'failure', true);
                        $this->_stage = 'begin';
                    } else {
                        $this->_stage = 'confirm';
                    }
                }
            }
        }
    }
    ?>
?view=_edit_group&action=remove_members&groupid=<?php 
    echo $groupid;
    ?>
" />
		</span>
		
		
		<div class="bulk-action well" id="update-field">
			<table class="valign-middle">
			<?php 
    $dummy = new Person();
    foreach (array('congregationid', 'status', 'age_bracket') as $field) {
        $dummy->fields[$field]['allow_empty'] = TRUE;
        $dummy->fields[$field]['empty_text'] = '(No change)';
        $dummy->setValue($field, NULL);
        echo '<tr><td>Set ' . $dummy->getFieldLabel($field) . ' to: </td><td>';
        $dummy->printFieldInterface($field);
        echo '</td></tr>';
    }
    $customFields = $GLOBALS['system']->getDBObjectData('custom_field', array(), 'OR', 'rank');
    $dummy = new Custom_Field();
    $addParams = array('type' => 'select', 'options' => array('Replacing existing values ', 'Adding to existing values'));
    foreach ($customFields as $fieldid => $fieldDetails) {
        $dummy->populate($fieldid, $fieldDetails);
        echo '<tr><td>Set ' . ents($dummy->getValue('name')) . ' to: </td><td>';
        $dummy->printWidget('');
        if ($dummy->getValue('allow_multiple')) {
            echo '</td><td>';
            print_widget('custom_' . $fieldid . '_add', $addParams, 0);
        }
Esempio n. 6
0
    function printForm()
    {
        $GLOBALS['system']->includeDBClass('person_group');
        $actions = $this->getValue('actions');
        $notes = array_get($actions, 'notes');
        if (empty($notes)) {
            $notes = array(array());
            // 1 blank note to start us off
        }
        ?>
		<table class="action-plan">
			<tbody>
				<tr>
					<th>Name</th>
					<td><?php 
        $this->printFieldInterface('name');
        ?>
</td>
				</tr>
				<tr>
					<th>Notes</th>
					<td>
						When this plan is executed, add these notes to the person/family:
						<table class="expandable">
						<?php 
        foreach ($notes as $i => $note) {
            ?>
							<tr>
								<td>
									<div class="well">
									<?php 
            $this->_printNoteForm($note, $i);
            ?>
									</div>
								</td>
							</tr>
							<?php 
        }
        ?>
						</table>
					</td>
				</tr>
				<tr>
					<th>Groups</th>
					<td>
						When this plan is executed, <b>add</b> the persons / famiy members to these groups:
						<?php 
        Person_Group::printMultiChooser('groups', array_get($actions, 'groups', array()), array(), FALSE);
        ?>
					</td>
				</tr>
				<tr>
					<th></th>
					<td>
						When this plan is executed, <b>remove</b> the persons / famiy members from these groups:
						<?php 
        Person_Group::printMultiChooser('groups_remove', array_get($actions, 'groups_remove', array()), array(), FALSE);
        ?>
					</td>
				</tr>
				<tr>
					<th>Fields</th>
					<td>
						When this plan is executed, for each person / family member:
						<table class="fields">
						<?php 
        $fields = array_get($actions, 'fields', array());
        $dummy = new Person();
        foreach (array('congregationid', 'status', 'age_bracket') as $field) {
            $value = '';
            $addToExisting = FALSE;
            $v = array_get($fields, $field);
            if ($v) {
                $value = $v['value'];
                $addToExisting = $v['add'];
            }
            $dummy->fields[$field]['allow_empty'] = TRUE;
            $dummy->fields[$field]['empty_text'] = '(No change)';
            if (strlen($value)) {
                $dummy->setValue($field, $value);
            }
            echo '<tr><td>';
            print_widget('fields_enabled[' . $field . ']', array('type' => 'checkbox'), strlen($value));
            echo 'Set ' . $dummy->getFieldLabel($field) . ' </td><td>';
            $dummy->printFieldInterface($field);
            echo '</td></tr>';
        }
        $customFields = $GLOBALS['system']->getDBObjectData('custom_field', array(), 'OR', 'rank');
        $dummy = new Custom_Field();
        $addParams = array('type' => 'select', 'options' => array('Replacing existing values ', 'Adding to existing values'));
        foreach ($customFields as $fieldid => $fieldDetails) {
            $value = '';
            $addToExisting = FALSE;
            $v = array_get($fields, 'custom_' . $fieldid);
            if ($v) {
                $value = $v['value'];
                $addToExisting = $v['add'];
            }
            $dummy->populate($fieldid, $fieldDetails);
            echo '<tr><td>';
            print_widget('fields_enabled[custom_' . $fieldid . ']', array('type' => 'checkbox'), strlen($value));
            echo 'Set ' . ents($dummy->getValue('name')) . '&nbsp;</td><td>';
            if ($fieldDetails['type'] == 'date') {
                // For now, we only support setting date fields to the reference date.
                // But there is room for future expansion to support fixed dates too.
                $dateVal = $noteVal = '';
                if (strlen($value)) {
                    list($dateVal, $noteVal) = explode('===', $value);
                }
                echo 'to the reference date, with note ';
                print_widget('custom_' . $fieldid . '_note', array('type' => 'text'), $noteVal);
            } else {
                $dummy->printWidget($value);
            }
            if ($dummy->getValue('allow_multiple')) {
                print_widget('fields_addvalue[custom_' . $fieldid . ']', $addParams, $addToExisting);
            }
            echo '</td></tr>';
        }
        ?>
						</table>
					</td>
				</tr>
				<tr>
					<th>Attendance</th>
					<td>
						<input type="hidden" name="mark_present" value="0" />
						<label class="checkbox">
							<input type="checkbox" id="mark_present" name="mark_present" value="1" <?php 
        if (array_get($actions, 'attendance')) {
            echo 'checked="checked"';
        }
        ?>
>
							When this plan is executed, mark the persons / family members as present at their congregation for the most recent attendance date
						</label>
						<p><small>This will only have effect if they are in a congregation. They will be marked present for the most recent date on which attendance has been recorded for that congregation.</small></p>
					</td>
				</tr>
				<tr>
					<th>Options</th>
					<td>
						
						<input type="hidden" name="default_on_create_family" value="0" />
						<label class="checkbox">
							<input type="checkbox" id="default_on_create_family" name="default_on_create_family" value="1" <?php 
        if ($this->getValue('default_on_create_family')) {
            echo 'checked="checked"';
        }
        ?>
>
							By default, execute this plan when creating a new family
						</label>

						<input type="hidden" name="default_on_add_person" value="0" />
						<label class="checkbox">
							<input type="checkbox" id="default_on_add_person" name="default_on_add_person" value="1" <?php 
        if ($this->getValue('default_on_add_person')) {
            echo 'checked="checked"';
        }
        ?>
>
							By default, execute this plan when adding a new person to an existing family
						</label>
					</td>
				</tr>
			</tbody>
		</table>
		<script>
		$('form').submit(function() {
			var ok = true;
			$('.note').each(function() {
				var t = $(this);
				if ((t.find('textarea:first').val() != '') && (t.find('input[name$="_subject"]').val() == '')) {
					t.find('input[name$="_subject"]').select();
					alert("All notes to be added must include a subject");
					ok = false;
				}
				if (!ok) return false;
				if (t.find('input[type=radio][value=relative]').attr('checked') && t.find('input[name$=action_date_offset]').val() == '') {
					t.find('input[name$=action_date_offset]').focus();
					alert("If a relative action date is selected you must specify a number of days");
					ok = false;
				}
			});
			return ok;
		});
		</script>
		<?php 
    }
Esempio n. 7
0
}
$a = array();
for ($i = 0; $i <= 5; $i++) {
    $var2 = new stdClass();
    $var2->value = $i;
    $var2->{"position" . $i} = 'position at ' . $i;
    $a[$i] = $var2;
}
for ($i = 0; $i <= 5; $i++) {
    echo $a[$i]->{"position" . $i};
    echo $a[$i]->value;
}
function test(&$intVal)
{
    static $i = 0;
    $i += $intVal;
    $intVal++;
    return $i;
}
$a = 5;
$b = 0;
for ($m = $a; $m < 10; $m++) {
    $b += test($a);
}
echo "<br/>";
echo $a;
echo "<br/>";
echo $b;
$tim = new Person();
$tim->setValue("Tim", "Smith");
echo $tim->getValue();
    function printView()
    {
        if (empty($this->_record_sets)) {
            // STEP 1 - choose congregation and date
            ?>
			<form method="get" class="well well-small clearfix">
				<input type="hidden" name="view" value="<?php 
            echo $_REQUEST['view'];
            ?>
" />
				<table class="attendance-config-table valign-middle">
					<tr>
						<th>For</th>
						<td colspan="2" class="fill-me">
							<?php 
            print_widget('age_bracket', array('type' => 'select', 'options' => array('' => 'All age brackets') + explode(',', AGE_BRACKET_OPTIONS), 'default' => '', 'allow_empty' => false), $this->_age_bracket);
            ?>
						</td>
					</tr>
					<tr>
						<th rowspan="2">In</th>
						<td class="valign-top">
							<label class="radio">
								<input type="radio" name="for_type" 
									value="congregationid" id="for_type_congregation" 
									data-toggle="enable" data-target="#congregationchooser select"
									<?php 
            if (empty($this->_groupid)) {
                echo 'checked="checked"';
            }
            ?>
								>
								Congregation(s) &nbsp;
							</label>
						</td>
						<td class="fill-me">
							<table id="congregationchooser" class="expandable table-condensed no-padding" cellspacing="0">
						<?php 
            $congs = $this->_congregationids ? $this->_congregationids : array(0);
            foreach ($congs as $congid) {
                ?>
							<tr>
								<td>
								<?php 
                print_widget('congregationid[]', array('type' => 'reference', 'references' => 'congregation', 'order_by' => 'name', 'allow_empty' => true, 'empty_text' => '-- Choose --'), $congid);
                ?>
								</td>
							</tr>
							<?php 
            }
            ?>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<label class="radio">
								<input type="radio" name="for_type" 
									value="groupid" id="for_type_group"
									data-toggle="enable" data-target="#groupchooser select" 
									<?php 
            if (!empty($this->_groupid)) {
                echo 'checked="checked"';
            }
            ?>
								>
								Group
							</label>
						</td>
						<td class="fill-me" id="groupchooser">
							<?php 
            print_widget('groupid', array('type' => 'reference', 'references' => 'person_group', 'filter' => array('can_record_attendance' => '1', 'is_archived' => 0)), $this->_groupid);
            ?>
						</td>
					</tr>
					<tr>
						<th>On</th>
						<td colspan="2">
							<?php 
            print_widget('attendance_date', array('type' => 'date'), $this->_attendance_date);
            ?>
						</td>
					</tr>
				<?php 
            if ($GLOBALS['system']->featureEnabled('PHOTOS')) {
                ?>
					<tr>
						<th></th>
						<td>
							<label class="checkbox">
								<input type="checkbox" name="show_photos" value="1" <?php 
                if ($this->_show_photos) {
                    echo 'checked="checked"';
                }
                ?>
 />
								Show photos
							</label>
						</td>
					</tr>
					<?php 
            }
            ?>
				</table>
				<button type="submit" class="btn attendance-config-submit">Continue <i class="icon-chevron-right"></i></button>
				<input type="hidden" name="params_submitted" value="1" />
			</form>
			<?php 
        } else {
            if (empty($_POST['attendances_submitted'])) {
                $_SESSION['enter_attendance_token'] = md5(time());
                // STEP 2 - enter attendances
                ob_start();
                ?>
			<form method="post" class="attendance warn-unsaved" action="?view=attendance__record">
				<input type="hidden" name="for_type" value="<?php 
                echo ents($_REQUEST['for_type']);
                ?>
" />
				<input type="hidden" name="attendance_date" value="<?php 
                echo $this->_attendance_date;
                ?>
" />
				<input type="hidden" name="age_bracket" value="<?php 
                echo $this->_age_bracket;
                ?>
" />
				<input type="hidden" name="show_photos" value="<?php 
                echo $this->_show_photos;
                ?>
" />
				<input type="hidden" name="enter_attendance_token" value="<?php 
                echo $_SESSION['enter_attendance_token'];
                ?>
" />
				<input type="hidden" name="attendances_submitted" value="1" />

				<p class="visible-desktop smallprint">For greatest speed, press P for present and A for absent.  The cursor will automatically progress to the next person.  To go back, use the arrow keys.</p>
				<?php 
                $totalPrinted = 0;
                foreach ($this->_record_sets as $i => $set) {
                    if ((int) $set->congregationid) {
                        ?>
						<input type="hidden" name="congregationid[]" value="<?php 
                        echo $set->congregationid;
                        ?>
" />
						<?php 
                        $congregation = $GLOBALS['system']->getDBObject('congregation', (int) $set->congregationid);
                        $title = $congregation->getValue('name') . ' Congregation';
                    } else {
                        if ($set->groupid) {
                            $group =& $GLOBALS['system']->getDBObject('person_group', $set->groupid);
                            $title = $group->getValue('name') . ' Group';
                            ?>
						<input type="hidden" name="groupid" value="<?php 
                            echo $set->groupid;
                            ?>
" />
						<?php 
                        } else {
                            return;
                        }
                    }
                    if (strlen($set->age_bracket)) {
                        $GLOBALS['system']->includeDBClass('person');
                        $p = new Person();
                        $p->setValue('age_bracket', $set->age_bracket);
                        $title = $p->getFormattedValue('age_bracket') . ' in ' . $title;
                    }
                    ?>
					<h3><?php 
                    echo ents($title);
                    ?>
</h3>
					<div class="width-really-auto form-inline">
						<?php 
                    $setPrinted = $set->printForm($i);
                    if ($setPrinted > 0) {
                        $totalPrinted += $setPrinted;
                        if ((int) $set->congregationid) {
                            $headcountFieldName = 'headcount[congregation][' . $set->congregationid . ']';
                            $headcountValue = Headcount::fetch('congregation', $this->_attendance_date, $set->congregationid);
                        } else {
                            $headcountFieldName = 'headcount[group][' . $set->groupid . ']';
                            $headcountValue = Headcount::fetch('person_group', $this->_attendance_date, $set->groupid);
                        }
                        ?>
							<div class="container row-fluid control-group">
								<p class="span6">
									Total headcount:
									<input type="text" class="int-box" name="<?php 
                        echo $headcountFieldName;
                        ?>
" value="<?php 
                        echo $headcountValue;
                        ?>
" size="5" />
								</p>
								<p class="span6 align-right nowrap">
									<input type="submit" class="btn" value="Save All Attendances" />
									<a href="?view=attendance__record" class="btn">Cancel</a>
								</p>
							</div>
							<?php 
                    } else {
                        ?>
							<i>(No persons in this listing)</i>
							<?php 
                    }
                    ?>
					</div>
					<?php 
                }
                ?>
			</form>
			<?php 
                if (ini_get('max_input_vars') && $totalPrinted > ini_get('max_input_vars')) {
                    ob_end_clean();
                    print_message("The parameters you have selected will list more persons " . "than your server can process.  Please narrow down your parameters, " . "or ask your server administrator to increase the PHP max_input_vars setting" . " (currently " . ini_get('max_input_vars') . ')', 'error');
                } else {
                    ob_flush();
                }
            } else {
                // STEP 3 - confirmation
                foreach ($this->_record_sets as $set) {
                    if ($set->congregationid) {
                        $congregation = $GLOBALS['system']->getDBObject('congregation', (int) $set->congregationid);
                        $title = $congregation->getValue('name') . ' congregation';
                    } else {
                        $group =& $GLOBALS['system']->getDBObject('person_group', $set->groupid);
                        $title = $group->getValue('name') . ' group';
                    }
                    echo '<h3>' . $title . '</h3>';
                    $set->printStats();
                }
                ?>
			<p><a href="?view=<?php 
                echo $_REQUEST['view'];
                ?>
"><i class="icon-pencil"></i>Record more attendances</a></p>
			<p><a href="?view=persons__reports"><i class="icon-list"></i>Analyse attendance using a person report</a></p>
			<?php 
            }
        }
    }