<?php

if ($lNumShifts <= 0) {
    echoT('There are no shifts assigned to this event. Please create one or more shifts, then<br>
          add volunteers to the shift.<br><br>');
} elseif ($lNumVols <= 0) {
    echoT('There are no volunteers assigned to this event. Please create one or more shifts, then<br>
          add volunteers to the shift.<br><br>');
} else {
    foreach ($shifts as $shift) {
        $lShiftID = $shift->lKeyID;
        if ($shift->lNumVolsInShift > 0) {
            $strBlockLink = strLinkEdit_VolEventHrs($lEventID, $lShiftID, 'Edit hours for this shift', true);
        } else {
            $strBlockLink = '';
        }
        openBlock(date('F j Y', $shift->dteEvent) . '&nbsp&nbsp;' . date('g:i a', $shift->dteEventStartTime) . ': ' . '<b>' . htmlspecialchars($shift->strShiftName) . '</b> (' . $shift->enumDuration . ')', $strBlockLink);
        echoT('<table>');
        if ($shift->lNumVolsInShift > 0) {
            $dTotHrs = 0.0;
            foreach ($shift->vols as $vol) {
                $lVolID = $vol->lVolID;
                $dTotHrs += $vol->dHoursWorked;
                echoT('
               <tr>
                  <td style="width: 50px;">' . strLinkView_Volunteer($lVolID, 'View volunteer record', true) . str_pad($lVolID, 5, '0', STR_PAD_LEFT) . '
                  </td>
                  <td style="width: 250px;">' . htmlspecialchars($vol->strLName . ', ' . $vol->strFName) . '
                  </td>
                  <td style="width: 90px;">&nbsp;hours logged:</td>
                  <td style="width: 50px; text-align: right;">' . number_format($vol->dHoursWorked, 2) . '
 private function strVolHoursPVADetailReport($sRpt, $lStartRec, $lRecsPerPage)
 {
     //---------------------------------------------------------------------
     //
     //---------------------------------------------------------------------
     global $genumDateFormat;
     $strTimeFormat = strMysqlTimeFormat();
     $this->pvaHoursDetailVars($sRpt, $dteStart, $dteEnd, $lVolID);
     $strLimit = " LIMIT {$lStartRec}, {$lRecsPerPage} ";
     $strOut = $this->strHrsPVADetailsLabel($sRpt, $dteStart, $dteEnd, $lVolID);
     $sqlStr = 'SELECT vsa_lKeyID,
            vem_lKeyID, vem_strEventName,
            ved_lKeyID, ved_dteEvent,
            vsa_dHoursWorked,
            vs_lKeyID, vs_strShiftName, vs_enumDuration,
            DATE_FORMAT(vs_dteShiftStartTime, ' . $strTimeFormat . ') AS strStart
         FROM vol_events_dates_shifts_assign
            INNER JOIN vol_events_dates_shifts ON vsa_lEventDateShiftID = vs_lKeyID
            INNER JOIN vol_events_dates        ON vs_lEventDateID = ved_lKeyID
            INNER JOIN vol_events              ON ved_lVolEventID = vem_lKeyID
         WHERE NOT vsa_bRetired
            AND NOT vs_bRetired
            AND NOT vem_bRetired
            AND (ved_dteEvent BETWEEN ' . strPrepDate($dteStart) . ' AND ' . strPrepDateTime($dteEnd) . " )\n               AND vsa_lVolID={$lVolID}\n            ORDER BY ved_dteEvent, vs_dteShiftStartTime, vsa_lKeyID\n            {$strLimit};";
     $query = $this->db->query($sqlStr);
     $lNumRows = $query->num_rows();
     if ($lNumRows == 0) {
         return $strOut . '<br><br><i>There are no records that match your search criteria.</i>';
     }
     $strOut .= '
        <table class="enpRptC">
           <tr>
              <td class="enpRptLabel">
                 event ID
              </td>
              <td class="enpRptLabel">
                 Event
              </td>
              <td class="enpRptLabel">
                 Date
              </td>
              <td class="enpRptLabel">
                 Shift
              </td>
              <td class="enpRptLabel">
                 Start Time
              </td>
              <td class="enpRptLabel">
                 Hours Logged
              </td>
              <td class="enpRptLabel">
                 Hours Scheduled
              </td>
           </tr>';
     foreach ($query->result() as $row) {
         $lEventID = $row->vem_lKeyID;
         $lEDateID = $row->ved_lKeyID;
         $lShiftID = $row->vs_lKeyID;
         $strOut .= '<tr class="makeStripe">
            <td class="enpRpt" style="text-align: center;">' . strLinkView_VolEvent($lEventID, 'View event record', true) . '&nbsp;' . str_pad($lEventID, 5, '0', STR_PAD_LEFT) . '
            </td>
            <td class="enpRpt" >' . htmlspecialchars($row->vem_strEventName) . '
            </td>
            <td class="enpRpt" style="text-align: right">' . date($genumDateFormat, dteMySQLDate2Unix($row->ved_dteEvent)) . '&nbsp;' . strLinkView_VolEventDate($lEDateID, 'View event date/shifts', true) . '
            </td>
            <td class="enpRpt">' . htmlspecialchars($row->vs_strShiftName) . '
            </td>
            <td class="enpRpt" style="text-align: right">' . $row->strStart . '
            </td>
            <td class="enpRpt" style="text-align: right">' . number_format($row->vsa_dHoursWorked, 2) . '&nbsp;' . strLinkEdit_VolEventHrs($lEventID, $lShiftID, 'Edit volunteer hours for this shift', true) . '
            </td>
            <td class="enpRpt" style="text-align: right">' . number_format(tdh\sngXlateDuration($row->vs_enumDuration), 2) . '
            </td>
          </tr>';
     }
     $strOut .= '</table><br>';
     return $strOut;
 }