Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/cceconvenors/
Upload File :
Current File : /var/www/cesa.co.za/cceconvenors/markassignments.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

include_once('header.php');
?>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.5/css/buttons.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/rowgroup/1.1.2/css/rowGroup.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.0.2/css/dataTables.dateTime.min.css">
<link rel="stylesheet" type="text/css" href="/cceconvenors/js/editor/css/editor.dataTables.css">
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/rowgroup/1.1.2/js/dataTables.rowGroup.min.js"></script>

<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.0/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/keytable/2.5.3/js/dataTables.keyTable.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/datetime/1.0.2/js/dataTables.dateTime.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.0/js/buttons.html5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js" type="text/javascript"></script>

<script type="text/javascript" src="/cceconvenors/js/editor/js/dataTables.editor.js?v=2.0.0"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-migrate-3.0.0.min.js"></script>
<script type="text/javascript" src="/js/jquery.autogrow.js"></script>

<h1>Assignment Marking</h1>
<?php
$conni = mysqli_connect(EW_CONN_HOST, EW_CONN_USER, EW_CONN_PASS, EW_CONN_DB);

$sql = "SELECT CCEAssignments.* FROM CCEAssignments WHERE CCEAssignmentID=" . intval($_REQUEST["id"]);

$rec = mysqli_query($conni, $sql);
if ($row = mysqli_fetch_assoc($rec)) {
    extract($row);
    $arrQ = explode(",", $QuestionNumbers);
}
/*
  $sql="SELECT QuestionNum FROM CCEAssignmentQuestions WHERE CCEAssignmentID=".intval($_REQUEST["id"])." AND QuestionType='A' ORDER BY QuestionNum";
  $rec2=mysqli_query($conni, $sql);
  if (mysqli_num_rows($rec2)>0) {
  $arrQ=array();
  while ($row2=mysqli_fetch_assoc($rec2)) {
  $arrQ[]="Q".$row2["QuestionNum"];
  }
  }
 */

$assigMarkingObj = new CCEAssignmentMarking($sqlf);

if (isset($_POST["sendFeedbackExamplesButton"]) && strlen($_POST["sendFeedbackExamplesButton"]) > 0) {

    $assigMarkingObj->sendFeeback($_POST, $_REQUEST, $env);
} elseif (isset($_POST["send"]) && ($_POST["send"] == 1)) {

    $phpScript = "\$assigMarkingObj = new CCEAssignmentMarking(\$sqlf); "
        . "\$postData = json_decode('" . json_encode($_POST) . "', true); "
        . "\$requestData = json_decode('" . json_encode($_REQUEST) . "', true); "
        . "\$iNumFeedbackSent = \$assigMarkingObj->sendFeeback(\$postData, \$requestData, '" . $env . "');";

    BatchJob::saveJob($phpScript);
?>
    <div style="border:1px solid green; padding:10px"><b>Feedback messages have been queued for sending. You will receive a notification when all feedback messages have been sent.</b></div>
<?php
}

if (intval($_REQUEST["id"]) <= 0) {
    die('Invalid assignment');
}

// Submissions already marked
$sql = 'INSERT INTO CCEAssignmentMarking (CCEStudentAssigID, Score, Ruling, GeneralComments)
SELECT CCEStudentAssigID, AssignmentScore, RulingCode, Remarks
FROM CCEStudentAssignments
WHERE NOT EXISTS (SELECT * FROM CCEAssignmentMarking WHERE CCEAssignmentMarking.`CCEStudentAssigID`=CCEStudentAssignments.`CCEStudentAssigID`)
AND CCEStudentAssignments.CCEAssignmentID=' . intval($_REQUEST["id"]) . ' AND Passed>0';
//echo $sql."<br><br>";
mysqli_query($conni, $sql);

// First submissions
$sql = 'INSERT INTO CCEAssignmentMarking (CCEStudentAssigID, SubOnTime, DaysLate)
SELECT CCEStudentAssigID, IF(DateSubmitted>DATE_ADD(DueDate, INTERVAL 2 DAY),"N","Y"), IF(DateSubmitted>DueDate,DATEDIFF(DateSubmitted, DueDate)-2,0)
FROM CCEStudentAssignments JOIN CCEAssignments USING (CCEAssignmentID)
WHERE NOT EXISTS (SELECT * FROM CCEAssignmentMarking WHERE CCEAssignmentMarking.`CCEStudentAssigID`=CCEStudentAssignments.`CCEStudentAssigID`)
AND NOT EXISTS (SELECT * FROM CCEStudentAssignments SA2 WHERE SA2.`CCEStudentAssigID`<CCEStudentAssignments.`CCEStudentAssigID`
AND SA2.CCEAssignmentID=' . intval($_REQUEST["id"]) . ' AND SA2.CCEStudentiD=CCEStudentAssignments.CCEStudentID)
AND CCEStudentAssignments.CCEAssignmentID=' . intval($_REQUEST["id"]) . ' AND Passed=0';
//echo $sql."<br><br>";
mysqli_query($conni, $sql);

// Resubs etc
$sql = 'INSERT INTO CCEAssignmentMarking (CCEStudentAssigID, SubOnTime, DaysLate)
SELECT SA2.CCEStudentAssigID, IF(SA2.DateSubmitted>DATE_ADD(CCEMessages.SentDateTime, INTERVAL 15 DAY),"N","Y"), IF(SA1.DateSubmitted>DueDate,DATEDIFF(SA1.DateSubmitted, CCEAssignments.DueDate)-2,0)
FROM CCEStudentAssignments SA2 JOIN CCEStudentAssignments SA1 USING (CCEStudentID, CCEAssignmentID)
JOIN CCEAssignmentFeedback ON (SA1.CCEStudentAssigID=CCEAssignmentFeedback.CCEStudentAssigID)
JOIN CCEMessages USING (CCEMessageID)
JOIN CCEAssignments USING (CCEAssignmentID)
WHERE NOT EXISTS (SELECT * FROM CCEAssignmentMarking WHERE CCEAssignmentMarking.`CCEStudentAssigID`=SA2.`CCEStudentAssigID`)
AND SA2.CCEStudentAssigID>SA1.CCEStudentAssigID
AND SA2.CCEAssignmentID=' . intval($_REQUEST["id"]) . ' AND SA2.Passed=0';
//echo $sql."<br><br>";
mysqli_query($conni, $sql);
?>
<p>
    This assignment has <b><?php echo count($arrQ); ?></b> questions.
    <a href="assigsetquestions.php?id=<?php echo intval($_REQUEST["id"]); ?>">Click here to adjust this.</a>
</p>
<?php
if (CCEConvenorAuth::isAssignmentFeedbackAdmin()) {
?>
    <p style="float:right">
    <form method="post" action="markassignments.php">
        <input type="hidden" name="id" value="<?php echo intval($_REQUEST["id"]); ?>">
        <input type="hidden" id="resend_feedback_id" name="resend_feedback_id" value="" />
        <input type="hidden" id="resend_student_assignment_id" name="resend_student_assignment_id" value="" />
        <input type="checkbox" name="send" value="1"> Tick here to confirm that feedback must be sent
        <input type="checkbox" name="resubmit_date_override" value="1"> Override resubmit date to two weeks after today
        <input type="submit" id="sendFeedbackButton" name="sendFeedbackButton" value="Send Feedback Now">
        <input type="submit" id="sendFeedbackExamplesButton" name="sendFeedbackExamplesButton" value="Send Feedback Examples Now">
    </form>
    </p>
<?php
}
?>
<h2><?php
    echo $RefNum . ": " . $AssignmentName;

    if ($Archived > 0) {
        echo ' !!! ARCHIVED !!!';
    }
    ?></h2>
<h3>Due Date: <?php echo $DueDate; ?></h3>
<h4>Resub Due: <?php echo GetResubDate($row["CCEAssignmentID"]); ?></h4>
<p><b>Result Summary:</b>
    <?php
    $sql = "SELECT CCEAssignmentMarking.Ruling, COUNT(*) AS Num
FROM CCEStudents JOIN CCEStudentAssignments USING (CCEStudentID)
JOIN CCEAssignmentMarking USING (CCEStudentAssigID)
JOIN CCEAssignments ON CCEStudentAssignments.CCEAssignmentID = CCEAssignments.CCEAssignmentID
WHERE CCEStudentAssignments.CCEAssignmentID=" . intval($_REQUEST["id"]) . "
AND CCEStudents.ModulesEnrolled LIKE '%" . $CCEModuleID . "%'
AND CCEStudents.Archived=0
AND YEAR(CCEStudentAssignments.DateSubmitted)=" . date("Y") . "
AND CCEStudents.CCEStudentID <> 54 "
        . CCEStudents::sqlClassAverageExclusionClause('CCEStudents', 'CCEAssignments.CCEModuleID') . "
GROUP BY CCEAssignmentMarking.Ruling ORDER BY CCEAssignmentMarking.Ruling";
    
    $recSummary = mysqli_query($conni, $sql);

    // echo $sql . '<br />';

    while ($rowSummary = mysqli_fetch_assoc($recSummary)) {
        echo (empty($rowSummary["Ruling"]) ? "Not marked" : $rowSummary["Ruling"]) . ":&nbsp;" . $rowSummary["Num"] . "&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    
    mysqli_free_result($recSummary);
    ?>

<table width="100%" class="dataTable display cell-border compact hover order-column row-border stripe" id="dataTables-assig">
    <thead>
        <tr id="headerfirstrow" style="display:none">
            <th colspan=10><b><?php echo $RefNum . ": " . $AssignmentName; ?>, Due Date: <?php echo $DueDate; ?></b></th>
        </tr>
        <tr>
            <th></th>
            <th>Student</th>
            <th><span class="vertical-heading-up">Score</span></th>
            <th>Marked By</th>
            <th>Extension</th>
            <th><span class="vertical-heading-up">Sub On Time?</span></th>
            <th><span class="vertical-heading-up">Activity Complete?</span></th>
            <th><span class="vertical-heading-up">References?</span></th>
            <th><span class="vertical-heading-up">Ruling</span></th>
            <th>Feedback</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<script language="javascript">
    var editor; // use a global for the submit and return data rendering in the examples
    var cceConvenorCanEditSentFeedback = <?php echo CCEConvenorAuth::isAssignmentFeedbackAdmin() ? 'true' : 'false'; ?>;

    function cceMarkingRowExcluded(data) {
        return !!(data && (data.ModuleExcluded === true || data.ModuleExcluded === 1 || data.ModuleExcluded === '1'));
    }
    var markingBubbleRow = null;

    function registerMarkingEditorFile(fileId, url) {
        if (!fileId || !url || !$.fn.dataTable.Editor) {
            return;
        }
        if (!$.fn.dataTable.Editor.files) {
            $.fn.dataTable.Editor.files = {};
        }
        if (!$.fn.dataTable.Editor.files.files) {
            $.fn.dataTable.Editor.files.files = {};
        }
        $.fn.dataTable.Editor.files.files[fileId] = {
            filename: fileId,
            web_path: url
        };
    }

    function markingFileUploadDisplay(fileId) {
        if (!fileId) {
            return "";
        }
        var row = markingBubbleRow || markingEditorRowData();
        var url = row && row.FileUploadUrl;
        if (!url) {
            try {
                url = editor.file('files', fileId).web_path;
            } catch (e) {
                // File not registered in Editor cache yet.
            }
        }
        if (url) {
            return markingDownloadLink(fileId, url, 'marking-file-download-link');
        }
        return fileId;
    }

    function refreshMarkingFileUploadField() {
        if (!editor || !editor.field('FileUpload')) {
            return;
        }
        var row = markingBubbleRow || markingEditorRowData();
        if (row && row.FileUpload && row.FileUploadUrl) {
            registerMarkingEditorFile(row.FileUpload, row.FileUploadUrl);
        }
        var fileId = editor.field('FileUpload').val();
        if (fileId) {
            editor.field('FileUpload').set(fileId);
        }
    }

    function centreMarkingBubble() {
        $('div.DTE_Bubble.marking-feedback-modal').css({
            top: '5vh',
            bottom: 'auto',
            height: '90vh',
            maxHeight: '90vh',
            left: '50%',
            right: 'auto',
            transform: 'translateX(-50%)'
        }).find('div.DTE_Bubble_Liner').css('left', '0');
        $(window).off('resize.marking-feedback-bubble').on('resize.marking-feedback-bubble', centreMarkingBubble);
    }

    function markingDownloadLink(label, url, linkClass) {
        if (!url) {
            return label;
        }
        var classAttr = linkClass ? " class='" + linkClass + "'" : "";
        return "<a href='" + url + "' target='_blank' rel='noopener'" + classAttr + ">" + label + "</a>";
    }

    function markingEditorRowData() {
        if (markingBubbleRow) {
            return markingBubbleRow;
        }
        if (typeof table === 'undefined' || !table || !editor) {
            return null;
        }
        var modifier = editor.modifier();
        if (modifier) {
            var row = table.row(modifier);
            if (row.any()) {
                return row.data();
            }
        }
        var selected = table.rows({
            selected: true
        });
        if (selected.any()) {
            return selected.data()[0];
        }
        return null;
    }

    $(document).ready(function() {


        $('#sendFeedbackButton').click(function() {
            var resendFeedbackIds = [];
            var resendStudentAssignmentIds = [];
            $('.resend_feedback').each(function() {
                if ($(this).is(':checked')) {
                    resendFeedbackIds[resendFeedbackIds.length] = $(this).val();
                    resendStudentAssignmentIds[resendStudentAssignmentIds.length] = $(this).data('student-assignment-id');
                }
                $('#resend_feedback_id').val(resendFeedbackIds.join(','));
                $('#resend_student_assignment_id').val(resendStudentAssignmentIds.join(','));
            });
        });
        editor = new $.fn.dataTable.Editor({
            ajax: "/cceconvenors/ajax/markassignments.php?id=<?php echo intval($_REQUEST["id"]); ?>",
            table: "#dataTables-assig",
            idSrc: 'rowkey',
            fields: [{
                    label: "Student:",
                    name: "Student",
                    type: "readonly"
                }, {
                    name: "FeedbackSent",
                    type: "hidden"
                },
                {
                    label: "Date Submtted:",
                    name: "DateSubmitted",
                    type: "readonly"
                }, {
                    label: "Extension Date Requested",
                    name: "CCEExtensionDate",
                    type: "text",
                    className: "bubble-full-width-field",
                    attr: {
                        placeholder: "YYYY-MM-DD"
                    }
                }, {
                    label: "Extension Approved",
                    name: "Status",
                    type: "radio",
                    className: "bubble-full-width-field",
                    def: "",
                    options: [{
                            label: "Approved",
                            value: "A"
                        },
                        {
                            label: "Approved with Penalty",
                            value: "P"
                        },
                        {
                            label: "Declined",
                            value: "D"
                        },
                        {
                            label: "No Status",
                            value: ""
                        }
                    ]
                }, {
                    label: "Convenor Comment",
                    name: "StatusReason",
                    type: "textarea",
                    className: "bubble-full-width-field",
                    attr: {
                        rows: 8
                    }
                }, {
                    label: "Extension Motivation",
                    name: "Motivation",
                    type: "readonly",
                    className: "bubble-full-width-field"
                }, {
                    label: "Submitted On Time?",
                    name: "SubOnTime",
                    type: "radio",
                    options: [{
                            label: "Yes",
                            value: "Y"
                        },
                        {
                            label: "No",
                            value: "N"
                        }
                    ]
                }, {
                    label: "References Listed?",
                    name: "References",
                    type: "radio",
                    options: [{
                            label: "Yes",
                            value: "Y"
                        },
                        {
                            label: "No",
                            value: "N"
                        },
                        {
                            label: "N/A",
                            value: "N/A"
                        }
                    ]
                }, {
                    label: "Ruling",
                    name: "Ruling",
                    className: "smallerEdit",
                    type: "radio",
                    options: [{
                            label: "E",
                            value: "E"
                        },
                        {
                            label: "AE",
                            value: "AE"
                        },
                        {
                            label: "A",
                            value: "A"
                        },
                        {
                            label: "AL",
                            value: "AL"
                        },
                        {
                            label: "AC",
                            value: "AC"
                        },
                        {
                            label: "R",
                            value: "R"
                        }
                    ]

                    <?php
                    $iQ = 0;
                    foreach ($arrQ as $val) {
                        $iQ++;
                    ?>
                }, {
                    label: "<?php echo $val; ?>:",
                    name: "Comment<?php echo $iQ; ?>",
                    type: "textarea",
                    className: "bubble-comment-field",
                    attr: {
                        rows: 8
                    }
                <?php
                    }
                ?>
                }, {
                    label: "Activity Complete?",
                    name: "ActivityCompl",
                    type: "radio",
                    def: "",
                    options: [{
                            label: "Yes",
                            value: "Y"
                        },
                        {
                            label: "No",
                            value: "N"
                        },
                        {
                            label: "N/A",
                            value: ""
                        }
                    ]
                }, {
                    label: "General Comments:",
                    name: "GeneralComments",
                    type: "textarea",
                    className: "bubble-full-width-field",
                    attr: {
                        rows: 8
                    }
                }, {
                    label: "File Upload:",
                    name: "FileUpload",
                    type: "upload",
                    className: "bubble-full-width-field",
                    display: function(file_id) {
                        return markingFileUploadDisplay(file_id);
                    },
                    clearText: "Clear"
                }
            ],
            formOptions: {
                inline: {
                    onBlur: 'submit'
                },
                bubble: {
                    windowPadding: 20,
                    positionTop: '50%',
                    positionLeft: '50%'
                }
            }
        });
        editor
            .on('postEdit', function() {
                editor.off('preClose');
                table.row({
                    selected: true
                }).deselect();
            })
            .on('postRemove', function() {
                table.ajax.reload();
            })
            .on('opened', function(e, mode) {
                if (mode !== 'bubble') {
                    return;
                }
                var $bubble = $('div.DTE_Bubble').addClass('marking-feedback-modal');
                $bubble.find('div.DTE_Bubble_Liner').css('left', '0');
                centreMarkingBubble();
                window.requestAnimationFrame(function() {
                    centreMarkingBubble();
                    refreshMarkingFileUploadField();
                });
            })
            .on('closed', function(e, mode) {
                if (mode === 'bubble') {
                    $('div.DTE_Bubble').removeClass('marking-feedback-modal');
                    $(window).off('resize.marking-feedback-bubble');
                    markingBubbleRow = null;
                }
            })
            .on('open', function() {
                // $('#DTE_Field_GeneralComments').autogrow();
                // Store the values of the fields on open
                openVals = JSON.stringify(editor.get());
                editor.on('preClose', function(e) {
                    // On close, check if the values have changed and ask for closing confirmation if they have
                    if (openVals !== JSON.stringify(editor.get())) {
                        return confirm('You have unsaved changes. Are you sure you want to close the edit window?');
                    }
                });
            })
            .on('postCreate close', function() {
                editor.off('preClose');
            });
        editor.on('preOpen', function(e, mode, action) {
            var excludedCheckRow = markingEditorRowData();
            if (!excludedCheckRow && mode === 'bubble' && typeof table !== 'undefined' && table) {
                var excludedModifier = editor.modifier();
                if (excludedModifier) {
                    var excludedBubbleRow = table.row(excludedModifier);
                    if (excludedBubbleRow.any()) {
                        excludedCheckRow = excludedBubbleRow.data();
                    }
                }
            }
            if (cceMarkingRowExcluded(excludedCheckRow)) {
                return false;
            }
            if (mode === 'bubble' && !markingBubbleRow && typeof table !== 'undefined' && table) {
                var modifier = editor.modifier();
                if (modifier) {
                    var bubbleRow = table.row(modifier);
                    if (bubbleRow.any()) {
                        markingBubbleRow = bubbleRow.data();
                    }
                }
            }
            var rowData = editor.get();
            if (rowData['FeedbackSent'] != '' && !cceConvenorCanEditSentFeedback) {
                return false;
            }
            var selectedRow = markingEditorRowData();
            if (selectedRow) {
                if (selectedRow.FileUpload && selectedRow.FileUploadUrl) {
                    registerMarkingEditorFile(selectedRow.FileUpload, selectedRow.FileUploadUrl);
                }
                if (selectedRow.SupportingDoc) {
                    var supportingDocUrl = selectedRow.SupportingDocUrl;
                    if (!supportingDocUrl && selectedRow.extensions && selectedRow.extensions.length) {
                        for (var i = 0; i < selectedRow.extensions.length; i++) {
                            if (selectedRow.extensions[i].SupportingDoc === selectedRow.SupportingDoc) {
                                supportingDocUrl = selectedRow.extensions[i].SupportingDocUrl;
                                break;
                            }
                        }
                    }
                    if (supportingDocUrl) {
                        registerMarkingEditorFile(selectedRow.SupportingDoc, supportingDocUrl);
                    }
                }
            }
        });
        var table = $('#dataTables-assig').DataTable({
            ajax: "/cceconvenors/ajax/markassignments.php?id=<?php echo intval($_REQUEST["id"]); ?>",
            dom: "Blfrtip",
            bSort: true,
            autoWidth: false,
            "lengthMenu": [
                [-1, 10, 25, 50],
                ["All", 10, 25, 50]
            ],
            "paging": false,
            columns: [{
                    data: null,
                    defaultContent: '',
                    className: 'select-checkbox',
                    orderable: false
                },
                {
                    data: null,
                    render: function(data, type, row) {
                        if (cceMarkingRowExcluded(data)) {
                            return data.Student + "<br /><span style='font-size:10px; font-weight:bold; color:darkgray'>Excluded from module</span>";
                        }
                        dt = '';
                        if (data.FeedbackSent != '') {
                            dt = data.Student + "<br /><span style='font-size:10px; font-weight:bold'>Feedback sent on " + data.FeedbackSent + "</span>";
                        } else {
                            if ((data.Score != '')) {
                                dt = data.Student + "<br /><span style='font-size:10px; font-weight:bold; color:green'>Feedback can be sent</span>";
                            } else {
                                if (data.CCEStudentAssigID == '') {
                                    dt = data.Student + "<br /><span style='font-size:10px; font-weight:bold; color:darkgray'>No submission received</span>";
                                } else {
                                    dt = data.Student + "<br /><span style='font-size:10px; font-weight:bold; color:red'>Marking not complete</span>";
                                }
                            }
                        }
                        if (data.AssignmentFile1 != '') dt = dt + '<br />' + markingDownloadLink('File 1', data.AssignmentFile1Url);
                        if (data.AssignmentFile2 != '') dt = dt + '<br />' + markingDownloadLink('File 2', data.AssignmentFile2Url);
                        if (data.AssignmentFile3 != '') dt = dt + '<br />' + markingDownloadLink('File 3', data.AssignmentFile3Url);
                        if (data.AssignmentFile4 != '') dt = dt + '<br />' + markingDownloadLink('File 4', data.AssignmentFile4Url);
                        if (data.AssignmentFile5 != '') dt = dt + '<br />' + markingDownloadLink('File 5', data.AssignmentFile5Url);
                        return dt;
                    }
                },
                {
                    data: null,
                    render: function(data, type, row) {
                        if (cceMarkingRowExcluded(data)) {
                            return "-";
                        }
                        return data.Score ? data.Score : "";
                    }
                },
                {
                    data: null,
                    render: function(data, type, row) {
                        if (cceMarkingRowExcluded(data)) {
                            return "-";
                        }
                        var markedBy = data.MarkedBy ? data.MarkedBy : "";
                        var markedDate = data.DateMarked ? data.DateMarked : "";
                        var out = "";

                        if (markedBy !== "") {
                            out += "<span style='font-size:10px'>" + markedBy + "</span>";
                        }

                        if (markedDate !== "") {
                            out += (out !== "" ? "<br />" : "") + "<span style='font-size:10px'>" + markedDate + "</span>";
                        }

                        if (data.DateSubmitted) {
                            out += (out !== "" ? "<br />" : "") + "<span style='font-size:10px'>Submitted: " + data.DateSubmitted + "</span>";
                        }

                        return out;
                    }
                },
                {
                    data: null,
                    render: function(data, type, row) {
                        if (cceMarkingRowExcluded(data)) {
                            return "-";
                        }
                        dt = '';
                        //                    console.log(data.extensions);
                        if (data.extensions.length > 0) {
                            showLink = false;
                            for (var eCnt = 0; eCnt < data.extensions.length; eCnt++) {
                                if (data.extensions[eCnt].Status == 'None') {
                                    continue;
                                }

                                if (eCnt > 0) {
                                    continue;
                                }

                                if (data.extensions[eCnt].CCEExtensionDate != '') {
                                    showLink = true;
                                    dt += '<div class="well"><span style="font-size:10px">' +
                                        'Extension requested to:<br>' + data.extensions[eCnt].CCEExtensionDate;
                                    if (data.extensions[eCnt].Motivation != '') dt = dt + '<br/><i>Motivation provided, click to read</i><hr>';
                                    if (data.extensions[eCnt].DateRequested != '') dt = dt + '<br/>Requested on:<br>' + data.extensions[eCnt].DateRequested + '<hr>';
                                    if (data.extensions[eCnt].SupportingDoc != '') dt = dt + '<br/>Motivation File: ' + markingDownloadLink(data.extensions[eCnt].SupportingDoc, data.extensions[eCnt].SupportingDocUrl) + '<hr>';
                                    if (data.extensions[eCnt].Status != '') {
                                        dt = dt + '<br />';
                                        if (data.extensions[eCnt].Status == 'A' || data.extensions[eCnt].Status == 'P') {
                                            if (data.extensions[eCnt].Status == 'A') {
                                                dt = dt + "<b>Status:</b> <i>Approved</i>";
                                            } else {
                                                dt = dt + "<b>Status:</b> <i>Approved with Penalty</i>";
                                            }
                                            dt = dt + '<br/><b>Updated on:</b> ' + data.extensions[eCnt].DateUpdated;
                                            dt = dt + '<br/><b>Updated by:</b> ' + data.extensions[eCnt].UpdatedBy;
                                            dt = dt + '<hr />';
                                        }
                                        if (data.extensions[eCnt].Status == 'D') dt = dt + "<b>Status:</b> <i>Declined</i>";
                                    } //if status != ''
                                } // extension date not set
                                dt = dt + '</span></div>';
                            } //for each extension
                            if (showLink) {
                                dt = dt + '<a href="/cceconvenors/CCEStAssigExtensionRequestslist.php?CCEStudentID=' + data.CCEStudentID + '&CCEAssignmentID=<?php echo intval($_REQUEST["id"]); ?>">View all ' + data.extensions.length + ' Extension Requests</a>';
                            }
                            return '' + dt + '';
                        } //has extensions
                    },
                    editField: ['CCEExtensionDate', 'Status', 'StatusReason', 'Motivation', 'SupportingDoc']
                },
                {
                    data: "SubOnTime",
                    render: function(data, type, row) {
                        return cceMarkingRowExcluded(row) ? "-" : (data ? data : "");
                    }
                },
                {
                    data: "ActivityCompl",
                    render: function(data, type, row) {
                        return cceMarkingRowExcluded(row) ? "-" : (data ? data : "");
                    }
                },
                {
                    data: "References",
                    render: function(data, type, row) {
                        return cceMarkingRowExcluded(row) ? "-" : (data ? data : "");
                    }
                },
                {
                    data: "Ruling",
                    render: function(data, type, row) {
                        return cceMarkingRowExcluded(row) ? "-" : (data ? data : "");
                    }
                },
                {
                    data: null,
                    render: function(data, type, row) {
                        if (cceMarkingRowExcluded(data)) {
                            return "-";
                        }
                        //                    console.log(data);
                        var dt = '';
                        <?php
                        $iQ = 0;
                        foreach ($arrQ as $val) {
                            $iQ++;
                        ?>
                            if ('Comment<?php echo $iQ; ?>' in data) {
                                dt = dt + "<?php echo $val; ?>: " + data.Comment<?php echo $iQ; ?>.replace(/\n/g, "<br />") + "<br />";
                            } else if ('COMMENT<?php echo $iQ; ?>' in data) {
                                dt = dt + "<?php echo $val; ?>: " + data.COMMENT<?php echo $iQ; ?>.replace(/\n/g, "<br />") + "<br />";
                            } else {
                                //                        console.log(data);
                            }
                        <?php
                        } //foreach
                        ?>
                        //                  if (data.ActivityCompl=="Y") dt=dt+"Class Activity: Complete.<br />";
                        //                  if (data.ActivityCompl=="N") dt=dt+"Class Activity: Not complete.<br />";
                        dt = dt + data.GeneralComments.replace(/\n/g, "<br />");
                        file_id = data.FileUpload;
                        if (file_id) {
                            dt = dt + "<br /><i>File attachment uploaded</i>";
                        }
                        return "<span style='font-size:10px'>" + dt + "</span>" +
                            '<p align="center">Resend Feedback <input type="checkbox" id="student_id" name="student_id[]" class="resend_feedback" value="' + data.CCEStudentID + '" data-student-assignment-id="' + data.CCEStudentAssigID + '" /></p>';
                    },
                    editField: [<?php
                                for ($i = 1; $i <= count($arrQ); $i++) {
                                    echo "'Comment" . $i . "', ";
                                }
                                ?> 'GeneralComments', 'FileUpload']
                }

            ],
            order: [1, 'asc'],
            columnDefs: [{
                    targets: 0,
                    width: "20px",
                    orderable: false,
                    createdCell: function(td, cellData, rowData, row, col) {
                        if (cceMarkingRowExcluded(rowData) || (rowData.FeedbackSent != '' && !cceConvenorCanEditSentFeedback)) {
                            $(td).removeClass('select-checkbox');
                        }
                    }
                },
                {
                    targets: [1],
                    width: "120px"
                },
                {
                    targets: [2],
                    width: "40px",
                    className: 'dt-center'
                },
                {
                    targets: [3],
                    width: "120px"
                },
                {
                    targets: [4],
                    width: "10%",
                    className: 'editable',
                    createdCell: function(td, cellData, rowData, row, col) {
                        if (cceMarkingRowExcluded(rowData) || (rowData.FeedbackSent != '' && !cceConvenorCanEditSentFeedback)) {
                            $(td).removeClass('editable');
                        }
                    }
                },
                {
                    targets: [5, 6, 7, 8],
                    width: "32px",
                    className: 'dt-center editable',
                    createdCell: function(td, cellData, rowData, row, col) {
                        if (cceMarkingRowExcluded(rowData) || (rowData.FeedbackSent != '' && !cceConvenorCanEditSentFeedback)) {
                            $(td).removeClass('editable');
                        }
                    }
                },
                {
                    targets: [9],
                    className: 'editable',
                    createdCell: function(td, cellData, rowData, row, col) {
                        if (cceMarkingRowExcluded(rowData) || (rowData.FeedbackSent != '' && !cceConvenorCanEditSentFeedback)) {
                            $(td).removeClass('editable');
                        }
                    }
                }
            ],
            keys: {
                columns: '.editable',
                keys: [9],
                editor: editor,
                editOnFocus: false
            },
            select: {
                style: 'os',
                selector: 'td:first-child'
            },
            buttons: [{
                    extend: "edit",
                    editor: editor
                },
                {
                    extend: "remove",
                    editor: editor,
                    text: 'Delete Marking and Comments'
                }
            ]
        });
        $('#dataTables-assig').on('click', 'tbody td.editable', function(e) {
            if ((e.currentTarget.cellIndex == 9) || (e.currentTarget.cellIndex == 4)) {
                markingBubbleRow = table.row(this).data();
                editor.bubble(this, {
                    title: markingBubbleRow.Student
                });
            } else {
                markingBubbleRow = null;
                editor.inline(this);
            }
        });
    });
    // Keep the initial column width calculation stable.
    // Showing the hidden colspan header row on scroll triggers a layout recalculation.
    $(window).scroll(function() {
        // Intentionally left blank.
    });

    // Keep convenors PHP session alive while this long-running screen stays open.
    function cceMarkingSessionKeepAlive() {
        jQuery.getJSON('/cceconvenors/ajax/session-keep-alive.php', function() {});
    }
    setInterval(cceMarkingSessionKeepAlive, 100000);
    cceMarkingSessionKeepAlive();
</script>
<?php
include_once('footer.php');