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);
 }
Beispiel #2
0
 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";
     }
 }
    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 
    }