Sorry for the newbie question...
I modified CRM_Contact_Form_Task_Label
class, to create my own Task. It creates necessary data for printing membership cards. If a contact has all necessary data, then these are printed to a file, if not, the contact should be shown as result of a Custom Search.
I can't figure out why, but this code doesn't shows up the file, only redirects the page. File is shown up when I add exit;
after the $fileReady = self::createMembershipCard($rows);
row.
Please advise me, how can I show up the file and then redirect the page.
Thank you!
function postProcess($params = NULL) {
[...]
$fileReady = FALSE;
$fileReady = self::createMembershipCard($rows);
if($fileReady) {
$csvListOfIds = implode(",", $failed);
CRM_Utils_System::redirect( CRM_Utils_System::url('civicrm/contact/search/custom', "reset=1&force=1&csid=19&cid={$csvListOfIds}"));
}
}
/**
* Create export file for Membership Cards.
*
* @param array $contactRows
* Associated array of contact data.
*/
public function createMembershipCard(&$contactRows) {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.txt');
$output = fopen('php://output', 'w');
if(sizeof($contactRows) != 0) {
foreach($contactRows as $item) {
$toOutput = $item['display_name'].';'.date('Y.m.d.').';2099.21.31.'.PHP_EOL;
fwrite($output, $toOutput);
}
}
fclose($output);
return TRUE;
}