Skip to content

Commit

Permalink
Fix iPDFOutputType setting (#7027)
Browse files Browse the repository at this point in the history
# Description & Issue number it closes 
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. -->

Resolves #1905

## Screenshots (if appropriate)
<!-- Before and after --> 
None

## How to test the changes?

No change should be detected.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

<!-- Please describe the tests that you ran to verify your changes.
Provide instructions so we can reproduce. Please also list any relevant
details for your test configuration -->

Visual inspection.

# Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
DAcodedBEAT authored May 16, 2024
2 parents 7f854bc + 8c1ee0c commit d707317
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 387 deletions.
1 change: 0 additions & 1 deletion src/Include/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

$taskService = new TaskService();

//
// Turn ON output buffering
ob_start();

Expand Down
35 changes: 13 additions & 22 deletions src/Reports/ClassAttendance.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*******************************************************************************
*
* filename : Reports/ClassAttendance.php
* last change : 2013-02-22
* description : Creates a PDF for a Sunday School Class Attendance List
* Udpdated : 2017-10-23
* Philippe Logel
******************************************************************************/

require '../Include/Config.php';
require '../Include/Functions.php';

Expand All @@ -20,11 +11,12 @@
use ChurchCRM\model\ChurchCRM\Map\PersonTableMap;
use ChurchCRM\Reports\PdfAttendance;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\LoggerUtils;

$iGroupID = InputUtils::legacyFilterInput($_GET['GroupID']);
$aGrp = explode(',', $iGroupID);
$nGrps = count($aGrp);
//echo $iGroupID;
LoggerUtils::getAppLogger()->debug("Group ID = {$iGroupID}");

$iFYID = InputUtils::legacyFilterInput($_GET['FYID'], 'int');

Expand All @@ -33,7 +25,7 @@
$tAllRoles = InputUtils::legacyFilterInput($_GET['AllRoles'], 'int');
$withPictures = InputUtils::legacyFilterInput($_GET['withPictures'], 'int');

//echo "all roles ={$tAllRoles}";
LoggerUtils::getAppLogger()->debug("All roles = {$tAllRoles}");

$tNoSchool1 = InputUtils::legacyFilterInputArr($_GET, 'NoSchool1');
$tNoSchool2 = InputUtils::legacyFilterInputArr($_GET, 'NoSchool2');
Expand Down Expand Up @@ -82,7 +74,7 @@

for ($i = 0; $i < $nGrps; $i++) {
$iGroupID = $aGrp[$i];
// uset($aStudents);

if ($i > 0) {
$pdf->addPage();
}
Expand All @@ -93,7 +85,7 @@

$reportHeader = str_pad($group->getName(), 95) . $FYString;

// Build the teacher string- first teachers, then the liaison
// Build the teacher string -- first teachers, then the liaison
$teacherString = gettext('Teachers') . ': ';
$bFirstTeacher = true;
$iTeacherCnt = 0;
Expand All @@ -103,7 +95,7 @@
$groupRoleMemberships = Person2group2roleP2g2rQuery::create()
->joinWithPerson()
->orderBy(PersonTableMap::COL_PER_LASTNAME)
->_and()->orderBy(PersonTableMap::COL_PER_FIRSTNAME) // I've try to reproduce per_LastName, per_FirstName
->_and()->orderBy(PersonTableMap::COL_PER_FIRSTNAME)
->findByGroupId($iGroupID);

if ($tAllRoles != 1) {
Expand Down Expand Up @@ -131,7 +123,8 @@
$lst_OptionName = $groupRole->getOptionName();

if ($lst_OptionName === 'Teacher') {
$aTeachers[$iTeacherCnt] = $person; // Make an array of teachers while we're here
// Make an array of teachers while we're here
$aTeachers[$iTeacherCnt] = $person;
if (!$bFirstTeacher) {
$teacherString .= ', ';
}
Expand Down Expand Up @@ -186,7 +179,7 @@
$withPictures
);

// we start a new page
// We start a new page
if ($y > $yTeachers + 10) {
$pdf->addPage();
}
Expand All @@ -213,9 +206,7 @@
$withPictures
);
} else {
//
// print all roles on the attendance sheet
//
// Print all roles on the attendance sheet
$iStudentCnt = 0;

unset($aStudents);
Expand Down Expand Up @@ -253,9 +244,9 @@
);
}
}

header('Pragma: public'); // Needed for IE when using a shared SSL certificate
if ($iPDFOutputType == 1) {
// Needed for IE when using a shared SSL certificate
header('Pragma: public');
if ((int) SystemConfig::getValue('iPDFOutputType') === 1) {
$pdf->Output('ClassAttendance' . date(SystemConfig::getValue('sDateFilenameFormat')) . '.pdf', 'D');
} else {
$pdf->Output();
Expand Down
15 changes: 3 additions & 12 deletions src/Reports/ClassList.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*******************************************************************************
*
* filename : Reports/ClassList.php
* last change : 2017-11-04 Philippe Logel
* description : Creates a PDF for a Sunday School Class List
*
******************************************************************************/

namespace ChurchCRM\Reports;

require '../Include/Config.php';
Expand Down Expand Up @@ -88,7 +80,7 @@ public function __construct()
$groupRoleMemberships = Person2group2roleP2g2rQuery::create()
->joinWithPerson()
->orderBy(PersonTableMap::COL_PER_LASTNAME)
->_and()->orderBy(PersonTableMap::COL_PER_FIRSTNAME) // I've try to reproduce ORDER BY per_LastName, per_FirstName
->_and()->orderBy(PersonTableMap::COL_PER_FIRSTNAME)
->findByGroupId($iGroupID);

$students = [];
Expand Down Expand Up @@ -190,8 +182,7 @@ public function __construct()
$pdf->Line($nameX - $imageHeight, $y, $nameX - $imageHeight, $y + $imageHeight);
$pdf->Line($nameX, $y, $nameX, $y + $imageHeight);

// we build the cross in the case of there's no photo
//$this->SetLineWidth(0.25);
// We build the cross in the case of there's no photo
$pdf->Line($nameX - $imageHeight, $y + $imageHeight, $nameX, $y);
$pdf->Line($nameX - $imageHeight, $y, $nameX, $y + $imageHeight);

Expand Down Expand Up @@ -270,7 +261,7 @@ public function __construct()
}

header('Pragma: public'); // Needed for IE when using a shared SSL certificate
if ($iPDFOutputType == 1) {
if ((int) SystemConfig::getValue('iPDFOutputType') === 1) {
$pdf->Output('ClassList' . date(SystemConfig::getValue('sDateFilenameFormat')) . '.pdf', 'D');
} else {
$pdf->Output();
Expand Down
14 changes: 3 additions & 11 deletions src/Reports/ConfirmLabels.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*******************************************************************************
*
* filename : Reports/ConfimLabels.php
* last change : 2003-08-30
* description : Creates a PDF with all the mailing labels for the confirm data letter
******************************************************************************/

require '../Include/Config.php';
require '../Include/Functions.php';

Expand Down Expand Up @@ -56,9 +48,9 @@

$pdf->addPdfLabel($labelText);
}

header('Pragma: public'); // Needed for IE when using a shared SSL certificate
if ($iPDFOutputType == 1) {
// Needed for IE when using a shared SSL certificate
header('Pragma: public');
if ((int) SystemConfig::getValue('iPDFOutputType') === 1) {
$pdf->Output('ConfirmDataLabels' . date(SystemConfig::getValue('sDateFilenameFormat')) . '.pdf', 'D');
} else {
$pdf->Output();
Expand Down
34 changes: 11 additions & 23 deletions src/Reports/DirectoryReport.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
<?php

/*******************************************************************************
*
* filename : Reports/DirectoryReport.php
* last change : 2003-08-30
* description : Creates a Member directory
*
* https://churchcrm.io/
* Copyright 2003 Jason York, 2004-2005 Michael Wilt, Richard Bondi
******************************************************************************/

require '../Include/Config.php';
require '../Include/Functions.php';

use ChurchCRM\Authentication\AuthenticationManager;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\Reports\PdfDirectory;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\LoggerUtils;
use ChurchCRM\Utils\MiscUtils;
use ChurchCRM\Utils\RedirectUtils;

// Check for Create Directory user permission.
AuthenticationManager::redirectHomeIfFalse(AuthenticationManager::getCurrentUser()->isCreateDirectoryEnabled());
Expand Down Expand Up @@ -88,10 +77,10 @@
$sPageSize = 'legal';
}

//echo "ncols={$bNumberofColumns} page size={$sPageSize}";
LoggerUtils::getAppLogger()->debug("ncols = {$bNumberofColumns} page size = {$sPageSize}");

// Instantiate the directory class and build the report.
//echo "font sz = {$bFontSz} and line sp={$bLineSp}";
// Instantiate the directory class and build the report
LoggerUtils::getAppLogger()->debug("font sz = {$bFontSz} and line sp = {$bLineSp}");
$pdf = new PdfDirectory($bNumberofColumns, $sPageSize, $bFontSz, $bLineSp);

// Get the list of custom person fields
Expand Down Expand Up @@ -193,7 +182,8 @@

$isFamily = false;

if ($memberCount > 1) { // Here we have a family record.
if ($memberCount > 1) {
// Here we have a family record
$iFamilyID = $per_fam_ID;
$isFamily = true;

Expand Down Expand Up @@ -267,8 +257,6 @@
$sEmail = SelectWhichInfo($per_Email, $fam_Email, false);

if ($bDirAddress) {
// if (strlen($sAddress1)) { $OutStr .= $sAddress1 . "\n"; }
// if (strlen($sAddress2)) { $OutStr .= $sAddress2 . "\n"; }
if (strlen($sAddress1)) {
$OutStr .= $sAddress1;
}
Expand Down Expand Up @@ -317,7 +305,7 @@
$pdf->addHeader($sLastLetter);
}

// if photo include pass the id, otherwise 0 equates to no family/pers
// If photo include pass the ID, otherwise 0 equates to no family/person
$fid = 0;
$pid = 0;
if ($bDirPhoto) {
Expand All @@ -327,17 +315,17 @@
$pid = $per_ID;
}
}
$pdf->addRecord($pdf->sRecordName, $OutStr, $numlines, $fid, $pid); // another hack: added +1
$pdf->addRecord($pdf->sRecordName, $OutStr, $numlines, $fid, $pid);
}
}

if ($mysqlversion == 3 && $mysqlsubversion >= 22) {
$sSQL = 'DROP TABLE IF EXISTS tmp;';
mysqli_query($cnInfoCentral, $sSQL);
}
header('Pragma: public'); // Needed for IE when using a shared SSL certificate

if (SystemConfig::getValue('iPDFOutputType') == 1) {
// Needed for IE when using a shared SSL certificate
header('Pragma: public');
if ((int) SystemConfig::getValue('iPDFOutputType') === 1) {
$pdf->Output('Directory-' . date(SystemConfig::getValue('sDateFilenameFormat')) . '.pdf', 'D');
} else {
$pdf->Output();
Expand Down
54 changes: 24 additions & 30 deletions src/Reports/EnvelopeReport.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
<?php

/*******************************************************************************
*
* filename : Reports/EnvelopeReport.php
* description : Creates a report showing all envelope assignments
******************************************************************************/

namespace ChurchCRM\Reports;

require '../Include/Config.php';
require '../Include/Functions.php';

use ChurchCRM\Authentication\AuthenticationManager;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\model\ChurchCRM\Family;
use ChurchCRM\model\ChurchCRM\FamilyQuery;
use ChurchCRM\Utils\RedirectUtils;

// If CSVAdminOnly option is enabled and user is not admin, redirect to the menu.
// If CSVAdminOnly option is enabled and user is not admin, redirect to the menu
if (!AuthenticationManager::getCurrentUser()->isAdmin() && SystemConfig::getValue('bCSVAdminOnly')) {
RedirectUtils::redirect('v2/dashboard');
}

class PdfEnvelopeReport extends ChurchInfoReport
{
// Private properties
public $_Margin_Left = 12; // Left Margin
public $_Margin_Top = 12; // Top margin
public $_Char_Size = 12; // Character size
public $_Margin_Left = 12;
public $_Margin_Top = 12;
public $_Char_Size = 12;
public $_CurLine = 2;
public $_Column = 0;
public $_Font = 'Times';
Expand Down Expand Up @@ -59,11 +54,12 @@ public function __construct()
$this->setCharSize(12);
}

public function checkLines($numlines): void
public function checkLines(int $numlines): void
{
$CurY = $this->GetY(); // Temporarily store off the position
// Temporarily store off the position
$CurY = $this->GetY();

// Need to determine if we will extend beyoned 17mm from the bottom of
// Need to determine if we will extend beyond 17mm from the bottom of
// the page.
$this->SetY(-17);
if ($this->_Margin_Top + (($this->_CurLine + $numlines) * 5) > $this->GetY()) {
Expand All @@ -77,42 +73,40 @@ public function checkLines($numlines): void
$this->_CurLine = 2;
}
}
$this->SetY($CurY); // Put the position back
// Put the position back
$this->SetY($CurY);
}

// This function formats the string for a family
public function sGetFamilyString($aRow): string
public function sGetFamilyString(Family $family): string
{
extract($aRow); // Get a row from family_fam

return $fam_Envelope . ' ' . $this->makeSalutation($fam_ID);
return $family->getEnvelope() . ' ' . $this->makeSalutation($family->getId());
}

// Number of lines is only for the $text parameter
public function addRecord($text, $numlines): void
{
$numlines++; // add an extra blank line after record
// Add an extra blank line after record
$numlines++;
$this->checkLines($numlines);

$_PosX = $this->_Margin_Left + ($this->_Column * 108);
$_PosY = $this->_Margin_Top + ($this->_CurLine * 5);
$this->SetXY($_PosX, $_PosY);
$this->MultiCell(0, 5, $text); // set width to 0 prints to right margin
// Set width to 0 prints to right margin
$this->MultiCell(0, 5, $text);
$this->_CurLine += $numlines;
}
}

// Instantiate the directory class and build the report.
$pdf = new PdfEnvelopeReport();

$sSQL = 'SELECT fam_ID, fam_Envelope FROM family_fam WHERE fam_Envelope>0 ORDER BY fam_Envelope';
$rsRecords = RunQuery($sSQL);
$families = FamilyQuery::Create()->orderByEnvelope()->filterByEnvelope(0, 'Criteria::GREATER_THAN')->find();

while ($aRow = mysqli_fetch_array($rsRecords)) {
foreach ($families as $family) {
$OutStr = '';
extract($aRow);

$OutStr = $pdf->sGetFamilyString($aRow);
$OutStr = $pdf->sGetFamilyString($family);

// Count the number of lines in the output string
if (strlen($OutStr)) {
Expand All @@ -123,9 +117,9 @@ public function addRecord($text, $numlines): void

$pdf->addRecord($OutStr, $numlines);
}

header('Pragma: public'); // Needed for IE when using a shared SSL certificate
if (SystemConfig::getValue('iPDFOutputType') == 1) {
// Needed for IE when using a shared SSL certificate
header('Pragma: public');
if ((int) SystemConfig::getValue('iPDFOutputType') === 1) {
$pdf->Output('EnvelopeAssignments-' . date(SystemConfig::getValue('sDateFilenameFormat')) . '.pdf', 'D');
} else {
$pdf->Output();
Expand Down
Loading

0 comments on commit d707317

Please sign in to comment.