function lNumClientsInAgeRange($bActive, $lAgeStart, $lAgeEnd)
 {
     //---------------------------------------------------------------------
     //
     //---------------------------------------------------------------------
     global $gdteNow;
     $mysqlDteBase = str_replace("'", '', strPrepDate($gdteNow));
     dateRangeYears($mysqlDteBase, $lAgeStart, $lAgeEnd, $mysqlStartDate, $mysqlEndDate);
     if ($bActive) {
         $strInnerExtra = '
            INNER JOIN client_status                      ON csh_lClientID   = cr_lKeyID
            INNER JOIN lists_client_status_entries        ON csh_lStatusID   = cst_lKeyID
         ';
         $strSubQuery = '
              -- ---------------------------------------
              -- subquery to find most current status
              -- ---------------------------------------
            AND csh_lKeyID=(SELECT csh_lKeyID
                            FROM client_status
                            WHERE csh_lClientID=cr_lKeyID
                               AND NOT csh_bRetired
                            ORDER BY csh_dteStatusDate DESC, csh_lKeyID DESC
                            LIMIT 0,1)
            ';
         $strExtraClientWhere = ' AND cst_bShowInDir ';
     } else {
         $strInnerExtra = $strSubQuery = '';
         $strExtraClientWhere = '';
     }
     $sqlStr = "SELECT COUNT(*) AS lNumClients\n            FROM client_records\n               {$strInnerExtra}\n            WHERE 1\n               AND NOT cr_bRetired\n               {$strSubQuery}\n               {$strExtraClientWhere}\n               AND cr_dteBirth > " . strPrepStr($mysqlStartDate) . '
            AND cr_dteBirth <=' . strPrepStr($mysqlEndDate) . ';';
     $query = $this->db->query($sqlStr);
     $row = $query->row();
     return $row->lNumClients;
 }
 function strClientAgeReport(&$sRpt, $lStartRec, $lRecsPerPage)
 {
     //---------------------------------------------------------------------
     //
     //---------------------------------------------------------------------
     global $gdteNow;
     $cClient = new mclients();
     $strOut = '';
     $mysqlDteBase = str_replace("'", '', strPrepDate($gdteNow));
     dateRangeYears($mysqlDteBase, $sRpt->lStartAge, $sRpt->lEndAge, $mysqlStartDate, $mysqlEndDate);
     $cClient->strClientLimit = " LIMIT {$lStartRec}, {$lRecsPerPage} ";
     $cClient->strExtraClientWhere = "\n            AND cst_bShowInDir\n            AND cr_dteBirth > " . strPrepStr($mysqlStartDate) . '
         AND cr_dteBirth <=' . strPrepStr($mysqlEndDate) . ' ';
     $cClient->loadClientsGeneric();
     if ($cClient->lNumClients == 0) {
         return '<i><br>There are no clients who meet your search criteria.</i>';
     } else {
         return $this->strBasicClientRpt($cClient, 'Client Age: ' . htmlspecialchars($sRpt->label));
     }
 }