<?php

global $genumDateFormat;
echoT($strHTMLSummary);
$params = array('enumStyle' => 'terse');
$clsRpt = new generic_rpt($params);
$clsRpt->strWidthLabel = '180pt';
$attributes = new stdClass();
$attributes->width = null;
$bReadOnly = $utable->bReadOnly;
if ($bMultiEntry && !$bReadOnly) {
    $strLinkRem = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . strLinkRem_UFMultiRecEntry($utable->enumTType, $lTableID, $lFID, $lRID, 'Remove', true, true) . '&nbsp;' . strLinkRem_UFMultiRecEntry($utable->enumTType, $lTableID, $lFID, $lRID, 'Remove', false, true);
} else {
    $strLinkRem = '';
}
if ($bReadOnly) {
    $strLinkEdit = '';
} else {
    $strLinkEdit = strLinkEdit_UFMultiRecEntry($utable->enumTType, $lTableID, $lFID, $lRID, true, 'Edit record', ' id="editURec_' . $lTableID . '_' . $lRID . '" ', $lEnrollRecID) . '&nbsp;' . strLinkEdit_UFMultiRecEntry($utable->enumTType, $lTableID, $lFID, $lRID, false, 'Edit record', ' id="editURec1_' . $lTableID . '_' . $lRID . '" ', $lEnrollRecID);
}
if ($bCProg && !$bEnrollment) {
    $strCloneAttendance = '&nbsp;&nbsp;&nbsp;' . strLinkClone_CPAttendance($cprog->lKeyID, $lRID, 'Clone ' . $cprog->strSafeAttendLabel, true) . '&nbsp;' . strLinkClone_CPAttendance($cprog->lKeyID, $lRID, 'Clone ' . $cprog->strSafeAttendLabel, false) . '&nbsp';
} else {
    $strCloneAttendance = '';
}
openBlock($strTableLabel, $strLinkEdit . $strCloneAttendance . $strLinkRem);
echoT($clsRpt->openReport(800));
if ($utable->lNumFields == 0 && !$bCProg) {
    echoT('<i>There is no data associated with this record!</i><br>');
} else {
    echoT($clsRpt->openRow() . $clsRpt->writeLabel('tableID:') . $clsRpt->writeCell(str_pad($lTableID, 5, '0', STR_PAD_LEFT)) . $clsRpt->closeRow());
function writeMRecRows($lTableID, $lFID, &$utable, &$mRecs, $lEnrollRecID)
{
    //---------------------------------------------------------------------
    //
    //---------------------------------------------------------------------
    global $genumDateFormat;
    $strFNPrefix = $utable->strFieldPrefix;
    $strFNKeyID = $strFNPrefix . '_lKeyID';
    if ($utable->bCProg) {
        $lCProgID = $utable->cprog->lKeyID;
    }
    $bReadOnly = $utable->bReadOnly;
    foreach ($mRecs as $mrec) {
        echoT('<tr class="makeStripe">');
        $lRecID = $mrec->{$strFNKeyID};
        if ($utable->bCProg && !$utable->bEnrollment) {
            $strClone = '<br>' . strLinkClone_CPAttendance($lCProgID, $lRecID, 'Clone attendance record', true);
        } else {
            $strClone = '';
        }
        if ($bReadOnly) {
            $strEditLink = '';
        } else {
            $strEditLink = strLinkEdit_UFMultiRecEntry($utable->enumTType, $lTableID, $lFID, $lRecID, true, 'Edit record', '', $lEnrollRecID);
        }
        echoT('
            <td class="enpRpt" style="text-align: center;">' . str_pad($lRecID, 5, '0', STR_PAD_LEFT) . '&nbsp;' . strLinkView_UFMFRecordViaRecID($lTableID, $lFID, $lRecID, 'View', true) . '
            </td>');
        echoT('
            <td class="enpRpt" style="text-align: center;">' . $strEditLink . $strClone . '
            </td>');
        if (!$bReadOnly) {
            echoT('
               <td class="enpRpt" style="text-align: center;">' . strLinkRem_UFMultiRecEntry($utable->enumTType, $lTableID, $lFID, $lRecID, 'Remove', true, true) . '
               </td>');
        }
        if ($utable->bCProg) {
            //-----------------------------
            // enrollment records
            //-----------------------------
            if ($utable->bEnrollment) {
                echoT('
                  <td class="enpRpt">' . date($genumDateFormat, $mrec->dteStart) . '&nbsp;
                  </td>');
                if (is_null($mrec->dteMysqlEnd)) {
                    $strEnd = '<i>Ongoing</i>';
                } else {
                    $strEnd = date($genumDateFormat, $mrec->dteEnd);
                }
                echoT('
                     <td class="enpRpt" style="text-align: center;">' . $strEnd . '
                     </td>
                     <td class="enpRpt" style="text-align: center;">' . ($mrec->bCurrentlyEnrolled ? 'Yes' : 'No') . '
                     </td>
                     <td class="enpRpt" style="text-align: center;">' . strLinkAdd_CProgAttendance(false, $lFID, $utable->cprog->lKeyID, $lRecID, 'Add attendance record', true) . '
                     </td>
                     ');
            } else {
                //-----------------------------
                // attendance records
                //-----------------------------
                echoT('
                  <td class="enpRpt" style="text-align: center;">' . str_pad($mrec->lEnrollRecordID, 5, '0', STR_PAD_LEFT) . '&nbsp;' . strLinkView_UFMFRecordViaRecID($utable->cprog->lEnrollmentTableID, $lFID, $mrec->lEnrollRecordID, 'View enrollment record', true) . '
                  </td>
                  <td class="enpRpt">' . date($genumDateFormat, $mrec->dteAttendance) . '&nbsp;
                  </td>
                  <td class="enpRpt" style="text-align: right;">' . number_format($mrec->dDuration, 2) . '&nbsp;
                  </td>
                  <td class="enpRpt" style="width: 220pt;">' . nl2br(htmlspecialchars($mrec->strCaseNotes)) . '&nbsp;
                  </td>
                  ');
                $utable->dTotDuration += $mrec->dDuration;
            }
        }
        if ($utable->lNumFields > 0) {
            foreach ($utable->ufields as $ufield) {
                displayField($mrec, $ufield);
            }
        }
        echoT('</tr>');
    }
}