Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/cceconvenors/
Upload File :
Current File : /var/www/cesa.co.za/cceconvenors/assigsummary.php

<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "CCEAssignmentsinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
if (!isset($_SESSION[EW_SESSION_STATUS]) || ($_SESSION[EW_SESSION_STATUS] != "login")) {
    header("Location: cceconvenors/login.php");
    die();
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0

$assigSummaryPage = true;
include_once('header.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/BaseTableClass.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/CCEStudentAssignment.php');
?>
<h1> Assignment Submissions Summary</h1>
<p><strong>Module totals:</strong> assignment average (0-10 scale).</p>
<p>Students excluded from a module show <strong>-</strong> for that module and are omitted from averages.</p>
<?php

$conn = mysqli_connect(EW_CONN_HOST, EW_CONN_USER, EW_CONN_PASS, EW_CONN_DB);
$sql = "SELECT CCEAssignments.*, CCEModules.ModuleName
    FROM CCEAssignments
    INNER JOIN CCEModules ON CCEAssignments.CCEModuleID = CCEModules.CCEModuleID
    WHERE Archived=0 AND AssigType IN (0,2) AND ReleaseDate <= '" . date("Y-m-d") . "'
    ORDER BY CCEModules.CCEModuleID, RefNum";
//echo $sql . '<br />';
$rec = mysqli_query($conn, $sql);
$assignmentRows = array();
while ($row = mysqli_fetch_assoc($rec)) {
    $assignmentRows[] = $row;
}
mysqli_free_result($rec);

$moduleGroupHeaders = array();
foreach ($assignmentRows as $row) {
    $moduleId = (int) $row['CCEModuleID'];
    if (!isset($moduleGroupHeaders[$moduleId])) {
        $moduleGroupHeaders[$moduleId] = array(
            'moduleId' => $moduleId,
            'name' => $row['ModuleName'],
            'assignments' => 0,
        );
    }
    $moduleGroupHeaders[$moduleId]['assignments']++;
}
foreach ($moduleGroupHeaders as $moduleId => $group) {
    $moduleGroupHeaders[$moduleId]['colspan'] = $group['assignments'] + 1;
}

$sqlStudents = "SELECT CCEStudents.CCEStudentID, CCEStudents.Surname, CCEStudents.FirstName, CCEStudents.KnownAs,
        CCEStudents.ModulesEnrolled, CCEStudents.ModulesExcluded, CCEFacilitators.FacilitatorName, CCEStudents.StudentNumber
    FROM (CCEStudents INNER JOIN CCEStudentCourses USING (CCEStudentID)
    inner join CCESetup ON (CCEStudentCourses.CCECourseScheduleID=CCESetup.CurrentScheduleID))
    LEFT JOIN CCEFacilitators ON (CCEFacilitatorID=FacilitatorID)
    WHERE CCEStudents.Archived <> 1 ";
if (true || $env == 'prod') {
    $sqlStudents .= " AND CCEStudents.CCEStudentID <> 54 ";
}
$sqlStudents .= " ORDER BY " . CCEStudentDisplayOrder::sqlOrderByDisplayName('CCEStudents');
$recStudents = mysqli_query($conn, $sqlStudents);
$studentRows = array();
while ($rowStudents = mysqli_fetch_assoc($recStudents)) {
    $studentRows[] = $rowStudents;
}
mysqli_free_result($recStudents);
$numStdudents = count($studentRows);

?>
<div class="assig-summary-filters">
<table class="table assig-summary-filters-table" cellpadding="5" cellspacing="0">
    <tr>
        <th>Filters</th>
        <td width="16%" align="center"><input type="radio" class="module-filter" name="check-module" id="check-all"
                value="0" checked /> All</td>
        <td width="16%" align="center"><input type="radio" class="module-filter" name="check-module" id="check-cce"
                value="1" /> Consulting Engineering Environment</td>
        <td width="16%" align="center"><input type="radio" class="module-filter" name="check-module" id="check-pd"
                value="2" /> Project Delivery</td>
        <td width="16%" align="center"><input type="radio" class="module-filter" name="check-module" id="check-fin"
                value="3" /> Finance</td>
        <td width="16%" align="center"><input type="radio" class="module-filter" name="check-module" id="check-law"
                value="4" /> Law</td>
        <td width="16%" align="center"><input type="radio" class="module-filter" name="check-module" id="check-is"
                value="5" /> Interpersonal Skills</td>
    </tr>
    <tr>
        <th colspan="2">Average</th>
        <td align="center" valign="top">
            <?php echo round(GetAverageAssigScore(0, true, 1), 2); ?>
        </td>
        <td align="center" valign="top">
            <?php echo round(GetAverageAssigScore(0, true, 2), 2); ?>
        </td>
        <td align="center" valign="top">
            <?php echo round(GetAverageAssigScore(0, true, 3), 2); ?>
        </td>
        <td align="center" valign="top">
            <?php echo round(GetAverageAssigScore(0, true, 4), 2); ?>
        </td>
        <td align="center" valign="top">
            <?php echo round(GetAverageAssigScore(0, true, 5), 2); ?>
        </td>
    </tr>
</table>
</div>

<?php

$assigStickyWidthPx = 200;
$assigModuleAvgWidthPx = 48;
$assigAssignmentWidthPx = 76;
$assigTableMinWidthPx = $assigStickyWidthPx
    + (count($moduleGroupHeaders) * $assigModuleAvgWidthPx)
    + (count($assignmentRows) * $assigAssignmentWidthPx);
?>

<div class="assig-summary-wrapper" id="assig-summary-wrapper" style="--assig-table-min-width: <?php echo (int) $assigTableMinWidthPx; ?>px">
    <div class="assig-summary-scroll">
    <table cellspacing="0" cellpadding="2" class="table assig-summary-table">
        <colgroup>
            <col class="sticky-col-name">
            <col class="sticky-col-avg">
            <?php
            $prevMod = '';
            foreach ($assignmentRows as $row) {
                if ($prevMod != $row['CCEModuleID']) {
                    ?>
                    <col class="assig-col-module-avg mod-cell-<?php echo (int) $row['CCEModuleID']; ?>">
                    <?php
                }
                ?>
                <col class="assig-col-assignment mod-cell-<?php echo (int) $row['CCEModuleID']; ?>">
                <?php
                $prevMod = $row['CCEModuleID'];
            }
            ?>
            <col class="assig-col-filler">
        </colgroup>
        <tr class="module-group-header-row">
            <td colspan="2" class="cell darkcell sticky-col sticky-col-name" style="border-right:none;"></td>
            <?php foreach ($moduleGroupHeaders as $group) { ?>
                <td colspan="<?php echo (int) $group['colspan']; ?>"
                    class="cell darkcell mod-cell-<?php echo (int) $group['moduleId']; ?> mod-group-start">
                    <?php echo htmlspecialchars($group['name']); ?>
                </td>
            <?php } ?>
            <td class="assig-col-filler" aria-hidden="true">&nbsp;</td>
        </tr>
        <tr>
            <td class="cell darkcell headingcell sticky-col sticky-col-name">NAME</td>
            <td class="cell darkcell headingcell sticky-col sticky-col-avg" style="border-left:none;">Avg</td>
            <?php
            $dueDateYear = date("Y");
            $prevMod = '';
            $headerCellclass = ' darkcell';
            foreach ($assignmentRows as $row) {
                if ($prevMod != $row['CCEModuleID']) {
                    $groupStartClass = ' mod-group-start';
            ?>
                    <td class="cell<?php echo $headerCellclass; ?> headingcell assig-col-module-avg mod-cell-<?php echo $row['CCEModuleID']; ?><?php echo $groupStartClass; ?>"
                        style="font-size: 10px; text-align: center;">
                        A
                    </td>
                <?php
                }
                $headerCellclass = ' lightcell';
                ?>
                <td class="cell<?php echo $headerCellclass; ?> headingcell assig-col-assignment mod-cell-<?php echo $row['CCEModuleID']; ?>" style="border-left:none;font-size:10px;" valign="top">
                    <?php echo str_replace(" ", "", $row["RefNum"]); ?><br>
                    <?php echo $row["DueDate"]; ?><br />
                    <?php echo GetResubDate($row["CCEAssignmentID"]); ?>
                </td>
            <?php
                $dueDate = new \DateTime($row["DueDate"]);
                $dueDateYear = $dueDate->format("Y");
                $prevMod = $row['CCEModuleID'];
            }
            ?>
            <td class="assig-col-filler" aria-hidden="true">&nbsp;</td>
        </tr>
        <?php
        $iLastFacilitator = "";
        $cellclass = " darkcell";
        foreach ($studentRows as $rowStudents) {
            if ($iLastFacilitator != $rowStudents["FacilitatorName"]) {
                $iLastFacilitator = $rowStudents["FacilitatorName"];
                if ($cellclass == " darkcell") {
                    $cellclass = " lightcell";
                } else {
                    $cellclass = " darkcell";
                }
            }
            $cellclass = " lightcell";
            $displayName = (isset($rowStudents["KnownAs"]) && trim($rowStudents["KnownAs"]) !== "")
                ? $rowStudents["KnownAs"]
                : $rowStudents["FirstName"];
            $excludedModuleIds = CCEStudents::parseModulesExcludedCsv(
                isset($rowStudents["ModulesExcluded"]) ? $rowStudents["ModulesExcluded"] : ''
            );
        ?>
            <tr>
                <td class="cell<?php echo $cellclass; ?> sticky-col sticky-col-name" width="160" style="border-top:none;" nowrap><?php
                    echo $displayName . " " . $rowStudents["Surname"];
                ?></td>
                <td class="cell<?php echo $cellclass; ?> sticky-col sticky-col-avg" width="40" style="border-top:none;border-left:none; text-align: right;" nowrap><?php
                    echo GetAverageAssigScore($rowStudents["CCEStudentID"], true);
                ?></td>
                <?php
                $prevMod = '';
                foreach ($assignmentRows as $row) {
                    $moduleExcluded = in_array((int) $row['CCEModuleID'], $excludedModuleIds, true);
                    $tooltip = "";
                    if ($prevMod != $row['CCEModuleID']) {
                        $groupStartClass = ' mod-group-start';
                ?>
                        <td class="cell assig-col-module-avg mod-cell-<?php echo $row['CCEModuleID']; ?><?php echo $groupStartClass; ?>"
                            style="border-top:none;">
                            <?php
                            if ($moduleExcluded) {
                                echo '-';
                            } else {
                                echo GetAverageAssigScore($rowStudents["CCEStudentID"], true, $row["CCEModuleID"]);
                            }
                            ?>
                        </td>
                        <?php
                    }

                                    if ($moduleExcluded) {
                                        $cellclass2 = "";
                                        $cellvalue = "-";
                                        $tooltip = "Excluded from module";
                                    } elseif (in_array($row["CCEModuleID"], explode(",", $rowStudents["ModulesEnrolled"]))) {

                                        // Achieved assignments that need enhancement must say "E" instead of "Y"
                                        // Enhancements and resubmissions - add an E or an R as required

                                        /* FeedbackReleased: 1 if feedback has been sent (CCEAssignmentFeedback has CCEMessageID); used to choose green vs blue for score cells */
                                        $sql = "SELECT CCEStudentAssignments.*, CCEAssignmentMarking.Ruling AS MarkedRuling, CCEAssignmentMarking.Score, "
                                            . "(SELECT 1 FROM CCEAssignmentFeedback af WHERE af.CCEStudentAssigID = CCEStudentAssignments.CCEStudentAssigID AND af.CCEMessageID IS NOT NULL LIMIT 1) AS FeedbackReleased "
                                            . "FROM CCEStudentAssignments LEFT JOIN CCEAssignmentMarking USING (CCEStudentAssigID) "
                                            . "WHERE CCEStudentID='" . $rowStudents["CCEStudentID"] . "' AND CCEAssignmentID=" . $row["CCEAssignmentID"] . " "
                                            . "AND YEAR(CCEStudentAssignments.DateSubmitted)=" . $dueDateYear . " "
                                            . "ORDER BY CCEStudentAssignments.CCEStudentAssigID DESC";

                                        // if ($rowStudents["CCEStudentID"] == 382 && $row["CCEAssignmentID"] == 723) {
                                        //     echo $sql . '<br />';
                                        // }

                                        $recAssig = mysqli_query($conn, $sql);
                                        $cellclass2 = " notsubmitted";
                                        $cellvalue = "N";
                                        $tooltip = "";
                                        if ($rowAssig = mysqli_fetch_assoc($recAssig)) {

                                            $cellvalue = "&nbsp;";
                                            $iStatus = $rowAssig["Passed"];

                                            // Check if assignment has been marked (Score can be 0, so check for null/empty string, not just !empty)
                                            $isMarked = CCEStudentAssignment::isSummarySubmissionMarked($rowAssig);

                                            /* True when feedback has been released to student; drives green (not released) vs blue (released) for score block. */
                                            $feedbackReleased = !empty($rowAssig["FeedbackReleased"]);

                                            // Display score only if assignment has been marked; do not show 0 for submitted-but-not-marked
                                            $displayScore = CCEStudentAssignment::resolveSummaryDisplayScore($rowAssig);
                                            if ($displayScore !== null) {
                                                $cellvalue = $displayScore;
                                            }

                                            //                                            if ($rowAssig["RulingCode"] == '') {
                                            //                                                $rowAssig["RulingCode"] = $rowAssig["MarkedRuling"];
                                            //
                                            //                                                if ($rowAssig["MarkedRuling"] == 'R') {
                                            //                                                    $iStatus = 2;
                                            //                                                } elseif (in_array($rowAssig["MarkedRuling"], array('A', 'AC', 'E'))) {
                                            //                                                    $iStatus = 1;
                                            //                                                }
                                            //                                            }
                                            //                                            if ($iStatus == 0)
                                            //                                                $cellvalue = "Y";
                                            //                                            if ($iStatus == 1)
                                            //                                                $cellvalue = "Y";
                                            //                                            if ($iStatus == 2)
                                            //                                                $cellvalue = "N";

                                            if ((mysqli_num_rows($recAssig) > 1) && ($iStatus == 0)) {
                                                // More than one submission - Look at the first one
                                                $latestAssigRow = $rowAssig;
                                                $currentScore = $rowAssig["Score"];
                                                $currentFeedbackScore = $rowAssig["AssignmentScore"];
                                                if ($rowAssig = mysqli_fetch_assoc($recAssig)) {

                                                    //                                                    if ($rowAssig["RulingCode"] == '') {
                                                    //                                                        $rowAssig["RulingCode"] = $rowAssig["MarkedRuling"];
                                                    //                                                    }

                                                    if (($rowAssig["RulingCode"] == "NE") || ($rowAssig["RulingCode"] == "U") || ($rowAssig["RulingCode"] == "R")) {
                                                        $cellclass2 = " resubmitted";
                                                        if ($rowAssig["RulingCode"] == "NE")
                                                            $cellvalue = "E";
                                                        if (($rowAssig["RulingCode"] == "U") || ($rowAssig["RulingCode"] == "R")) {
                                                            $cellvalue = "R";
                                                        }

                                                        // Prefer score of the marked (latest) resubmission when available
                                                        $latestMarkedRow = array(
                                                            'MarkedRuling' => isset($latestAssigRow['MarkedRuling']) ? $latestAssigRow['MarkedRuling'] : null,
                                                            'Score' => $currentScore,
                                                            'AssignmentScore' => $currentFeedbackScore,
                                                        );
                                                        $resubScore = CCEStudentAssignment::resolveSummaryDisplayScore($latestMarkedRow);
                                                        if ($resubScore !== null) {
                                                            $cellvalue = $resubScore;
                                                        } elseif ($isMarked) {
                                                            if ($currentFeedbackScore !== null && $currentFeedbackScore !== '' && is_numeric($currentFeedbackScore)) {
                                                                $cellvalue = $currentFeedbackScore;
                                                            } elseif ($currentScore !== null && $currentScore !== '' && is_numeric($currentScore)) {
                                                                $cellvalue = $currentScore;
                                                            }
                                                        }
                                                    } else {
                                                        // Check if this submission has been marked before defaulting to notevaluated
                                                        $isCurrentMarked = (isset($rowAssig["MarkedRuling"]) && $rowAssig["MarkedRuling"] !== null && $rowAssig["MarkedRuling"] !== '') 
                                                                         || (isset($rowAssig["Score"]) && $rowAssig["Score"] !== null && $rowAssig["Score"] !== '' && is_numeric($rowAssig["Score"]));
                                                        if ($isCurrentMarked) {
                                                            /* Green = marked but feedback not yet released; blue = feedback released; red = marked for resubmission. */
                                                            $scoreBlockClass = $feedbackReleased ? " achieved" : " markedpendingfeedback";
                                                            if ($rowAssig["Passed"] == 1) {
                                                                $cellclass2 = $scoreBlockClass;
                                                            } elseif ($rowAssig["Passed"] == 2) {
                                                                $cellclass2 = " notachieved";
                                                            } else {
                                                                $cellclass2 = $scoreBlockClass;
                                                            }
                                                        } else {
                                                            $cellclass2 = " notevaluated";
                                                        }
                                                    }

                                                    //                                                    if ($rowStudents["CCEStudentID"] == 314 && $row["CCEAssignmentID"] == 581) {
                                                    //                                                        echo $cellvalue . ' with score ' . $currentScore . ' assignment feedback score: ' . $currentFeedbackScore . '<br />';
                                                    //                                                    }
                                                    //                                                    $cellvalue .= ' - ' . $sql . ' - ' . $iStatus;
                                                    //                                                    $cellvalue .= ' - ' . $currentScore . ' - ' . $currentFeedbackScore . ' - ' . $rowAssig["Score"] . ' - ' . $rowAssig["AssignmentScore"] . ' - ' . $rowAssig["RulingCode"] . ' - ' . $iStatus;
                                                }

                                                //                                                if ($rowStudents["CCEStudentID"] == 314 && $row["CCEAssignmentID"] == 581) {
                                                //                                                    echo $cellvalue . ' after assignment count<br />';
                                                //                                                }
                                                //                                            $cellvalue .= ' - ' . $sql . ' - ' . $iStatus;
                                                //                                            $cellvalue .= ' - ' . $rowAssig["Score"] . ' - ' . $rowAssig["AssignmentScore"] . ' - ' . $iStatus;
                                            } else {
                                                // Check if assignment has been marked before defaulting to notevaluated
                                                /* Green = marked, feedback not released; blue = feedback released; red (iStatus==2) = marked for resubmission. */
                                                $scoreBlockClass = $feedbackReleased ? " achieved" : " markedpendingfeedback";
                                                if ($iStatus == 0) {
                                                    // Only show as notevaluated if it hasn't been marked yet
                                                    if ($isMarked) {
                                                        $cellclass2 = $scoreBlockClass;
                                                    } else {
                                                        $cellclass2 = " notevaluated";
                                                    }
                                                } elseif ($iStatus == 1) {
                                                    $cellclass2 = $scoreBlockClass;
                                                    // Needs enhancement? Same green/blue rule: blue (white text) if released, green if not.
                                                    if ($rowAssig["RulingCode"] == "NE") {
                                                        $cellvalue .= "E";
                                                        $cellclass2 = $feedbackReleased ? " achieved whitetext" : " markedpendingfeedback";
                                                    }
                                                } elseif ($iStatus == 2) {
                                                    /* Red: marked for resubmission. Show marked score when available; otherwise R. */
                                                    $cellclass2 = " notachieved";
                                                    $resubScore = CCEStudentAssignment::resolveSummaryDisplayScore($rowAssig);
                                                    $cellvalue = ($resubScore !== null) ? $resubScore : "R";
                                                }
                                            }
                                            //                                            if ($rowStudents["CCEStudentID"] == 314 && $row["CCEAssignmentID"] == 581) {
                                            //                                                echo $cellvalue . '<br />';
                                            //                                            }
                                            //                                            $cellvalue .= ' - ' . $sql . ' - ' . $iStatus;
                                            //                                            $cellvalue .= ' - ' . $rowAssig["Score"] . ' - ' . $rowAssig["AssignmentScore"] . ' - ' . $iStatus;
                                        } else {
                                            // No submission: ensure not-submitted is always shown as pink
                                            $cellclass2 = " notsubmitted";
                                            $cellvalue = "N";
                                            $tooltip = '';

                                            // Pending extension request (not yet approved or denied): show ! so convenors see where extensions need processing
                                            $hasPendingRequest = false;
                                            $sqlPending = "SELECT 1 FROM CCEStAssigExtensionRequests caer "
                                                . "WHERE caer.CCEStudentID='" . mysqli_real_escape_string($conn, $rowStudents["CCEStudentID"]) . "' AND caer.CCEAssignmentID=" . intval($row["CCEAssignmentID"])
                                                . " AND (caer.Status IS NULL OR caer.Status = '' OR caer.Status NOT IN ('A','P','D')) LIMIT 1";
                                            $recPending = mysqli_query($conn, $sqlPending);
                                            if ($recPending && mysqli_num_rows($recPending) > 0) {
                                                $cellvalue .= "!";
                                                $tooltip .= 'Extension request pending (not yet approved or denied). ';
                                                $hasPendingRequest = true;
                                            }
                                            if ($recPending) {
                                                mysqli_free_result($recPending);
                                            }

                                            $sql = "SELECT * FROM CCEStAssigExtensions cae "
                                                . "INNER JOIN CCEStAssigExtensionRequests caer ON cae.CCEStudentID = caer.CCEStudentID AND cae.CCEAssignmentID = caer.CCEAssignmentID "
                                                . "WHERE cae.CCEStudentID='" . $rowStudents["CCEStudentID"] . "' AND cae.CCEAssignmentID=" . $row["CCEAssignmentID"];
                                            $recAssig = mysqli_query($conn, $sql);
                                            if ($recAssig && mysqli_num_rows($recAssig) > 0) {
                                                $tooltip .= 'Click for more: ';
                                        ?>
                                                <div id="dialogExtensionDate_<?php echo $rowStudents["CCEStudentID"]; ?>_<?php echo $row["CCEAssignmentID"]; ?>" style="display: none;" title="Contact form" class="linkExtensionDateDialog">

                                                    <?php
                                                    while ($rowAssig = mysqli_fetch_assoc($recAssig)) {
                                                    ?>
                                                        <div class="well">
                                                            Extension date: <?php echo $rowAssig["CCEExtensionDate"] ?><br />
                                                            <?php
                                                            if (strlen($rowAssig["SupportingDoc"]) > 0) {
                                                            ?>
                                                                <a href="/cceadmin/assignmentsupload/<?php echo $rowAssig["SupportingDoc"]; ?>" target="_blank">Supporting Document</a><br />
                                                            <?php
                                                            }

                                                            if (strlen($rowAssig["Motivation"]) > 0) {
                                                            ?>
                                                                <p>
                                                                    <?php echo nl2br($rowAssig["Motivation"]) ?>
                                                                </p>
                                                            <?php
                                                            }

                                                            $tooltip .= CCEStAssigExtensionRequest::getStatusString($rowAssig["Status"]) . ' ';
                                                            ?>
                                                            <p>
                                                                <b>Status:</b> <?php echo CCEStAssigExtensionRequest::getStatusString($rowAssig["Status"]); ?>
                                                            </p>
                                                        </div>
                                                    <?php
                                                        //if ($rowAssig["CCEExtensionDate"] >= date("Y-m-d"))
                                                        $cellvalue .= "*";
                                                        $tooltip .= "Extension date: " . $rowAssig["CCEExtensionDate"] . '; ';
                                                    } //while
                                                    ?>
                                                </div>
                                    <?php
                                            } elseif ($hasPendingRequest) {
                                                // Unprocessed extension request: show dialog so convenors can see details (opens in same popup as approved extensions)
                                                $sqlPendingDetails = "SELECT * FROM CCEStAssigExtensionRequests caer "
                                                    . "WHERE caer.CCEStudentID='" . mysqli_real_escape_string($conn, $rowStudents["CCEStudentID"]) . "' AND caer.CCEAssignmentID=" . intval($row["CCEAssignmentID"])
                                                    . " AND (caer.Status IS NULL OR caer.Status = '' OR caer.Status NOT IN ('A','P','D')) ORDER BY caer.DateRequested DESC";
                                                $recPendingDetails = mysqli_query($conn, $sqlPendingDetails);
                                                if ($recPendingDetails && mysqli_num_rows($recPendingDetails) > 0) {
                                                    $tooltip .= 'Click for more: ';
                                        ?>
                                                <div id="dialogExtensionDate_<?php echo $rowStudents["CCEStudentID"]; ?>_<?php echo $row["CCEAssignmentID"]; ?>" style="display: none;" title="Extension request (pending)" class="linkExtensionDateDialog">
                                                    <?php
                                                    while ($rowPending = mysqli_fetch_assoc($recPendingDetails)) {
                                                    ?>
                                                        <div class="well">
                                                            Requested extension date: <?php echo htmlspecialchars($rowPending["CCEExtensionDate"] ?? ''); ?><br />
                                                            <?php if (!empty($rowPending["DateRequested"])) { ?>Date requested: <?php echo htmlspecialchars($rowPending["DateRequested"]); ?><br /><?php } ?>
                                                            <?php
                                                            if (!empty($rowPending["SupportingDoc"])) {
                                                            ?>
                                                                <a href="/cceadmin/assignmentsupload/<?php echo htmlspecialchars($rowPending["SupportingDoc"]); ?>" target="_blank">Supporting Document</a><br />
                                                            <?php
                                                            }
                                                            if (!empty($rowPending["Motivation"])) {
                                                            ?>
                                                                <p><?php echo nl2br(htmlspecialchars($rowPending["Motivation"])); ?></p>
                                                            <?php
                                                            }
                                                            ?>
                                                            <p><b>Status:</b> <?php echo CCEStAssigExtensionRequest::getStatusString($rowPending["Status"]); ?></p>
                                                        </div>
                                                    <?php
                                                    }
                                                    ?>
                                                </div>
                                    <?php
                                                    mysqli_free_result($recPendingDetails);
                                                }
                                            }
                                        }
                                        mysqli_free_result($recAssig);
                                    } else {
                                        $cellclass2 = "";
                                        $cellvalue = "&nbsp;";
                                    }
                                    ?>
                                    <td class="cell<?php echo $cellclass2; ?> assig-col-assignment mod-cell-<?php echo $row['CCEModuleID']; ?>" style="border-top:none;border-left:none;">
                                        <a href="#" class="linkExtensionDate" data-student-id="<?php echo $rowStudents["CCEStudentID"]; ?>" data-assignment-id="<?php echo $row["CCEAssignmentID"]; ?>" title="<?php echo $tooltip; ?>"><?php
                                                                                                                                                                                                                                        echo $cellvalue;

                                                                                                                                                                                                                                        //                                        if ($rowStudents["CCEStudentID"] == 314 && $row["CCEAssignmentID"] == 581) {
                                                                                                                                                                                                                                        //                                            echo ' ' . $currentScore;
                                                                                                                                                                                                                                        //                                            exit;
                                                                                                                                                                                                                                        //                                        }
                                                                                                                                                                                                                                        ?></a>
                                    </td>
                                <?php
                                    $prevMod = $row['CCEModuleID'];
                                } //while assignments
                                // Activities
                                /*
                              foreach ($arrModules as $ModID) {
                              $NumWB=0;
                              $sql="SELECT * FROM CCEStudentActivities WHERE CCEStudentID='".$rowStudents["CCEStudentID"]."' AND CCEModuleID=".$ModID." ORDER BY ActivityRef";
                              $recAssig=mysqli_query($conn, $sql);
                              while ($rowAssig=mysqli_fetch_assoc($recAssig)) {
                              $NumWB++;
                              }
                             */
                                ?>
                                <!--    <td class="cell<?php echo $cellclass2; ?>" width="41" style="border-top:none;border-left:none;width:25pt;"><?php if (!empty($NumWB)) echo $NumWB . " WB"; ?></td> -->
                                <?php
                                //		}
                                ?>
                <td class="assig-col-filler" aria-hidden="true">&nbsp;</td>
            </tr>
        <?php
        } // foreach students
        $cellclass = " darkcell";
        ?>
        <tr>
            <td class="cell<?php echo $cellclass; ?> sticky-col sticky-col-name" width="160" style="border-top:none;" nowrap>Class Average</td>
            <td class="cell<?php echo $cellclass; ?> sticky-col sticky-col-avg" width="40" style="border-top:none;border-left:none; text-align: right;" nowrap><?php
                echo GetClassAssigAverage();
            ?></td>
            <?php
            $prevMod = '';
            foreach ($assignmentRows as $row) {
                if ($prevMod != $row['CCEModuleID']) {
                    $groupStartClass = ' mod-group-start';
            ?>
                    <td class="cell assig-col-module-avg mod-cell-<?php echo $row['CCEModuleID']; ?><?php echo $groupStartClass; ?>" style="border-top:none;">
                        <?php echo GetAverageAssigScore(0, true, $row["CCEModuleID"]); ?>
                    </td>
                <?php
                }
                ?>
                <td class="cell darkcell assig-col-assignment mod-cell-<?php echo $row['CCEModuleID']; ?>" style="border-top:none;border-left:none;">
                    <?php echo GetClassAssigAverage($row["CCEAssignmentID"]); ?>
                </td>
            <?php
                $prevMod = $row['CCEModuleID'];
            }
            ?>
            <td class="assig-col-filler" aria-hidden="true">&nbsp;</td>
        </tr>
    </table>
    </div>
</div>
<br>
<?php
// Legend: explains cell colours/classes used in the assignment summary grid above.
// Left column = submission/score states; right column = resubmissions and extensions.
?>
<table cellspacing="0" cellpadding="0">
    <tr>
        <td colspan="3" style="padding-bottom: 14px;">
            <strong>Module summary column</strong> (first column in each module group):<br />
            <strong>A</strong> — Assignment average for that module (0-10 scale).
        </td>
    </tr>
    <tr>
        <td>
            <table cellspacing="0" cellpadding="0">
                <!-- .notevaluated (green): submitted, no mark/score yet; student has not received a result -->
                <tr>
                    <td width="63" class="notevaluated">&nbsp;</td>
                    <td width="300">Submitted / Not Yet Evaluated (No Score)</td>
                </tr>
                <!-- .markedpendingfeedback (green): marked and score shown; feedback not yet released to student (convenor sees score only) -->
                <tr>
                    <td width="63" class="markedpendingfeedback" align="center">8</td>
                    <td width="300">Marked / Feedback not yet released (With Score)</td>
                </tr>
                <!-- .achieved (blue): marked and feedback released; score is the final achieved score visible to student -->
                <tr>
                    <td width="63" class="achieved">&nbsp;</td>
                    <td width="300">Feedback Released</td>
                </tr>
                <!-- .notsubmitted (pink): no submission recorded for this assignment -->
                <tr>
                    <td width="63" class="notsubmitted">&nbsp;</td>
                    <td width="300">Not yet Submitted</td>
                </tr>
                <!-- .notachieved (red): marked for resubmission; shows score when marked, otherwise R -->
                <tr>
                    <td width="63" class="notachieved" align="center">R / 6</td>
                    <td width="300">Marked for resubmission (score shown when available)</td>
                </tr>
            </table>
        </td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
        <td>
            <table cellspacing="0" cellpadding="0">
                <!-- .resubmitted (yellow): resubmission received; shows marked resubmission score when available, else R or E -->
                <tr>
                    <td width="63" align="center" class="resubmitted">R / 7</td>
                    <td width="300">Resubmission received (score of marked resubmission when available)</td>
                </tr>
                <!-- .notsubmitted (pink) with asterisk: extension granted; hover for extension date -->
                <tr>
                    <td width="63" align="center" class="notsubmitted">N*</td>
                    <td width="300">Extension granted (hover mouse over cell to see date)</td>
                </tr>
                <!-- .notsubmitted (pink) with exclamation: extension requested but not yet approved or denied -->
                <tr>
                    <td width="63" align="center" class="notsubmitted">N!</td>
                    <td width="300">Extension requested, pending (needs processing)</td>
                </tr>
                <tr>
                    <td colspan="2">Click on the student's name to access extensions</td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<script language="Javascript">
    function assigSummaryRecalcTableWidth() {
        var width = 200;
        $('.assig-summary-table col').each(function() {
            var $col = $(this);
            if ($col.hasClass('assig-col-filler')) {
                return;
            }
            if ($col.hasClass('mod-cell-filter-hidden')) {
                return;
            }
            if ($col.hasClass('sticky-col-name') || $col.hasClass('sticky-col-avg')) {
                return;
            }
            if ($col.hasClass('assig-col-module-avg')) {
                width += 48;
            } else if ($col.hasClass('assig-col-assignment')) {
                width += 76;
            }
        });
        $('#assig-summary-wrapper').css('--assig-table-min-width', width + 'px');
    }

    function showHideModules() {

        var hideModules = new Array();
        var showModules = new Array();

        $('.module-filter').each(function() {
            if ($('#check-all').is(':checked') || $(this).is(':checked')) {
                showModules[showModules.length] = $(this).val();
            } else {
                hideModules[hideModules.length] = $(this).val();
            }
        });

        for (mCnt = 0; mCnt < hideModules.length; mCnt++) {
            $('.mod-cell-' + hideModules[mCnt]).addClass('mod-cell-filter-hidden');
        }

        for (mCnt = 0; mCnt < showModules.length; mCnt++) {
            $('.mod-cell-' + showModules[mCnt]).removeClass('mod-cell-filter-hidden');
        }

        assigSummaryRecalcTableWidth();
    }

    $(document).ready(function() {
        $('.module-filter').change(showHideModules);
        assigSummaryRecalcTableWidth();

        $(".linkExtensionDateDialog").dialog({
            autoOpen: false,
            minWidth: 420,
            minHeight: 350
        });

        $('.linkExtensionDate').click(function() {

            var studentId = $(this).attr('data-student-id');
            var assignmentId = $(this).attr('data-assignment-id');
            $('#dialogExtensionDate_' + studentId + '_' + assignmentId).dialog('open');
            return false;
        });
    });
</script>
<?php
include_once('footer.php');