예제 #1
0
function getUnreadMessages($inUserID)
{
    if (isset($_SESSION['userid'])) {
        $messages = array();
        $messageid;
        $dbhandle = db_connect();
        $stmt = $dbhandle->stmt_init();
        //Get all messages from/to this user that are unread
        $stmt->prepare("SELECT MessageID, Time FROM Messages WHERE SenderID=? AND ReceiverID=? AND ReadFlag=0 ORDER BY Time");
        $stmt->bind_param("ii", $inUserID, $_SESSION['userid']);
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($messageid, $temptime);
        //Add each resulting message to the array to return
        //Mark the message as read
        while ($stmt->fetch()) {
            $message = new message();
            $message->getFromDB($messageid);
            $message->markRead();
            array_push($messages, $message);
        }
        $stmt->close();
        $dbhandle->close();
        return $messages;
    }
}
예제 #2
0
<?php

require_once 'message_class.php';
$out = array();
if (isset($_POST['messageid'])) {
    $message = new message();
    if ($message->getFromDB($_POST['messageid']) != null) {
        $out['error'] = true;
        $out['MsgNotFound'] = true;
    } else {
        if ($message->markRead() == null) {
            $out['Success'] = true;
        } else {
            $out['error'] = true;
            $out['NotMarkedRead'] = true;
        }
    }
} else {
    $out['error'] = true;
    $out['BadPostInput'] = true;
}
echo json_encode($out);