| Current Path : /var/www/cesa.co.za/cesanet/ |
| Current File : /var/www/cesa.co.za/cesanet/assignmentadd.php |
<?php
include("inc_functions.php");
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
if (!isset($_SESSION["StudentID"]) || empty($_SESSION["StudentID"]) || $_SESSION["StudentID"] == null)
header("Location: /cesanet/login.php");
$assignmentExtensionRequestObj = new CCEStAssigExtensionRequest($sqlf);
$studentAssignmentObj = new CCEStudentAssignment($sqlf);
$assignmentObj = new CCEAssignment($sqlf);
$assignmentMarkingObj = new CCEAssignmentMarking($sqlf);
$cceUploadedFileService = new CceUploadedFileService();
// Handle file delete and redirect before any output (redirect requires no prior output).
if (!isset($_POST['go'])
&& isset($_GET['id']) && isset($_GET['delete_file']) && isset($_GET['CCEStudentAssigID'])
&& in_array((string)$_GET['delete_file'], ['1', '2', '3', '4', '5'], true)
&& intval($_GET['id']) > 0 && intval($_GET['CCEStudentAssigID']) > 0
&& CurrentStudent()
) {
$fileNum = (int)$_GET['delete_file'];
// Delegate business rules and delete behaviour to the service class.
$deleted = $studentAssignmentObj->deleteUploadedFileIfAllowed(
intval($_SESSION['StudentID']),
intval($_GET['id']),
intval($_GET['CCEStudentAssigID']),
$fileNum
);
$redirectUrl = 'assignmentadd.php?id=' . urlencode($_GET['id']) . '&CCEStudentAssigID=' . intval($_GET['CCEStudentAssigID']);
if (isset($_GET['debug']) && $_GET['debug'] == '1') {
$redirectUrl .= '&debug=1';
// Optional: indicate delete result in debug mode via query string flag.
$redirectUrl .= '&deleted=' . ($deleted ? '1' : '0');
}
header('Location: ' . $redirectUrl);
exit;
}
include_once($_SERVER['DOCUMENT_ROOT'] . "/cesanet/includes/html_begin.php");
?>
<h1> Upload Assignment</h1>
<?php
if (!CurrentStudent()) {
echo "<p><b>Only available to current students.</b></p>";
die();
}
if (!isset($_POST['go']) && intval($_REQUEST['id']) <= 0) {
echo "<p><b>Please select an assignment.</b></p>";
} elseif (isset($_POST["go"])) {
if (!isset($_SESSION["StudentID"]) || empty($_SESSION["StudentID"])) {
echo "<p><b>ERROR: Your session has timed out. Please <a href='login.php'>login</a> and submit your assignment again.</b></p>";
} elseif (isset($_REQUEST["go"]) && ($_REQUEST["go"] == 1)) {
// Submit
$sql = "SELECT * "
. "FROM CCEAssignments "
. "LEFT OUTER JOIN CCEStudentAssignments ON ("
. "CCEAssignments.CCEAssignmentID=CCEStudentAssignments.CCEAssignmentID "
. "AND CCEStudentAssignments.CCEStudentID=" . $_SESSION["StudentID"] . " "
. "AND (YEAR(CCEStudentAssignments.DateSubmitted)=" . date("Y") . " "
. "OR CCEStudentAssignments.DateSubmitted IS NULL) ) "
. "WHERE CCEAssignments.CCEAssignmentID=" . intval($_REQUEST["assignmentid"]) . " "
. "ORDER BY CCEStudentAssignments.DateSubmitted DESC";
// echo 'Please ignore debug information: ' . $sql . '<br />';
// exit;
$rec = mysql_query($sql);
$resubmit = false;
$assignmentCodeName = '';
if ($row = mysql_fetch_assoc($rec)) {
if ($row['CCEStudentAssigID'] <= 0) {
$studentAssigment = $studentAssignmentObj->findOrCreateByStudentAssignment(
$_SESSION['StudentID'],
$row['CCEAssignmentID'],
$row['CCEStudentAssigID']
);
$row['CCEStudentAssigID'] = $studentAssigment['CCEStudentAssigID'];
}
$dueDate = $studentAssignmentObj->getDueDate(
$row['CCEAssignmentID'],
$_SESSION['StudentID'],
$row['CCEStudentAssigID'],
true
);
} else {
ErrorLog::logError('Student assignment find failed: ' . $sql);
echo 'Unable to find the assignment for this student. This error has been reported.';
exit;
}
$assignmentCodeName = $row['CCEAssignmentID'] . ': ' . $row['RefNum'] . ' - ' . $row['AssignmentName'];
// var_dump($row);
// echo '<br />';
if ($row = mysql_fetch_assoc($rec) && $row['RulingCode'] == 'R') {
$resubmit = true;
}
if (($row = mysql_fetch_assoc($rec)) && ($row["RulingCode"] != "R") && ($dueDate->getTimestamp() <= time())) {
echo "<p><b>The due date for this assignment was " . $dueDate->format('j F Y H:i') . ", you cannot change your submission.</b></p>";
} else {
$assignmentId = intval($_REQUEST["assignmentid"]);
$studentId = intval($_SESSION["StudentID"]);
$sql = "SELECT * "
. "FROM CCEStudentAssignments "
. "WHERE CCEStudentAssignments.CCEStudentID=" . $_SESSION["StudentID"] . " "
. "AND CCEStudentAssignments.CCEAssignmentID = " . intval($_REQUEST["assignmentid"]) . " "
. "ORDER BY CCEStudentAssignments.DateSubmitted DESC";
// echo $sql;
// exit;
$rec = mysql_query($sql);
if ($row = mysql_fetch_assoc($rec)) {
$uploadfilename1 = $row["AssignmentFile1"];
$uploadfilename2 = $row["AssignmentFile2"];
$uploadfilename3 = $row["AssignmentFile3"];
$uploadfilename4 = $row["AssignmentFile4"];
$uploadfilename5 = $row["AssignmentFile5"];
$uploadfile1 = $row["AssignmentFile1"];
$uploadfile2 = $row["AssignmentFile2"];
$uploadfile3 = $row["AssignmentFile3"];
$uploadfile4 = $row["AssignmentFile4"];
$uploadfile5 = $row["AssignmentFile5"];
} else {
$uploadfile1 = "";
$uploadfile2 = "";
$uploadfile3 = "";
$uploadfile4 = "";
$uploadfile5 = "";
}
// var_dump($row);
// exit;
for ($uploadSlot = 1; $uploadSlot <= 5; $uploadSlot++) {
$uploadResult = $cceUploadedFileService->storeStudentAssignmentUpload(
'file' . $uploadSlot,
$assignmentId,
$studentId,
$uploadSlot
);
if (is_array($uploadResult) && !empty($uploadResult['filename'])) {
${'uploadfilename' . $uploadSlot} = $uploadResult['filename'];
${'uploadfile' . $uploadSlot} = $uploadResult['filename'];
}
}
// $sql = "DELETE FROM CCEStudentAssignments WHERE CCEStudentID=" . $_SESSION["StudentID"] . "
// AND CCEAssignmentID=" . intval($_REQUEST["assignmentid"]) . " AND Passed=0 AND RulingCode IS NULL
// AND YEAR(CCEStudentAssignments.DateSubmitted)=" . date("Y");
// mysql_query($sql);
// $sql = "INSERT INTO CCEStudentAssignments (CCEStudentID, CCEAssignmentID, AssignmentFile1, AssignmentFile2, AssignmentFile3, AssignmentFile4,
// AssignmentFile5, `References`, Comments, DateSubmitted)
// VALUES ('" . $_SESSION["StudentID"] . "', '" . $_REQUEST["assignmentid"] . "',
// '" . str_replace('../cceadmin/assignmentsupload/', '', $uploadfile1) . "',
// '" . str_replace('../cceadmin/assignmentsupload/', '', $uploadfile2) . "',
// '" . str_replace('../cceadmin/assignmentsupload/', '', $uploadfile3) . "',
// '" . str_replace('../cceadmin/assignmentsupload/', '', $uploadfile4) . "',
// '" . str_replace('../cceadmin/assignmentsupload/', '', $uploadfile5) . "',
// '" . addslashes(stripslashes($_REQUEST["references"])) . "', '" . addslashes(stripslashes($_REQUEST["comments"])) . "',
// '" . date("Y-m-d H:i:s") . "')";
// echo $sql;
// exit;
// mysql_query($sql);
$studentAssigment = $studentAssignmentObj->findOrCreateByStudentAssignment(
$_SESSION["StudentID"],
$_REQUEST["assignmentid"],
$row['CCEStudentAssigID']
);
$studentAssigment['AssignmentFile1'] = $uploadfile1;
$studentAssigment['AssignmentFile2'] = $uploadfile2;
$studentAssigment['AssignmentFile3'] = $uploadfile3;
$studentAssigment['AssignmentFile4'] = $uploadfile4;
$studentAssigment['AssignmentFile5'] = $uploadfile5;
$studentAssigment['DateSubmitted'] = date("Y-m-d H:i:s");
// $studentAssigment['References'] = addslashes(stripslashes($_REQUEST["references"]));
$studentAssigment['Comments'] = $_REQUEST["comments"];
unset($studentAssigment['References']);
$studentAssignmentObj->save($studentAssigment);
// var_dump($studentAssigment);
// exit;
$sql = "SELECT CCEStudentAssigID FROM CCEStudentAssignments
WHERE CCEStudentID=" . intval($_SESSION["StudentID"]) . " AND CCEAssignmentID=" . intval($_REQUEST["assignmentid"]) . "
AND YEAR(CCEStudentAssignments.DateSubmitted)=" . date("Y") . "
ORDER BY CCEStudentAssigID DESC";
$rec = mysql_query($sql);
$row = mysql_fetch_assoc($rec);
$iSAID = $row["CCEStudentAssigID"];
$sql = "UPDATE CCEStudentAssignments SET `References` = '" . addslashes(stripslashes($_REQUEST["references"])) . "' "
. "WHERE CCEStudentAssigID = " . $studentAssigment['CCEStudentAssigID'];
mysql_query($sql);
/*
** Logic to calculate days late
$bResub = false;
if (mysql_num_rows($rec) > 1)
$bResub = true;
$iDaysLate = 0;
$resubSQL = 'Not a resubmission';
$resubRow = array();
$sql = "SELECT MAX(CCEStAssigExtensionRequests.CCEExtensionDate) AS CCEExtensionDate, CCEAssignments.DueDate, CCEStudentAssignments.DateSubmitted
FROM CCEStudentAssignments JOIN CCEAssignments USING (CCEAssignmentID)
LEFT JOIN CCEStAssigExtensionRequests ON (CCEStAssigExtensionRequests.CCEStudentID=CCEStudentAssignments.CCEStudentID
AND CCEStAssigExtensionRequests.CCEAssignmentID=CCEStudentAssignments.CCEAssignmentID AND CCEStAssigExtensionRequests.Status IN ('A', 'P'))
WHERE CCEStudentAssignments.CCEStudentAssigID=" . $iSAID . "
GROUP BY CCEAssignments.DueDate, CCEStudentAssignments.DateSubmitted";
//echo $sql;
$rec = mysql_query($sql);
if ($row = mysql_fetch_assoc($rec)) {
$sDueDate = (empty($row["CCEExtensionDate"]) ? $row["DueDate"] : $row["CCEExtensionDate"]);
if ($bResub) {
$sql = "SELECT MIN(CCEMessages.SentDateTime) AS FeedbackSent FROM
CCEStudentAssignments SA1 JOIN CCEAssignmentFeedback ON (SA1.CCEStudentAssigID=CCEAssignmentFeedback.CCEStudentAssigID)
JOIN CCEMessages USING (CCEMessageID)
WHERE SA1.CCEAssignmentID=" . intval($_REQUEST["assignmentid"]) . "
AND YEAR(SA1.DateSubmitted)=" . date("Y") . "
AND SA1.Passed>0";
$resubSQL = $sql;
$recR = mysql_query($sql);
if ($rowR = mysql_fetch_assoc($recR)) {
$resubRow = $rowR;
if (!empty($rowR["FeedbackSent"])) {
$sDueDate = date("Y-m-d", strtotime("+15 days", strtotime($rowR["FeedbackSent"])));
} else {
$sDueDate = date("Y-m-d", strtotime("+14 days", strtotime($row["DueDate"])));
}
} else {
$sDueDate = date("Y-m-d", strtotime("+14 days", strtotime($row["DueDate"])));
}
}
//echo $sDueDate;
} else {
$sDueDate = date("Y-m-d");
}
*/
$resubSQL = 'Resub SQL no longer needed';
$resubRow = [];
$dateSubmitted = new DateTime();
// $dateSubmitted = new DateTime($row["DateSubmitted"]);
// $dueDate = new DateTime($sDueDate);
// $dueDate->setTime(23, 59, 59);
// No more 1 day grace period
// $iDaysLate = floor(($dateSubmitted->getTimestamp() - $dueDate->getTimestamp()) / (24 * 60 * 60)) - 1;
//Subtract half mark for each late day
// Marks are subtracting upon marking
$iDaysLate = 0;
if (!is_object($dueDate)) {
$dueDate = new DateTime();
}
if ($dateSubmitted->getTimestamp() > $dueDate->getTimestamp()) {
$iDaysLate = ceil(($dateSubmitted->getTimestamp() - $dueDate->getTimestamp()) / (24 * 60 * 60));
}
ErrorLog::logInfo('Assignment ' . $assignmentCodeName . ' submitted ' . $dateSubmitted->format('Y-m-d H:i:s') . ' was due '
. $dueDate->format('Y-m-d H:i:s') . ' - ' . $_SESSION["StudentID"] . ' - Days late: ' . $iDaysLate . ' - ' . ($iDaysLate > 0 ? "N" : "Y")
. ' - ' . $resubSQL
. ' - ' . print_r($resubRow, true));
if ($iDaysLate < 0)
$iDaysLate = 0;
// $sql = "INSERT INTO CCEAssignmentMarking (CCEStudentAssigID, SubOnTime, DaysLate) "
// . "VALUES (" . $iSAID . ", '" . ($iDaysLate > 0 ? "N" : "Y") . "', " . $iDaysLate . ")";
//echo $sql;
// mysql_query($sql);
$assignmentMarkingObj->findOrCreateByStudentAssignment($iSAID, ($iDaysLate > 0 ? "N" : "Y"), $iDaysLate);
$sql = "UPDATE CCEStudentAssigAnswers SET CCEStudentAssigID=" . $iSAID . " WHERE CCEStudentID=" . intval($_SESSION["StudentID"])
. " AND CCEAssignmentID=" . intval($_REQUEST["assignmentid"]);
mysql_query($sql);
$sql = "SELECT CCEStudents.EmailAddress, CCEStudents.FirstName, CCEStudents.Surname, CCEStudents.KnownAs,
CCEFacilitators2.EmailAddress AS MentorEmail,
CCEFacilitators.EmailAddress AS FacilitatorEmail, CCEAssignments.RefNum, CCEAssignments.AssignmentName
FROM CCEStudents JOIN CCEStudentAssignments ON (CCEStudents.CCEStudentID=CCEStudentAssignments.CCEStudentID)
JOIN CCEAssignments ON (CCEStudentAssignments.CCEAssignmentID=CCEAssignments.CCEAssignmentID)
JOIN CCEModuleSchedules ON (CCEAssignments.CCEModuleID=CCEModuleSchedules.CCEModuleID)
LEFT JOIN CCEFacilitators ON (CCEModuleSchedules.FacilitatorID=CCEFacilitators.FacilitatorID)
LEFT JOIN CCEFacilitators CCEFacilitators2 ON (CCEStudents.CCEFacilitatorID=CCEFacilitators2.FacilitatorID)
WHERE CCEStudents.CCEStudentID=" . $_SESSION["StudentID"] . "
AND YEAR(CCEStudentAssignments.DateSubmitted)=" . date("Y") . "
AND CCEAssignments.Archived=0
AND CCEAssignments.CCEAssignmentID=" . $_REQUEST["assignmentid"];
$rec = mysql_query($sql);
if ($row = mysql_fetch_assoc($rec)) {
$msg = "Dear " . $row["KnownAs"] . " " . $row["Surname"] . "\r\n\r\n";
if ($resubmit) {
$subjectText = "BCE Assignment Resubmitted: " . $row["RefNum"] . " - " . $row["AssignmentName"];
$msg .= "Thank you for resubmitting the assignment " . $row["RefNum"] . " - " . $row["AssignmentName"] . " on the CESAnet.";
} else {
$subjectText = "BCE Assignment Submitted";
$msg .= "Thank you for submitting the assignment " . $row["RefNum"] . " - " . $row["AssignmentName"] . " on the CESAnet.";
}
$msg .= "\r\n\r\n" . 'Please ensure that you have submitted the correct assignment and in pdf format by checking your uploaded assignment on the CESAnet.';
$sBCCHeaders = "";
$bcc = array();
$sendToEmail = $row["EmailAddress"];
$isCesaTestStudent = isTestStudent($_SESSION["StudentID"]);
if (!$isCesaTestStudent && !empty($row["FacilitatorEmail"])) {
$sBCCHeaders = "\r\n" . "BCC: " . $row["FacilitatorEmail"];
$bcc[] = $row["FacilitatorEmail"];
}
if (!empty($row["MentorEmail"])) {
$sBCCHeaders .= "\r\n" . "BCC: " . $row["MentorEmail"];
$bcc[] = $row["MentorEmail"];
}
// Prevent notifying real recipients from DEV.
if (strpos($_SERVER['HTTP_HOST'], 'dev') > 0) {
$sendToEmail = 'cesa-bce@igotafrica.com';
$bcc = array();
}
maill($sendToEmail, $subjectText, $msg, null, array('from-name' => 'CESA BCE', 'from-address' => 'brenda@cesa.co.za', 'bcc' => $bcc));
$sql = "INSERT INTO CCEMessages (CCEModuleID, SentByName, SentTo, SentDateTime, MessageSubject, MessageText) "
. "VALUES (0, 'System', '" . addslashes($row["FirstName"] . " " . $row["Surname"]) . "', '" . date("Y-m-d H:i:s")
. "', 'CESAnet Assignment Submitted', '" . addslashes(stripslashes($msg)) . "')";
mysqli_query($conni, $sql);
$sql = "INSERT INTO CCEMessagesSentTo (CCEMessageID, SentType, SentID) "
. "VALUES (" . mysqli_insert_id($conni) . ", 'Student', '" . $_SESSION["StudentID"] . "')";
mysqli_query($conni, $sql);
ErrorLog::logInfo('Assignment ' . $assignmentCodeName . ' submitted ' . date('Y-m-d H:i:s') . ' mail sent: ' . $row["EmailAddress"]);
}
?>
<?php if ((int) $_SESSION["StudentID"] === 54) { ?>
<p><b>Thank you for submitting your assignment.</b></p>
<?php } else { ?>
<p><b>Thank you for submitting your assignment, the module convenor has been notified.</b></p>
<?php } ?>
<div id="v3FeedbackStatus" class="alert alert-info mt-3" role="alert">Loading feedback form…</div>
<div class="modal fade" id="v3FeedbackModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="v3FeedbackModalTitle">Feedback form</h5>
</div>
<div class="modal-body">
<p><strong>Please complete the feedback form to complete your assignment submission.</strong></p>
<div id="v3FeedbackModalFormContainer"></div>
<div id="v3FeedbackModalMessage" class="mt-3"></div>
</div>
</div>
</div>
</div>
<script>
(function() {
var assignmentId = <?php echo intval($_REQUEST["assignmentid"]); ?>;
var statusEl = document.getElementById('v3FeedbackStatus');
var modalEl = document.getElementById('v3FeedbackModal');
var titleEl = document.getElementById('v3FeedbackModalTitle');
var formContainerEl = document.getElementById('v3FeedbackModalFormContainer');
var messageEl = document.getElementById('v3FeedbackModalMessage');
function setStatus(message, type) {
if (!statusEl) {
return;
}
statusEl.className = 'alert mt-3 alert-' + (type || 'info');
statusEl.textContent = message;
}
function modalInstance() {
if (!window.bootstrap || !modalEl) {
return null;
}
return window.bootstrap.Modal.getOrCreateInstance(modalEl, {
backdrop: 'static',
keyboard: false
});
}
function bindSubmit(formId) {
var formEl = formContainerEl ? formContainerEl.querySelector('form') : null;
if (!formEl) {
setStatus('Unable to find feedback form fields.', 'danger');
return;
}
formEl.addEventListener('submit', function(e) {
e.preventDefault();
var submitBtn = formEl.querySelector('button[type="submit"], input[type="submit"]');
if (submitBtn) {
submitBtn.disabled = true;
}
if (messageEl) {
messageEl.innerHTML = '<div class="alert alert-info">Submitting feedback form…</div>';
}
var payload = new FormData(formEl);
payload.append('form_id', formId);
fetch('v3_feedback_submit.php', {
method: 'POST',
body: payload,
credentials: 'same-origin'
}).then(function(response) {
return response.json();
}).then(function(data) {
if (!data || !data.success) {
throw new Error((data && data.error) ? data.error : 'Feedback form submission failed.');
}
if (messageEl) {
messageEl.innerHTML = '<div class="alert alert-success">Feedback form submitted successfully.</div>';
}
setStatus('Feedback form submitted successfully.', 'success');
var instance = modalInstance();
if (instance) {
setTimeout(function() {
instance.hide();
}, 700);
}
}).catch(function(error) {
if (submitBtn) {
submitBtn.disabled = false;
}
if (messageEl) {
messageEl.innerHTML = '<div class="alert alert-danger">' + error.message + '</div>';
}
});
});
}
fetch('v3_feedback_form.php?assignment_id=' + encodeURIComponent(String(assignmentId)), {
method: 'GET',
credentials: 'same-origin',
headers: {
'Accept': 'application/json'
}
}).then(function(response) {
return response.json();
}).then(function(data) {
if (!data || !data.success) {
throw new Error((data && data.error) ? data.error : 'Unable to load feedback form.');
}
var formName = data.title || 'Feedback form';
titleEl.textContent = 'Feedback form: ' + formName;
formContainerEl.innerHTML = data.html || '<p>No form markup returned.</p>';
bindSubmit(data.form_id);
setStatus('Feedback form loaded.', 'success');
var instance = modalInstance();
if (instance) {
instance.show();
}
}).catch(function(error) {
setStatus('Unable to load feedback form: ' + error.message, 'danger');
});
})();
</script>
<?php
}
}
} else {
if (isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0) {
// Business logic lives in service class: copy v3 form template and rename for this assignment.
$assignmentObj->ensureV3FormCopiedForAssignment(intval($_REQUEST['id']));
}
$dueDate = $studentAssignmentObj->getDueDate(intval($_REQUEST['id']), intval($_SESSION['StudentID']), intval($_REQUEST['CCEStudentAssigID']));
// Add ?debug=1 to the URL to see delete-flow debug output (DEV only; remove for production).
$debugDelete = isset($_REQUEST['debug']) && $_REQUEST['debug'] == '1';
if ($debugDelete) {
echo '<div style="background:#fff3cd;border:1px solid #856404;padding:10px;margin:10px 0;"><strong>DEBUG (form display):</strong> id=' . (isset($_GET['id']) ? htmlspecialchars($_GET['id']) : 'NOT SET')
. ', CCEStudentAssigID=' . (isset($_REQUEST['CCEStudentAssigID']) ? htmlspecialchars($_REQUEST['CCEStudentAssigID']) : 'NOT SET')
. ', delete_file=' . (isset($_REQUEST['delete_file']) ? htmlspecialchars($_REQUEST['delete_file']) : 'NOT SET')
. '</div>';
}
$formAction = 'assignmentadd.php';
if (isset($_GET['id']) && intval($_GET['id']) > 0) {
$formAction .= '?id=' . urlencode($_GET['id']);
} elseif (isset($_GET['modid']) && intval($_GET['modid']) > 0) {
$formAction .= '?modid=' . urlencode($_GET['modid']);
}
?>
<form action="<?php echo htmlspecialchars($formAction); ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="var btn = document.getElementById('button'); if (btn) { btn.disabled = true; btn.value = 'Submitting…'; }">
<input type="hidden" name="go" id="hid_go" value="1" />
<p><b>Please note the following instructions:</b><br />
<ul>
<li>All assignments and class activities must be completed on the assignment sheet (accessible through the link below to the information file).<br />
<br />
</li>
<li>References must be included on the assignment sheet<br /><br /></li>
<li>All assignments must be uploaded in pdf format<br /><br /></li>
<li>Please ensure that you are uploading the correct assignment<br /><br /></li>
<li>Please do not use unusual characters, especially subscripts, superscripts and symbols, when naming your files. File names may contain letters, numbers, spaces, hyphens and underscores, but no other characters are allowed.<br />
<br />
</li>
<li>When including additional files, ensure that you reference these in the assignment sheet<br /><br /></li>
<li>Once you are happy that you have attached all the correct information, click on Submit Assignment<br /><br /></li>
<li>Please ensure you have selected the correct assignment for which you are submitting.<br /><br /></li>
</ul>
</p>
<?php
if (!isset($_GET["id"]) && isset($_GET["modid"])) {
$sql = "SELECT * FROM CCEModules WHERE CCEModuleID=" . $_GET["modid"] . "";
$rec = mysql_query($sql);
if ($row = mysql_fetch_assoc($rec)) {
?>
<h2><?php echo $row["ModuleName"]; ?></h2>
Assignment (please select): <select name="assignmentid">
<?php
$sql = "SELECT * FROM CCEAssignments
WHERE CCEAssignments.CCEModuleID=" . $_GET["modid"] . " AND CCEAssignments.Archived=0 ORDER BY RefNum";
$rec = mysql_query($sql);
while ($row = mysql_fetch_assoc($rec)) {
?>
<option value="<?php echo $row["CCEAssignmentID"]; ?>"><?php echo $row["RefNum"] . ": " . $row["AssignmentName"]; ?></option>
<?php
}
?>
</select>
<?php
}
} else {
$sql = "SELECT * FROM CCEAssignments
WHERE CCEAssignments.CCEAssignmentID=" . $_GET["id"] . " AND CCEAssignments.Archived=0";
$rec = mysql_query($sql);
if ($row = mysql_fetch_assoc($rec)) {
$extensionRequests = $assignmentExtensionRequestObj->findAllByStudentAssignment($_SESSION["StudentID"], $row['CCEAssignmentID']);
?>
<h2><?php echo $row["AssignmentName"]; ?><br />
<?php echo CCEStAssigExtensionRequest::getExtensionDueString($row, $extensionRequests, true); ?></h2>
<p><b>Assignment Information File: <a href="<?php echo "https://www.cesa.co.za/cceadmin/assignments/" . urlencode($row["AssignmentPDF"]); ?>" target="_blank">CLICK HERE TO DOWNLOAD THE INFORMATION FILE</A></b></p>
<input type="hidden" name="assignmentid" value="<?php echo $_GET["id"]; ?>" />
<?php
}
}
$bAlreadySub = false;
$lastRow = array(
'AssignmentFile1' => '',
'AssignmentFile2' => '',
'AssignmentFile3' => '',
'AssignmentFile4' => '',
'AssignmentFile5' => '',
);
if (isset($_GET["id"])) {
$sql = "SELECT * FROM CCEAssignments JOIN CCEStudentAssignments ON (CCEAssignments.CCEAssignmentID=CCEStudentAssignments.CCEAssignmentID AND CCEStudentAssignments.CCEStudentID=" . $_SESSION["StudentID"] . ")
WHERE CCEAssignments.CCEAssignmentID=" . intval($_REQUEST["id"]);
if (intval($_REQUEST["CCEStudentAssigID"]) > 0) {
$sql .= " AND CCEStudentAssignments.CCEStudentAssigID=" . intval($_REQUEST["CCEStudentAssigID"]);
}
$sql .= " AND YEAR(CCEStudentAssignments.DateSubmitted)=" . date("Y") . "
ORDER BY CCEStudentAssignments.DateSubmitted DESC";
$rec = mysql_query($sql);
if ($debugDelete) {
echo '<div style="background:#fff3cd;border:1px solid #856404;padding:10px;margin:10px 0;"><strong>DEBUG (student assignment query):</strong> sql ran, mysql_num_rows=' . (isset($rec) && $rec ? mysql_num_rows($rec) : 'N/A') . '</div>';
}
if ($row = mysql_fetch_assoc($rec)) {
echo "<p><b>You submitted this assignment on " . date("Y-m-d", strtotime($row["DateSubmitted"])) . "</b></p>";
$dueDate = new DateTime($row["DueDate"]);
$dueDate->setTime(23, 59, 59);
// var_dump($row);
// echo '<br />';
if ($row["RulingCode"] != "R" && $dueDate->getTimestamp() <= time()) {
echo "<p><b>The due date for this assignment was " . $dueDate->format('j F Y H:i') . ", you cannot change your submission.</b></p>";
$bAlreadySub = true;
?>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<?php
for ($fCnt = 1; $fCnt <= 5; $fCnt++) {
?>
<tr>
<td width="5%" nowrap>File <?php echo $fCnt ?>:</td>
<td>
<?php
if (isset($row['AssignmentFile' . $fCnt]) && strlen($row['AssignmentFile' . $fCnt]) > 0) {
$fileUrl = $cceUploadedFileService->buildStudentAssignmentFileUrl(
intval($_GET['id']),
intval($_SESSION['StudentID']),
$fCnt,
$row['AssignmentFile' . $fCnt]
);
?>
<a href="<?php echo htmlspecialchars((string) $fileUrl); ?>" target="_blank" rel="noopener"><?php echo htmlspecialchars($row['AssignmentFile' . $fCnt]); ?></a>
<?php
}
?>
</td>
</tr>
<?php
} //for
?>
</table>
<?php
} elseif (empty($row["RulingCode"])) {
echo "<h2 class=\"text-red\" style=\"color: #FF0000;\">Any files you upload now will <i>replace</i> your previous submission.</h2>";
}
$lastRow = $row;
// Allow delete only when submission is still editable (before deadline, or with extension, or resubmit).
// Same rules as for upload/submit - do not change existing allow/disallow logic.
if ($debugDelete) {
echo '<div style="background:#d1ecf1;border:1px solid #0c5460;padding:10px;margin:10px 0;"><strong>DEBUG (before delete check):</strong> bAlreadySub=' . ($bAlreadySub ? 'true' : 'false')
. ', CCEStudentAssigID=' . (isset($lastRow['CCEStudentAssigID']) ? $lastRow['CCEStudentAssigID'] : 'NOT SET')
. ', delete_file=' . (isset($_REQUEST['delete_file']) ? $_REQUEST['delete_file'] : 'NOT SET')
. ', in_array=' . (isset($_REQUEST['delete_file']) && in_array((string)$_REQUEST['delete_file'], ['1', '2', '3', '4', '5'], true) ? 'yes' : 'no')
. '</div>';
}
if (!$bAlreadySub && isset($_REQUEST['delete_file']) && in_array((string)$_REQUEST['delete_file'], ['1', '2', '3', '4', '5'], true)) {
$fileNum = (int)$_REQUEST['delete_file'];
if ($debugDelete) {
echo '<div style="background:#f8d7da;border:1px solid #721c24;padding:10px;margin:10px 0;"><strong>DEBUG (inside delete block):</strong> fileNum=' . $fileNum
. ', AssignmentFile' . $fileNum . '=' . (isset($lastRow['AssignmentFile' . $fileNum]) ? htmlspecialchars($lastRow['AssignmentFile' . $fileNum]) : 'NOT SET')
. ', CCEStudentAssigID=' . (isset($lastRow['CCEStudentAssigID']) ? $lastRow['CCEStudentAssigID'] : 'NOT SET')
. '</div>';
}
if (!empty($lastRow['AssignmentFile' . $fileNum])) {
$clearResult = $studentAssignmentObj->clearAssignmentFile($lastRow['CCEStudentAssigID'], $fileNum);
$redirectUrl = 'assignmentadd.php?id=' . urlencode($_GET['id']);
if (!empty($lastRow['CCEStudentAssigID'])) {
$redirectUrl .= '&CCEStudentAssigID=' . (int)$lastRow['CCEStudentAssigID'];
}
if ($debugDelete) {
$redirectUrl .= '&debug=1';
echo '<div style="background:#d4edda;border:1px solid #155724;padding:10px;margin:10px 0;"><strong>DEBUG (delete done):</strong> clearAssignmentFile returned ' . ($clearResult ? 'true' : 'false')
. '. <a href="' . htmlspecialchars($redirectUrl) . '">Click here to continue (redirect URL)</a></div>';
exit;
}
header('Location: ' . $redirectUrl);
exit;
} elseif ($debugDelete) {
echo '<div style="background:#f8d7da;border:1px solid #721c24;padding:10px;margin:10px 0;"><strong>DEBUG:</strong> Did not redirect - AssignmentFile' . $fileNum . ' is empty</div>';
}
}
} elseif ($debugDelete) {
echo '<div style="background:#fff3cd;border:1px solid #856404;padding:10px;margin:10px 0;"><strong>DEBUG:</strong> No row from student assignment query (mysql_fetch_assoc returned false)</div>';
}
}
if (!$bAlreadySub) {
$sql = "SELECT CCEAssignmentQuestions.*, CCEStudentAssigAnswers.CCEStudentAnswer, CCEStudentAssigAnswers.AssignmentFile1, CCEStudentAssigAnswers.AssignmentFile2, "
. "CCEStudentAssigAnswers.AssignmentFile3, CCEStudentAssigAnswers.AssignmentFile4, CCEStudentAssigAnswers.AssignmentFile5 "
. "FROM CCEAssignmentQuestions "
. "LEFT JOIN CCEStudentAssigAnswers "
. "ON (CCEAssignmentQuestions.CCEAssignmentQID=CCEStudentAssigAnswers.CCEAssignmentQID AND CCEStudentAssigAnswers.CCEStudentID=" . $_SESSION["StudentID"] . ") "
. "WHERE CCEAssignmentQuestions.CCEAssignmentID=" . intval($_GET["id"]) . " "
. "ORDER BY QuestionType DESC, DisplayOrder, QuestionNum";
//echo $sql;
$recQ = mysql_query($sql);
if (mysql_num_rows($recQ) == 0) {
//echo "<p>This assignment does not include any online questions, please upload your completed assignment file below.";
} else {
?>
<p><b>Please answer the following questions:</b></p>
<?php
}
$sLastType = "";
while ($rowQ = mysql_fetch_assoc($recQ)) {
if ($sLastType != $rowQ["QuestionType"]) {
if (!empty($sLastType)) {
?>
<p>
<input type="button" name="button" id="button" value="Save Answers and Return Later" onClick="SaveAnswers()" />
</p>
<?php
}
if ($rowQ["QuestionType"] == "A")
echo "<p><u>Assignment</u></p>";
if ($rowQ["QuestionType"] == "B")
echo "<p><u>Activity</u></p>";
}
$sLastType = $rowQ["QuestionType"];
?>
<table border=0 cellspacing=0 cellpadding=5 width="100%">
<tr>
<td valign="top" width="10%"><?php echo $rowQ["QuestionNum"]; ?></td>
<td valign="top" width="90%"><?php echo strip_tags($rowQ["QuestionText"], "<p><b><strong><i><u><table><tr><td><th><br><br /><ul><ol><li>"); ?><br>
<textarea name="Question<?php echo $rowQ["CCEAssignmentQID"]; ?>" id="Question<?php echo $rowQ["CCEAssignmentQID"]; ?>" rows="8" cols="60" required placeholder="Answer"><?php echo $rowQ["CCEStudentAnswer"]; ?></textarea>
</td>
</tr>
</table>
<hr>
<?php
} //while
if (mysql_num_rows($recQ) > 0) {
?>
<p>
<input type="button" name="button" id="button" value="Save Answers and Return Later" onClick="SaveAnswers()" />
</p>
<p><b>List the references used in this assignment:</b></p>
<textarea name="references" id="references" cols="45" rows="5" required><?php echo $_REQUEST["references"]; ?></textarea>
<?php
}
?>
<p><b>Upload your assignment file/s here:</b></p>
<p class="text-muted">You may delete a file you have uploaded before the deadline, or before your extension deadline. Deleted files are removed from your submission; you can upload a new file in the same slot.</p>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<?php
for ($fCnt = 1; $fCnt <= 5; $fCnt++) {
$hasFile = isset($lastRow['AssignmentFile' . $fCnt]) && strlen($lastRow['AssignmentFile' . $fCnt]) > 0;
$deleteUrl = isset($_GET['id']) && !empty($lastRow['CCEStudentAssigID'])
? 'assignmentadd.php?id=' . urlencode($_GET['id']) . '&CCEStudentAssigID=' . (int)$lastRow['CCEStudentAssigID'] . '&delete_file=' . $fCnt
: '';
?>
<tr>
<td width="5%" nowrap>File <?php echo $fCnt ?>:</td>
<td width="15%" nowrap>
<input type="file" name="file<?php echo $fCnt ?>" id="file<?php echo $fCnt; ?>" />
</td>
<td>
<?php
if ($hasFile) {
$fileUrl = $cceUploadedFileService->buildStudentAssignmentFileUrl(
intval($_GET['id']),
intval($_SESSION['StudentID']),
$fCnt,
$lastRow['AssignmentFile' . $fCnt]
);
?>
<a href="<?php echo htmlspecialchars((string) $fileUrl); ?>" target="_blank" rel="noopener"><?php echo htmlspecialchars($lastRow['AssignmentFile' . $fCnt]); ?></a>
<?php
if ($deleteUrl) {
?>
<span class="ms-2"><a href="<?php echo htmlspecialchars($deleteUrl); ?>" class="text-danger" onclick="return confirm('Remove this file from your submission?');">Delete</a></span>
<?php
}
}
?>
</td>
</tr>
<?php
} //for
?>
</table>
<!-- <p>Your Comments (optional):<br />
<label>
<textarea name="comments" id="comments" cols="45" rows="5"><?php echo $_REQUEST["comments"]; ?></textarea>
</label>
</p> -->
<div class="row p-3">
<div class="d-grid gap-2 d-md-block text-center">
<input type="submit" name="button" id="button" value="Submit Assignment" class="btn btn-primary" />
</div>
</div>
<?php
}
?>
</form>
<p> </p>
<?php
}
include_once($_SERVER['DOCUMENT_ROOT'] . "/cesanet/includes/html_end.php");