<commit_before><?php
/*******************************************************************************
 *
 *  filename    : SundaySchoolReports.php
 *  last change : 2003-09-03
 *  description : form to invoke Sunday School reports
 *
 *  edited by <NAME>/June 2006 - added capability to include multiple groups.  Group reports are printed with a page break between group selections.
 *
 ******************************************************************************/

// Include the function library
require '../Include/Config.php';
require '../Include/Functions.php';
use ChurchCRM\UserQuery;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\dto\SystemConfig;

// Get all the groups
$sSQL = 'SELECT * FROM group_grp WHERE grp_Type=4 ORDER BY grp_Name';
$rsGroups = RunQuery($sSQL);

// Set the page title and include HTML header
$sPageTitle = gettext('Sunday School Reports');
require '../Include/Header.php';

// Is this the second pass?
if (isset($_POST['SubmitClassList']) || isset($_POST['SubmitClassAttendance'])) {
    $iFYID = InputUtils::LegacyFilterInput($_POST['FYID'], 'int');
    
    $dFirstSunday = InputUtils::LegacyFilterInput($_POST['FirstSunday'],'date');
    $dLastSunday = InputUtils::LegacyFilterInput($_POST['LastSunday'],'date');
    $dNoSchool1 = InputUtils::LegacyFilterInput($_POST['NoSchool1'],'date');
    $dNoSchool2 = InputUtils::LegacyFilterInput($_POST['NoSchool2'],'date');
    $dNoSchool3 = InputUtils::LegacyFilterInput($_POST['NoSchool3'],'date');
    $dNoSchool4 = InputUtils::LegacyFilterInput($_POST['NoSchool4'],'date');
    $dNoSchool5 = InputUtils::LegacyFilterInput($_POST['NoSchool5'],'date');
    $dNoSchool6 = InputUtils::LegacyFilterInput($_POST['NoSchool6'],'date');
    $dNoSchool7 = InputUtils::LegacyFilterInput($_POST['NoSchool7'],'date');
    $dNoSchool8 = InputUtils::LegacyFilterInput($_POST['NoSchool8'],'date');
    $iExtraStudents = InputUtils::LegacyFilterInput($_POST['ExtraStudents'], 'int');
    $iExtraTeachers = InputUtils::LegacyFilterInput($_POST['ExtraTeachers'], 'int');
    $_SESSION['idefaultFY'] = $iFYID;

    $bAtLeastOneGroup = false;

    if (!empty($_POST['GroupID'])) {
        $count = 0;
        foreach ($_POST['GroupID'] as $Grp) {
            $aGroups[$count++] = InputUtils::LegacyFilterInput($Grp, 'int');
        }
        $aGrpID = implode(',', $aGroups);
        $bAtLeastOneGroup = true;
    }
    
    $allroles = InputUtils::LegacyFilterInput($_POST['allroles']);
    $withPictures = InputUtils::LegacyFilterInput($_POST['withPictures']);

    $currentUser = UserQuery::create()->findPk($_SESSION['iUserID']);
    $currentUser->setCalStart($dFirstSunday);
    $currentUser->setCalEnd($dLastSunday);
    $currentUser->setCalNoSchool1($dNoSchool1);
    $currentUser->setCalNoSchool2($dNoSchool2);
    $currentUser->setCalNoSchool3($dNoSchool3);
    $currentUser->setCalNoSchool4($dNoSchool4);
    $currentUser->setCalNoSchool5($dNoSchool5);
    $currentUser->setCalNoSchool6($dNoSchool6);
    $currentUser->setCalNoSchool7($dNoSchool7);
    $currentUser->setCalNoSchool7($dNoSchool8);
    $currentUser->save();

    if ($bAtLeastOneGroup && isset($_POST['SubmitClassList']) && $aGrpID != 0) {
        Redirect('Reports/ClassList.php?GroupID='.$aGrpID.'&FYID='.$iFYID.'&FirstSunday='.$dFirstSunday.'&LastSunday='.$dLastSunday.'&AllRoles='.$allroles);
    } elseif ($bAtLeastOneGroup && isset($_POST['SubmitClassAttendance']) && $aGrpID != 0) {
        $toStr = 'Reports/ClassAttendance.php?';
        //	      $toStr .= "GroupID=" . $iGroupID;
        $toStr .= 'GroupID='.$aGrpID;
        $toStr .= '&FYID='.$iFYID;
        $toStr .= '&FirstSunday='.$dFirstSunday;
        $toStr .= '&LastSunday='.$dLastSunday;
        $toStr .= '&AllRoles='.$allroles;
        $toStr .= '&withPictures='.$withPictures;
        if ($dNoSchool1) {
            $toStr .= '&NoSchool1='.$dNoSchool1;
        }
        if ($dNoSchool2) {
            $toStr .= '&NoSchool2='.$dNoSchool2;
        }
        if ($dNoSchool3) {
            $toStr .= '&NoSchool3='.$dNoSchool3;
        }
        if ($dNoSchool4) {
            $toStr .= '&NoSchool4='.$dNoSchool4;
        }
        if ($dNoSchool5) {
            $toStr .= '&NoSchool5='.$dNoSchool5;
        }
        if ($dNoSchool6) {
            $toStr .= '&NoSchool6='.$dNoSchool6;
        }
        if ($dNoSchool7) {
            $toStr .= '&NoSchool7='.$dNoSchool7;
        }
        if ($dNoSchool8) {
            $toStr .= '&NoSchool8='.$dNoSchool8;
        }
        if ($iExtraStudents) {
            $toStr .= '&ExtraStudents='.$iExtraStudents;
        }
        if ($iExtraTeachers) {
            $toStr .= '&ExtraTeachers='.$iExtraTeachers;
        }
        Redirect($toStr);
    } elseif (!$bAtLeastOneGroup || $aGrpID == 0) {
        echo "<p class=\"alert alert-danger\"><span class=\"fa fa-exclamation-triangle\"> ".gettext('At least one group must be selected to make class lists or attendance sheets.')."</span></p>";
    }
} else {
    $iFYID = $_SESSION['idefaultFY'];
    $iGroupID = 0;
    $currentUser = UserQuery::create()->findPk($_SESSION['iUserID']);
    
    if ($currentUser->getCalStart() != null)
	    $dFirstSunday = $currentUser->getCalStart()->format('Y-m-d');
    if ($currentUser->getCalEnd() != null)
	    $dLastSunday = $currentUser->getCalEnd()->format('Y-m-d');
    if ($currentUser->getCalNoSchool1() != null)
	    $dNoSchool1 = $currentUser->getCalNoSchool1()->format('Y-m-d');
    if ($currentUser->getCalNoSchool2() != null)
	    $dNoSchool2 = $currentUser->getCalNoSchool2()->format('Y-m-d');
    if ($currentUser->getCalNoSchool3() != null)
	    $dNoSchool3 = $currentUser->getCalNoSchool3()->format('Y-m-d');
    if ($currentUser->getCalNoSchool4() != null)
	    $dNoSchool4 = $currentUser->getCalNoSchool4()->format('Y-m-d');
    if ($currentUser->getCalNoSchool5() != null)
	    $dNoSchool5 = $currentUser->getCalNoSchool5()->format('Y-m-d');
    if ($currentUser->getCalNoSchool6() != null)
	    $dNoSchool6 = $currentUser->getCalNoSchool6()->format('Y-m-d');
    if ($currentUser->getCalNoSchool7() != null)
	    $dNoSchool7 = $currentUser->getCalNoSchool7()->format('Y-m-d');
    if ($currentUser->getCalNoSchool8() != null)
	    $dNoSchool8 = $currentUser->getCalNoSchool8()->format('Y-m-d');
	    
    $iExtraStudents = 0;<commit_msg>Apply fixes from StyleCI (#3118)<commit_after><?php
/*******************************************************************************
 *
 *  filename    : SundaySchoolReports.php
 *  last change : 2003-09-03
 *  description : form to invoke Sunday School reports
 *
 *  edited by <NAME>/June 2006 - added capability to include multiple groups.  Group reports are printed with a page break between group selections.
 *
 ******************************************************************************/

// Include the function library
require '../Include/Config.php';
require '../Include/Functions.php';
use ChurchCRM\UserQuery;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\dto\SystemConfig;

// Get all the groups
$sSQL = 'SELECT * FROM group_grp WHERE grp_Type=4 ORDER BY grp_Name';
$rsGroups = RunQuery($sSQL);

// Set the page title and include HTML header
$sPageTitle = gettext('Sunday School Reports');
require '../Include/Header.php';

// Is this the second pass?
if (isset($_POST['SubmitClassList']) || isset($_POST['SubmitClassAttendance'])) {
    $iFYID = InputUtils::LegacyFilterInput($_POST['FYID'], 'int');
    
    $dFirstSunday = InputUtils::LegacyFilterInput($_POST['FirstSunday'], 'date');
    $dLastSunday = InputUtils::LegacyFilterInput($_POST['LastSunday'], 'date');
    $dNoSchool1 = InputUtils::LegacyFilterInput($_POST['NoSchool1'], 'date');
    $dNoSchool2 = InputUtils::LegacyFilterInput($_POST['NoSchool2'], 'date');
    $dNoSchool3 = InputUtils::LegacyFilterInput($_POST['NoSchool3'], 'date');
    $dNoSchool4 = InputUtils::LegacyFilterInput($_POST['NoSchool4'], 'date');
    $dNoSchool5 = InputUtils::LegacyFilterInput($_POST['NoSchool5'], 'date');
    $dNoSchool6 = InputUtils::LegacyFilterInput($_POST['NoSchool6'], 'date');
    $dNoSchool7 = InputUtils::LegacyFilterInput($_POST['NoSchool7'], 'date');
    $dNoSchool8 = InputUtils::LegacyFilterInput($_POST['NoSchool8'], 'date');
    $iExtraStudents = InputUtils::LegacyFilterInput($_POST['ExtraStudents'], 'int');
    $iExtraTeachers = InputUtils::LegacyFilterInput($_POST['ExtraTeachers'], 'int');
    $_SESSION['idefaultFY'] = $iFYID;

    $bAtLeastOneGroup = false;

    if (!empty($_POST['GroupID'])) {
        $count = 0;
        foreach ($_POST['GroupID'] as $Grp) {
            $aGroups[$count++] = InputUtils::LegacyFilterInput($Grp, 'int');
        }
        $aGrpID = implode(',', $aGroups);
        $bAtLeastOneGroup = true;
    }
    
    $allroles = InputUtils::LegacyFilterInput($_POST['allroles']);
    $withPictures = InputUtils::LegacyFilterInput($_POST['withPictures']);

    $currentUser = UserQuery::create()->findPk($_SESSION['iUserID']);
    $currentUser->setCalStart($dFirstSunday);
    $currentUser->setCalEnd($dLastSunday);
    $currentUser->setCalNoSchool1($dNoSchool1);
    $currentUser->setCalNoSchool2($dNoSchool2);
    $currentUser->setCalNoSchool3($dNoSchool3);
    $currentUser->setCalNoSchool4($dNoSchool4);
    $currentUser->setCalNoSchool5($dNoSchool5);
    $currentUser->setCalNoSchool6($dNoSchool6);
    $currentUser->setCalNoSchool7($dNoSchool7);
    $currentUser->setCalNoSchool7($dNoSchool8);
    $currentUser->save();

    if ($bAtLeastOneGroup && isset($_POST['SubmitClassList']) && $aGrpID != 0) {
        Redirect('Reports/ClassList.php?GroupID='.$aGrpID.'&FYID='.$iFYID.'&FirstSunday='.$dFirstSunday.'&LastSunday='.$dLastSunday.'&AllRoles='.$allroles);
    } elseif ($bAtLeastOneGroup && isset($_POST['SubmitClassAttendance']) && $aGrpID != 0) {
        $toStr = 'Reports/ClassAttendance.php?';
        //	      $toStr .= "GroupID=" . $iGroupID;
        $toStr .= 'GroupID='.$aGrpID;
        $toStr .= '&FYID='.$iFYID;
        $toStr .= '&FirstSunday='.$dFirstSunday;
        $toStr .= '&LastSunday='.$dLastSunday;
        $toStr .= '&AllRoles='.$allroles;
        $toStr .= '&withPictures='.$withPictures;
        if ($dNoSchool1) {
            $toStr .= '&NoSchool1='.$dNoSchool1;
        }
        if ($dNoSchool2) {
            $toStr .= '&NoSchool2='.$dNoSchool2;
        }
        if ($dNoSchool3) {
            $toStr .= '&NoSchool3='.$dNoSchool3;
        }
        if ($dNoSchool4) {
            $toStr .= '&NoSchool4='.$dNoSchool4;
        }
        if ($dNoSchool5) {
            $toStr .= '&NoSchool5='.$dNoSchool5;
        }
        if ($dNoSchool6) {
            $toStr .= '&NoSchool6='.$dNoSchool6;
        }
        if ($dNoSchool7) {
            $toStr .= '&NoSchool7='.$dNoSchool7;
        }
        if ($dNoSchool8) {
            $toStr .= '&NoSchool8='.$dNoSchool8;
        }
        if ($iExtraStudents) {
            $toStr .= '&ExtraStudents='.$iExtraStudents;
        }
        if ($iExtraTeachers) {
            $toStr .= '&ExtraTeachers='.$iExtraTeachers;
        }
        Redirect($toStr);
    } elseif (!$bAtLeastOneGroup || $aGrpID == 0) {
        echo "<p class=\"alert alert-danger\"><span class=\"fa fa-exclamation-triangle\"> ".gettext('At least one group must be selected to make class lists or attendance sheets.')."</span></p>";
    }
} else {
    $iFYID = $_SESSION['idefaultFY'];
    $iGroupID = 0;
    $currentUser = UserQuery::create()->findPk($_SESSION['iUserID']);
    
    if ($currentUser->getCalStart() != null) {
        $dFirstSunday = $currentUser->getCalStart()->format('Y-m-d');
    }
    if ($currentUser->getCalEnd() != null) {
        $dLastSunday = $currentUser->getCalEnd()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool1() != null) {
        $dNoSchool1 = $currentUser->getCalNoSchool1()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool2() != null) {
        $dNoSchool2 = $currentUser->getCalNoSchool2()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool3() != null) {
        $dNoSchool3 = $currentUser->getCalNoSchool3()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool4() != null) {
        $dNoSchool4 = $currentUser->getCalNoSchool4()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool5() != null) {
        $dNoSchool5 = $currentUser->getCalNoSchool5()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool6() != null) {
        $dNoSchool6 = $currentUser->getCalNoSchool6()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool7() != null) {
        $dNoSchool7 = $currentUser->getCalNoSchool7()->format('Y-m-d');
    }
    if ($currentUser->getCalNoSchool8() != null) {
        $dNoSchool8 = $currentUser->getCalNoSchool8()->format('Y-m-d');
    }
        
    $iExtraStudents = 0;
{'fraction_non_alphanumeric': 0.20208758436666144, 'fraction_numerical': 0.01585308428818082, 'mean_word_length': 3.6746148202494497, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1676926', 'n_tokens_mistral': 4504, 'n_tokens_neox': 4150, 'n_words': 619}