function run() { $fp = fopen('php://output', 'w'); header('Content-type: application/force-download'); header("Content-Type: application/download"); header('Content-type: text/csv'); header('Content-Disposition: attachment; filename="jethro_' . date('Y-m-d_h:i') . '.csv"'); $GLOBALS['system']->includeDBClass('family'); $GLOBALS['system']->includeDBClass('person'); switch (array_get($_REQUEST, 'merge_type')) { case 'family': $merge_data = Family::getFamilyDataByMemberIDs($_POST['personid']); $dummy = new Family(); $dummy_family = NULL; break; case 'person': default: $merge_data = $GLOBALS['system']->getDBObjectData('person', array('id' => (array) $_POST['personid'])); $dummy = new Person(); $dummy_family = new Family(); break; } $headerrow = array('ID'); foreach (array_keys(reset($merge_data)) as $header) { if ($header == 'familyid') { continue; } $headerrow[] = strtoupper($dummy->getFieldLabel($header)); } fputcsv($fp, $headerrow); foreach ($merge_data as $id => $row) { @$dummy->populate($id, $row); $outputrow = array($id); foreach ($row as $k => $v) { if ($k == 'history') { continue; } if ($k == 'familyid') { continue; } if ($dummy->hasField($k)) { $outputrow[] = $dummy->getFormattedValue($k, $v); // pass value to work around read-only fields } else { if ($dummy_family && $dummy_family->hasField($k)) { $outputrow[] = $dummy_family->getFormattedValue($k, $v); } else { $outputrow[] = $v; } } } fputcsv($fp, $outputrow); } fclose($fp); }
function run() { $results = array(); if (!empty($_REQUEST['search'])) { $name = $_REQUEST['search']; $GLOBALS['system']->includeDBClass('person'); $results = Person::getPersonsByName($name, array_get($_REQUEST, 'include_archived', false)); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // HTTP/1.0 header("Content-Type: application/json"); echo "{\"results\": ["; $arr = array(); $GLOBALS['system']->includeDBClass('person'); $dummy = new Person(); $count = 0; foreach ($results as $i => $details) { if ($count++ > 12) { break; } $dummy->populate($i, $details); $arr[] = ' { id: ' . $i . ', value: "' . addcslashes(ents($details['first_name'] . ' ' . $details['last_name']), '"') . '", info: "' . addcslashes(ents($dummy->getFormattedValue('status') . ', ' . $dummy->getFormattedValue('congregationid')), '"') . '" } '; } echo implode(", ", $arr); echo "]}"; } }
function run() { // Ref: http://en.wikipedia.org/wiki/VCard header('Content-type: text/vcf'); header('Content-Disposition: attachment; filename="contacts_' . date('Y-m-d_h:i') . '.vcf"'); $GLOBALS['system']->includeDBClass('person'); $GLOBALS['system']->includeDBClass('family'); $merge_data = $GLOBALS['system']->getDBObjectData('person', array('id' => $_REQUEST['personid'])); $dummy = new Person(); $family = new Family(); foreach ($merge_data as $id => $row) { $dummy->populate($id, $row); $family->setvalue('home_tel', $row['home_tel']); echo "BEGIN:VCARD\n"; echo "VERSION:3.0\n"; echo "N:" . $row['last_name'] . ";" . $row['first_name'] . ";;;\n"; echo "FN:" . $row['first_name'] . " " . $row['last_name'] . "\n"; echo "EMAIL;type=INTERNET;type=HOME:" . $row['email'] . "\n"; echo "ADR;type=HOME:;;" . $row['address_street'] . ";" . $row['address_suburb'] . ";" . $row['address_state'] . ";" . $row['address_postcode'] . ";\n"; echo "TEL;type=HOME:" . $family->getFormattedValue('home_tel') . "\n"; echo "TEL;type=WORK:" . $dummy->getFormattedValue('work_tel') . "\n"; echo "TEL;type=MOBILE:" . $dummy->getFormattedValue('mobile_tel') . "\n"; echo "TEL;type=CELL:" . $dummy->getFormattedValue('mobile_tel') . "\n"; if ($g = $dummy->getValue('Gender')) { echo "GENDER:" . strtoupper($g[0]) . "\n"; } echo "CATEGORIES:" . $row['congregation'] . "\n"; echo "ORG:" . $dummy->getFormattedValue('congregationid') . "\n"; echo "NOTES:" . $dummy->getFormattedValue('congregationid') . "\n"; echo "ROLE:" . $dummy->getFormattedValue('status') . "\n"; echo "TITLE:" . $dummy->getFormattedValue('status') . "\n"; echo "SOURCE:" . build_url(array('personid' => array($id))) . "\n"; // where to get vcard from echo "URL:" . build_url(array('call' => NULL, 'view' => 'persons', 'personid' => $id)) . "\n"; // definitive location for full details echo "UID:" . build_url(array('call' => NULL, 'view' => 'persons', 'personid' => $id)) . "\n"; echo "END:VCARD\n\n"; } }
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; }
public function getStats() { $db = $GLOBALS['db']; $groupingField = (int) $this->congregationid ? 'p.status' : 'pgms.label'; $SQL = 'SELECT present, ' . $groupingField . ' AS status, count(p.id) AS total FROM attendance_record ar JOIN person p ON ar.personid = p.id LEFT JOIN person_group pg ON pg.id = ar.groupid LEFT JOIN person_group_membership pgm ON pgm.personid = p.id AND pgm.groupid = pg.id LEFT JOIN person_group_membership_status pgms ON pgms.id = pgm.membership_status WHERE date = ' . $db->quote($this->date) . ' AND ar.groupid = ' . $db->quote((int) $this->groupid) . ' '; if ($this->congregationid) { $SQL .= ' AND p.congregationid = ' . $db->quote($this->congregationid); } $SQL .= ' GROUP BY present, ' . $groupingField . ' ORDER BY present, ' . $groupingField; $res = $db->queryAll($SQL); check_db_result($res); $totals = array(0 => 0, 1 => 0); $breakdowns = array(0 => array(), 1 => array()); $dummy = new Person(); foreach ($res as $r) { if ($this->congregationid) { $r['status'] = $dummy->getFormattedValue('status', $r['status']); } $totals[$r['present']] += $r['total']; $breakdowns[$r['present']][] = $r; } return array($totals, $breakdowns); }
function getMergeVars($person_data, $email) { static $dummy_person = null; if (is_null($dummy_person)) { $GLOBALS['system']->includeDBClass('person'); $dummy_person = new Person(); } $dummy_person->populate(0, $person_data); return array('EMAIL' => $email, 'FNAME' => $dummy_person->getFormattedValue('first_name'), 'LNAME' => $dummy_person->getFormattedValue('last_name'), 'GENDER' => $dummy_person->getFormattedValue('gender'), 'CONG' => $dummy_person->getFormattedValue('congregationid'), 'STATUS' => $dummy_person->getFormattedValue('status'), 'AGEBRACKET' => $dummy_person->getFormattedValue('age_bracket')); }
function printResults($with_links = FALSE) { $db = $GLOBALS['db']; $groupid = (int) $_REQUEST['groupid']; $all_member_details = array_get($_REQUEST, 'all_member_details', 0); if (empty($groupid)) { return; } $sql = ' select family.id as familyid, family.family_name, family.home_tel, person.*, congregation.long_name as congname, address_street, address_suburb, address_state, address_postcode from family join person on family.id = person.familyid left join congregation on person.congregationid = congregation.id where person.status <> "archived" and family.id in (select familyid from person join person_group_membership pgm on person.id = pgm.personid where pgm.groupid = ' . (int) $groupid; if (!empty($_REQUEST['congregationid'])) { $sql .= ' AND person.congregationid in (' . implode(',', array_map(array($db, 'quote'), $_REQUEST['congregationid'])) . ')'; } $sql .= ') order by family_name asc, age_bracket asc, gender desc '; $res = $db->queryAll($sql, null, null, true, true, true); check_db_result($res); if (empty($res)) { ?> <p><i>No families to show</i></p><?php return; } $sql = ' select personid from person_group_membership pgm where pgm.groupid = ' . (int) $groupid; $signups = $db->queryCol($sql); check_db_result($signups); $GLOBALS['system']->includeDBClass('family'); $GLOBALS['system']->includeDBClass('person'); $dummy_family = new Family(); $dummy_person = new Person(); ?> <table class="contact-list"> <?php foreach ($res as $familyid => $family_members) { $adults = array(); $children = array(); $adults_use_full = false; $children_use_full = false; foreach ($family_members as $member) { if (empty($_REQUEST['age_bracket']) || in_array($member['age_bracket'], $_REQUEST['age_bracket'])) { $adults[] = $member; if ($member['last_name'] != $member['family_name']) { $adults_use_full = true; } } else { $children[] = $member; if ($member['last_name'] != $member['family_name']) { $children_use_full = true; } } } $first_member = reset($family_members); ?> <tr><td colspan="4"><h2 style="margin-bottom: 0px"><?php echo $first_member['family_name']; ?> </h2></td></tr> <?php if ($first_member['home_tel']) { $dummy_family->setValue('home_tel', $first_member['home_tel']); echo '<tr><td colspan="4"><h3 style="border: 0px; margin: 0px; padding: 0px">'; echo ents($dummy_family->getFormattedValue('home_tel')); echo '</h3></td></tr>'; } if (!empty($_REQUEST['include_address']) && $first_member['address_street']) { echo '<tr><td colspan="4">' . nl2br(ents($first_member['address_street'])) . '<br />'; echo ents($first_member['address_suburb'] . ' ' . $first_member['address_state'] . ' ' . $first_member['address_postcode']); echo '</td></tr>'; } $fn = $with_links ? 'printFieldValue' : 'getFormattedValue'; foreach ($adults as $adult) { $dummy_person->populate($adult['id'], $adult); ?> <tr> <td><?php echo ents($adults_use_full ? $adult['first_name'] . ' ' . $adult['last_name'] : $adult['first_name']); ?> </td> <td><?php echo ents($adult['congname']); ?> </td> <td><?php if ($all_member_details || in_array($adult['id'], $signups)) { echo ents($dummy_person->getFormattedValue('mobile_tel')); } ?> </td> <td><?php if ($all_member_details || in_array($adult['id'], $signups)) { echo ents($dummy_person->{$fn}('email')); } ?> </td> </tr> <?php } $child_names = array(); foreach ($children as $child) { $child_names[] = $children_use_full ? $child['first_name'] . ' ' . $child['last_name'] : $child['first_name']; } if ($child_names) { ?> <tr> <td colspan="4"><?php echo ents(implode(', ', $child_names)); ?> </td </tr> <?php } ?> <?php } ?> </table> <?php }
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) </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 } } }
protected function getMergeData() { $merge_type = array_get($_REQUEST, 'merge_type', 'person'); switch ($merge_type) { case 'family': $GLOBALS['system']->includeDBClass('family'); $merge_data = Family::getFamilyDataByMemberIDs($_POST['personid']); $dummy = new Family(); break; case 'person': default: $temp_merge_data = $GLOBALS['system']->getDBObjectData('person', array('id' => $_POST['personid'])); $merge_data = array(); foreach ($_REQUEST['personid'] as $id) { $merge_data[$id] = $temp_merge_data[$id]; } $GLOBALS['system']->includeDBClass('person'); $dummy = new Person(); break; } foreach ($merge_data as $id => $row) { @$dummy->populate($id, $row); foreach ($row as $k => $v) { if ($k == 'history') { unset($merge_data[$id][$k]); } if ($dummy->hasField($k)) { $merge_data[$id][$k] = $dummy->getFormattedValue($k); } if ($k == 'selected_firstnames') { $merge_data[$id]['selected_members'] = $v; } } } return $merge_data; }
} ?> <label> <input type="checkbox" checked="checked" value="<?php echo (int) $personid; ?> " /> </label> <div> <strong><?php echo ents($dummy->toString()); ?> </strong> <br /> <?php echo ents($dummy->getFormattedValue('age_bracket')); echo ' • '; echo ents($dummy->getFormattedValue('gender')); echo '<br />'; echo ents($dummy->getFormattedValue('status')); echo ' • '; echo ents($dummy->getFormattedValue('congregationid')); ?> </div> </div> </a> <?php } $all_emails = $family->getAllEmailAddrs(); if (!empty($all_emails)) {
function replace_keywords($content, $person) { static $dummy = NULL; if (!$dummy) { $dummy = new Person(); } $dummy->populate($person['id'], $person); foreach ($person as $k => $v) { $keyword = '%' . strtoupper($k) . '%'; if (FALSE !== strpos($content, $keyword)) { if ($k == 'expirydate') { $replacement = format_date($v); } else { $replacement = $dummy->getFormattedValue($k); } $content = str_replace($keyword, $replacement, $content); } } return $content; }