Your IP : 216.73.217.117


Current Path : /var/www/cesa.co.za/cesanet/
Upload File :
Current File : /var/www/cesa.co.za/cesanet/messages.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");

include_once($_SERVER['DOCUMENT_ROOT'] . "/cesanet/includes/html_begin.php");
?>
<h1> Messages Inbox</h1>
<?php
if (!CurrentStudent()) {
    echo "<p><b>Only available to current students.</b></p>";
    die();
}
include_once($_SERVER['DOCUMENT_ROOT'] . "/cesanet/includes/message_menu.php");
?>
<p><strong>Unread Messages:</strong></p>
<?php
$sql = "SELECT CCEMessages.* FROM CCEMessages, CCEMessagesSentTo
WHERE CCEMessages.CCEMessageID=CCEMessagesSentTo.CCEMessageID
AND CCEMessagesSentTo.SentType='Student'
AND CCEMessagesSentTo.SentID=" . $_SESSION["StudentID"] . "
AND CCEMessages.CCEMessageID NOT IN (SELECT CCEMessageID FROM CCEMessageLog WHERE ReadByType='Student' AND ReadByID=" . $_SESSION["StudentID"] . ")
AND CCEMessages.MessageSubject NOT LIKE 'Feedback on BCE Assignment %' 
AND CCEMessages.MessageSubject NOT LIKE 'CESAnet Assignment Submitted%' 
ORDER BY SentDateTime DESC";
$rec = mysql_query($sql);
if (mysql_num_rows($rec) == 0) {
    echo "<p>You have no new messages.</p>";
} else {
    ?>
    <table border="1" cellpadding="5" cellspacing="0" width="95%" align="center">
        <tr>
            <td><b>Subject</b></td>
            <td width="10%" nowrap><b>Date Sent</b></td>
            <td width="20%" nowrap><b>From</b></td>
            <td width="5%" nowrap>&nbsp;</td>
        </tr>
        <?php
        while ($row = mysql_fetch_assoc($rec)) {
            ?>
            <tr>
                <td><?php echo $row["MessageSubject"]; ?></td>
                <td width="10%" nowrap><?php echo date("Y-m-d H:i", strtotime($row["SentDateTime"])); ?></td>
                <td width="20%" nowrap><?php echo $row["SentByName"]; ?></td>
                <td width="5%" nowrap><a href="readmessage.php?id=<?php echo $row["CCEMessageID"]; ?>">Read Now</a></td>
            </tr>
            <?php
        }
        ?>
    </table>
    <?php
}
mysql_free_result($rec);
?>

<p><strong>Read Messages:</strong></p>
<?php
$sql = "SELECT CCEMessages.CCEMessageID, SentDateTime, SentByName, MessageSubject, MIN(ReadDateTime) AS DateRead
FROM CCEMessages, CCEMessagesSentTo, CCEMessageLog
WHERE CCEMessages.CCEMessageID=CCEMessagesSentTo.CCEMessageID
AND CCEMessages.CCEMessageID=CCEMessageLog.CCEMessageID
AND CCEMessagesSentTo.SentType='Student'
AND CCEMessagesSentTo.SentID=" . $_SESSION["StudentID"] . "
AND CCEMessageLog.ReadByType='Student'
AND CCEMessageLog.ReadByID=" . $_SESSION["StudentID"] . " 
AND CCEMessages.MessageSubject NOT LIKE 'Feedback on BCE Assignment %' 
AND CCEMessages.MessageSubject NOT LIKE 'CESAnet Assignment Submitted %' 
GROUP BY CCEMessages.CCEMessageID, SentDateTime, SentByName, MessageSubject
ORDER BY SentDateTime DESC";
$rec = mysql_query($sql);
if (mysql_num_rows($rec) == 0) {
    echo "<p>You have no previous read messages.</p>";
} else {
    ?>
    <table border="1" cellpadding="5" cellspacing="0" width="95%" align="center">
        <tr>
            <td><b>Subject</b></td>
            <td width="10%" nowrap><b>Date Read</b></td>
            <td width="10%" nowrap><b>Date Sent</b></td>
            <td width="20%" nowrap><b>From</b></td>
            <td width="5%" nowrap>&nbsp;</td></tr>
        <?php
        while ($row = mysql_fetch_assoc($rec)) {
            ?>
            <tr>
                <td><?php echo $row["MessageSubject"]; ?></td>
                <td width="10%" nowrap><?php echo date("Y-m-d H:i", strtotime($row["DateRead"])); ?></td>
                <td width="10%" nowrap><?php echo date("Y-m-d H:i", strtotime($row["SentDateTime"])); ?></td>
                <td width="20%" nowrap><?php echo $row["SentByName"]; ?></td>
                <td width="5%" nowrap><a href="readmessage.php?id=<?php echo $row["CCEMessageID"]; ?>">Read Now</a></td></tr>
            <?php
        }
        ?>
    </table>
    <?php
}
mysql_free_result($rec);

include_once($_SERVER['DOCUMENT_ROOT'] . "/cesanet/includes/html_end.php");