Example #1
0
 function printFieldInterface($name, $prefix = '')
 {
     if ($name == 'volunteer_group' && (empty($this->id) || $this->haveLock())) {
         $GLOBALS['system']->includeDBClass('person_group');
         $value = array_get($this->values, $name);
         Person_Group::printChooser($prefix . $name, $value, array(), null, '(None)');
     } else {
         parent::printFieldInterface($name, $prefix);
     }
 }
    function printView()
    {
        ?>
		<div class="member-homepage-box">
			<h3>
				<a class="pull-right" href="?view=_edit_me"><small>Edit</small></a>
				My Family
			</h3>
			<?php 
        $family = $GLOBALS['system']->getDBObject('family', $GLOBALS['member_user_system']->getCurrentMember('familyid'));
        unset($family->fields['status']);
        $family->printCustomSummary(array($this, 'printFamilyMembers'));
        ?>
		</div>

		<?php 
        if ($GLOBALS['system']->featureEnabled('ROSTERS&SERVICES')) {
            ?>
			<div class="member-homepage-box">
			<h3>
				<a class="pull-right" href="?view=_edit_ical"><small>Subscribe</small></a>
				My Roster Allocations &nbsp;
			</h3>
			<?php 
            $GLOBALS['system']->includeDBClass('roster_role_assignment');
            $rallocs = Roster_Role_Assignment::getUpcomingAssignments($GLOBALS['member_user_system']->getCurrentMember('id'), NULL);
            if ($rallocs) {
                ?>
				<table class="table table-auto-width">
				<?php 
                foreach ($rallocs as $date => $allocs) {
                    ?>
					 <tr>
						 <th><?php 
                    echo date('j M', strtotime($date));
                    ?>
</th>
						 <td>
							<?php 
                    foreach ($allocs as $alloc) {
                        echo $alloc['cong'] . ' ' . $alloc['title'] . '<br />';
                    }
                    ?>
						 </td>
					 </tr>
					 <?php 
                }
                ?>
				</table>
				<?php 
            } else {
                ?>
				<p><i>None</i></p>
				<?php 
            }
            ?>
			</div>
			<?php 
        }
        $GLOBALS['system']->includeDBClass('person_group');
        $groups = Person_Group::getGroups($GLOBALS['member_user_system']->getCurrentMember('id'), FALSE, TRUE);
        if (count($groups) > 1) {
            echo '<div  class="member-homepage-box" >';
            echo '<h3>My Groups</h3>';
            echo '<ul>';
            foreach ($groups as $id => $details) {
                echo '<li><a href="?view=_groups&groupid=' . (int) $id . '">' . ents($details['name']) . '</a></li>';
            }
            echo '</ul>';
            echo '</div>';
        }
    }
 /**
  * Get the options for filtering people by (person or group-membership) status
  * @return array
  */
 public static function getStatusOptions()
 {
     $statusOptions = array();
     foreach (Person::getStatusOptions() as $id => $val) {
         $statusOptions['p-' . $id] = $val;
     }
     list($gOptions, $default) = Person_Group::getMembershipStatusOptionsAndDefault();
     foreach ($gOptions as $id => $val) {
         $statusOptions['g-' . $id] = $val;
     }
     return $statusOptions;
 }
</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 
        $gstr = '';
        foreach (Person_Group::getGroups($id) as $gid => $gdetail) {
            if (strlen($gstr)) {
                $gstr .= ', ';
            }
            $gstr = $gstr . $gdetail['name'];
        }
        if (strlen($gstr)) {
            ?>
							<a title="<?php 
            echo ents($gstr);
            ?>
" href="?view=persons&personid=<?php 
            echo $id;
            ?>
#groups">	
								<?php 
    function printForm()
    {
        $dummy_person = new Person();
        $dummy_person->fields['congregationid']['allow_multiple'] = true;
        $dummy_person->fields['age_bracket']['allow_multiple'] = true;
        ?>
		<form method="get">
		<input type="hidden" name="view" value="<?php 
        echo ents($_REQUEST['view']);
        ?>
" />
		<table>
			<tr>
				<th>Opt-in group</th>
				<td><?php 
        Person_Group::printChooser('groupid', 0);
        ?>
</td>
			</tr>
			<tr>
				<th>Congregation</th>
				<td>Only include opted-in persons from<br />
				<?php 
        $dummy_person->printFieldInterface('congregationid');
        ?>
</td>
			</tr>
			<tr>
				<th>Age brackets</th>
				<td>Only show contact details for persons who are<br />
				<?php 
        $dummy_person->printFieldInterface('age_bracket');
        ?>
				</td>
			</tr>
			<tr>
				<th>Other family members</th>
				<td>For other members of the families of persons who opted in, show<br />
				<label class="radio">
					<input type="radio" name="all_member_details" value="0" checked="checked" id="all_member_details_0" />
					only their names
				</label>
				<label class="radio">
					<input type="radio" name="all_member_details" value="1" id="all_member_details_1" />
					their contact details, same as for opted-in persons
				</label>
			</tr>
			<tr>
					<th>Addresses</th>
					<td>
						<label class="checkbox">
							<input type="checkbox" name="include_address" />
							Include home addresses in results
						</label>
					</td>
			</tr>
			<tr>
				<th></th>
				<td><input type="submit" name="go" value="Go" /></td>
			</tr>
		</table>
		</form>
		<?php 
    }
    public function printView()
    {
        ?>
		<p>Some of the following settings can be edited on this page.  Other settings are read only on this page, but can be adjusted by getting your 
		<?php 
        if (defined('SYSADMIN_HREF')) {
            echo '<a href="' . SYSADMIN_HREF . '">';
        }
        ?>
		system administrator
		<?php 
        if (defined('SYSADMIN_HREF')) {
            echo '</a>';
        }
        ?>
		to edit the Jethro configuration file.</p>
		<table class="table no-autofocus system-config">
			<tr>
				<td colspan="2"><h3>Overall system settings</h3></td>
			</tr>
			<tr>
				<th>System Name</th>
				<td><?php 
        echo SYSTEM_NAME;
        ?>
</td>
			</tr>
			<tr>
				<th>Base URL</th>
				<td><?php 
        echo BASE_URL;
        ?>
</td>
			</tr>
			<tr>
				<th>Require HTTPS</th>
				<td><?php 
        echo REQUIRE_HTTPS ? 'Yes' : 'No';
        ?>
</td>
			</tr>
			<tr>
				<td colspan="2"><h3>Jethro behaviour settings</h3></td>
			</tr>
			<tr>
				<th>Enabled Features</th>
				<td>
					<?php 
        $enabled = explode(',', ENABLED_FEATURES);
        foreach (explode(',', 'NOTES,PHOTOS,DATES,ATTENDANCE,ROSTERS&SERVICES,SERVICEDETAILS,DOCUMENTS,SERVICEDOCUMENTS') as $feature) {
            echo '<i class="icon-' . (in_array($feature, $enabled) ? 'ok-sign' : 'ban-circle') . '"></i>' . $feature . '<br />';
        }
        ?>
				</td>
			</tr>
			<tr>
				<th>Require note when adding new family?</th>
				<td><?php 
        echo REQUIRE_INITIAL_NOTE ? 'Yes' : 'No';
        ?>
</td>
			</tr>
			<tr>
				<th>Attendance list order</th>
				<td><?php 
        echo ATTENDANCE_LIST_ORDER;
        ?>
					<br /><small>When recording attendance, persons will be listed in this order</small>
				</td>
			</tr>
			<tr>
				<th>Chunk size for listings</th>
				<td>
					<?php 
        echo CHUNK_SIZE;
        ?>
					<br /><small>When listing all persons or families, Jethro will paginate the results and aim for this number per page (up to a maximum of 26 pages).</small>
				
				</td>
			</tr>			
			<tr>
				<th>Lock length for editing objects</th>
				<td><?php 
        echo LOCK_LENGTH;
        ?>
					<br /><small>When you open an object for editing, Jethro will prevent other users from editing the object for this long.  You will need to save your changes within this timeframe.</small>
				</td>
			</tr>

			<tr>
				<td colspan="2"><h3>Security settings</h3></td>
			</tr>
			<tr>
				<th>Default Permissions</th>
				<td>
				<?php 
        $GLOBALS['system']->includeDBClass('staff_member');
        $sm = new Staff_Member();
        $sm->printFieldValue('permissions', DEFAULT_PERMISSIONS);
        ?>
				</td>
			</tr>
			<tr>
				<th>Session Inactivity Timeout</th>
				<td>
					<?php 
        echo defined('SESSION_TIMEOUT_MINS') && SESSION_TIMEOUT_MINS > 0 ? SESSION_TIMEOUT_MINS : 90;
        ?>
mins
					<br /><small>Users will be asked to log in again if they haven't done anything for this length of time.  This is important for security, especially on mobile devices.</small>
				</td>
			</tr>
			<tr>
				<th>Maximum Session Length</th>
				<td>
					<?php 
        $val = defined('SESSION_MAXLENGTH_MINS') && SESSION_MAXLENGTH_MINS > 0 ? SESSION_MAXLENGTH_MINS : 8 * 60;
        if ($val % 60 == 0 && $val > 60) {
            echo $val / 60 . ' hours';
        } else {
            echo $val . ' mins';
        }
        ?>
					<br /><small>Active users will be asked to log in again after this length of time.  This is important for security, especially on mobile devices.</small>
				</td>
			</tr>			
			<tr>
				<td colspan="2"><h3>Jethro data structure settings</h3></td>
			</tr>
			<tr>
				<th>Person Status Options</th>
				<td><?php 
        echo PERSON_STATUS_OPTIONS;
        ?>
 (Default <?php 
        echo PERSON_STATUS_DEFAULT;
        ?>
)</td>
			</tr>
			<tr>
				<th>Age Bracket Options</th>
				<td>
					<?php 
        echo AGE_BRACKET_OPTIONS;
        ?>
					<br /><small>This list must always begin with 'adult'</small>
				</td>
			</tr>
			<tr>
				<th>Group Membership Status Options</th>
				<td>
					<form method="post">
					<input type="hidden" name="group_membership_statuses_submitted" value="1" />
					<table class="table-condensed expandable table-bordered table-auto-width">
						<thead>
							<tr>
								<th>ID</th>
								<th>Label</th>
								<th>Default?</th>
								<th>Re-order</th>
								<th>Delete?</th>
							</tr>
						</thead>
						<tbody>
					<?php 
        $GLOBALS['system']->includeDBClass('person_group');
        list($options, $default) = Person_Group::getMembershipStatusOptionsAndDefault();
        $options[null] = '';
        $i = 0;
        foreach ($options as $id => $label) {
            ?>
						<tr>
							<td>
								<?php 
            if ($id) {
                echo $id;
                echo '<input type="hidden" name="membership_status_' . $i . '_id" value="' . $id . '" />';
            }
            echo '<input type="hidden" name="membership_status_ranking[]" value="' . $i . '" />';
            ?>
							</td>
							<td><input type="text" name="membership_status_<?php 
            echo $i;
            ?>
_label" value="<?php 
            echo ents($label);
            ?>
" /></td>
							<td><input type="radio" name="membership_status_default_rank" value="<?php 
            echo $i;
            ?>
" <?php 
            if ($id == $default) {
                echo 'checked="checked"';
            }
            ?>
 /></td>
							<td>
								<img src="<?php 
            echo BASE_URL;
            ?>
/resources/img/arrow_up_thin_black.png" class="icon move-row-up" title="Move this role up" />
								<img src="<?php 
            echo BASE_URL;
            ?>
/resources/img/arrow_down_thin_black.png" class="icon move-row-down" title="Move this role down" />
							</td>
							<td>
								<?php 
            if ($id) {
                ?>
									<input type="checkbox" name="membership_status_delete[]" data-toggle="strikethrough" data-target="row" value="<?php 
                echo $id;
                ?>
" />
									<?php 
            }
            ?>
							</td>

						</tr>
						<?php 
            $i++;
        }
        ?>
					</table>
					<input type="submit" value="Save" class="btn" />
					</form>
				</td>
			</tr>
			<tr>
				<td colspan="2"><h3>Rosters and Services</h3></td>
			</tr>
			<tr>
				<th>Roster Weeks Default</th>
				<td>
					<?php 
        echo ROSTER_WEEKS_DEFAULT;
        ?>
					<br /><small>By default, rosters will display this number of weeks in the future.</small>
				</td>
			</tr>
			<tr>
				<th>Roster repeat date threshold</th>
				<td>
					<?php 
        echo REPEAT_DATE_THRESHOLD;
        ?>
					<br /><small>If a roster has more than this number of columns, the date column will be repeated on the right hand side</small>
				</td>
			</tr>
			<tr>
				<th>Service Documents: Folders to populate</th>
				<td>
					<?php 
        if (SERVICE_DOCS_TO_POPULATE_DIRS) {
            echo implode('<br />', explode('|', SERVICE_DOCS_TO_POPULATE_DIRS));
        }
        ?>
				</td>
			</tr>
			<tr>
				<th>Service Documents: Folders to expand</th>
				<td>
					<?php 
        if (SERVICE_DOCS_TO_EXPAND_DIRS) {
            echo implode('<br />', explode('|', SERVICE_DOCS_TO_POPULATE_DIRS));
        }
        ?>
				</td>
			</tr>

			<tr>
				<td colspan="2"><h3>External tools</h3></td>
			</tr>
			<tr>
				<th>Bible reference URL</th>
				<td>
					<?php 
        echo BIBLE_URL;
        ?>
					<br /><small>Bible references in rosters will be linked using this URL template</small>
				</td>
			</tr>
			<tr>
				<th>Maps URL</th>
				<td>
					<?php 
        echo MAP_LOOKUP_URL;
        ?>
					<br /><small>The "map" link displayed next to a family's address uses this URL template</small>
				</td>
			</tr>
			<tr>
				<th>Email chunk size</th>
				<td>
					<?php 
        echo EMAIL_CHUNK_SIZE;
        ?>
					<br /><small>Email servers can only handle a limited number of recipients per email.  When constructing email links to multiple persons, Jethro will divide the list into several links if there are more than this number of recipients.</small>
				</td>
			</tr>
			<tr>
				<th>SMS Gateway</th>
				<td>
					<?php 
        echo SMS_HTTP_URL;
        ?>
<br />
					<?php 
        echo SMS_HTTP_POST_TEMPLATE && SMS_HTTP_RESPONSE_OK_REGEX ? 'See details in config file' : '<b>Not fully configured<b>';
        ?>
			</tr>
			<tr>
				<th>Max length for SMS messages</th>
				<td>
					<?php 
        echo SMS_MAX_LENGTH;
        ?>
					<br /><small>160 characters is generally a one-part SMS. Longer messages will be sent in several parts and will cost more.</small>
				</td>
			</tr>
			<tr>
				<th>Logging of SMS sending</th>
				<td>
					<?php 
        echo SMS_SEND_LOGFILE ? 'Configured' : 'Not configured';
        ?>
					<br /><small>This allows you to track how many SMSes each user is sending via Jethro.</small>
				</td>
			</tr>
			<tr>
				<td colspan="2"><h3>Locale settings</h3></td>
			</tr>

			<tr>
				<th>Timezone</th>
				<td><?php 
        echo defined('TIMEZONE') ? TIMEZONE : '(Server default)';
        ?>
</td>
			</tr>
			<tr>
				<th>Label for the Address 'suburb' field</th>
				<td><?php 
        echo defined('ADDRESS_SUBURB_LABEL') ? ADDRESS_SUBURB_LABEL : 'Suburb';
        ?>
</td>
			</tr>
			<tr>
				<th>Label for the address 'state' field</th>
				<td>
					<?php 
        if (!defined('ADDRESS_STATE_LABEL')) {
            echo 'State';
        } else {
            if (ADDRESS_STATE_LABEL) {
                echo ADDRESS_STATE_LABEL;
            } else {
                echo '(State field disabled)';
            }
        }
        echo '<br /><small>The state field can be hidden altogether by setting this to blank</small>';
        ?>
				</td>
			</tr>
			<tr>
				<th>Options for the Address 'state' field</th>
				<td><?php 
        echo ADDRESS_STATE_OPTIONS;
        ?>
  (Default: <?php 
        echo ADDRESS_STATE_DEFAULT;
        ?>
)</td>
			</tr>
			<tr>
				<th>Label for the address 'postcode' field</th>
				<td><?php 
        echo defined('ADDRESS_POSTCODE_LABEL') ? ADDRESS_POSTCODE_LABEL : 'Postcode';
        ?>
</td>
			</tr>
			<tr>
				<th>Valid formats for the address 'postcode' field</th>
				<td><?php 
        echo ADDRESS_POSTCODE_WIDTH . ' characters matching the expression ' . ADDRESS_POSTCODE_REGEX;
        ?>
</td>
			</tr>
			<tr>
				<th>Postcode lookup URL</th>
				<td>
					<?php 
        echo POSTCODE_LOOKUP_URL;
        ?>
					<br /><small>When editing an address, the "look up <?php 
        echo defined('ADDRESS_POSTCODE_LABEL') ? ADDRESS_POSTCODE_LABEL : 'postcode';
        ?>
" link uses this URL</small>
				</td>
			</tr>
			<tr>
				<th>Envelope Size</th>
				<td><?php 
        echo ENVELOPE_WIDTH_MM . 'mm x ' . ENVELOPE_HEIGHT_MM . 'mm';
        ?>
</td>
			</tr>


			<tr>
				<th>Formats for the home phone field</th>
				<td>
					<?php 
        echo nl2br(HOME_TEL_FORMATS);
        ?>
					<br /><small>When a phone number is displayed, it is laid out using these formats. When a phone number is entered, Jethro makes sure it has the right number of digits to match one of these formats.</small>
				</td>
			</tr>
			<tr>
				<th>Formats for the work phone field</th>
				<td><?php 
        echo nl2br(HOME_TEL_FORMATS);
        ?>
</td>
			</tr>
			<tr>
				<th>Formats for the mobile phone field</th>
				<td><?php 
        echo nl2br(MOBILE_TEL_FORMATS);
        ?>
</td>
			</tr>



		</table>
		<?php 
    }
 function _processObjectEditing()
 {
     $mod_count = 0;
     $processed = FALSE;
     switch (array_get($_REQUEST, 'action')) {
         case 'add_member':
         case 'add_members':
             $personids = array_get($_POST, 'personid', array());
             list($status_options, $default_status) = Person_Group::getMembershipStatusOptionsAndDefault();
             $mstatus = array_get($_POST, 'membership_status', $default_status);
             // When moving from an old group to this one, the magic membership status _PRESERVE_
             // means we should look up their status in the old group and use that status in the new group.
             if (!empty($_POST['remove_from_groupid'])) {
                 $old_group = $GLOBALS['system']->getDBObject('person_group', (int) $_POST['remove_from_groupid']);
                 if ($mstatus == '_PRESERVE_') {
                     $old_memberships = $old_group->getMembers();
                 }
             }
             // overwrite_membership means if they are already in the group with a different status,
             // their membership status will be updated.  Used for single-person actions but not bulk.
             $overwrite = array_get($_POST, 'overwrite_membership');
             if (!empty($personids)) {
                 if (!is_array($personids)) {
                     $personids = array($personids);
                 }
                 foreach ($personids as $personid) {
                     $new_member =& $GLOBALS['system']->getDBObject('person', (int) $personid);
                     $newstatus = $mstatus == '_PRESERVE_' ? $old_memberships[$personid]['membership_status_id'] : $mstatus;
                     if ($new_member->id) {
                         if ($this->_edited_object->addMember((int) $personid, $newstatus, $overwrite)) {
                             $mod_count++;
                         }
                     }
                 }
                 $verb = !empty($_POST['remove_from_groupid']) ? 'moved' : 'added';
                 if (count($personids) > 1) {
                     add_message($mod_count . ' persons ' . $verb . ' to group');
                 } else {
                     add_message('Person ' . $verb . ' to group');
                 }
             }
             if (!empty($_POST['remove_from_groupid']) && !empty($old_group)) {
                 $old_group->removeMembers($_POST['personid']);
             }
             $processed = TRUE;
             break;
         case 'remove_member':
         case 'remove_members':
             $personids = $_POST['personid'];
             if (!empty($personids)) {
                 if (!is_array($personids)) {
                     $personids = array($personids);
                 }
                 foreach ($personids as $personid) {
                     if ($this->_edited_object->removeMember((int) $personid)) {
                         $mod_count++;
                     }
                 }
                 if (count($personids) > 1) {
                     add_message($mod_count . ' persons removed from group');
                 } else {
                     add_message('Person removed from group');
                 }
             }
             $processed = TRUE;
             break;
         case 'delete':
             if ($_POST['action'] == 'delete') {
                 // must be POSTed
                 $GLOBALS['user_system']->checkPerm(PERM_EDITGROUP);
                 $name = $this->_edited_object->toString();
                 $this->_edited_object->delete();
                 add_message('Group "' . $name . '" deleted');
                 redirect('groups__list_all', array('groupid' => NULL, 'action' => NULL));
                 // exits
             }
             break;
     }
     if (!$processed) {
         // normal group edit
         $GLOBALS['user_system']->checkPerm(PERM_EDITGROUP);
         $processed = parent::_processObjectEditing();
     }
     if ($processed) {
         switch (array_get($_REQUEST, 'back_to')) {
             case 'persons':
                 redirect('persons', array('personid' => (int) reset($personids)), 'groups');
             case 'groups__list_all':
                 redirect('groups__list_all', array('groupid' => NULL, 'action' => NULL));
                 // exits
             // exits
             case 'groups':
             default:
                 redirect('groups', array('groupid' => $this->_edited_object->id));
                 // exits
         }
     }
 }
 public static function printMembershipStatusChooser($personid, $value)
 {
     Person_Group::printMembershipStatusChooser('membership_status[' . (int) $personid . ']', $value);
 }
							data-toggle="enable" data-target="#<?php 
        echo $verb;
        ?>
_new_group *" />
					<b>a new group:</b>
				</label>
				<table class="indent-left" id="<?php 
        echo $verb;
        ?>
_new_group">
					<tr>
						<td>New group name: </td>
						<td>
							<?php 
        $GLOBALS['system']->includeDBClass('person_group');
        $g = new Person_Group();
        $g->printFieldInterface('name');
        ?>
						</td>
					</tr>
					<tr>
						<td>Group category:</td>
						<td><?php 
        $g->printFieldInterface('categoryid');
        ?>
</td>
					</tr>
					<tr>
						<td></td>
						<td>
						<?php 
    function printView()
    {
        switch ($this->_stage) {
            case 'begin':
                if (!$GLOBALS['system']->getDBObjectData('person_group')) {
                    print_message('You must create a group to import into before you can import persons.  See Groups > Add.');
                    return;
                }
                ?>
				<p>This page allows you to import persons, families and notes from a CSV file.</p>
				<p>The CSV file must be in a format like this <a href="<?php 
                echo BASE_URL;
                ?>
/resources/sample_import.csv">sample file</a>. <br />(The order of columns is flexible but the first row must be a header with these column names).</p>
				<p>A new person record will be created for each row in the file. </p>
				<p>A new family record will be created whenever a new row contains a change in family name or family details.  <br />However, changing to or from a blank value in a field does not create a new family unless the whole row is blank.</p>
				<p>All the imported persons will be added to the group you choose below.</p>
				<form method="post" enctype="multipart/form-data">
				<table>
					<tr>
						<td>Import File:</td>
						<td><input type="file" name="import" /></td>
					</tr>
					<tr>
						<td>Group:</td>
						<td><?php 
                Person_Group::printChooser('groupid', 0);
                ?>
</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td class="compulsory"><input type="submit" class="btn" value="Go" /></td>
					</tr>
				</table>
				</form>
				<p>(You will be asked to confirm at the next step)</p>
				<?php 
                break;
            case 'confirm':
                $groupname = $GLOBALS['system']->getDBObject('person_group', $_SESSION['import']['groupid'])->toString();
                $GLOBALS['system']->includeDBClass('family');
                $this->_dummy_family = new Family();
                ?>
				<p>Please check the following is correct and click "confirm" at the bottom</p>
				<p><b><?php 
                echo $_SESSION['import']['total_families'];
                ?>
</b> families,<br />
				<b><?php 
                echo $_SESSION['import']['total_persons'];
                ?>
</b> persons and <br />
				<b><?php 
                echo $_SESSION['import']['total_notes'];
                ?>
</b> notes<br />
				will be created</p>
				<p>The new persons will be added to the <b><?php 
                echo $groupname;
                ?>
</b> group</p>

				<?php 
                foreach ($_SESSION['import']['families'] as $family) {
                    foreach ($family['members'] as $k => &$v) {
                        unset($v['note']);
                    }
                    ?>
					<h3><?php 
                    echo ents($family['family_name']);
                    ?>
 family</h3>
					<?php 
                    $this->_dummy_family->populate(0, $family);
                    $this->_dummy_family->printSummary(FALSE, $family['members']);
                }
                ?>
				<form class="stop-js" method="post"><input type="submit" name="confirm_import" value="Proceed with import" class="confirm-title btn" title="Proceed with import" />
				<a href="<?php 
                echo build_url(array());
                ?>
" class="btn">Cancel and start again</a>
				</form>
				<?php 
                break;
            case 'done':
                break;
        }
    }
    function printView()
    {
        $GLOBALS['system']->includeDBClass('member');
        ?>
		<div class="member-homepage-box visible-phone">
			<h3>Search people</h3>
			<form method="get" class="form-inline">
				<input type="hidden" name="view" value="people" />
				<input name="search" type="text" placeholder="Enter name to search" value="<?php 
        echo ents(array_get($_REQUEST, 'search'));
        ?>
">
				<button data-action="search" class="btn" type="submit">Search</button>
			</form>
		</div>

		<div class="member-homepage-box">
			<h3>
				<a class="pull-right" href="?view=_edit_me"><small>Edit</small></a>
				My Family
			</h3>
			<?php 
        $family = $GLOBALS['system']->getDBObject('family', $GLOBALS['member_user_system']->getCurrentMember('familyid'));
        unset($family->fields['status']);
        $family->printCustomSummary(array($this, 'printFamilyMembers'));
        ?>
		</div>

		<?php 
        if ($GLOBALS['system']->featureEnabled('ROSTERS&SERVICES')) {
            ?>
			<div class="member-homepage-box">
			<h3>
				<a class="pull-right" href="?view=_edit_ical"><small>Subscribe</small></a>
				My Roster Allocations &nbsp;
			</h3>
			<?php 
            $GLOBALS['system']->includeDBClass('roster_role_assignment');
            $rallocs = Roster_Role_Assignment::getUpcomingAssignments($GLOBALS['member_user_system']->getCurrentMember('id'), NULL);
            if ($rallocs) {
                ?>
				<table class="table table-auto-width">
				<?php 
                foreach ($rallocs as $date => $allocs) {
                    ?>
					 <tr>
						 <th><?php 
                    echo date('j M', strtotime($date));
                    ?>
</th>
						 <td>
							<?php 
                    foreach ($allocs as $alloc) {
                        echo $alloc['cong'] . ' ' . $alloc['title'] . '<br />';
                    }
                    ?>
						 </td>
					 </tr>
					 <?php 
                }
                ?>
				</table>
				<?php 
            } else {
                ?>
				<p><i>None</i></p>
				<?php 
            }
            ?>
			</div>
			<?php 
        }
        $GLOBALS['system']->includeDBClass('person_group');
        $groups = Person_Group::getGroups($GLOBALS['member_user_system']->getCurrentMember('id'), FALSE, TRUE);
        if (count($groups) > 1) {
            echo '<div  class="member-homepage-box" >';
            echo '<h3>My Groups</h3>';
            echo '<ul>';
            foreach ($groups as $id => $details) {
                echo '<li><a href="?view=_groups&groupid=' . (int) $id . '">' . ents($details['name']) . '</a></li>';
            }
            echo '</ul>';
            echo '</div>';
        }
        ?>
		<div class="member-homepage-box hidden-phone">
			<h3>Search people</h3>
			<form method="get" class="form-inline">
				<input type="hidden" name="view" value="people" />
				<input name="search" type="text" placeholder="Enter name to search" value="<?php 
        echo ents(array_get($_REQUEST, 'search'));
        ?>
">
				<button data-action="search" class="btn" type="submit">Search</button>
			</form>
		</div>
		<?php 
    }
Example #12
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 
    }
    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>
			<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(), TRUE);
        ?>
					</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(), TRUE);
        ?>
					</td>
				</tr>
			<?php 
        if ($GLOBALS['system']->featureEnabled('DATES')) {
            $datetype_params = array('type' => 'select', 'options' => array('' => '(Choose type)'));
            $dateFields = $GLOBALS['system']->getDBObjectData('custom_field', array('type' => 'date'), 'OR', 'rank');
            foreach ($dateFields as $fieldID => $fieldDetails) {
                $datetype_params['options'][$fieldID] = $fieldDetails['name'];
            }
            $datenote_params = array('type' => 'text', 'width' => 40);
            ?>
				<tr>
					<th>Dates</th>
					<td>
						When this plan is executed, for each person / family member:
						<table class="expandable">
						<?php 
            $dates = array_get($actions, 'dates');
            if (empty($dates)) {
                $dates = array('' => '');
            }
            foreach ($dates as $typeid => $note) {
                ?>
							<tr>
								<td class="nowrap">
								Set 
								<?php 
                print_widget('datetypes[]', $datetype_params, "{$typeid}");
                ?>
								to the reference date, with note
								<?php 
                print_widget('datenotes[]', $datenote_params, $note);
                ?>
								</td>
							</tr>
							<?php 
            }
            ?>
						</table>
					</td>
				</tr>
				<?php 
        }
        ?>
				<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 
    }
    function printFieldInterface($name, $prefix = '')
    {
        switch ($name) {
            case 'password':
                if ($GLOBALS['user_system']->getCurrentUser('id') == $this->id || $GLOBALS['user_system']->havePerm(PERM_SYSADMIN)) {
                    ?>
					<input type="password" data-minlength="<?php 
                    echo (int) $this->getMinPasswordLength();
                    ?>
" autocomplete="off" name="<?php 
                    echo $prefix . $name . '1';
                    ?>
" /><br />
					<input type="password" data-minlength="<?php 
                    echo (int) $this->getMinPasswordLength();
                    ?>
" autocomplete="off" name="<?php 
                    echo $prefix . $name . '2';
                    ?>
" /><br />
					<p class="help-inline">Enter once, then again to confirm. Passwords must be at least <?php 
                    echo (int) $this->getMinPasswordLength();
                    ?>
 characters and contain 2 letters and 2 numbers</p>
					<?php 
                } else {
                    ?>
					<p class="small">A user's password can only be edited by system administrators or the user themselves</p>
					<?php 
                }
                break;
            case 'restrictions':
                $GLOBALS['system']->includeDBClass('person_group');
                if ($GLOBALS['user_system']->havePerm(PERM_SYSADMIN)) {
                    ?>
					<table class="standard">
						<tr>
							<th>Restrict to these congregations: &nbsp;</th>
							<th>Restrict to these groups:</th>
						</tr>
						<tr>
							<td>
								<?php 
                    print_widget('restrictions[congregation]', array('type' => 'reference', 'references' => 'congregation', 'allow_multiple' => true), array_get($this->_restrictions, 'congregation', array()));
                    ?>
							</td>
							<td>
								<?php 
                    Person_Group::printMultiChooser('restrictions[group]', array_get($this->_restrictions, 'group', array()), array(), FALSE);
                    ?>
							</td>
						</tr>
					</table>
					<p class="help-inline">If you select congregations or groups here, this user will only be able to see persons who belong to one of the selected congregations or groups.  It will look like those are the only congregations, groups and persons in the system.  Users with congregation or group restrictions cannot add new persons or families.  Changes to restrictions take effect immediately.</p>
					<?php 
                } else {
                    $this->printFieldValue($name);
                    ?>
					<p class="help-inline">Only system administrators can edit this field</p>
					<?php 
                }
                break;
            case 'permissions':
                if ($name == 'permissions') {
                    // Subtly display the numeric permission level to help with config.php
                    ?>
					<div title="This number represents this combination of permissions, and can be used to set the default permissions in the config file" style="color: #ccc; position: absolute; right: 10px; padding: 3px"><?php 
                    echo $this->getValue($name);
                    ?>
</div>
					<?php 
                }
                if ($GLOBALS['user_system']->havePerm(PERM_SYSADMIN)) {
                    parent::printFieldInterface($name, $prefix);
                    ?>
					<p class="help-inline"><b>Note:</b> Changes to permissions only take effect the next time a user logs in</p>
					<?php 
                } else {
                    $this->printFieldValue($name);
                    ?>
					<p class="help-inline">Only system administrators can edit this field</p>
					<?php 
                }
                break;
            default:
                parent::printFieldInterface($name, $prefix);
        }
    }
    private function printSet($cohortid, $cohortname)
    {
        $stats = Attendance_Record_Set::getStatsForPeriod($this->_start_date, $this->_end_date, $cohortid);
        if (empty($stats) || $stats[NULL]['rate'] == 0) {
            return FALSE;
        }
        ?>
		<div class="span4">
		<table class="table table-bordered attendance-stats">
			<thead>
				<tr>
					<th colspan="4"><?php 
        echo ents($cohortname);
        ?>
</th>
				</tr>
				<tr>
					<th><?php 
        echo _('Segment');
        ?>
</th>
					<th title=<?php 
        echo _('"Percentage of dates marked present rather than absent"');
        ?>
><?php 
        echo _('Rate');
        ?>
</th>
					<th class="present" title=<?php 
        echo _('"Average number marked present per date"');
        ?>
><?php 
        echo _('Avg&nbsp;P');
        ?>
</th>
					<th class="absent" title="<?php 
        echo _('Average number marked absent per date"');
        ?>
><?php 
        echo _('Avg&nbsp;A');
        ?>
</th>
			</thead>
			<tbody>
		<?php 
        $map['age_bracket'] = explode(',', AGE_BRACKET_OPTIONS);
        if ($cohortid[0] == 'g') {
            list($map['status'], $default) = Person_Group::getMembershipStatusOptionsAndDefault();
        } else {
            $map['status'] = $this->status_map;
        }
        foreach (array('status', 'age_bracket') as $grouping) {
            foreach ($map[$grouping] as $k => $v) {
                if (!isset($stats[$grouping][$k])) {
                    continue;
                }
                ?>
				<tr <?php 
                if ($k == 0 && $grouping == 'age_bracket') {
                    echo 'class="thick-top-border"';
                }
                ?>
>
					<th><?php 
                echo ents($v);
                ?>
</th>
				<?php 
                if (isset($stats[$grouping][$k])) {
                    ?>
					<td><?php 
                    echo $stats[$grouping][$k]['rate'];
                    ?>
%</td>
					<td><?php 
                    echo number_format($stats[$grouping][$k]['avg_present'], 1);
                    ?>
</td>
					<td><?php 
                    echo number_format($stats[$grouping][$k]['avg_absent'], 1);
                    ?>
</td>
					<?php 
                } else {
                    ?>
					<td>-</td>
					<td>-</td>
					<td>-</td>
					<?php 
                }
                ?>
				</tr>
				<?php 
            }
        }
        ?>
				<tr class="thick-top-border">
					<th><?php 
        echo _('Overall');
        ?>
</th>
					<td><?php 
        echo $stats[NULL]['rate'];
        ?>
%</td>
					<td><?php 
        echo number_format($stats[NULL]['avg_present'], 1);
        ?>
</td>
					<td><?php 
        echo number_format($stats[NULL]['avg_absent'], 1);
        ?>
</td>
				</tr>
				<tr class="headcount">
					<th colspan="2">
						<?php 
        echo _('Avg&nbsp;Headcount');
        ?>
					</th>
					<td class="right">
						<?php 
        $bits = explode('-', $cohortid);
        $hc = Headcount::fetchAverage($bits[0], $bits[1], $this->_start_date, $this->_end_date);
        if ($hc) {
            echo number_format($hc, 1);
        } else {
            echo 'N/A';
        }
        ?>
					</td>
					<td colspan="2"></td>
				</tr>
			</tbody>
		</table>
		</div>
		<?php 
        return TRUE;
    }
Example #16
0
    static function printMultiChooser($name, $value, $exclude_groups = array(), $allow_category_select = FALSE)
    {
        ?>
		<table class="expandable">
		<?php 
        foreach ($value as $id) {
            ?>
			<tr>
				<td>
					<?php 
            Person_Group::printChooser($name . '[]', $id, $exclude_groups, $allow_category_select);
            ?>
				</td>
			</tr>
			<?php 
        }
        ?>
			<tr>
				<td>
					<?php 
        Person_Group::printChooser($name . '[]', 0, $exclude_groups, $allow_category_select);
        ?>
				</td>
			</tr>
		</table>
		<?php 
    }
			<input type="hidden" name="overwrite_membership" value="1" />
			<input type="hidden" name="back_to" value="persons" />

			<div class="modal-header">
				<h4>Add <?php 
    $person->printFieldValue('name');
    ?>
 to a group</h4>
			</div>
			<div class="modal-body">
				<?php 
    $GLOBALS['system']->includeDBClass('person_group');
    echo 'Add as a ';
    Person_Group::printMembershipStatusChooser('membership_status');
    echo ' of ';
    $can_add_group = Person_Group::printChooser('groupid', 0, array_keys($groups));
    ?>
			</div>
			<div class="modal-footer">
				<input type="submit" class="btn" value="Go" accesskey="s" onclick="if (!$('[name=groupid]').val()) { alert('Choose a group first'); return false; }" />
				<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
			</div>
		</form>
	</div>
	<?php 
}
// -------- CHECK PERMISSIONS AND ASSEMBLE DATA ------------- //
$accordion = SizeDetector::getWidth() && SizeDetector::isNarrow();
$tabs = array('basic' => 'Basic Details');
if ($GLOBALS['user_system']->havePerm(PERM_VIEWNOTE)) {
    $notes = $person->getNotesHistory();
    function printForm()
    {
        $GLOBALS['system']->includeDBClass('person_group');
        $params = $this->getValue('params');
        ?>
		<h3>Find me people...</h3>

		<h4>whose person/family record matches these rules:</h4>
		<table class="table table-border table-auto-width indent-left table-condensed">
		<?php 
        foreach ($this->_query_fields as $i) {
            $v = $this->_field_details[$i];
            if (in_array($v['type'], array('select', 'reference', 'datetime', 'text')) && !in_array($i, array('p.first_name', 'p.last_name', 'f.family_name', 'p.remarks', 'p.email'))) {
                ?>
				<tr>
					<td>
						<label class="checkbox">
							<input autofocus="1" type="checkbox" name="enable_rule[]" value="<?php 
                echo $i;
                ?>
" id="enable_rule_<?php 
                echo $i;
                ?>
" class="select-rule-toggle" <?php 
                if (isset($params['rules'][$i])) {
                    echo 'checked="checked" ';
                }
                ?>
/>
							<strong><?php 
                echo $v['label'];
                ?>
</strong>
							<?php 
                if ($v['type'] == 'datetime') {
                    echo 'is between...';
                } else {
                    echo 'is...';
                }
                ?>
						</label>
					</td>
					<td>
						<div class="select-rule-options" <?php 
                if (!isset($params['rules'][$i])) {
                    echo 'style="display: none" ';
                }
                ?>
>
							<?php 
                $key = str_replace('.', '_', $i);
                if ($v['type'] == 'datetime') {
                    $value = array_get($params['rules'], $i, array('from' => '2000-01-01', 'to' => date('Y-m-d')));
                    print_widget('params_' . $key . '_from', array('type' => 'date'), $value['from']);
                    echo ' and ';
                    print_widget('params_' . $i . '_to', array('type' => 'date'), $value['to']);
                } else {
                    $v['allow_multiple'] = TRUE;
                    print_widget('params_' . $key, $v, array_get($params['rules'], $i, $v['type'] == 'select' ? array() : ''));
                }
                ?>
						</div>
					</td>
				</tr>
				<?php 
            }
        }
        ?>
		</table>
		
		<?php 
        // DATE FIELD RULES
        if ($GLOBALS['system']->featureEnabled('DATES')) {
            if (empty($params['dates']) && !empty($params['rules']['date'])) {
                $params['dates'][] = $params['rules']['date'] + array('criteria' => 'between');
                unset($params['rules']['date']);
            }
            ?>
			<h4>who have
				<?php 
            $dlParams = array('type' => 'select', 'options' => array('OR' => 'any', 'AND' => 'all'));
            print_widget('params_date_logic', $dlParams, array_get($params, 'date_logic', 'AND'));
            ?>
				 the following date fields...</h4>
			<table class="table expandable indent-left" id="datefield-rules">
			<?php 
            $values = array_get($params, 'dates', array());
            if (empty($values)) {
                $values[] = array('typeid' => NULL, 'criteria' => 'any', 'anniversary' => TRUE, 'from' => '2000-01-01', 'to' => date('Y-m-d'));
            }
            foreach ($values as $i => $value) {
                ?>
				<tr>
					<td class="narrow">
						<?php 
                print_widget('params_date_' . $i . '_typeid', array('type' => 'select', 'options' => array(0 => '--Choose--') + Person::getDateTypes()), (string) $value['typeid']);
                ?>
					</td>
					<td>
						<?php 
                // backwards compatibility:
                if (array_get($value, 'criteria') == 'between') {
                    $value['criteria'] = $value['anniversary'] ? 'anniversary' : 'exact';
                }
                $cparams = array('type' => 'select', 'options' => array('any' => 'filled with any value', 'empty' => 'not filled in', 'exact' => 'with exact value within...', 'anniversary' => 'with exact value or anniversary within...'), 'class' => 'datefield-rule-criteria');
                print_widget('params_date_' . $i . '_criteria', $cparams, $value['criteria']);
                $pts = array('fixed' => '', 'relative' => '');
                $pts[array_get($value, 'periodtype', 'fixed')] = 'checked="checked"';
                ?>
						<div class="datefield-rule-period">
							<label class="checkbox">
								<input type="radio" name="params_date_<?php 
                echo $i;
                ?>
_periodtype" value="fixed" <?php 
                echo $pts['fixed'];
                ?>
 />
								the period from
								<?php 
                print_widget('params_date_' . $i . '_from', array('type' => 'date'), $value['from']);
                ?>
								to
								<?php 
                print_widget('params_date_' . $i . '_to', array('type' => 'date'), $value['to']);
                ?>
							</label>
							<label class="checkbox">
								<input type="radio" name="params_date_<?php 
                echo $i;
                ?>
_periodtype" value="relative"<?php 
                echo $pts['relative'];
                ?>
 />
								the
								<?php 
                print_widget('params_date_' . $i . '_periodlength', array('type' => 'int'), array_get($value, 'periodlength', 14));
                ?>
								day period
								<?php 
                print_widget('params_date_' . $i . '_periodanchor', array('type' => 'select', 'options' => array('before' => 'before', 'ending' => 'ending on', 'starting' => 'starting on', 'after' => 'after')), array_get($value, 'periodanchor', 'ending'));
                ?>
								the day the report is executed
							</label>

						</div>
					</td>
				</tr>
				<?php 
            }
            ?>
			</table>
			<?php 
        }
        ?>

		<h4>who <strong>are</strong> in one or more of these groups:</h4>
		<div class="indent-left">

			<?php 
        Person_Group::printMultiChooser('include_groupids', array_get($params, 'include_groups', array()), array(), TRUE);
        ?>

			<label class="checkbox">
				<input type="checkbox" name="enable_group_membership_status" data-toggle="enable" data-target="#group-membership-status *" value="1"	<?php 
        if (!empty($params['group_membership_status'])) {
            echo 'checked="checked"';
        }
        ?>
 />
				with membership status of
			</label>
			<span id="group-membership-status"><?php 
        Person_Group::printMembershipStatusChooser('group_membership_status', array_get($params, 'group_membership_status'), true);
        ?>
</span>

			<label class="checkbox">
				<input type="checkbox" name="enable_group_join_date" data-toggle="enable" data-target="#group-join-dates *" value="1"	<?php 
        if (!empty($params['group_join_date_from'])) {
            echo 'checked="checked"';
        }
        ?>
 />
				and joined the group between
			</label> 
			<span id="group-join-dates">
			<?php 
        print_widget('group_join_date_from', array('type' => 'date'), array_get($params, 'group_join_date_from'));
        ?>
			and <?php 
        print_widget('group_join_date_to', array('type' => 'date'), array_get($params, 'group_join_date_to'));
        ?>
			</span>
		</div>


		<h4>who are <strong>not</strong> in any of these groups:</h4>
		<div class="indent-left">
			<?php 
        Person_Group::printMultiChooser('exclude_groupids', array_get($params, 'exclude_groups', array()), array(), TRUE);
        ?>
		</div>
	
	<?php 
        if ($GLOBALS['user_system']->havePerm(PERM_VIEWNOTE)) {
            ?>
		<h4>who have a person note containing the phrase:</h4>
		<div class="indent-left">
			<input type="text" name="note_phrase" size="60" value="<?php 
            echo isset($params["note_phrase"]) ? $params["note_phrase"] : "";
            ?>
">
		</div>
		<?php 
        }
        if ($GLOBALS['user_system']->havePerm(PERM_VIEWATTENDANCE)) {
            ?>
		<h4>whose attendance...</h4>
		<div class="indent-left">
			at 
			<?php 
            $groupid_params = array('type' => 'select', 'options' => array(null => '(Nothing)', '__cong__' => 'their congregation'), 'attrs' => array('data-toggle' => 'enable', 'data-target' => '.attendance-input'));
            $groups = $GLOBALS['system']->getDBObjectData('person_group', array('!attendance_recording_days' => 0, 'is_archived' => 0), 'AND');
            foreach ($groups as $id => $groupdata) {
                $groupid_params['options'][$id] = $groupdata['name'];
            }
            print_widget('attendance_groupid', $groupid_params, array_get($params, 'attendance_groupid', 0));
            ?>
			<br />

			has been 

			<?php 
            $operator_params = array('type' => 'select', 'options' => array('<' => 'less than', '>' => 'more than'), 'class' => 'attendance-input');
            print_widget('attendance_operator', $operator_params, array_get($params, 'attendance_operator', '<'));
            ?>
			<input name="attendance_percent" type="text" size="2" class="int-box attendance-input" value="<?php 
            echo (int) array_get($params, 'attendance_percent', 50);
            ?>
" />%

			<br />over the last <input name="attendance_weeks" type="text" size="2" class="int-box attendance-input" value="<?php 
            echo (int) array_get($params, 'attendance_weeks', 2);
            ?>
" /> weeks
		</div>
		<?php 
        }
        ?>

		<h3>For each person found, show me...</h3>
		<?php 
        $show_fields = array_get($params, 'show_fields', array());
        ?>

		<table class="table-condensed expandable indent-left">
		<?php 
        foreach ($show_fields as $chosen_field) {
            ?>
			<tr>
				<td>
					<img src="<?php 
            echo BASE_URL;
            ?>
/resources/img/expand_up_down_green_small.png" class="icon insert-row-below" style="position: relative; top: 2ex" title="Create a blank entry here" />
				</td>
				<td>
					<?php 
            $options = array('' => '');
            foreach ($this->_show_fields as $i => $opt) {
                if (is_null($opt)) {
                    $options['--' . $i] = '-----';
                } else {
                    $options[$opt] = $this->_field_details[$opt]['label'];
                }
            }
            if ($GLOBALS['user_system']->havePerm(PERM_VIEWATTENDANCE)) {
                $options['--Z'] = '-----';
                $options['attendance_percent'] = 'Attendance rate during specified period';
                $options['attendance_numabsences'] = 'Number of absences since last marked present';
            }
            if ($GLOBALS['user_system']->havePerm(PERM_VIEWNOTE)) {
                $options['--Y'] = '-----';
                $options['notes.subjects'] = 'Notes matching the phrase above';
                $options['actionnotes.subjects'] = 'Notes requiring action';
            }
            if ($GLOBALS['system']->featureEnabled('DATES')) {
                $options['--A'] = '-----';
                foreach (Person::getDateTypes() as $typeid => $name) {
                    $options['date---' . $typeid] = ucfirst($name) . ' Date';
                }
            }
            $options['--B'] = '-----';
            if ($GLOBALS['system']->featureEnabled('PHOTOS')) {
                $options['photo'] = 'Photo';
            }
            $options['groups'] = 'Which of the selected groups they are in';
            $options['membershipstatus'] = 'Group membership status';
            $options['all_members'] = 'Names of all their family members';
            $options['adult_members'] = 'Names of their adult family members';
            if ($GLOBALS['system']->featureEnabled('PHOTOS')) {
                $options['photo'] = 'Photo';
            }
            $options['--D'] = '-----';
            $options['view_link'] = 'A link to view their person record';
            $options['edit_link'] = 'A link to edit their person record';
            $options['checkbox'] = 'A checkbox for bulk actions';
            print_widget('show_fields[]', array('options' => $options, 'type' => 'select', 'disabled_prefix' => '--'), $chosen_field);
            ?>
				</td>
				<td class="nowrap">
					<img src="<?php 
            echo BASE_URL;
            ?>
/resources/img/arrow_up_thin_black.png" class="icon move-row-up" title="Move this item up" />
					<img src="<?php 
            echo BASE_URL;
            ?>
/resources/img/arrow_down_thin_black.png" class="icon move-row-down" title="Move this item down" />
					<img src="<?php 
            echo BASE_URL;
            ?>
/resources/img/cross_red.png" class="icon delete-row" title="Delete this item" />
				</td>
			</tr>
			<?php 
        }
        ?>
		</table>


		<h3>Group the results...</h3>
		<?php 
        $gb = array_get($params, 'group_by', '');
        ?>
		<div class="indent-left">
			<select name="group_by">
				<option value=""<?php 
        if ($gb == '') {
            echo ' selected="selected"';
        }
        ?>
>all together</option>
				<option value="groupid"<?php 
        if ($gb == 'groupid') {
            echo ' selected="selected"';
        }
        ?>
>by group membership</option>
			<?php 
        foreach ($this->_query_fields as $i) {
            $v = $this->_field_details[$i];
            if (!in_array($v['type'], array('select', 'reference'))) {
                continue;
            }
            ?>
				<option value="<?php 
            echo $i;
            ?>
"<?php 
            if ($gb == $i) {
                echo ' selected="selected"';
            }
            ?>
>by <?php 
            echo $v['label'];
            ?>
</option>
				<?php 
        }
        ?>
			</select>
			<p class="smallprint">Note: Result groups that do not contain any persons will not be shown</p>
		</div>

		<h3>Sort the results by...</h3>

		<select name="sort_by" class="indent-left">
		<?php 
        $sb = array_get($params, 'sort_by');
        foreach ($this->_show_fields as $name) {
            if (is_null($name)) {
                ?>
				<option disabled="disabled">------</option>
				<?php 
            } else {
                ?>
				<option value="<?php 
                echo $name;
                ?>
"<?php 
                if ($sb == $name) {
                    echo ' selected="selected"';
                }
                ?>
><?php 
                echo ents($this->_field_details[$name]['label']);
                ?>
</option>
				<?php 
            }
        }
        ?>
		<option disabled="disabled">------</option>
		<option value="attendance_percent"<?php 
        if ($sb == "attendance_percent") {
            echo ' selected="selected"';
        }
        ?>
>Attendance rate during the specified period</option>
		<option value="attendance_numabsences""<?php 
        if ($sb == "attendance_numabsences") {
            echo ' selected="selected"';
        }
        ?>
>Number of absences since last marked present</option>
		<?php 
        if ($GLOBALS['system']->featureEnabled('DATES')) {
            ?>
			<option disabled="disabled">------</option>
			<?php 
            foreach (Person::getDateTypes() as $typeid => $name) {
                ?>
				<option value="date---<?php 
                echo $typeid;
                ?>
"<?php 
                if ($sb == 'date---' . $typeid) {
                    echo ' selected="selected"';
                }
                ?>
><?php 
                echo ents($name);
                ?>
 date</option>
				<?php 
            }
        }
        ?>
		</select>

		<?php 
        if ($GLOBALS['user_system']->havePerm(PERM_MANAGEREPORTS)) {
            ?>
			<h3>I want to save this report...</h3>
			<div class="indent-left">
				<label type="radio">
					<input type="radio" name="save_option" value="new" id="save_option_new" <?php 
            if (empty($this->id)) {
                echo 'checked="checked"';
            }
            ?>
 />
					as a new report called
					<input type="text" name="new_query_name" />
				</label>
		
				<label type="radio">
					<input type="radio" name="save_option" value="replace" id="save_option_replace" <?php 
            if ($this->id && $this->id != 'TEMP') {
                echo 'checked="checked"';
            }
            ?>
 />
					in place of an existing report
					<?php 
            print_widget('replace_query_id', array('type' => 'reference', 'references' => 'person_query'), $this->id);
            ?>
				</label>

				<label type="radio">
					<input type="radio" name="save_option" value="temp" id="save_option_temp"<?php 
            if (empty($this->id) || $this->id == 'TEMP') {
                echo ' checked="checked"';
            }
            ?>
 />
					only temporarily as an ad-hoc report
				</label>
			</div>
			<?php 
        }
    }
    private function printSet($cohortid, $cohortname)
    {
        $stats = Attendance_Record_Set::getStatsForPeriod($this->_start_date, $this->_end_date, $cohortid);
        if (empty($stats)) {
            return FALSE;
        }
        ?>
		<div class="span4">
		<table class="table table-bordered attendance-stats">
			<thead>
				<tr>
					<th colspan="4"><?php 
        echo ents($cohortname);
        ?>
</th>
				</tr>
				<tr>
					<th>Status</th>
					<th title="Percentage of dates marked present rather than absent">Rate</th>
					<th class="present" title="Average number marked present per date">Avg&nbsp;P</th>
					<th class="absent" title="Average number marked absent per date">Avg&nbsp;A</th>
			</thead>
			<tbody>
		<?php 
        if ($cohortid[0] == 'g') {
            list($map, $default) = Person_Group::getMembershipStatusOptionsAndDefault();
        } else {
            $map = $this->status_map;
        }
        foreach ($map as $k => $v) {
            if (isset($stats[$k])) {
                ?>
				<tr>
					<th><?php 
                echo ents($v);
                ?>
</th>
					<td style="width: 6ex; text-align: right"><?php 
                echo $stats[$k]['rate'];
                ?>
%</td>
					<td style="width: 6ex; text-align: right"><?php 
                echo number_format($stats[$k]['avg_present'], 1);
                ?>
</td>
					<td style="width: 6ex; text-align: right"><?php 
                echo number_format($stats[$k]['avg_absent'], 1);
                ?>
</td>
				</tr>
				<?php 
            }
        }
        ?>
				<tr class="thick-top-border">
					<th>Overall</th>
					<td style="width: 6ex; text-align: right"><?php 
        echo $stats[NULL]['rate'];
        ?>
%</td>
					<td style="width: 6ex; text-align: right"><?php 
        echo number_format($stats[NULL]['avg_present'], 1);
        ?>
</td>
					<td style="width: 6ex; text-align: right"><?php 
        echo number_format($stats[NULL]['avg_absent'], 1);
        ?>
</td>
				</tr>
				<tr class="headcount">
					<th colspan="2">
						Avg&nbsp;Headcount
					</th>
					<td class="right">
						<?php 
        $bits = explode('-', $cohortid);
        $hc = Headcount::fetchAverage($bits[0], $bits[1], $this->_start_date, $this->_end_date);
        if ($hc) {
            echo number_format($hc, 1);
        } else {
            echo 'N/A';
        }
        ?>
					</td>
					<td colspan="2"></td>
				</tr>
			</tbody>
		</table>
		</div>
		<?php 
        return TRUE;
    }