diff --git a/src/AddDonors.php b/src/AddDonors.php index 0c64c3d57b..b69446cbc0 100644 --- a/src/AddDonors.php +++ b/src/AddDonors.php @@ -45,7 +45,7 @@ $sSQL = "SELECT pn_per_id FROM paddlenum_pn WHERE pn_per_id='$donorID' AND pn_FR_ID = '$iFundRaiserID'"; $rsBuyer = RunQuery($sSQL); - if ($donorID > 0 && mysqli_num_rows($rsBuyer) == 0) { + if ($donorID > 0 && mysqli_num_rows($rsBuyer) === 0) { $sSQL = "INSERT INTO paddlenum_pn (pn_Num, pn_fr_ID, pn_per_ID) VALUES ('$extraPaddleNum', '$iFundRaiserID', '$donorID')"; RunQuery($sSQL); diff --git a/src/CartToGroup.php b/src/CartToGroup.php index 5d47299fac..e732bcf948 100644 --- a/src/CartToGroup.php +++ b/src/CartToGroup.php @@ -40,7 +40,7 @@ require 'Include/Header.php'; if (count($_SESSION['aPeopleCart']) > 0) { -?> + ?> diff --git a/src/ChurchCRM/Authentication/AuthenticationManager.php b/src/ChurchCRM/Authentication/AuthenticationManager.php index 3ea27810c1..73c4f3914f 100644 --- a/src/ChurchCRM/Authentication/AuthenticationManager.php +++ b/src/ChurchCRM/Authentication/AuthenticationManager.php @@ -61,9 +61,7 @@ public static function endSession(bool $preventRedirect = false): void $currentSessionUserName = 'Unknown'; try { - if (self::getCurrentUser() instanceof User) { - $currentSessionUserName = self::getCurrentUser()->getName(); - } + $currentSessionUserName = self::getCurrentUser()->getName(); } catch (\Exception $e) { //unable to get name of user logging out. Don't really care. } diff --git a/src/ChurchCRM/Backup/BackupDownloader.php b/src/ChurchCRM/Backup/BackupDownloader.php index 993c3b79f8..d1388cb1f5 100644 --- a/src/ChurchCRM/Backup/BackupDownloader.php +++ b/src/ChurchCRM/Backup/BackupDownloader.php @@ -32,9 +32,6 @@ public static function downloadBackup(string $filename): void $ext = strtolower($path_parts['extension']); switch ($ext) { case 'gz': - header('Content-type: application/x-gzip'); - header('Content-Disposition: attachment; filename="' . $path_parts['basename'] . '"'); - break; case 'tar.gz': header('Content-type: application/x-gzip'); header('Content-Disposition: attachment; filename="' . $path_parts['basename'] . '"'); diff --git a/src/ChurchCRM/Backup/BackupJob.php b/src/ChurchCRM/Backup/BackupJob.php index 427c41a46a..194c09bd0b 100644 --- a/src/ChurchCRM/Backup/BackupJob.php +++ b/src/ChurchCRM/Backup/BackupJob.php @@ -17,32 +17,13 @@ class BackupJob extends JobBase { private string $BackupFileBaseName; - private ?\SplFileInfo $BackupFile = null; - /** - * @var bool - */ - private $IncludeExtraneousFiles; - /** - * @var string - */ - public $BackupDownloadFileName; - /** - * @var bool - */ - public $shouldEncrypt; - - /** - * @var string - */ - public $BackupPassword; - - /** - * @param string $BaseName - * @param BackupType $BackupType - * @param bool $IncludeExtraneousFiles - */ - public function __construct(string $BaseName, $BackupType, $IncludeExtraneousFiles, $EncryptBackup, $BackupPassword) + private bool $IncludeExtraneousFiles; + public string $BackupDownloadFileName; + public bool $shouldEncrypt; + public string $BackupPassword; + + public function __construct(string $BaseName, string $BackupType, bool $IncludeExtraneousFiles, bool $EncryptBackup, string $BackupPassword) { $this->BackupType = $BackupType; $this->TempFolder = $this->createEmptyTempFolder(); diff --git a/src/ChurchCRM/Backup/JobBase.php b/src/ChurchCRM/Backup/JobBase.php index 92da13031b..c10d187064 100644 --- a/src/ChurchCRM/Backup/JobBase.php +++ b/src/ChurchCRM/Backup/JobBase.php @@ -8,13 +8,8 @@ class JobBase { - /** @var BackupType */ - protected $BackupType; - - /** - * @var string - */ - protected $TempFolder; + protected string $BackupType; + protected string $TempFolder; protected function createEmptyTempFolder(): string { diff --git a/src/ChurchCRM/Backup/RestoreJob.php b/src/ChurchCRM/Backup/RestoreJob.php index 24ca23bf00..144bc48fba 100644 --- a/src/ChurchCRM/Backup/RestoreJob.php +++ b/src/ChurchCRM/Backup/RestoreJob.php @@ -9,6 +9,7 @@ use ChurchCRM\SQLUtils; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\LoggerUtils; +use Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException; use Defuse\Crypto\File; use Exception; use PharData; @@ -17,15 +18,7 @@ class RestoreJob extends JobBase { private \SplFileInfo $RestoreFile; - - /** - * @var array - */ - public $Messages = []; - /** - * @var bool - */ - private $IsBackupEncrypted; + public array $Messages = []; private ?string $restorePassword = null; private function isIncomingFileFailed(): bool @@ -64,7 +57,7 @@ private function decryptBackup(): void File::decryptFileWithPassword($this->RestoreFile, $tempfile, $this->restorePassword); rename($tempfile, $this->RestoreFile); LoggerUtils::getAppLogger()->info('File decrypted'); - } catch (\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { + } catch (WrongKeyOrModifiedCiphertextException $ex) { if ($ex->getMessage() == 'Bad version header.') { LoggerUtils::getAppLogger()->info("Bad version header; this file probably wasn't encrypted"); } else { @@ -80,9 +73,9 @@ private function discoverBackupType(): void switch ($this->RestoreFile->getExtension()) { case 'gz': $basename = $this->RestoreFile->getBasename(); - if (substr($basename, strlen($basename) - 6, 6) == 'tar.gz') { + if (str_ends_with($basename, 'tar.gz')) { $this->BackupType = BackupType::FULL_BACKUP; - } elseif (substr($basename, strlen($basename) - 6, 6) == 'sql.gz') { + } elseif (str_ends_with($basename, 'sql.gz')) { $this->BackupType = BackupType::GZSQL; } break; diff --git a/src/ChurchCRM/Bootstrapper.php b/src/ChurchCRM/Bootstrapper.php index 4ff535efb9..ad21d69143 100644 --- a/src/ChurchCRM/Bootstrapper.php +++ b/src/ChurchCRM/Bootstrapper.php @@ -198,9 +198,9 @@ private static function isDatabaseEmpty(): bool $connection = Propel::getConnection(); $query = "SHOW TABLES FROM `" . self::$databaseName . "`"; $statement = $connection->prepare($query); - $resultset = $statement->execute(); + $statement->execute(); $results = $statement->fetchAll(\PDO::FETCH_ASSOC); - if (count($results) == 0) { + if (count($results) === 0) { self::$bootStrapLogger->debug("No database tables found"); return true; } diff --git a/src/ChurchCRM/Config/Menu/Menu.php b/src/ChurchCRM/Config/Menu/Menu.php index 674c140fdb..81c53613ff 100644 --- a/src/ChurchCRM/Config/Menu/Menu.php +++ b/src/ChurchCRM/Config/Menu/Menu.php @@ -12,7 +12,7 @@ class Menu { /** - * @var Config[] + * @var array|null */ private static ?array $menuItems = null; diff --git a/src/ChurchCRM/Config/Menu/MenuItem.php b/src/ChurchCRM/Config/Menu/MenuItem.php index 2b73e45069..49081cdd48 100644 --- a/src/ChurchCRM/Config/Menu/MenuItem.php +++ b/src/ChurchCRM/Config/Menu/MenuItem.php @@ -65,9 +65,6 @@ public function getName() return $this->name; } - /** - * @return bool - */ public function isExternal(): bool { return $this->external; diff --git a/src/ChurchCRM/Dashboard/EventsMenuItems.php b/src/ChurchCRM/Dashboard/EventsMenuItems.php index ce19bbdfe4..5f319d91d7 100644 --- a/src/ChurchCRM/Dashboard/EventsMenuItems.php +++ b/src/ChurchCRM/Dashboard/EventsMenuItems.php @@ -17,13 +17,11 @@ public static function getDashboardItemName(): string public static function getDashboardItemValue(): array { - $activeEvents = [ + return [ 'Events' => self::getNumberEventsOfToday(), 'Birthdays' => self::getNumberBirthDates(), 'Anniversaries' => self::getNumberAnniversaries(), ]; - - return $activeEvents; } public static function shouldInclude(string $PageName): bool @@ -48,8 +46,6 @@ private static function getNumberBirthDates() ->filterByBirthMonth(date('m')) ->filterByBirthDay(date('d')) ->count(); - - return $peopleWithBirthDays; } private static function getNumberAnniversaries() diff --git a/src/ChurchCRM/MICRFunctions.php b/src/ChurchCRM/MICRFunctions.php index ceab2cd540..e6566ce09d 100644 --- a/src/ChurchCRM/MICRFunctions.php +++ b/src/ChurchCRM/MICRFunctions.php @@ -6,24 +6,24 @@ class MICRFunctions { - public $CHECKNO_FIRST = 1; // oo tt o - public $ROUTE_FIRST1 = 2; // tt o - public $ROUTE_FIRST2 = 3; // tt oo - public $NOT_RECOGNIZED = 4; + public int $CHECKNO_FIRST = 1; // oo tt o + public int $ROUTE_FIRST1 = 2; // tt o + public int $ROUTE_FIRST2 = 3; // tt oo + public int $NOT_RECOGNIZED = 4; - public function identifyFormat($micr) + public function identifyFormat(string $micr): int { // t000000000t0000o0000000000000o ROUTE_FIRST2 // t000000000t 0000000000o 0000 ROUTE_FIRST1 // o000000o t000000000t 0000000000o CHECKNO_FIRST $firstChar = mb_substr($micr, 0, 1); - if ($firstChar == 'o') { + if ($firstChar === 'o') { return $this->CHECKNO_FIRST; } elseif ($firstChar == 't') { $firstSmallO = strpos($micr, 'o'); $secondSmallO = strrpos($micr, 'o'); - if ($firstSmallO == $secondSmallO) { + if ($firstSmallO === $secondSmallO) { // Only one 'o' $len = strlen($micr); if ($len - $firstSmallO > 12) { @@ -35,9 +35,11 @@ public function identifyFormat($micr) return $this->ROUTE_FIRST2; } } + + throw new \InvalidArgumentException('Unknown format provided'); } - public function findRoute($micr): string + public function findRoute(string $micr): string { $routeAndAccount = $this->findRouteAndAccount($micr); $breakChar = strpos($routeAndAccount, 't', 1); @@ -45,7 +47,7 @@ public function findRoute($micr): string return mb_substr($micr, 1, $breakChar - 1); } - public function findAccount($micr): string + public function findAccount(string $micr): string { $routeAndAccount = $this->findRouteAndAccount($micr); $breakChar = strpos($routeAndAccount, 't', 1); @@ -53,7 +55,7 @@ public function findAccount($micr): string return mb_substr($routeAndAccount, $breakChar + 1, strlen($micr) - $breakChar); } - public function findRouteAndAccount($micr) + public function findRouteAndAccount(string $micr): string { $formatID = $this->identifyFormat($micr); @@ -78,7 +80,7 @@ public function findRouteAndAccount($micr) } } - public function findCheckNo($micr) + public function findCheckNo(string $micr): string { $formatID = $this->identifyFormat($micr); if ($formatID == $this->CHECKNO_FIRST) { diff --git a/src/ChurchCRM/Reports/ChurchInfoReport.php b/src/ChurchCRM/Reports/ChurchInfoReport.php index 30c028d211..a991eeb8d9 100644 --- a/src/ChurchCRM/Reports/ChurchInfoReport.php +++ b/src/ChurchCRM/Reports/ChurchInfoReport.php @@ -51,7 +51,6 @@ public function printRightJustified($x, $y, $str): void public function printRightJustifiedCell($x, $y, $wid, $str): void { $strconv = iconv('UTF-8', 'ISO-8859-1', $str); - $iLen = strlen($strconv); $this->SetXY($x, $y); $this->Cell($wid, SystemConfig::getValue('incrementY'), $strconv, 1, 0, 'R'); } @@ -59,7 +58,6 @@ public function printRightJustifiedCell($x, $y, $wid, $str): void public function printCenteredCell($x, $y, $wid, $str): void { $strconv = iconv('UTF-8', 'ISO-8859-1', $str); - $iLen = strlen($strconv); $this->SetXY($x, $y); $this->Cell($wid, SystemConfig::getValue('incrementY'), $strconv, 1, 0, 'C'); } @@ -119,10 +117,9 @@ public function startLetterPage($fam_ID, $fam_Name, $fam_Address1, $fam_Address2 if ($fam_Country != '' && $fam_Country != SystemConfig::getValue('sDefaultCountry')) { $this->writeAt(SystemConfig::getValue('leftX'), $curY, $fam_Country); $curY += SystemConfig::getValue('incrementY'); - } - $curY += 5.0; // mm to get away from the second window + } // mm to get away from the second window - return $curY; + return $curY + 5.0; } public function makeSalutation($famID): string diff --git a/src/ChurchCRM/Reports/PDF_AddressReport.php b/src/ChurchCRM/Reports/PDF_AddressReport.php index 63ab79704c..a30e697121 100644 --- a/src/ChurchCRM/Reports/PDF_AddressReport.php +++ b/src/ChurchCRM/Reports/PDF_AddressReport.php @@ -9,10 +9,7 @@ class PdfAddressReport extends ChurchInfoReport private int $_Margin_Top = 12; // Top margin private int $_Char_Size = 12; // Character size private int $_CurLine = 2; - private int $_Column = 0; private string $_Font = 'Times'; - private $sFamily; - private $sLastName; private function numLinesInFpdfCell(int $w, $txt): int { diff --git a/src/ChurchCRM/Reports/PDF_Attendance.php b/src/ChurchCRM/Reports/PDF_Attendance.php index 0652780a0d..70ae5ae9f1 100644 --- a/src/ChurchCRM/Reports/PDF_Attendance.php +++ b/src/ChurchCRM/Reports/PDF_Attendance.php @@ -2,6 +2,8 @@ namespace ChurchCRM\Reports; +use ChurchCRM\Utils\LoggerUtils; + class PdfAttendance extends ChurchInfoReport { public function __construct() @@ -35,22 +37,22 @@ public function drawAttendanceCalendar( array $imgs, $with_img ) { + $logger = LoggerUtils::getAppLogger(); $startMonthX = 60; $dayWid = 7; if ($with_img) { - $yIncrement = 10; // normally 6 + $yIncrement = 10; } else { $yIncrement = 6; } $yTitle = 20; - $yTeachers = $yTitle + $yIncrement; $nameX = 10 + $yIncrement / 2; $numMembers = 0; $aNameCount = 0; - $MaxLinesPerPage = -5 * $yIncrement + 66; // 36 lines for a yIncrement of 6, 16 lines for a yIncrement of 10, y=-5x+66 + $MaxLinesPerPage = -5 * $yIncrement + 66; // 36 lines for a yIncrement of 6, 16 lines for a yIncrement of 10, y=-5x+66 $fontTitleTitle = 16; @@ -63,34 +65,30 @@ public function drawAttendanceCalendar( $aNoSchoolX = []; $noSchoolCnt = 0; -// - // determine how many pages will be includes in this report -// + // Determine how many pages will be includes in this report -// // First cull the input names array to remove duplicates, then extend the array to include the requested // number of blank lines -// $prevThisName = ''; $aNameCount = 0; $NameList = []; + $imgList = []; for ($row = 0; $row < count($aNames); $row++) { $person = $aNames[$row]; $thisName = $person->getFullName(); - // Special handling for person listed twice- only show once in the Attendance Calendar + // Special handling for a person listed twice -- only show once in the Attendance Calendar // This happens when a child is listed in two different families (parents divorced and // both active in the church) - if ($thisName != $prevThisName) { + if ($thisName !== $prevThisName) { $NameList[$aNameCount] = $thisName; $imgList[$aNameCount++] = $imgs[$row]; - // echo "adding {$thisName} to NameList at {$aNameCount}\n\r"; + $logger->debug("Adding {$thisName} to NameList at {$aNameCount}"); } $prevThisName = $thisName; } -// - // add extra blank lines to the array -// + + // Add extra blank lines to the array for ($i = 0; $i < $extraLines; $i++) { $NameList[$aNameCount] = ' '; $imgList[$aNameCount++] = ''; @@ -98,15 +96,13 @@ public function drawAttendanceCalendar( $numMembers = count($NameList); $nPages = ceil($numMembers / $MaxLinesPerPage); + $logger->debug("nPages = {$nPages}"); + + $bottomY = 0; - // echo "nPages = {$nPages} \n\r"; - // // Main loop which draws each page - // for ($p = 0; $p < $nPages; $p++) { - // - // Paint the title section- class name and year on the top, then teachers/liaison - // + // Paint the title section: class name and year on the top, then teachers/liaison if ($p > 0) { $this->addPage(); } @@ -114,44 +110,36 @@ public function drawAttendanceCalendar( $this->writeAt($nameX, $yTitle, $rptHeader); $this->SetLineWidth(0.5); - //$this->Line($nameX-5, $yTeachers - 0.45, 195, $yTeachers - 0.45); // unusefull $yMonths = $yTop; $yDays = $yTop + $yIncrement; $y = $yDays + $yIncrement; - // - // put title on the page - // + + // Put title on the page $this->SetFont('Times', 'B', $fontTitleNormal); $this->writeAt($nameX, $yDays + 1, $tTitle); $this->SetFont('Times', '', $fontTitleNormal); - // - // calculate the starting and ending rows for the page - // + // Calculate the starting and ending rows for the page $pRowStart = $p * $MaxLinesPerPage; $pRowEnd = min(($p + 1) * $MaxLinesPerPage, $numMembers); - // echo "pRowStart = {$pRowStart} and pRowEnd= {$pRowEnd}\n\r"; - // - // Write the names down the page and draw lines between - // + $logger->debug("pRowStart = {$pRowStart} and pRowEnd = {$pRowEnd}"); + // Write the names down the page and draw lines between $this->SetLineWidth(0.25); for ($row = $pRowStart; $row < $pRowEnd; $row++) { $this->writeAt($nameX, $y + (($with_img == true) ? 3 : 1), $NameList[$row]); if ($with_img == true) { - //$this->SetLineWidth(0.5); $this->Line($nameX - $yIncrement, $y, $nameX, $y); $this->Line($nameX - $yIncrement, $y + $yIncrement, $nameX, $y + $yIncrement); $this->Line($nameX - $yIncrement, $y, $nameX, $y); $this->Line($nameX - $yIncrement, $y, $nameX - $yIncrement, $y + $yIncrement); - // we build the cross in the case of there's no photo - //$this->SetLineWidth(0.25); + // We build the cross in case there's no photo $this->Line($nameX - $yIncrement, $y + $yIncrement, $nameX, $y); $this->Line($nameX - $yIncrement, $y, $nameX, $y + $yIncrement); - if ($NameList[$row] != ' ' && strlen($imgList[$row]) > 5 && file_exists($imgList[$row])) { + if ($NameList[$row] != ' ' && strlen($imgList[$row]) > 5 && is_file($imgList[$row])) { [$width, $height] = getimagesize($imgList[$row]); $factor = $yIncrement / $height; $nw = $width * $factor; @@ -163,24 +151,22 @@ public function drawAttendanceCalendar( $y += $yIncrement; } - // - // write a totals text at the bottom - // + + // Write a totals text at the bottom $this->SetFont('Times', 'B', $fontTitleNormal); $this->writeAt($nameX, $y + 1, gettext('Totals')); $this->SetFont('Times', '', $fontTitleNormal); $bottomY = $y + $yIncrement; - // + // Paint the calendar grid - // $dayCounter = 0; - $monthCounter = 0; $dayX = $startMonthX; $monthX = $startMonthX; $noSchoolCnt = 0; $heavyVerticalXCnt = 0; $lightVerticalXCnt = 0; + $aLightVerticalX = []; $tWhichSunday = $tFirstSunday; $dWhichSunday = strtotime($tWhichSunday); @@ -188,9 +174,8 @@ public function drawAttendanceCalendar( $dWhichMonthDate = $dWhichSunday; $whichMonth = date('n', $dWhichMonthDate); - $doneFlag = false; - - while (!$doneFlag) { + $bInProgressFlag = true; + while ($bInProgressFlag) { $dayListX[$dayCounter] = $dayX; $dayListNum[$dayCounter] = date('d', $dWhichSunday); @@ -220,7 +205,8 @@ public function drawAttendanceCalendar( $aNoSchoolX[$noSchoolCnt++] = $dayX; } - if (date('n', $dWhichSunday) != $whichMonth) { // Finish the previous month + // Finish the previous month + if (date('n', $dWhichSunday) != $whichMonth) { $this->writeAt($monthX, $yMonths + 1, mb_substr(gettext(date('F', $dWhichMonthDate)), 0, 3)); $aHeavyVerticalX[$heavyVerticalXCnt++] = $monthX; $whichMonth = date('n', $dWhichSunday); @@ -232,17 +218,12 @@ public function drawAttendanceCalendar( $dayX += $dayWid; $dayCounter++; - // if ($tWhichSunday == $tLastSunday) $doneFlag = true; - // - // replaced this conditional to correct a problem where begin and end dates were not the same - // day of week - // if (strtotime($tWhichSunday) >= strtotime($tLastSunday)) { - $doneFlag = true; + // Done - set flag for end of while loop + $bInProgressFlag = false; } - // Increment the date by one week - // + // Increment the date by one week $sundayDay = date('d', $dWhichSunday); $sundayMonth = date('m', $dWhichSunday); $sundayYear = date('Y', $dWhichSunday); @@ -299,16 +280,13 @@ public function drawAttendanceCalendar( $yBottom = $yMonths + (($numMembers + $extraLines + 2) * $yIncrement); $this->Line($nameX, $yBottom, $rightEdgeX, $yBottom); $this->Line($nameX, $yBottom + $yIncrement, $rightEdgeX, $yBottom + $yIncrement); - // - // add in horizontal lines between names - // + + // Add in horizontal lines between names $y = $yTop; for ($s = $pRowStart; $s < $pRowEnd + 4; $s++) { $this->Line($nameX, $y, $rightEdgeX, $y); $y += $yIncrement; } - - //$this->addPage(); } return $bottomY; diff --git a/src/ChurchCRM/Reports/PDF_Directory.php b/src/ChurchCRM/Reports/PDF_Directory.php index 38bb534a7d..a0bfec38c3 100644 --- a/src/ChurchCRM/Reports/PDF_Directory.php +++ b/src/ChurchCRM/Reports/PDF_Directory.php @@ -345,7 +345,7 @@ public function sGetFamilyString($aRow): string // This function formats the string for the head of household. // NOTE: This is used for the Head AND Spouse (called twice) - public function sGetHeadString($rsCustomFields, $aHead) + public function sGetHeadString($rsCustomFields, $aHead): string { global $bDirBirthday; global $bDirPersonalPhone; diff --git a/src/ChurchCRM/SQLUtils.php b/src/ChurchCRM/SQLUtils.php index 56baa39995..36dfeb3209 100644 --- a/src/ChurchCRM/SQLUtils.php +++ b/src/ChurchCRM/SQLUtils.php @@ -8,7 +8,7 @@ class SQLUtils /** * Import SQL from file. * - * @param string path to sql file + * @param string $fileName path to sql file */ public static function sqlImport(string $fileName, $mysqli): void { @@ -71,8 +71,7 @@ public static function sqlImport(string $fileName, $mysqli): void /** * Remove comments from sql. * - * @param string sql - * @param bool is multicomment line + * @param bool $isMultiComment is multicomment line * * @return string */ @@ -94,7 +93,7 @@ private static function clearSQL($sql, &$isMultiComment) while (preg_match('{--\s|#|/\*[^!]}sUi', $sql, $matched, PREG_OFFSET_CAPTURE, $offset)) { [$comment, $foundOn] = $matched[0]; if (self::isQuoted($foundOn, $sql)) { - $offset = $foundOn + strlen($comment); + $offset = (int) $foundOn + strlen($comment); } else { if (mb_substr($comment, 0, 2) == '/*') { $closedOn = strpos($sql, '*/', $foundOn); @@ -116,13 +115,8 @@ private static function clearSQL($sql, &$isMultiComment) /** * Check if "offset" position is quoted. - * - * @param int $offset - * @param string $text - * - * @return bool */ - private static function isQuoted($offset, $text): bool + private static function isQuoted(int $offset, string $text): bool { if ($offset > strlen($text)) { $offset = strlen($text); @@ -141,7 +135,7 @@ private static function isQuoted($offset, $text): bool return $isQuoted; } - private static function query($sql, $mysqli): void + private static function query(string $sql, $mysqli): void { if (preg_match("/DEFINER\s*=.*@.*/", $sql)) { return; diff --git a/src/ChurchCRM/Search/AddressSearchResultProvider.php b/src/ChurchCRM/Search/AddressSearchResultProvider.php index f22c0a91e4..a5b0848513 100644 --- a/src/ChurchCRM/Search/AddressSearchResultProvider.php +++ b/src/ChurchCRM/Search/AddressSearchResultProvider.php @@ -12,10 +12,9 @@ class AddressSearchResultProvider extends BaseSearchResultProvider public function __construct() { $this->pluralNoun = 'Address'; - parent::__construct(); } - public function getSearchResults(string $SearchQuery) + public function getSearchResults(string $SearchQuery): SearchResultGroup { if (SystemConfig::getBooleanValue('bSearchIncludeAddresses')) { $this->addSearchResults($this->getPersonSearchResultsByPartialAddress($SearchQuery)); @@ -34,15 +33,20 @@ private function getPersonSearchResultsByPartialAddress(string $SearchQuery): ar try { $searchLikeString = '%' . $SearchQuery . '%'; - $addresses = FamilyQuery::create()-> - filterByCity($searchLikeString, Criteria::LIKE)-> - _or()->filterByAddress1($searchLikeString, Criteria::LIKE)-> - _or()->filterByAddress2($searchLikeString, Criteria::LIKE)-> - _or()->filterByZip($searchLikeString, Criteria::LIKE)-> - _or()->filterByState($searchLikeString, Criteria::LIKE)-> - limit(SystemConfig::getValue('bSearchIncludeAddressesMax'))->find(); - - if (!empty($addresses)) { + $addresses = FamilyQuery::create() + ->filterByCity($searchLikeString, Criteria::LIKE) + ->_or() + ->filterByAddress1($searchLikeString, Criteria::LIKE) + ->_or() + ->filterByAddress2($searchLikeString, Criteria::LIKE) + ->_or() + ->filterByZip($searchLikeString, Criteria::LIKE) + ->_or() + ->filterByState($searchLikeString, Criteria::LIKE) + ->limit(SystemConfig::getValue('bSearchIncludeAddressesMax')) + ->find(); + + if ($addresses->count() > 0) { $id++; foreach ($addresses as $address) { $searchResults[] = new SearchResult('person-address-' . $id, $address->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $address->getViewURI()); diff --git a/src/ChurchCRM/Search/BaseSearchResultProvider.php b/src/ChurchCRM/Search/BaseSearchResultProvider.php index d098b27e2f..e6aaa7199c 100644 --- a/src/ChurchCRM/Search/BaseSearchResultProvider.php +++ b/src/ChurchCRM/Search/BaseSearchResultProvider.php @@ -4,28 +4,20 @@ abstract class BaseSearchResultProvider { - /* @var string */ - protected $pluralNoun; - /* @var ChurchCRM\Search\SearchResult[] */ - protected $searchResults = []; + protected string $pluralNoun; - abstract public function getSearchResults(string $SearchQuery); + /* @var SearchResult[] */ + protected array $searchResults = []; - protected function formatSearchGroup() - { - if (!empty($this->searchResults)) { - return new SearchResultGroup(gettext($this->pluralNoun) . ' (' . count($this->searchResults) . ')', $this->searchResults); - } - - return []; - } + abstract public function getSearchResults(string $SearchQuery): SearchResultGroup; - protected function addSearchResults(array $results) + protected function formatSearchGroup(): SearchResultGroup { - $this->searchResults = array_merge($this->searchResults, $results); + return new SearchResultGroup(gettext($this->pluralNoun) . ' (' . count($this->searchResults) . ')', $this->searchResults); } - protected function __construct() + protected function addSearchResults(array $results): void { + $this->searchResults = array_merge($this->searchResults, $results); } } diff --git a/src/ChurchCRM/Search/CalendarEventSearchResultProvider.php b/src/ChurchCRM/Search/CalendarEventSearchResultProvider.php index 4c912fe4a5..29ace3674c 100644 --- a/src/ChurchCRM/Search/CalendarEventSearchResultProvider.php +++ b/src/ChurchCRM/Search/CalendarEventSearchResultProvider.php @@ -12,10 +12,9 @@ class CalendarEventSearchResultProvider extends BaseSearchResultProvider public function __construct() { $this->pluralNoun = 'Calendar Events'; - parent::__construct(); } - public function getSearchResults(string $SearchQuery) + public function getSearchResults(string $SearchQuery): SearchResultGroup { if (SystemConfig::getBooleanValue('bSearchIncludeCalendarEvents')) { $this->addSearchResults($this->getCalendarEventSearchResultsByPartialName($SearchQuery)); @@ -41,7 +40,7 @@ private function getCalendarEventSearchResultsByPartialName(string $SearchQuery) ->filterByDesc("%$SearchQuery%", Criteria::LIKE) ->limit(SystemConfig::getValue('bSearchIncludeGroupsMax')) ->find(); - if (!empty($events)) { + if ($events->count() > 0) { $id++; foreach ($events as $event) { $searchResults[] = new SearchResult('event-name-' . $id, $event->getTitle(), $event->getViewURI()); diff --git a/src/ChurchCRM/Search/FamilySearchResultProvider.php b/src/ChurchCRM/Search/FamilySearchResultProvider.php index bb28b09190..849325e1fd 100644 --- a/src/ChurchCRM/Search/FamilySearchResultProvider.php +++ b/src/ChurchCRM/Search/FamilySearchResultProvider.php @@ -13,12 +13,10 @@ class FamilySearchResultProvider extends BaseSearchResultProvider public function __construct() { $this->pluralNoun = 'Families'; - parent::__construct(); } - public function getSearchResults(string $SearchQuery) + public function getSearchResults(string $SearchQuery): SearchResultGroup { - $searchResults = []; if (SystemConfig::getBooleanValue('bSearchIncludeFamilies')) { $this->addSearchResults($this->getFamilySearchResultsByPartialName($SearchQuery)); } @@ -38,15 +36,21 @@ private function getFamilySearchResultsByPartialName(string $SearchQuery): array $id = 0; try { - $families = FamilyQuery::create()-> - filterByName("%$SearchQuery%", Criteria::LIKE)-> - _or()->filterByHomePhone("%$SearchQuery%", Criteria::LIKE)-> - _or()->filterByEmail("%$SearchQuery%", Criteria::LIKE)-> - _or()->filterByCellPhone("%$SearchQuery%", Criteria::LIKE)-> - _or()->filterByWorkPhone("%$SearchQuery%", Criteria::LIKE)-> - limit(SystemConfig::getValue('bSearchIncludeFamiliesMax'))->find(); + $families = FamilyQuery::create() + ->filterByName("%$SearchQuery%", Criteria::LIKE) + ->_or() + ->filterByHomePhone("%$SearchQuery%", Criteria::LIKE) + ->_or() + ->filterByEmail("%$SearchQuery%", Criteria::LIKE) + ->_or() + ->filterByCellPhone("%$SearchQuery%", Criteria::LIKE) + ->_or() + ->filterByWorkPhone("%$SearchQuery%", Criteria::LIKE) + ->limit(SystemConfig::getValue('bSearchIncludeFamiliesMax')) + ->find(); + - if (!empty($families)) { + if ($families->count() > 0) { $id++; foreach ($families as $family) { $searchResults[] = new SearchResult('family-name-' . $id, $family->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), $family->getViewURI()); @@ -55,7 +59,8 @@ private function getFamilySearchResultsByPartialName(string $SearchQuery): array return $searchResults; } catch (\Exception $e) { - LoggerUtils::getAppLogger()->warning($e->getMessage()); + LoggerUtils::getAppLogger()->warning($e->getMessage(), ['exception' => $e]); + throw $e; } } diff --git a/src/ChurchCRM/Search/FinanceDepositSearchResultProvider.php b/src/ChurchCRM/Search/FinanceDepositSearchResultProvider.php index 77b0525075..0d6237c0d4 100644 --- a/src/ChurchCRM/Search/FinanceDepositSearchResultProvider.php +++ b/src/ChurchCRM/Search/FinanceDepositSearchResultProvider.php @@ -14,10 +14,9 @@ class FinanceDepositSearchResultProvider extends BaseSearchResultProvider public function __construct() { $this->pluralNoun = 'Deposits'; - parent::__construct(); } - public function getSearchResults(string $SearchQuery) + public function getSearchResults(string $SearchQuery): SearchResultGroup { if (AuthenticationManager::getCurrentUser()->isFinanceEnabled()) { if (SystemConfig::getBooleanValue('bSearchIncludeDeposits')) { @@ -44,7 +43,7 @@ private function getDepositSearchResults(string $SearchQuery): array ->withColumn('CONCAT("' . SystemURLs::getRootPath() . '/DepositSlipEditor.php?DepositSlipID=",Deposit.Id)', 'uri') ->limit(SystemConfig::getValue('bSearchIncludeDepositsMax'))->find(); - if (!empty($Deposits)) { + if ($Deposits->count() > 0) { $id++; foreach ($Deposits->toArray() as $Deposit) { $searchResults[] = new SearchResult('finance-deposit-' . $id, $Deposit['displayName'], $Deposit['uri']); diff --git a/src/ChurchCRM/Search/FinancePaymentSearchResultProvider.php b/src/ChurchCRM/Search/FinancePaymentSearchResultProvider.php index 0fab5814eb..33d99b850f 100644 --- a/src/ChurchCRM/Search/FinancePaymentSearchResultProvider.php +++ b/src/ChurchCRM/Search/FinancePaymentSearchResultProvider.php @@ -14,10 +14,9 @@ class FinancePaymentSearchResultProvider extends BaseSearchResultProvider public function __construct() { $this->pluralNoun = 'Payments'; - parent::__construct(); } - public function getSearchResults(string $SearchQuery) + public function getSearchResults(string $SearchQuery): SearchResultGroup { if (AuthenticationManager::getCurrentUser()->isFinanceEnabled()) { if (SystemConfig::getBooleanValue('bSearchIncludePayments')) { @@ -49,7 +48,7 @@ private function getPaymentsWithValuesInRange(int $min, int $max): array ->groupByGroupKey() ->find(); - if (!empty($Payments)) { + if ($Payments->count() > 0) { $id++; foreach ($Payments as $Payment) { // I can't seem to get the SQL HAVING clause to work through Propel ORM to use @@ -83,7 +82,7 @@ private function getPaymentSearchResults(string $SearchQuery): array ->groupByGroupKey() ->find(); - if (!empty($Payments)) { + if ($Payments->count() > 0) { $id++; foreach ($Payments as $Payment) { $searchResults[] = new SearchResult('finance-payment-' . $id, 'Check ' . $Payment->getCheckNo() . ' on Deposit ' . $Payment->getDepId(), $Payment->getVirtualColumn('uri')); diff --git a/src/ChurchCRM/Search/GroupSearchResultProvider.php b/src/ChurchCRM/Search/GroupSearchResultProvider.php index 1c3068aa75..4b54092376 100644 --- a/src/ChurchCRM/Search/GroupSearchResultProvider.php +++ b/src/ChurchCRM/Search/GroupSearchResultProvider.php @@ -12,10 +12,9 @@ class GroupSearchResultProvider extends BaseSearchResultProvider public function __construct() { $this->pluralNoun = 'Groups'; - parent::__construct(); } - public function getSearchResults(string $SearchQuery) + public function getSearchResults(string $SearchQuery): SearchResultGroup { if (SystemConfig::getBooleanValue('bSearchIncludeGroups')) { $this->addSearchResults($this->getPersonSearchResultsByPartialName($SearchQuery)); @@ -37,7 +36,7 @@ private function getPersonSearchResultsByPartialName(string $SearchQuery): array ->filterByName("%$SearchQuery%", Criteria::LIKE) ->limit(SystemConfig::getValue('bSearchIncludeGroupsMax')) ->find(); - if (!empty($groups)) { + if ($groups->count() > 0) { $id++; foreach ($groups as $group) { $searchResults[] = new SearchResult('group-name-' . $id, $group->getName(), $group->getViewURI()); diff --git a/src/ChurchCRM/Search/PersonSearchResultProvider.php b/src/ChurchCRM/Search/PersonSearchResultProvider.php index 060bc920cb..aaef203a15 100644 --- a/src/ChurchCRM/Search/PersonSearchResultProvider.php +++ b/src/ChurchCRM/Search/PersonSearchResultProvider.php @@ -12,10 +12,9 @@ class PersonSearchResultProvider extends BaseSearchResultProvider public function __construct() { $this->pluralNoun = 'Persons'; - parent::__construct(); } - public function getSearchResults(string $SearchQuery) + public function getSearchResults(string $SearchQuery): SearchResultGroup { if (SystemConfig::getBooleanValue('bSearchIncludePersons')) { $this->addSearchResults($this->getPersonSearchResultsByPartialName($SearchQuery)); @@ -45,7 +44,7 @@ private function getPersonSearchResultsByPartialName(string $SearchQuery): array _or()->filterByWorkPhone($searchLikeString, Criteria::LIKE)-> limit(SystemConfig::getValue('bSearchIncludePersonsMax'))->find(); - if (!empty($people)) { + if ($people->count() > 0) { $id++; foreach ($people as $person) { $searchResults[] = new SearchResult('person-name-' . $id, $person->getFullName(), $person->getViewURI()); diff --git a/src/ChurchCRM/Search/SearchResultGroup.php b/src/ChurchCRM/Search/SearchResultGroup.php index 52762c7cb0..a2dc0b91be 100644 --- a/src/ChurchCRM/Search/SearchResultGroup.php +++ b/src/ChurchCRM/Search/SearchResultGroup.php @@ -4,8 +4,8 @@ class SearchResultGroup implements \JsonSerializable { - private string $groupName; - private array $results; + public string $groupName; + public array $results; public function __construct(string $groupName, array $results) { diff --git a/src/ChurchCRM/Service/AppIntegrityService.php b/src/ChurchCRM/Service/AppIntegrityService.php index 6b0dc54158..cb06a3fcdb 100644 --- a/src/ChurchCRM/Service/AppIntegrityService.php +++ b/src/ChurchCRM/Service/AppIntegrityService.php @@ -184,8 +184,8 @@ private static function verifyDirectoryWriteable(string $path): bool */ public static function getApplicationPrerequisites(): array { - $prerequisites = [ - new Prerequisite('PHP 8.1+', fn () => version_compare(PHP_VERSION, '8.1.0', '>=')), + return [ + new Prerequisite('PHP 8.1+', fn (): bool => version_compare(PHP_VERSION, '8.1.0', '>=')), new Prerequisite('PCRE and UTF-8 Support', fn (): bool => function_exists('preg_match') && @preg_match('/^.$/u', 'ñ') && @preg_match('/^\pL$/u', 'ñ')), new Prerequisite('Multibyte Encoding', fn (): bool => extension_loaded('mbstring')), new Prerequisite('PHP Phar', fn (): bool => extension_loaded('phar')), @@ -206,8 +206,6 @@ public static function getApplicationPrerequisites(): array new Prerequisite('PHP ZipArchive', fn (): bool => extension_loaded('zip')), new Prerequisite('Mysqli Functions', fn (): bool => function_exists('mysqli_connect')), ]; - - return $prerequisites; } /** @@ -258,7 +256,7 @@ public static function hasModRewrite(): bool $header['status'] = $line; } - list($key, $value) = explode(': ', $line); + [$key, $value] = explode(': ', $line); $header[$key] = $value; } diff --git a/src/ChurchCRM/Service/DashboardService.php b/src/ChurchCRM/Service/DashboardService.php index 3c57d7d204..dc4202b38c 100644 --- a/src/ChurchCRM/Service/DashboardService.php +++ b/src/ChurchCRM/Service/DashboardService.php @@ -34,9 +34,8 @@ public function getFamilyCount(): array $familyCount = FamilyQuery::Create() ->filterByDateDeactivated() ->count(); - $data = ['familyCount' => $familyCount]; - return $data; + return ['familyCount' => $familyCount]; } public function getPersonCount(): array @@ -46,9 +45,8 @@ public function getPersonCount(): array ->filterByDateDeactivated(null) ->endUse() ->count(); - $data = ['personCount' => $personCount]; - return $data; + return ['personCount' => $personCount]; } /** @@ -93,9 +91,8 @@ public function getGroupStats(): array '; $rsQuickStat = RunQuery($sSQL); $row = mysqli_fetch_array($rsQuickStat); - $data = ['groups' => $row['Group_cnt'], 'sundaySchoolClasses' => $row['SundaySchoolClasses'], 'sundaySchoolkids' => $row['SundaySchoolKidsCount']]; - return $data; + return ['groups' => $row['Group_cnt'], 'sundaySchoolClasses' => $row['SundaySchoolClasses'], 'sundaySchoolkids' => $row['SundaySchoolKidsCount']]; } /** diff --git a/src/ChurchCRM/Service/FinancialService.php b/src/ChurchCRM/Service/FinancialService.php index df00e2bc10..4d6c709434 100644 --- a/src/ChurchCRM/Service/FinancialService.php +++ b/src/ChurchCRM/Service/FinancialService.php @@ -17,13 +17,13 @@ class FinancialService { - public function deletePayment($groupKey): void + public function deletePayment(string $groupKey): void { requireUserGroupMembership('bFinance'); PledgeQuery::create()->findOneByGroupKey($groupKey)->delete(); } - public function getMemberByScanString($tScanString): array + public function getMemberByScanString(string $tScanString): array { requireUserGroupMembership('bFinance'); @@ -175,9 +175,9 @@ private function validateFund(array $payment): void //If a single fund is selected, that fund must exist, and not equal the default "Select a Fund" selection. //If a split is selected, at least one fund must be non-zero, the total must add up to the total of all funds, and all funds in the split must be valid funds. $FundSplit = $payment['FundSplit']; - if (count($FundSplit) >= 1 && $FundSplit[0]->FundID != 'None') { // split + if (count($FundSplit) >= 1 && $FundSplit[0]->FundID !== 'None') { // split $nonZeroFundAmountEntered = 0; - foreach ($FundSplit as $fun_id => $fund) { + foreach ($FundSplit as $fund) { //$fun_active = $fundActive[$fun_id]; if ($fund->Amount > 0) { $nonZeroFundAmountEntered++; @@ -234,10 +234,8 @@ public function processCurrencyDenominations($payment, string $groupKey): void foreach ($currencyDenoms as $cdom) { $sSQL = "INSERT INTO pledge_denominations_pdem (pdem_plg_GroupKey, plg_depID, pdem_denominationID, pdem_denominationQuantity) VALUES ('" . $groupKey . "','" . $payment->DepositID . "','" . $cdom->currencyID . "','" . $cdom->Count . "')"; - if (isset($sSQL)) { - RunQuery($sSQL); - unset($sSQL); - } + RunQuery($sSQL); + unset($sSQL); } } @@ -344,209 +342,6 @@ public function getPledgeorPayment(string $GroupKey): string return json_encode($payment, JSON_THROW_ON_ERROR); } - private function generateBankDepositSlip($thisReport): void - { - // -------------------------------- - // BEGIN FRONT OF BANK DEPOSIT SLIP - $thisReport->pdf->addPage('L', [187, 84]); - $thisReport->pdf->SetFont('Courier', '', 18); - // Print Deposit Slip portion of report - - $thisReport->pdf->SetXY($thisReport->date1X, $thisReport->date1Y); - $thisReport->pdf->Write(8, $thisReport->deposit->dep_Date); - - $thisReport->pdf->SetXY($thisReport->customerName1X, $thisReport->customerName1Y); - $thisReport->pdf->Write(8, SystemConfig::getValue('sChurchName')); - - $thisReport->pdf->SetXY($thisReport->AccountNumberX, $thisReport->AccountNumberY); - $thisReport->pdf->Cell(55, 7, SystemConfig::getValue('sChurchChkAcctNum'), 1, 1, 'R'); - - if ($thisReport->deposit->totalCash > 0) { - $totalCashStr = sprintf('%.2f', $thisReport->deposit->totalCash); - $thisReport->pdf->SetXY($thisReport->cashX, $thisReport->cashY); - $thisReport->pdf->Cell(46, 7, $totalCashStr, 1, 1, 'R'); - } - - if ($thisReport->deposit->totalChecks > 0) { - $totalChecksStr = sprintf('%.2f', $thisReport->deposit->totalChecks); - $thisReport->pdf->SetXY($thisReport->checksX, $thisReport->checksY); - $thisReport->pdf->Cell(46, 7, $totalChecksStr, 1, 1, 'R'); - } - - $grandTotalStr = sprintf('%.2f', $thisReport->deposit->dep_Total); - $cashReceivedStr = sprintf('%.2f', 0); - - $thisReport->pdf->SetXY($thisReport->cashReceivedX, $thisReport->cashReceivedY); - $thisReport->pdf->Cell(46, 7, $cashReceivedStr, 1, 1, 'R'); - - $thisReport->pdf->SetXY($thisReport->topTotalX, $thisReport->topTotalY); - $thisReport->pdf->Cell(46, 7, $grandTotalStr, 1, 1, 'R'); - - // -------------------------------- - // BEGIN BACK OF BANK DEPOSIT SLIP - - $thisReport->pdf->addPage('P', [84, 187]); - $numItems = 0; - foreach ($thisReport->payments as $payment) { - // List all the checks and total the cash - if ($payment->plg_method === 'CHECK') { - $plgSumStr = sprintf('%.2f', $payment->plg_amount); - $thisReport->pdf->SetFontSize(14); - $thisReport->pdf->SetXY($thisReport->depositSlipBackCheckNosX, $thisReport->depositSlipBackCheckNosY + $numItems * $thisReport->depositSlipBackCheckNosHeight); - $thisReport->pdf->Cell($thisReport->depositSlipBackCheckNosWidth, $thisReport->depositSlipBackCheckNosHeight, $payment->plg_CheckNo, 1, 0, 'L'); - $thisReport->pdf->SetFontSize(18); - $thisReport->pdf->Cell($thisReport->depositSlipBackDollarsWidth, $thisReport->depositSlipBackDollarsHeight, $plgSumStr, 1, 1, 'R'); - $numItems += 1; - } - } - } - - private function generateDepositSummary($thisReport): void - { - $thisReport->depositSummaryParameters = new \stdClass(); - - $thisReport->depositSummaryParameters->title = new \stdClass(); - $thisReport->depositSummaryParameters->title->x = 85; - $thisReport->depositSummaryParameters->title->y = 7; - - $thisReport->depositSummaryParameters->date = new \stdClass(); - $thisReport->depositSummaryParameters->date->x = 185; - $thisReport->depositSummaryParameters->date->y = 7; - - $thisReport->depositSummaryParameters->summary = new \stdClass(); - $thisReport->depositSummaryParameters->summary->x = 12; - $thisReport->depositSummaryParameters->summary->y = 15; - $thisReport->depositSummaryParameters->summary->intervalY = 4; - $thisReport->depositSummaryParameters->summary->FundX = 15; - $thisReport->depositSummaryParameters->summary->MethodX = 55; - $thisReport->depositSummaryParameters->summary->FromX = 80; - $thisReport->depositSummaryParameters->summary->MemoX = 120; - $thisReport->depositSummaryParameters->summary->AmountX = 185; - - $thisReport->depositSummaryParameters->aggregateX = 135; - $thisReport->depositSummaryParameters->displayBillCounts = false; - - $thisReport->pdf->addPage(); - $thisReport->pdf->SetXY($thisReport->depositSummaryParameters->date->x, $thisReport->depositSummaryParameters->date->y); - $thisReport->pdf->Write(8, $thisReport->deposit->dep_Date); - - $thisReport->pdf->SetXY($thisReport->depositSummaryParameters->title->x, $thisReport->depositSummaryParameters->title->y); - $thisReport->pdf->SetFont('Courier', 'B', 20); - $thisReport->pdf->Write(8, 'Deposit Summary ' . $thisReport->deposit->dep_ID); - $thisReport->pdf->SetFont('Times', 'B', 10); - - $thisReport->curX = $thisReport->depositSummaryParameters->summary->x; - $thisReport->curY = $thisReport->depositSummaryParameters->summary->y; - - $thisReport->pdf->SetFont('Times', 'B', 10); - $thisReport->pdf->SetXY($thisReport->curX, $thisReport->curY); - $thisReport->pdf->Write(8, 'Chk No.'); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->FundX, $thisReport->curY); - $thisReport->pdf->Write(8, 'Fund'); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->MethodX, $thisReport->curY); - $thisReport->pdf->Write(8, 'PmtMethod'); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->FromX, $thisReport->curY); - $thisReport->pdf->Write(8, 'Rcd From'); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->MemoX, $thisReport->curY); - $thisReport->pdf->Write(8, 'Memo'); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->AmountX, $thisReport->curY); - $thisReport->pdf->Write(8, 'Amount'); - $thisReport->curY += 2 * $thisReport->depositSummaryParameters->summary->intervalY; - - $totalAmount = 0; - - //while ($aRow = mysqli_fetch_array($rsPledges)) - foreach ($thisReport->payments as $payment) { - $thisReport->pdf->SetFont('Times', '', 10); - - // Format Data - if (strlen($payment->plg_CheckNo) > 8) { - $payment->plg_CheckNo = '...' . mb_substr($payment->plg_CheckNo, -8, 8); - } - if (strlen($payment->fun_Name) > 20) { - $payment->fun_Name = mb_substr($payment->fun_Name, 0, 20) . '...'; - } - if (strlen($payment->plg_comment) > 40) { - $payment->plg_comment = mb_substr($payment->plg_comment, 0, 38) . '...'; - } - if (strlen($payment->familyName) > 25) { - $payment->familyName = mb_substr($payment->familyName, 0, 24) . '...'; - } - - $thisReport->pdf->printRightJustified($thisReport->curX + 2, $thisReport->curY, $payment->plg_CheckNo); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->FundX, $thisReport->curY); - $thisReport->pdf->Write(8, $payment->fun_Name); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->MethodX, $thisReport->curY); - $thisReport->pdf->Write(8, $payment->plg_method); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->FromX, $thisReport->curY); - $thisReport->pdf->Write(8, $payment->familyName); - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->MemoX, $thisReport->curY); - $thisReport->pdf->Write(8, $payment->plg_comment); - - $thisReport->pdf->SetFont('Courier', '', 8); - - $thisReport->pdf->printRightJustified($thisReport->curX + $thisReport->depositSummaryParameters->summary->AmountX, $thisReport->curY, $payment->plg_amount); - - $thisReport->curY += $thisReport->depositSummaryParameters->summary->intervalY; - - if ($thisReport->curY >= 250) { - $thisReport->pdf->addPage(); - $thisReport->curY = $thisReport->topY; - } - } - - $thisReport->curY += $thisReport->depositSummaryParameters->summary->intervalY; - - $thisReport->pdf->SetXY($thisReport->curX + $thisReport->depositSummaryParameters->summary->MemoX, $thisReport->curY); - $thisReport->pdf->Write(8, 'Deposit total'); - - $grandTotalStr = sprintf('%.2f', $thisReport->deposit->dep_Total); - $thisReport->pdf->printRightJustified($thisReport->curX + $thisReport->depositSummaryParameters->summary->AmountX, $thisReport->curY, $grandTotalStr); - - // Now print deposit totals by fund - $thisReport->curY += 2 * $thisReport->depositSummaryParameters->summary->intervalY; - if ($thisReport->depositSummaryParameters->displayBillCounts) { - $this->generateCashDenominations($thisReport); - } - $thisReport->curX = $thisReport->depositSummaryParameters->aggregateX; - $this->generateTotalsByFund($thisReport); - - $thisReport->curY += $thisReport->summaryIntervalY; - $this->generateTotalsByCurrencyType($thisReport); - $thisReport->curY += $thisReport->summaryIntervalY * 2; - - $thisReport->curY += 130; - $thisReport->curX = $thisReport->depositSummaryParameters->summary->x; - - $this->generateWitnessSignature($thisReport); - } - - private function generateWitnessSignature($thisReport): void - { - $thisReport->pdf->setXY($thisReport->curX, $thisReport->curY); - $thisReport->pdf->write(8, 'Witness 1'); - $thisReport->pdf->line($thisReport->curX + 17, $thisReport->curY + 8, $thisReport->curX + 80, $thisReport->curY + 8); - - $thisReport->curY += 10; - $thisReport->pdf->setXY($thisReport->curX, $thisReport->curY); - $thisReport->pdf->write(8, 'Witness 2'); - $thisReport->pdf->line($thisReport->curX + 17, $thisReport->curY + 8, $thisReport->curX + 80, $thisReport->curY + 8); - - $thisReport->curY += 10; - $thisReport->pdf->setXY($thisReport->curX, $thisReport->curY); - $thisReport->pdf->write(8, 'Witness 3'); - $thisReport->pdf->line($thisReport->curX + 17, $thisReport->curY + 8, $thisReport->curX + 80, $thisReport->curY + 8); - } - public function getDepositPDF($depID): void { } @@ -556,9 +351,8 @@ public function getDepositCSV(string $depID): \stdClass requireUserGroupMembership('bFinance'); $retstring = ''; $line = []; - $firstLine = true; $payments = $this->getPayments($depID); - if (count($payments) == 0) { + if (count($payments) === 0) { throw new \Exception('No Payments on this Deposit', 404); } foreach ($payments[0] as $key => $value) { @@ -567,7 +361,7 @@ public function getDepositCSV(string $depID): \stdClass $retstring = implode(',', $line) . "\n"; foreach ($payments as $payment) { $line = []; - foreach ($payment as $key => $value) { + foreach ($payment as $value) { $line[] = str_replace(',', '', $value); } $retstring .= implode(',', $line) . "\n"; @@ -583,7 +377,6 @@ public function getDepositCSV(string $depID): \stdClass public function getCurrencyTypeOnDeposit(string $currencyID, string $depositID) { - $currencies = []; // Get the list of Currency denominations $sSQL = 'select sum(pdem_denominationQuantity) from pledge_denominations_pdem where plg_depID = ' . $depositID . ' diff --git a/src/ChurchCRM/Service/GroupService.php b/src/ChurchCRM/Service/GroupService.php index 86203483dd..5129103655 100644 --- a/src/ChurchCRM/Service/GroupService.php +++ b/src/ChurchCRM/Service/GroupService.php @@ -3,6 +3,7 @@ namespace ChurchCRM\Service; use ChurchCRM\model\ChurchCRM\ListOption; +use ChurchCRM\model\ChurchCRM\Person; use ChurchCRM\model\ChurchCRM\Person2group2roleP2g2r; use ChurchCRM\model\ChurchCRM\PersonQuery; @@ -14,7 +15,7 @@ class GroupService * @param int $groupID Group ID from which to remove the user * @param int $personID UserID to remove from the group */ - public function removeUserFromGroup($groupID, $personID): void + public function removeUserFromGroup(int $groupID, int $personID): void { requireUserGroupMembership('bManageGroups'); $sSQL = 'DELETE FROM person2group2role_p2g2r WHERE p2g2r_per_ID = ' . $personID . ' AND p2g2r_grp_ID = ' . $groupID; @@ -110,7 +111,7 @@ public function addUserToGroup(int $iGroupID, int $iPersonID, int $iRoleID): arr * * @return array representing the roles of the group */ - public function getGroupRoles($groupID): array + public function getGroupRoles(int $groupID): array { $groupRoles = []; $sSQL = 'SELECT grp_ID, lst_OptionName, lst_OptionID, lst_OptionSequence @@ -121,7 +122,7 @@ public function getGroupRoles($groupID): array $rsList = RunQuery($sSQL); // Validate that this list ID is really for a group roles list. (for security) - if (mysqli_num_rows($rsList) == 0) { + if (mysqli_num_rows($rsList) === 0) { throw new \Exception('invalid request'); } @@ -158,7 +159,7 @@ public function getGroupRoleOrder(string $groupID, string $groupRoleID) return $rowOrder[0]; } - public function deleteGroupRole(string $groupID, string $groupRoleID) + public function deleteGroupRole(string $groupID, string $groupRoleID): array { requireUserGroupMembership('bManageGroups'); $sSQL = 'SELECT * FROM list_lst @@ -341,9 +342,10 @@ public function getGroupMembers(string $groupID, $personID = null): array while ($row = mysqli_fetch_assoc($result)) { //on teste si les propriétés sont bonnes if (array_key_exists('p2g2r_per_ID', $row) && array_key_exists('lst_OptionName', $row)) { + /** @var Person|null $dbPerson */ $dbPerson = PersonQuery::create()->findPk($row['p2g2r_per_ID']); - if (array_key_exists('displayName', $dbPerson)) { + if ($dbPerson instanceof Person) { $person['displayName'] = $dbPerson->getFullName(); $person['groupRole'] = $row['lst_OptionName']; $members[] = $person; diff --git a/src/ChurchCRM/Service/PersonService.php b/src/ChurchCRM/Service/PersonService.php index 718d65468b..76f0049b03 100644 --- a/src/ChurchCRM/Service/PersonService.php +++ b/src/ChurchCRM/Service/PersonService.php @@ -10,7 +10,7 @@ class PersonService /** * @return array> */ - public function search(string $searchTerm, $includeFamilyRole = true): array + public function search(string $searchTerm, bool $includeFamilyRole = true): array { $searchLikeString = '%' . $searchTerm . '%'; $people = PersonQuery::create() @@ -27,7 +27,7 @@ public function search(string $searchTerm, $includeFamilyRole = true): array $values['lastName'] = $person->getLastName(); $values['displayName'] = $person->getFullName(); $values['uri'] = $person->getViewURI(); - $values['thumbnailURI'] = $person->getThumbnailURI(); + $values['thumbnailURI'] = $person->getPhoto()->getThumbnailURI(); $values['title'] = $person->getTitle(); $values['address'] = $person->getAddress(); $values['role'] = $person->getFamilyRoleName(); diff --git a/src/ChurchCRM/Service/SystemService.php b/src/ChurchCRM/Service/SystemService.php index 1c05ab799e..479792db2a 100644 --- a/src/ChurchCRM/Service/SystemService.php +++ b/src/ChurchCRM/Service/SystemService.php @@ -4,6 +4,7 @@ use ChurchCRM\Backup\BackupJob; use ChurchCRM\Backup\BackupType; +use ChurchCRM\dto\Prerequisite; use ChurchCRM\dto\SystemConfig; use ChurchCRM\dto\SystemURLs; use ChurchCRM\Utils\ChurchCRMReleaseManager; @@ -33,7 +34,7 @@ public static function getInstalledVersion() return $composerJson['version']; } - public static function getCopyrightDate() + public static function getCopyrightDate(): string { return (new \DateTime())->format('Y'); } @@ -73,13 +74,13 @@ public static function getPrerequisiteStatus(): string { if (AppIntegrityService::arePrerequisitesMet()) { return 'All Prerequisites met'; - } else { - $unmet = AppIntegrityService::getUnmetPrerequisites(); + } - $unmetNames = array_map(fn ($o): string => (string) $o->getName(), $unmet); + $unmet = AppIntegrityService::getUnmetPrerequisites(); - return 'Missing Prerequisites: ' . json_encode(array_values($unmetNames), JSON_THROW_ON_ERROR); - } + $unmetNames = array_map(fn (Prerequisite $o): string => $o->getName(), $unmet); + + return 'Missing Prerequisites: ' . json_encode(array_values($unmetNames), JSON_THROW_ON_ERROR); } private static function isTimerThresholdExceeded(string $LastTime, int $ThresholdHours): bool diff --git a/src/ChurchCRM/Service/TimelineService.php b/src/ChurchCRM/Service/TimelineService.php index d1c24eb177..845bd7ec87 100644 --- a/src/ChurchCRM/Service/TimelineService.php +++ b/src/ChurchCRM/Service/TimelineService.php @@ -36,7 +36,7 @@ public function getForFamily(int $familyID): array krsort($timeline); $sortedTimeline = []; - foreach ($timeline as $date => $item) { + foreach ($timeline as $item) { $sortedTimeline[] = $item; } @@ -99,7 +99,7 @@ private function sortTimeline(array $timeline): array krsort($timeline); $sortedTimeline = []; - foreach ($timeline as $date => $item) { + foreach ($timeline as $item) { $sortedTimeline[] = $item; } @@ -124,8 +124,6 @@ public function getForPerson(int $personID): array } /** - * @param Note $dbNote - * * @return mixed|null */ public function noteToTimelineItem(Note $dbNote) @@ -180,11 +178,7 @@ public function createTimeLineItem(string $id, $type, string $datetime, $year, $ $item['style'] = 'fa-calendar bg-green'; break; case 'verify': - $item['style'] = 'fa-circle-check bg-teal'; - break; case 'verify-link': - $item['style'] = 'fa-circle-check bg-teal'; - break; case 'verify-URL': $item['style'] = 'fa-circle-check bg-teal'; break; diff --git a/src/ChurchCRM/Service/UpgradeService.php b/src/ChurchCRM/Service/UpgradeService.php index cd9a86c541..258b4d3ab9 100644 --- a/src/ChurchCRM/Service/UpgradeService.php +++ b/src/ChurchCRM/Service/UpgradeService.php @@ -18,7 +18,7 @@ class UpgradeService { - public static function upgradeDatabaseVersion() + public static function upgradeDatabaseVersion(): bool { $logger = LoggerUtils::getAppLogger(); $db_version = SystemService::getDBVersion(); @@ -66,11 +66,9 @@ public static function upgradeDatabaseVersion() throw new \Exception("Invalid upgrade file specified: $scriptName"); } } - if (!$errorFlag) { - $version->setUpdateEnd(new \DateTimeImmutable()); - $version->save(); - sleep(2); - } + $version->setUpdateEnd(new \DateTimeImmutable()); + $version->save(); + sleep(2); // increment the number of scripts executed. // If no scripts run, then there is no supported upgrade path defined in the JSON file diff --git a/src/ChurchCRM/Slim/Middleware/AuthMiddleware.php b/src/ChurchCRM/Slim/Middleware/AuthMiddleware.php index 21a74ef01b..5c40f6687e 100644 --- a/src/ChurchCRM/Slim/Middleware/AuthMiddleware.php +++ b/src/ChurchCRM/Slim/Middleware/AuthMiddleware.php @@ -39,7 +39,7 @@ public function __invoke(Request $request, RequestHandler $handler): Response private function isPath(Request $request, string $pathPart): bool { $pathAry = explode('/', $request->getUri()->getPath()); - if (!empty($pathAry) && $pathAry[0] === $pathPart) { + if ($pathAry[0] === $pathPart) { return true; } diff --git a/src/ChurchCRM/SystemCalendars/AnniversariesCalendar.php b/src/ChurchCRM/SystemCalendars/AnniversariesCalendar.php index 79b3c036d7..1103523828 100644 --- a/src/ChurchCRM/SystemCalendars/AnniversariesCalendar.php +++ b/src/ChurchCRM/SystemCalendars/AnniversariesCalendar.php @@ -39,7 +39,7 @@ public function getName(): string return gettext('Anniversaries'); } - public function getEvents(string $start, string $end) + public function getEvents(string $start, string $end): ObjectCollection { $families = FamilyQuery::create() ->filterByWeddingdate('', Criteria::NOT_EQUAL) @@ -48,7 +48,7 @@ public function getEvents(string $start, string $end) return $this->familyCollectionToEvents($families); } - public function getEventById(int $Id) + public function getEventById(int $Id): ObjectCollection { $families = FamilyQuery::create() ->filterByWeddingdate('', Criteria::NOT_EQUAL) diff --git a/src/ChurchCRM/SystemCalendars/BirthdaysCalendar.php b/src/ChurchCRM/SystemCalendars/BirthdaysCalendar.php index be8a48b189..e750975844 100644 --- a/src/ChurchCRM/SystemCalendars/BirthdaysCalendar.php +++ b/src/ChurchCRM/SystemCalendars/BirthdaysCalendar.php @@ -39,7 +39,7 @@ public function getName(): string return gettext('Birthdays'); } - public function getEvents(string $start, string $end) + public function getEvents(string $start, string $end): ObjectCollection { $people = PersonQuery::create() ->filterByBirthDay('', Criteria::NOT_EQUAL) @@ -48,7 +48,7 @@ public function getEvents(string $start, string $end) return $this->peopleCollectionToEvents($people); } - public function getEventById(int $Id) + public function getEventById(int $Id): ObjectCollection { $people = PersonQuery::create() ->filterByBirthDay('', Criteria::NOT_EQUAL) @@ -63,7 +63,7 @@ private function peopleCollectionToEvents(ObjectCollection $People): ObjectColle $events = new ObjectCollection(); $events->setModel(Event::class); foreach ($People as $person) { - for ($year = date('Y'); $year <= date('Y') + 1; $year++) { + for ($year = (int) date('Y'); $year <= (int) date('Y') + 1; $year++) { $birthday = new Event(); $birthday->setId($person->getId()); $birthday->setEditable(false); diff --git a/src/ChurchCRM/SystemCalendars/HolidayCalendar.php b/src/ChurchCRM/SystemCalendars/HolidayCalendar.php index 152eb8acb0..cd1bcb4d35 100644 --- a/src/ChurchCRM/SystemCalendars/HolidayCalendar.php +++ b/src/ChurchCRM/SystemCalendars/HolidayCalendar.php @@ -47,7 +47,7 @@ public function getName(): string return gettext('Holidays'); } - public function getEvents(string $start, string $end) + public function getEvents(string $start, string $end): ObjectCollection { $Country = Countries::getCountryByName(SystemConfig::getValue('sChurchCountry')); $year = date('Y'); @@ -63,9 +63,12 @@ public function getEvents(string $start, string $end) return $events; } - public function getEventById(int $Id) + public function getEventById(int $Id): ObjectCollection { - return false; + $emptySet = new ObjectCollection(); + $emptySet->setModel(Event::class); + + return $emptySet; } private function yasumiHolidayToEvent(Holiday $holiday): Event diff --git a/src/ChurchCRM/SystemCalendars/SystemCalendar.php b/src/ChurchCRM/SystemCalendars/SystemCalendar.php index 5e20bd39e0..28b5857241 100644 --- a/src/ChurchCRM/SystemCalendars/SystemCalendar.php +++ b/src/ChurchCRM/SystemCalendars/SystemCalendar.php @@ -17,17 +17,9 @@ public function getForegroundColor(): string; public function getBackgroundColor(): string; - /** - * @return ObjectCollection|array - */ - public function getEvents(string $start, string $end); - - /** - * TODO: this seems wrong. please fix this. - * - * @return ObjectCollection|array|Event|false - */ - public function getEventById(int $Id); + public function getEvents(string $start, string $end): ObjectCollection; + + public function getEventById(int $Id): ObjectCollection; public static function isAvailable(): bool; } diff --git a/src/ChurchCRM/SystemCalendars/UnpinnedEvents.php b/src/ChurchCRM/SystemCalendars/UnpinnedEvents.php index 64570ced6c..3bbc7459c4 100644 --- a/src/ChurchCRM/SystemCalendars/UnpinnedEvents.php +++ b/src/ChurchCRM/SystemCalendars/UnpinnedEvents.php @@ -38,24 +38,20 @@ public function getName(): string return gettext('Unpinned Events'); } - public function getEvents(string $start, string $end) + public function getEvents(string $start, string $end): ObjectCollection { - $Events = EventQuery::create() + return EventQuery::create() ->filterByStart(['min' => $start]) ->filterByEnd(['max' => $end]) ->useCalendarEventQuery(null, Criteria::LEFT_JOIN) ->filterByCalendarId(null) ->endUse() ->find(); - - return $Events; } - public function getEventById(int $Id) + public function getEventById(int $Id): ObjectCollection { - $Event = EventQuery::create() - ->findOneById($Id); - - return $Event; + return EventQuery::create() + ->findById($Id); } } diff --git a/src/ChurchCRM/Twig/GettextExtension.php b/src/ChurchCRM/Twig/GettextExtension.php new file mode 100644 index 0000000000..e3de833888 --- /dev/null +++ b/src/ChurchCRM/Twig/GettextExtension.php @@ -0,0 +1,16 @@ +countryCode = $countryCode; - $stateFileName = SystemURLs::getDocumentRoot() . '/locale/states/' . $countryCode . '.json'; if (is_file($stateFileName)) { $statesFile = file_get_contents($stateFileName); diff --git a/src/ChurchCRM/dto/Cart.php b/src/ChurchCRM/dto/Cart.php index f1d7f920d7..e11b7ce113 100644 --- a/src/ChurchCRM/dto/Cart.php +++ b/src/ChurchCRM/dto/Cart.php @@ -180,11 +180,9 @@ public static function emptyToGroup($GroupID, $RoleID): void public static function getCartPeople() { - $people = PersonQuery::create() + return PersonQuery::create() ->filterById($_SESSION['aPeopleCart']) ->find(); - - return $people; } public static function getEmailLink(): string @@ -216,9 +214,8 @@ public static function getSMSLink(): string $SMSNumberArray[] = $cartPerson->getCellPhone(); } } - $sSMSLink = implode(',', $SMSNumberArray); - return $sSMSLink; + return implode(',', $SMSNumberArray); } public static function emptyAll(): void diff --git a/src/ChurchCRM/dto/ChurchCRMReleaseManager.php b/src/ChurchCRM/dto/ChurchCRMReleaseManager.php index 43b0ac814f..5f739b6cc9 100644 --- a/src/ChurchCRM/dto/ChurchCRMReleaseManager.php +++ b/src/ChurchCRM/dto/ChurchCRMReleaseManager.php @@ -295,7 +295,5 @@ public static function doUpgrade(string $zipFilename, string $sha1): void $logger->info('Upgrade process complete'); ini_set('display_errors', $displayErrors); self::$isUpgradeInProgress = false; - - return; } } diff --git a/src/ChurchCRM/dto/ConfigItem.php b/src/ChurchCRM/dto/ConfigItem.php index c8b233c9c1..a8944f5901 100644 --- a/src/ChurchCRM/dto/ConfigItem.php +++ b/src/ChurchCRM/dto/ConfigItem.php @@ -15,8 +15,8 @@ class ConfigItem private $url; private $data; private $dbConfigItem; - private $section = null; - private $category = null; + private $section; + private $category; public function __construct($id, $name, $type, $default, $tooltip = '', $url = '', $data = '') { diff --git a/src/ChurchCRM/dto/MenuEventsCount.php b/src/ChurchCRM/dto/MenuEventsCount.php index 318d1094ef..d70c0c29c9 100644 --- a/src/ChurchCRM/dto/MenuEventsCount.php +++ b/src/ChurchCRM/dto/MenuEventsCount.php @@ -20,12 +20,10 @@ class MenuEventsCount { public static function getBirthDates() { - $peopleWithBirthDays = PersonQuery::create() + return PersonQuery::create() ->filterByBirthMonth(date('m')) ->filterByBirthDay(date('d')) ->find(); - - return $peopleWithBirthDays; } /** diff --git a/src/ChurchCRM/dto/Notification.php b/src/ChurchCRM/dto/Notification.php index 263b38ef41..e05517fc5e 100644 --- a/src/ChurchCRM/dto/Notification.php +++ b/src/ChurchCRM/dto/Notification.php @@ -9,11 +9,11 @@ class Notification { - protected $projectorText; - protected $recipients; + protected string $projectorText; + protected array $recipients; protected ?Person $person = null; - public function setRecipients($recipients): void + public function setRecipients(array $recipients): void { $this->recipients = $recipients; } @@ -36,72 +36,74 @@ public function setProjectorText(string $text): void $this->projectorText = $text; } - private function sendEmail() + private function sendEmail(): bool { $emailaddresses = []; foreach ($this->recipients as $recipient) { $emailaddresses[] = $recipient->getEmail(); } - try { - $email = new NotificationEmail($emailaddresses, $this->person->getFullName()); - $emailStatus = $email->send(); + $email = new NotificationEmail($emailaddresses, $this->person->getFullName()); - return $emailStatus; - } catch (\Exception $ex) { - return false; - } + return $email->send(); } private function sendSMS(): bool { - try { - $client = new Client(new Basic(SystemConfig::getValue('sNexmoAPIKey'), SystemConfig::getValue('sNexmoAPISecret'))); - - foreach ($this->recipients as $recipient) { - $message = $client->message()->sendText([ - 'to' => $recipient->getNumericCellPhone(), - 'from' => SystemConfig::getValue('sNexmoFromNumber'), - 'text' => gettext('Notification for') . ' ' . $this->person->getFullName(), - ]); - } + $client = new Client(new Basic(SystemConfig::getValue('sNexmoAPIKey'), SystemConfig::getValue('sNexmoAPISecret'))); - return true; - } catch (\Exception $ex) { - return false; + foreach ($this->recipients as $recipient) { + $client->message()->sendText( + $recipient->getNumericCellPhone(), + SystemConfig::getValue('sNexmoFromNumber'), + gettext('Notification for') . ' ' . $this->person->getFullName() + ); } + + return true; } - private function sendProjector() + private function sendProjector(): string { - try { - $OLPAlert = new OpenLPNotification( - SystemConfig::getValue('sOLPURL'), - SystemConfig::getValue('sOLPUserName'), - SystemConfig::getValue('sOLPPassword') - ); - $OLPAlert->setAlertText($this->projectorText); - - return $OLPAlert->send(); - } catch (\Exception $ex) { - return false; - } + $OLPAlert = new OpenLPNotification( + SystemConfig::getValue('sOLPURL'), + SystemConfig::getValue('sOLPUserName'), + SystemConfig::getValue('sOLPPassword') + ); + $OLPAlert->setAlertText($this->projectorText); + + return $OLPAlert->send(); } public function send(): array { $methods = []; if (SystemConfig::hasValidMailServerSettings()) { - $send = $this->sendEmail(); - $methods[] = 'email: ' . $send; + $sendEmail = false; + try { + $sendEmail = $this->sendEmail(); + } catch (\Throwable) { + // do nothing + } + $methods[] = 'email: ' . $sendEmail; } if (SystemConfig::hasValidSMSServerSettings()) { - $send = (bool) $this->sendSMS(); - $methods[] = 'sms: ' . $send; + $sendSms = false; + try { + $sendSms = $this->sendSMS(); + } catch (\Throwable) { + // do nothing + } + $methods[] = 'sms: ' . $sendSms; } if (SystemConfig::hasValidOpenLPSettings()) { - $send = (bool) $this->sendProjector(); - $methods[] = 'projector: ' . $send; + $sendOpenLp = false; + try { + $sendOpenLp = (bool) $this->sendProjector(); + } catch (\Throwable) { + // do nothing + } + $methods[] = 'projector: ' . $sendOpenLp; } return [ 'status' => '', diff --git a/src/ChurchCRM/dto/PeopleCustomField.php b/src/ChurchCRM/dto/PeopleCustomField.php index fdf49641d5..34ced6c367 100644 --- a/src/ChurchCRM/dto/PeopleCustomField.php +++ b/src/ChurchCRM/dto/PeopleCustomField.php @@ -57,9 +57,6 @@ public function getFormattedValue() return $this->formattedValue; } - /** - * @return mixed - */ public function getLink(): ?string { return $this->link; @@ -73,17 +70,11 @@ public function getName() return $this->name; } - /** - * @return mixed - */ public function getValue(): string { return $this->value; } - /** - * @return mixed - */ public function getIcon(): string { return $this->icon; diff --git a/src/ChurchCRM/dto/Photo.php b/src/ChurchCRM/dto/Photo.php index 05440de002..322c0dfe5a 100644 --- a/src/ChurchCRM/dto/Photo.php +++ b/src/ChurchCRM/dto/Photo.php @@ -9,8 +9,8 @@ class Photo { - private $photoType; - private $id; + private string $photoType; + private int $id; private $photoURI; private ?string $photoThumbURI = null; private ?string $thumbnailPath = null; @@ -20,7 +20,7 @@ class Photo public static $validExtensions = ['png', 'jpeg', 'jpg']; - public function __construct($photoType, $id) + public function __construct(string $photoType, int $id) { $this->photoType = $photoType; $this->id = $id; @@ -208,7 +208,7 @@ public function getThumbnailBytes(): string return $content; } - public function getPhotoBytes(): string|false + public function getPhotoBytes() { $content = file_get_contents($this->photoURI); MiscUtils::throwIfFailed($content); @@ -251,8 +251,6 @@ private function loadFromGravatar($email, string $baseName): string $s = 60; $d = '404'; $r = 'g'; - $img = false; - $atts = []; $url = 'https://www.gravatar.com/avatar/'; $url .= md5(strtolower(trim($email))); $url .= "?s=$s&d=$d&r=$r"; @@ -268,7 +266,7 @@ private function loadFromGravatar($email, string $baseName): string throw new \Exception('Gravatar not found'); } - private function loadFromGoogle($email, string $baseName): string|false + private function loadFromGoogle($email, string $baseName) { $url = 'http://picasaweb.google.com/data/entry/api/user/'; $url .= strtolower(trim($email)); @@ -293,7 +291,7 @@ private function loadFromGoogle($email, string $baseName): string|false return false; } - private function getRandomColor(\GdImage $image): int|false + private function getRandomColor(\GdImage $image) { $red = random_int(0, 150); $green = random_int(0, 150); diff --git a/src/ChurchCRM/dto/iCal.php b/src/ChurchCRM/dto/iCal.php index 4764062bff..bbd48c4b70 100644 --- a/src/ChurchCRM/dto/iCal.php +++ b/src/ChurchCRM/dto/iCal.php @@ -50,8 +50,7 @@ public function toString(): string foreach ($this->eventsArray as $event) { $iCal .= $this->eventToVEVENT($event); } - $iCal .= 'END:VCALENDAR'; - return $iCal; + return $iCal . 'END:VCALENDAR'; } } diff --git a/src/ChurchCRM/model/ChurchCRM/Deposit.php b/src/ChurchCRM/model/ChurchCRM/Deposit.php index 8ed9210cc9..d8759365fb 100644 --- a/src/ChurchCRM/model/ChurchCRM/Deposit.php +++ b/src/ChurchCRM/model/ChurchCRM/Deposit.php @@ -280,8 +280,6 @@ private function generateDepositSummary(\stdClass $thisReport): void $thisReport->pdf->Write(8, 'Amount'); $thisReport->curY += 2 * $thisReport->depositSummaryParameters->summary->intervalY; - $totalAmount = 0; - //while ($aRow = mysqli_fetch_array($rsPledges)) foreach ($this->getPledges() as $payment) { $thisReport->pdf->SetFont('Times', '', 10); @@ -426,55 +424,47 @@ public function getTotalAmount() public function getTotalChecks() { - $totalCash = PledgeQuery::create() + return PledgeQuery::create() ->filterByDepId($this->getId()) ->filterByMethod('CHECK') ->withColumn('SUM(Pledge.Amount)', 'sumAmount') ->find() ->getColumnValues('sumAmount')[0]; - - return $totalCash; } public function getTotalCash() { - $totalCash = PledgeQuery::create() + return PledgeQuery::create() ->filterByDepId($this->getId()) ->filterByMethod('CASH') ->withColumn('SUM(Pledge.Amount)', 'sumAmount') ->find() ->getColumnValues('sumAmount')[0]; - - return $totalCash; } public function getCountChecks() { - $countCash = PledgeQuery::create() + return PledgeQuery::create() ->filterByDepId($this->getId()) ->groupByGroupKey() ->filterByMethod('CHECK') ->find() ->count(); - - return $countCash; } public function getCountCash() { - $countCash = PledgeQuery::create() + return PledgeQuery::create() ->filterByDepId($this->getId()) ->groupByGroupKey() ->filterByMethod('CASH') ->find() ->count(); - - return $countCash; } public function getFundTotals() { - $funds = PledgeQuery::create() + return PledgeQuery::create() ->filterByDepId($this->getId()) ->groupByFundId() ->withColumn('SUM(' . PledgeTableMap::COL_PLG_AMOUNT . ')', 'Total') @@ -483,8 +473,6 @@ public function getFundTotals() ->orderBy(DonationFundTableMap::COL_FUN_NAME) ->select(['Name', 'Total']) ->find(); - - return $funds; } public function getPledgesJoinAll(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) diff --git a/src/ChurchCRM/model/ChurchCRM/Family.php b/src/ChurchCRM/model/ChurchCRM/Family.php index f1ab2917a0..048d1f5236 100644 --- a/src/ChurchCRM/model/ChurchCRM/Family.php +++ b/src/ChurchCRM/model/ChurchCRM/Family.php @@ -67,9 +67,7 @@ public function getViewURI(): string public function getWeddingDay() { if ($this->getWeddingdate() !== null && $this->getWeddingdate() !== '') { - $day = $this->getWeddingdate()->format('d'); - - return $day; + return $this->getWeddingdate()->format('d'); } return ''; @@ -78,9 +76,7 @@ public function getWeddingDay() public function getWeddingMonth() { if ($this->getWeddingdate() !== null && $this->getWeddingdate() !== '') { - $month = $this->getWeddingdate()->format('m'); - - return $month; + return $this->getWeddingdate()->format('m'); } return ''; @@ -174,8 +170,6 @@ private function getPeopleByRole(string $roleConfigName): array /** * @throws PropelException - * - * @return array */ public function getEmails(): array { @@ -281,7 +275,7 @@ public function verify(): void $this->createTimeLineNote('verify'); } - public function getFamilyString($booleanIncludeHOH = true) + public function getFamilyString(bool $booleanIncludeHOH = true): string { $HoH = []; if ($booleanIncludeHOH) { @@ -332,13 +326,11 @@ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColum public function toSearchArray(): array { - $searchArray = [ + return [ 'Id' => $this->getId(), 'displayName' => $this->getFamilyString(SystemConfig::getBooleanValue('bSearchIncludeFamilyHOH')), 'uri' => SystemURLs::getRootPath() . '/v2/family/' . $this->getId(), ]; - - return $searchArray; } public function isActive(): bool diff --git a/src/ChurchCRM/model/ChurchCRM/KioskAssignment.php b/src/ChurchCRM/model/ChurchCRM/KioskAssignment.php index b04106db3b..314d86ee61 100644 --- a/src/ChurchCRM/model/ChurchCRM/KioskAssignment.php +++ b/src/ChurchCRM/model/ChurchCRM/KioskAssignment.php @@ -11,24 +11,20 @@ /** * Skeleton subclass for representing a row from the 'kioskassginment_kasm' table. * - * - * * You should add additional methods to this class to meet the * application requirements. This class will only be generated as * long as it does not already exist in the output directory. */ class KioskAssignment extends BaseKioskAssignment { - private function getActiveEvent() + private function getActiveEvent(): ?Event { if ($this->getAssignmentType() == KioskAssignmentTypes::EVENTATTENDANCEKIOSK) { - $Event = EventQuery::create() + return EventQuery::create() ->filterByStart('now', Criteria::LESS_EQUAL) ->filterByEnd('now', Criteria::GREATER_EQUAL) ->filterById($this->getEventId()) ->findOne(); - - return $Event; } else { throw new \Exception('This kiosk does not support group attendance'); } @@ -42,20 +38,18 @@ public function getActiveGroupMembers() $groupTypeJoin->addForeignValueCondition('list_lst', 'lst_ID', '', $this->getActiveEvent()->getGroup()->getRoleListId(), Join::EQUAL); $groupTypeJoin->setJoinType(Criteria::LEFT_JOIN); - $ssClass = PersonQuery::create() + return PersonQuery::create() ->joinWithPerson2group2roleP2g2r() ->usePerson2group2roleP2g2rQuery() - ->filterByGroupId($this->getEvent()->getGroupId()) - ->joinGroup() - ->addJoinObject($groupTypeJoin) + ->filterByGroup($this->getEvent()->getGroups()) + ->joinGroup() + ->addJoinObject($groupTypeJoin) ->withColumn(ListOptionTableMap::COL_LST_OPTIONNAME, 'RoleName') ->endUse() - ->leftJoin('EventAttend') - ->withColumn('(CASE WHEN event_attend.event_id is not null AND event_attend.checkout_date IS NULL then 1 else 0 end)', 'status') + ->leftJoin('EventAttend') + ->withColumn('(CASE WHEN event_attend.event_id is not null AND event_attend.checkout_date IS NULL then 1 else 0 end)', 'status') ->select(['Id', 'FirstName', 'LastName', 'status']) ->find(); - - return $ssClass; } else { throw new \Exception('This kiosk does not support group attendance'); } diff --git a/src/ChurchCRM/model/ChurchCRM/Person.php b/src/ChurchCRM/model/ChurchCRM/Person.php index 7bc28fc0e5..5a2c01adde 100644 --- a/src/ChurchCRM/model/ChurchCRM/Person.php +++ b/src/ChurchCRM/model/ChurchCRM/Person.php @@ -98,7 +98,7 @@ public function getFamilyRole() { $familyRole = null; $roleId = $this->getFmrId(); - if (isset($roleId) && $roleId !== 0) { + if ($roleId !== 0) { $familyRole = ListOptionQuery::create()->filterById(2)->filterByOptionId($roleId)->findOne(); } @@ -187,7 +187,9 @@ public function isUser(): bool } /** - * Get address of a person. If empty, return family address. + * Get full address string of a person. + * + * If the address is not defined on the person record, return family address if one exists. */ public function getAddress(): string { @@ -197,6 +199,7 @@ public function getAddress(): string if (!empty($this->getAddress2())) { $tmp = $tmp . ' ' . $this->getAddress2(); } + $address[] = $tmp; if (!empty($this->getCity())) { $address[] = $this->getCity() . ','; @@ -212,13 +215,10 @@ public function getAddress(): string } return implode(' ', $address); - } else { - if ($this->getFamily()) { - return $this->getFamily() - ->getAddress(); - } + } elseif ($this->getFamily()) { + return $this->getFamily()->getAddress(); } - //if it reaches here, no address found. return empty $address + return ''; } @@ -281,30 +281,31 @@ public function getFamilyPhone(int $type): string } /** - * * If person address found, return latitude and Longitude of person address - * else return family latitude and Longitude. - * - * @return array + * If person address found, return latitude and Longitude of person address + * Otherwise, return the family latitude and Longitude. */ public function getLatLng(): array { - $address = $this->getAddress(); //if person address empty, this will get Family address + $bUseFamilyAddress = !empty($this->getAddress1()) && $this->getFamily(); + $lat = 0; $lng = 0; - if (!empty($this->getAddress1())) { - $latLng = GeoUtils::getLatLong($this->getAddress()); + if ($bUseFamilyAddress && $this->getFamily()->hasLatitudeAndLongitude()) { + $lat = $this->getFamily()->getLatitude(); + $lng = $this->getFamily()->getLongitude(); + } else { + // if person address is empty, this will get Family address + $sFullAddress = $this->getAddress(); + + $latLng = GeoUtils::getLatLong($sFullAddress); if (!empty($latLng['Latitude']) && !empty($latLng['Longitude'])) { $lat = $latLng['Latitude']; $lng = $latLng['Longitude']; } - } else { - // note: this is useful when a person don't have a family (i.e. not an address) - if (!empty($this->getFamily())) { - if (!$this->getFamily()->hasLatitudeAndLongitude()) { - $this->getFamily()->updateLanLng(); - } - $lat = $this->getFamily()->getLatitude(); - $lng = $this->getFamily()->getLongitude(); + + if ($bUseFamilyAddress) { + // if we are using a family address, cache the result to avoid additional work in the future + $this->getFamily()->updateLanLng(); } } @@ -506,7 +507,7 @@ public function preDelete(ConnectionInterface $con = null) $this->deletePhoto(); $obj = Person2group2roleP2g2rQuery::create()->filterByPerson($this)->find($con); - if (!empty($obj)) { + if ($obj->count() > 0) { $groupService = new GroupService(); foreach ($obj as $group2roleP2g2r) { $groupService->removeUserFromGroup($group2roleP2g2r->getGroupId(), $group2roleP2g2r->getPersonId()); @@ -538,13 +539,11 @@ public function preDelete(ConnectionInterface $con = null) public function getProperties() { - $personProperties = PropertyQuery::create() + return PropertyQuery::create() ->filterByProClass('p') ->useRecordPropertyQuery() ->filterByRecordId($this->getId()) ->find(); - - return $personProperties; } // return array of person properties @@ -573,7 +572,7 @@ public function getPropertiesString(): array /** * @return string[] */ - public function getCustomFields($allPersonCustomFields, $customMapping, &$CustomList, $name_func): array + public function getCustomFields($allPersonCustomFields, array $customMapping, array &$CustomList, $name_func): array { // add custom fields to person_custom table since they are not defined in the propel schema $rawQry = PersonCustomQuery::create(); @@ -665,9 +664,8 @@ public function getNumericAge(): int if (!$birthDate instanceof \DateTimeImmutable || $this->hideAge()) { return false; } - if (empty($now)) { - $now = date_create('today'); - } + + $now = date_create('today'); $age = date_diff($now, $birthDate); if ($age->y < 1) { $ageValue = 0; diff --git a/src/ChurchCRM/model/ChurchCRM/Pledge.php b/src/ChurchCRM/model/ChurchCRM/Pledge.php index ccaa3cfe8f..e6057fb0ae 100644 --- a/src/ChurchCRM/model/ChurchCRM/Pledge.php +++ b/src/ChurchCRM/model/ChurchCRM/Pledge.php @@ -18,7 +18,7 @@ */ class Pledge extends BasePledge { - public function getFormattedFY() + public function getFormattedFY(): string { return MakeFYString($this->getFyId()); } @@ -26,7 +26,6 @@ public function getFormattedFY() /** * Code to be run before deleting the object in database. * - * @param ConnectionInterface $con * * @return bool */ diff --git a/src/ChurchCRM/tasks/PHPPendingDeprecationVersionCheckTask.php b/src/ChurchCRM/tasks/PHPPendingDeprecationVersionCheckTask.php index e350ca078d..802e69ad8c 100644 --- a/src/ChurchCRM/tasks/PHPPendingDeprecationVersionCheckTask.php +++ b/src/ChurchCRM/tasks/PHPPendingDeprecationVersionCheckTask.php @@ -10,7 +10,7 @@ class PHPPendingDeprecationVersionCheckTask implements TaskInterface, PreUpgrade public function isActive(): bool { - return version_compare(PHP_VERSION, $this::REQUIRED_PHP_VERSION, '<'); + return version_compare(PHP_VERSION, self::REQUIRED_PHP_VERSION, '<'); } public function isAdmin(): bool @@ -30,6 +30,6 @@ public function getTitle(): string public function getDesc(): string { - return gettext('Support for this PHP version will soon be removed. Current PHP Version: ' . PHP_VERSION . '. Minimum Required PHP Version: ' . $this::REQUIRED_PHP_VERSION); + return gettext('Support for this PHP version will soon be removed. Current PHP Version: ' . PHP_VERSION . '. Minimum Required PHP Version: ' . self::REQUIRED_PHP_VERSION); } } diff --git a/src/ChurchCRM/utils/ExecutionTime.php b/src/ChurchCRM/utils/ExecutionTime.php index 9fe35465b2..a3a3d2d58c 100644 --- a/src/ChurchCRM/utils/ExecutionTime.php +++ b/src/ChurchCRM/utils/ExecutionTime.php @@ -5,21 +5,17 @@ class ExecutionTime { // inspired from https://stackoverflow.com/a/22885011 - private $startTime; - private $endTime; - private $startR; - private $endR; + private float $startTime; + private ?float $endTime = null; public function __construct() { $this->startTime = microtime(true); - $this->startR = getrusage(); } public function end(): void { $this->endTime = microtime(true); - $this->endR = getrusage(); } public function getMilliseconds(): float @@ -35,16 +31,12 @@ public function getMilliseconds(): float return round($value, 2); } - private function runTime(array $ru, array $rus, string $index) - { - return ($ru["ru_$index.tv_sec"] * 1000 + intval($ru["ru_$index.tv_usec"] / 1000)) - - ($rus["ru_$index.tv_sec"] * 1000 + intval($rus["ru_$index.tv_usec"] / 1000)); - } - public function __toString(): string { - return 'This process used ' . $this->runTime($this->endTime, $this->startTime, 'utime') . - " ms for its computations\nIt spent " . $this->runTime($this->endTime, $this->startTime, 'stime') . - " ms in system calls\n"; + if ($this->endTime === null) { + return 'This process is still running: ' . $this->getMilliseconds() . ' ms.'; + } + + return 'This process completed in ' . $this->getMilliseconds() . ' ms.'; } } diff --git a/src/ChurchCRM/utils/InputUtils.php b/src/ChurchCRM/utils/InputUtils.php index f2198ea85b..1e1dc082e7 100644 --- a/src/ChurchCRM/utils/InputUtils.php +++ b/src/ChurchCRM/utils/InputUtils.php @@ -61,7 +61,7 @@ public static function filterInt($sInput): int return 0; } - return (int) intval(trim($sInput)); + return intval(trim($sInput)); } public static function filterFloat($sInput): float @@ -72,7 +72,7 @@ public static function filterFloat($sInput): float return 0; } - return (float) floatval(trim($sInput)); + return floatval(trim($sInput)); } public static function filterDate($sInput): string @@ -106,6 +106,8 @@ public static function legacyFilterInput($sInput, $type = 'string', $size = 1) return self::filterFloat($sInput); case 'date': return self::filterDate($sInput); + default: + throw new \InvalidArgumentException('Invalid "type" for legacyFilterInput provided'); } } else { return ''; diff --git a/src/ChurchCRM/utils/MiscUtils.php b/src/ChurchCRM/utils/MiscUtils.php index 8d6f18948e..10af70a098 100644 --- a/src/ChurchCRM/utils/MiscUtils.php +++ b/src/ChurchCRM/utils/MiscUtils.php @@ -124,9 +124,8 @@ public static function getGitHubWikiAnchorLink(string $text): string $anchor = preg_replace('/[^\w\d\- ]+/', '', $anchor); $anchor = preg_replace('/\s/', '-', $anchor); $anchor = preg_replace('/\-+$/', '', $anchor); - $anchor = str_replace(' ', '-', $anchor); - return $anchor; + return str_replace(' ', '-', $anchor); } public static function dashesToCamelCase(string $string, bool $capitalizeFirstCharacter = false): string diff --git a/src/DonatedItemEditor.php b/src/DonatedItemEditor.php index 9d153f1c9f..cd0641fd34 100644 --- a/src/DonatedItemEditor.php +++ b/src/DonatedItemEditor.php @@ -250,7 +250,7 @@ + ?> diff --git a/src/EditEventAttendees.php b/src/EditEventAttendees.php index ddc4fe2941..d9b619d59e 100644 --- a/src/EditEventAttendees.php +++ b/src/EditEventAttendees.php @@ -72,6 +72,7 @@ $sRowClass = AlternateRowStyle($sRowClass); $sPhoneCountry = SelectWhichInfo($per_Country, $fam_Country, false); + $sHomePhone = SelectWhichInfo(ExpandPhoneNumber($per_HomePhone, $sPhoneCountry, $dummy), ExpandPhoneNumber($fam_HomePhone, $fam_Country, $dummy), true); $sEmail = SelectWhichInfo($per_Email, $fam_Email, false); ?> diff --git a/src/EventAttendance.php b/src/EventAttendance.php index 17b8d97fd1..166f4c0ae0 100644 --- a/src/EventAttendance.php +++ b/src/EventAttendance.php @@ -4,7 +4,15 @@ require 'Include/Functions.php'; use ChurchCRM\dto\SystemURLs; +use ChurchCRM\model\ChurchCRM\EventQuery; +use ChurchCRM\model\ChurchCRM\EventTypeQuery; use ChurchCRM\Utils\InputUtils; +use Propel\Runtime\ActiveQuery\Criteria; + +$events = null; +$aEventID = []; +$aEventTitle = []; +$aEventStartDateTime = []; $sPostChoice = null; if (array_key_exists('Choice', $_POST)) { @@ -41,9 +49,9 @@ if ($sPostChoice === 'Attendees') { $sSQL = 'SELECT t1.per_ID, t1.per_Title, t1.per_FirstName, t1.per_MiddleName, t1.per_LastName, t1.per_Suffix, t1.per_Email, t1.per_HomePhone, t1.per_Country, t1.per_MembershipDate, t4.fam_HomePhone, t4.fam_Country, t1.per_Gender - FROM person_per AS t1, events_event AS t2, event_attend AS t3, family_fam AS t4 - WHERE t1.per_ID = t3.person_id AND t2.event_id = t3.event_id AND t3.event_id = ' . $iEventId . " AND t1.per_fam_ID = t4.fam_ID AND per_cls_ID IN ('1','2','5') - ORDER BY t1.per_LastName, t1.per_ID"; + FROM person_per AS t1, events_event AS t2, event_attend AS t3, family_fam AS t4 + WHERE t1.per_ID = t3.person_id AND t2.event_id = t3.event_id AND t3.event_id = ' . $iEventId . " AND t1.per_fam_ID = t4.fam_ID AND per_cls_ID IN ('1','2','5') + ORDER BY t1.per_LastName, t1.per_ID"; $sPageTitle = gettext('Event Attendees'); } elseif ($sPostChoice === 'Nonattendees') { $aSQL = 'SELECT DISTINCT(person_id) FROM event_attend WHERE event_id = ' . $iEventId; @@ -55,21 +63,21 @@ if (count($aArr) > 0) { $aArrJoin = implode(',', $aArr); $sSQL = 'SELECT t1.per_ID, t1.per_Title, t1.per_FirstName, t1.per_MiddleName, t1.per_LastName, t1.per_Suffix, t1.per_Email, t1.per_HomePhone, t1.per_Country, t1.per_MembershipDate, t2.fam_HomePhone, t2.fam_Country, t1.per_Gender - FROM person_per AS t1, family_fam AS t2 - WHERE t1.per_fam_ID = t2.fam_ID AND t1.per_ID NOT IN (' . $aArrJoin . ") AND per_cls_ID IN ('1','2','5') - ORDER BY t1.per_LastName, t1.per_ID"; + FROM person_per AS t1, family_fam AS t2 + WHERE t1.per_fam_ID = t2.fam_ID AND t1.per_ID NOT IN (' . $aArrJoin . ") AND per_cls_ID IN ('1','2','5') + ORDER BY t1.per_LastName, t1.per_ID"; } else { $sSQL = "SELECT t1.per_ID, t1.per_Title, t1.per_FirstName, t1.per_MiddleName, t1.per_LastName, t1.per_Suffix, t1.per_Email, t1.per_HomePhone, t1.per_Country, t1.per_MembershipDate, t2.fam_HomePhone, t2.fam_Country, t1.per_Gender - FROM person_per AS t1, family_fam AS t2 - WHERE t1.per_fam_ID = t2.fam_ID AND per_cls_ID IN ('1','2','5') - ORDER BY t1.per_LastName, t1.per_ID"; + FROM person_per AS t1, family_fam AS t2 + WHERE t1.per_fam_ID = t2.fam_ID AND per_cls_ID IN ('1','2','5') + ORDER BY t1.per_LastName, t1.per_ID"; } $sPageTitle = gettext('Event Nonattendees'); } elseif ($sPostChoice === 'Guests') { $sSQL = 'SELECT t1.per_ID, t1.per_Title, t1.per_FirstName, t1.per_MiddleName, t1.per_LastName, t1.per_Suffix, t1.per_HomePhone, t1.per_Country, t1.per_Gender - FROM person_per AS t1, events_event AS t2, event_attend AS t3 - WHERE t1.per_ID = t3.person_id AND t2.event_id = t3.event_id AND t3.event_id = ' . $iEventId . " AND per_cls_ID IN ('0','3') - ORDER BY t1.per_LastName, t1.per_ID"; + FROM person_per AS t1, events_event AS t2, event_attend AS t3 + WHERE t1.per_ID = t3.person_id AND t2.event_id = t3.event_id AND t3.event_id = ' . $iEventId . " AND per_cls_ID IN ('0','3') + ORDER BY t1.per_LastName, t1.per_ID"; $sPageTitle = gettext('Event Guests'); } } elseif ($sGetAction === 'List' && !empty($sGetEvent)) { @@ -89,24 +97,49 @@ // Create arrays of the attendees. for ($row = 1; $row <= $numRows; $row++) { $aRow = mysqli_fetch_assoc($rsOpps); - extract($aRow); - - if ($sGetAction === 'List') { - $aEventID[$row] = $event_id; - $aEventTitle[$row] = htmlentities(stripslashes($event_title), ENT_NOQUOTES, 'UTF-8'); - $aEventStartDateTime[$row] = $event_start; - } else { - $aPersonID[$row] = $per_ID; - $aTitle[$row] = $per_Title; - $aFistName[$row] = $per_FirstName; - $aMiddleName[$row] = $per_MiddleName; - $aLastName[$row] = $per_LastName; - $aSuffix[$row] = $per_Suffix; - $aEmail[$row] = $per_Email; - $aGender[$row] = $per_Gender == 1 ? gettext("Male") : gettext("Female"); - $aHomePhone[$row] = SelectWhichInfo(ExpandPhoneNumber($per_HomePhone, $per_Country, $dummy), ExpandPhoneNumber($fam_HomePhone, $fam_Country, $dummy), true); - } + + $aPersonID[$row] = $aRow['per_ID']; + $aTitle[$row] = $aRow['per_Title']; + $aFirstName[$row] = $aRow['per_FirstName']; + $aMiddleName[$row] = $aRow['per_MiddleName']; + $aLastName[$row] = $aRow['per_LastName']; + $aSuffix[$row] = $aRow['per_Suffix']; + $aEmail[$row] = $aRow['per_Email']; + $aGender[$row] = $aRow['per_Gender'] == 1 ? gettext("Male") : gettext("Female"); + + $aHomePhone[$row] = SelectWhichInfo( + ExpandPhoneNumber( + $aRow['per_HomePhone'], + $aRow['per_Country'], + $dummy + ), + ExpandPhoneNumber( + $aRow['fam_HomePhone'], + $aRow['fam_Country'], + $dummy + ), + true + ); +} + +$eventsQuery = EventQuery::create()->orderByStart(Criteria::DESC); +if (array_key_exists('Action', $_GET) && $_GET['Action'] === 'List' && !empty($_GET['Event'])) { + $eventType = EventTypeQuery::create()->findOneById($_GET['Event']); + $eventsQuery = $eventsQuery->filterByEventType($eventType); + + // text is All Events of type $_GET['Type'], because it doesn't work for portuguese, spanish, french, etc + $sPageTitle = gettext('All Events of Type') . ': ' . $_GET['Type']; +} + +$events = $eventsQuery->find(); +$numRows = $events->count(); +for ($row = 1; $row <= $events->count(); $row++) { + $event = $events[$row - 1]; + $aEventID[$row] = $event->getId(); + $aEventTitle[$row] = htmlentities(stripslashes($event->getTitle()), ENT_NOQUOTES, 'UTF-8'); + $aEventStartDateTime[$row] = $event->getStart(\DateTimeInterface::ATOM); } +require 'Include/Header.php'; // Construct the form ?> @@ -127,10 +160,9 @@ // List all events for ($row = 1; $row <= $numRows2; $row++) { $aRow = mysqli_fetch_array($rsOpps); - extract($aRow); echo '   ' . gettext($type_name) . + $aRow['type_id'] . '&Type=' . gettext($aRow['type_name']) . '" title="List All ' . + gettext($aRow['type_name']) . ' Events">' . gettext($aRow['type_name']) . '' . "
\n"; } ?> @@ -229,7 +261,7 @@ - + ' . $aEmail[$row] . '' : '' ?> diff --git a/src/EventEditor.php b/src/EventEditor.php index 52cc4c1e51..37f821d0ec 100644 --- a/src/EventEditor.php +++ b/src/EventEditor.php @@ -44,7 +44,6 @@ $iErrors = 0; if ($sAction === 'Create Event' && !empty($tyid)) { - // User is coming from the event types screen and thus there // is no existing event in the event_event table // diff --git a/src/FamilyCustomFieldsEditor.php b/src/FamilyCustomFieldsEditor.php index 4f7f2fb5ba..5fd7dace44 100644 --- a/src/FamilyCustomFieldsEditor.php +++ b/src/FamilyCustomFieldsEditor.php @@ -88,9 +88,9 @@ $newFieldName = InputUtils::legacyFilterInput($_POST['newFieldName']); $newFieldSec = $_POST['newFieldSec']; - if (strlen($newFieldName) == 0) { + if (strlen($newFieldName) === 0) { $bNewNameError = true; - } elseif (strlen($newFieldType) == 0 || $newFieldType < 1) { + } elseif (strlen($newFieldType) === 0 || $newFieldType < 1) { // This should never happen, but check anyhow. // $bNewTypeError = true; } else { diff --git a/src/FamilyEditor.php b/src/FamilyEditor.php index d3b8b0233c..ea98a63122 100644 --- a/src/FamilyEditor.php +++ b/src/FamilyEditor.php @@ -13,12 +13,12 @@ use ChurchCRM\model\ChurchCRM\Person; use ChurchCRM\model\ChurchCRM\PersonQuery; use ChurchCRM\Utils\InputUtils; -use ChurchCRM\Utils\MiscUtils; use ChurchCRM\Utils\RedirectUtils; $sPageTitle = gettext('Family Editor'); $iFamilyID = -1; +$family = null; // Get the FamilyID from the querystring if (array_key_exists('FamilyID', $_GET)) { @@ -32,8 +32,8 @@ RedirectUtils::redirect('v2/dashboard'); } - $sSQL = 'SELECT fam_ID FROM family_fam WHERE fam_ID = ' . $iFamilyID; - if (mysqli_num_rows(RunQuery($sSQL)) == 0) { + $family = FamilyQuery::create()->findOneById($iFamilyID); + if ($family === null) { RedirectUtils::redirect('v2/dashboard'); } } elseif (!AuthenticationManager::getCurrentUser()->isAddRecordsEnabled()) { @@ -417,29 +417,29 @@ } else { //FirstPass //Are we editing or adding? - if ($iFamilyID > 0) { + if ($family) { //Editing.... //Get the information on this family $sSQL = 'SELECT * FROM family_fam WHERE fam_ID = ' . $iFamilyID; $rsFamily = RunQuery($sSQL); extract(mysqli_fetch_array($rsFamily)); - $iFamilyID = $fam_ID; - $sName = $fam_Name; - $sAddress1 = $fam_Address1; - $sAddress2 = $fam_Address2; - $sCity = $fam_City; - $sState = $fam_State; - $sZip = $fam_Zip; - $sCountry = $fam_Country; - $sHomePhone = $fam_HomePhone; - $sWorkPhone = $fam_WorkPhone; - $sCellPhone = $fam_CellPhone; - $sEmail = $fam_Email; - $bSendNewsLetter = ($fam_SendNewsLetter == 'TRUE'); - $dWeddingDate = $fam_WeddingDate; - $nLatitude = $fam_Latitude; - $nLongitude = $fam_Longitude; + $iFamilyID = $family->getId(); + $sName = $family->getName(); + $sAddress1 = $family->getAddress1(); + $sAddress2 = $family->getAddress2(); + $sCity = $family->getCity(); + $sState = $family->getState(); + $sZip = $family->getZip(); + $sCountry = $family->getCountry(); + $sHomePhone = $family->getHomePhone(); + $sWorkPhone = $family->getWorkPhone(); + $sCellPhone = $family->getCellPhone(); + $sEmail = $family->getEmail(); + $bSendNewsLetter = $family->getSendNewsletter() === 'TRUE'; + $dWeddingDate = $family->getWeddingdate(SystemConfig::getValue("sDatePickerFormat")); + $nLatitude = $family->getLatitude(); + $nLongitude = $family->getLongitude(); // Expand the phone number $sHomePhone = ExpandPhoneNumber($sHomePhone, $sCountry, $bNoFormat_HomePhone); @@ -560,8 +560,8 @@ + ?>

@@ -593,9 +593,9 @@

maxlength="10" size="8">
@@ -606,7 +606,7 @@
+ ?>
@@ -617,7 +617,7 @@
- @@ -641,7 +641,7 @@ "' data-mask> > + } ?>>
@@ -680,9 +680,9 @@
> + } ?>>
- @@ -704,11 +704,11 @@ ">
+ ?>
- @@ -726,15 +726,15 @@ + } ?>" size="30" maxlength="50"> - 0) { - ?> + ?>

@@ -747,7 +747,7 @@ while ($rowCustomField = mysqli_fetch_array($rsCustomFields, MYSQLI_BOTH)) { extract($rowCustomField); if (AuthenticationManager::getCurrentUser()->isEnabledSecurity($aSecurityType[$fam_custom_FieldSec])) { - ?> + ?>
@@ -765,7 +765,7 @@
+ } ?>

@@ -776,7 +776,7 @@
0) { - ?> + ?> @@ -813,14 +813,14 @@ } for ($iCount = 1; $iCount <= $iFamilyMemberRows; $iCount++) { - ?> + ?>
+ } ?>
@@ -835,13 +835,13 @@ @@ -849,7 +849,7 @@ @@ -915,8 +915,8 @@ } ?> - > + @@ -926,8 +926,8 @@
-
+ @@ -936,7 +936,7 @@ '; - } + } echo '
'; echo '
'; - } + } echo ''; echo ''; echo ' '; - if (AuthenticationManager::getCurrentUser()->isAddRecordsEnabled()) { - echo ' '; - } + if (AuthenticationManager::getCurrentUser()->isAddRecordsEnabled()) { + echo ' '; + } echo ' 0) { - echo " onclick=\"javascript:document.location='v2/family/$iFamilyID';\">"; - } else { - echo " onclick=\"javascript:document.location='" . SystemURLs::getRootPath() . "/v2/family';\">"; - } + if ($iFamilyID > 0) { + echo " onclick=\"javascript:document.location='v2/family/$iFamilyID';\">"; + } else { + echo " onclick=\"javascript:document.location='" . SystemURLs::getRootPath() . "/v2/family';\">"; + } echo ''; - ?> + ?> ' . gettext('Fiscal Year:') . ''; echo ''; - PrintFYIDSelect($iFYID, 'FYID'); + PrintFYIDSelect('FYID', $iFYID); echo ''; } diff --git a/src/FundRaiserEditor.php b/src/FundRaiserEditor.php index dbc89c36dd..5aab67306f 100644 --- a/src/FundRaiserEditor.php +++ b/src/FundRaiserEditor.php @@ -141,9 +141,9 @@ + } else { + echo 'v2/dashboard'; + } ?>';"> 0) { echo '\n"; @@ -250,7 +250,7 @@ Delete - diff --git a/src/GroupList.php b/src/GroupList.php index 47c4b32166..e988a11395 100644 --- a/src/GroupList.php +++ b/src/GroupList.php @@ -34,7 +34,7 @@ isManageGroupsEnabled()) { -?> + ?>
diff --git a/src/GroupPropsEditor.php b/src/GroupPropsEditor.php index 73dd12f22b..1ed635eefe 100644 --- a/src/GroupPropsEditor.php +++ b/src/GroupPropsEditor.php @@ -101,16 +101,16 @@ require 'Include/Header.php'; -if (mysqli_num_rows($rsPropList) == 0) { -?> +if (mysqli_num_rows($rsPropList) === 0) { + ?>


- + ?>
@@ -145,7 +145,7 @@ - @@ -159,6 +159,6 @@
- + ?>

- + ?>
@@ -285,7 +285,7 @@ + ?>

@@ -349,10 +349,10 @@ > + } ?>> - @@ -369,7 +369,7 @@ - diff --git a/src/GroupReports.php b/src/GroupReports.php index ed9dd4d9c7..69535b183c 100644 --- a/src/GroupReports.php +++ b/src/GroupReports.php @@ -141,6 +141,6 @@ -getId() . '">' . gettext('Edit this Group') . ''; echo ''; ?> - getHasSpecialProps()) { echo '' . gettext('Edit Group-Specific Properties Form') . ''; } @@ -115,7 +115,7 @@ if (AuthenticationManager::getCurrentUser()->isEmailEnabled()) { // Does user have permission to email groups // Display link - ?> + ?>
-